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.");
}
Aggregations