use of org.apache.flink.util.FlinkException in project flink by apache.
the class CliFrontend method cancel.
/**
* Executes the CANCEL action.
*
* @param args Command line arguments for the cancel action.
*/
protected void cancel(String[] args) throws Exception {
LOG.info("Running 'cancel' command.");
final Options commandOptions = CliFrontendParser.getCancelCommandOptions();
final CommandLine commandLine = getCommandLine(commandOptions, args, false);
CancelOptions cancelOptions = new CancelOptions(commandLine);
// evaluate help flag
if (cancelOptions.isPrintHelp()) {
CliFrontendParser.printHelpForCancel(customCommandLines);
return;
}
final CustomCommandLine activeCommandLine = validateAndGetActiveCommandLine(commandLine);
final String[] cleanedArgs = cancelOptions.getArgs();
if (cancelOptions.isWithSavepoint()) {
logAndSysout("DEPRECATION WARNING: Cancelling a job with savepoint is deprecated. Use \"stop\" instead.");
final JobID jobId;
final String targetDirectory;
if (cleanedArgs.length > 0) {
jobId = parseJobId(cleanedArgs[0]);
targetDirectory = cancelOptions.getSavepointTargetDirectory();
} else {
jobId = parseJobId(cancelOptions.getSavepointTargetDirectory());
targetDirectory = null;
}
final SavepointFormatType formatType = cancelOptions.getFormatType();
if (targetDirectory == null) {
logAndSysout("Cancelling job " + jobId + " with " + formatType + " savepoint to default savepoint directory.");
} else {
logAndSysout("Cancelling job " + jobId + " with " + formatType + " savepoint to " + targetDirectory + '.');
}
runClusterAction(activeCommandLine, commandLine, clusterClient -> {
final String savepointPath;
try {
savepointPath = clusterClient.cancelWithSavepoint(jobId, targetDirectory, formatType).get(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (Exception e) {
throw new FlinkException("Could not cancel job " + jobId + '.', e);
}
logAndSysout("Cancelled job " + jobId + ". Savepoint stored in " + savepointPath + '.');
});
} else {
final JobID jobId;
if (cleanedArgs.length > 0) {
jobId = parseJobId(cleanedArgs[0]);
} else {
throw new CliArgsException("Missing JobID. Specify a JobID to cancel a job.");
}
logAndSysout("Cancelling job " + jobId + '.');
runClusterAction(activeCommandLine, commandLine, clusterClient -> {
try {
clusterClient.cancel(jobId).get(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (Exception e) {
throw new FlinkException("Could not cancel job " + jobId + '.', e);
}
});
logAndSysout("Cancelled job " + jobId + '.');
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class CliFrontend method runClusterAction.
/**
* Retrieves the {@link ClusterClient} from the given {@link CustomCommandLine} and runs the
* given {@link ClusterAction} against it.
*
* @param activeCommandLine to create the {@link ClusterDescriptor} from
* @param commandLine containing the parsed command line options
* @param clusterAction the cluster action to run against the retrieved {@link ClusterClient}.
* @param <ClusterID> type of the cluster id
* @throws FlinkException if something goes wrong
*/
private <ClusterID> void runClusterAction(CustomCommandLine activeCommandLine, CommandLine commandLine, ClusterAction<ClusterID> clusterAction) throws FlinkException {
final Configuration effectiveConfiguration = getEffectiveConfiguration(activeCommandLine, commandLine);
LOG.debug("Effective configuration after Flink conf, and custom commandline: {}", effectiveConfiguration);
final ClusterClientFactory<ClusterID> clusterClientFactory = clusterClientServiceLoader.getClusterClientFactory(effectiveConfiguration);
final ClusterID clusterId = clusterClientFactory.getClusterId(effectiveConfiguration);
if (clusterId == null) {
throw new FlinkException("No cluster id was specified. Please specify a cluster to which you would like to connect.");
}
try (final ClusterDescriptor<ClusterID> clusterDescriptor = clusterClientFactory.createClusterDescriptor(effectiveConfiguration)) {
try (final ClusterClient<ClusterID> clusterClient = clusterDescriptor.retrieve(clusterId).getClusterClient()) {
clusterAction.runAction(clusterClient);
}
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class EmbeddedExecutor method submitJob.
private static CompletableFuture<JobID> submitJob(final Configuration configuration, final DispatcherGateway dispatcherGateway, final JobGraph jobGraph, final Time rpcTimeout) {
checkNotNull(jobGraph);
LOG.info("Submitting Job with JobId={}.", jobGraph.getJobID());
return dispatcherGateway.getBlobServerPort(rpcTimeout).thenApply(blobServerPort -> new InetSocketAddress(dispatcherGateway.getHostname(), blobServerPort)).thenCompose(blobServerAddress -> {
try {
ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(blobServerAddress, configuration));
} catch (FlinkException e) {
throw new CompletionException(e);
}
return dispatcherGateway.submitJob(jobGraph, rpcTimeout);
}).thenApply(ack -> jobGraph.getJobID());
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class CliFrontendSavepointTest method testTriggerSavepointFailure.
@Test
public void testTriggerSavepointFailure() throws Exception {
replaceStdOutAndStdErr();
JobID jobId = new JobID();
String expectedTestException = "expectedTestException";
Exception testException = new Exception(expectedTestException);
final ClusterClient<String> clusterClient = createFailingClusterClient(testException);
try {
MockedCliFrontend frontend = new MockedCliFrontend(clusterClient);
String[] parameters = { jobId.toString() };
try {
frontend.savepoint(parameters);
fail("Savepoint should have failed.");
} catch (FlinkException e) {
assertTrue(ExceptionUtils.findThrowableWithMessage(e, expectedTestException).isPresent());
}
} finally {
clusterClient.close();
restoreStdOutAndStdErr();
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class DefaultOperatorCoordinatorHandler method deliverOperatorEventToCoordinator.
@Override
public void deliverOperatorEventToCoordinator(final ExecutionAttemptID taskExecutionId, final OperatorID operatorId, final OperatorEvent evt) throws FlinkException {
// Failure semantics (as per the javadocs of the method):
// If the task manager sends an event for a non-running task or an non-existing operator
// coordinator, then respond with an exception to the call. If task and coordinator exist,
// then we assume that the call from the TaskManager was valid, and any bubbling exception
// needs to cause a job failure.
final Execution exec = executionGraph.getRegisteredExecutions().get(taskExecutionId);
if (exec == null || exec.getState() != ExecutionState.RUNNING && exec.getState() != ExecutionState.INITIALIZING) {
// on the safe, we notify the TM that the event could not be delivered.
throw new TaskNotRunningException("Task is not known or in state running on the JobManager.");
}
final OperatorCoordinatorHolder coordinator = coordinatorMap.get(operatorId);
if (coordinator == null) {
throw new FlinkException("No coordinator registered for operator " + operatorId);
}
try {
coordinator.handleEventFromOperator(exec.getParallelSubtaskIndex(), evt);
} catch (Throwable t) {
ExceptionUtils.rethrowIfFatalErrorOrOOM(t);
globalFailureHandler.handleGlobalFailure(t);
}
}
Aggregations