@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); } }
/** * 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.")); } }
operationResultFuture = operation.call(); } catch (Exception e) { return FlinkCompletableFuture.completedExceptionally( new RetryException("Could not execute the provided operation.", e));
operationResultFuture = operation.call(); } catch (Exception e) { return FlinkCompletableFuture.completedExceptionally( new RetryException("Could not execute the provided operation.", e));
triggerIds[i] = execution.getAttemptId(); } else { return FlinkCompletableFuture.completedExceptionally( new IllegalStateException("Task " + tasksToSample[i] .getTaskNameWithSubtaskIndex() + " is not running.")); return FlinkCompletableFuture.completedExceptionally(new IllegalStateException("Shut down"));
/** * Test method to trigger a checkpoint/savepoint. * * @param timestamp The timestamp for the checkpoint. * @param options The checkpoint options. * @return A future to the completed checkpoint */ @VisibleForTesting @Internal public Future<CompletedCheckpoint> triggerCheckpoint(long timestamp, CheckpointOptions options) throws Exception { switch (options.getCheckpointType()) { case SAVEPOINT: return triggerSavepoint(timestamp, options.getTargetLocation()); case FULL_CHECKPOINT: CheckpointTriggerResult triggerResult = triggerCheckpoint(timestamp, checkpointProperties, checkpointDirectory, false); if (triggerResult.isSuccess()) { return triggerResult.getPendingCheckpoint().getCompletionFuture(); } else { Throwable cause = new Exception("Failed to trigger checkpoint: " + triggerResult.getFailureReason().message()); return FlinkCompletableFuture.completedExceptionally(cause); } default: throw new IllegalArgumentException("Unknown checkpoint type: " + options.getCheckpointType()); } }
} else { Throwable cause = new Exception("Failed to trigger savepoint: " + triggerResult.getFailureReason().message()); result = FlinkCompletableFuture.completedExceptionally(cause);
return FlinkCompletableFuture.completedExceptionally(exception); return FlinkCompletableFuture.completedExceptionally(exception);