Search in sources :

Example 6 with CreateJobResponse

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

Example 7 with CreateJobResponse

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

the class UndeployFilteringTest method createAndAwaitJobRunning.

private JobId createAndAwaitJobRunning() throws Exception {
    final CreateJobResponse jobby = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, jobby.getStatus());
    final JobId jobId = job.getId();
    final JobDeployResponse deployResponse = client.deploy(Deployment.of(jobId, START), TEST_HOST).get();
    assertEquals(JobDeployResponse.Status.OK, deployResponse.getStatus());
    awaitJobState(client, TEST_HOST, jobId, State.RUNNING, 30, TimeUnit.SECONDS);
    return jobId;
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobId(com.spotify.helios.common.descriptors.JobId)

Example 8 with CreateJobResponse

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

the class DeregisterTest method testDeregister.

@Test
public void testDeregister() throws Exception {
    startDefaultMaster();
    final String host = testHost();
    final AgentMain agent = startDefaultAgent(host);
    final HeliosClient client = defaultClient();
    // 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());
    // Wait for agent to come up
    awaitHostRegistered(client, host, LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
    // 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());
    // Wait for the job to run
    awaitJobState(client, host, jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    // Kill off agent
    agent.stopAsync().awaitTerminated();
    // 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) AgentMain(com.spotify.helios.agent.AgentMain) 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) JobDeleteResponse(com.spotify.helios.common.protocol.JobDeleteResponse) Test(org.junit.Test)

Example 9 with CreateJobResponse

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

the class CliJobCreationTest method testTemplateUnknownJobJsonOutput.

@Test
public void testTemplateUnknownJobJsonOutput() throws Exception {
    // Trying to create a job with a non-existant job as a template should return JSON with
    // UNKNOWN_JOB
    final String output = cli("create", "--json", "--template", "non-existant-job", testJobNameAndVersion, BUSYBOX);
    final CreateJobResponse createJobResponse = Json.read(output, CreateJobResponse.class);
    assertEquals(CreateJobResponse.Status.UNKNOWN_JOB, createJobResponse.getStatus());
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Test(org.junit.Test)

Example 10 with CreateJobResponse

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

the class CliJobCreationTest method testTemplateAmbiguousJobJsonOutput.

@Test
public void testTemplateAmbiguousJobJsonOutput() throws Exception {
    // Create two jobs
    cli("create", testJobNameAndVersion, BUSYBOX);
    cli("create", testJobNameAndVersion + "1", BUSYBOX);
    // Trying to create a job with an ambiguous template reference should return JSON with
    // AMBIGUOUS_JOB_REFERENCE
    final String output = cli("create", "--json", "--template", testJobNameAndVersion, testJobNameAndVersion, BUSYBOX);
    final CreateJobResponse createJobResponse = Json.read(output, CreateJobResponse.class);
    assertEquals(CreateJobResponse.Status.AMBIGUOUS_JOB_REFERENCE, createJobResponse.getStatus());
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Test(org.junit.Test)

Aggregations

CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)31 Test (org.junit.Test)24 Job (com.spotify.helios.common.descriptors.Job)16 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)16 HeliosClient (com.spotify.helios.client.HeliosClient)14 Deployment (com.spotify.helios.common.descriptors.Deployment)14 JobId (com.spotify.helios.common.descriptors.JobId)13 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)7 DockerClient (com.spotify.docker.client.DockerClient)6 AgentMain (com.spotify.helios.agent.AgentMain)4 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)4 HostStatus (com.spotify.helios.common.descriptors.HostStatus)3 JobDeleteResponse (com.spotify.helios.common.protocol.JobDeleteResponse)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Container (com.spotify.docker.client.messages.Container)2 HostConfig (com.spotify.docker.client.messages.HostConfig)2 PortMapping (com.spotify.helios.common.descriptors.PortMapping)2 HostDeregisterResponse (com.spotify.helios.common.protocol.HostDeregisterResponse)2 Integer.toHexString (java.lang.Integer.toHexString)2 List (java.util.List)2