use of com.spotify.helios.common.descriptors.Deployment 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.common.descriptors.Deployment 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.common.descriptors.Deployment 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);
}
use of com.spotify.helios.common.descriptors.Deployment in project helios by spotify.
the class DeploymentGroupTest method testRollingUpdateMigrate.
@Test
public void testRollingUpdateMigrate() 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 on the host (i.e. a job not part of the deployment group)
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId, host);
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", 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);
}
use of com.spotify.helios.common.descriptors.Deployment in project helios by spotify.
the class DeploymentGroupTest method testRollingUpdate.
@Test
public void testRollingUpdate() throws Exception {
final List<String> hosts = ImmutableList.of("dc1-" + testHost() + "-a1.dc1.example.com", "dc1-" + testHost() + "-a2.dc1.example.com", "dc2-" + testHost() + "-a1.dc2.example.com", "dc2-" + testHost() + "-a3.dc2.example.com", "dc3-" + testHost() + "-a4.dc3.example.com");
// start agents
for (final String host : hosts) {
startDefaultAgent(host, "--labels", TEST_LABEL);
}
// Wait for agents to come up
final HeliosClient client = defaultClient();
for (final String host : hosts) {
awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
}
// create a deployment group and job
cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
// TODO: fix this!
// Wait to make sure the host-update has run
Thread.sleep(1000);
// trigger a rolling update
cli("rolling-update", "--async", testJobNameAndVersion, TEST_GROUP);
// ensure the job is running on all agents and the deployment group reaches DONE
for (final String host : hosts) {
awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
}
final Deployment deployment = defaultClient().hostStatus(hosts.get(0)).get().getJobs().get(jobId);
assertEquals(TEST_GROUP, deployment.getDeploymentGroupName());
awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
// create a second job
final String secondJobVersion = testJobVersion + "2";
final String secondJobNameAndVersion = testJobNameAndVersion + "2";
final JobId secondJobId = createJob(testJobName, secondJobVersion, BUSYBOX, IDLE_COMMAND);
// trigger a rolling update to replace the first job with the second job
final String output = cli("rolling-update", secondJobNameAndVersion, TEST_GROUP);
// Check that the hosts in the output are ordered
final List<String> lines = Lists.newArrayList(Splitter.on("\n").split(output));
for (int i = 0; i < hosts.size(); i++) {
assertThat(lines.get(i + 2), containsString(hosts.get(i)));
}
// ensure the second job rolled out fine
for (final String host : hosts) {
awaitTaskState(secondJobId, host, TaskStatus.State.RUNNING);
}
awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
}
Aggregations