use of org.apache.flink.runtime.rest.handler.HandlerRequest in project flink by apache.
the class JobManagerLogListHandler method handleRequest.
@Override
protected CompletableFuture<LogListInfo> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
if (logDir == null) {
return CompletableFuture.completedFuture(new LogListInfo(Collections.emptyList()));
}
final File[] logFiles = logDir.listFiles();
if (logFiles == null) {
return FutureUtils.completedExceptionally(new IOException("Could not list files in " + logDir));
}
final List<LogInfo> logs = Arrays.stream(logFiles).filter(File::isFile).map(logFile -> new LogInfo(logFile.getName(), logFile.length(), logFile.lastModified())).collect(Collectors.toList());
return CompletableFuture.completedFuture(new LogListInfo(logs));
}
use of org.apache.flink.runtime.rest.handler.HandlerRequest 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.handler.HandlerRequest 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.handler.HandlerRequest 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