Search in sources :

Example 46 with JobResult

use of org.apache.flink.runtime.jobmaster.JobResult in project flink by apache.

the class MiniCluster method executeJobBlocking.

/**
 * This method runs a job in blocking mode. The method returns only after the job completed
 * successfully, or after it failed terminally.
 *
 * @param job The Flink job to execute
 * @return The result of the job execution
 * @throws JobExecutionException Thrown if anything went amiss during initial job launch, or if
 *     the job terminally failed.
 */
public JobExecutionResult executeJobBlocking(JobGraph job) throws JobExecutionException, InterruptedException {
    checkNotNull(job, "job is null");
    final CompletableFuture<JobSubmissionResult> submissionFuture = submitJob(job);
    final CompletableFuture<JobResult> jobResultFuture = submissionFuture.thenCompose((JobSubmissionResult ignored) -> requestJobResult(job.getJobID()));
    final JobResult jobResult;
    try {
        jobResult = jobResultFuture.get();
    } catch (ExecutionException e) {
        throw new JobExecutionException(job.getJobID(), "Could not retrieve JobResult.", ExceptionUtils.stripExecutionException(e));
    }
    try {
        return jobResult.toJobExecutionResult(Thread.currentThread().getContextClassLoader());
    } catch (IOException | ClassNotFoundException e) {
        throw new JobExecutionException(job.getJobID(), e);
    }
}
Also used : JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) JobResult(org.apache.flink.runtime.jobmaster.JobResult) IOException(java.io.IOException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 47 with JobResult

use of org.apache.flink.runtime.jobmaster.JobResult in project flink by apache.

the class MiniClusterITCase method testCallFinalizeOnMasterBeforeJobCompletes.

@Test
public void testCallFinalizeOnMasterBeforeJobCompletes() throws Exception {
    final int parallelism = 11;
    final MiniClusterConfiguration cfg = new MiniClusterConfiguration.Builder().setNumTaskManagers(1).setNumSlotsPerTaskManager(2 * parallelism).setConfiguration(getDefaultConfiguration()).build();
    try (final MiniCluster miniCluster = new MiniCluster(cfg)) {
        miniCluster.start();
        final JobVertex source = new JobVertex("Source");
        source.setInvokableClass(WaitingNoOpInvokable.class);
        source.setParallelism(parallelism);
        WaitOnFinalizeJobVertex.resetFinalizedOnMaster();
        final WaitOnFinalizeJobVertex sink = new WaitOnFinalizeJobVertex("Sink", 20L);
        sink.setInvokableClass(NoOpInvokable.class);
        sink.setParallelism(parallelism);
        sink.connectNewDataSetAsInput(source, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
        final JobGraph jobGraph = JobGraphTestUtils.streamingJobGraph(source, sink);
        final CompletableFuture<JobSubmissionResult> submissionFuture = miniCluster.submitJob(jobGraph);
        final CompletableFuture<JobResult> jobResultFuture = submissionFuture.thenCompose((JobSubmissionResult ignored) -> miniCluster.requestJobResult(jobGraph.getJobID()));
        jobResultFuture.get().toJobExecutionResult(getClass().getClassLoader());
        assertTrue(WaitOnFinalizeJobVertex.finalizedOnMaster.get());
    }
}
Also used : JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) JobResult(org.apache.flink.runtime.jobmaster.JobResult) Test(org.junit.Test)

Example 48 with JobResult

use of org.apache.flink.runtime.jobmaster.JobResult in project flink by apache.

the class MiniClusterITCase method testOutOfMemoryErrorMessageEnrichmentInJobVertexInitialization.

@Test
public void testOutOfMemoryErrorMessageEnrichmentInJobVertexInitialization() throws Exception {
    final int parallelism = 1;
    final MiniClusterConfiguration cfg = new MiniClusterConfiguration.Builder().setNumTaskManagers(1).setNumSlotsPerTaskManager(parallelism).setConfiguration(getDefaultConfiguration()).build();
    try (final MiniCluster miniCluster = new MiniCluster(cfg)) {
        miniCluster.start();
        final JobVertex failingJobVertex = new OutOfMemoryInInitializationVertex();
        failingJobVertex.setInvokableClass(NoOpInvokable.class);
        failingJobVertex.setParallelism(parallelism);
        final JobGraph jobGraph = JobGraphTestUtils.streamingJobGraph(failingJobVertex);
        final CompletableFuture<JobSubmissionResult> submissionFuture = miniCluster.submitJob(jobGraph);
        final CompletableFuture<JobResult> jobResultFuture = submissionFuture.thenCompose((JobSubmissionResult ignored) -> miniCluster.requestJobResult(jobGraph.getJobID()));
        try {
            jobResultFuture.get();
        } catch (ExecutionException e) {
            assertThat(e, FlinkMatchers.containsCause(OutOfMemoryError.class));
            assertThat(e, FlinkMatchers.containsMessage("Java heap space. A heap space-related out-of-memory error has occurred."));
        }
    }
}
Also used : JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) JobResult(org.apache.flink.runtime.jobmaster.JobResult) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 49 with JobResult

use of org.apache.flink.runtime.jobmaster.JobResult in project flink by apache.

the class JobResultDeserializer method deserialize.

@Override
public JobResult deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
    JobID jobId = null;
    ApplicationStatus applicationStatus = ApplicationStatus.UNKNOWN;
    long netRuntime = -1;
    SerializedThrowable serializedThrowable = null;
    Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = null;
    while (true) {
        final JsonToken jsonToken = p.nextToken();
        assertNotEndOfInput(p, jsonToken);
        if (jsonToken == JsonToken.END_OBJECT) {
            break;
        }
        final String fieldName = p.getValueAsString();
        switch(fieldName) {
            case JobResultSerializer.FIELD_NAME_JOB_ID:
                assertNextToken(p, JsonToken.VALUE_STRING);
                jobId = jobIdDeserializer.deserialize(p, ctxt);
                break;
            case JobResultSerializer.FIELD_NAME_APPLICATION_STATUS:
                assertNextToken(p, JsonToken.VALUE_STRING);
                applicationStatus = ApplicationStatus.valueOf(p.getValueAsString().toUpperCase());
                break;
            case JobResultSerializer.FIELD_NAME_NET_RUNTIME:
                assertNextToken(p, JsonToken.VALUE_NUMBER_INT);
                netRuntime = p.getLongValue();
                break;
            case JobResultSerializer.FIELD_NAME_ACCUMULATOR_RESULTS:
                assertNextToken(p, JsonToken.START_OBJECT);
                accumulatorResults = parseAccumulatorResults(p, ctxt);
                break;
            case JobResultSerializer.FIELD_NAME_FAILURE_CAUSE:
                assertNextToken(p, JsonToken.START_OBJECT);
                serializedThrowable = serializedThrowableDeserializer.deserialize(p, ctxt);
                break;
            default:
        }
    }
    try {
        return new JobResult.Builder().jobId(jobId).applicationStatus(applicationStatus).netRuntime(netRuntime).accumulatorResults(accumulatorResults).serializedThrowable(serializedThrowable).build();
    } catch (final RuntimeException e) {
        throw new JsonMappingException(null, "Could not deserialize " + JobResult.class.getSimpleName(), e);
    }
}
Also used : JobResult(org.apache.flink.runtime.jobmaster.JobResult) SerializedValue(org.apache.flink.util.SerializedValue) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) JsonMappingException(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException) JsonToken(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken) JobID(org.apache.flink.api.common.JobID) SerializedThrowable(org.apache.flink.util.SerializedThrowable)

Example 50 with JobResult

use of org.apache.flink.runtime.jobmaster.JobResult 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

JobResult (org.apache.flink.runtime.jobmaster.JobResult)58 Test (org.junit.Test)28 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)25 JobID (org.apache.flink.api.common.JobID)15 Test (org.junit.jupiter.api.Test)13 MiniCluster (org.apache.flink.runtime.minicluster.MiniCluster)11 ExecutionException (java.util.concurrent.ExecutionException)8 JobSubmissionResult (org.apache.flink.api.common.JobSubmissionResult)7 Deadline (org.apache.flink.api.common.time.Deadline)7 Configuration (org.apache.flink.configuration.Configuration)7 File (java.io.File)5 JobResultStore (org.apache.flink.runtime.highavailability.JobResultStore)5 IOException (java.io.IOException)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)4 Duration (java.time.Duration)3 List (java.util.List)3 Time (org.apache.flink.api.common.time.Time)3 MiniClusterClient (org.apache.flink.client.program.MiniClusterClient)3