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);
}
}
}
Aggregations