use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class SavepointHandlersTest method testTriggerSavepointNoDirectory.
@Test
public void testTriggerSavepointNoDirectory() throws Exception {
TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction((AsynchronousJobOperationKey operationKey, String directory, SavepointFormatType formatType) -> CompletableFuture.completedFuture(Acknowledge.get())).build();
try {
savepointTriggerHandler.handleRequest(triggerSavepointRequestWithDefaultDirectory(), testingRestfulGateway).get();
fail("Expected exception not thrown.");
} catch (RestHandlerException rhe) {
assertThat(rhe.getMessage(), equalTo("Config key [state.savepoints.dir] is not set. " + "Property [target-directory] must be provided."));
assertThat(rhe.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class SavepointHandlersTest method testQueryStatusOfUnknownOperationReturnsError.
@Test
public void testQueryStatusOfUnknownOperationReturnsError() throws HandlerRequestException, RestHandlerException {
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setGetSavepointStatusFunction(key -> FutureUtils.completedExceptionally(new UnknownOperationKeyException(key))).build();
final CompletableFuture<AsynchronousOperationResult<SavepointInfo>> statusFuture = savepointStatusHandler.handleRequest(savepointStatusRequest(new TriggerId()), testingRestfulGateway);
assertThat(statusFuture, RestMatchers.respondsWithError(HttpResponseStatus.NOT_FOUND));
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class CheckpointingStatisticsHandler method createCheckpointingStatistics.
private static CheckpointingStatistics createCheckpointingStatistics(AccessExecutionGraph executionGraph) throws RestHandlerException {
final CheckpointStatsSnapshot checkpointStatsSnapshot = executionGraph.getCheckpointStatsSnapshot();
if (checkpointStatsSnapshot == null) {
throw new RestHandlerException("Checkpointing has not been enabled.", HttpResponseStatus.NOT_FOUND, RestHandlerException.LoggingBehavior.IGNORE);
} else {
final CheckpointStatsCounts checkpointStatsCounts = checkpointStatsSnapshot.getCounts();
final CheckpointingStatistics.Counts counts = new CheckpointingStatistics.Counts(checkpointStatsCounts.getNumberOfRestoredCheckpoints(), checkpointStatsCounts.getTotalNumberOfCheckpoints(), checkpointStatsCounts.getNumberOfInProgressCheckpoints(), checkpointStatsCounts.getNumberOfCompletedCheckpoints(), checkpointStatsCounts.getNumberOfFailedCheckpoints());
final CompletedCheckpointStatsSummarySnapshot checkpointStatsSummary = checkpointStatsSnapshot.getSummaryStats();
final CheckpointingStatistics.Summary summary = new CheckpointingStatistics.Summary(StatsSummaryDto.valueOf(checkpointStatsSummary.getCheckpointedSize()), StatsSummaryDto.valueOf(checkpointStatsSummary.getStateSizeStats()), StatsSummaryDto.valueOf(checkpointStatsSummary.getEndToEndDurationStats()), new StatsSummaryDto(0, 0, 0, 0, 0, 0, 0, 0), StatsSummaryDto.valueOf(checkpointStatsSummary.getProcessedDataStats()), StatsSummaryDto.valueOf(checkpointStatsSummary.getPersistedDataStats()));
final CheckpointStatsHistory checkpointStatsHistory = checkpointStatsSnapshot.getHistory();
final CheckpointStatistics.CompletedCheckpointStatistics completed = checkpointStatsHistory.getLatestCompletedCheckpoint() != null ? (CheckpointStatistics.CompletedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics(checkpointStatsHistory.getLatestCompletedCheckpoint(), false) : null;
final CheckpointStatistics.CompletedCheckpointStatistics savepoint = checkpointStatsHistory.getLatestSavepoint() != null ? (CheckpointStatistics.CompletedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics(checkpointStatsHistory.getLatestSavepoint(), false) : null;
final CheckpointStatistics.FailedCheckpointStatistics failed = checkpointStatsHistory.getLatestFailedCheckpoint() != null ? (CheckpointStatistics.FailedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics(checkpointStatsHistory.getLatestFailedCheckpoint(), false) : null;
final RestoredCheckpointStats restoredCheckpointStats = checkpointStatsSnapshot.getLatestRestoredCheckpoint();
final CheckpointingStatistics.RestoredCheckpointStatistics restored;
if (restoredCheckpointStats == null) {
restored = null;
} else {
restored = new CheckpointingStatistics.RestoredCheckpointStatistics(restoredCheckpointStats.getCheckpointId(), restoredCheckpointStats.getRestoreTimestamp(), restoredCheckpointStats.getProperties().isSavepoint(), restoredCheckpointStats.getExternalPath());
}
final CheckpointingStatistics.LatestCheckpoints latestCheckpoints = new CheckpointingStatistics.LatestCheckpoints(completed, savepoint, failed, restored);
final List<CheckpointStatistics> history = new ArrayList<>(16);
for (AbstractCheckpointStats abstractCheckpointStats : checkpointStatsSnapshot.getHistory().getCheckpoints()) {
history.add(CheckpointStatistics.generateCheckpointStatistics(abstractCheckpointStats, false));
}
return new CheckpointingStatistics(counts, summary, latestCheckpoints, history);
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class ClientCoordinationHandler method handleRequest.
@Override
protected CompletableFuture<ClientCoordinationResponseBody> handleRequest(@Nonnull HandlerRequest<ClientCoordinationRequestBody> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
JobID jobId = request.getPathParameter(JobIDPathParameter.class);
OperatorID operatorId = request.getPathParameter(OperatorIDPathParameter.class);
SerializedValue<CoordinationRequest> serializedRequest = request.getRequestBody().getSerializedCoordinationRequest();
CompletableFuture<CoordinationResponse> responseFuture = gateway.deliverCoordinationRequestToCoordinator(jobId, operatorId, serializedRequest, timeout);
return responseFuture.thenApply(coordinationResponse -> {
try {
return new ClientCoordinationResponseBody(new SerializedValue<>(coordinationResponse));
} catch (IOException e) {
throw new CompletionException(new RestHandlerException("Failed to serialize coordination response", HttpResponseStatus.INTERNAL_SERVER_ERROR, e));
}
});
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class CheckpointConfigHandler method archiveJsonWithPath.
@Override
public Collection<ArchivedJson> archiveJsonWithPath(AccessExecutionGraph graph) throws IOException {
ResponseBody response;
try {
response = createCheckpointConfigInfo(graph);
} catch (RestHandlerException rhe) {
response = new ErrorResponseBody(rhe.getMessage());
}
String path = CheckpointConfigHeaders.getInstance().getTargetRestEndpointURL().replace(':' + JobIDPathParameter.KEY, graph.getJobID().toString());
return Collections.singletonList(new ArchivedJson(path, response));
}
Aggregations