use of com.spotify.helios.master.TokenVerificationException 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));
}
}
use of com.spotify.helios.master.TokenVerificationException 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);
}
}
}
}
Aggregations