Search in sources :

Example 1 with Job

use of com.emc.storageos.volumecontroller.Job in project coprhd-controller by CoprHD.

the class QueueJobTracker method run.

public void run() {
    HashMap<String, HashMap<String, Integer>> jobProgressMap = new HashMap<String, HashMap<String, Integer>>();
    while (true) {
        JobWrapper jobWrapper = null;
        _logger.debug("Tracker: Will check job status after {} ms...", _trackingPeriodInMillis);
        try {
            ArrayList<String> completedJobs = new ArrayList<String>();
            Thread.sleep(_trackingPeriodInMillis);
            _logger.debug("Tracker: Checking status of {} jobs", _activeJobs.size());
            for (Iterator<JobWrapper> iter = _activeJobs.iterator(); iter.hasNext(); ) {
                jobWrapper = iter.next();
                Job job = jobWrapper.getJob();
                try {
                    setPollingStartTime(job);
                    JobPollResult result = job.poll(_jobContext, _trackingPeriodInMillis);
                    updateJobProgress(jobProgressMap, result);
                    boolean stopJobTracking = false;
                    String msg = null;
                    // Check if we have to stop job tracking.
                    if (result.isJobInTerminalState()) {
                        // stop tracking jobs in final status and final post processing status
                        msg = String.format("Tracker: Stopping tracking job %s with status: %s and post-processing status %s", result.getJobId(), result.getJobStatus(), result.getJobPostProcessingStatus());
                        stopJobTracking = true;
                    } else {
                        long trackingTime = System.currentTimeMillis() - job.getPollingStartTime();
                        if (trackingTime > job.getTimeoutTimeMsec()) {
                            // Stop tracking job if maximum job tracking time was reached.
                            msg = String.format("Tracker: Stopping tracking job %s with status: %s and post-processing status %s .\n" + "The job tracking time reached job tracking time limit %d hours, job tracking time %d hours.", result.getJobId(), result.getJobStatus(), result.getJobPostProcessingStatus(), job.getTimeoutTimeMsec() / (60 * 60 * 1000), trackingTime / (60 * 60 * 1000));
                            _logger.info(msg);
                            String errorMsg = String.format("Could not execute job %s on backend device. Exceeded time limit for job status tracking.", result.getJobName());
                            if (job instanceof VPlexMigrationJob) {
                                errorMsg = String.format("Could not execute VPlex Migration Job %s on backend device. Exceeded time limit for VPLEX migration timeout.", result.getJobName());
                            }
                            ServiceError error = DeviceControllerException.errors.unableToExecuteJob(errorMsg);
                            job.getTaskCompleter().error(_jobContext.getDbClient(), error);
                            stopJobTracking = true;
                        }
                    }
                    if (stopJobTracking) {
                        _logger.info(msg);
                        stopTrackingJob(jobWrapper);
                        completedJobs.add(result.getJobId());
                    }
                } catch (Exception ex) {
                    _logger.error("Tracker: Unexpected exception.", ex);
                }
            }
            if (!jobProgressMap.isEmpty()) {
                _logger.info(String.format("Progress of jobs - %n %s", jobProgressMap.toString()));
            }
            removeCompletedJobProgressItems(jobProgressMap, completedJobs);
        } catch (InterruptedException ie) {
            _logger.info("Tracker: Unexpected Interrupted exception.", ie);
        } catch (Exception e) {
            _logger.info("Tracker: Unexpected exception.", e);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VPlexMigrationJob(com.emc.storageos.vplexcontroller.job.VPlexMigrationJob) VPlexMigrationJob(com.emc.storageos.vplexcontroller.job.VPlexMigrationJob) Job(com.emc.storageos.volumecontroller.Job) JobPollResult(com.emc.storageos.volumecontroller.impl.JobPollResult)

Aggregations

DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 Job (com.emc.storageos.volumecontroller.Job)1 JobPollResult (com.emc.storageos.volumecontroller.impl.JobPollResult)1 VPlexMigrationJob (com.emc.storageos.vplexcontroller.job.VPlexMigrationJob)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1