use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.
the class TemporaryJob method port.
/**
* Returns the port that a job can be reached at given the host and name of registered port.
* This is useful to discover the value of a dynamically allocated port.
* @param host the host where the job is deployed
* @param port the name of the registered port
* @return the port where the job can be reached, or null if the host or port name is not found
*/
public Integer port(final String host, final String port) {
checkArgument(hosts.contains(host), "host %s not found", host);
checkArgument(job.getPorts().containsKey(port), "port %s not found", port);
final TaskStatus status = statuses.get(host);
if (status == null) {
return null;
}
final PortMapping portMapping = status.getPorts().get(port);
if (portMapping == null) {
return null;
}
return portMapping.getExternalPort();
}
use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.
the class TemporaryJob method awaitPort.
private void awaitPort(final String port, final String host) throws TimeoutException {
final String endpoint = endpointFromHost(host);
final TaskStatus taskStatus = statuses.get(host);
assert taskStatus != null;
final PortMapping portMapping = taskStatus.getPorts().get(port);
final Integer externalPort = portMapping.getExternalPort();
assert externalPort != null;
Polling.awaitUnchecked(TIMEOUT_MILLIS, MILLISECONDS, "Unable to connect to port " + port + " on host " + host + " within %d %s", new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
log.info("Probing: {} @ {}:{}", port, endpoint, portMapping);
final boolean up = prober.probe(endpoint, portMapping);
if (up) {
log.info("Up: {} @ {}:{}", port, endpoint, externalPort);
return true;
} else {
return null;
}
}
});
}
use of com.spotify.helios.common.descriptors.TaskStatus 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.TaskStatus in project helios by spotify.
the class JobStatusCommand method displayTask.
private void displayTask(final boolean full, final JobStatusTable table, final JobId jobId, final JobStatus jobStatus, final Map<String, TaskStatus> taskStatuses, final Iterable<String> matchingHosts) {
for (final String host : matchingHosts) {
final Map<String, Deployment> deployments = jobStatus.getDeployments();
final TaskStatus ts = taskStatuses.get(host);
final Deployment deployment = (deployments == null) ? null : deployments.get(host);
table.task(jobId, formatHostname(full, host), ts, deployment);
}
}
use of com.spotify.helios.common.descriptors.TaskStatus 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