Search in sources :

Example 41 with JobStatus

use of org.apache.flink.api.common.JobStatus in project flink by apache.

the class AbstractHAJobRunITCase method testJobExecutionInHaMode.

@Test
public void testJobExecutionInHaMode(@InjectMiniCluster MiniCluster flinkCluster) throws Exception {
    final JobGraph jobGraph = JobGraphTestUtils.singleNoOpJobGraph();
    // providing a timeout helps making the test fail in case some issue occurred while
    // initializing the cluster
    flinkCluster.submitJob(jobGraph).get(30, TimeUnit.SECONDS);
    final Deadline deadline = Deadline.fromNow(Duration.ofSeconds(30));
    final JobStatus jobStatus = FutureUtils.retrySuccessfulWithDelay(() -> flinkCluster.getJobStatus(jobGraph.getJobID()), Time.milliseconds(10), deadline, status -> flinkCluster.isRunning() && status == JobStatus.FINISHED, TestingUtils.defaultScheduledExecutor()).get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
    assertThat(jobStatus).isEqualTo(JobStatus.FINISHED);
    runAfterJobTermination();
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) Deadline(org.apache.flink.api.common.time.Deadline) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Configuration(org.apache.flink.configuration.Configuration) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobStatus(org.apache.flink.api.common.JobStatus) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) TestingUtils(org.apache.flink.testutils.TestingUtils) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) AllCallbackWrapper(org.apache.flink.core.testutils.AllCallbackWrapper) FileSystem(org.apache.flink.core.fs.FileSystem) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) InjectMiniCluster(org.apache.flink.test.junit5.InjectMiniCluster) Duration(java.time.Duration) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) Time(org.apache.flink.api.common.time.Time) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) ZooKeeperExtension(org.apache.flink.runtime.zookeeper.ZooKeeperExtension) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) Deadline(org.apache.flink.api.common.time.Deadline) Test(org.junit.jupiter.api.Test)

Example 42 with JobStatus

use of org.apache.flink.api.common.JobStatus in project flink by apache.

the class WebMonitorMessagesTest method testJobDetailsMessage.

@Test
public void testJobDetailsMessage() {
    try {
        final Random rnd = new Random();
        int[] numVerticesPerState = new int[ExecutionState.values().length];
        int numTotal = 0;
        for (int i = 0; i < numVerticesPerState.length; i++) {
            int count = rnd.nextInt(55);
            numVerticesPerState[i] = count;
            numTotal += count;
        }
        long time = rnd.nextLong();
        long endTime = rnd.nextBoolean() ? -1L : time + rnd.nextInt();
        long lastModified = endTime == -1 ? time + rnd.nextInt() : endTime;
        String name = GenericMessageTester.randomString(rnd);
        JobID jid = GenericMessageTester.randomJobId(rnd);
        JobStatus status = GenericMessageTester.randomJobStatus(rnd);
        JobDetails msg1 = new JobDetails(jid, name, time, endTime, endTime - time, status, lastModified, numVerticesPerState, numTotal);
        JobDetails msg2 = new JobDetails(jid, name, time, endTime, endTime - time, status, lastModified, numVerticesPerState, numTotal);
        GenericMessageTester.testMessageInstances(msg1, msg2);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) Random(java.util.Random) JobID(org.apache.flink.api.common.JobID) JobDetails(org.apache.flink.runtime.messages.webmonitor.JobDetails) RequestJobDetails(org.apache.flink.runtime.messages.webmonitor.RequestJobDetails) Test(org.junit.Test)

Example 43 with JobStatus

use of org.apache.flink.api.common.JobStatus in project flink by apache.

the class Dispatcher method requestClusterOverview.

@Override
public CompletableFuture<ClusterOverview> requestClusterOverview(Time timeout) {
    CompletableFuture<ResourceOverview> taskManagerOverviewFuture = runResourceManagerCommand(resourceManagerGateway -> resourceManagerGateway.requestResourceOverview(timeout));
    final List<CompletableFuture<Optional<JobStatus>>> optionalJobInformation = queryJobMastersForInformation(jobManagerRunner -> jobManagerRunner.requestJobStatus(timeout));
    CompletableFuture<Collection<Optional<JobStatus>>> allOptionalJobsFuture = FutureUtils.combineAll(optionalJobInformation);
    CompletableFuture<Collection<JobStatus>> allJobsFuture = allOptionalJobsFuture.thenApply(this::flattenOptionalCollection);
    final JobsOverview completedJobsOverview = executionGraphInfoStore.getStoredJobsOverview();
    return allJobsFuture.thenCombine(taskManagerOverviewFuture, (Collection<JobStatus> runningJobsStatus, ResourceOverview resourceOverview) -> {
        final JobsOverview allJobsOverview = JobsOverview.create(runningJobsStatus).combine(completedJobsOverview);
        return new ClusterOverview(resourceOverview, allJobsOverview);
    });
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) CompletableFuture(java.util.concurrent.CompletableFuture) ClusterOverview(org.apache.flink.runtime.messages.webmonitor.ClusterOverview) Collection(java.util.Collection) ResourceOverview(org.apache.flink.runtime.resourcemanager.ResourceOverview) JobsOverview(org.apache.flink.runtime.messages.webmonitor.JobsOverview)

Example 44 with JobStatus

use of org.apache.flink.api.common.JobStatus 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 45 with JobStatus

use of org.apache.flink.api.common.JobStatus in project flink by apache.

the class FileExecutionGraphInfoStore method put.

@Override
public void put(ExecutionGraphInfo executionGraphInfo) throws IOException {
    final JobID jobId = executionGraphInfo.getJobId();
    final ArchivedExecutionGraph archivedExecutionGraph = executionGraphInfo.getArchivedExecutionGraph();
    final JobStatus jobStatus = archivedExecutionGraph.getState();
    final String jobName = archivedExecutionGraph.getJobName();
    Preconditions.checkArgument(jobStatus.isTerminalState(), "The job " + jobName + '(' + jobId + ") is not in a terminal state. Instead it is in state " + jobStatus + '.');
    switch(jobStatus) {
        case FINISHED:
            numFinishedJobs++;
            break;
        case CANCELED:
            numCanceledJobs++;
            break;
        case FAILED:
            numFailedJobs++;
            break;
        case SUSPENDED:
            break;
        default:
            throw new IllegalStateException("The job " + jobName + '(' + jobId + ") should have been in a known terminal state. " + "Instead it was in state " + jobStatus + '.');
    }
    // write the ArchivedExecutionGraph to disk
    storeExecutionGraphInfo(executionGraphInfo);
    final JobDetails detailsForJob = JobDetails.createDetailsForJob(archivedExecutionGraph);
    jobDetailsCache.put(jobId, detailsForJob);
    executionGraphInfoCache.put(jobId, executionGraphInfo);
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) JobID(org.apache.flink.api.common.JobID) JobDetails(org.apache.flink.runtime.messages.webmonitor.JobDetails)

Aggregations

JobStatus (org.apache.flink.api.common.JobStatus)62 Test (org.junit.Test)28 JobID (org.apache.flink.api.common.JobID)19 CompletableFuture (java.util.concurrent.CompletableFuture)15 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)14 FlinkException (org.apache.flink.util.FlinkException)8 ExecutionException (java.util.concurrent.ExecutionException)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Time (org.apache.flink.api.common.time.Time)6 ExecutionGraphInfo (org.apache.flink.runtime.scheduler.ExecutionGraphInfo)6 TaskExecutionState (org.apache.flink.runtime.taskmanager.TaskExecutionState)6 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5 ExecutionState (org.apache.flink.runtime.execution.ExecutionState)5 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)5 TimeUnit (java.util.concurrent.TimeUnit)4 Configuration (org.apache.flink.configuration.Configuration)4 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)4 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)4