Search in sources :

Example 16 with HostStatus

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

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

the class DeploymentTest method test.

@Test
public void test() throws Exception {
    final Map<String, PortMapping> ports = ImmutableMap.of("foos", PortMapping.of(17, externalPort));
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost());
    // Create a job
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setPorts(ports).setCreatingUser(TEST_USER).build();
    final JobId jobId = job.getId();
    final CreateJobResponse created = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, created.getStatus());
    final CreateJobResponse duplicateJob = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.JOB_ALREADY_EXISTS, duplicateJob.getStatus());
    // Try querying for the job
    final Map<JobId, Job> noMatchJobs = client.jobs(testJobName + "not_matching").get();
    assertTrue(noMatchJobs.isEmpty());
    final Map<JobId, Job> matchJobs1 = client.jobs(testJobName).get();
    assertJobsEqual(ImmutableMap.of(jobId, job), matchJobs1);
    final Map<JobId, Job> matchJobs2 = client.jobs(testJobName + ":" + testJobVersion).get();
    assertJobsEqual(ImmutableMap.of(jobId, job), matchJobs2);
    final Map<JobId, Job> matchJobs3 = client.jobs(job.getId().toString()).get();
    assertJobsEqual(ImmutableMap.of(jobId, job), matchJobs3);
    // Wait for agent to come up
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Deploy the job on the agent
    final Deployment deployment = Deployment.of(jobId, START, TEST_USER);
    final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
    final JobDeployResponse deployed2 = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.JOB_ALREADY_DEPLOYED, deployed2.getStatus());
    final JobDeployResponse deployed3 = client.deploy(Deployment.of(BOGUS_JOB, START), testHost()).get();
    assertEquals(JobDeployResponse.Status.JOB_NOT_FOUND, deployed3.getStatus());
    final JobDeployResponse deployed4 = client.deploy(deployment, BOGUS_HOST).get();
    assertEquals(JobDeployResponse.Status.HOST_NOT_FOUND, deployed4.getStatus());
    // undeploy and redeploy to make sure things still work in the face of the tombstone
    final JobUndeployResponse undeployResp = client.undeploy(jobId, testHost()).get();
    assertEquals(JobUndeployResponse.Status.OK, undeployResp.getStatus());
    final JobDeployResponse redeployed = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, redeployed.getStatus());
    // Check that the job is in the desired state
    final Deployment fetchedDeployment = client.deployment(testHost(), jobId).get();
    assertEquals(deployment, fetchedDeployment);
    // Wait for the job to run
    TaskStatus taskStatus;
    taskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    assertJobEquals(job, taskStatus.getJob());
    assertEquals(JobDeleteResponse.Status.STILL_IN_USE, client.deleteJob(jobId).get().getStatus());
    // Wait for a while and make sure that the container is still running
    Thread.sleep(5000);
    final HostStatus hostStatus = client.hostStatus(testHost()).get();
    taskStatus = hostStatus.getStatuses().get(jobId);
    assertEquals(jobId.toString(), RUNNING, taskStatus.getState());
    // Undeploy the job
    final JobUndeployResponse undeployed = client.undeploy(jobId, testHost()).get();
    assertEquals(JobUndeployResponse.Status.OK, undeployed.getStatus());
    // Make sure that it is no longer in the desired state
    final Deployment undeployedJob = client.deployment(testHost(), jobId).get();
    assertTrue(undeployedJob == null);
    // Wait for the task to disappear
    awaitTaskGone(client, testHost(), jobId, LONG_WAIT_SECONDS, SECONDS);
    // Verify that the job can be deleted
    assertEquals(JobDeleteResponse.Status.OK, client.deleteJob(jobId).get().getStatus());
    // Verify that a nonexistent job returns JOB_NOT_FOUND
    assertEquals(JobDeleteResponse.Status.JOB_NOT_FOUND, client.deleteJob(jobId).get().getStatus());
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) Integer.toHexString(java.lang.Integer.toHexString) HeliosClient(com.spotify.helios.client.HeliosClient) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) JobUndeployResponse(com.spotify.helios.common.protocol.JobUndeployResponse) HostStatus(com.spotify.helios.common.descriptors.HostStatus) PortMapping(com.spotify.helios.common.descriptors.PortMapping) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 18 with HostStatus

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

the class JobsResourceTest method testListJobsWithHostNameFilter.

@Test
public void testListJobsWithHostNameFilter() throws Exception {
    // one host matches this name pattern
    final String namePattern = "foo";
    when(model.listHosts(namePattern)).thenReturn(ImmutableList.of("foobar.example.net"));
    final JobId jobId1 = JobId.parse("foobar:1");
    final JobId jobId2 = JobId.parse("foobat:2");
    final Job job1 = Job.newBuilder().build();
    final Job job2 = Job.newBuilder().build();
    // and it has two jobs deployed to it
    final HostStatus hostStatus = mockHostStatus(ImmutableMap.of(jobId1, Deployment.of(jobId1, Goal.START), jobId2, Deployment.of(jobId2, Goal.START)));
    when(model.getHostStatus("foobar.example.net")).thenReturn(hostStatus);
    when(model.getJob(jobId1)).thenReturn(job1);
    when(model.getJob(jobId2)).thenReturn(job2);
    assertThat(resource.list("", namePattern), is(ImmutableMap.of(jobId1, job1, jobId2, job2)));
}
Also used : HostStatus(com.spotify.helios.common.descriptors.HostStatus) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 19 with HostStatus

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

the class JobsResourceTest method mockHostStatus.

private static HostStatus mockHostStatus(Map<JobId, Deployment> jobs) {
    final HostStatus hostStatus = mock(HostStatus.class);
    when(hostStatus.getJobs()).thenReturn(jobs);
    return hostStatus;
}
Also used : HostStatus(com.spotify.helios.common.descriptors.HostStatus)

Example 20 with HostStatus

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

Aggregations

HostStatus (com.spotify.helios.common.descriptors.HostStatus)28 Test (org.junit.Test)17 JobId (com.spotify.helios.common.descriptors.JobId)13 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)10 HeliosClient (com.spotify.helios.client.HeliosClient)9 Map (java.util.Map)8 Job (com.spotify.helios.common.descriptors.Job)6 Deployment (com.spotify.helios.common.descriptors.Deployment)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 DockerClient (com.spotify.docker.client.DockerClient)4 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)4 ExecutionException (java.util.concurrent.ExecutionException)4 AgentMain (com.spotify.helios.agent.AgentMain)3 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)3 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)3 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)3 TimeoutException (java.util.concurrent.TimeoutException)3 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)2 Timed (com.codahale.metrics.annotation.Timed)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2