Java Code Examples for org.apache.flink.client.ClientUtils#executeProgram()

The following examples show how to use org.apache.flink.client.ClientUtils#executeProgram() . 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: DetachedApplicationRunner.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<JobID> tryExecuteJobs(final DispatcherGateway dispatcherGateway, final PackagedProgram program, final Configuration configuration) {
	configuration.set(DeploymentOptions.ATTACHED, false);

	final List<JobID> applicationJobIds = new ArrayList<>();
	final PipelineExecutorServiceLoader executorServiceLoader =
			new WebSubmissionExecutorServiceLoader(applicationJobIds, dispatcherGateway);

	try {
		ClientUtils.executeProgram(executorServiceLoader, configuration, program, enforceSingleJobExecution, true);
	} catch (ProgramInvocationException e) {
		LOG.warn("Could not execute application: ", e);
		throw new FlinkRuntimeException("Could not execute application.", e);
	}

	return applicationJobIds;
}
 
Example 2
Source File: ClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void launchMultiExecuteJob(final boolean enforceSingleJobExecution) throws ProgramInvocationException {
	try (final ClusterClient<?> clusterClient =
				new MiniClusterClient(new Configuration(), MINI_CLUSTER_RESOURCE.getMiniCluster())) {

		final PackagedProgram program = PackagedProgram.newBuilder()
				.setEntryPointClassName(TestMultiExecute.class.getName())
				.build();

		final Configuration configuration = fromPackagedProgram(program, 1, false);

		ClientUtils.executeProgram(
				new TestExecutorServiceLoader(clusterClient, plan),
				configuration,
				program,
				enforceSingleJobExecution,
				false);
	}
}
 
Example 3
Source File: ClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This test verifies that the local execution environment cannot be created when
 * the program is submitted through a client.
 */
@Test
public void tryLocalExecution() throws ProgramInvocationException, ProgramMissingJobException {
	PackagedProgram packagedProgramMock = mock(PackagedProgram.class);

	when(packagedProgramMock.getUserCodeClassLoader())
			.thenReturn(packagedProgramMock.getClass().getClassLoader());

	doAnswer(new Answer<Void>() {
		@Override
		public Void answer(InvocationOnMock invocation) throws Throwable {
			ExecutionEnvironment.createLocalEnvironment();
			return null;
		}
	}).when(packagedProgramMock).invokeInteractiveModeForExecution();

	try {
		final ClusterClient<?> client = new MiniClusterClient(new Configuration(), MINI_CLUSTER_RESOURCE.getMiniCluster());
		final Configuration configuration = fromPackagedProgram(packagedProgramMock, 1, true);
		ClientUtils.executeProgram(new TestExecutorServiceLoader(client, plan), configuration, packagedProgramMock, false, false);
		fail("Creating the local execution environment should not be possible");
	}
	catch (InvalidProgramException e) {
		// that is what we want
	}
}
 
Example 4
Source File: ApplicationDispatcherBootstrap.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Runs the user program entrypoint and completes the given {@code jobIdsFuture} with the {@link
 * JobID JobIDs} of the submitted jobs.
 *
 * <p>This should be executed in a separate thread (or task).
 */
private void runApplicationEntryPoint(
		final CompletableFuture<List<JobID>> jobIdsFuture,
		final DispatcherGateway dispatcher,
		final ScheduledExecutor scheduledExecutor,
		final boolean enforceSingleJobExecution) {
	try {
		final List<JobID> applicationJobIds =
				new ArrayList<>(getRecoveredJobIds(recoveredJobs));

		final PipelineExecutorServiceLoader executorServiceLoader =
				new EmbeddedExecutorServiceLoader(
						applicationJobIds, dispatcher, scheduledExecutor);

		ClientUtils.executeProgram(
				executorServiceLoader,
				configuration,
				application,
				enforceSingleJobExecution,
				true /* suppress sysout */);

		if (applicationJobIds.isEmpty()) {
			jobIdsFuture.completeExceptionally(
					new ApplicationExecutionException(
							"The application contains no execute() calls."));
		} else {
			jobIdsFuture.complete(applicationJobIds);
		}
	} catch (Throwable t) {
		jobIdsFuture.completeExceptionally(
				new ApplicationExecutionException("Could not execute application.", t));
	}
}
 
Example 5
Source File: CliFrontend.java    From flink with Apache License 2.0 4 votes vote down vote up
protected void executeProgram(final Configuration configuration, final PackagedProgram program) throws ProgramInvocationException {
	ClientUtils.executeProgram(new DefaultExecutorServiceLoader(), configuration, program, false, false);
}