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