Search in sources :

Example 21 with RestHandlerException

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));
    }
}
Also used : AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Test(org.junit.Test)

Example 22 with RestHandlerException

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));
}
Also used : AsynchronousOperationResult(org.apache.flink.runtime.rest.handler.async.AsynchronousOperationResult) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) SavepointTestUtilities.setReferenceToOperationKey(org.apache.flink.runtime.rest.handler.job.savepoints.SavepointTestUtilities.setReferenceToOperationKey) QueueStatus(org.apache.flink.runtime.rest.messages.queue.QueueStatus) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) AtomicReference(java.util.concurrent.atomic.AtomicReference) AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) TriggerIdPathParameter(org.apache.flink.runtime.rest.messages.TriggerIdPathParameter) Assert.assertThat(org.junit.Assert.assertThat) SavepointTestUtilities.getResultIfKeyMatches(org.apache.flink.runtime.rest.handler.job.savepoints.SavepointTestUtilities.getResultIfKeyMatches) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Map(java.util.Map) SavepointTriggerRequestBody(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerRequestBody) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Assert.fail(org.junit.Assert.fail) SavepointStatusMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointStatusMessageParameters) UnknownOperationKeyException(org.apache.flink.runtime.dispatcher.UnknownOperationKeyException) HandlerRequestException(org.apache.flink.runtime.rest.handler.HandlerRequestException) RestMatchers(org.apache.flink.runtime.rest.RestMatchers) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) OperationResult(org.apache.flink.runtime.rest.handler.async.OperationResult) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) Test(org.junit.Test) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) SavepointTriggerMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerMessageParameters) JobID(org.apache.flink.api.common.JobID) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) Assert.assertEquals(org.junit.Assert.assertEquals) UnknownOperationKeyException(org.apache.flink.runtime.dispatcher.UnknownOperationKeyException) AsynchronousOperationResult(org.apache.flink.runtime.rest.handler.async.AsynchronousOperationResult) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 23 with RestHandlerException

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);
    }
}
Also used : CheckpointStatsCounts(org.apache.flink.runtime.checkpoint.CheckpointStatsCounts) CheckpointStatsCounts(org.apache.flink.runtime.checkpoint.CheckpointStatsCounts) AbstractCheckpointStats(org.apache.flink.runtime.checkpoint.AbstractCheckpointStats) ArrayList(java.util.ArrayList) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) CheckpointingStatistics(org.apache.flink.runtime.rest.messages.checkpoints.CheckpointingStatistics) RestoredCheckpointStats(org.apache.flink.runtime.checkpoint.RestoredCheckpointStats) CheckpointStatsHistory(org.apache.flink.runtime.checkpoint.CheckpointStatsHistory) CompletedCheckpointStatsSummarySnapshot(org.apache.flink.runtime.checkpoint.CompletedCheckpointStatsSummarySnapshot) StatsSummaryDto(org.apache.flink.runtime.rest.messages.checkpoints.StatsSummaryDto) CheckpointStatsSnapshot(org.apache.flink.runtime.checkpoint.CheckpointStatsSnapshot) CheckpointStatistics(org.apache.flink.runtime.rest.messages.checkpoints.CheckpointStatistics)

Example 24 with RestHandlerException

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));
        }
    });
}
Also used : CoordinationResponse(org.apache.flink.runtime.operators.coordination.CoordinationResponse) CoordinationRequest(org.apache.flink.runtime.operators.coordination.CoordinationRequest) CompletionException(java.util.concurrent.CompletionException) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) IOException(java.io.IOException) ClientCoordinationResponseBody(org.apache.flink.runtime.rest.messages.job.coordination.ClientCoordinationResponseBody) JobID(org.apache.flink.api.common.JobID) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException)

Example 25 with RestHandlerException

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));
}
Also used : ArchivedJson(org.apache.flink.runtime.webmonitor.history.ArchivedJson) ErrorResponseBody(org.apache.flink.runtime.rest.messages.ErrorResponseBody) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) ErrorResponseBody(org.apache.flink.runtime.rest.messages.ErrorResponseBody) ResponseBody(org.apache.flink.runtime.rest.messages.ResponseBody)

Aggregations

RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)39 Test (org.junit.Test)13 IOException (java.io.IOException)11 CompletionException (java.util.concurrent.CompletionException)11 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)8 File (java.io.File)7 ExecutionException (java.util.concurrent.ExecutionException)7 JobID (org.apache.flink.api.common.JobID)7 Time (org.apache.flink.api.common.time.Time)6 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)6 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 Map (java.util.Map)5 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)5 HttpResponseStatus (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus)5 ExceptionUtils (org.apache.flink.util.ExceptionUtils)5 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)5