Search in sources :

Example 1 with RunningJobsStatus

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

the class CliFrontend method list.

/**
	 * Executes the list action.
	 * 
	 * @param args Command line arguments for the list action.
	 */
protected int list(String[] args) {
    LOG.info("Running 'list' command.");
    ListOptions options;
    try {
        options = CliFrontendParser.parseListCommand(args);
    } catch (CliArgsException e) {
        return handleArgException(e);
    } catch (Throwable t) {
        return handleError(t);
    }
    // evaluate help flag
    if (options.isPrintHelp()) {
        CliFrontendParser.printHelpForList();
        return 0;
    }
    boolean running = options.getRunning();
    boolean scheduled = options.getScheduled();
    // print running and scheduled jobs if not option supplied
    if (!running && !scheduled) {
        running = true;
        scheduled = true;
    }
    try {
        ActorGateway jobManagerGateway = getJobManagerGateway(options);
        LOG.info("Connecting to JobManager to retrieve list of jobs");
        Future<Object> response = jobManagerGateway.ask(JobManagerMessages.getRequestRunningJobsStatus(), clientTimeout);
        Object result;
        try {
            result = Await.result(response, clientTimeout);
        } catch (Exception e) {
            throw new Exception("Could not retrieve running jobs from the JobManager.", e);
        }
        if (result instanceof RunningJobsStatus) {
            LOG.info("Successfully retrieved list of jobs");
            List<JobStatusMessage> jobs = ((RunningJobsStatus) result).getStatusMessages();
            ArrayList<JobStatusMessage> runningJobs = null;
            ArrayList<JobStatusMessage> scheduledJobs = null;
            if (running) {
                runningJobs = new ArrayList<JobStatusMessage>();
            }
            if (scheduled) {
                scheduledJobs = new ArrayList<JobStatusMessage>();
            }
            for (JobStatusMessage rj : jobs) {
                if (running && (rj.getJobState().equals(JobStatus.RUNNING) || rj.getJobState().equals(JobStatus.RESTARTING))) {
                    runningJobs.add(rj);
                }
                if (scheduled && rj.getJobState().equals(JobStatus.CREATED)) {
                    scheduledJobs.add(rj);
                }
            }
            SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            Comparator<JobStatusMessage> njec = new Comparator<JobStatusMessage>() {

                @Override
                public int compare(JobStatusMessage o1, JobStatusMessage o2) {
                    return (int) (o1.getStartTime() - o2.getStartTime());
                }
            };
            if (running) {
                if (runningJobs.size() == 0) {
                    System.out.println("No running jobs.");
                } else {
                    Collections.sort(runningJobs, njec);
                    System.out.println("------------------ Running/Restarting Jobs -------------------");
                    for (JobStatusMessage rj : runningJobs) {
                        System.out.println(df.format(new Date(rj.getStartTime())) + " : " + rj.getJobId() + " : " + rj.getJobName() + " (" + rj.getJobState() + ")");
                    }
                    System.out.println("--------------------------------------------------------------");
                }
            }
            if (scheduled) {
                if (scheduledJobs.size() == 0) {
                    System.out.println("No scheduled jobs.");
                } else {
                    Collections.sort(scheduledJobs, njec);
                    System.out.println("----------------------- Scheduled Jobs -----------------------");
                    for (JobStatusMessage rj : scheduledJobs) {
                        System.out.println(df.format(new Date(rj.getStartTime())) + " : " + rj.getJobId() + " : " + rj.getJobName());
                    }
                    System.out.println("--------------------------------------------------------------");
                }
            }
            return 0;
        } else {
            throw new Exception("ReqeustRunningJobs requires a response of type " + "RunningJobs. Instead the response is of type " + result.getClass() + ".");
        }
    } catch (Throwable t) {
        return handleError(t);
    }
}
Also used : ListOptions(org.apache.flink.client.cli.ListOptions) CliArgsException(org.apache.flink.client.cli.CliArgsException) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ProgramMissingJobException(org.apache.flink.client.program.ProgramMissingJobException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) ProgramParametrizationException(org.apache.flink.client.program.ProgramParametrizationException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) CliArgsException(org.apache.flink.client.cli.CliArgsException) IOException(java.io.IOException) Date(java.util.Date) Comparator(java.util.Comparator) RunningJobsStatus(org.apache.flink.runtime.messages.JobManagerMessages.RunningJobsStatus) JobStatusMessage(org.apache.flink.runtime.client.JobStatusMessage) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with RunningJobsStatus

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

the class FlinkClient method getTopologyJobId.

// Flink specific additional methods
/**
	 * Package internal method to get a Flink {@link JobID} from a Storm topology name.
	 *
	 * @param id
	 * 		The Storm topology name.
	 * @return Flink's internally used {@link JobID}.
	 */
JobID getTopologyJobId(final String id) {
    final Configuration configuration = GlobalConfiguration.loadConfiguration();
    if (this.timeout != null) {
        configuration.setString(ConfigConstants.AKKA_ASK_TIMEOUT, this.timeout);
    }
    try {
        final ActorRef jobManager = this.getJobManager();
        final FiniteDuration askTimeout = this.getTimeout();
        final Future<Object> response = Patterns.ask(jobManager, JobManagerMessages.getRequestRunningJobsStatus(), new Timeout(askTimeout));
        final Object result;
        try {
            result = Await.result(response, askTimeout);
        } catch (final Exception e) {
            throw new RuntimeException("Could not retrieve running jobs from the JobManager", e);
        }
        if (result instanceof RunningJobsStatus) {
            final List<JobStatusMessage> jobs = ((RunningJobsStatus) result).getStatusMessages();
            for (final JobStatusMessage status : jobs) {
                if (status.getJobName().equals(id)) {
                    return status.getJobId();
                }
            }
        } else {
            throw new RuntimeException("ReqeustRunningJobs requires a response of type " + "RunningJobs. Instead the response is of type " + result.getClass() + ".");
        }
    } catch (final IOException e) {
        throw new RuntimeException("Could not connect to Flink JobManager with address " + this.jobManagerHost + ":" + this.jobManagerPort, e);
    }
    return null;
}
Also used : RunningJobsStatus(org.apache.flink.runtime.messages.JobManagerMessages.RunningJobsStatus) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) JobStatusMessage(org.apache.flink.runtime.client.JobStatusMessage) FiniteDuration(scala.concurrent.duration.FiniteDuration) IOException(java.io.IOException) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) IOException(java.io.IOException) NotAliveException(org.apache.storm.generated.NotAliveException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException)

Aggregations

IOException (java.io.IOException)2 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)2 JobStatusMessage (org.apache.flink.runtime.client.JobStatusMessage)2 RunningJobsStatus (org.apache.flink.runtime.messages.JobManagerMessages.RunningJobsStatus)2 ActorRef (akka.actor.ActorRef)1 Timeout (akka.util.Timeout)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 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)1 CliArgsException (org.apache.flink.client.cli.CliArgsException)1 ListOptions (org.apache.flink.client.cli.ListOptions)1 ProgramMissingJobException (org.apache.flink.client.program.ProgramMissingJobException)1 ProgramParametrizationException (org.apache.flink.client.program.ProgramParametrizationException)1 Configuration (org.apache.flink.configuration.Configuration)1 GlobalConfiguration (org.apache.flink.configuration.GlobalConfiguration)1 IllegalConfigurationException (org.apache.flink.configuration.IllegalConfigurationException)1 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)1