Search in sources :

Example 96 with JobId

use of com.spotify.helios.common.descriptors.JobId 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 97 with JobId

use of com.spotify.helios.common.descriptors.JobId 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)

Example 98 with JobId

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

the class DeploymentGroupTest method testRollingUpdateCoordination.

@Test
public void testRollingUpdateCoordination() throws Exception {
    // stop the default master
    master.stopAsync().awaitTerminated();
    // start a bunch of masters and agents
    final Map<String, MasterMain> masters = startDefaultMasters(3);
    final Map<String, AgentMain> agents = Maps.newLinkedHashMap();
    for (int i = 0; i < 20; i++) {
        final String name = TEST_HOST + i;
        agents.put(name, startDefaultAgent(name, "--labels", TEST_LABEL));
    }
    // create a deployment group and start rolling out
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    cli("rolling-update", "--async", "--par", String.valueOf(agents.size()), testJobNameAndVersion, TEST_GROUP);
    // wait until the task is running on the final agent
    awaitTaskState(jobId, getLast(agents.keySet()), TaskStatus.State.RUNNING);
    // ensure that all masters were involved
    final Set<String> deployingMasters = Sets.newHashSet();
    final Map<String, HostStatus> hostStatuses = defaultClient().hostStatuses(Lists.newArrayList(agents.keySet())).get();
    for (final HostStatus status : hostStatuses.values()) {
        for (final Deployment deployment : status.getJobs().values()) {
            deployingMasters.add(deployment.getDeployerMaster());
        }
    }
    assertEquals(masters.size(), deployingMasters.size());
}
Also used : AgentMain(com.spotify.helios.agent.AgentMain) MasterMain(com.spotify.helios.master.MasterMain) Deployment(com.spotify.helios.common.descriptors.Deployment) HostStatus(com.spotify.helios.common.descriptors.HostStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 99 with JobId

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

the class DeploymentGroupTest method testRemovingAgentTagUndeploysJob.

@Test
public void testRemovingAgentTagUndeploysJob() throws Exception {
    final HeliosClient client = defaultClient();
    final String oldHost = testHost();
    final String deregisterHost = testHost() + "2";
    final String unchangedHost = testHost() + "3";
    final String newHost = testHost() + "4";
    final String anotherNewHost = testHost() + "5";
    @SuppressWarnings("VariableDeclarationUsageDistance") AgentMain oldAgent = startDefaultAgent(oldHost, "--labels", "foo=bar");
    awaitUpWithLabels(oldHost, "foo", "bar");
    final AgentMain deregisterAgent = startDefaultAgent(deregisterHost, "--labels", "foo=bar");
    awaitUpWithLabels(deregisterHost, "foo", "bar");
    startDefaultAgent(unchangedHost, "--labels", "foo=bar");
    awaitUpWithLabels(unchangedHost, "foo", "bar");
    cli("create-deployment-group", "--json", TEST_GROUP, "foo=bar");
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    cli("rolling-update", "--async", testJobNameAndVersion, TEST_GROUP);
    awaitTaskState(jobId, oldHost, TaskStatus.State.RUNNING);
    awaitTaskState(jobId, deregisterHost, TaskStatus.State.RUNNING);
    awaitTaskState(jobId, unchangedHost, TaskStatus.State.RUNNING);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
    // Rollout should be complete and on its second iteration at this point.
    // Start another agent and wait for it to have the job deployed to it.
    startDefaultAgent(newHost, "--labels", "foo=bar");
    awaitUpWithLabels(newHost, "foo", "bar");
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(jobId, newHost, TaskStatus.State.RUNNING);
    // Restart the old agent with labels that still match the deployment group
    // The job should not be undeployed.
    stopAgent(oldAgent);
    oldAgent = startDefaultAgent(oldHost, "--labels", "foo=bar", "another=label");
    awaitUpWithLabels(oldHost, "foo", "bar", "another", "label");
    awaitTaskState(jobId, oldHost, TaskStatus.State.RUNNING);
    // Restart the old agent with labels that do not match the deployment group.
    stopAgent(oldAgent);
    oldAgent = startDefaultAgent(oldHost, "--labels", "foo=notbar");
    awaitUpWithLabels(oldHost, "foo", "notbar");
    // ...which should trigger a rolling update
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    // Start yet another agent in order to trigger another rolling update.
    startDefaultAgent(anotherNewHost, "--labels", "foo=bar");
    // Wait for the rolling update(s) to finish.
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
    // ...which should remove the job.
    awaitUndeployed(oldHost, jobId);
    // Restart the old agent with labels that match the deployment group (again)
    // The job should be deployed.
    stopAgent(oldAgent);
    startDefaultAgent(oldHost, "--labels", "foo=bar");
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(jobId, oldHost, TaskStatus.State.RUNNING);
    // Deregister an agent
    stopAgent(deregisterAgent);
    final HostDeregisterResponse deregisterResponse = client.deregisterHost(deregisterHost).get();
    assertEquals(HostDeregisterResponse.Status.OK, deregisterResponse.getStatus());
    // Make sure we 'undeploy' from the now non-existent agent.
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
}
Also used : HostDeregisterResponse(com.spotify.helios.common.protocol.HostDeregisterResponse) AgentMain(com.spotify.helios.agent.AgentMain) Matchers.containsString(org.hamcrest.Matchers.containsString) HeliosClient(com.spotify.helios.client.HeliosClient) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 100 with JobId

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

the class DeploymentGroupTest method testRollingUpdateWithOverlapAndParallelism.

@Test
public void testRollingUpdateWithOverlapAndParallelism() throws Exception {
    // create and start agents
    final List<String> hosts = ImmutableList.of("dc1-" + testHost() + "-a1.dc1.example.com", "dc1-" + testHost() + "-a2.dc1.example.com", "dc2-" + testHost() + "-a1.dc2.example.com", "dc2-" + testHost() + "-a3.dc2.example.com", "dc3-" + testHost() + "-a4.dc3.example.com");
    for (final String host : hosts) {
        startDefaultAgent(host, "--labels", TEST_LABEL);
    }
    // create a deployment group
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    // create and roll out a first job
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    cli("rolling-update", "--async", "-p", "2", "--overlap", testJobNameAndVersion, TEST_GROUP);
    for (final String host : hosts) {
        awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
    }
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    // create and roll out a second job
    final String secondJobVersion = testJobVersion + "2";
    final String secondJobNameAndVersion = testJobNameAndVersion + "2";
    final JobId secondJobId = createJob(testJobName, secondJobVersion, BUSYBOX, IDLE_COMMAND);
    cli("rolling-update", "--async", "-p", "2", "--overlap", secondJobNameAndVersion, TEST_GROUP);
    for (final String host : hosts) {
        awaitTaskState(secondJobId, host, TaskStatus.State.RUNNING);
    }
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) JobId(com.spotify.helios.common.descriptors.JobId) 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