Search in sources :

Example 1 with JobNotDeployedException

use of com.spotify.helios.master.JobNotDeployedException in project helios by spotify.

the class ExpiredJobReaper method runOneIteration.

@Override
public void runOneIteration() {
    for (final Entry<JobId, Job> entry : masterModel.getJobs().entrySet()) {
        final JobId jobId = entry.getKey();
        final Job job = entry.getValue();
        if (job.getExpires() == null) {
            //noinspection UnnecessaryContinue
            continue;
        } else if (job.getExpires().getTime() <= clock.now().getMillis()) {
            final JobStatus status = masterModel.getJobStatus(jobId);
            final List<String> hosts = ImmutableList.copyOf(status.getDeployments().keySet());
            for (final String host : hosts) {
                try {
                    masterModel.undeployJob(host, jobId, job.getToken());
                } catch (HostNotFoundException e) {
                    log.error("couldn't undeploy job {} from host {} when it hit deadline", jobId, host, e);
                } catch (JobNotDeployedException e) {
                    log.debug("job {} was already undeployed when it hit deadline", jobId, e);
                } catch (TokenVerificationException e) {
                    log.error("couldn't undeploy job {} from host {} because token verification failed", jobId, host, e);
                }
            }
            try {
                masterModel.removeJob(jobId, job.getToken());
            } catch (JobDoesNotExistException e) {
                log.debug("job {} was already removed when it hit deadline", jobId, e);
            } catch (JobStillDeployedException e) {
                log.debug("job {} still deployed on some host(s) after expiry reap", jobId, e);
            } catch (TokenVerificationException e) {
                log.error("couldn't remove job {} because token verification failed", jobId, e);
            }
        }
    }
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) HostNotFoundException(com.spotify.helios.master.HostNotFoundException) TokenVerificationException(com.spotify.helios.master.TokenVerificationException) JobStillDeployedException(com.spotify.helios.master.JobStillDeployedException) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) JobNotDeployedException(com.spotify.helios.master.JobNotDeployedException) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId)

Example 2 with JobNotDeployedException

use of com.spotify.helios.master.JobNotDeployedException in project helios by spotify.

the class ZooKeeperMasterModelIntegrationTest method testUpdateDeploy.

@Test
public void testUpdateDeploy() throws Exception {
    try {
        stopJob(model, JOB);
        fail("should have thrown JobNotDeployedException");
    } catch (JobNotDeployedException e) {
        assertTrue(true);
    } catch (Exception e) {
        fail("Should have thrown an JobNotDeployedException, got " + e.getClass());
    }
    model.addJob(JOB);
    try {
        stopJob(model, JOB);
        fail("should have thrown exception");
    } catch (HostNotFoundException e) {
        assertTrue(true);
    } catch (Exception e) {
        fail("Should have thrown an HostNotFoundException");
    }
    model.registerHost(HOST, "foo");
    final List<String> hosts = model.listHosts();
    assertThat(hosts, hasItem(HOST));
    try {
        stopJob(model, JOB);
        fail("should have thrown exception");
    } catch (JobNotDeployedException e) {
        assertTrue(true);
    } catch (Exception e) {
        fail("Should have thrown an JobNotDeployedException");
    }
    model.deployJob(HOST, Deployment.newBuilder().setGoal(Goal.START).setJobId(JOB.getId()).build());
    final Map<JobId, Job> jobsOnHost = model.getJobs();
    assertEquals(1, jobsOnHost.size());
    final Job descriptor = jobsOnHost.get(JOB.getId());
    assertEquals(JOB, descriptor);
    // should succeed this time!
    stopJob(model, JOB);
    final Deployment jobCfg = model.getDeployment(HOST, JOB.getId());
    assertEquals(Goal.STOP, jobCfg.getGoal());
}
Also used : HostNotFoundException(com.spotify.helios.master.HostNotFoundException) Deployment(com.spotify.helios.common.descriptors.Deployment) JobNotDeployedException(com.spotify.helios.master.JobNotDeployedException) Job(com.spotify.helios.common.descriptors.Job) JobStillDeployedException(com.spotify.helios.master.JobStillDeployedException) DeploymentGroupDoesNotExistException(com.spotify.helios.master.DeploymentGroupDoesNotExistException) DeploymentGroupExistsException(com.spotify.helios.master.DeploymentGroupExistsException) HostNotFoundException(com.spotify.helios.master.HostNotFoundException) ExpectedException(org.junit.rules.ExpectedException) JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) JobNotDeployedException(com.spotify.helios.master.JobNotDeployedException) HeliosException(com.spotify.helios.common.HeliosException) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Aggregations

Job (com.spotify.helios.common.descriptors.Job)2 JobId (com.spotify.helios.common.descriptors.JobId)2 HostNotFoundException (com.spotify.helios.master.HostNotFoundException)2 JobDoesNotExistException (com.spotify.helios.master.JobDoesNotExistException)2 JobNotDeployedException (com.spotify.helios.master.JobNotDeployedException)2 JobStillDeployedException (com.spotify.helios.master.JobStillDeployedException)2 ImmutableList (com.google.common.collect.ImmutableList)1 HeliosException (com.spotify.helios.common.HeliosException)1 Deployment (com.spotify.helios.common.descriptors.Deployment)1 JobStatus (com.spotify.helios.common.descriptors.JobStatus)1 DeploymentGroupDoesNotExistException (com.spotify.helios.master.DeploymentGroupDoesNotExistException)1 DeploymentGroupExistsException (com.spotify.helios.master.DeploymentGroupExistsException)1 TokenVerificationException (com.spotify.helios.master.TokenVerificationException)1 List (java.util.List)1 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1