Search in sources :

Example 1 with JarHandlerContext

use of org.apache.flink.runtime.webmonitor.handlers.utils.JarHandlerUtils.JarHandlerContext in project flink by apache.

the class JarRunHandler method handleRequest.

@Override
@VisibleForTesting
public CompletableFuture<JarRunResponseBody> handleRequest(@Nonnull final HandlerRequest<JarRunRequestBody> request, @Nonnull final DispatcherGateway gateway) throws RestHandlerException {
    final Configuration effectiveConfiguration = new Configuration(configuration);
    effectiveConfiguration.set(DeploymentOptions.ATTACHED, false);
    effectiveConfiguration.set(DeploymentOptions.TARGET, EmbeddedExecutor.NAME);
    final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);
    context.applyToConfiguration(effectiveConfiguration);
    SavepointRestoreSettings.toConfiguration(getSavepointRestoreSettings(request), effectiveConfiguration);
    final PackagedProgram program = context.toPackagedProgram(effectiveConfiguration);
    return CompletableFuture.supplyAsync(() -> applicationRunner.run(gateway, program, effectiveConfiguration), executor).handle((jobIds, throwable) -> {
        program.close();
        if (throwable != null) {
            throw new CompletionException(new RestHandlerException("Could not execute application.", HttpResponseStatus.BAD_REQUEST, throwable));
        } else if (jobIds.isEmpty()) {
            throw new CompletionException(new RestHandlerException("No jobs included in application.", HttpResponseStatus.BAD_REQUEST));
        }
        return new JarRunResponseBody(jobIds.get(0));
    });
}
Also used : PackagedProgram(org.apache.flink.client.program.PackagedProgram) Configuration(org.apache.flink.configuration.Configuration) JarHandlerContext(org.apache.flink.runtime.webmonitor.handlers.utils.JarHandlerUtils.JarHandlerContext) CompletionException(java.util.concurrent.CompletionException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

CompletionException (java.util.concurrent.CompletionException)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 PackagedProgram (org.apache.flink.client.program.PackagedProgram)1 Configuration (org.apache.flink.configuration.Configuration)1 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)1 JarHandlerContext (org.apache.flink.runtime.webmonitor.handlers.utils.JarHandlerUtils.JarHandlerContext)1