Search in sources :

Example 16 with JobDeployResponse

use of com.spotify.helios.common.protocol.JobDeployResponse in project helios by spotify.

the class VolumeTest method assertVolumes.

public void assertVolumes(final JobId jobId) throws Exception {
    // 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 taskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    assertJobEquals(job, taskStatus.getJob());
    final Integer barPort = taskStatus.getPorts().get("bar").getExternalPort();
    final Integer hostnamePort = taskStatus.getPorts().get("hostname").getExternalPort();
    assert barPort != null;
    assert hostnamePort != null;
    // Read "foo" from /volume/bar
    final String foo = recvUtf8(barPort, 3);
    assertEquals("foo", foo);
    // Read hostname from /hostname
    final String hostname = getNewDockerClient().info().name();
    final String mountedHostname = recvUtf8(hostnamePort, hostname.length());
    assertEquals(hostname, mountedHostname);
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse)

Example 17 with JobDeployResponse

use of com.spotify.helios.common.protocol.JobDeployResponse in project helios by spotify.

the class DeploymentTest method testLotsOfConcurrentJobs.

@Test
public void testLotsOfConcurrentJobs() throws Exception {
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost());
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    final int numberOfJobs = 40;
    final List<JobId> jobIds = Lists.newArrayListWithCapacity(numberOfJobs);
    final String jobName = testJobName + "_" + toHexString(ThreadLocalRandom.current().nextInt());
    // create and deploy a bunch of jobs
    for (Integer i = 0; i < numberOfJobs; i++) {
        final Job job = Job.newBuilder().setName(jobName).setVersion(i.toString()).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());
        final Deployment deployment = Deployment.of(jobId, START, TEST_USER);
        final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
        assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
        jobIds.add(jobId);
    }
    // get the container ID's for the jobs
    final Set<String> containerIds = Sets.newHashSetWithExpectedSize(numberOfJobs);
    for (final JobId jobId : jobIds) {
        final TaskStatus taskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
        containerIds.add(taskStatus.getContainerId());
    }
    try (final DockerClient dockerClient = getNewDockerClient()) {
        // kill all the containers for the jobs
        for (final String containerId : containerIds) {
            dockerClient.killContainer(containerId);
        }
        // make sure all the containers come back up
        final int restartedContainers = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<Integer>() {

            @Override
            public Integer call() throws Exception {
                int matchingContainerCount = 0;
                for (final Container c : dockerClient.listContainers()) {
                    for (final String name : c.names()) {
                        if (name.contains(jobName)) {
                            matchingContainerCount++;
                        }
                    }
                }
                if (matchingContainerCount < containerIds.size()) {
                    return null;
                } else {
                    return matchingContainerCount;
                }
            }
        });
        assertEquals(numberOfJobs, restartedContainers);
    }
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) 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) Container(com.spotify.docker.client.messages.Container) CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 18 with JobDeployResponse

use of com.spotify.helios.common.protocol.JobDeployResponse in project helios by spotify.

the class DeregisterTest method testDeregisterJobDeployedWithoutStatus.

// Verify that we can deregister a host there are jobs deployed to it, for which there's no
// corresponding status information. For example, if a job was deployed to the host after is went
// down.
@Test
public void testDeregisterJobDeployedWithoutStatus() throws Exception {
    startDefaultMaster();
    final String host = testHost();
    final HeliosClient client = defaultClient();
    final DefaultZooKeeperClient zkClient = new DefaultZooKeeperClient(zk().curatorWithSuperAuth());
    final String idPath = Paths.configHostId(host);
    ZooKeeperRegistrarUtil.registerHost(zkClient, idPath, host, UUID.randomUUID().toString());
    // Create a job
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setPorts(ImmutableMap.of("foo", PortMapping.of(4711), "bar", PortMapping.of(4712, ports.localPort("bar")))).build();
    final JobId jobId = job.getId();
    final CreateJobResponse created = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, created.getStatus());
    // Deploy the job on the agent
    final Deployment deployment = Deployment.of(jobId, START);
    final JobDeployResponse deployed = client.deploy(deployment, host).get();
    assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
    // Deregister agent
    final HostDeregisterResponse deregisterResponse = client.deregisterHost(host).get();
    assertEquals(HostDeregisterResponse.Status.OK, deregisterResponse.getStatus());
    // Verify that it's possible to remove the job
    final JobDeleteResponse deleteResponse = client.deleteJob(jobId).get();
    assertEquals(JobDeleteResponse.Status.OK, deleteResponse.getStatus());
}
Also used : HostDeregisterResponse(com.spotify.helios.common.protocol.HostDeregisterResponse) CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Deployment(com.spotify.helios.common.descriptors.Deployment) HeliosClient(com.spotify.helios.client.HeliosClient) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) Job(com.spotify.helios.common.descriptors.Job) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobId(com.spotify.helios.common.descriptors.JobId) JobDeleteResponse(com.spotify.helios.common.protocol.JobDeleteResponse) Test(org.junit.Test)

Example 19 with JobDeployResponse

use of com.spotify.helios.common.protocol.JobDeployResponse in project helios by spotify.

the class CliDeploymentTest method testDeployingNonexistantJobJson.

@Test
public void testDeployingNonexistantJobJson() throws Exception {
    startDefaultMaster();
    // Wait for master to come up
    Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {

        @Override
        public String call() throws Exception {
            final String output = cli("masters");
            return output.contains(masterName()) ? output : null;
        }
    });
    // Verify that deploying a nonexistent job to the host fails
    final String output = cli("deploy", "--json", BOGUS_JOB.toString(), testHost());
    final JobDeployResponse jobDeployResponse = Json.read(output, JobDeployResponse.class);
    assertEquals(JobDeployResponse.Status.JOB_NOT_FOUND, jobDeployResponse.getStatus());
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) Test(org.junit.Test)

Example 20 with JobDeployResponse

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

Aggregations

JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)26 Deployment (com.spotify.helios.common.descriptors.Deployment)18 Test (org.junit.Test)18 JobId (com.spotify.helios.common.descriptors.JobId)16 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)16 Job (com.spotify.helios.common.descriptors.Job)11 HeliosClient (com.spotify.helios.client.HeliosClient)10 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)8 DockerClient (com.spotify.docker.client.DockerClient)6 AgentMain (com.spotify.helios.agent.AgentMain)4 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 HostStatus (com.spotify.helios.common.descriptors.HostStatus)3 JobDeleteResponse (com.spotify.helios.common.protocol.JobDeleteResponse)3 Container (com.spotify.docker.client.messages.Container)2 HostConfig (com.spotify.docker.client.messages.HostConfig)2 HostDeregisterResponse (com.spotify.helios.common.protocol.HostDeregisterResponse)2 Integer.toHexString (java.lang.Integer.toHexString)2 List (java.util.List)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1