Search in sources :

Example 71 with Job

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

the class PredefinedPortImageDeploymentTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());
    final HeliosClient client = defaultClient();
    // Create a job using an image exposing port 11211 but without mapping it
    final Job job1 = Job.newBuilder().setName(testTag + "memcached").setVersion("v1").setImage(MEMCACHED).build();
    final JobId jobId1 = job1.getId();
    client.createJob(job1).get();
    // Create a job using an image exposing port 11211 and map it to a specific external port
    final Job job2 = Job.newBuilder().setName(testTag + "memcached").setVersion("v2").setImage(MEMCACHED).setPorts(ImmutableMap.of("tcp", PortMapping.of(11211, externalPort))).build();
    final JobId jobId2 = job2.getId();
    client.createJob(job2).get();
    // Wait for agent to come up
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Deploy the jobs on the agent
    client.deploy(Deployment.of(jobId1, START), testHost()).get();
    client.deploy(Deployment.of(jobId2, START), testHost()).get();
    // Wait for the jobs to run
    awaitJobState(client, testHost(), jobId1, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    awaitJobState(client, testHost(), jobId2, RUNNING, LONG_WAIT_SECONDS, SECONDS);
}
Also used : 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 72 with Job

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

the class ZooKeeperMasterModelIntegrationTest method testUpdateDeploy.

@Test
public void testUpdateDeploy() throws Exception {
    try {
        stopJob(model, JOB);
        fail("should have thrown JobNotDeployedException");
    } catch (JobNotDeployedException e) {
        assertTrue(true);
    } catch (Exception e) {
        fail("Should have thrown an JobNotDeployedException, got " + e.getClass());
    }
    model.addJob(JOB);
    try {
        stopJob(model, JOB);
        fail("should have thrown exception");
    } catch (HostNotFoundException e) {
        assertTrue(true);
    } catch (Exception e) {
        fail("Should have thrown an HostNotFoundException");
    }
    model.registerHost(HOST, "foo");
    final List<String> hosts = model.listHosts();
    assertThat(hosts, hasItem(HOST));
    try {
        stopJob(model, JOB);
        fail("should have thrown exception");
    } catch (JobNotDeployedException e) {
        assertTrue(true);
    } catch (Exception e) {
        fail("Should have thrown an JobNotDeployedException");
    }
    model.deployJob(HOST, Deployment.newBuilder().setGoal(Goal.START).setJobId(JOB.getId()).build());
    final Map<JobId, Job> jobsOnHost = model.getJobs();
    assertEquals(1, jobsOnHost.size());
    final Job descriptor = jobsOnHost.get(JOB.getId());
    assertEquals(JOB, descriptor);
    // should succeed this time!
    stopJob(model, JOB);
    final Deployment jobCfg = model.getDeployment(HOST, JOB.getId());
    assertEquals(Goal.STOP, jobCfg.getGoal());
}
Also used : HostNotFoundException(com.spotify.helios.master.HostNotFoundException) Deployment(com.spotify.helios.common.descriptors.Deployment) JobNotDeployedException(com.spotify.helios.master.JobNotDeployedException) Job(com.spotify.helios.common.descriptors.Job) JobStillDeployedException(com.spotify.helios.master.JobStillDeployedException) DeploymentGroupDoesNotExistException(com.spotify.helios.master.DeploymentGroupDoesNotExistException) DeploymentGroupExistsException(com.spotify.helios.master.DeploymentGroupExistsException) HostNotFoundException(com.spotify.helios.master.HostNotFoundException) ExpectedException(org.junit.rules.ExpectedException) JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) JobNotDeployedException(com.spotify.helios.master.JobNotDeployedException) HeliosException(com.spotify.helios.common.HeliosException) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 73 with Job

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

the class ZooKeeperMasterModelIntegrationTest method testJobCreation.

@Test
public void testJobCreation() throws Exception {
    assertThat(model.getJobs().entrySet(), empty());
    model.addJob(JOB);
    assertEquals(model.getJobs().get(JOB_ID), JOB);
    assertEquals(model.getJob(JOB_ID), JOB);
    final Job secondJob = Job.newBuilder().setCommand(ImmutableList.of(COMMAND)).setImage(IMAGE).setName(JOB_NAME).setVersion("SECOND").build();
    model.addJob(secondJob);
    assertEquals(model.getJob(secondJob.getId()), secondJob);
    assertEquals(2, model.getJobs().size());
}
Also used : Job(com.spotify.helios.common.descriptors.Job) Test(org.junit.Test)

Example 74 with Job

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

the class SupervisorTest method verifySupervisorHandlesUndeployingOfNotRunningContainerWithGracePeriod.

/**
   * Verifies a fix for a NPE that is thrown when the Supervisor receives a goal of UNDEPLOY for a
   * job with gracePeriod that has never been STARTed.
   */
@Test
public void verifySupervisorHandlesUndeployingOfNotRunningContainerWithGracePeriod() throws Exception {
    final int gracePeriod = 5;
    final Job job = JOB.toBuilder().setGracePeriod(gracePeriod).build();
    final Supervisor sut = createSupervisor(job);
    sut.setGoal(Goal.UNDEPLOY);
    // when the NPE was thrown, the model was never updated
    verify(model, timeout(30000)).setTaskStatus(eq(job.getId()), argThat(is(taskStatusWithState(TaskStatus.State.STOPPING))));
    verify(model, timeout(30000)).setTaskStatus(eq(job.getId()), argThat(is(taskStatusWithState(TaskStatus.State.STOPPED))));
    verify(sleeper, never()).sleep(gracePeriod * 1000);
}
Also used : Job(com.spotify.helios.common.descriptors.Job) Test(org.junit.Test)

Example 75 with Job

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

the class DeploymentGroupTest method testUpdateDeploymentGroupHosts.

// A test that ensures healthy deployment groups will perform a rolling update when their hosts
// change.
@Test
public void testUpdateDeploymentGroupHosts() throws Exception {
    final ZooKeeperClient client = spy(this.client);
    final ZooKeeperMasterModel masterModel = spy(newMasterModel(client));
    // Return a job so we can add a real deployment group.
    final Job job = Job.newBuilder().setCommand(ImmutableList.of("COMMAND")).setImage("IMAGE").setName("JOB_NAME").setVersion("VERSION").build();
    doReturn(job).when(masterModel).getJob(job.getId());
    // Add a real deployment group.
    final DeploymentGroup dg = DeploymentGroup.newBuilder().setName(GROUP_NAME).setHostSelectors(ImmutableList.of(HostSelector.parse("role=melmac"))).setJobId(job.getId()).setRolloutOptions(RolloutOptions.newBuilder().build()).setRollingUpdateReason(MANUAL).build();
    masterModel.addDeploymentGroup(dg);
    // Setup some hosts
    final String oldHost = "host1";
    final String newHost = "host2";
    client.ensurePath(Paths.configHost(oldHost));
    client.ensurePath(Paths.configHost(newHost));
    client.ensurePath(Paths.statusHostUp(oldHost));
    client.ensurePath(Paths.statusHostUp(newHost));
    // Give the deployment group a host.
    client.setData(Paths.statusDeploymentGroupHosts(dg.getName()), Json.asBytes(ImmutableList.of(oldHost)));
    // And a status...
    client.setData(Paths.statusDeploymentGroup(dg.getName()), DeploymentGroupStatus.newBuilder().setState(DONE).build().toJsonBytes());
    // Switch out our host!
    // TODO(negz): Use an unchanged host, make sure ordering remains the same.
    masterModel.updateDeploymentGroupHosts(dg.getName(), ImmutableList.of(newHost));
    verify(client, times(2)).transaction(opCaptor.capture());
    final DeploymentGroup changed = dg.toBuilder().setRollingUpdateReason(HOSTS_CHANGED).build();
    // Ensure we set the DG status to HOSTS_CHANGED.
    // This means we triggered a rolling update.
    final ZooKeeperOperation setDeploymentGroupHostChanged = set(Paths.configDeploymentGroup(dg.getName()), changed);
    // Ensure ZK tasks are written to:
    // - Perform a rolling undeploy for the removed (old) host
    // - Perform a rolling update for the added (new) host and the unchanged host
    final List<RolloutTask> tasks = ImmutableList.<RolloutTask>builder().addAll(RollingUndeployPlanner.of(changed).plan(singletonList(oldHost))).addAll(RollingUpdatePlanner.of(changed).plan(singletonList(newHost))).build();
    final ZooKeeperOperation setDeploymentGroupTasks = set(Paths.statusDeploymentGroupTasks(dg.getName()), DeploymentGroupTasks.newBuilder().setRolloutTasks(tasks).setTaskIndex(0).setDeploymentGroup(changed).build());
    assertThat(opCaptor.getValue(), hasItems(setDeploymentGroupHostChanged, setDeploymentGroupTasks));
}
Also used : ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) Job(com.spotify.helios.common.descriptors.Job) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Aggregations

Job (com.spotify.helios.common.descriptors.Job)79 Test (org.junit.Test)57 JobId (com.spotify.helios.common.descriptors.JobId)38 HeliosClient (com.spotify.helios.client.HeliosClient)25 Deployment (com.spotify.helios.common.descriptors.Deployment)21 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)16 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)15 JobStatus (com.spotify.helios.common.descriptors.JobStatus)12 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)11 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)10 KeeperException (org.apache.zookeeper.KeeperException)10 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)10 PortMapping (com.spotify.helios.common.descriptors.PortMapping)9 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)8 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 DockerClient (com.spotify.docker.client.DockerClient)7 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)7 IOException (java.io.IOException)7 ServicePorts (com.spotify.helios.common.descriptors.ServicePorts)6