use of com.spotify.helios.common.protocol.JobDeleteResponse in project helios by spotify.
the class JobRemoveTest method testRemoveJobDeletesHistory.
@Test
public void testRemoveJobDeletesHistory() throws Exception {
startDefaultAgent(testHost());
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId, testHost());
awaitJobState(defaultClient(), testHost(), jobId, TaskStatus.State.RUNNING, LONG_WAIT_SECONDS, SECONDS);
undeployJob(jobId, testHost());
awaitJobUndeployed(defaultClient(), testHost(), jobId, LONG_WAIT_SECONDS, SECONDS);
final ZooKeeperClient zkClient = new ZooKeeperClientProvider(new DefaultZooKeeperClient(zk().curatorWithSuperAuth()), ZooKeeperModelReporter.noop()).get("test-client");
// Check that there's some history events
assertNotNull(zkClient.stat(Paths.historyJob(jobId)));
// Remove job
final JobDeleteResponse response = defaultClient().deleteJob(jobId).get(WAIT_TIMEOUT_SECONDS, SECONDS);
assertEquals(JobDeleteResponse.Status.OK, response.getStatus());
// Verify that history is gone
assertNull(zkClient.stat(Paths.historyJob(jobId)));
}
use of com.spotify.helios.common.protocol.JobDeleteResponse in project helios by spotify.
the class TokenTest method remove.
private void remove(final String token, final JobDeleteResponse.Status status) throws Exception {
final List<String> args = buildArgs(token, "--yes", testJobNameAndVersion);
final JobDeleteResponse response = cliJson(JobDeleteResponse.class, "remove", args);
assertThat(response.getStatus(), equalTo(status));
}
use of com.spotify.helios.common.protocol.JobDeleteResponse 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.protocol.JobDeleteResponse in project helios by spotify.
the class Jobs method undeploy.
/**
* Undeploy the job from all specified hosts, and delete the job. Any failures will be ignored,
* and we will keep trying each host. A list of errors encountered along the way will be returned
* to the caller.
* @param client the HeliosClient to use
* @param job the job to undeploy and delete
* @param hosts the hosts to undeploy from
* @param errors errors encountered during the undeploy will be added to this list
* @return the list of errors
*/
static List<AssertionError> undeploy(final HeliosClient client, final Job job, final List<String> hosts, final List<AssertionError> errors) {
final JobId id = job.getId();
for (final String host : hosts) {
log.info("Undeploying {} from {}", getJobDescription(job), host);
final JobUndeployResponse response;
try {
response = get(client.undeploy(id, host));
if (response.getStatus() != JobUndeployResponse.Status.OK && response.getStatus() != JobUndeployResponse.Status.JOB_NOT_FOUND) {
errors.add(new AssertionError(format("Failed to undeploy job %s - %s", id, response)));
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
errors.add(new AssertionError(e));
}
}
try {
log.debug("Deleting job {}", id);
final JobDeleteResponse response = get(client.deleteJob(id));
if (response.getStatus() != JobDeleteResponse.Status.OK && response.getStatus() != JobDeleteResponse.Status.JOB_NOT_FOUND) {
errors.add(new AssertionError(format("Failed to delete job %s - %s", id.toString(), response.toString())));
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
errors.add(new AssertionError(e));
}
return errors;
}
use of com.spotify.helios.common.protocol.JobDeleteResponse in project helios by spotify.
the class HeliosIT method test.
@Test
public void test() throws Exception {
final CreateJobResponse create = cli(CreateJobResponse.class, "create", "test:1", "spotify/busybox:latest");
assertThat(create.getStatus(), equalTo(CreateJobResponse.Status.OK));
final JobDeployResponse deploy = cli(JobDeployResponse.class, "deploy", "test:1", TEST_HOST);
assertThat(deploy.getStatus(), equalTo(JobDeployResponse.Status.OK));
final JobUndeployResponse undeploy = cli(JobUndeployResponse.class, "undeploy", "--yes", "test:1", "-a");
assertThat(undeploy.getStatus(), equalTo(JobUndeployResponse.Status.OK));
final JobDeleteResponse delete = cli(JobDeleteResponse.class, "remove", "--yes", "test:1");
assertThat(delete.getStatus(), equalTo(JobDeleteResponse.Status.OK));
}
Aggregations