org.apache.flink.runtime.rest.messages.job.JobExecutionResultHeaders Java Examples

The following examples show how to use org.apache.flink.runtime.rest.messages.job.JobExecutionResultHeaders. 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: JobExecutionResultHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public JobExecutionResultHandler(
		final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		final Time timeout,
		final Map<String, String> responseHeaders) {
	super(
		leaderRetriever,
		timeout,
		responseHeaders,
		JobExecutionResultHeaders.getInstance());
}
 
Example #2
Source File: RestClusterClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Requests the {@link JobResult} for the given {@link JobID}. The method retries multiple
 * times to poll the {@link JobResult} before giving up.
 *
 * @param jobId specifying the job for which to retrieve the {@link JobResult}
 * @return Future which is completed with the {@link JobResult} once the job has completed or
 * with a failure if the {@link JobResult} could not be retrieved.
 */
@Override
public CompletableFuture<JobResult> requestJobResult(@Nonnull JobID jobId) {
	return pollResourceAsync(
		() -> {
			final JobMessageParameters messageParameters = new JobMessageParameters();
			messageParameters.jobPathParameter.resolve(jobId);
			return sendRequest(
				JobExecutionResultHeaders.getInstance(),
				messageParameters);
		});
}
 
Example #3
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private TestJobExecutionResultHandler(
		final Object... jobExecutionResults) {
	super(JobExecutionResultHeaders.getInstance());
	checkArgument(Arrays.stream(jobExecutionResults)
		.allMatch(object -> object instanceof JobExecutionResultResponseBody
			|| object instanceof RestHandlerException));
	this.jobExecutionResults = Arrays.asList(jobExecutionResults).iterator();
}
 
Example #4
Source File: JobExecutionResultHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public JobExecutionResultHandler(
		final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		final Time timeout,
		final Map<String, String> responseHeaders) {
	super(
		leaderRetriever,
		timeout,
		responseHeaders,
		JobExecutionResultHeaders.getInstance());
}
 
Example #5
Source File: RestClusterClient.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Requests the {@link JobResult} for the given {@link JobID}. The method retries multiple
 * times to poll the {@link JobResult} before giving up.
 *
 * @param jobId specifying the job for which to retrieve the {@link JobResult}
 * @return Future which is completed with the {@link JobResult} once the job has completed or
 * with a failure if the {@link JobResult} could not be retrieved.
 */
@Override
public CompletableFuture<JobResult> requestJobResult(@Nonnull JobID jobId) {
	return pollResourceAsync(
		() -> {
			final JobMessageParameters messageParameters = new JobMessageParameters();
			messageParameters.jobPathParameter.resolve(jobId);
			return sendRequest(
				JobExecutionResultHeaders.getInstance(),
				messageParameters);
		});
}
 
Example #6
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private TestJobExecutionResultHandler(
		final Object... jobExecutionResults) {
	super(JobExecutionResultHeaders.getInstance());
	checkArgument(Arrays.stream(jobExecutionResults)
		.allMatch(object -> object instanceof JobExecutionResultResponseBody
			|| object instanceof RestHandlerException));
	this.jobExecutionResults = Arrays.asList(jobExecutionResults).iterator();
}
 
Example #7
Source File: JobExecutionResultHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public JobExecutionResultHandler(
		final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		final Time timeout,
		final Map<String, String> responseHeaders) {
	super(
		leaderRetriever,
		timeout,
		responseHeaders,
		JobExecutionResultHeaders.getInstance());
}
 
Example #8
Source File: RestClusterClient.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Requests the {@link JobResult} for the given {@link JobID}. The method retries multiple
 * times to poll the {@link JobResult} before giving up.
 *
 * @param jobId specifying the job for which to retrieve the {@link JobResult}
 * @return Future which is completed with the {@link JobResult} once the job has completed or
 * with a failure if the {@link JobResult} could not be retrieved.
 */
@Override
public CompletableFuture<JobResult> requestJobResult(@Nonnull JobID jobId) {
	return pollResourceAsync(
		() -> {
			final JobMessageParameters messageParameters = new JobMessageParameters();
			messageParameters.jobPathParameter.resolve(jobId);
			return sendRequest(
				JobExecutionResultHeaders.getInstance(),
				messageParameters);
		});
}
 
Example #9
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private TestJobExecutionResultHandler(
		final Object... jobExecutionResults) {
	super(JobExecutionResultHeaders.getInstance());
	checkArgument(Arrays.stream(jobExecutionResults)
		.allMatch(object -> object instanceof JobExecutionResultResponseBody
			|| object instanceof RestHandlerException));
	this.jobExecutionResults = Arrays.asList(jobExecutionResults).iterator();
}
 
Example #10
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testSubmitJobAndWaitForExecutionResult() throws Exception {
	final TestJobExecutionResultHandler testJobExecutionResultHandler =
		new TestJobExecutionResultHandler(
			new RestHandlerException("should trigger retry", HttpResponseStatus.SERVICE_UNAVAILABLE),
			JobExecutionResultResponseBody.inProgress(),
			JobExecutionResultResponseBody.created(new JobResult.Builder()
				.applicationStatus(ApplicationStatus.SUCCEEDED)
				.jobId(jobId)
				.netRuntime(Long.MAX_VALUE)
				.accumulatorResults(Collections.singletonMap("testName", new SerializedValue<>(OptionalFailure.of(1.0))))
				.build()),
			JobExecutionResultResponseBody.created(new JobResult.Builder()
				.applicationStatus(ApplicationStatus.FAILED)
				.jobId(jobId)
				.netRuntime(Long.MAX_VALUE)
				.serializedThrowable(new SerializedThrowable(new RuntimeException("expected")))
				.build()));

	// fail first HTTP polling attempt, which should not be a problem because of the retries
	final AtomicBoolean firstPollFailed = new AtomicBoolean();
	failHttpRequest = (messageHeaders, messageParameters, requestBody) ->
		messageHeaders instanceof JobExecutionResultHeaders && !firstPollFailed.getAndSet(true);

	try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(
		testJobExecutionResultHandler,
		new TestJobSubmitHandler())) {
		RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());

		try {
			JobExecutionResult jobExecutionResult;

			jobExecutionResult = ClientUtils.submitJobAndWaitForResult(restClusterClient, jobGraph, ClassLoader.getSystemClassLoader());
			assertThat(jobExecutionResult.getJobID(), equalTo(jobId));
			assertThat(jobExecutionResult.getNetRuntime(), equalTo(Long.MAX_VALUE));
			assertThat(
				jobExecutionResult.getAllAccumulatorResults(),
				equalTo(Collections.singletonMap("testName", 1.0)));

			try {
				ClientUtils.submitJobAndWaitForResult(restClusterClient, jobGraph, ClassLoader.getSystemClassLoader());
				fail("Expected exception not thrown.");
			} catch (final ProgramInvocationException e) {
				final Optional<RuntimeException> cause = ExceptionUtils.findThrowable(e, RuntimeException.class);

				assertThat(cause.isPresent(), is(true));
				assertThat(cause.get().getMessage(), equalTo("expected"));
			}
		} finally {
			restClusterClient.close();
		}
	}
}