Search in sources :

Example 1 with TaskManagerDetailsInfo

use of org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerDetailsInfo in project flink by apache.

the class TaskManagerDetailsHandlerTest method testTaskManagerMetricsInfoExtraction.

@Test
public void testTaskManagerMetricsInfoExtraction() throws RestHandlerException, ExecutionException, InterruptedException, JsonProcessingException, HandlerRequestException {
    initializeMetricStore(metricFetcher.getMetricStore());
    resourceManagerGateway.setRequestTaskManagerDetailsInfoFunction(taskManagerId -> CompletableFuture.completedFuture(new TaskManagerInfoWithSlots(createEmptyTaskManagerInfo(), Collections.emptyList())));
    HandlerRequest<EmptyRequestBody> request = createRequest();
    TaskManagerDetailsInfo taskManagerDetailsInfo = testInstance.handleRequest(request, resourceManagerGateway).get();
    TaskManagerMetricsInfo actual = taskManagerDetailsInfo.getTaskManagerMetricsInfo();
    TaskManagerMetricsInfo expected = new TaskManagerMetricsInfo(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 15L, 16L, 17L, 18L, 19L, 20L, Collections.emptyList());
    ObjectMapper objectMapper = new ObjectMapper();
    String actualJson = objectMapper.writeValueAsString(actual);
    String expectedJson = objectMapper.writeValueAsString(expected);
    assertThat(actualJson, is(expectedJson));
}
Also used : TaskManagerMetricsInfo(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerMetricsInfo) TaskManagerInfoWithSlots(org.apache.flink.runtime.resourcemanager.TaskManagerInfoWithSlots) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) TaskManagerDetailsInfo(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerDetailsInfo) ObjectMapper(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with TaskManagerDetailsInfo

use of org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerDetailsInfo 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)

Aggregations

TaskManagerInfoWithSlots (org.apache.flink.runtime.resourcemanager.TaskManagerInfoWithSlots)2 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)2 TaskManagerDetailsInfo (org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerDetailsInfo)2 TaskManagerMetricsInfo (org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerMetricsInfo)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Nonnull (javax.annotation.Nonnull)1 Time (org.apache.flink.api.common.time.Time)1 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)1 ResourceManagerGateway (org.apache.flink.runtime.resourcemanager.ResourceManagerGateway)1 UnknownTaskExecutorException (org.apache.flink.runtime.resourcemanager.exceptions.UnknownTaskExecutorException)1 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)1 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)1 MetricFetcher (org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher)1 MetricStore (org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore)1 AbstractResourceManagerHandler (org.apache.flink.runtime.rest.handler.resourcemanager.AbstractResourceManagerHandler)1 MessageHeaders (org.apache.flink.runtime.rest.messages.MessageHeaders)1