use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class JobSubmitHandler method handleRequest.
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(@Nonnull HandlerRequest<JobSubmitRequestBody> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
final Collection<File> uploadedFiles = request.getUploadedFiles();
final Map<String, Path> nameToFile = uploadedFiles.stream().collect(Collectors.toMap(File::getName, Path::fromLocalFile));
if (uploadedFiles.size() != nameToFile.size()) {
throw new RestHandlerException(String.format("The number of uploaded files was %s than the expected count. Expected: %s Actual %s", uploadedFiles.size() < nameToFile.size() ? "lower" : "higher", nameToFile.size(), uploadedFiles.size()), HttpResponseStatus.BAD_REQUEST);
}
final JobSubmitRequestBody requestBody = request.getRequestBody();
if (requestBody.jobGraphFileName == null) {
throw new RestHandlerException(String.format("The %s field must not be omitted or be null.", JobSubmitRequestBody.FIELD_NAME_JOB_GRAPH), HttpResponseStatus.BAD_REQUEST);
}
CompletableFuture<JobGraph> jobGraphFuture = loadJobGraph(requestBody, nameToFile);
Collection<Path> jarFiles = getJarFilesToUpload(requestBody.jarFileNames, nameToFile);
Collection<Tuple2<String, Path>> artifacts = getArtifactFilesToUpload(requestBody.artifactFileNames, nameToFile);
CompletableFuture<JobGraph> finalizedJobGraphFuture = uploadJobGraphFiles(gateway, jobGraphFuture, jarFiles, artifacts, configuration);
CompletableFuture<Acknowledge> jobSubmissionFuture = finalizedJobGraphFuture.thenCompose(jobGraph -> gateway.submitJob(jobGraph, timeout));
return jobSubmissionFuture.thenCombine(jobGraphFuture, (ack, jobGraph) -> new JobSubmitResponseBody("/jobs/" + jobGraph.getJobID()));
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class AbstractCheckpointHandler method handleRequest.
@Override
protected R handleRequest(HandlerRequest<EmptyRequestBody> request, AccessExecutionGraph executionGraph) throws RestHandlerException {
final long checkpointId = request.getPathParameter(CheckpointIdPathParameter.class);
final CheckpointStatsSnapshot checkpointStatsSnapshot = executionGraph.getCheckpointStatsSnapshot();
if (checkpointStatsSnapshot != null) {
AbstractCheckpointStats checkpointStats = checkpointStatsSnapshot.getHistory().getCheckpointById(checkpointId);
if (checkpointStats != null) {
checkpointStatsCache.tryAdd(checkpointStats);
} else {
checkpointStats = checkpointStatsCache.tryGet(checkpointId);
}
if (checkpointStats != null) {
return handleCheckpointRequest(request, checkpointStats);
} else {
throw new RestHandlerException("Could not find checkpointing statistics for checkpoint " + checkpointId + '.', HttpResponseStatus.NOT_FOUND);
}
} else {
throw new RestHandlerException("Checkpointing was not enabled for job " + executionGraph.getJobID() + '.', HttpResponseStatus.NOT_FOUND);
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class CheckpointingStatisticsHandler method archiveJsonWithPath.
@Override
public Collection<ArchivedJson> archiveJsonWithPath(AccessExecutionGraph graph) throws IOException {
ResponseBody json;
try {
json = createCheckpointingStatistics(graph);
} catch (RestHandlerException rhe) {
json = new ErrorResponseBody(rhe.getMessage());
}
String path = getMessageHeaders().getTargetRestEndpointURL().replace(':' + JobIDPathParameter.KEY, graph.getJobID().toString());
return Collections.singletonList(new ArchivedJson(path, json));
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException 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.RestHandlerException in project flink by apache.
the class RestClusterClientSavepointTriggerTest method testTriggerSavepointRetry.
@Test
public void testTriggerSavepointRetry() throws Exception {
final TriggerId triggerId = new TriggerId();
final String expectedSavepointDir = "hello";
final AtomicBoolean failRequest = new AtomicBoolean(true);
try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint(request -> triggerId, trigger -> {
if (failRequest.compareAndSet(true, false)) {
throw new RestHandlerException("expected", HttpResponseStatus.SERVICE_UNAVAILABLE);
} else {
return new SavepointInfo(expectedSavepointDir, null);
}
})) {
final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
final String savepointPath = restClusterClient.triggerSavepoint(new JobID(), null, SavepointFormatType.CANONICAL).get();
assertEquals(expectedSavepointDir, savepointPath);
}
}
Aggregations