use of com.spotify.helios.cli.JobStatusTable in project helios by spotify.
the class JobStatusCommand method run.
@Override
int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException {
final String jobIdString = options.getString(jobArg.getDest());
final String hostPattern = options.getString(hostArg.getDest());
final boolean full = options.getBoolean(fullArg.getDest());
final Map<JobId, Job> jobs;
if (Strings.isNullOrEmpty(jobIdString)) {
jobs = client.jobs().get();
} else {
jobs = client.jobs(jobIdString).get();
}
if (jobs == null) {
out.printf("The specified Helios master either returned an error or job id matcher " + "\"%s\" matched no jobs%n", jobIdString);
return 1;
}
final Set<JobId> jobIds = jobs.keySet();
if (!Strings.isNullOrEmpty(jobIdString) && jobIds.isEmpty()) {
if (json) {
out.println("{ }");
} else {
out.printf("job id matcher \"%s\" matched no jobs%n", jobIdString);
}
return 1;
}
final Map<JobId, JobStatus> statuses = Maps.newTreeMap();
statuses.putAll(client.jobStatuses(jobIds).get());
if (json) {
showJsonStatuses(out, hostPattern, jobIds, statuses);
return 0;
}
final JobStatusTable table = jobStatusTable(out, full);
final boolean noHostMatchedEver = showStatusesForHosts(hostPattern, jobIds, statuses, new HostStatusDisplayer() {
@Override
public void matchedStatus(JobStatus jobStatus, Iterable<String> matchingHosts, Map<String, TaskStatus> taskStatuses) {
displayTask(full, table, jobStatus.getJob().getId(), jobStatus, taskStatuses, matchingHosts);
}
});
if (noHostMatchedEver) {
String domainsSwitchString = "";
final List<String> domains = options.get("domains");
if (domains.size() > 0) {
domainsSwitchString = "-d " + Joiner.on(",").join(domains);
}
out.printf("There are no jobs deployed to hosts with the host pattern '%s'%n" + "Run 'helios %s hosts %s' to check your host exists and is up.%n", hostPattern, domainsSwitchString, hostPattern);
return 1;
}
table.print();
return 0;
}
Aggregations