use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class TerminationTest method testNoIntOnExit.
@Test
public void testNoIntOnExit() throws Exception {
startDefaultMaster();
final String host = testHost();
startDefaultAgent(host);
final HeliosClient client = defaultClient();
awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
// Note: signal 2 is SIGINT
final Job jobToInterrupt = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(asList("/bin/sh", "-c", "trap handle 2; handle() { echo int; exit 0; }; " + "while true; do sleep 1; done")).build();
final JobId jobId = createJob(jobToInterrupt);
deployJob(jobId, host);
awaitTaskState(jobId, host, RUNNING);
client.setGoal(new Deployment(jobId, Goal.STOP, Deployment.EMTPY_DEPLOYER_USER, Deployment.EMPTY_DEPLOYER_MASTER, Deployment.EMPTY_DEPLOYMENT_GROUP_NAME), host);
final TaskStatus taskStatus = awaitTaskState(jobId, host, STOPPED);
final String log;
try (final DockerClient dockerClient = getNewDockerClient();
LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout())) {
log = logs.readFully();
}
// No message expected, since SIGINT should not be sent
assertEquals("", log);
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class DeregisterTest method testDeregisterHostThatDoesntExist.
@Test
public void testDeregisterHostThatDoesntExist() throws Exception {
startDefaultMaster();
final String host = testHost();
final HeliosClient client = defaultClient();
final HostDeregisterResponse deregisterResponse = client.deregisterHost(host).get();
assertEquals(HostDeregisterResponse.Status.NOT_FOUND, deregisterResponse.getStatus());
}
use of com.spotify.helios.client.HeliosClient 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());
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class DeploymentGroupTest method testRollingUpdateWithToken.
@Test
public void testRollingUpdateWithToken() throws Exception {
final String host = testHost();
startDefaultAgent(host, "--labels", TEST_LABEL);
// Wait for agent to come up
final HeliosClient client = defaultClient();
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Manually deploy a job with a token on the host (i.e. a job not part of the deployment group)
final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setToken(TOKEN).build();
final JobId jobId = createJob(job);
// Create a deployment-group and trigger a migration rolling-update
cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
cli("rolling-update", "--async", "--token", TOKEN, testJobNameAndVersion, TEST_GROUP);
// rolling-update should succeed & job should be running
awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
// Check that we cannot manually undeploy the job with a token
final String output = cli("undeploy", jobId.toString(), host);
assertThat(output, containsString("FORBIDDEN"));
awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class DeploymentGroupTest method testRollingUpdateMigrateWithToken.
@Test
public void testRollingUpdateMigrateWithToken() throws Exception {
final String host = testHost();
startDefaultAgent(host, "--labels", TEST_LABEL);
// Wait for agent to come up
final HeliosClient client = defaultClient();
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Manually deploy a job with a token on the host (i.e. a job not part of the deployment group)
final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setToken(TOKEN).build();
final JobId jobId = createJob(job);
deployJob(jobId, host, TOKEN);
awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
// Create a deployment-group and trigger a migration rolling-update
cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
cli("rolling-update", "--async", "--migrate", "--token", TOKEN, testJobNameAndVersion, TEST_GROUP);
// Check that the deployment's deployment-group name eventually changes to TEST_GROUP
// (should be null or empty before)
final String jobDeploymentGroup = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {
@Override
public String call() throws Exception {
final Deployment deployment = defaultClient().hostStatus(host).get().getJobs().get(jobId);
if (deployment != null && !isNullOrEmpty(deployment.getDeploymentGroupName())) {
return deployment.getDeploymentGroupName();
} else {
return null;
}
}
});
assertEquals(TEST_GROUP, jobDeploymentGroup);
// rolling-update should succeed & job should be running
awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
}
Aggregations