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