agave-jobs/jobs-core/src/main/java/org/iplantc/service/jobs/callbacks/JobCallbackManager.java
/**
     * Handles general {@link Job} status callbacks sent to the trigger endpoints 
     * from running jobs as GET requests.
     * 
     * @param callback
     * @return the updated job
     * @throws JobCallbackException
     * @throws ObjectNotFoundException
     * @throws JobException
     */
Handles general  Job status callbacks sent to the trigger endpoints
from running jobs as GET requests.


Handles general Job status callbacks sent to the trigger endpoints from running jobs as GET requests .
public Job process(JobCallback callback) 
    throws JobCallbackException, ObjectNotFoundException, JobException
    {
        if (callback == null) {
            throw new JobCallbackException("Callback cannot be null.");
        }
        Job job = callback.getJob();
        if (job == null) {
            throw new ObjectNotFoundException(null, "No job found with given id");
        } 
        else if (!job.isVisible()) {
            throw new JobCallbackException("Ignoring " + callback.getStatus() + 
            		" callback on job " + job.getUuid() + ". Job has already been deleted.");
        }
        else 
        {
            TenancyHelper.setCurrentEndUser(job.getOwner());
            TenancyHelper.setCurrentTenantId(job.getTenantId());
            validateLocalSchedulerJobId(callback);
            String message = null;
            JobStatusType status = callback.getStatus();
            if (job.getStatus() == STOPPED && JobStatusType.isRunning(callback.getStatus())) {
                throw new JobCallbackException("Job " + callback.getJob().getUuid() + " is currently stopped.");
            }
            if (!job.isArchiveOutput() && (status == ARCHIVING || 
                    status == ARCHIVING_FAILED || 
                    status == ARCHIVING_FINISHED)) 
            {
                throw new JobCallbackException("Job " + job.getUuid()
                        + " is not configured for archive.");
            } 
            else if (!job.getStatus().getNextValidStates().contains(status))
            {
                throw new JobCallbackException("Job " + job.getUuid()
                        + " cannot update status from " + job.getStatus().name() 
                        + " to " + status.name() + ".");
            }
            else
            {
                if (status == HEARTBEAT) 
                {
                    log.debug("Job " + job.getUuid() + " received heartbeat notification.");
                    JobEvent event = new JobEvent(HEARTBEAT, HEARTBEAT.getDescription(), job.getOwner());
                    job.addEvent(event);
                    JobDao.persist(job);
                    status = job.getStatus();
                    message = job.getErrorMessage();
                }
                else if (status == CLEANING_UP)
                {
                    if (job.getStatus() != RUNNING) {
                    }
                    if (job.getStatus() == CLEANING_UP) {
                        log.debug("Job " + job.getUuid() + " received notification identical to its current status.");
                        message = "Job receieved duplicate " + status.name() + " notification";
                    } else {
                        log.debug("Job " + job.getUuid() + " received " + status.name() + " notification.");
                        message = CLEANING_UP.getDescription();
                    }
                    job = JobManager.updateStatus(job, CLEANING_UP, message);
                    if (!job.isArchiveOutput()) {
                        log.debug("Job " + job.getUuid() + " will skip archiving at user request.");
                        status = JobStatusType.FINISHED;
                        message = "Job completed. Skipping archiving at user request.";
                    }
                }
                else if (job.getStatus() == status) 
                {
                    log.debug("Job " + job.getUuid() + " received notification identical to its current status.");
                    message = "Job receieved duplicate " + status.name() + " notification";
                }
                else 
                {
                    log.debug("Job " + job.getUuid() + " received " + status.name() + " notification.");
                    message = status.getDescription();
                }
                return JobManager.updateStatus(job, status, message);
            }
        }
    }
public Job process ( JobCallback callback ) throws JobCallbackException , ObjectNotFoundException , JobException { if ( callback == null ) { throw new JobCallbackException ( "Callback cannot be null." ) ; } Job job = callback . getJob ( ) ; if ( job == null ) { throw new ObjectNotFoundException ( null , "No job found with given id" ) ; } else if ( ! job . isVisible ( ) ) { throw new JobCallbackException ( "Ignoring " + callback . getStatus ( ) + " callback on job " + job . getUuid ( ) + ". Job has already been deleted." ) ; } else { TenancyHelper . setCurrentEndUser ( job . getOwner ( ) ) ; TenancyHelper . setCurrentTenantId ( job . getTenantId ( ) ) ; validateLocalSchedulerJobId ( callback ) ; String message = null ; JobStatusType status = callback . getStatus ( ) ; if ( job . getStatus ( ) == STOPPED && JobStatusType . isRunning ( callback . getStatus ( ) ) ) { throw new JobCallbackException ( "Job " + callback . getJob ( ) . getUuid ( ) + " is currently stopped." ) ; } if ( ! job . isArchiveOutput ( ) && ( status == ARCHIVING || status == ARCHIVING_FAILED || status == ARCHIVING_FINISHED ) ) { throw new JobCallbackException ( "Job " + job . getUuid ( ) + " is not configured for archive." ) ; } else if ( ! job . getStatus ( ) . getNextValidStates ( ) . contains ( status ) ) { throw new JobCallbackException ( "Job " + job . getUuid ( ) + " cannot update status from " + job . getStatus ( ) . name ( ) + " to " + status . name ( ) + "." ) ; } else { if ( status == HEARTBEAT ) { log . debug ( "Job " + job . getUuid ( ) + " received heartbeat notification." ) ; JobEvent event = new JobEvent ( HEARTBEAT , HEARTBEAT . getDescription ( ) , job . getOwner ( ) ) ; job . addEvent ( event ) ; JobDao . persist ( job ) ; status = job . getStatus ( ) ; message = job . getErrorMessage ( ) ; } else if ( status == CLEANING_UP ) { if ( job . getStatus ( ) != RUNNING ) { } if ( job . getStatus ( ) == CLEANING_UP ) { log . debug ( "Job " + job . getUuid ( ) + " received notification identical to its current status." ) ; message = "Job receieved duplicate " + status . name ( ) + " notification" ; } else { log . debug ( "Job " + job . getUuid ( ) + " received " + status . name ( ) + " notification." ) ; message = CLEANING_UP . getDescription ( ) ; } job = JobManager . updateStatus ( job , CLEANING_UP , message ) ; if ( ! job . isArchiveOutput ( ) ) { log . debug ( "Job " + job . getUuid ( ) + " will skip archiving at user request." ) ; status = JobStatusType . FINISHED ; message = "Job completed. Skipping archiving at user request." ; } } else if ( job . getStatus ( ) == status ) { log . debug ( "Job " + job . getUuid ( ) + " received notification identical to its current status." ) ; message = "Job receieved duplicate " + status . name ( ) + " notification" ; } else { log . debug ( "Job " + job . getUuid ( ) + " received " + status . name ( ) + " notification." ) ; message = status . getDescription ( ) ; } return JobManager . updateStatus ( job , status , message ) ; } } }
Handles general {@link Job} status callbacks sent to the trigger endpoints
 from running jobs as GET requests.
Handles general { @link Job } status callbacks sent to the trigger endpoints from running jobs as GET requests .
// can't set a stopped job back to running. Bad request // the HEARTBEAT status is used to update the job timestamp and is used // by app developers just to keep aware of a job being alive. // can't update an archive status when the job is not set to archive // heartbeats need to set an event, but they do not udpate the job status. // if job was not running, then fetch the job start time from the  // remote system offline so we have accurate reporting //                        RemoteAccountingValidator validator = new RemoteAccoutingValidator(job); //                        validator.run();