Search in sources :

Example 1 with Deployment

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

the class MultipleHostsTest method testFilteringJobAndHostStatuses.

@Test
public void testFilteringJobAndHostStatuses() throws Exception {
    final String aHost = testHost() + "a";
    final String bHost = testHost() + "b";
    startDefaultMaster();
    startDefaultAgent(aHost);
    startDefaultAgent(bHost);
    awaitHostStatus(aHost, UP, LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(bHost, UP, LONG_WAIT_SECONDS, SECONDS);
    final HeliosClient client = defaultClient();
    final Job job = Job.newBuilder().setName(testJobName + "I_WANT_THIS_ONE").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).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId jobId2 = job2.getId();
    client.createJob(job2).get();
    final Deployment deployment = Deployment.of(jobId, Goal.START);
    client.deploy(deployment, aHost);
    client.deploy(deployment, bHost);
    client.deploy(Deployment.of(jobId2, Goal.START), aHost);
    awaitJobState(client, aHost, jobId, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
    awaitJobState(client, bHost, jobId, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
    awaitJobState(client, aHost, jobId2, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
    final Map<JobId, JobStatus> cliStatuses = new ObjectMapper().readValue(cli("status", "--job", "I_WANT_THIS_ONE", "--host", aHost, "--json"), new TypeReference<Map<JobId, JobStatus>>() {
    });
    assertEquals("status should only have one job", 1, cliStatuses.size());
    assertTrue(cliStatuses.containsKey(jobId));
    final JobStatus status = cliStatuses.get(jobId);
    assertEquals("deployments should have only one item", 1, status.getDeployments().size());
    assertTrue("should only have deployment info for aHost", status.getDeployments().containsKey(aHost));
    assertEquals("Task statuses should only have one item", 1, status.getTaskStatuses().size());
    assertTrue("should only have status info for aHost", status.getTaskStatuses().containsKey(aHost));
}
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) Map(java.util.Map) JobId(com.spotify.helios.common.descriptors.JobId) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with Deployment

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

the class NamespaceTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    final String id = "test-" + Integer.toHexString(new SecureRandom().nextInt());
    final String namespace = "helios-" + id;
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost(), "--id=" + id);
    // Create a job
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).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());
    awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    try (final DockerClient docker = getNewDockerClient()) {
        final List<Container> containers = docker.listContainers();
        Container jobContainer = null;
        for (final Container container : containers) {
            for (final String name : container.names()) {
                if (name.startsWith("/" + namespace)) {
                    jobContainer = container;
                }
            }
        }
        assertNotNull(jobContainer);
    }
}
Also used : Container(com.spotify.docker.client.messages.Container) CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) DockerClient(com.spotify.docker.client.DockerClient) SecureRandom(java.security.SecureRandom) 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) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 3 with Deployment

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

the class NetworkModeTest method test.

@Test
public void test() throws Exception {
    final CreateJobResponse created = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, created.getStatus());
    final JobId jobId = job.getId();
    // 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);
    try (final DockerClient docker = getNewDockerClient()) {
        final HostConfig hostConfig = docker.inspectContainer(taskStatus.getContainerId()).hostConfig();
        assertEquals(NETWORK_MODE, hostConfig.networkMode());
    }
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) DockerClient(com.spotify.docker.client.DockerClient) HostConfig(com.spotify.docker.client.messages.HostConfig) Deployment(com.spotify.helios.common.descriptors.Deployment) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 4 with Deployment

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

the class ZooKeeperHeliosFailoverTest method deploy.

private void deploy(final Job job) throws Exception {
    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);
    final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
    // Wait for the job to run
    awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Deployment(com.spotify.helios.common.descriptors.Deployment) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobId(com.spotify.helios.common.descriptors.JobId)

Example 5 with Deployment

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

the class ResourcesTest method testClient.

@Test
public void testClient() throws Exception {
    // Doesn't work on CircleCI because their lxc-driver can't set cpus
    // See output of `docker run --cpuset-cpus 0-1 spotify/busybox:latest true`
    assumeFalse(isCircleCi());
    final CreateJobResponse created = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, created.getStatus());
    final JobId jobId = job.getId();
    // 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());
    try (final DockerClient docker = getNewDockerClient()) {
        final HostConfig hostConfig = docker.inspectContainer(taskStatus.getContainerId()).hostConfig();
        assertEquals(CPU_SHARES, hostConfig.cpuShares());
        assertEquals(CPUSET_CPUS, hostConfig.cpusetCpus());
        final Info info = docker.info();
        final Iterable<String> split = Splitter.on(".").split(docker.version().apiVersion());
        //noinspection ConstantConditions
        final int major = Integer.parseInt(Iterables.get(split, 0, "0"));
        //noinspection ConstantConditions
        final int minor = Integer.parseInt(Iterables.get(split, 1, "0"));
        // TODO (dxia) This doesn't work on docker < 1.7 ie docker API < 1.19 for some reason.
        if (major >= 1 && minor >= 19) {
            if (info.memoryLimit()) {
                assertEquals(MEMORY, hostConfig.memory());
            }
            if (info.swapLimit()) {
                assertEquals(MEMORY_SWAP, hostConfig.memorySwap());
            }
        }
    }
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) DockerClient(com.spotify.docker.client.DockerClient) HostConfig(com.spotify.docker.client.messages.HostConfig) Deployment(com.spotify.helios.common.descriptors.Deployment) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) Info(com.spotify.docker.client.messages.Info) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) 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