Search in sources :

Example 1 with JobStatus

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

the class MultipleHostsTest method testFilteringJobAndHostStatuses.

@Test
public void testFilteringJobAndHostStatuses() throws Exception {
    final String aHost = testHost() + "a";
    final String bHost = testHost() + "b";
    startDefaultMaster();
    startDefaultAgent(aHost);
    startDefaultAgent(bHost);
    awaitHostStatus(aHost, UP, LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(bHost, UP, LONG_WAIT_SECONDS, SECONDS);
    final HeliosClient client = defaultClient();
    final Job job = Job.newBuilder().setName(testJobName + "I_WANT_THIS_ONE").setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId jobId = job.getId();
    client.createJob(job).get();
    final Job job2 = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId jobId2 = job2.getId();
    client.createJob(job2).get();
    final Deployment deployment = Deployment.of(jobId, Goal.START);
    client.deploy(deployment, aHost);
    client.deploy(deployment, bHost);
    client.deploy(Deployment.of(jobId2, Goal.START), aHost);
    awaitJobState(client, aHost, jobId, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
    awaitJobState(client, bHost, jobId, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
    awaitJobState(client, aHost, jobId2, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
    final Map<JobId, JobStatus> cliStatuses = new ObjectMapper().readValue(cli("status", "--job", "I_WANT_THIS_ONE", "--host", aHost, "--json"), new TypeReference<Map<JobId, JobStatus>>() {
    });
    assertEquals("status should only have one job", 1, cliStatuses.size());
    assertTrue(cliStatuses.containsKey(jobId));
    final JobStatus status = cliStatuses.get(jobId);
    assertEquals("deployments should have only one item", 1, status.getDeployments().size());
    assertTrue("should only have deployment info for aHost", status.getDeployments().containsKey(aHost));
    assertEquals("Task statuses should only have one item", 1, status.getTaskStatuses().size());
    assertTrue("should only have status info for aHost", status.getTaskStatuses().containsKey(aHost));
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) Deployment(com.spotify.helios.common.descriptors.Deployment) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) Map(java.util.Map) JobId(com.spotify.helios.common.descriptors.JobId) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with JobStatus

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

the class SystemTestBase method deployJob.

protected void deployJob(final JobId jobId, final String host, final String token) throws Exception {
    final List<String> deployArgs = Lists.newArrayList(jobId.toString(), host);
    if (token != null) {
        deployArgs.addAll(ImmutableList.of("--token", token));
    }
    final String deployOutput = cli("deploy", deployArgs);
    assertThat(deployOutput, containsString(host + ": done"));
    final String output = cli("status", "--host", host, "--json");
    final Map<JobId, JobStatus> statuses = Json.readUnchecked(output, new TypeReference<Map<JobId, JobStatus>>() {
    });
    assertTrue(statuses.keySet().contains(jobId));
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) Integer.toHexString(java.lang.Integer.toHexString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) JobId(com.spotify.helios.common.descriptors.JobId)

Example 3 with JobStatus

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

the class DeploymentGroupTest method testStoppedJob.

@Test
public void testStoppedJob() throws Exception {
    final String host = testHost();
    startDefaultAgent(host, "--labels", TEST_LABEL);
    // Wait for agent to come up
    final HeliosClient client = defaultClient();
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Create the deployment group and two jobs
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    final JobId firstJobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    final String secondJobVersion = randomHexString();
    final String secondJobNameAndVersion = testJobName + ":" + secondJobVersion;
    final JobId secondJobId = createJob(testJobName, secondJobVersion, BUSYBOX, IDLE_COMMAND);
    // Trigger a rolling update of the first job
    cli("rolling-update", "--async", testJobNameAndVersion, TEST_GROUP);
    awaitTaskState(firstJobId, host, TaskStatus.State.RUNNING);
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    // Stop the job
    cli("stop", testJobNameAndVersion, host);
    awaitTaskState(firstJobId, host, TaskStatus.State.STOPPED);
    // Trigger a rolling update, replacing the first job with the second.
    // Verify the first job is undeployed and the second job is running.
    cli("rolling-update", "--async", secondJobNameAndVersion, TEST_GROUP);
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(secondJobId, host, TaskStatus.State.RUNNING);
    final JobStatus status = client.jobStatus(firstJobId).get();
    assertThat(status.getDeployments().isEmpty(), is(true));
    // Stop the job
    cli("stop", secondJobNameAndVersion, host);
    awaitTaskState(secondJobId, host, TaskStatus.State.STOPPED);
    // Trigger a rolling update of the same job, and verify the job gets started. This takes
    // a different code path than when replacing a different job, which we tested above.
    cli("rolling-update", "--async", secondJobNameAndVersion, TEST_GROUP);
    awaitTaskState(secondJobId, host, TaskStatus.State.RUNNING);
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) HeliosClient(com.spotify.helios.client.HeliosClient) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 4 with JobStatus

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

the class ExpiredJobReaperTest method testExpiredJobReaper.

@Test
public void testExpiredJobReaper() throws Exception {
    when(mockClock.now()).thenReturn(new Instant(CURRENT_TS));
    when(masterModel.getJobs()).thenReturn(JOBS);
    when(masterModel.getJobStatus(any(JobId.class))).then(new Answer<JobStatus>() {

        @Override
        public JobStatus answer(final InvocationOnMock invocation) throws Throwable {
            final JobId jobId = (JobId) invocation.getArguments()[0];
            final Map<String, Deployment> deployments = ImmutableMap.of("hostA", Deployment.of(jobId, Goal.START), "hostB", Deployment.of(jobId, Goal.START));
            return JobStatus.newBuilder().setJob(JOBS.get(jobId)).setDeployments(deployments).build();
        }
    });
    ExpiredJobReaper.newBuilder().setClock(mockClock).setMasterModel(masterModel).build().runOneIteration();
    // Make sure that the expiring job was removed, but that the non-expiring job
    // and the job that expires far in the future were not.
    verify(masterModel).undeployJob(eq("hostA"), eq(EXPIRING_JOB_ID), eq(""));
    verify(masterModel).undeployJob(eq("hostB"), eq(EXPIRING_JOB_ID), eq(""));
    verify(masterModel).removeJob(eq(EXPIRING_JOB_ID), eq(""));
    verifyNoMoreInteractions(ignoreStubs(masterModel));
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Instant(org.joda.time.Instant) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 5 with JobStatus

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

the class TemporaryJob method verifyHealthy.

void verifyHealthy() throws AssertionError {
    log.debug("Checking health of {}", job.getImage());
    final JobStatus status = Futures.getUnchecked(client.jobStatus(job.getId()));
    if (status == null) {
        return;
    }
    for (final Map.Entry<String, TaskStatus> entry : status.getTaskStatuses().entrySet()) {
        verifyHealthy(entry.getKey(), entry.getValue());
    }
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

JobStatus (com.spotify.helios.common.descriptors.JobStatus)23 JobId (com.spotify.helios.common.descriptors.JobId)19 Job (com.spotify.helios.common.descriptors.Job)11 Test (org.junit.Test)9 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)8 HeliosClient (com.spotify.helios.client.HeliosClient)6 Map (java.util.Map)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 Deployment (com.spotify.helios.common.descriptors.Deployment)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 IOException (java.io.IOException)3 PortMapping (com.spotify.helios.common.descriptors.PortMapping)2 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)2 TaskStatusEvent (com.spotify.helios.common.descriptors.TaskStatusEvent)2 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)2 Integer.toHexString (java.lang.Integer.toHexString)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1