Search in sources :

Example 41 with Deployment

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

the class MultipleJobsTest method jobStatusBulk.

@Test
public void jobStatusBulk() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());
    awaitHostRegistered(testHost(), LONG_WAIT_SECONDS, SECONDS);
    final HeliosClient client = defaultClient();
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId jobId = job.getId();
    client.createJob(job).get();
    final Job job2 = Job.newBuilder().setName(testJobName + "2").setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId job2Id = job2.getId();
    client.createJob(job2).get();
    final Deployment deployment = Deployment.of(jobId, START, TEST_USER);
    final Deployment deployment2 = Deployment.of(job2Id, START, TEST_USER);
    client.deploy(deployment, testHost()).get();
    awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    client.deploy(deployment2, testHost()).get();
    awaitJobState(client, testHost(), job2Id, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    final Map<JobId, JobStatus> statuses = client.jobStatuses(ImmutableSet.of(jobId, job2Id)).get();
    assertTrue("should contain job 1 id", statuses.containsKey(jobId));
    assertTrue("should contain job 2 id", statuses.containsKey(job2Id));
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) Deployment(com.spotify.helios.common.descriptors.Deployment) 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 42 with Deployment

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

the class PortCollisionJobTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());
    final HeliosClient client = defaultClient();
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    final Job job1 = Job.newBuilder().setName(testTag + "foo").setVersion("1").setImage(BUSYBOX).setCommand(IDLE_COMMAND).setPorts(ImmutableMap.of("foo", PortMapping.of(10001, externalPort))).build();
    final Job job2 = Job.newBuilder().setName(testTag + "bar").setVersion("1").setImage(BUSYBOX).setCommand(IDLE_COMMAND).setPorts(ImmutableMap.of("foo", PortMapping.of(10002, externalPort))).build();
    final CreateJobResponse created1 = client.createJob(job1).get();
    assertEquals(CreateJobResponse.Status.OK, created1.getStatus());
    final CreateJobResponse created2 = client.createJob(job2).get();
    assertEquals(CreateJobResponse.Status.OK, created2.getStatus());
    final Deployment deployment1 = Deployment.of(job1.getId(), STOP);
    final JobDeployResponse deployed1 = client.deploy(deployment1, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, deployed1.getStatus());
    final Deployment deployment2 = Deployment.of(job2.getId(), STOP);
    final JobDeployResponse deployed2 = client.deploy(deployment2, testHost()).get();
    assertEquals(JobDeployResponse.Status.PORT_CONFLICT, deployed2.getStatus());
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Deployment(com.spotify.helios.common.descriptors.Deployment) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) Test(org.junit.Test)

Example 43 with Deployment

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

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

the class AgentZooKeeperDownTolerationTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    final DockerClient dockerClient = getNewDockerClient();
    final HeliosClient client = defaultClient();
    final AgentMain agent1 = startDefaultAgent(testHost());
    // Create a job
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId jobId = job.getId();
    final CreateJobResponse created = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, created.getStatus());
    // 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);
    final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
    // Wait for the job to run
    final TaskStatus firstTaskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    assertJobEquals(job, firstTaskStatus.getJob());
    assertNotNull(dockerClient.inspectContainer(firstTaskStatus.getContainerId()));
    // Stop zookeeper
    zk().stop();
    // Wait for a while and make sure that the container is still running
    Thread.sleep(5000);
    assertTrue(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running());
    // Stop the agent
    agent1.stopAsync().awaitTerminated();
    // Start the agent again
    final AgentMain agent2 = startDefaultAgent(testHost());
    // Wait for a while and make sure that the same container is still running
    Thread.sleep(5000);
    assertTrue(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running());
    // Kill the container
    dockerClient.killContainer(firstTaskStatus.getContainerId());
    assertFalse(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running());
    // Wait for a while and make sure that a new container was spawned
    final String firstRestartedContainerId = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {

        @Override
        public String call() throws Exception {
            final List<Container> containers = listContainers(dockerClient, testTag);
            return containers.size() == 1 ? containers.get(0).id() : null;
        }
    });
    // Stop the agent
    agent2.stopAsync().awaitTerminated();
    // Kill the container
    dockerClient.killContainer(firstRestartedContainerId);
    assertFalse(dockerClient.inspectContainer(firstRestartedContainerId).state().running());
    // Start the agent again
    startDefaultAgent(testHost());
    // Wait for a while and make sure that a new container was spawned
    final String secondRestartedContainerId = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {

        @Override
        public String call() throws Exception {
            final List<Container> containers = listContainers(dockerClient, testTag);
            return containers.size() == 1 ? containers.get(0).id() : null;
        }
    });
    assertTrue(dockerClient.inspectContainer(secondRestartedContainerId).state().running());
    // Start zookeeper
    zk().start();
    // Verify that the agent is listed as up
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Wait for the new container id to be reflected in the task status
    Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<TaskStatus>() {

        @Override
        public TaskStatus call() throws Exception {
            final JobStatus jobStatus = client.jobStatus(jobId).get();
            final TaskStatus taskStatus = jobStatus.getTaskStatuses().get(testHost());
            return taskStatus != null && Objects.equals(taskStatus.getContainerId(), secondRestartedContainerId) ? taskStatus : null;
        }
    });
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Deployment(com.spotify.helios.common.descriptors.Deployment) HeliosClient(com.spotify.helios.client.HeliosClient) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobStatus(com.spotify.helios.common.descriptors.JobStatus) CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) AgentMain(com.spotify.helios.agent.AgentMain) List(java.util.List) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Aggregations

Deployment (com.spotify.helios.common.descriptors.Deployment)44 JobId (com.spotify.helios.common.descriptors.JobId)30 Test (org.junit.Test)24 Job (com.spotify.helios.common.descriptors.Job)21 HeliosClient (com.spotify.helios.client.HeliosClient)19 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)18 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)16 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)14 DockerClient (com.spotify.docker.client.DockerClient)8 HostStatus (com.spotify.helios.common.descriptors.HostStatus)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 AgentMain (com.spotify.helios.agent.AgentMain)5 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)5 JobStatus (com.spotify.helios.common.descriptors.JobStatus)5 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)5 KeeperException (org.apache.zookeeper.KeeperException)5 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)5 RolloutTask (com.spotify.helios.common.descriptors.RolloutTask)3 Task (com.spotify.helios.common.descriptors.Task)3 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)3