use of org.apache.flink.core.execution.DetachedJobExecutionResult in project flink by apache.
the class ContextEnvironment method getJobExecutionResult.
private JobExecutionResult getJobExecutionResult(final JobClient jobClient) throws Exception {
checkNotNull(jobClient);
JobExecutionResult jobExecutionResult;
if (getConfiguration().getBoolean(DeploymentOptions.ATTACHED)) {
CompletableFuture<JobExecutionResult> jobExecutionResultFuture = jobClient.getJobExecutionResult();
if (getConfiguration().getBoolean(DeploymentOptions.SHUTDOWN_IF_ATTACHED)) {
Thread shutdownHook = ShutdownHookUtil.addShutdownHook(() -> {
// wait a smidgen to allow the async request to go through
// before
// the jvm exits
jobClient.cancel().get(1, TimeUnit.SECONDS);
}, ContextEnvironment.class.getSimpleName(), LOG);
jobExecutionResultFuture.whenComplete((ignored, throwable) -> ShutdownHookUtil.removeShutdownHook(shutdownHook, ContextEnvironment.class.getSimpleName(), LOG));
}
jobExecutionResult = jobExecutionResultFuture.get();
if (!suppressSysout) {
System.out.println(jobExecutionResult);
}
LOG.info(String.valueOf(jobExecutionResult));
} else {
jobExecutionResult = new DetachedJobExecutionResult(jobClient.getJobID());
}
return jobExecutionResult;
}
use of org.apache.flink.core.execution.DetachedJobExecutionResult in project flink by apache.
the class StreamExecutionEnvironment method execute.
/**
* Triggers the program execution. The environment will execute all parts of the program that
* have resulted in a "sink" operation. Sink operations are for example printing results or
* forwarding them to a message queue.
*
* @param streamGraph the stream graph representing the transformations
* @return The result of the job execution, containing elapsed time and accumulators.
* @throws Exception which occurs during job execution.
*/
@Internal
public JobExecutionResult execute(StreamGraph streamGraph) throws Exception {
final JobClient jobClient = executeAsync(streamGraph);
try {
final JobExecutionResult jobExecutionResult;
if (configuration.getBoolean(DeploymentOptions.ATTACHED)) {
jobExecutionResult = jobClient.getJobExecutionResult().get();
} else {
jobExecutionResult = new DetachedJobExecutionResult(jobClient.getJobID());
}
jobListeners.forEach(jobListener -> jobListener.onJobExecuted(jobExecutionResult, null));
return jobExecutionResult;
} catch (Throwable t) {
// get() on the JobExecutionResult Future will throw an ExecutionException. This
// behaviour was largely not there in Flink versions before the PipelineExecutor
// refactoring so we should strip that exception.
Throwable strippedException = ExceptionUtils.stripExecutionException(t);
jobListeners.forEach(jobListener -> {
jobListener.onJobExecuted(null, strippedException);
});
ExceptionUtils.rethrowException(strippedException);
// never reached, only make javac happy
return null;
}
}
use of org.apache.flink.core.execution.DetachedJobExecutionResult in project flink by apache.
the class StreamContextEnvironment method getJobExecutionResult.
private JobExecutionResult getJobExecutionResult(final JobClient jobClient) throws Exception {
checkNotNull(jobClient);
JobExecutionResult jobExecutionResult;
if (configuration.getBoolean(DeploymentOptions.ATTACHED)) {
CompletableFuture<JobExecutionResult> jobExecutionResultFuture = jobClient.getJobExecutionResult();
if (configuration.getBoolean(DeploymentOptions.SHUTDOWN_IF_ATTACHED)) {
Thread shutdownHook = ShutdownHookUtil.addShutdownHook(() -> {
// wait a smidgen to allow the async request to go through
// before
// the jvm exits
jobClient.cancel().get(1, TimeUnit.SECONDS);
}, StreamContextEnvironment.class.getSimpleName(), LOG);
jobExecutionResultFuture.whenComplete((ignored, throwable) -> ShutdownHookUtil.removeShutdownHook(shutdownHook, StreamContextEnvironment.class.getSimpleName(), LOG));
}
jobExecutionResult = jobExecutionResultFuture.get();
if (!suppressSysout) {
System.out.println(jobExecutionResult);
}
} else {
jobExecutionResult = new DetachedJobExecutionResult(jobClient.getJobID());
}
return jobExecutionResult;
}
Aggregations