Search in sources :

Example 41 with HeliosClient

use of com.spotify.helios.client.HeliosClient 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 42 with HeliosClient

use of com.spotify.helios.client.HeliosClient 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 43 with HeliosClient

use of com.spotify.helios.client.HeliosClient 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 44 with HeliosClient

use of com.spotify.helios.client.HeliosClient in project helios by spotify.

the class DeploymentGroupTest method testRemoveDeploymentGroupActive.

@Test
public void testRemoveDeploymentGroupActive() 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);
    // Use an invalid image to make sure the DG doesn't succeed (this ensure the DG will be active
    // for 5+ minutes, which is plenty of time).
    final JobId jobId = createJob(testJobName, testJobVersion, "invalid_image", IDLE_COMMAND);
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    cli("rolling-update", "--async", "--migrate", testJobNameAndVersion, TEST_GROUP);
    final RemoveDeploymentGroupResponse response = defaultClient().removeDeploymentGroup(TEST_GROUP).get();
    assertEquals(RemoveDeploymentGroupResponse.Status.REMOVED, response.getStatus());
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) HeliosClient(com.spotify.helios.client.HeliosClient) RemoveDeploymentGroupResponse(com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 45 with HeliosClient

use of com.spotify.helios.client.HeliosClient in project helios by spotify.

the class DeploymentGroupTest method testRollingUpdateMigrateNothingToUndeploy.

@Test
public void testRollingUpdateMigrateNothingToUndeploy() 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);
    // Manually deploy a job on the host
    final String manualJobVersion = "foo-" + testJobVersion;
    final JobId manualJobId = createJob(testJobName, manualJobVersion, BUSYBOX, IDLE_COMMAND);
    deployJob(manualJobId, host);
    awaitTaskState(manualJobId, host, TaskStatus.State.RUNNING);
    // create a deployment group and trigger a migration rolling-update -- with a different
    // job that the one deployed manually! The manually deployed job should remain running on the
    // host.
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    cli("rolling-update", "--async", "--migrate", testJobNameAndVersion, TEST_GROUP);
    // rolling-update should succeed & job should be running
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
    final String jobDeploymentGroup = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {

        @Override
        public String call() throws Exception {
            final Deployment deployment = defaultClient().hostStatus(host).get().getJobs().get(jobId);
            if (deployment != null && !isNullOrEmpty(deployment.getDeploymentGroupName())) {
                return deployment.getDeploymentGroupName();
            } else {
                return null;
            }
        }
    });
    assertEquals(TEST_GROUP, jobDeploymentGroup);
    // Ensure that the manually deployed job is still there & running
    final Deployment manualDeployment = defaultClient().hostStatus(host).get().getJobs().get(manualJobId);
    assertNotNull(manualDeployment);
    assertEquals(Goal.START, manualDeployment.getGoal());
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) Matchers.containsString(org.hamcrest.Matchers.containsString) HeliosClient(com.spotify.helios.client.HeliosClient) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Aggregations

HeliosClient (com.spotify.helios.client.HeliosClient)57 Test (org.junit.Test)53 JobId (com.spotify.helios.common.descriptors.JobId)35 Job (com.spotify.helios.common.descriptors.Job)25 Deployment (com.spotify.helios.common.descriptors.Deployment)19 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)14 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)13 Matchers.containsString (org.hamcrest.Matchers.containsString)11 DockerClient (com.spotify.docker.client.DockerClient)10 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)10 HostStatus (com.spotify.helios.common.descriptors.HostStatus)9 AgentMain (com.spotify.helios.agent.AgentMain)8 JobStatus (com.spotify.helios.common.descriptors.JobStatus)6 PortMapping (com.spotify.helios.common.descriptors.PortMapping)5 Map (java.util.Map)5 ExecHealthCheck (com.spotify.helios.common.descriptors.ExecHealthCheck)4 HealthCheck (com.spotify.helios.common.descriptors.HealthCheck)4 HttpHealthCheck (com.spotify.helios.common.descriptors.HttpHealthCheck)4 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)4 TcpHealthCheck (com.spotify.helios.common.descriptors.TcpHealthCheck)4