agave-jobs/jobs-core/src/main/java/org/iplantc/service/jobs/managers/JobManager.java
/**
     * Kills a running job by updating its status and using the remote scheduler command and local id to stop it forcefully.
     *
     * @param job the job to kill
     * @throws JobTerminationException if the termination attempt failed
     * @throws JobException if unable to update the job record
     */
Kills a running job by updating its status and using the remote scheduler command and local id to stop it forcefully.
@param job the job to kill
@throws JobTerminationException if the termination attempt failed
@throws JobException if unable to update the job record
Kills a running job by updating its status and using the remote scheduler command and local id to stop it forcefully . @param job the job to kill @throws JobTerminationException if the termination attempt failed @throws JobException if unable to update the job record
public static Job kill(Job job) throws JobTerminationException, JobException {
        if (!JobStatusType.hasQueued(job.getStatus()) || job.getStatus() == JobStatusType.ARCHIVING) {
            job = JobManager.updateStatus(job, JobStatusType.STOPPED, "Job cancelled by user.");
            for (JobEvent event : job.getEvents()) {
                if (event.getTransferTask() != null) {
                    if (event.getTransferTask().getStatus() == TransferStatusType.PAUSED ||
                            event.getTransferTask().getStatus() == TransferStatusType.QUEUED ||
                            event.getTransferTask().getStatus() == TransferStatusType.RETRYING ||
                            event.getTransferTask().getStatus() == TransferStatusType.TRANSFERRING) {
                        try {
                            TransferTaskDao.cancelAllRelatedTransfers(event.getTransferTask().getId());
                        } catch (Exception e) {
                            log.error("Failed to cancel transfer task " +
                                    event.getTransferTask().getUuid() + " while stopping job " +
                                    job.getUuid(), e);
                        }
                    }
                }
            }
            return job;
        } else if (!job.isRunning()) {
            return job;
        } else {
            JobKiller killer = null;
            int retries = 0;
            while (retries < Settings.MAX_SUBMISSION_RETRIES) {
                try {
                    log.debug("Attempt " + (retries + 1) + " to kill job " + job.getUuid() +
                            " and clean up assets");
                    killer = new JobKillerFactory().getInstance(job);
                    killer.attack();
                    log.debug("Successfully killed remaining processes of job " + job.getUuid());
                    job = JobManager.updateStatus(job, JobStatusType.FAILED,
                            "Successfully killed remote job process.");
                    return job;
                } catch (SystemUnavailableException e) {
                    String message = "Failed to kill job " + job.getUuid()
                            + " identified by id " + job.getLocalJobId() + " on " + job.getSystem()
                            + ". The system is currently unavailable.";
                    log.debug(message);
                    job = JobManager.updateStatus(job, job.getStatus(), "Failed to kill job "
                            + " identified by id " + job.getLocalJobId() + " on " + job.getSystem()
                            + " Response from " + job.getSystem() + ": " + e.getMessage());
                    throw new JobTerminationException(message, e);
                } catch (RemoteExecutionException e) {
                    job = killer.getJob();
                    String message = "Failed to kill job " + job.getUuid()
                            + " identified by id " + job.getLocalJobId() + " on " + job.getSystem()
                            + " Response from " + job.getSystem() + ": " + e.getMessage();
                    log.debug(message);
                    job = JobManager.updateStatus(job, JobStatusType.FAILED, "Failed to kill job "
                            + " identified by id " + job.getLocalJobId() + " on " + job.getSystem()
                            + " Response from " + job.getSystem() + ": " + e.getMessage());
                    throw new JobTerminationException(message, e);
                } catch (JobTerminationException e) {
                    retries++;
                    job = killer.getJob();
                    String message = "Failed to kill job " + job.getUuid() +
                            " on attempt " + retries + ". Response from " + job.getSystem() + ": " + e.getMessage();
                    log.debug(message);
                    job = JobManager.updateStatus(job, job.getStatus(), message);
                    if (retries == Settings.MAX_SUBMISSION_RETRIES) {
                        message = "Failed to kill job " + job.getUuid() +
                                " after " + retries + "  attempts. Terminating job.";
                        log.debug(message);
                        job = JobManager.updateStatus(job, JobStatusType.FAILED, message);
                        return job;
                    }
                }
            }
            job = JobManager.updateStatus(job, JobStatusType.STOPPED);
            for (JobEvent event : job.getEvents()) {
                if (event.getTransferTask() != null) {
                    if (event.getTransferTask().getStatus() == TransferStatusType.PAUSED ||
                            event.getTransferTask().getStatus() == TransferStatusType.QUEUED ||
                            event.getTransferTask().getStatus() == TransferStatusType.RETRYING ||
                            event.getTransferTask().getStatus() == TransferStatusType.TRANSFERRING) {
                        try {
                            TransferTaskDao.cancelAllRelatedTransfers(event.getTransferTask().getId());
                        } catch (Exception e) {
                            log.error("Failed to cancel transfer task " +
                                    event.getTransferTask().getUuid() + " while stopping job " +
                                    job.getUuid(), e);
                        }
                    }
                }
            }
            return job;
        }
    }
public static Job kill ( Job job ) throws JobTerminationException , JobException { if ( ! JobStatusType . hasQueued ( job . getStatus ( ) ) || job . getStatus ( ) == JobStatusType . ARCHIVING ) { job = JobManager . updateStatus ( job , JobStatusType . STOPPED , "Job cancelled by user." ) ; for ( JobEvent event : job . getEvents ( ) ) { if ( event . getTransferTask ( ) != null ) { if ( event . getTransferTask ( ) . getStatus ( ) == TransferStatusType . PAUSED || event . getTransferTask ( ) . getStatus ( ) == TransferStatusType . QUEUED || event . getTransferTask ( ) . getStatus ( ) == TransferStatusType . RETRYING || event . getTransferTask ( ) . getStatus ( ) == TransferStatusType . TRANSFERRING ) { try { TransferTaskDao . cancelAllRelatedTransfers ( event . getTransferTask ( ) . getId ( ) ) ; } catch ( Exception e ) { log . error ( "Failed to cancel transfer task " + event . getTransferTask ( ) . getUuid ( ) + " while stopping job " + job . getUuid ( ) , e ) ; } } } } return job ; } else if ( ! job . isRunning ( ) ) { return job ; } else { JobKiller killer = null ; int retries = 0 ; while ( retries < Settings . MAX_SUBMISSION_RETRIES ) { try { log . debug ( "Attempt " + ( retries + 1 ) + " to kill job " + job . getUuid ( ) + " and clean up assets" ) ; killer = new JobKillerFactory ( ) . getInstance ( job ) ; killer . attack ( ) ; log . debug ( "Successfully killed remaining processes of job " + job . getUuid ( ) ) ; job = JobManager . updateStatus ( job , JobStatusType . FAILED , "Successfully killed remote job process." ) ; return job ; } catch ( SystemUnavailableException e ) { String message = "Failed to kill job " + job . getUuid ( ) + " identified by id " + job . getLocalJobId ( ) + " on " + job . getSystem ( ) + ". The system is currently unavailable." ; log . debug ( message ) ; job = JobManager . updateStatus ( job , job . getStatus ( ) , "Failed to kill job " + " identified by id " + job . getLocalJobId ( ) + " on " + job . getSystem ( ) + " Response from " + job . getSystem ( ) + ": " + e . getMessage ( ) ) ; throw new JobTerminationException ( message , e ) ; } catch ( RemoteExecutionException e ) { job = killer . getJob ( ) ; String message = "Failed to kill job " + job . getUuid ( ) + " identified by id " + job . getLocalJobId ( ) + " on " + job . getSystem ( ) + " Response from " + job . getSystem ( ) + ": " + e . getMessage ( ) ; log . debug ( message ) ; job = JobManager . updateStatus ( job , JobStatusType . FAILED , "Failed to kill job " + " identified by id " + job . getLocalJobId ( ) + " on " + job . getSystem ( ) + " Response from " + job . getSystem ( ) + ": " + e . getMessage ( ) ) ; throw new JobTerminationException ( message , e ) ; } catch ( JobTerminationException e ) { retries ++ ; job = killer . getJob ( ) ; String message = "Failed to kill job " + job . getUuid ( ) + " on attempt " + retries + ". Response from " + job . getSystem ( ) + ": " + e . getMessage ( ) ; log . debug ( message ) ; job = JobManager . updateStatus ( job , job . getStatus ( ) , message ) ; if ( retries == Settings . MAX_SUBMISSION_RETRIES ) { message = "Failed to kill job " + job . getUuid ( ) + " after " + retries + "  attempts. Terminating job." ; log . debug ( message ) ; job = JobManager . updateStatus ( job , JobStatusType . FAILED , message ) ; return job ; } } } job = JobManager . updateStatus ( job , JobStatusType . STOPPED ) ; for ( JobEvent event : job . getEvents ( ) ) { if ( event . getTransferTask ( ) != null ) { if ( event . getTransferTask ( ) . getStatus ( ) == TransferStatusType . PAUSED || event . getTransferTask ( ) . getStatus ( ) == TransferStatusType . QUEUED || event . getTransferTask ( ) . getStatus ( ) == TransferStatusType . RETRYING || event . getTransferTask ( ) . getStatus ( ) == TransferStatusType . TRANSFERRING ) { try { TransferTaskDao . cancelAllRelatedTransfers ( event . getTransferTask ( ) . getId ( ) ) ; } catch ( Exception e ) { log . error ( "Failed to cancel transfer task " + event . getTransferTask ( ) . getUuid ( ) + " while stopping job " + job . getUuid ( ) , e ) ; } } } } return job ; } }
Kills a running job by updating its status and using the remote scheduler command and local id to stop it forcefully.
Kills a running job by updating its status and using the remote scheduler command and local id to stop it forcefully .
// if it's not in queue, just update the status //			JobDao.refresh(job); // nothing to be done for jobs that are not running // Occasionally the status check will have run or the job will actually complete // prior to this being called. That will invalidate the current object. Here we // refresh with job prior to updating the status so we don't get a stale state // exception //			JobDao.refresh(job); //			job.setStatus(JobStatusType.STOPPED,  JobStatusType.STOPPED.getDescription()); //			job.setLastUpdated(new DateTime().toDate()); //			job.setEndTime(job.getLastUpdated()); //			JobDao.persist(job);