Java Code Examples for org.apache.flink.runtime.resourcemanager.ResourceManagerGateway#requestSlot()

The following examples show how to use org.apache.flink.runtime.resourcemanager.ResourceManagerGateway#requestSlot() . 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: SlotPoolImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void requestSlotFromResourceManager(
		final ResourceManagerGateway resourceManagerGateway,
		final PendingRequest pendingRequest) {

	checkNotNull(resourceManagerGateway);
	checkNotNull(pendingRequest);

	log.info("Requesting new slot [{}] and profile {} from resource manager.", pendingRequest.getSlotRequestId(), pendingRequest.getResourceProfile());

	final AllocationID allocationId = new AllocationID();

	pendingRequests.put(pendingRequest.getSlotRequestId(), allocationId, pendingRequest);

	pendingRequest.getAllocatedSlotFuture().whenComplete(
		(AllocatedSlot allocatedSlot, Throwable throwable) -> {
			if (throwable != null || !allocationId.equals(allocatedSlot.getAllocationId())) {
				// cancel the slot request if there is a failure or if the pending request has
				// been completed with another allocated slot
				resourceManagerGateway.cancelSlotRequest(allocationId);
			}
		});

	CompletableFuture<Acknowledge> rmResponse = resourceManagerGateway.requestSlot(
		jobMasterId,
		new SlotRequest(jobId, allocationId, pendingRequest.getResourceProfile(), jobManagerAddress),
		rpcTimeout);

	FutureUtils.whenCompleteAsyncIfNotDone(
		rmResponse,
		componentMainThreadExecutor,
		(Acknowledge ignored, Throwable failure) -> {
			// on failure, fail the request future
			if (failure != null) {
				slotRequestToResourceManagerFailed(pendingRequest.getSlotRequestId(), failure);
			}
		});
}
 
Example 2
Source File: SlotPoolImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private void requestSlotFromResourceManager(
		final ResourceManagerGateway resourceManagerGateway,
		final PendingRequest pendingRequest) {

	checkNotNull(resourceManagerGateway);
	checkNotNull(pendingRequest);

	log.info("Requesting new slot [{}] and profile {} from resource manager.", pendingRequest.getSlotRequestId(), pendingRequest.getResourceProfile());

	final AllocationID allocationId = new AllocationID();

	pendingRequests.put(pendingRequest.getSlotRequestId(), allocationId, pendingRequest);

	pendingRequest.getAllocatedSlotFuture().whenComplete(
		(AllocatedSlot allocatedSlot, Throwable throwable) -> {
			if (throwable != null || !allocationId.equals(allocatedSlot.getAllocationId())) {
				// cancel the slot request if there is a failure or if the pending request has
				// been completed with another allocated slot
				resourceManagerGateway.cancelSlotRequest(allocationId);
			}
		});

	CompletableFuture<Acknowledge> rmResponse = resourceManagerGateway.requestSlot(
		jobMasterId,
		new SlotRequest(jobId, allocationId, pendingRequest.getResourceProfile(), jobManagerAddress),
		rpcTimeout);

	FutureUtils.whenCompleteAsyncIfNotDone(
		rmResponse,
		componentMainThreadExecutor,
		(Acknowledge ignored, Throwable failure) -> {
			// on failure, fail the request future
			if (failure != null) {
				slotRequestToResourceManagerFailed(pendingRequest.getSlotRequestId(), failure);
			}
		});
}
 
Example 3
Source File: SlotPoolImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
private void requestSlotFromResourceManager(
		final ResourceManagerGateway resourceManagerGateway,
		final PendingRequest pendingRequest) {

	checkNotNull(resourceManagerGateway);
	checkNotNull(pendingRequest);

	final AllocationID allocationId = new AllocationID();
	pendingRequest.setAllocationId(allocationId);

	pendingRequests.put(pendingRequest.getSlotRequestId(), allocationId, pendingRequest);

	pendingRequest.getAllocatedSlotFuture().whenComplete(
		(AllocatedSlot allocatedSlot, Throwable throwable) -> {
			if (throwable != null) {
				// the allocation id can be remapped so we need to get it from the pendingRequest
				// where it will be updated timely
				final Optional<AllocationID> updatedAllocationId = pendingRequest.getAllocationId();

				if (updatedAllocationId.isPresent()) {
					// cancel the slot request if there is a failure
					resourceManagerGateway.cancelSlotRequest(updatedAllocationId.get());
				}
			}
		});

	log.info("Requesting new slot [{}] and profile {} with allocation id {} from resource manager.",
		pendingRequest.getSlotRequestId(), pendingRequest.getResourceProfile(), allocationId);

	CompletableFuture<Acknowledge> rmResponse = resourceManagerGateway.requestSlot(
		jobMasterId,
		new SlotRequest(jobId, allocationId, pendingRequest.getResourceProfile(), jobManagerAddress),
		rpcTimeout);

	FutureUtils.whenCompleteAsyncIfNotDone(
		rmResponse,
		componentMainThreadExecutor,
		(Acknowledge ignored, Throwable failure) -> {
			// on failure, fail the request future
			if (failure != null) {
				slotRequestToResourceManagerFailed(pendingRequest.getSlotRequestId(), failure);
			}
		});
}