Search in sources :

Example 16 with CreateJobResponse

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

the class VolumeTest method testClient.

@Test
public void testClient() throws Exception {
    final CreateJobResponse created = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, created.getStatus());
    assertVolumes(job.getId());
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Test(org.junit.Test)

Example 17 with CreateJobResponse

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

the class JobsResource method post.

/**
   * Create a job given the definition in {@code job}.
   *
   * @param job The job to create.
   * @param username The user creating the job.
   * @return The response.
   */
@POST
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public CreateJobResponse post(@Valid final Job job, @RequestUser final String username) {
    final Job.Builder clone = job.toBuilder().setCreatingUser(username).setCreated(clock.now().getMillis()).setHash(job.getId().getHash());
    final Job actualJob = clone.build();
    final Collection<String> errors = jobValidator.validate(actualJob);
    final String jobIdString = actualJob.getId().toString();
    if (!errors.isEmpty()) {
        throw badRequest(new CreateJobResponse(INVALID_JOB_DEFINITION, ImmutableList.copyOf(errors), jobIdString));
    }
    try {
        model.addJob(actualJob);
    } catch (JobExistsException e) {
        throw badRequest(new CreateJobResponse(JOB_ALREADY_EXISTS, ImmutableList.<String>of(), jobIdString));
    }
    log.info("created job: {}", actualJob);
    return new CreateJobResponse(CreateJobResponse.Status.OK, ImmutableList.<String>of(), jobIdString);
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) JobExistsException(com.spotify.helios.master.JobExistsException) Job(com.spotify.helios.common.descriptors.Job) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 18 with CreateJobResponse

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

the class TokenTest method testJobWithToken.

@Test
public void testJobWithToken() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());
    final HeliosClient client = defaultClient();
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Create a job and specify a token
    final CreateJobResponse createJobResponse = cliJson(CreateJobResponse.class, "create", TOKEN, testJobNameAndVersion, BUSYBOX);
    assertThat(createJobResponse.getStatus(), equalTo(CreateJobResponse.Status.OK));
    // Now run all operations which honor the token. Test that they work as
    // expected when given no token, the wrong token, and the correct token.
    deploy(NO_TOKEN, JobDeployResponse.Status.FORBIDDEN);
    deploy(WRONG_TOKEN, JobDeployResponse.Status.FORBIDDEN);
    deploy(TOKEN, JobDeployResponse.Status.OK);
    stop(NO_TOKEN, SetGoalResponse.Status.FORBIDDEN);
    stop(WRONG_TOKEN, SetGoalResponse.Status.FORBIDDEN);
    stop(TOKEN, SetGoalResponse.Status.OK);
    undeploy(NO_TOKEN, JobUndeployResponse.Status.FORBIDDEN);
    undeploy(WRONG_TOKEN, JobUndeployResponse.Status.FORBIDDEN);
    undeploy(TOKEN, JobUndeployResponse.Status.OK);
    remove(NO_TOKEN, JobDeleteResponse.Status.FORBIDDEN);
    remove(WRONG_TOKEN, JobDeleteResponse.Status.FORBIDDEN);
    remove(TOKEN, JobDeleteResponse.Status.OK);
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) HeliosClient(com.spotify.helios.client.HeliosClient) Test(org.junit.Test)

Example 19 with CreateJobResponse

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

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

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