Search in sources :

Example 1 with JobAlreadyDeployedException

use of com.spotify.helios.master.JobAlreadyDeployedException 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)

Aggregations

ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1 Timed (com.codahale.metrics.annotation.Timed)1 Deployment (com.spotify.helios.common.descriptors.Deployment)1 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)1 HostNotFoundException (com.spotify.helios.master.HostNotFoundException)1 JobAlreadyDeployedException (com.spotify.helios.master.JobAlreadyDeployedException)1 JobDoesNotExistException (com.spotify.helios.master.JobDoesNotExistException)1 JobPortAllocationConflictException (com.spotify.helios.master.JobPortAllocationConflictException)1 TokenVerificationException (com.spotify.helios.master.TokenVerificationException)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1