Search in sources :

Example 36 with RestHandlerException

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);
        }
    });
}
Also used : TaskManagerDetailsInfo(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerDetailsInfo) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) AbstractResourceManagerHandler(org.apache.flink.runtime.rest.handler.resourcemanager.AbstractResourceManagerHandler) MessageHeaders(org.apache.flink.runtime.rest.messages.MessageHeaders) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) ArrayList(java.util.ArrayList) Map(java.util.Map) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) TaskManagerInfoWithSlots(org.apache.flink.runtime.resourcemanager.TaskManagerInfoWithSlots) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) MetricFetcher(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher) TaskManagerMessageParameters(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerMessageParameters) Nonnull(javax.annotation.Nonnull) TaskManagerIdPathParameter(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerIdPathParameter) TaskManagerMetricsInfo(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerMetricsInfo) UnknownTaskExecutorException(org.apache.flink.runtime.resourcemanager.exceptions.UnknownTaskExecutorException) MetricStore(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) CompletionException(java.util.concurrent.CompletionException) Preconditions(org.apache.flink.util.Preconditions) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) List(java.util.List) Time(org.apache.flink.api.common.time.Time) ResourceManagerGateway(org.apache.flink.runtime.resourcemanager.ResourceManagerGateway) TaskManagerMetricsInfo(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerMetricsInfo) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) UnknownTaskExecutorException(org.apache.flink.runtime.resourcemanager.exceptions.UnknownTaskExecutorException) CompletionException(java.util.concurrent.CompletionException) TaskManagerInfoWithSlots(org.apache.flink.runtime.resourcemanager.TaskManagerInfoWithSlots) TaskManagerDetailsInfo(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerDetailsInfo) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException)

Example 37 with RestHandlerException

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);
        }
    });
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) UnknownTaskExecutorException(org.apache.flink.runtime.resourcemanager.exceptions.UnknownTaskExecutorException) CompletionException(java.util.concurrent.CompletionException) Collection(java.util.Collection) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) ResourceManagerGateway(org.apache.flink.runtime.resourcemanager.ResourceManagerGateway)

Example 38 with RestHandlerException

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"));
            }
        }
    }
}
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)

Example 39 with RestHandlerException

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();
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Test(org.junit.Test)

Aggregations

RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)39 Test (org.junit.Test)13 IOException (java.io.IOException)11 CompletionException (java.util.concurrent.CompletionException)11 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)8 File (java.io.File)7 ExecutionException (java.util.concurrent.ExecutionException)7 JobID (org.apache.flink.api.common.JobID)7 Time (org.apache.flink.api.common.time.Time)6 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)6 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 Map (java.util.Map)5 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)5 HttpResponseStatus (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus)5 ExceptionUtils (org.apache.flink.util.ExceptionUtils)5 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)5