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());
}
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);
}
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);
}
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);
}
}
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());
}
Aggregations