Search in sources :

Example 6 with JobDeleteResponse

use of com.spotify.helios.common.protocol.JobDeleteResponse in project helios by spotify.

the class JobRemoveCommand method runWithJobId.

@Override
protected int runWithJobId(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final JobId jobId, final BufferedReader stdin) throws IOException, ExecutionException, InterruptedException {
    final boolean yes = options.getBoolean(yesArg.getDest());
    final boolean force = options.getBoolean(forceArg.getDest());
    if (force) {
        log.warn("If you are using '--force' to skip the interactive prompt, " + "note that we have deprecated it. Please use '--yes'.");
    }
    if (!yes && !force) {
        out.printf("This will remove the job %s%n", jobId);
        final boolean confirmed = Utils.userConfirmed(out, stdin);
        if (!confirmed) {
            return 1;
        }
    }
    if (!json) {
        out.printf("Removing job %s%n", jobId);
    }
    int code = 0;
    final String token = options.getString(tokenArg.getDest());
    final JobDeleteResponse response = client.deleteJob(jobId, token).get();
    if (!json) {
        out.printf("%s: ", jobId);
    }
    if (response.getStatus() == JobDeleteResponse.Status.OK) {
        if (json) {
            out.print(response.toJsonString());
        } else {
            out.printf("done%n");
        }
    } else {
        if (json) {
            out.print(response.toJsonString());
        } else {
            out.printf("failed: %s%n", response);
        }
        code = 1;
    }
    return code;
}
Also used : JobDeleteResponse(com.spotify.helios.common.protocol.JobDeleteResponse)

Example 7 with JobDeleteResponse

use of com.spotify.helios.common.protocol.JobDeleteResponse in project helios by spotify.

the class DeregisterTest method testDeregisterJobDeployedWithoutStatus.

// Verify that we can deregister a host there are jobs deployed to it, for which there's no
// corresponding status information. For example, if a job was deployed to the host after is went
// down.
@Test
public void testDeregisterJobDeployedWithoutStatus() throws Exception {
    startDefaultMaster();
    final String host = testHost();
    final HeliosClient client = defaultClient();
    final DefaultZooKeeperClient zkClient = new DefaultZooKeeperClient(zk().curatorWithSuperAuth());
    final String idPath = Paths.configHostId(host);
    ZooKeeperRegistrarUtil.registerHost(zkClient, idPath, host, UUID.randomUUID().toString());
    // 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());
    // 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());
    // 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) Deployment(com.spotify.helios.common.descriptors.Deployment) HeliosClient(com.spotify.helios.client.HeliosClient) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) 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 8 with JobDeleteResponse

use of com.spotify.helios.common.protocol.JobDeleteResponse in project helios by spotify.

the class JobRemoveTest method testRemoveJobWithoutHistory.

@Test
public void testRemoveJobWithoutHistory() throws Exception {
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    final JobDeleteResponse response = defaultClient().deleteJob(jobId).get(WAIT_TIMEOUT_SECONDS, SECONDS);
    assertEquals(JobDeleteResponse.Status.OK, response.getStatus());
}
Also used : JobId(com.spotify.helios.common.descriptors.JobId) 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