*/
@Override
@Transactional(rollbackFor = GenieException.class)
public Job killJob(final String id) throws GenieException {
if (StringUtils.isBlank(id)) {
throw new GeniePreconditionException("No id entered unable to kill job.");
}
LOG.debug("called for id: " + id);
final Job job = this.jobRepo.findOne(id);
// do some basic error handling
if (job == null) {
throw new GenieNotFoundException("No job exists for id " + id + ". Unable to kill.");
}
// check if it is done already
if (job.getStatus() == JobStatus.SUCCEEDED
|| job.getStatus() == JobStatus.KILLED
|| job.getStatus() == JobStatus.FAILED) {
// job already exited, return status to user
return job;
} else if (job.getStatus() == JobStatus.INIT
|| job.getProcessHandle() == -1) {
// can't kill a job if it is still initializing
throw new GeniePreconditionException("Unable to kill job as it is still initializing");
}
// if we get here, job is still running - and can be killed
// redirect to the right node if killURI points to a different node
final String killURI = job.getKillURI();
if (StringUtils.isBlank(killURI)) {
throw new GeniePreconditionException("Failed to get killURI for jobID: " + id);
}
final String localURI = getEndPoint() + "/" + JOB_RESOURCE_PREFIX + "/" + id;
if (!killURI.equals(localURI)) {
LOG.debug("forwarding kill request to: " + killURI);