Search in sources :

Example 1 with JobDeleteResponse

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)));
}
Also used : ZooKeeperClientProvider(com.spotify.helios.servicescommon.coordination.ZooKeeperClientProvider) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) JobId(com.spotify.helios.common.descriptors.JobId) JobDeleteResponse(com.spotify.helios.common.protocol.JobDeleteResponse) Test(org.junit.Test)

Example 2 with JobDeleteResponse

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));
}
Also used : JobDeleteResponse(com.spotify.helios.common.protocol.JobDeleteResponse)

Example 3 with JobDeleteResponse

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());
}
Also used : HostDeregisterResponse(com.spotify.helios.common.protocol.HostDeregisterResponse) CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) AgentMain(com.spotify.helios.agent.AgentMain) Deployment(com.spotify.helios.common.descriptors.Deployment) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobId(com.spotify.helios.common.descriptors.JobId) JobDeleteResponse(com.spotify.helios.common.protocol.JobDeleteResponse) Test(org.junit.Test)

Example 4 with JobDeleteResponse

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;
}
Also used : JobUndeployResponse(com.spotify.helios.common.protocol.JobUndeployResponse) ExecutionException(java.util.concurrent.ExecutionException) JobId(com.spotify.helios.common.descriptors.JobId) JobDeleteResponse(com.spotify.helios.common.protocol.JobDeleteResponse) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with JobDeleteResponse

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));
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) JobUndeployResponse(com.spotify.helios.common.protocol.JobUndeployResponse) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobDeleteResponse(com.spotify.helios.common.protocol.JobDeleteResponse) Test(org.junit.Test)

Aggregations

JobDeleteResponse (com.spotify.helios.common.protocol.JobDeleteResponse)8 JobId (com.spotify.helios.common.descriptors.JobId)5 Test (org.junit.Test)5 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)3 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)3 HeliosClient (com.spotify.helios.client.HeliosClient)2 Deployment (com.spotify.helios.common.descriptors.Deployment)2 Job (com.spotify.helios.common.descriptors.Job)2 HostDeregisterResponse (com.spotify.helios.common.protocol.HostDeregisterResponse)2 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)2 DefaultZooKeeperClient (com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient)2 AgentMain (com.spotify.helios.agent.AgentMain)1 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)1 ZooKeeperClientProvider (com.spotify.helios.servicescommon.coordination.ZooKeeperClientProvider)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1