use of com.spotify.helios.client.HeliosClient 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.client.HeliosClient 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);
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class DeploymentGroupTest method testStoppedJob.
@Test
public void testStoppedJob() 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);
// Create the deployment group and two jobs
cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
final JobId firstJobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
final String secondJobVersion = randomHexString();
final String secondJobNameAndVersion = testJobName + ":" + secondJobVersion;
final JobId secondJobId = createJob(testJobName, secondJobVersion, BUSYBOX, IDLE_COMMAND);
// Trigger a rolling update of the first job
cli("rolling-update", "--async", testJobNameAndVersion, TEST_GROUP);
awaitTaskState(firstJobId, host, TaskStatus.State.RUNNING);
awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
// Stop the job
cli("stop", testJobNameAndVersion, host);
awaitTaskState(firstJobId, host, TaskStatus.State.STOPPED);
// Trigger a rolling update, replacing the first job with the second.
// Verify the first job is undeployed and the second job is running.
cli("rolling-update", "--async", secondJobNameAndVersion, TEST_GROUP);
awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
awaitTaskState(secondJobId, host, TaskStatus.State.RUNNING);
final JobStatus status = client.jobStatus(firstJobId).get();
assertThat(status.getDeployments().isEmpty(), is(true));
// Stop the job
cli("stop", secondJobNameAndVersion, host);
awaitTaskState(secondJobId, host, TaskStatus.State.STOPPED);
// Trigger a rolling update of the same job, and verify the job gets started. This takes
// a different code path than when replacing a different job, which we tested above.
cli("rolling-update", "--async", secondJobNameAndVersion, TEST_GROUP);
awaitTaskState(secondJobId, host, TaskStatus.State.RUNNING);
awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class CliHostListTest method testStatusFilter.
@Test
public void testStatusFilter() throws Exception {
String jsonOutput = cli("hosts", "-f", "--json", "--status", "UP");
Map<String, HostStatus> statuses = Json.readUnchecked(jsonOutput, new TypeReference<Map<String, HostStatus>>() {
});
final HeliosClient client = defaultClient();
Map<String, HostStatus> expectedStatuses = client.hostStatuses(ImmutableList.of(hostname1)).get();
assertThat(expectedStatuses, equalTo(statuses));
jsonOutput = cli("hosts", "-f", "--json", "--status", "DOWN");
statuses = Json.readUnchecked(jsonOutput, new TypeReference<Map<String, HostStatus>>() {
});
expectedStatuses = client.hostStatuses(ImmutableList.of(hostname2)).get();
assertThat(expectedStatuses, equalTo(statuses));
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class AgentReportingTest method verifyAgentReportsDockerVersion.
@Test
public void verifyAgentReportsDockerVersion() throws Exception {
startDefaultMaster();
startDefaultAgent(testHost());
final HeliosClient client = defaultClient();
final DockerVersion dockerVersion = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<DockerVersion>() {
@Override
public DockerVersion call() throws Exception {
final HostStatus status = client.hostStatus(testHost()).get();
return status == null ? null : status.getHostInfo() == null ? null : status.getHostInfo().getDockerVersion();
}
});
try (final DockerClient dockerClient = getNewDockerClient()) {
final String expectedDockerVersion = dockerClient.version().version();
assertThat(dockerVersion.getVersion(), is(expectedDockerVersion));
}
}
Aggregations