Search in sources :

Example 6 with JobStatusMessage

use of org.apache.flink.runtime.client.JobStatusMessage in project flink by apache.

the class ProcessFailureCancelingITCase method cancelRunningJob.

private void cancelRunningJob(ActorRef jobManager) throws Exception {
    final FiniteDuration askTimeout = new FiniteDuration(10, TimeUnit.SECONDS);
    // try at most for 30 seconds
    final long deadline = System.currentTimeMillis() + 30000;
    JobID jobId = null;
    do {
        Future<Object> response = Patterns.ask(jobManager, JobManagerMessages.getRequestRunningJobsStatus(), new Timeout(askTimeout));
        Object result;
        try {
            result = Await.result(response, askTimeout);
        } catch (Exception e) {
            throw new Exception("Could not retrieve running jobs from the JobManager.", e);
        }
        if (result instanceof JobManagerMessages.RunningJobsStatus) {
            List<JobStatusMessage> jobs = ((JobManagerMessages.RunningJobsStatus) result).getStatusMessages();
            if (jobs.size() == 1) {
                jobId = jobs.get(0).getJobId();
                break;
            }
        }
    } while (System.currentTimeMillis() < deadline);
    if (jobId == null) {
        // we never found it running, must have failed already
        return;
    }
    // tell the JobManager to cancel the job
    jobManager.tell(new JobManagerMessages.CancelJob(jobId), ActorRef.noSender());
}
Also used : Timeout(akka.util.Timeout) JobStatusMessage(org.apache.flink.runtime.client.JobStatusMessage) JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) FiniteDuration(scala.concurrent.duration.FiniteDuration) JobID(org.apache.flink.api.common.JobID) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

JobStatusMessage (org.apache.flink.runtime.client.JobStatusMessage)6 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)4 JobManagerMessages (org.apache.flink.runtime.messages.JobManagerMessages)4 JobID (org.apache.flink.api.common.JobID)3 RunningJobsStatus (org.apache.flink.runtime.messages.JobManagerMessages.RunningJobsStatus)3 FiniteDuration (scala.concurrent.duration.FiniteDuration)3 Timeout (akka.util.Timeout)2 IOException (java.io.IOException)2 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)2 ActorRef (akka.actor.ActorRef)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 TimeoutException (java.util.concurrent.TimeoutException)1 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)1 CliArgsException (org.apache.flink.client.cli.CliArgsException)1 ListOptions (org.apache.flink.client.cli.ListOptions)1