Search in sources :

Example 26 with JobId

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

the class DeploymentGroupTest method testRollingUpdateWithToken.

@Test
public void testRollingUpdateWithToken() 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 with a token on the host (i.e. a job not part of the deployment group)
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setToken(TOKEN).build();
    final JobId jobId = createJob(job);
    // Create a deployment-group and trigger a migration rolling-update
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    cli("rolling-update", "--async", "--token", TOKEN, testJobNameAndVersion, TEST_GROUP);
    // rolling-update should succeed & job should be running
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
    // Check that we cannot manually undeploy the job with a token
    final String output = cli("undeploy", jobId.toString(), host);
    assertThat(output, containsString("FORBIDDEN"));
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 27 with JobId

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

the class DeploymentGroupTest method testRollingUpdateMigrateWithToken.

@Test
public void testRollingUpdateMigrateWithToken() 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 with a token on the host (i.e. a job not part of the deployment group)
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setToken(TOKEN).build();
    final JobId jobId = createJob(job);
    deployJob(jobId, host, TOKEN);
    awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
    // Create a deployment-group and trigger a migration rolling-update
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    cli("rolling-update", "--async", "--migrate", "--token", TOKEN, testJobNameAndVersion, TEST_GROUP);
    // Check that the deployment's deployment-group name eventually changes to TEST_GROUP
    // (should be null or empty before)
    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);
    // rolling-update should succeed & job should be running
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) Matchers.containsString(org.hamcrest.Matchers.containsString) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 28 with JobId

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

the class DeploymentGroupTest method testRollingUpdateMigrate.

@Test
public void testRollingUpdateMigrate() 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 (i.e. a job not part of the deployment group)
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    deployJob(jobId, host);
    awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
    // Create a deployment-group and trigger a migration rolling-update
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    cli("rolling-update", "--async", "--migrate", testJobNameAndVersion, TEST_GROUP);
    // Check that the deployment's deployment-group name eventually changes to TEST_GROUP
    // (should be null or empty before)
    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);
    // rolling-update should succeed & job should be running
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
}
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 29 with JobId

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

the class DeploymentGroupTest method testRollingUpdate.

@Test
public void testRollingUpdate() throws Exception {
    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");
    // start agents
    for (final String host : hosts) {
        startDefaultAgent(host, "--labels", TEST_LABEL);
    }
    // Wait for agents to come up
    final HeliosClient client = defaultClient();
    for (final String host : hosts) {
        awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
    }
    // create a deployment group and job
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    // TODO: fix this!
    // Wait to make sure the host-update has run
    Thread.sleep(1000);
    // trigger a rolling update
    cli("rolling-update", "--async", testJobNameAndVersion, TEST_GROUP);
    // ensure the job is running on all agents and the deployment group reaches DONE
    for (final String host : hosts) {
        awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
    }
    final Deployment deployment = defaultClient().hostStatus(hosts.get(0)).get().getJobs().get(jobId);
    assertEquals(TEST_GROUP, deployment.getDeploymentGroupName());
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    // create a second job
    final String secondJobVersion = testJobVersion + "2";
    final String secondJobNameAndVersion = testJobNameAndVersion + "2";
    final JobId secondJobId = createJob(testJobName, secondJobVersion, BUSYBOX, IDLE_COMMAND);
    // trigger a rolling update to replace the first job with the second job
    final String output = cli("rolling-update", secondJobNameAndVersion, TEST_GROUP);
    // Check that the hosts in the output are ordered
    final List<String> lines = Lists.newArrayList(Splitter.on("\n").split(output));
    for (int i = 0; i < hosts.size(); i++) {
        assertThat(lines.get(i + 2), containsString(hosts.get(i)));
    }
    // ensure the second job rolled out fine
    for (final String host : hosts) {
        awaitTaskState(secondJobId, host, TaskStatus.State.RUNNING);
    }
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
}
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 30 with JobId

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

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