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());
}
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;
}
}
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()));
}
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) {
}
}
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());
}
}
}
Aggregations