Search in sources :

Example 36 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class VolumeTest method assertVolumes.

public void assertVolumes(final JobId jobId) throws Exception {
    // Wait for agent to come up
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Deploy the job on the agent
    final Deployment deployment = Deployment.of(jobId, START);
    final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
    // Wait for the job to run
    final TaskStatus taskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    assertJobEquals(job, taskStatus.getJob());
    final Integer barPort = taskStatus.getPorts().get("bar").getExternalPort();
    final Integer hostnamePort = taskStatus.getPorts().get("hostname").getExternalPort();
    assert barPort != null;
    assert hostnamePort != null;
    // Read "foo" from /volume/bar
    final String foo = recvUtf8(barPort, 3);
    assertEquals("foo", foo);
    // Read hostname from /hostname
    final String hostname = getNewDockerClient().info().name();
    final String mountedHostname = recvUtf8(hostnamePort, hostname.length());
    assertEquals(hostname, mountedHostname);
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse)

Example 37 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class ZooKeeperClusterIdTest method testAgent.

@Test
public void testAgent() throws Exception {
    startDefaultMaster("--zk-cluster-id=" + zkClusterId);
    startDefaultAgent(testHost(), "--zk-cluster-id=" + zkClusterId);
    awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Create job and deploy it
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    deployJob(jobId, testHost());
    final TaskStatus runningStatus = awaitTaskState(jobId, testHost(), RUNNING);
    final String containerId = runningStatus.getContainerId();
    // Delete the config node which contains the cluster ID and all the job definitions
    zk().curatorWithSuperAuth().delete().deletingChildrenIfNeeded().forPath("/config");
    // Sleep for a second so agent has a chance to react to deletion
    Thread.sleep(1000);
    // Make sure the agent didn't stop the job
    try (final DockerClient docker = getNewDockerClient()) {
        final List<Container> containers = docker.listContainers();
        final CustomTypeSafeMatcher<Container> containerIdMatcher = new CustomTypeSafeMatcher<Container>("Container with id " + containerId) {

            @Override
            protected boolean matchesSafely(Container container) {
                return container.id().equals(containerId);
            }
        };
        assertContainersMatch(containers, containerIdMatcher);
    }
}
Also used : Container(com.spotify.docker.client.messages.Container) DockerClient(com.spotify.docker.client.DockerClient) CustomTypeSafeMatcher(org.hamcrest.CustomTypeSafeMatcher) Matchers.containsString(org.hamcrest.Matchers.containsString) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 38 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class Agent method createSupervisor.

/**
   * Create a job supervisor.
   *
   * @param job The job .
   */
private Supervisor createSupervisor(final Job job, final Map<String, Integer> portAllocation) {
    log.debug("creating job supervisor: {}", job);
    final TaskStatus taskStatus = model.getTaskStatus(job.getId());
    final String containerId = (taskStatus == null) ? null : taskStatus.getContainerId();
    final Supervisor supervisor = supervisorFactory.create(job, containerId, portAllocation, supervisorListener);
    supervisors.put(job.getId(), supervisor);
    return supervisor;
}
Also used : TaskStatus(com.spotify.helios.common.descriptors.TaskStatus)

Example 39 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class ZooKeeperAgentModel method getTaskStatuses.

/**
   * Returns the {@link TaskStatus}es for all tasks assigned to the current agent.
   */
@Override
public Map<JobId, TaskStatus> getTaskStatuses() {
    final Map<JobId, TaskStatus> statuses = Maps.newHashMap();
    for (final Map.Entry<String, byte[]> entry : this.taskStatuses.entrySet()) {
        try {
            final JobId id = JobId.fromString(entry.getKey());
            final TaskStatus status = Json.read(entry.getValue(), TaskStatus.class);
            statuses.put(id, status);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    }
    return statuses;
}
Also used : IOException(java.io.IOException) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) Map(java.util.Map) JobId(com.spotify.helios.common.descriptors.JobId)

Example 40 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class DefaultStatusUpdater method update.

@Override
public void update() throws InterruptedException {
    final TaskStatus status = builder.setGoal(goal).setState(state).setContainerId(containerId).setThrottled(throttleState).setContainerError(containerError).build();
    model.setTaskStatus(status.getJob().getId(), status);
}
Also used : TaskStatus(com.spotify.helios.common.descriptors.TaskStatus)

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