Java Code Examples for org.apache.flink.runtime.clusterframework.types.AllocationID#equals()

The following examples show how to use org.apache.flink.runtime.clusterframework.types.AllocationID#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskSlot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Allocate the task slot for the given job and allocation id. If the slot could be allocated,
 * or is already allocated/active for the given job and allocation id, then the method returns
 * true. Otherwise it returns false.
 *
 * <p>A slot can only be allocated if it's current state is free.
 *
 * @param newJobId to allocate the slot for
 * @param newAllocationId to identify the slot allocation
 * @return True if the slot was allocated for the given job and allocation id; otherwise false
 */
public boolean allocate(JobID newJobId, AllocationID newAllocationId) {
	if (TaskSlotState.FREE == state) {
		// sanity checks
		Preconditions.checkState(allocationId == null);
		Preconditions.checkState(jobId == null);

		this.jobId = Preconditions.checkNotNull(newJobId);
		this.allocationId = Preconditions.checkNotNull(newAllocationId);

		state = TaskSlotState.ALLOCATED;

		return true;
	} else if (TaskSlotState.ALLOCATED == state || TaskSlotState.ACTIVE == state) {
		Preconditions.checkNotNull(newJobId);
		Preconditions.checkNotNull(newAllocationId);

		return newJobId.equals(jobId) && newAllocationId.equals(allocationId);
	} else {
		return false;
	}
}
 
Example 2
Source File: TaskSlot.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Allocate the task slot for the given job and allocation id. If the slot could be allocated,
 * or is already allocated/active for the given job and allocation id, then the method returns
 * true. Otherwise it returns false.
 *
 * <p>A slot can only be allocated if it's current state is free.
 *
 * @param newJobId to allocate the slot for
 * @param newAllocationId to identify the slot allocation
 * @return True if the slot was allocated for the given job and allocation id; otherwise false
 */
public boolean allocate(JobID newJobId, AllocationID newAllocationId) {
	if (TaskSlotState.FREE == state) {
		// sanity checks
		Preconditions.checkState(allocationId == null);
		Preconditions.checkState(jobId == null);

		this.jobId = Preconditions.checkNotNull(newJobId);
		this.allocationId = Preconditions.checkNotNull(newAllocationId);

		state = TaskSlotState.ALLOCATED;

		return true;
	} else if (TaskSlotState.ALLOCATED == state || TaskSlotState.ACTIVE == state) {
		Preconditions.checkNotNull(newJobId);
		Preconditions.checkNotNull(newAllocationId);

		return newJobId.equals(jobId) && newAllocationId.equals(allocationId);
	} else {
		return false;
	}
}
 
Example 3
Source File: TaskSlot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public boolean isActive(JobID activeJobId, AllocationID activeAllocationId) {
	Preconditions.checkNotNull(activeJobId);
	Preconditions.checkNotNull(activeAllocationId);

	return TaskSlotState.ACTIVE == state &&
		activeJobId.equals(jobId) &&
		activeAllocationId.equals(allocationId);
}
 
Example 4
Source File: TaskSlot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public boolean isAllocated(JobID jobIdToCheck, AllocationID allocationIDToCheck) {
	Preconditions.checkNotNull(jobIdToCheck);
	Preconditions.checkNotNull(allocationIDToCheck);

	return jobIdToCheck.equals(jobId) && allocationIDToCheck.equals(allocationId) &&
		(TaskSlotState.ACTIVE == state || TaskSlotState.ALLOCATED == state);
}
 
Example 5
Source File: TaskSlot.java    From flink with Apache License 2.0 5 votes vote down vote up
public boolean isActive(JobID activeJobId, AllocationID activeAllocationId) {
	Preconditions.checkNotNull(activeJobId);
	Preconditions.checkNotNull(activeAllocationId);

	return TaskSlotState.ACTIVE == state &&
		activeJobId.equals(jobId) &&
		activeAllocationId.equals(allocationId);
}
 
Example 6
Source File: TaskSlot.java    From flink with Apache License 2.0 5 votes vote down vote up
public boolean isAllocated(JobID jobIdToCheck, AllocationID allocationIDToCheck) {
	Preconditions.checkNotNull(jobIdToCheck);
	Preconditions.checkNotNull(allocationIDToCheck);

	return jobIdToCheck.equals(jobId) && allocationIDToCheck.equals(allocationId) &&
		(TaskSlotState.ACTIVE == state || TaskSlotState.ALLOCATED == state);
}
 
Example 7
Source File: SlotPoolImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private void maybeRemapOrphanedAllocation(
		final AllocationID allocationIdOfRequest,
		final AllocationID allocationIdOfSlot) {

	// allocation of a request is orphaned if the request is fulfilled by a different allocated slot.
	// if the request of that allocated slot is still pending, it should take over the orphaned allocation.
	// this enables the request to fail fast if the remapped allocation fails.
	if (!allocationIdOfRequest.equals(allocationIdOfSlot)) {
		final PendingRequest requestOfAllocatedSlot = pendingRequests.getValueByKeyB(allocationIdOfSlot);
		if (requestOfAllocatedSlot != null) {
			requestOfAllocatedSlot.setAllocationId(allocationIdOfRequest);

			// this re-insertion of request will not affect its original insertion order
			pendingRequests.put(
				requestOfAllocatedSlot.getSlotRequestId(),
				allocationIdOfRequest,
				requestOfAllocatedSlot);
		} else {
			// request id of the allocated slot can be null if the slot is returned by scheduler.
			// the orphaned allocation will not be adopted in this case, which means it is not needed
			// anymore by any pending requests. we should cancel it to avoid allocating unnecessary slots.
			if (resourceManagerGateway != null) {
				resourceManagerGateway.cancelSlotRequest(allocationIdOfRequest);
			}
		}
	}
}
 
Example 8
Source File: TaskSlot.java    From flink with Apache License 2.0 5 votes vote down vote up
public boolean isActive(JobID activeJobId, AllocationID activeAllocationId) {
	Preconditions.checkNotNull(activeJobId);
	Preconditions.checkNotNull(activeAllocationId);

	return TaskSlotState.ACTIVE == state &&
		activeJobId.equals(jobId) &&
		activeAllocationId.equals(allocationId);
}
 
Example 9
Source File: TaskSlot.java    From flink with Apache License 2.0 5 votes vote down vote up
public boolean isAllocated(JobID jobIdToCheck, AllocationID allocationIDToCheck) {
	Preconditions.checkNotNull(jobIdToCheck);
	Preconditions.checkNotNull(allocationIDToCheck);

	return jobIdToCheck.equals(jobId) && allocationIDToCheck.equals(allocationId) &&
		(TaskSlotState.ACTIVE == state || TaskSlotState.ALLOCATED == state);
}