Search in sources :

Example 1 with JobExecutionResultHeaders

use of org.apache.flink.runtime.rest.messages.job.JobExecutionResultHeaders in project flink by apache.

the class RestClusterClientTest method testSubmitJobAndWaitForExecutionResult.

@Test
public void testSubmitJobAndWaitForExecutionResult() throws Exception {
    final TestJobExecutionResultHandler testJobExecutionResultHandler = new TestJobExecutionResultHandler(new RestHandlerException("should trigger retry", HttpResponseStatus.SERVICE_UNAVAILABLE), JobExecutionResultResponseBody.inProgress(), // On an UNKNOWN JobResult it should be retried
    JobExecutionResultResponseBody.created(new JobResult.Builder().applicationStatus(ApplicationStatus.UNKNOWN).jobId(jobId).netRuntime(Long.MAX_VALUE).accumulatorResults(Collections.singletonMap("testName", new SerializedValue<>(OptionalFailure.of(1.0)))).build()), 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 the first JobExecutionResult HTTP polling attempt, which should not be a problem
    // because of the retries.
    final AtomicBoolean firstExecutionResultPollFailed = new AtomicBoolean(false);
    // Fail the first JobSubmit HTTP request, which should not be a problem because of the
    // retries.
    final AtomicBoolean firstSubmitRequestFailed = new AtomicBoolean(false);
    failHttpRequest = (messageHeaders, messageParameters, requestBody) -> {
        if (messageHeaders instanceof JobExecutionResultHeaders) {
            return !firstExecutionResultPollFailed.getAndSet(true);
        }
        if (messageHeaders instanceof JobSubmitHeaders) {
            return !firstSubmitRequestFailed.getAndSet(true);
        }
        return false;
    };
    try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(testJobExecutionResultHandler, new TestJobSubmitHandler())) {
        try (RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort())) {
            final JobExecutionResult jobExecutionResult = restClusterClient.submitJob(jobGraph).thenCompose(restClusterClient::requestJobResult).get().toJobExecutionResult(ClassLoader.getSystemClassLoader());
            assertTrue(firstExecutionResultPollFailed.get());
            assertTrue(firstSubmitRequestFailed.get());
            assertThat(jobExecutionResult.getJobID(), equalTo(jobId));
            assertThat(jobExecutionResult.getNetRuntime(), equalTo(Long.MAX_VALUE));
            assertThat(jobExecutionResult.getAllAccumulatorResults(), equalTo(Collections.singletonMap("testName", 1.0)));
            try {
                restClusterClient.submitJob(jobGraph).thenCompose(restClusterClient::requestJobResult).get().toJobExecutionResult(ClassLoader.getSystemClassLoader());
                fail("Expected exception not thrown.");
            } catch (final Exception e) {
                final Optional<RuntimeException> cause = ExceptionUtils.findThrowable(e, RuntimeException.class);
                assertThat(cause.isPresent(), is(true));
                assertThat(cause.get().getMessage(), equalTo("expected"));
            }
        }
    }
}
Also used : Optional(java.util.Optional) JobResult(org.apache.flink.runtime.jobmaster.JobResult) JobExecutionResultHeaders(org.apache.flink.runtime.rest.messages.job.JobExecutionResultHeaders) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) FlinkException(org.apache.flink.util.FlinkException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RestClientException(org.apache.flink.runtime.rest.util.RestClientException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) ConfigurationException(org.apache.flink.util.ConfigurationException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) JobSubmitHeaders(org.apache.flink.runtime.rest.messages.job.JobSubmitHeaders) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)1 JobResult (org.apache.flink.runtime.jobmaster.JobResult)1 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)1 JobExecutionResultHeaders (org.apache.flink.runtime.rest.messages.job.JobExecutionResultHeaders)1 JobSubmitHeaders (org.apache.flink.runtime.rest.messages.job.JobSubmitHeaders)1 RestClientException (org.apache.flink.runtime.rest.util.RestClientException)1 TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)1 ConfigurationException (org.apache.flink.util.ConfigurationException)1 FlinkException (org.apache.flink.util.FlinkException)1 SerializedThrowable (org.apache.flink.util.SerializedThrowable)1 Test (org.junit.Test)1