Search in sources :

Example 1 with HandlerRequest

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));
}
Also used : LogListInfo(org.apache.flink.runtime.rest.messages.LogListInfo) Arrays(java.util.Arrays) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) LogInfo(org.apache.flink.runtime.rest.messages.LogInfo) MessageHeaders(org.apache.flink.runtime.rest.messages.MessageHeaders) Collectors(java.util.stream.Collectors) File(java.io.File) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) List(java.util.List) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Map(java.util.Map) LogListInfo(org.apache.flink.runtime.rest.messages.LogListInfo) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) AbstractRestHandler(org.apache.flink.runtime.rest.handler.AbstractRestHandler) Nullable(javax.annotation.Nullable) LogInfo(org.apache.flink.runtime.rest.messages.LogInfo) IOException(java.io.IOException) File(java.io.File)

Example 2 with HandlerRequest

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);
        }
    });
}
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 3 with HandlerRequest

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);
    });
}
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 4 with HandlerRequest

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

Map (java.util.Map)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Nonnull (javax.annotation.Nonnull)4 Time (org.apache.flink.api.common.time.Time)4 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)4 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)4 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)4 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)4 GatewayRetriever (org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever)4 CompletionException (java.util.concurrent.CompletionException)3 AbstractRestHandler (org.apache.flink.runtime.rest.handler.AbstractRestHandler)3 MessageHeaders (org.apache.flink.runtime.rest.messages.MessageHeaders)3 ExceptionUtils (org.apache.flink.util.ExceptionUtils)3 List (java.util.List)2 JobID (org.apache.flink.api.common.JobID)2 FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)2 JobIDPathParameter (org.apache.flink.runtime.rest.messages.JobIDPathParameter)2 JobMessageParameters (org.apache.flink.runtime.rest.messages.JobMessageParameters)2 HttpResponseStatus (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus)2 Preconditions (org.apache.flink.util.Preconditions)2