Search in sources :

Example 1 with JobDoesNotExistException

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

the class DeploymentGroupResource method rollingUpdate.

@POST
@Path("/{name}/rolling-update")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public Response rollingUpdate(@PathParam("name") @Valid final String name, @Valid final RollingUpdateRequest args) {
    try {
        final DeploymentGroup deploymentGroup = model.getDeploymentGroup(name);
        model.rollingUpdate(deploymentGroup, args.getJob(), args.getRolloutOptions());
        return Response.ok(new RollingUpdateResponse(RollingUpdateResponse.Status.OK)).build();
    } catch (DeploymentGroupDoesNotExistException e) {
        return Response.ok(new RollingUpdateResponse(RollingUpdateResponse.Status.DEPLOYMENT_GROUP_NOT_FOUND)).build();
    } catch (JobDoesNotExistException e) {
        return Response.ok(new RollingUpdateResponse(RollingUpdateResponse.Status.JOB_NOT_FOUND)).build();
    }
}
Also used : JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) DeploymentGroupDoesNotExistException(com.spotify.helios.master.DeploymentGroupDoesNotExistException) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 2 with JobDoesNotExistException

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

the class HostsResource method jobPut.

/**
 * Sets the deployment of the job identified by its {@link JobId} on the host named by
 * {@code host} to {@code deployment}.
 *
 * @param host       The host to deploy to.
 * @param jobId      The job to deploy.
 * @param deployment Deployment information.
 * @param username   The user deploying.
 * @param token      The authorization token for this deployment.
 *
 * @return The response.
 */
@PUT
@Path("/{host}/jobs/{job}")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public JobDeployResponse jobPut(@PathParam("host") final String host, @PathParam("job") final JobId jobId, @Valid final Deployment deployment, @RequestUser final String username, @QueryParam("token") @DefaultValue(EMPTY_TOKEN) final String token) {
    if (!jobId.isFullyQualified()) {
        throw badRequest(new JobDeployResponse(JobDeployResponse.Status.INVALID_ID, host, jobId));
    }
    try {
        final Deployment actualDeployment = deployment.toBuilder().setDeployerUser(username).build();
        model.deployJob(host, actualDeployment, token);
        return new JobDeployResponse(JobDeployResponse.Status.OK, host, jobId);
    } catch (JobAlreadyDeployedException e) {
        throw badRequest(new JobDeployResponse(JobDeployResponse.Status.JOB_ALREADY_DEPLOYED, host, jobId));
    } catch (HostNotFoundException e) {
        throw badRequest(new JobDeployResponse(JobDeployResponse.Status.HOST_NOT_FOUND, host, jobId));
    } catch (JobDoesNotExistException e) {
        throw badRequest(new JobDeployResponse(JobDeployResponse.Status.JOB_NOT_FOUND, host, jobId));
    } catch (JobPortAllocationConflictException e) {
        throw badRequest(new JobDeployResponse(JobDeployResponse.Status.PORT_CONFLICT, host, jobId));
    } catch (TokenVerificationException e) {
        throw forbidden(new JobDeployResponse(JobDeployResponse.Status.FORBIDDEN, host, jobId));
    }
}
Also used : JobPortAllocationConflictException(com.spotify.helios.master.JobPortAllocationConflictException) JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) HostNotFoundException(com.spotify.helios.master.HostNotFoundException) TokenVerificationException(com.spotify.helios.master.TokenVerificationException) Deployment(com.spotify.helios.common.descriptors.Deployment) JobAlreadyDeployedException(com.spotify.helios.master.JobAlreadyDeployedException) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) PUT(javax.ws.rs.PUT)

Example 3 with JobDoesNotExistException

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

the class HistoryResource method jobHistory.

/**
 * Returns the {@link TaskStatusEvents} for the specified job.
 *
 * @param jobId The ID of the job.
 *
 * @return The history of the jobs.
 *
 * @throws HeliosException If an unexpected error occurs.
 */
@GET
@Produces(APPLICATION_JSON)
@Path("jobs/{id}")
@Timed
@ExceptionMetered
public TaskStatusEvents jobHistory(@PathParam("id") @Valid final JobId jobId) throws HeliosException {
    if (!jobId.isFullyQualified()) {
        throw badRequest("Invalid id");
    }
    try {
        final List<TaskStatusEvent> events = model.getJobHistory(jobId);
        metrics.jobsHistoryEventSize(events.size());
        final TaskStatusEvents result = new TaskStatusEvents(events, OK);
        return result;
    } catch (JobDoesNotExistException e) {
        return new TaskStatusEvents(ImmutableList.<TaskStatusEvent>of(), JOB_ID_NOT_FOUND);
    }
}
Also used : TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) TaskStatusEvents(com.spotify.helios.common.protocol.TaskStatusEvents) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 4 with JobDoesNotExistException

use of com.spotify.helios.master.JobDoesNotExistException 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);
            if (status == null) {
                log.warn("Couldn't find job status for {} because job has already been deleted." + "Skipping.", jobId);
                return;
            }
            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 5 with JobDoesNotExistException

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

the class DeploymentGroupResourceTest method testRollingUpdateJobDoesNotExist.

@Test
public void testRollingUpdateJobDoesNotExist() throws Exception {
    doThrow(new JobDoesNotExistException("")).when(model).rollingUpdate(any(DeploymentGroup.class), any(JobId.class), any(RolloutOptions.class));
    final Response response = resource.rollingUpdate("foo", new RollingUpdateRequest(new JobId("foo", "0.3", "1234"), RolloutOptions.getDefault()));
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(new RollingUpdateResponse(RollingUpdateResponse.Status.JOB_NOT_FOUND), response.getEntity());
}
Also used : RolloutOptions(com.spotify.helios.common.descriptors.RolloutOptions) RemoveDeploymentGroupResponse(com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) CreateDeploymentGroupResponse(com.spotify.helios.common.protocol.CreateDeploymentGroupResponse) Response(javax.ws.rs.core.Response) JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) RollingUpdateRequest(com.spotify.helios.common.protocol.RollingUpdateRequest) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Aggregations

JobDoesNotExistException (com.spotify.helios.master.JobDoesNotExistException)5 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)3 Timed (com.codahale.metrics.annotation.Timed)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)2 JobId (com.spotify.helios.common.descriptors.JobId)2 RollingUpdateResponse (com.spotify.helios.common.protocol.RollingUpdateResponse)2 HostNotFoundException (com.spotify.helios.master.HostNotFoundException)2 TokenVerificationException (com.spotify.helios.master.TokenVerificationException)2 ImmutableList (com.google.common.collect.ImmutableList)1 Deployment (com.spotify.helios.common.descriptors.Deployment)1 Job (com.spotify.helios.common.descriptors.Job)1 JobStatus (com.spotify.helios.common.descriptors.JobStatus)1 RolloutOptions (com.spotify.helios.common.descriptors.RolloutOptions)1 TaskStatusEvent (com.spotify.helios.common.descriptors.TaskStatusEvent)1 CreateDeploymentGroupResponse (com.spotify.helios.common.protocol.CreateDeploymentGroupResponse)1 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)1 RemoveDeploymentGroupResponse (com.spotify.helios.common.protocol.RemoveDeploymentGroupResponse)1 RollingUpdateRequest (com.spotify.helios.common.protocol.RollingUpdateRequest)1