use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class TaskManagerDetailsHandler method handleRequest.
@Override
protected CompletableFuture<TaskManagerDetailsInfo> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody> request, @Nonnull ResourceManagerGateway gateway) throws RestHandlerException {
final ResourceID taskManagerResourceId = request.getPathParameter(TaskManagerIdPathParameter.class);
CompletableFuture<TaskManagerInfoWithSlots> taskManagerInfoWithSlotsFuture = gateway.requestTaskManagerDetailsInfo(taskManagerResourceId, timeout);
metricFetcher.update();
return taskManagerInfoWithSlotsFuture.thenApply((taskManagerInfoWithSlots) -> {
final MetricStore.TaskManagerMetricStore tmMetrics = metricStore.getTaskManagerMetricStore(taskManagerResourceId.getResourceIdString());
final TaskManagerMetricsInfo taskManagerMetricsInfo;
if (tmMetrics != null) {
log.debug("Create metrics info for TaskManager {}.", taskManagerResourceId.getStringWithMetadata());
taskManagerMetricsInfo = createTaskManagerMetricsInfo(tmMetrics);
} else {
log.debug("No metrics for TaskManager {}.", taskManagerResourceId.getStringWithMetadata());
taskManagerMetricsInfo = TaskManagerMetricsInfo.empty();
}
return new TaskManagerDetailsInfo(taskManagerInfoWithSlots, taskManagerMetricsInfo);
}).exceptionally((Throwable throwable) -> {
final Throwable strippedThrowable = ExceptionUtils.stripExecutionException(throwable);
if (strippedThrowable instanceof UnknownTaskExecutorException) {
throw new CompletionException(new RestHandlerException("Could not find TaskExecutor " + taskManagerResourceId + '.', HttpResponseStatus.NOT_FOUND, strippedThrowable));
} else {
throw new CompletionException(strippedThrowable);
}
});
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class TaskManagerLogListHandler method handleRequest.
@Override
protected CompletableFuture<LogListInfo> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody> request, @Nonnull ResourceManagerGateway gateway) throws RestHandlerException {
final ResourceID taskManagerId = request.getPathParameter(TaskManagerIdPathParameter.class);
final ResourceManagerGateway resourceManagerGateway = getResourceManagerGateway(resourceManagerGatewayRetriever);
final CompletableFuture<Collection<LogInfo>> logsWithLengthFuture = resourceManagerGateway.requestTaskManagerLogList(taskManagerId, timeout);
return logsWithLengthFuture.thenApply(LogListInfo::new).exceptionally((throwable) -> {
final Throwable strippedThrowable = ExceptionUtils.stripCompletionException(throwable);
if (strippedThrowable instanceof UnknownTaskExecutorException) {
throw new CompletionException(new RestHandlerException("Could not find TaskExecutor " + taskManagerId, HttpResponseStatus.NOT_FOUND, strippedThrowable));
} else {
throw new CompletionException(throwable);
}
});
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException 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"));
}
}
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class RestClusterClientTest method testRetriableSendOperationIfConnectionErrorOrServiceUnavailable.
/**
* Tests that the send operation is being retried.
*/
@Test
public void testRetriableSendOperationIfConnectionErrorOrServiceUnavailable() throws Exception {
final PingRestHandler pingRestHandler = new PingRestHandler(FutureUtils.completedExceptionally(new RestHandlerException("test exception", HttpResponseStatus.SERVICE_UNAVAILABLE)), CompletableFuture.completedFuture(EmptyResponseBody.getInstance()));
try (final TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(pingRestHandler)) {
RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
try {
final AtomicBoolean firstPollFailed = new AtomicBoolean();
failHttpRequest = (messageHeaders, messageParameters, requestBody) -> messageHeaders instanceof PingRestHandlerHeaders && !firstPollFailed.getAndSet(true);
restClusterClient.sendRequest(PingRestHandlerHeaders.INSTANCE).get();
} finally {
restClusterClient.close();
}
}
}
Aggregations