Search in sources :

Example 1 with RequestJobStatus

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

the class JobManagerActorTestUtils method requestJobStatus.

/**
	 * Request a {@link JobStatusResponse}.
	 *
	 * @param jobId      Job ID of the job to request the status of
	 * @param jobManager Job manager actor to ask
	 * @param timeout    Timeout after which the operation fails
	 * @return The {@link JobStatusResponse} from the job manager
	 * @throws Exception If there is no answer within the timeout.
	 */
public static JobStatusResponse requestJobStatus(JobID jobId, ActorGateway jobManager, FiniteDuration timeout) throws Exception {
    checkNotNull(jobId, "Job ID");
    checkNotNull(jobManager, "Job manager");
    checkNotNull(timeout, "Timeout");
    // Ask the JobManager
    RequestJobStatus request = (RequestJobStatus) getRequestJobStatus(jobId);
    Future<Object> ask = jobManager.ask(request, timeout);
    Object response = Await.result(ask, timeout);
    if (response instanceof JobStatusResponse) {
        return (JobStatusResponse) response;
    }
    throw new IllegalStateException("Unexpected response.");
}
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)

Example 2 with RequestJobStatus

use of org.apache.flink.runtime.messages.JobManagerMessages.RequestJobStatus 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

JobStatusResponse (org.apache.flink.runtime.messages.JobManagerMessages.JobStatusResponse)2 RequestJobStatus (org.apache.flink.runtime.messages.JobManagerMessages.RequestJobStatus)2 JobManagerMessages.getRequestJobStatus (org.apache.flink.runtime.messages.JobManagerMessages.getRequestJobStatus)2 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 Deadline (scala.concurrent.duration.Deadline)1