Search in sources :

Example 26 with EmptyRequestBody

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

the class AggregatingMetricsHandlerTestBase method testSumAggregation.

@Test
public void testSumAggregation() throws Exception {
    Map<String, List<String>> queryParams = new HashMap<>(4);
    queryParams.put("get", Collections.singletonList("abc.metric1"));
    queryParams.put("agg", Collections.singletonList("sum"));
    HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), handler.getMessageHeaders().getUnresolvedMessageParameters(), pathParameters, queryParams, Collections.emptyList());
    AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY).get();
    Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();
    assertEquals(1, aggregatedMetrics.size());
    AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();
    assertEquals("abc.metric1", aggregatedMetric.getId());
    assertEquals(4.0, aggregatedMetric.getSum(), 0.1);
    assertNull(aggregatedMetric.getMin());
    assertNull(aggregatedMetric.getMax());
    assertNull(aggregatedMetric.getAvg());
}
Also used : AggregatedMetricsResponseBody(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody) AggregatedMetric(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric) HashMap(java.util.HashMap) List(java.util.List) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Test(org.junit.Test)

Example 27 with EmptyRequestBody

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

the class AggregatingMetricsHandlerTestBase method testMultipleAggregation.

@Test
public void testMultipleAggregation() throws Exception {
    Map<String, List<String>> queryParams = new HashMap<>(4);
    queryParams.put("get", Collections.singletonList("abc.metric1"));
    queryParams.put("agg", Arrays.asList("min", "max", "avg"));
    HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), handler.getMessageHeaders().getUnresolvedMessageParameters(), pathParameters, queryParams, Collections.emptyList());
    AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY).get();
    Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();
    assertEquals(1, aggregatedMetrics.size());
    AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();
    assertEquals("abc.metric1", aggregatedMetric.getId());
    assertEquals(1.0, aggregatedMetric.getMin(), 0.1);
    assertEquals(3.0, aggregatedMetric.getMax(), 0.1);
    assertEquals(2.0, aggregatedMetric.getAvg(), 0.1);
    assertNull(aggregatedMetric.getSum());
}
Also used : AggregatedMetricsResponseBody(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody) AggregatedMetric(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric) HashMap(java.util.HashMap) List(java.util.List) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Test(org.junit.Test)

Example 28 with EmptyRequestBody

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

the class AbstractExecutionGraphHandler method handleRequest.

@Override
protected CompletableFuture<R> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
    JobID jobId = request.getPathParameter(JobIDPathParameter.class);
    CompletableFuture<ExecutionGraphInfo> executionGraphFuture = executionGraphCache.getExecutionGraphInfo(jobId, gateway);
    return executionGraphFuture.thenApplyAsync(executionGraph -> {
        try {
            return handleRequest(request, executionGraph);
        } catch (RestHandlerException rhe) {
            throw new CompletionException(rhe);
        }
    }, executor).exceptionally(throwable -> {
        throwable = ExceptionUtils.stripCompletionException(throwable);
        if (throwable instanceof FlinkJobNotFoundException) {
            throw new CompletionException(new NotFoundException(String.format("Job %s not found", jobId), throwable));
        } else {
            throw new CompletionException(throwable);
        }
    });
}
Also used : ExecutionGraphCache(org.apache.flink.runtime.rest.handler.legacy.ExecutionGraphCache) Executor(java.util.concurrent.Executor) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) MessageHeaders(org.apache.flink.runtime.rest.messages.MessageHeaders) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) Preconditions(org.apache.flink.util.Preconditions) NotFoundException(org.apache.flink.runtime.rest.NotFoundException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) ResponseBody(org.apache.flink.runtime.rest.messages.ResponseBody) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Map(java.util.Map) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Nonnull(javax.annotation.Nonnull) Time(org.apache.flink.api.common.time.Time) AbstractRestHandler(org.apache.flink.runtime.rest.handler.AbstractRestHandler) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) CompletionException(java.util.concurrent.CompletionException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) NotFoundException(org.apache.flink.runtime.rest.NotFoundException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) JobID(org.apache.flink.api.common.JobID) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException)

Example 29 with EmptyRequestBody

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

the class JobExecutionResultHandler method handleRequest.

@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
    final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
    final CompletableFuture<JobStatus> jobStatusFuture = gateway.requestJobStatus(jobId, timeout);
    return jobStatusFuture.thenCompose(jobStatus -> {
        if (jobStatus.isGloballyTerminalState()) {
            return gateway.requestJobResult(jobId, timeout).thenApply(JobExecutionResultResponseBody::created);
        } else {
            return CompletableFuture.completedFuture(JobExecutionResultResponseBody.inProgress());
        }
    }).exceptionally(throwable -> {
        throw propagateException(throwable);
    });
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) JobExecutionResultHeaders(org.apache.flink.runtime.rest.messages.job.JobExecutionResultHeaders) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) JobStatus(org.apache.flink.api.common.JobStatus) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Map(java.util.Map) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Nonnull(javax.annotation.Nonnull) Time(org.apache.flink.api.common.time.Time) AbstractRestHandler(org.apache.flink.runtime.rest.handler.AbstractRestHandler) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) JobID(org.apache.flink.api.common.JobID)

Example 30 with EmptyRequestBody

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

EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)30 Test (org.junit.Test)23 HashMap (java.util.HashMap)12 List (java.util.List)8 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)7 AggregatedMetric (org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric)7 AggregatedMetricsResponseBody (org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody)7 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)6 JobExceptionsInfoWithHistory (org.apache.flink.runtime.rest.messages.JobExceptionsInfoWithHistory)5 ExecutionGraphInfo (org.apache.flink.runtime.scheduler.ExecutionGraphInfo)5 Map (java.util.Map)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Nonnull (javax.annotation.Nonnull)4 JobID (org.apache.flink.api.common.JobID)4 Time (org.apache.flink.api.common.time.Time)4 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)4 DefaultExecutionGraphCache (org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache)4 Path (java.nio.file.Path)3 CompletionException (java.util.concurrent.CompletionException)3 ExecutionException (java.util.concurrent.ExecutionException)3