Search in sources :

Example 31 with TaskStatus

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();
}
Also used : PortMapping(com.spotify.helios.common.descriptors.PortMapping) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus)

Example 32 with TaskStatus

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;
            }
        }
    });
}
Also used : PortMapping(com.spotify.helios.common.descriptors.PortMapping) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 33 with TaskStatus

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();
    }
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThrottleState(com.spotify.helios.common.descriptors.ThrottleState) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 34 with TaskStatus

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);
    }
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus)

Example 35 with TaskStatus

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());
            }
        }
    }
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId)

Aggregations

TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)53 JobId (com.spotify.helios.common.descriptors.JobId)40 Test (org.junit.Test)27 DockerClient (com.spotify.docker.client.DockerClient)18 Deployment (com.spotify.helios.common.descriptors.Deployment)15 Job (com.spotify.helios.common.descriptors.Job)14 HeliosClient (com.spotify.helios.client.HeliosClient)13 LogStream (com.spotify.docker.client.LogStream)10 HostStatus (com.spotify.helios.common.descriptors.HostStatus)10 JobStatus (com.spotify.helios.common.descriptors.JobStatus)8 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)7 PortMapping (com.spotify.helios.common.descriptors.PortMapping)6 Map (java.util.Map)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 TaskStatusEvent (com.spotify.helios.common.descriptors.TaskStatusEvent)4 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)4 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4