Search in sources :

Example 1 with CurrentJobStatus

use of org.apache.flink.runtime.messages.JobManagerMessages.CurrentJobStatus in project flink by apache.

the class JobManagerActorTestUtils method waitForJobStatus.

/**
	 * Waits for the expected {@link JobStatus}.
	 *
	 * <p>Repeatedly queries the JobManager via {@link RequestJobStatus} messages.
	 *
	 * @param jobId             Job ID of the job to wait for
	 * @param expectedJobStatus Expected job status
	 * @param jobManager        Job manager actor to ask
	 * @param timeout           Timeout after which the operation fails
	 * @throws Exception If the job is not found within the timeout or the job is in another state.
	 */
public static void waitForJobStatus(JobID jobId, JobStatus expectedJobStatus, ActorGateway jobManager, FiniteDuration timeout) throws Exception {
    checkNotNull(jobId, "Job ID");
    checkNotNull(expectedJobStatus, "Expected job status");
    checkNotNull(jobManager, "Job manager");
    checkNotNull(timeout, "Timeout");
    final Deadline deadline = timeout.fromNow();
    while (deadline.hasTimeLeft()) {
        // Request the job status
        JobStatusResponse response = requestJobStatus(jobId, jobManager, deadline.timeLeft());
        // Found the job
        if (response instanceof CurrentJobStatus) {
            JobStatus jobStatus = ((CurrentJobStatus) response).status();
            // OK, that's what we were waiting for
            if (jobStatus == expectedJobStatus) {
                return;
            } else if (jobStatus.isGloballyTerminalState()) {
                throw new IllegalStateException("Job is in terminal state " + jobStatus + ", " + "but was waiting for " + expectedJobStatus + ".");
            }
        } else // Did not find the job... retry
        if (response instanceof JobNotFound) {
            Thread.sleep(Math.min(100, deadline.timeLeft().toMillis()));
        } else {
            throw new IllegalStateException("Unexpected response.");
        }
    }
    throw new IllegalStateException("Job not found within deadline.");
}
Also used : JobStatusResponse(org.apache.flink.runtime.messages.JobManagerMessages.JobStatusResponse) RequestJobStatus(org.apache.flink.runtime.messages.JobManagerMessages.RequestJobStatus) JobManagerMessages.getRequestJobStatus(org.apache.flink.runtime.messages.JobManagerMessages.getRequestJobStatus) JobStatus(org.apache.flink.runtime.jobgraph.JobStatus) CurrentJobStatus(org.apache.flink.runtime.messages.JobManagerMessages.CurrentJobStatus) CurrentJobStatus(org.apache.flink.runtime.messages.JobManagerMessages.CurrentJobStatus) Deadline(scala.concurrent.duration.Deadline) JobNotFound(org.apache.flink.runtime.messages.JobManagerMessages.JobNotFound)

Aggregations

JobStatus (org.apache.flink.runtime.jobgraph.JobStatus)1 CurrentJobStatus (org.apache.flink.runtime.messages.JobManagerMessages.CurrentJobStatus)1 JobNotFound (org.apache.flink.runtime.messages.JobManagerMessages.JobNotFound)1 JobStatusResponse (org.apache.flink.runtime.messages.JobManagerMessages.JobStatusResponse)1 RequestJobStatus (org.apache.flink.runtime.messages.JobManagerMessages.RequestJobStatus)1 JobManagerMessages.getRequestJobStatus (org.apache.flink.runtime.messages.JobManagerMessages.getRequestJobStatus)1 Deadline (scala.concurrent.duration.Deadline)1