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

The following examples show how to use org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody. 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 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull final HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
		@Nonnull final RestfulGateway gateway) throws RestHandlerException {

	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);

	final CompletableFuture<JobStatus> jobStatusFuture = gateway.requestJobStatus(jobId, timeout);

	return jobStatusFuture.thenCompose(
		jobStatus -> {
			if (jobStatus.isGloballyTerminalState()) {
				return gateway
					.requestJobResult(jobId, timeout)
					.thenApply(JobExecutionResultResponseBody::created);
			} else {
				return CompletableFuture.completedFuture(
					JobExecutionResultResponseBody.inProgress());
			}
		}).exceptionally(throwable -> {
			throw propagateException(throwable);
		});
}
 
Example #2
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	if (jobExecutionResults.hasNext()) {
		lastJobExecutionResult = jobExecutionResults.next();
	}
	checkState(lastJobExecutionResult != null);
	if (lastJobExecutionResult instanceof JobExecutionResultResponseBody) {
		return CompletableFuture.completedFuture((JobExecutionResultResponseBody) lastJobExecutionResult);
	} else if (lastJobExecutionResult instanceof RestHandlerException) {
		return FutureUtils.completedExceptionally((RestHandlerException) lastJobExecutionResult);
	} else {
		throw new AssertionError();
	}
}
 
Example #3
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	if (jobExecutionResults.hasNext()) {
		lastJobExecutionResult = jobExecutionResults.next();
	}
	checkState(lastJobExecutionResult != null);
	if (lastJobExecutionResult instanceof JobExecutionResultResponseBody) {
		return CompletableFuture.completedFuture((JobExecutionResultResponseBody) lastJobExecutionResult);
	} else if (lastJobExecutionResult instanceof RestHandlerException) {
		return FutureUtils.completedExceptionally((RestHandlerException) lastJobExecutionResult);
	} else {
		throw new AssertionError();
	}
}
 
Example #4
Source File: JobExecutionResultHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull final HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
		@Nonnull final RestfulGateway gateway) throws RestHandlerException {

	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);

	final CompletableFuture<JobStatus> jobStatusFuture = gateway.requestJobStatus(jobId, timeout);

	return jobStatusFuture.thenCompose(
		jobStatus -> {
			if (jobStatus.isGloballyTerminalState()) {
				return gateway
					.requestJobResult(jobId, timeout)
					.thenApply(JobExecutionResultResponseBody::created);
			} else {
				return CompletableFuture.completedFuture(
					JobExecutionResultResponseBody.inProgress());
			}
		}).exceptionally(throwable -> {
			throw propagateException(throwable);
		});
}
 
Example #5
Source File: JobExecutionResultHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull final HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
		@Nonnull final RestfulGateway gateway) throws RestHandlerException {

	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);

	final CompletableFuture<JobStatus> jobStatusFuture = gateway.requestJobStatus(jobId, timeout);

	return jobStatusFuture.thenCompose(
		jobStatus -> {
			if (jobStatus.isGloballyTerminalState()) {
				return gateway
					.requestJobResult(jobId, timeout)
					.thenApply(JobExecutionResultResponseBody::created);
			} else {
				return CompletableFuture.completedFuture(
					JobExecutionResultResponseBody.inProgress());
			}
		}).exceptionally(throwable -> {
			throw propagateException(throwable);
		});
}
 
Example #6
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	if (jobExecutionResults.hasNext()) {
		lastJobExecutionResult = jobExecutionResults.next();
	}
	checkState(lastJobExecutionResult != null);
	if (lastJobExecutionResult instanceof JobExecutionResultResponseBody) {
		return CompletableFuture.completedFuture((JobExecutionResultResponseBody) lastJobExecutionResult);
	} else if (lastJobExecutionResult instanceof RestHandlerException) {
		return FutureUtils.completedExceptionally((RestHandlerException) lastJobExecutionResult);
	} else {
		throw new AssertionError();
	}
}
 
Example #7
Source File: JobExecutionResultHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testResultInProgress() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder()
		.setRequestJobStatusFunction(
			jobId -> CompletableFuture.completedFuture(JobStatus.RUNNING))
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.IN_PROGRESS));
}
 
Example #8
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 #9
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobSubmitCancel() throws Exception {
	TestJobSubmitHandler submitHandler = new TestJobSubmitHandler();
	TestJobCancellationHandler terminationHandler = new TestJobCancellationHandler();
	TestJobExecutionResultHandler testJobExecutionResultHandler =
		new TestJobExecutionResultHandler(
			JobExecutionResultResponseBody.created(new JobResult.Builder()
				.applicationStatus(ApplicationStatus.SUCCEEDED)
				.jobId(jobId)
				.netRuntime(Long.MAX_VALUE)
				.build()));

	try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(
		submitHandler,
		terminationHandler,
		testJobExecutionResultHandler)) {

		try (RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort())) {
			Assert.assertFalse(submitHandler.jobSubmitted);
			ClientUtils.submitJobAndWaitForResult(restClusterClient, jobGraph, ClassLoader.getSystemClassLoader());
			Assert.assertTrue(submitHandler.jobSubmitted);

			Assert.assertFalse(terminationHandler.jobCanceled);
			restClusterClient.cancel(jobId).get();
			Assert.assertTrue(terminationHandler.jobCanceled);
		}
	}
}
 
Example #10
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompletedResult() throws Exception {
	final JobStatus jobStatus = JobStatus.FINISHED;
	final ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder()
		.setJobID(TEST_JOB_ID)
		.setState(jobStatus)
		.build();

	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setRequestJobStatusFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(jobStatus);
			})
		.setRequestJobResultFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(JobResult.createFrom(executionGraph));
			}
		)
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(responseBody.getJobExecutionResult(), not(nullValue()));
}
 
Example #11
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testResultInProgress() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setRequestJobStatusFunction(
			jobId -> CompletableFuture.completedFuture(JobStatus.RUNNING))
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.IN_PROGRESS));
}
 
Example #12
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 #13
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobSubmitCancel() throws Exception {
	TestJobSubmitHandler submitHandler = new TestJobSubmitHandler();
	TestJobCancellationHandler terminationHandler = new TestJobCancellationHandler();
	TestJobExecutionResultHandler testJobExecutionResultHandler =
		new TestJobExecutionResultHandler(
			JobExecutionResultResponseBody.created(new JobResult.Builder()
				.applicationStatus(ApplicationStatus.SUCCEEDED)
				.jobId(jobId)
				.netRuntime(Long.MAX_VALUE)
				.build()));

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

		try {
			Assert.assertFalse(submitHandler.jobSubmitted);
			restClusterClient.submitJob(jobGraph, ClassLoader.getSystemClassLoader());
			Assert.assertTrue(submitHandler.jobSubmitted);

			Assert.assertFalse(terminationHandler.jobCanceled);
			restClusterClient.cancel(jobId);
			Assert.assertTrue(terminationHandler.jobCanceled);
		} finally {
			restClusterClient.shutdown();
		}
	}
}
 
Example #14
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompletedResult() throws Exception {
	final JobStatus jobStatus = JobStatus.FINISHED;
	final ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder()
		.setJobID(TEST_JOB_ID)
		.setState(jobStatus)
		.build();

	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder()
		.setRequestJobStatusFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(jobStatus);
			})
		.setRequestJobResultFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(JobResult.createFrom(executionGraph));
			}
		)
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(responseBody.getJobExecutionResult(), not(nullValue()));
}
 
Example #15
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testResultInProgress() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder()
		.setRequestJobStatusFunction(
			jobId -> CompletableFuture.completedFuture(JobStatus.RUNNING))
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.IN_PROGRESS));
}
 
Example #16
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 #17
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobSubmitCancelStop() throws Exception {
	TestJobSubmitHandler submitHandler = new TestJobSubmitHandler();
	TestJobTerminationHandler terminationHandler = new TestJobTerminationHandler();
	TestJobExecutionResultHandler testJobExecutionResultHandler =
		new TestJobExecutionResultHandler(
			JobExecutionResultResponseBody.created(new JobResult.Builder()
				.applicationStatus(ApplicationStatus.SUCCEEDED)
				.jobId(jobId)
				.netRuntime(Long.MAX_VALUE)
				.build()));

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

		try {
			Assert.assertFalse(submitHandler.jobSubmitted);
			restClusterClient.submitJob(jobGraph, ClassLoader.getSystemClassLoader());
			Assert.assertTrue(submitHandler.jobSubmitted);

			Assert.assertFalse(terminationHandler.jobCanceled);
			restClusterClient.cancel(jobId);
			Assert.assertTrue(terminationHandler.jobCanceled);

			Assert.assertFalse(terminationHandler.jobStopped);
			restClusterClient.stop(jobId);
			Assert.assertTrue(terminationHandler.jobStopped);
		} finally {
			restClusterClient.shutdown();
		}
	}
}
 
Example #18
Source File: JobExecutionResultHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompletedResult() throws Exception {
	final JobStatus jobStatus = JobStatus.FINISHED;
	final ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder()
		.setJobID(TEST_JOB_ID)
		.setState(jobStatus)
		.build();

	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder()
		.setRequestJobStatusFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(jobStatus);
			})
		.setRequestJobResultFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(JobResult.createFrom(executionGraph));
			}
		)
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(responseBody.getJobExecutionResult(), not(nullValue()));
}
 
Example #19
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();
		}
	}
}