use of com.spotify.helios.common.descriptors.JobStatus in project helios by spotify.
the class MultipleHostsTest method testFilteringJobAndHostStatuses.
@Test
public void testFilteringJobAndHostStatuses() throws Exception {
final String aHost = testHost() + "a";
final String bHost = testHost() + "b";
startDefaultMaster();
startDefaultAgent(aHost);
startDefaultAgent(bHost);
awaitHostStatus(aHost, UP, LONG_WAIT_SECONDS, SECONDS);
awaitHostStatus(bHost, UP, LONG_WAIT_SECONDS, SECONDS);
final HeliosClient client = defaultClient();
final Job job = Job.newBuilder().setName(testJobName + "I_WANT_THIS_ONE").setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
final JobId jobId = job.getId();
client.createJob(job).get();
final Job job2 = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
final JobId jobId2 = job2.getId();
client.createJob(job2).get();
final Deployment deployment = Deployment.of(jobId, Goal.START);
client.deploy(deployment, aHost);
client.deploy(deployment, bHost);
client.deploy(Deployment.of(jobId2, Goal.START), aHost);
awaitJobState(client, aHost, jobId, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
awaitJobState(client, bHost, jobId, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
awaitJobState(client, aHost, jobId2, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
final Map<JobId, JobStatus> cliStatuses = new ObjectMapper().readValue(cli("status", "--job", "I_WANT_THIS_ONE", "--host", aHost, "--json"), new TypeReference<Map<JobId, JobStatus>>() {
});
assertEquals("status should only have one job", 1, cliStatuses.size());
assertTrue(cliStatuses.containsKey(jobId));
final JobStatus status = cliStatuses.get(jobId);
assertEquals("deployments should have only one item", 1, status.getDeployments().size());
assertTrue("should only have deployment info for aHost", status.getDeployments().containsKey(aHost));
assertEquals("Task statuses should only have one item", 1, status.getTaskStatuses().size());
assertTrue("should only have status info for aHost", status.getTaskStatuses().containsKey(aHost));
}
use of com.spotify.helios.common.descriptors.JobStatus in project helios by spotify.
the class SystemTestBase method deployJob.
protected void deployJob(final JobId jobId, final String host, final String token) throws Exception {
final List<String> deployArgs = Lists.newArrayList(jobId.toString(), host);
if (token != null) {
deployArgs.addAll(ImmutableList.of("--token", token));
}
final String deployOutput = cli("deploy", deployArgs);
assertThat(deployOutput, containsString(host + ": done"));
final String output = cli("status", "--host", host, "--json");
final Map<JobId, JobStatus> statuses = Json.readUnchecked(output, new TypeReference<Map<JobId, JobStatus>>() {
});
assertTrue(statuses.keySet().contains(jobId));
}
use of com.spotify.helios.common.descriptors.JobStatus 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.common.descriptors.JobStatus in project helios by spotify.
the class ExpiredJobReaperTest method testExpiredJobReaper.
@Test
public void testExpiredJobReaper() throws Exception {
when(mockClock.now()).thenReturn(new Instant(CURRENT_TS));
when(masterModel.getJobs()).thenReturn(JOBS);
when(masterModel.getJobStatus(any(JobId.class))).then(new Answer<JobStatus>() {
@Override
public JobStatus answer(final InvocationOnMock invocation) throws Throwable {
final JobId jobId = (JobId) invocation.getArguments()[0];
final Map<String, Deployment> deployments = ImmutableMap.of("hostA", Deployment.of(jobId, Goal.START), "hostB", Deployment.of(jobId, Goal.START));
return JobStatus.newBuilder().setJob(JOBS.get(jobId)).setDeployments(deployments).build();
}
});
ExpiredJobReaper.newBuilder().setClock(mockClock).setMasterModel(masterModel).build().runOneIteration();
// Make sure that the expiring job was removed, but that the non-expiring job
// and the job that expires far in the future were not.
verify(masterModel).undeployJob(eq("hostA"), eq(EXPIRING_JOB_ID), eq(""));
verify(masterModel).undeployJob(eq("hostB"), eq(EXPIRING_JOB_ID), eq(""));
verify(masterModel).removeJob(eq(EXPIRING_JOB_ID), eq(""));
verifyNoMoreInteractions(ignoreStubs(masterModel));
}
use of com.spotify.helios.common.descriptors.JobStatus in project helios by spotify.
the class TemporaryJob method verifyHealthy.
void verifyHealthy() throws AssertionError {
log.debug("Checking health of {}", job.getImage());
final JobStatus status = Futures.getUnchecked(client.jobStatus(job.getId()));
if (status == null) {
return;
}
for (final Map.Entry<String, TaskStatus> entry : status.getTaskStatuses().entrySet()) {
verifyHealthy(entry.getKey(), entry.getValue());
}
}
Aggregations