use of com.spotify.helios.common.descriptors.JobStatus in project helios by spotify.
the class JobStatusCommand method showStatusesForHosts.
private boolean showStatusesForHosts(final String hostPattern, final Set<JobId> jobIds, final Map<JobId, JobStatus> statuses, final HostStatusDisplayer statusDisplayer) {
boolean noHostMatchedEver = true;
for (final JobId jobId : Ordering.natural().sortedCopy(jobIds)) {
final JobStatus jobStatus = statuses.get(jobId);
// jobStatus will be null if the job was deleted after we first got the list of job IDs
if (jobStatus == null) {
continue;
}
final Map<String, TaskStatus> taskStatuses = Maps.newTreeMap();
taskStatuses.putAll(jobStatus.getTaskStatuses());
// This will help us see hosts where jobs aren't running correctly.
for (final String host : jobStatus.getDeployments().keySet()) {
if (!taskStatuses.containsKey(host)) {
taskStatuses.put(host, null);
}
}
final FluentIterable<String> matchingHosts = FluentIterable.from(taskStatuses.keySet()).filter(containsPattern(hostPattern));
if (Strings.isNullOrEmpty(hostPattern) || !Strings.isNullOrEmpty(hostPattern) && !matchingHosts.isEmpty()) {
noHostMatchedEver = false;
}
statusDisplayer.matchedStatus(jobStatus, matchingHosts, taskStatuses);
}
return noHostMatchedEver;
}
use of com.spotify.helios.common.descriptors.JobStatus in project helios by spotify.
the class JobUndeployCommand method runWithJobId.
@Override
protected int runWithJobId(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final JobId jobId, final BufferedReader stdin) throws ExecutionException, InterruptedException, IOException {
final boolean all = options.getBoolean(allArg.getDest());
final boolean yes = options.getBoolean(yesArg.getDest());
final boolean force = options.getBoolean(forceArg.getDest());
final List<String> hosts;
if (force) {
log.warn("If you are using '--force' to skip the interactive prompt, " + "note that we have deprecated it. Please use '--yes'.");
}
if (all) {
final JobStatus status = client.jobStatus(jobId).get();
hosts = ImmutableList.copyOf(status.getDeployments().keySet());
if (hosts.isEmpty()) {
out.printf("%s is not currently deployed on any hosts.", jobId);
return 0;
}
if (!yes && !force) {
out.printf("This will undeploy %s from %s%n", jobId, hosts);
final boolean confirmed = Utils.userConfirmed(out, stdin);
if (!confirmed) {
return 1;
}
}
} else {
hosts = options.getList(hostsArg.getDest());
if (hosts.isEmpty()) {
out.println("Please either specify a list of hosts or use the -a/--all flag.");
return 1;
}
}
if (!json) {
out.printf("Undeploying %s from %s%n", jobId, hosts);
}
int code = 0;
final HostResolver resolver = HostResolver.create(client);
for (final String candidateHost : hosts) {
final String host = resolver.resolveName(candidateHost);
if (!json) {
out.printf("%s: ", host);
}
final String token = options.getString(tokenArg.getDest());
final JobUndeployResponse response = client.undeploy(jobId, host, token).get();
if (response.getStatus() == JobUndeployResponse.Status.OK) {
if (!json) {
out.println("done");
} else {
out.print(response.toJsonString());
}
} else {
if (!json) {
out.println("failed: " + response);
} else {
out.print(response.toJsonString());
}
code = -1;
}
}
return code;
}
use of com.spotify.helios.common.descriptors.JobStatus in project helios by spotify.
the class TemporaryJob method awaitUp.
private void awaitUp(final String host) throws TimeoutException {
final TemporaryJobReports.Step startContainer = reportWriter.step("start container").tag("jobId", job.getId()).tag("host", host).tag("image", job.getImage());
try {
final AtomicBoolean messagePrinted = new AtomicBoolean(false);
final TaskStatus status = Polling.awaitUnchecked(deployTimeoutMillis, MILLISECONDS, job.getId() + " was not up within %d %s", new Callable<TaskStatus>() {
@Override
public TaskStatus call() throws Exception {
final JobStatus status = Futures.getUnchecked(client.jobStatus(job.getId()));
if (status == null) {
log.debug("Job status not available");
return null;
}
final TaskStatus taskStatus = status.getTaskStatuses().get(host);
if (taskStatus == null) {
log.debug("Task status not available on {}", host);
return null;
}
if (!messagePrinted.get() && !isNullOrEmpty(jobDeployedMessageFormat) && !isNullOrEmpty(taskStatus.getContainerId())) {
outputDeployedMessage(host, taskStatus.getContainerId());
messagePrinted.set(true);
}
verifyHealthy(host, taskStatus);
final TaskStatus.State state = taskStatus.getState();
log.info("Job state of {}: {}", job.getImage(), state);
if (state == TaskStatus.State.RUNNING) {
return taskStatus;
}
return null;
}
});
statuses.put(host, status);
startContainer.markSuccess();
} finally {
startContainer.finish();
}
final TemporaryJobReports.Step probe = reportWriter.step("probe").tag("jobId", job.getId()).tag("host", host);
try {
for (final String port : waitPorts) {
awaitPort(port, host);
}
probe.markSuccess();
} finally {
probe.finish();
}
}
use of com.spotify.helios.common.descriptors.JobStatus in project helios by spotify.
the class JobListCommand method run.
@Override
int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException {
final boolean full = options.getBoolean(fullArg.getDest());
final boolean quiet = options.getBoolean(quietArg.getDest());
final String pattern = options.getString(patternArg.getDest());
final boolean deployed = options.getBoolean(deployedArg.getDest());
final Map<JobId, Job> jobs;
if (pattern == null) {
jobs = client.jobs().get();
} else {
jobs = client.jobs(pattern).get();
}
if (!Strings.isNullOrEmpty(pattern) && jobs.isEmpty()) {
if (json) {
out.println(Json.asPrettyStringUnchecked(jobs));
} else if (!quiet) {
out.printf("job pattern %s matched no jobs%n", pattern);
}
return 1;
}
final Map<JobId, JobStatus> jobStatuses = getJobStatuses(client, jobs, deployed);
final Set<JobId> sortedJobIds = Sets.newTreeSet(jobStatuses.keySet());
if (json) {
if (quiet) {
out.println(Json.asPrettyStringUnchecked(sortedJobIds));
} else {
final Map<JobId, Job> filteredJobs = Maps.newHashMap();
for (final Entry<JobId, Job> entry : jobs.entrySet()) {
if (jobStatuses.containsKey(entry.getKey())) {
filteredJobs.put(entry.getKey(), entry.getValue());
}
}
out.println(Json.asPrettyStringUnchecked(filteredJobs));
}
} else {
if (quiet) {
for (final JobId jobId : sortedJobIds) {
out.println(jobId);
}
} else {
final Table table = table(out);
table.row("JOB ID", "NAME", "VERSION", "HOSTS", "COMMAND", "ENVIRONMENT");
for (final JobId jobId : sortedJobIds) {
final Job job = jobs.get(jobId);
final String command = on(' ').join(escape(job.getCommand()));
final String env = Joiner.on(" ").withKeyValueSeparator("=").join(job.getEnv());
final JobStatus status = jobStatuses.get(jobId);
table.row(full ? jobId : jobId.toShortString(), jobId.getName(), jobId.getVersion(), status != null ? status.getDeployments().keySet().size() : 0, command, env);
}
table.print();
}
}
return 0;
}
use of com.spotify.helios.common.descriptors.JobStatus in project helios by spotify.
the class JobWatchCommand method showReport.
private static void showReport(PrintStream out, boolean exact, final List<String> prefixes, final Set<JobId> jobIds, final DateTimeFormatter formatter, final HeliosClient client) throws ExecutionException, InterruptedException {
final Map<JobId, JobStatus> statuses = client.jobStatuses(jobIds).get();
for (final JobId jobId : jobIds) {
final JobStatus jobStatus = statuses.get(jobId);
if (jobStatus == null) {
continue;
}
final Map<String, TaskStatus> taskStatuses = jobStatus.getTaskStatuses();
if (exact) {
for (final String host : prefixes) {
final TaskStatus ts = taskStatuses.get(host);
out.printf("%-20s %-30s %-8s %s%n", chop(jobId.toShortString(), 20), chop(host, 30), ts != null ? ts.getState() : "UNKNOWN", ts != null ? ts.getThrottled() : "UNKNOWN");
}
} else {
for (final String host : taskStatuses.keySet()) {
if (!hostMatches(prefixes, host)) {
continue;
}
final TaskStatus ts = taskStatuses.get(host);
out.printf("%-20s %-30s %-8s %s%n", chop(jobId.toShortString(), 20), chop(host, 30), ts.getState(), ts.getThrottled());
}
}
}
}
Aggregations