Search in sources :

Example 91 with JobId

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

the class ImageMissingTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());
    final HeliosClient client = defaultClient();
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    final JobId jobId = createJob(testJobName, testJobVersion, "this_sould_not_exist", ImmutableList.of("/bin/true"));
    deployJob(jobId, testHost());
    awaitJobThrottle(client, testHost(), jobId, IMAGE_MISSING, LONG_WAIT_SECONDS, SECONDS);
    final HostStatus hostStatus = client.hostStatus(testHost()).get();
    final TaskStatus taskStatus = hostStatus.getStatuses().get(jobId);
    assertEquals(TaskStatus.State.FAILED, taskStatus.getState());
}
Also used : HostStatus(com.spotify.helios.common.descriptors.HostStatus) HeliosClient(com.spotify.helios.client.HeliosClient) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 92 with JobId

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

the class JobHistoryTest method testJobHistoryDisabled.

@Test
public void testJobHistoryDisabled() throws Exception {
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost(), "--disable-job-history");
    awaitHostStatus(testHost(), Status.UP, LONG_WAIT_SECONDS, SECONDS);
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    deployJob(jobId, testHost());
    awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    undeployJob(jobId, testHost());
    awaitTaskGone(client, testHost(), jobId, LONG_WAIT_SECONDS, SECONDS);
}
Also used : HeliosClient(com.spotify.helios.client.HeliosClient) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 93 with JobId

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

the class JobHistoryTest method testJobHistory.

@Test
public void testJobHistory() throws Exception {
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost());
    awaitHostStatus(testHost(), Status.UP, LONG_WAIT_SECONDS, SECONDS);
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    deployJob(jobId, testHost());
    awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    undeployJob(jobId, testHost());
    awaitTaskGone(client, testHost(), jobId, LONG_WAIT_SECONDS, SECONDS);
    final TaskStatusEvents events = Polling.await(WAIT_TIMEOUT_SECONDS, SECONDS, new Callable<TaskStatusEvents>() {

        @Override
        public TaskStatusEvents call() throws Exception {
            final TaskStatusEvents events = client.jobHistory(jobId).get();
            final int size = events.getEvents().size();
            if (size == 0) {
                return null;
            }
            // We sometimes get more than one PULLING_IMAGE in the history if a pull tempfails.
            int requiredEventCount = -1;
            for (int i = 0; i < size; i++) {
                if (events.getEvents().get(i).getStatus().getState() != State.PULLING_IMAGE) {
                    requiredEventCount = i + 5;
                    break;
                }
            }
            if (requiredEventCount == -1) {
                return null;
            }
            if (size < requiredEventCount) {
                return null;
            }
            return events;
        }
    });
    final ListIterator<TaskStatusEvent> it = events.getEvents().listIterator();
    while (true) {
        final TaskStatusEvent event = it.next();
        if (event.getStatus().getState() != State.PULLING_IMAGE) {
            //rewind so that this event is the one returned by the next call to it.next() below
            it.previous();
            break;
        }
        assertThat(event, not(hasContainerId()));
    }
    assertThat(it.next(), allOf(hasState(State.CREATING), not(hasContainerId())));
    assertThat(it.next(), allOf(hasState(State.STARTING), hasContainerId()));
    assertThat(it.next(), hasState(State.RUNNING));
    assertThat(it.next(), hasState(State.STOPPING));
    assertThat(it.next(), hasState(State.EXITED, State.STOPPED));
}
Also used : TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) TaskStatusEvents(com.spotify.helios.common.protocol.TaskStatusEvents) HeliosClient(com.spotify.helios.client.HeliosClient) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 94 with JobId

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

the class JobListTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());
    awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Create job
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    // Test successful find
    // testJobName is of the form job_test_hexstring:vhexstring
    final String result1 = cli("jobs", "ob_", "--json");
    final Map<String, Object> resultObj1 = OBJECT_MAPPER.readValue(result1, MAP_TYPE);
    assertFalse(resultObj1.isEmpty());
    final Entry<String, Object> firstEntry = get(resultObj1.entrySet(), 0);
    assertEquals(jobId.toString(), firstEntry.getKey());
    // Test didn't find
    final String result2 = cli("jobs", "FramAZaMaWonTF1nD", "--json");
    final Map<String, Object> resultObj2 = OBJECT_MAPPER.readValue(result2, MAP_TYPE);
    // It might conceivably get here at some point, but better be empty if it does
    assertTrue(resultObj2.isEmpty());
    final String result3 = cli("jobs", "-y", "--json");
    final Map<String, Object> resultObj3 = OBJECT_MAPPER.readValue(result3, MAP_TYPE);
    assertTrue("Expected empty map but got: " + result3, resultObj3.isEmpty());
    final HeliosClient client = defaultClient();
    client.deploy(Deployment.of(jobId, Goal.START), testHost());
    awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    final String result4 = cli("jobs", "-y", "--json");
    final Map<String, Object> resultObj4 = OBJECT_MAPPER.readValue(result4, MAP_TYPE);
    assertFalse(resultObj4.isEmpty());
}
Also used : HeliosClient(com.spotify.helios.client.HeliosClient) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 95 with JobId

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

the class JobRemoveTest method testRemoveJobWithoutHistory.

@Test
public void testRemoveJobWithoutHistory() throws Exception {
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    final JobDeleteResponse response = defaultClient().deleteJob(jobId).get(WAIT_TIMEOUT_SECONDS, SECONDS);
    assertEquals(JobDeleteResponse.Status.OK, response.getStatus());
}
Also used : JobId(com.spotify.helios.common.descriptors.JobId) JobDeleteResponse(com.spotify.helios.common.protocol.JobDeleteResponse) Test(org.junit.Test)

Aggregations

JobId (com.spotify.helios.common.descriptors.JobId)115 Test (org.junit.Test)68 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)41 Job (com.spotify.helios.common.descriptors.Job)37 HeliosClient (com.spotify.helios.client.HeliosClient)35 Deployment (com.spotify.helios.common.descriptors.Deployment)29 Matchers.containsString (org.hamcrest.Matchers.containsString)25 DockerClient (com.spotify.docker.client.DockerClient)19 JobStatus (com.spotify.helios.common.descriptors.JobStatus)19 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)16 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)13 IOException (java.io.IOException)12 HostStatus (com.spotify.helios.common.descriptors.HostStatus)11 Map (java.util.Map)11 LogStream (com.spotify.docker.client.LogStream)10 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)10 KeeperException (org.apache.zookeeper.KeeperException)9 TaskStatusEvent (com.spotify.helios.common.descriptors.TaskStatusEvent)8 AgentMain (com.spotify.helios.agent.AgentMain)7 PortMapping (com.spotify.helios.common.descriptors.PortMapping)7