use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class JobHistoryTest method testJobHistoryDisabled.
@Test
public void testJobHistoryDisabled() throws Exception {
startDefaultMaster();
final HeliosClient client = defaultClient();
startDefaultAgent(testHost(), "--disable-job-history");
awaitHostStatus(testHost(), Status.UP, LONG_WAIT_SECONDS, SECONDS);
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId, testHost());
awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
undeployJob(jobId, testHost());
awaitTaskGone(client, testHost(), jobId, LONG_WAIT_SECONDS, SECONDS);
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class JobHistoryTest method testJobHistory.
@Test
public void testJobHistory() throws Exception {
startDefaultMaster();
final HeliosClient client = defaultClient();
startDefaultAgent(testHost());
awaitHostStatus(testHost(), Status.UP, LONG_WAIT_SECONDS, SECONDS);
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId, testHost());
awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
undeployJob(jobId, testHost());
awaitTaskGone(client, testHost(), jobId, LONG_WAIT_SECONDS, SECONDS);
final TaskStatusEvents events = Polling.await(WAIT_TIMEOUT_SECONDS, SECONDS, new Callable<TaskStatusEvents>() {
@Override
public TaskStatusEvents call() throws Exception {
final TaskStatusEvents events = client.jobHistory(jobId).get();
final int size = events.getEvents().size();
if (size == 0) {
return null;
}
// We sometimes get more than one PULLING_IMAGE in the history if a pull tempfails.
int requiredEventCount = -1;
for (int i = 0; i < size; i++) {
if (events.getEvents().get(i).getStatus().getState() != State.PULLING_IMAGE) {
requiredEventCount = i + 5;
break;
}
}
if (requiredEventCount == -1) {
return null;
}
if (size < requiredEventCount) {
return null;
}
return events;
}
});
final ListIterator<TaskStatusEvent> it = events.getEvents().listIterator();
while (true) {
final TaskStatusEvent event = it.next();
if (event.getStatus().getState() != State.PULLING_IMAGE) {
//rewind so that this event is the one returned by the next call to it.next() below
it.previous();
break;
}
assertThat(event, not(hasContainerId()));
}
assertThat(it.next(), allOf(hasState(State.CREATING), not(hasContainerId())));
assertThat(it.next(), allOf(hasState(State.STARTING), hasContainerId()));
assertThat(it.next(), hasState(State.RUNNING));
assertThat(it.next(), hasState(State.STOPPING));
assertThat(it.next(), hasState(State.EXITED, State.STOPPED));
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class JobListTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
startDefaultAgent(testHost());
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Create job
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
// Test successful find
// testJobName is of the form job_test_hexstring:vhexstring
final String result1 = cli("jobs", "ob_", "--json");
final Map<String, Object> resultObj1 = OBJECT_MAPPER.readValue(result1, MAP_TYPE);
assertFalse(resultObj1.isEmpty());
final Entry<String, Object> firstEntry = get(resultObj1.entrySet(), 0);
assertEquals(jobId.toString(), firstEntry.getKey());
// Test didn't find
final String result2 = cli("jobs", "FramAZaMaWonTF1nD", "--json");
final Map<String, Object> resultObj2 = OBJECT_MAPPER.readValue(result2, MAP_TYPE);
// It might conceivably get here at some point, but better be empty if it does
assertTrue(resultObj2.isEmpty());
final String result3 = cli("jobs", "-y", "--json");
final Map<String, Object> resultObj3 = OBJECT_MAPPER.readValue(result3, MAP_TYPE);
assertTrue("Expected empty map but got: " + result3, resultObj3.isEmpty());
final HeliosClient client = defaultClient();
client.deploy(Deployment.of(jobId, Goal.START), testHost());
awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
final String result4 = cli("jobs", "-y", "--json");
final Map<String, Object> resultObj4 = OBJECT_MAPPER.readValue(result4, MAP_TYPE);
assertFalse(resultObj4.isEmpty());
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class DeploymentGroupTest method testRemoveDeploymentGroupActive.
@Test
public void testRemoveDeploymentGroupActive() 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);
// Use an invalid image to make sure the DG doesn't succeed (this ensure the DG will be active
// for 5+ minutes, which is plenty of time).
final JobId jobId = createJob(testJobName, testJobVersion, "invalid_image", IDLE_COMMAND);
cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
cli("rolling-update", "--async", "--migrate", testJobNameAndVersion, TEST_GROUP);
final RemoveDeploymentGroupResponse response = defaultClient().removeDeploymentGroup(TEST_GROUP).get();
assertEquals(RemoveDeploymentGroupResponse.Status.REMOVED, response.getStatus());
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class DeploymentGroupTest method testRollingUpdateMigrateNothingToUndeploy.
@Test
public void testRollingUpdateMigrateNothingToUndeploy() 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
final String manualJobVersion = "foo-" + testJobVersion;
final JobId manualJobId = createJob(testJobName, manualJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(manualJobId, host);
awaitTaskState(manualJobId, host, TaskStatus.State.RUNNING);
// create a deployment group and trigger a migration rolling-update -- with a different
// job that the one deployed manually! The manually deployed job should remain running on the
// host.
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
cli("rolling-update", "--async", "--migrate", testJobNameAndVersion, TEST_GROUP);
// rolling-update should succeed & job should be running
awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
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);
// Ensure that the manually deployed job is still there & running
final Deployment manualDeployment = defaultClient().hostStatus(host).get().getJobs().get(manualJobId);
assertNotNull(manualDeployment);
assertEquals(Goal.START, manualDeployment.getGoal());
}
Aggregations