Search in sources :

Example 1 with JobWithState

use of edu.iu.dsc.tws.common.zk.JobWithState in project twister2 by DSC-SPIDAL.

the class ZKJobLister method listJobs.

/**
 * list jobs from ZooKeeper
 */
public static void listJobs() {
    CuratorFramework client = ZKUtils.connectToServer(ZKContext.serverAddresses(config));
    String rootPath = ZKContext.rootNode(config);
    List<JobWithState> jobs;
    try {
        jobs = JobZNodeManager.getJobs(client, rootPath);
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Could not get jobs from zookeeper", e);
        return;
    }
    if (jobs.size() == 0) {
        LOG.info("\nNumber of all jobs: " + jobs.size());
        return;
    }
    int maxJobIdLength = jobs.stream().mapToInt(j -> j.getJob().getJobId().length()).max().orElseThrow(() -> new RuntimeException("No valid jobID in jobs"));
    List<JobWithState> finishedJobs = jobs.stream().filter(j -> j.finished()).collect(Collectors.toList());
    List<JobWithState> activeJobs = jobs.stream().filter(j -> j.active()).collect(Collectors.toList());
    int jobIDColumn = maxJobIdLength + 3;
    String format = "%-" + jobIDColumn + "s%-12s%s\n";
    int lineWidth = jobIDColumn + 12 + "Number of workers".length();
    String separator = StringUtils.repeat('=', lineWidth);
    StringBuilder buffer = new StringBuilder();
    Formatter f = new Formatter(buffer);
    f.format("\n\n%s", "Number of all jobs: " + jobs.size());
    f.format("\n%s", "");
    f.format("\n%s", "List of finished jobs: " + finishedJobs.size() + "\n");
    outputJobs(finishedJobs, f, format, separator);
    f.format("\n%s", "");
    f.format("\n%s", "List of active jobs: " + activeJobs.size() + "\n");
    outputJobs(activeJobs, f, format, separator);
    LOG.info(buffer.toString());
}
Also used : WorkerWithState(edu.iu.dsc.tws.common.zk.WorkerWithState) CommandLineParser(org.apache.commons.cli.CommandLineParser) SchedulerContext(edu.iu.dsc.tws.api.config.SchedulerContext) ConfigLoader(edu.iu.dsc.tws.common.config.ConfigLoader) Options(org.apache.commons.cli.Options) ZKUtils(edu.iu.dsc.tws.common.zk.ZKUtils) JobWithState(edu.iu.dsc.tws.common.zk.JobWithState) Config(edu.iu.dsc.tws.api.config.Config) ZKPersStateManager(edu.iu.dsc.tws.common.zk.ZKPersStateManager) Logger(java.util.logging.Logger) HelpFormatter(org.apache.commons.cli.HelpFormatter) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) Formatter(java.util.Formatter) Level(java.util.logging.Level) DefaultParser(org.apache.commons.cli.DefaultParser) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Context(edu.iu.dsc.tws.api.config.Context) ParseException(org.apache.commons.cli.ParseException) ZKContext(edu.iu.dsc.tws.common.zk.ZKContext) CommandLine(org.apache.commons.cli.CommandLine) JobZNodeManager(edu.iu.dsc.tws.common.zk.JobZNodeManager) Option(org.apache.commons.cli.Option) CuratorFramework(org.apache.curator.framework.CuratorFramework) HelpFormatter(org.apache.commons.cli.HelpFormatter) Formatter(java.util.Formatter) JobWithState(edu.iu.dsc.tws.common.zk.JobWithState) ParseException(org.apache.commons.cli.ParseException)

Example 2 with JobWithState

use of edu.iu.dsc.tws.common.zk.JobWithState in project twister2 by DSC-SPIDAL.

the class ZKJobLister method listJob.

/**
 * list a single job info from zk server
 * @param jobID
 */
public static void listJob(String jobID) {
    CuratorFramework client = ZKUtils.connectToServer(ZKContext.serverAddresses(config));
    String rootPath = ZKContext.rootNode(config);
    JobWithState job;
    List<WorkerWithState> workers;
    try {
        job = JobZNodeManager.readJobZNode(client, rootPath, jobID);
        workers = ZKPersStateManager.getWorkers(client, rootPath, jobID);
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Could not get the job from zookeeper: " + jobID, e);
        return;
    }
    if (workers.size() == 0) {
        LOG.info("\nNumber of workers in the job: 0");
        return;
    }
    int maxWorkerIPLength = workers.stream().mapToInt(w -> w.getInfo().getWorkerIP().length()).max().orElseThrow(() -> new RuntimeException("No valid workerIP in WorkerInfo"));
    StringBuilder buffer = new StringBuilder();
    Formatter f = new Formatter(buffer);
    f.format("\n\n%s", "JobID: " + job.getJob().getJobId());
    f.format("\n%s", "Job State: " + job.getState());
    f.format("\n%s", "Number of Workers: " + job.getJob().getNumberOfWorkers());
    f.format("\n%s", "");
    f.format("\n%s", "List of Workers: " + "\n");
    int workerIDColumn = "WorkerID".length() + 3;
    int workerIPColumn = maxWorkerIPLength + 3;
    String format = "%-" + workerIDColumn + "s%-" + workerIPColumn + "s%s\n";
    int lineWidth = workerIDColumn + workerIPColumn + "Worker State".length();
    String separator = StringUtils.repeat('=', lineWidth);
    f.format(format, "WorkerID", "WorkerIP", "Worker State");
    f.format("%s\n", separator);
    for (WorkerWithState wws : workers) {
        f.format(format, "" + wws.getWorkerID(), wws.getInfo().getWorkerIP(), wws.getState().toString());
    }
    LOG.info(buffer.toString());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) HelpFormatter(org.apache.commons.cli.HelpFormatter) Formatter(java.util.Formatter) JobWithState(edu.iu.dsc.tws.common.zk.JobWithState) WorkerWithState(edu.iu.dsc.tws.common.zk.WorkerWithState) ParseException(org.apache.commons.cli.ParseException)

Example 3 with JobWithState

use of edu.iu.dsc.tws.common.zk.JobWithState in project twister2 by DSC-SPIDAL.

the class ZKJobLister method outputJobs.

private static void outputJobs(List<JobWithState> jobs, Formatter f, String format, String separator) {
    f.format(format, "JobID", "JobState", "Number of workers");
    f.format("%s\n", separator);
    for (JobWithState jws : jobs) {
        f.format(format, jws.getJob().getJobId(), jws.getState().toString(), "" + jws.getJob().getNumberOfWorkers());
    }
}
Also used : JobWithState(edu.iu.dsc.tws.common.zk.JobWithState)

Aggregations

JobWithState (edu.iu.dsc.tws.common.zk.JobWithState)3 WorkerWithState (edu.iu.dsc.tws.common.zk.WorkerWithState)2 Formatter (java.util.Formatter)2 HelpFormatter (org.apache.commons.cli.HelpFormatter)2 ParseException (org.apache.commons.cli.ParseException)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 Config (edu.iu.dsc.tws.api.config.Config)1 Context (edu.iu.dsc.tws.api.config.Context)1 SchedulerContext (edu.iu.dsc.tws.api.config.SchedulerContext)1 ConfigLoader (edu.iu.dsc.tws.common.config.ConfigLoader)1 JobZNodeManager (edu.iu.dsc.tws.common.zk.JobZNodeManager)1 ZKContext (edu.iu.dsc.tws.common.zk.ZKContext)1 ZKPersStateManager (edu.iu.dsc.tws.common.zk.ZKPersStateManager)1 ZKUtils (edu.iu.dsc.tws.common.zk.ZKUtils)1 List (java.util.List)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1