Search in sources :

Example 21 with JobStatus

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

the class SnapshotMigrationTestBase method restoreAndExecute.

@SafeVarargs
protected final void restoreAndExecute(StreamExecutionEnvironment env, String snapshotPath, Tuple2<String, Integer>... expectedAccumulators) throws Exception {
    final Deadline deadLine = Deadline.fromNow(Duration.ofMinutes(5));
    ClusterClient<?> client = miniClusterResource.getClusterClient();
    // Submit the job
    JobGraph jobGraph = env.getStreamGraph().getJobGraph();
    jobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(snapshotPath));
    JobID jobID = client.submitJob(jobGraph).get();
    boolean done = false;
    while (deadLine.hasTimeLeft()) {
        try {
            CompletableFuture<JobStatus> jobStatusFuture = client.getJobStatus(jobID);
            JobStatus jobStatus = jobStatusFuture.get(5, TimeUnit.SECONDS);
            if (jobStatus == JobStatus.FAILED) {
                LOG.warn("Job reached status failed", client.requestJobResult(jobID).get().getSerializedThrowable().get().deserializeError(ClassLoader.getSystemClassLoader()));
            }
            assertNotEquals(JobStatus.FAILED, jobStatus);
        } catch (Exception e) {
            fail("Could not connect to job: " + e);
        }
        Thread.sleep(100);
        Map<String, Object> accumulators = client.getAccumulators(jobID).get();
        boolean allDone = true;
        for (Tuple2<String, Integer> acc : expectedAccumulators) {
            Object numFinished = accumulators.get(acc.f0);
            if (numFinished == null) {
                allDone = false;
                break;
            }
            if (!numFinished.equals(acc.f1)) {
                allDone = false;
                break;
            }
        }
        if (allDone) {
            done = true;
            break;
        }
    }
    if (!done) {
        fail("Did not see the expected accumulator results within time limit.");
    }
}
Also used : Deadline(org.apache.flink.api.common.time.Deadline) JobStatus(org.apache.flink.api.common.JobStatus) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobID(org.apache.flink.api.common.JobID)

Example 22 with JobStatus

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

the class WebMonitorMessagesTest method randomJobDetails.

private Collection<JobDetails> randomJobDetails(Random rnd) {
    final JobDetails[] details = new JobDetails[rnd.nextInt(10)];
    for (int k = 0; k < details.length; k++) {
        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 = new GenericMessageTester.StringInstantiator().instantiate(rnd);
        JobID jid = new JobID();
        JobStatus status = JobStatus.values()[rnd.nextInt(JobStatus.values().length)];
        details[k] = new JobDetails(jid, name, time, endTime, endTime - time, status, lastModified, numVerticesPerState, numTotal);
    }
    return Arrays.asList(details);
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) JobDetails(org.apache.flink.runtime.messages.webmonitor.JobDetails) RequestJobDetails(org.apache.flink.runtime.messages.webmonitor.RequestJobDetails) JobID(org.apache.flink.api.common.JobID)

Example 23 with JobStatus

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

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

the class AdaptiveSchedulerTest method testJobStatusListenerNotifiedOfJobStatusChanges.

@Test
public void testJobStatusListenerNotifiedOfJobStatusChanges() throws Exception {
    final JobGraph jobGraph = createJobGraph();
    final DefaultDeclarativeSlotPool declarativeSlotPool = createDeclarativeSlotPool(jobGraph.getJobID());
    final Configuration configuration = new Configuration();
    configuration.set(JobManagerOptions.RESOURCE_WAIT_TIMEOUT, Duration.ofMillis(1L));
    final CompletableFuture<Void> jobCreatedNotification = new CompletableFuture<>();
    final CompletableFuture<Void> jobRunningNotification = new CompletableFuture<>();
    final CompletableFuture<Void> jobFinishedNotification = new CompletableFuture<>();
    final CompletableFuture<JobStatus> unexpectedJobStatusNotification = new CompletableFuture<>();
    final AdaptiveScheduler scheduler = new AdaptiveSchedulerBuilder(jobGraph, singleThreadMainThreadExecutor).setJobMasterConfiguration(configuration).setJobStatusListener((jobId, newJobStatus, timestamp) -> {
        switch(newJobStatus) {
            case CREATED:
                jobCreatedNotification.complete(null);
                break;
            case RUNNING:
                jobRunningNotification.complete(null);
                break;
            case FINISHED:
                jobFinishedNotification.complete(null);
                break;
            default:
                unexpectedJobStatusNotification.complete(newJobStatus);
        }
    }).setDeclarativeSlotPool(declarativeSlotPool).build();
    final SubmissionBufferingTaskManagerGateway taskManagerGateway = new SubmissionBufferingTaskManagerGateway(1 + PARALLELISM);
    singleThreadMainThreadExecutor.execute(() -> {
        scheduler.startScheduling();
        offerSlots(declarativeSlotPool, createSlotOffersForResourceRequirements(ResourceCounter.withResource(ResourceProfile.UNKNOWN, 1)), taskManagerGateway);
    });
    // wait for the task submission
    final TaskDeploymentDescriptor submittedTask = taskManagerGateway.submittedTasks.take();
    // let the job finish
    singleThreadMainThreadExecutor.execute(() -> scheduler.updateTaskExecutionState(new TaskExecutionState(submittedTask.getExecutionAttemptId(), ExecutionState.FINISHED)));
    jobCreatedNotification.get();
    jobRunningNotification.get();
    jobFinishedNotification.get();
    assertThat(unexpectedJobStatusNotification.isDone()).isFalse();
}
Also used : CheckpointCoordinatorConfiguration(org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration) Configuration(org.apache.flink.configuration.Configuration) TaskExecutionState(org.apache.flink.runtime.taskmanager.TaskExecutionState) JobStatus(org.apache.flink.api.common.JobStatus) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobGraphTestUtils.streamingJobGraph(org.apache.flink.runtime.jobgraph.JobGraphTestUtils.streamingJobGraph) CompletableFuture(java.util.concurrent.CompletableFuture) TaskDeploymentDescriptor(org.apache.flink.runtime.deployment.TaskDeploymentDescriptor) DefaultDeclarativeSlotPool(org.apache.flink.runtime.jobmaster.slotpool.DefaultDeclarativeSlotPool) Test(org.junit.Test) ArchivedExecutionGraphTest(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraphTest) DefaultSchedulerTest(org.apache.flink.runtime.scheduler.DefaultSchedulerTest)

Example 25 with JobStatus

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

the class CancelingTestBase method runAndCancelJob.

// --------------------------------------------------------------------------------------------
protected void runAndCancelJob(Plan plan, final int msecsTillCanceling, int maxTimeTillCanceled) throws Exception {
    // submit job
    final JobGraph jobGraph = getJobGraph(plan);
    final long rpcTimeout = configuration.get(AkkaOptions.ASK_TIMEOUT_DURATION).toMillis();
    ClusterClient<?> client = CLUSTER.getClusterClient();
    JobID jobID = client.submitJob(jobGraph).get();
    Deadline submissionDeadLine = new FiniteDuration(2, TimeUnit.MINUTES).fromNow();
    JobStatus jobStatus = client.getJobStatus(jobID).get(rpcTimeout, TimeUnit.MILLISECONDS);
    while (jobStatus != JobStatus.RUNNING && submissionDeadLine.hasTimeLeft()) {
        Thread.sleep(50);
        jobStatus = client.getJobStatus(jobID).get(rpcTimeout, TimeUnit.MILLISECONDS);
    }
    if (jobStatus != JobStatus.RUNNING) {
        Assert.fail("Job not in state RUNNING.");
    }
    Thread.sleep(msecsTillCanceling);
    client.cancel(jobID).get();
    Deadline cancelDeadline = new FiniteDuration(maxTimeTillCanceled, TimeUnit.MILLISECONDS).fromNow();
    JobStatus jobStatusAfterCancel = client.getJobStatus(jobID).get(rpcTimeout, TimeUnit.MILLISECONDS);
    while (jobStatusAfterCancel != JobStatus.CANCELED && cancelDeadline.hasTimeLeft()) {
        Thread.sleep(50);
        jobStatusAfterCancel = client.getJobStatus(jobID).get(rpcTimeout, TimeUnit.MILLISECONDS);
    }
    assertEquals(JobStatus.CANCELED, jobStatusAfterCancel);
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) Deadline(scala.concurrent.duration.Deadline) FiniteDuration(scala.concurrent.duration.FiniteDuration) JobID(org.apache.flink.api.common.JobID)

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