Search in sources :

Example 1 with JobExecutionResultResponseBody

use of org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody in project flink by apache.

the class JobExecutionResultHandlerTest method testCompletedResult.

@Test
public void testCompletedResult() throws Exception {
    final JobStatus jobStatus = JobStatus.FINISHED;
    final ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder().setJobID(TEST_JOB_ID).setState(jobStatus).build();
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setRequestJobStatusFunction(jobId -> {
        assertThat(jobId, equalTo(TEST_JOB_ID));
        return CompletableFuture.completedFuture(jobStatus);
    }).setRequestJobResultFunction(jobId -> {
        assertThat(jobId, equalTo(TEST_JOB_ID));
        return CompletableFuture.completedFuture(JobResult.createFrom(executionGraph));
    }).build();
    final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(testRequest, testingRestfulGateway).get();
    assertThat(responseBody.getStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
    assertThat(responseBody.getJobExecutionResult(), not(nullValue()));
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) QueueStatus(org.apache.flink.runtime.rest.messages.queue.QueueStatus) Matchers.not(org.hamcrest.Matchers.not) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Assert.assertThat(org.junit.Assert.assertThat) JobResult(org.apache.flink.runtime.jobmaster.JobResult) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Test(org.junit.Test) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 2 with JobExecutionResultResponseBody

use of org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody in project flink by apache.

the class JobExecutionResultHandlerTest method testResultInProgress.

@Test
public void testResultInProgress() throws Exception {
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setRequestJobStatusFunction(jobId -> CompletableFuture.completedFuture(JobStatus.RUNNING)).build();
    final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(testRequest, testingRestfulGateway).get();
    assertThat(responseBody.getStatus().getId(), equalTo(QueueStatus.Id.IN_PROGRESS));
}
Also used : QueueStatus(org.apache.flink.runtime.rest.messages.queue.QueueStatus) Matchers.not(org.hamcrest.Matchers.not) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Assert.assertThat(org.junit.Assert.assertThat) JobResult(org.apache.flink.runtime.jobmaster.JobResult) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Test(org.junit.Test) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 3 with JobExecutionResultResponseBody

use of org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody 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)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)3 JobID (org.apache.flink.api.common.JobID)3 JobStatus (org.apache.flink.api.common.JobStatus)3 Time (org.apache.flink.api.common.time.Time)3 FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)3 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)3 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)3 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)3 JobMessageParameters (org.apache.flink.runtime.rest.messages.JobMessageParameters)3 JobExecutionResultResponseBody (org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody)3 HttpResponseStatus (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus)3 ExceptionUtils (org.apache.flink.util.ExceptionUtils)3 Collections (java.util.Collections)2 ExecutionException (java.util.concurrent.ExecutionException)2 ArchivedExecutionGraph (org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph)2 JobResult (org.apache.flink.runtime.jobmaster.JobResult)2 ArchivedExecutionGraphBuilder (org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder)2 QueueStatus (org.apache.flink.runtime.rest.messages.queue.QueueStatus)2 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)2 TestLogger (org.apache.flink.util.TestLogger)2