Search in sources :

Example 6 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class SavepointWriterITCase method validateModification.

private void validateModification(StateBackend backend, String savepointPath) throws Exception {
    StreamExecutionEnvironment sEnv = StreamExecutionEnvironment.getExecutionEnvironment();
    if (backend != null) {
        sEnv.setStateBackend(backend);
    }
    DataStream<Account> stream = sEnv.fromCollection(accounts).keyBy(acc -> acc.id).flatMap(new UpdateAndGetAccount()).uid(ACCOUNT_UID);
    CompletableFuture<Collection<Account>> results = collector.collect(stream);
    stream.map(acc -> acc.id).map(new StatefulOperator()).uid(MODIFY_UID).addSink(new DiscardingSink<>());
    JobGraph jobGraph = sEnv.getStreamGraph().getJobGraph();
    jobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(savepointPath, false));
    ClusterClient<?> client = MINI_CLUSTER_RESOURCE.getClusterClient();
    Optional<SerializedThrowable> serializedThrowable = client.submitJob(jobGraph).thenCompose(client::requestJobResult).get().getSerializedThrowable();
    Assert.assertFalse(serializedThrowable.isPresent());
    Assert.assertEquals("Unexpected output", 3, results.get().size());
}
Also used : RichFlatMapFunction(org.apache.flink.api.common.functions.RichFlatMapFunction) Arrays(java.util.Arrays) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CompletableFuture(java.util.concurrent.CompletableFuture) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) EmbeddedRocksDBStateBackend(org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend) ArrayList(java.util.ArrayList) StateBootstrapFunction(org.apache.flink.state.api.functions.StateBootstrapFunction) HashSet(java.util.HashSet) ListState(org.apache.flink.api.common.state.ListState) StateBackend(org.apache.flink.runtime.state.StateBackend) StreamCollector(org.apache.flink.streaming.util.StreamCollector) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction) Collector(org.apache.flink.util.Collector) KeyedStateBootstrapFunction(org.apache.flink.state.api.functions.KeyedStateBootstrapFunction) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) AbstractTestBase(org.apache.flink.test.util.AbstractTestBase) Types(org.apache.flink.api.common.typeinfo.Types) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) DiscardingSink(org.apache.flink.streaming.api.functions.sink.DiscardingSink) AbstractID(org.apache.flink.util.AbstractID) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) Collection(java.util.Collection) Configuration(org.apache.flink.configuration.Configuration) Set(java.util.Set) Test(org.junit.Test) DataStream(org.apache.flink.streaming.api.datastream.DataStream) Objects(java.util.Objects) List(java.util.List) Rule(org.junit.Rule) ValueState(org.apache.flink.api.common.state.ValueState) ClusterClient(org.apache.flink.client.program.ClusterClient) BroadcastProcessFunction(org.apache.flink.streaming.api.functions.co.BroadcastProcessFunction) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) BroadcastStateBootstrapFunction(org.apache.flink.state.api.functions.BroadcastStateBootstrapFunction) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Optional(java.util.Optional) Assert(org.junit.Assert) RuntimeExecutionMode(org.apache.flink.api.common.RuntimeExecutionMode) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) Collection(java.util.Collection) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) SerializedThrowable(org.apache.flink.util.SerializedThrowable)

Example 7 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class JobResult method toJobExecutionResult.

/**
 * Converts the {@link JobResult} to a {@link JobExecutionResult}.
 *
 * @param classLoader to use for deserialization
 * @return JobExecutionResult
 * @throws JobCancellationException if the job was cancelled
 * @throws JobExecutionException if the job execution did not succeed
 * @throws IOException if the accumulator could not be deserialized
 * @throws ClassNotFoundException if the accumulator could not deserialized
 */
public JobExecutionResult toJobExecutionResult(ClassLoader classLoader) throws JobExecutionException, IOException, ClassNotFoundException {
    if (applicationStatus == ApplicationStatus.SUCCEEDED) {
        return new JobExecutionResult(jobId, netRuntime, AccumulatorHelper.deserializeAccumulators(accumulatorResults, classLoader));
    } else {
        final Throwable cause;
        if (serializedThrowable == null) {
            cause = null;
        } else {
            cause = serializedThrowable.deserializeError(classLoader);
        }
        final JobExecutionException exception;
        if (applicationStatus == ApplicationStatus.FAILED) {
            exception = new JobExecutionException(jobId, "Job execution failed.", cause);
        } else if (applicationStatus == ApplicationStatus.CANCELED) {
            exception = new JobCancellationException(jobId, "Job was cancelled.", cause);
        } else {
            exception = new JobExecutionException(jobId, "Job completed with illegal application status: " + applicationStatus + '.', cause);
        }
        throw exception;
    }
}
Also used : JobCancellationException(org.apache.flink.runtime.client.JobCancellationException) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) SerializedThrowable(org.apache.flink.util.SerializedThrowable)

Example 8 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class FailureHandlingResultSnapshotTest method testMissingThrowableHandling.

// see FLINK-22060/FLINK-21376
@Test
public void testMissingThrowableHandling() {
    final ExecutionVertex rootCauseExecutionVertex = extractExecutionVertex(0);
    final long rootCauseTimestamp = triggerFailure(rootCauseExecutionVertex, null);
    final FailureHandlingResult failureHandlingResult = FailureHandlingResult.restartable(rootCauseExecutionVertex.getID(), null, rootCauseTimestamp, StreamSupport.stream(executionGraph.getAllExecutionVertices().spliterator(), false).map(ExecutionVertex::getID).collect(Collectors.toSet()), 0L, false);
    final FailureHandlingResultSnapshot testInstance = FailureHandlingResultSnapshot.create(failureHandlingResult, this::getLatestExecution);
    final Throwable actualException = new SerializedThrowable(testInstance.getRootCause()).deserializeError(ClassLoader.getSystemClassLoader());
    assertThat(actualException, IsInstanceOf.instanceOf(FlinkException.class));
    assertThat(actualException, FlinkMatchers.containsMessage(ErrorInfo.handleMissingThrowable(null).getMessage()));
    assertThat(testInstance.getTimestamp(), is(rootCauseTimestamp));
    assertThat(testInstance.getRootCauseExecution().isPresent(), is(true));
    assertThat(testInstance.getRootCauseExecution().get(), is(rootCauseExecutionVertex.getCurrentExecutionAttempt()));
}
Also used : FailureHandlingResult(org.apache.flink.runtime.executiongraph.failover.flip1.FailureHandlingResult) SerializedThrowable(org.apache.flink.util.SerializedThrowable) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) FlinkException(org.apache.flink.util.FlinkException) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Test(org.junit.Test)

Example 9 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class SavepointInfoTest method testSetBothLocationAndFailureCause.

@Test
public void testSetBothLocationAndFailureCause() {
    try {
        new SavepointInfo("/tmp", new SerializedThrowable(new RuntimeException()));
        fail("Expected exception not thrown");
    } catch (IllegalArgumentException e) {
    }
}
Also used : SerializedThrowable(org.apache.flink.util.SerializedThrowable) Test(org.junit.Test)

Example 10 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class JobExecutionResultResponseBodyTest method assertOriginalEqualsToUnmarshalled.

@Override
protected void assertOriginalEqualsToUnmarshalled(final JobExecutionResultResponseBody expected, final JobExecutionResultResponseBody actual) {
    assertThat(actual.getStatus(), equalTo(actual.getStatus()));
    final JobResult expectedJobExecutionResult = expected.getJobExecutionResult();
    final JobResult actualJobExecutionResult = actual.getJobExecutionResult();
    if (expectedJobExecutionResult != null) {
        assertNotNull(actualJobExecutionResult);
        assertThat(actualJobExecutionResult.getJobId(), equalTo(expectedJobExecutionResult.getJobId()));
        assertThat(actualJobExecutionResult.getApplicationStatus(), equalTo(expectedJobExecutionResult.getApplicationStatus()));
        assertThat(actualJobExecutionResult.getNetRuntime(), equalTo(expectedJobExecutionResult.getNetRuntime()));
        assertThat(actualJobExecutionResult.getAccumulatorResults(), equalTo(expectedJobExecutionResult.getAccumulatorResults()));
        final Optional<SerializedThrowable> expectedFailureCauseOptional = expectedJobExecutionResult.getSerializedThrowable();
        expectedFailureCauseOptional.ifPresent(expectedFailureCause -> {
            final SerializedThrowable actualFailureCause = actualJobExecutionResult.getSerializedThrowable().orElseThrow(() -> new AssertionError("actualFailureCause is not available"));
            assertThat(actualFailureCause.getFullStringifiedStackTrace(), equalTo(expectedFailureCause.getFullStringifiedStackTrace()));
            assertThat(actualFailureCause.getOriginalErrorClassName(), equalTo(expectedFailureCause.getOriginalErrorClassName()));
            assertArrayEquals(expectedFailureCause.getSerializedException(), actualFailureCause.getSerializedException());
        });
        if (expectedJobExecutionResult.getAccumulatorResults() != null) {
            assertNotNull(actualJobExecutionResult.getAccumulatorResults());
            assertArrayEquals(actualJobExecutionResult.getAccumulatorResults().get(TEST_ACCUMULATOR_NAME).getByteArray(), expectedJobExecutionResult.getAccumulatorResults().get(TEST_ACCUMULATOR_NAME).getByteArray());
        }
    }
}
Also used : JobResult(org.apache.flink.runtime.jobmaster.JobResult) SerializedThrowable(org.apache.flink.util.SerializedThrowable)

Aggregations

SerializedThrowable (org.apache.flink.util.SerializedThrowable)30 Test (org.junit.Test)16 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)6 FlinkException (org.apache.flink.util.FlinkException)6 ExecutionException (java.util.concurrent.ExecutionException)5 Collection (java.util.Collection)4 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)4 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 UnavailableDispatcherOperationException (org.apache.flink.runtime.dispatcher.UnavailableDispatcherOperationException)3 JobResult (org.apache.flink.runtime.jobmaster.JobResult)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 RichFlatMapFunction (org.apache.flink.api.common.functions.RichFlatMapFunction)2 RichMapFunction (org.apache.flink.api.common.functions.RichMapFunction)2 ListState (org.apache.flink.api.common.state.ListState)2