org.apache.flink.runtime.webmonitor.handlers.utils.JarHandlerUtils.JarHandlerContext Java Examples

The following examples show how to use org.apache.flink.runtime.webmonitor.handlers.utils.JarHandlerUtils.JarHandlerContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JarRunHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JarRunResponseBody> handleRequest(
		@Nonnull final HandlerRequest<JarRunRequestBody, JarRunMessageParameters> 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)
			.thenApply(jobIds -> {
				if (jobIds.isEmpty()) {
					throw new CompletionException(new ProgramInvocationException("No jobs submitted."));
				}
				return new JarRunResponseBody(jobIds.get(0));
			});
}
 
Example #2
Source File: JarPlanHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JobPlanInfo> handleRequest(
		@Nonnull final HandlerRequest<JarPlanRequestBody, JarPlanMessageParameters> request,
		@Nonnull final RestfulGateway gateway) throws RestHandlerException {
	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);

	return CompletableFuture.supplyAsync(() -> {
		final JobGraph jobGraph = context.toJobGraph(configuration);
		return planGenerator.apply(jobGraph);
	}, executor);
}
 
Example #3
Source File: JarRunHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JarRunResponseBody> handleRequest(
		@Nonnull final HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request,
		@Nonnull final DispatcherGateway gateway) throws RestHandlerException {
	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);

	final SavepointRestoreSettings savepointRestoreSettings = getSavepointRestoreSettings(request);

	final CompletableFuture<JobGraph> jobGraphFuture = getJobGraphAsync(context, savepointRestoreSettings);

	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	CompletableFuture<JobGraph> jarUploadFuture = jobGraphFuture.thenCombine(blobServerPortFuture, (jobGraph, blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(e);
		}

		return jobGraph;
	});

	CompletableFuture<Acknowledge> jobSubmissionFuture = jarUploadFuture.thenCompose(jobGraph -> {
		// we have to enable queued scheduling because slots will be allocated lazily
		jobGraph.setAllowQueuedScheduling(true);
		return gateway.submitJob(jobGraph, timeout);
	});

	return jobSubmissionFuture
		.thenCombine(jarUploadFuture, (ack, jobGraph) -> new JarRunResponseBody(jobGraph.getJobID()));
}
 
Example #4
Source File: JarRunHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<JobGraph> getJobGraphAsync(
		JarHandlerContext context,
		final SavepointRestoreSettings savepointRestoreSettings) {
	return CompletableFuture.supplyAsync(() -> {
		final JobGraph jobGraph = context.toJobGraph(configuration);
		jobGraph.setSavepointRestoreSettings(savepointRestoreSettings);
		return jobGraph;
	}, executor);
}
 
Example #5
Source File: JarPlanHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JobPlanInfo> handleRequest(
		@Nonnull final HandlerRequest<JarPlanRequestBody, JarPlanMessageParameters> request,
		@Nonnull final RestfulGateway gateway) throws RestHandlerException {
	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);

	return CompletableFuture.supplyAsync(() -> {
		final JobGraph jobGraph = context.toJobGraph(configuration);
		return planGenerator.apply(jobGraph);
	}, executor);
}
 
Example #6
Source File: JarRunHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JarRunResponseBody> handleRequest(
		@Nonnull final HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request,
		@Nonnull final DispatcherGateway gateway) throws RestHandlerException {
	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);

	final SavepointRestoreSettings savepointRestoreSettings = getSavepointRestoreSettings(request);

	final CompletableFuture<JobGraph> jobGraphFuture = getJobGraphAsync(context, savepointRestoreSettings);

	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	CompletableFuture<JobGraph> jarUploadFuture = jobGraphFuture.thenCombine(blobServerPortFuture, (jobGraph, blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(e);
		}

		return jobGraph;
	});

	CompletableFuture<Acknowledge> jobSubmissionFuture = jarUploadFuture.thenCompose(jobGraph -> {
		// we have to enable queued scheduling because slots will be allocated lazily
		jobGraph.setAllowQueuedScheduling(true);
		return gateway.submitJob(jobGraph, timeout);
	});

	return jobSubmissionFuture
		.thenCombine(jarUploadFuture, (ack, jobGraph) -> new JarRunResponseBody(jobGraph.getJobID()));
}
 
Example #7
Source File: JarRunHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<JobGraph> getJobGraphAsync(
		JarHandlerContext context,
		final SavepointRestoreSettings savepointRestoreSettings) {
	return CompletableFuture.supplyAsync(() -> {
		final JobGraph jobGraph = context.toJobGraph(configuration);
		jobGraph.setSavepointRestoreSettings(savepointRestoreSettings);
		return jobGraph;
	}, executor);
}
 
Example #8
Source File: JarPlanHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JobPlanInfo> handleRequest(
		@Nonnull final HandlerRequest<JarPlanRequestBody, JarPlanMessageParameters> request,
		@Nonnull final RestfulGateway gateway) throws RestHandlerException {
	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);

	return CompletableFuture.supplyAsync(() -> {
		final JobGraph jobGraph = context.toJobGraph(configuration, true);
		return planGenerator.apply(jobGraph);
	}, executor);
}