use of com.spotify.helios.common.protocol.CreateJobResponse in project helios by spotify.
the class TokenTest method testJobWithoutToken.
@Test
public void testJobWithoutToken() 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 without a token
final CreateJobResponse createJobResponse = cliJson(CreateJobResponse.class, "create", testJobNameAndVersion, BUSYBOX);
assertThat(createJobResponse.getStatus(), equalTo(CreateJobResponse.Status.OK));
// Now run all operations which honor the token. Test
// that they work as expected with and without a token.
deploy(TOKEN, JobDeployResponse.Status.FORBIDDEN);
deploy(NO_TOKEN, JobDeployResponse.Status.OK);
stop(TOKEN, SetGoalResponse.Status.FORBIDDEN);
stop(NO_TOKEN, SetGoalResponse.Status.OK);
undeploy(TOKEN, JobUndeployResponse.Status.FORBIDDEN);
undeploy(NO_TOKEN, JobUndeployResponse.Status.OK);
remove(TOKEN, JobDeleteResponse.Status.FORBIDDEN);
remove(NO_TOKEN, JobDeleteResponse.Status.OK);
}
use of com.spotify.helios.common.protocol.CreateJobResponse in project helios by spotify.
the class UndeployRaceTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
final String agentId = "test-agent-id";
final HeliosClient client = defaultClient();
// Register a host without the agent running
client.registerHost(testHost(), agentId);
// Create, deploy and undeploy a job on the host without the agent running
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());
final Deployment deployment = Deployment.of(jobId, START);
// Wait for host to be registered in the master. Otherwise, the client.deploy() call will
// return HOST_NOT_FOUND
Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {
@Override
public String call() throws Exception {
final List<String> hosts = client.listHosts().get();
if (hosts.contains(testHost())) {
return testHost();
}
return null;
}
});
final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
final JobUndeployResponse undeployed = client.undeploy(jobId, testHost()).get();
assertEquals(JobUndeployResponse.Status.OK, undeployed.getStatus());
// Start agent
startDefaultAgent(testHost(), "--id", agentId);
awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// 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());
}
use of com.spotify.helios.common.protocol.CreateJobResponse in project helios by spotify.
the class PortCollisionJobTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
startDefaultAgent(testHost());
final HeliosClient client = defaultClient();
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
final Job job1 = Job.newBuilder().setName(testTag + "foo").setVersion("1").setImage(BUSYBOX).setCommand(IDLE_COMMAND).setPorts(ImmutableMap.of("foo", PortMapping.of(10001, externalPort))).build();
final Job job2 = Job.newBuilder().setName(testTag + "bar").setVersion("1").setImage(BUSYBOX).setCommand(IDLE_COMMAND).setPorts(ImmutableMap.of("foo", PortMapping.of(10002, externalPort))).build();
final CreateJobResponse created1 = client.createJob(job1).get();
assertEquals(CreateJobResponse.Status.OK, created1.getStatus());
final CreateJobResponse created2 = client.createJob(job2).get();
assertEquals(CreateJobResponse.Status.OK, created2.getStatus());
final Deployment deployment1 = Deployment.of(job1.getId(), STOP);
final JobDeployResponse deployed1 = client.deploy(deployment1, testHost()).get();
assertEquals(JobDeployResponse.Status.OK, deployed1.getStatus());
final Deployment deployment2 = Deployment.of(job2.getId(), STOP);
final JobDeployResponse deployed2 = client.deploy(deployment2, testHost()).get();
assertEquals(JobDeployResponse.Status.PORT_CONFLICT, deployed2.getStatus());
}
use of com.spotify.helios.common.protocol.CreateJobResponse in project helios by spotify.
the class JobCreateCommandTest method setUp.
@Before
public void setUp() {
// use a real, dummy Subparser impl to avoid having to mock out every single call
final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
final Subparser subparser = parser.addSubparsers().addParser("create");
final Supplier<Map<String, String>> envVarSupplier = new Supplier<Map<String, String>>() {
@Override
public Map<String, String> get() {
return ImmutableMap.copyOf(envVars);
}
};
command = new JobCreateCommand(subparser, envVarSupplier);
when(client.createJob(argThat(matchesName(JOB_NAME)))).thenReturn(immediateFuture(new CreateJobResponse(CreateJobResponse.Status.OK, Collections.<String>emptyList(), "12345")));
}
use of com.spotify.helios.common.protocol.CreateJobResponse in project helios by spotify.
the class AgentZooKeeperDownTolerationTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
final DockerClient dockerClient = getNewDockerClient();
final HeliosClient client = defaultClient();
final AgentMain agent1 = startDefaultAgent(testHost());
// Create a job
final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).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());
// 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 firstTaskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
assertJobEquals(job, firstTaskStatus.getJob());
assertNotNull(dockerClient.inspectContainer(firstTaskStatus.getContainerId()));
// Stop zookeeper
zk().stop();
// Wait for a while and make sure that the container is still running
Thread.sleep(5000);
assertTrue(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running());
// Stop the agent
agent1.stopAsync().awaitTerminated();
// Start the agent again
final AgentMain agent2 = startDefaultAgent(testHost());
// Wait for a while and make sure that the same container is still running
Thread.sleep(5000);
assertTrue(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running());
// Kill the container
dockerClient.killContainer(firstTaskStatus.getContainerId());
assertFalse(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running());
// Wait for a while and make sure that a new container was spawned
final String firstRestartedContainerId = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {
@Override
public String call() throws Exception {
final List<Container> containers = listContainers(dockerClient, testTag);
return containers.size() == 1 ? containers.get(0).id() : null;
}
});
// Stop the agent
agent2.stopAsync().awaitTerminated();
// Kill the container
dockerClient.killContainer(firstRestartedContainerId);
assertFalse(dockerClient.inspectContainer(firstRestartedContainerId).state().running());
// Start the agent again
startDefaultAgent(testHost());
// Wait for a while and make sure that a new container was spawned
final String secondRestartedContainerId = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {
@Override
public String call() throws Exception {
final List<Container> containers = listContainers(dockerClient, testTag);
return containers.size() == 1 ? containers.get(0).id() : null;
}
});
assertTrue(dockerClient.inspectContainer(secondRestartedContainerId).state().running());
// Start zookeeper
zk().start();
// Verify that the agent is listed as up
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Wait for the new container id to be reflected in the task status
Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<TaskStatus>() {
@Override
public TaskStatus call() throws Exception {
final JobStatus jobStatus = client.jobStatus(jobId).get();
final TaskStatus taskStatus = jobStatus.getTaskStatuses().get(testHost());
return taskStatus != null && Objects.equals(taskStatus.getContainerId(), secondRestartedContainerId) ? taskStatus : null;
}
});
}
Aggregations