public static <T> FlinkCompletableFuture<T> completed(T value) { return new FlinkCompletableFuture<>(value); }
@Override public Future<Void> retrievePayload() { return FlinkCompletableFuture.completed(null); } }
@Override public Future<SimpleSlot> allocateSlot(ScheduledUnit task, boolean allowQueued) { try { final Object ret = scheduleTask(task, allowQueued); if (ret instanceof SimpleSlot) { return FlinkCompletableFuture.completed((SimpleSlot) ret); } else if (ret instanceof Future) { @SuppressWarnings("unchecked") Future<SimpleSlot> typed = (Future<SimpleSlot>) ret; return typed; } else { // this should never happen, simply guard this case with an exception throw new RuntimeException(); } } catch (NoResourceAvailableException e) { return FlinkCompletableFuture.completedExceptionally(e); } }
private void checkTimeoutSlotAllocation(AllocationID allocationID) { PendingRequest request = pendingRequests.remove(allocationID); if (request != null && !request.future().isDone()) { request.future().completeExceptionally(new TimeoutException("Slot allocation request timed out")); } }
Future<SimpleSlot> internalAllocateSlot( ScheduledUnit task, ResourceProfile resources, Iterable<TaskManagerLocation> locationPreferences) { // (1) do we have a slot available already? SlotAndLocality slotFromPool = availableSlots.poll(resources, locationPreferences); if (slotFromPool != null) { SimpleSlot slot = createSimpleSlot(slotFromPool.slot(), slotFromPool.locality()); allocatedSlots.add(slot); return FlinkCompletableFuture.completed(slot); } // the request will be completed by a future final AllocationID allocationID = new AllocationID(); final FlinkCompletableFuture<SimpleSlot> future = new FlinkCompletableFuture<>(); // (2) need to request a slot if (resourceManagerGateway == null) { // no slot available, and no resource manager connection stashRequestWaitingForResourceManager(allocationID, resources, future); } else { // we have a resource manager connection, so let's ask it for more resources requestSlotFromResourceManager(allocationID, future, resources); } return future; }
/** * Request a stack trace sample from the task of this execution. * * @param sampleId of the stack trace sample * @param numSamples the sample should contain * @param delayBetweenSamples to wait * @param maxStrackTraceDepth of the samples * @param timeout until the request times out * @return Future stack trace sample response */ public Future<StackTraceSampleResponse> requestStackTraceSample( int sampleId, int numSamples, Time delayBetweenSamples, int maxStrackTraceDepth, Time timeout) { final SimpleSlot slot = assignedResource; if (slot != null) { final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway(); return taskManagerGateway.requestStackTraceSample( attemptId, sampleId, numSamples, delayBetweenSamples, maxStrackTraceDepth, timeout); } else { return FlinkCompletableFuture.completedExceptionally(new Exception("The execution has no slot assigned.")); } }
@Override public void handleError(Exception exception) { future.completeExceptionally(exception); } }
@Override public void notifyLeaderAddress(String leaderAddress, UUID leaderSessionID) { future.complete(new LeaderAddressAndId(leaderAddress, leaderSessionID)); }
operationResultFuture = operation.call(); } catch (Exception e) { return FlinkCompletableFuture.completedExceptionally( new RetryException("Could not execute the provided operation.", e));
@Override public boolean cancel(boolean mayInterruptIfRunning) { return completeExceptionally(new CancellationException("Future has been canceled.")); }
private void checkTimeoutRequestWaitingForResourceManager(AllocationID allocationID) { PendingRequest request = waitingForResourceManager.remove(allocationID); if (request != null && !request.future().isDone()) { request.future().completeExceptionally(new NoResourceAvailableException( "No slot available and no connection to Resource Manager established.")); } }
@GuardedBy("lock") private CompletedCheckpoint finalizeInternal( @Nullable StreamStateHandle externalMetadata, @Nullable String externalPointer) { assert(Thread.holdsLock(lock)); CompletedCheckpoint completed = new CompletedCheckpoint( jobId, checkpointId, checkpointTimestamp, System.currentTimeMillis(), operatorStates, masterState, props, externalMetadata, externalPointer); onCompletionPromise.complete(completed); // to prevent null-pointers from concurrent modification, copy reference onto stack PendingCheckpointStats statsCallback = this.statsCallback; if (statsCallback != null) { // Finalize the statsCallback and give the completed checkpoint a // callback for discards. CompletedCheckpointStats.DiscardCallback discardCallback = statsCallback.reportCompletedCheckpoint(externalPointer); completed.setDiscardCallback(discardCallback); } // mark this pending checkpoint as disposed, but do NOT drop the state dispose(false); return completed; }
public OneTimeLeaderListenerFuture() { this.future = new FlinkCompletableFuture<>(); }
@Override public Future<Void> retrievePayload() { return FlinkCompletableFuture.completed(null); } }
return FlinkCompletableFuture.completedExceptionally(exception); return FlinkCompletableFuture.completedExceptionally(exception); resourceManagerLeaderId, leaderSessionId); return FlinkCompletableFuture.<RegistrationResponse>completed( new RegistrationResponse.Decline("Resource manager leader id did not match."));
operationResultFuture = operation.call(); } catch (Exception e) { return FlinkCompletableFuture.completedExceptionally( new RetryException("Could not execute the provided operation.", e));
private void slotRequestToResourceManagerFailed(AllocationID allocationID, Throwable failure) { PendingRequest request = pendingRequests.remove(allocationID); if (request != null) { request.future().completeExceptionally(new NoResourceAvailableException( "No pooled slot available and request to ResourceManager for new slot failed", failure)); } else { if (LOG.isDebugEnabled()) { LOG.debug("Unregistered slot request {} failed.", allocationID, failure); } } }
terminationFuture.complete(FAILED);
public static <T> FlinkCompletableFuture<T> completedExceptionally(Throwable t) { return new FlinkCompletableFuture<>(t); } }
@Override public Future<Void> retrievePayload() { return FlinkCompletableFuture.completed(null); } }