Search in sources :

Example 36 with ExecutionGraphInfo

use of org.apache.flink.runtime.scheduler.ExecutionGraphInfo in project flink by apache.

the class Dispatcher method cancelJob.

@Override
public CompletableFuture<Acknowledge> cancelJob(JobID jobId, Time timeout) {
    Optional<JobManagerRunner> maybeJob = getJobManagerRunner(jobId);
    if (maybeJob.isPresent()) {
        return maybeJob.get().cancel(timeout);
    }
    final ExecutionGraphInfo executionGraphInfo = executionGraphInfoStore.get(jobId);
    if (executionGraphInfo != null) {
        final JobStatus jobStatus = executionGraphInfo.getArchivedExecutionGraph().getState();
        if (jobStatus == JobStatus.CANCELED) {
            return CompletableFuture.completedFuture(Acknowledge.get());
        } else {
            return FutureUtils.completedExceptionally(new FlinkJobTerminatedWithoutCancellationException(jobId, jobStatus));
        }
    }
    log.debug("Dispatcher is unable to cancel job {}: not found", jobId);
    return FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId));
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) FlinkJobTerminatedWithoutCancellationException(org.apache.flink.runtime.messages.FlinkJobTerminatedWithoutCancellationException) JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner)

Example 37 with ExecutionGraphInfo

use of org.apache.flink.runtime.scheduler.ExecutionGraphInfo 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 38 with ExecutionGraphInfo

use of org.apache.flink.runtime.scheduler.ExecutionGraphInfo in project flink by apache.

the class DispatcherResourceCleanupTest method testErrorHandlingIfJobCannotBeMarkedAsCleanInJobResultStore.

@Test
public void testErrorHandlingIfJobCannotBeMarkedAsCleanInJobResultStore() throws Exception {
    final CompletableFuture<JobResultEntry> dirtyJobFuture = new CompletableFuture<>();
    final JobResultStore jobResultStore = TestingJobResultStore.builder().withCreateDirtyResultConsumer(dirtyJobFuture::complete).withMarkResultAsCleanConsumer(jobId -> {
        throw new IOException("Expected IOException.");
    }).build();
    final TestingJobManagerRunnerFactory jobManagerRunnerFactory = startDispatcherAndSubmitJob(createTestingDispatcherBuilder().setJobResultStore(jobResultStore), 0);
    ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder().setJobID(jobId).setState(JobStatus.FINISHED).build();
    final TestingJobManagerRunner testingJobManagerRunner = jobManagerRunnerFactory.takeCreatedJobManagerRunner();
    testingJobManagerRunner.completeResultFuture(new ExecutionGraphInfo(executionGraph));
    final CompletableFuture<? extends Throwable> errorFuture = this.testingFatalErrorHandlerResource.getFatalErrorHandler().getErrorFuture();
    try {
        final Throwable unexpectedError = errorFuture.get(100, TimeUnit.MILLISECONDS);
        fail("No error should have been reported but an " + unexpectedError.getClass() + " was handled.");
    } catch (TimeoutException e) {
    // expected
    }
    assertThat(dirtyJobFuture.get().getJobId(), is(jobId));
}
Also used : Arrays(java.util.Arrays) JobSubmissionException(org.apache.flink.runtime.client.JobSubmissionException) ThrowingRunnable(org.apache.flink.util.function.ThrowingRunnable) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) JobManagerJobMetricGroupFactory(org.apache.flink.runtime.jobmaster.factories.JobManagerJobMetricGroupFactory) Assert.assertThat(org.junit.Assert.assertThat) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) TestingJobMasterGatewayBuilder(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGatewayBuilder) TestingFatalErrorHandlerResource(org.apache.flink.runtime.util.TestingFatalErrorHandlerResource) Assert.fail(org.junit.Assert.fail) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) ClassRule(org.junit.ClassRule) AfterClass(org.junit.AfterClass) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) FlinkMatchers.containsCause(org.apache.flink.core.testutils.FlinkMatchers.containsCause) Preconditions(org.apache.flink.util.Preconditions) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) TestingJobResultStore(org.apache.flink.runtime.testutils.TestingJobResultStore) Matchers.equalTo(org.hamcrest.Matchers.equalTo) JobManagerSharedServices(org.apache.flink.runtime.jobmaster.JobManagerSharedServices) Optional(java.util.Optional) AbstractDispatcherTest.awaitStatus(org.apache.flink.runtime.dispatcher.AbstractDispatcherTest.awaitStatus) Matchers.is(org.hamcrest.Matchers.is) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) Queue(java.util.Queue) Time(org.apache.flink.api.common.time.Time) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) FlinkException(org.apache.flink.util.FlinkException) BlobServer(org.apache.flink.runtime.blob.BlobServer) BeforeClass(org.junit.BeforeClass) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) TestingJobMasterGateway(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGateway) TestingResourceCleanerFactory(org.apache.flink.runtime.dispatcher.cleanup.TestingResourceCleanerFactory) RpcService(org.apache.flink.runtime.rpc.RpcService) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ExpectedException(org.junit.rules.ExpectedException) IsInstanceOf(org.hamcrest.core.IsInstanceOf) Before(org.junit.Before) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) FlinkMatchers.containsMessage(org.apache.flink.core.testutils.FlinkMatchers.containsMessage) Configuration(org.apache.flink.configuration.Configuration) Test(org.junit.Test) IOException(java.io.IOException) TestingBlobStoreBuilder(org.apache.flink.runtime.blob.TestingBlobStoreBuilder) Reference(org.apache.flink.util.Reference) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JobResultEntry(org.apache.flink.runtime.highavailability.JobResultEntry) JobID(org.apache.flink.api.common.JobID) Rule(org.junit.Rule) JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner) BlobUtils(org.apache.flink.runtime.blob.BlobUtils) ArrayDeque(java.util.ArrayDeque) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) IOException(java.io.IOException) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) TestingJobResultStore(org.apache.flink.runtime.testutils.TestingJobResultStore) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) CompletableFuture(java.util.concurrent.CompletableFuture) JobResultEntry(org.apache.flink.runtime.highavailability.JobResultEntry) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 39 with ExecutionGraphInfo

use of org.apache.flink.runtime.scheduler.ExecutionGraphInfo in project flink by apache.

the class DispatcherResourceCleanupTest method testFatalErrorIfJobCannotBeMarkedDirtyInJobResultStore.

@Test
public void testFatalErrorIfJobCannotBeMarkedDirtyInJobResultStore() throws Exception {
    final JobResultStore jobResultStore = TestingJobResultStore.builder().withCreateDirtyResultConsumer(jobResult -> {
        throw new IOException("Expected IOException.");
    }).build();
    final TestingJobManagerRunnerFactory jobManagerRunnerFactory = startDispatcherAndSubmitJob(createTestingDispatcherBuilder().setJobResultStore(jobResultStore), 0);
    ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder().setJobID(jobId).setState(JobStatus.FINISHED).build();
    final TestingJobManagerRunner testingJobManagerRunner = jobManagerRunnerFactory.takeCreatedJobManagerRunner();
    testingJobManagerRunner.completeResultFuture(new ExecutionGraphInfo(executionGraph));
    final CompletableFuture<? extends Throwable> errorFuture = this.testingFatalErrorHandlerResource.getFatalErrorHandler().getErrorFuture();
    assertThat(errorFuture.get(100, TimeUnit.MILLISECONDS), IsInstanceOf.instanceOf(FlinkException.class));
    testingFatalErrorHandlerResource.getFatalErrorHandler().clearError();
}
Also used : Arrays(java.util.Arrays) JobSubmissionException(org.apache.flink.runtime.client.JobSubmissionException) ThrowingRunnable(org.apache.flink.util.function.ThrowingRunnable) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) JobManagerJobMetricGroupFactory(org.apache.flink.runtime.jobmaster.factories.JobManagerJobMetricGroupFactory) Assert.assertThat(org.junit.Assert.assertThat) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) TestingJobMasterGatewayBuilder(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGatewayBuilder) TestingFatalErrorHandlerResource(org.apache.flink.runtime.util.TestingFatalErrorHandlerResource) Assert.fail(org.junit.Assert.fail) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) ClassRule(org.junit.ClassRule) AfterClass(org.junit.AfterClass) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) FlinkMatchers.containsCause(org.apache.flink.core.testutils.FlinkMatchers.containsCause) Preconditions(org.apache.flink.util.Preconditions) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) TestingJobResultStore(org.apache.flink.runtime.testutils.TestingJobResultStore) Matchers.equalTo(org.hamcrest.Matchers.equalTo) JobManagerSharedServices(org.apache.flink.runtime.jobmaster.JobManagerSharedServices) Optional(java.util.Optional) AbstractDispatcherTest.awaitStatus(org.apache.flink.runtime.dispatcher.AbstractDispatcherTest.awaitStatus) Matchers.is(org.hamcrest.Matchers.is) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) Queue(java.util.Queue) Time(org.apache.flink.api.common.time.Time) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) FlinkException(org.apache.flink.util.FlinkException) BlobServer(org.apache.flink.runtime.blob.BlobServer) BeforeClass(org.junit.BeforeClass) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) TestingJobMasterGateway(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGateway) TestingResourceCleanerFactory(org.apache.flink.runtime.dispatcher.cleanup.TestingResourceCleanerFactory) RpcService(org.apache.flink.runtime.rpc.RpcService) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ExpectedException(org.junit.rules.ExpectedException) IsInstanceOf(org.hamcrest.core.IsInstanceOf) Before(org.junit.Before) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) FlinkMatchers.containsMessage(org.apache.flink.core.testutils.FlinkMatchers.containsMessage) Configuration(org.apache.flink.configuration.Configuration) Test(org.junit.Test) IOException(java.io.IOException) TestingBlobStoreBuilder(org.apache.flink.runtime.blob.TestingBlobStoreBuilder) Reference(org.apache.flink.util.Reference) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JobResultEntry(org.apache.flink.runtime.highavailability.JobResultEntry) JobID(org.apache.flink.api.common.JobID) Rule(org.junit.Rule) JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner) BlobUtils(org.apache.flink.runtime.blob.BlobUtils) ArrayDeque(java.util.ArrayDeque) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) IOException(java.io.IOException) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) TestingJobResultStore(org.apache.flink.runtime.testutils.TestingJobResultStore) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 40 with ExecutionGraphInfo

use of org.apache.flink.runtime.scheduler.ExecutionGraphInfo in project flink by apache.

the class MiniDispatcherTest method testNotTerminationWithoutGloballyTerminalState.

/**
 * Tests that in detached mode, the {@link MiniDispatcher} will not complete the future that
 * signals job termination if the JobStatus is not globally terminal state.
 */
@Test
public void testNotTerminationWithoutGloballyTerminalState() throws Exception {
    final MiniDispatcher miniDispatcher = createMiniDispatcher(ClusterEntrypoint.ExecutionMode.DETACHED);
    miniDispatcher.start();
    try {
        // wait until we have submitted the job
        final TestingJobManagerRunner testingJobManagerRunner = testingJobManagerRunnerFactory.takeCreatedJobManagerRunner();
        testingJobManagerRunner.completeResultFuture(new ExecutionGraphInfo(new ArchivedExecutionGraphBuilder().setJobID(jobGraph.getJobID()).setState(JobStatus.SUSPENDED).build()));
        testingJobManagerRunner.getTerminationFuture().get();
        Assertions.assertThat(miniDispatcher.getShutDownFuture()).isNotDone();
    } finally {
        RpcUtils.terminateRpcEndpoint(miniDispatcher, timeout);
    }
}
Also used : ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) Test(org.junit.Test)

Aggregations

ExecutionGraphInfo (org.apache.flink.runtime.scheduler.ExecutionGraphInfo)45 Test (org.junit.Test)33 ArchivedExecutionGraphBuilder (org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder)23 Time (org.apache.flink.api.common.time.Time)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 JobID (org.apache.flink.api.common.JobID)11 JobStatus (org.apache.flink.api.common.JobStatus)9 FlinkException (org.apache.flink.util.FlinkException)8 File (java.io.File)7 TestingJobManagerRunner (org.apache.flink.runtime.jobmaster.TestingJobManagerRunner)7 ArrayList (java.util.ArrayList)6 ArchivedExecutionGraph (org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph)6 FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)6 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)6 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)5 JobManagerRunner (org.apache.flink.runtime.jobmaster.JobManagerRunner)5 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)5 JobExceptionsInfoWithHistory (org.apache.flink.runtime.rest.messages.JobExceptionsInfoWithHistory)5 RootExceptionHistoryEntry (org.apache.flink.runtime.scheduler.exceptionhistory.RootExceptionHistoryEntry)5 ExceptionUtils (org.apache.flink.util.ExceptionUtils)5