} catch (ParseException e) {
logger.error(e.getMessage());
}
}
JobStatus status = new JobStatus(statusType, jobId, changeTime);
status.setExitCode(exitCode);
status.setFailureReason(failureReason);
Job job = null;
try {
job = jobDB.retrieveJob(status.getJobId(), null);
} catch (Exception e) {
logger.warn("job " + status.getJobId() + " not found!");
return;
}
try {
if(doOnJobStatusChanged(status, job)) {
boolean updateJob = false;
if (lrmsJobId != null && (job.getLRMSJobId() == null || job.getLRMSJobId().equalsIgnoreCase("N/A"))) {
job.setLRMSJobId(lrmsJobId);
updateJob = true;
}
if (workerNode != null) {
boolean isReallyRunning = false;
if(job.getWorkerNode() != null && !job.getWorkerNode().equals("N/A") && status.getType() != JobStatus.REALLY_RUNNING) {
for(JobStatus oldStatus : job.getStatusHistory()) {
if(oldStatus.getType() == JobStatus.REALLY_RUNNING) {
isReallyRunning = true;
break;
}
}
}
if(!isReallyRunning) {
job.setWorkerNode(workerNode);
updateJob = true;
}
}
if (updateJob) {
try {
jobDB.update(job);
} catch (Throwable e) {
logger.error(e);
}
}
}
} catch (JobManagementException e) {
logger.error(e.getMessage());
}
} else if (JobCommandConstant.JOB_LIST.equals(command.getName())) {
logger.debug("Calling jobList.");
try {
String user = null;
if (!isAdmin) {
user = userId;
}
List<String> jobIdFound = jobDB.retrieveJobId(user);
JobEnumeration jobEnum = new JobEnumeration(jobIdFound, jobDB);
command.getResult().addParameter("JOB_ENUM", jobEnum);
} catch (DatabaseException e) {
logger.error(e.getMessage());
throw new CommandException("database error occurred");
}
} else {
JobEnumeration jobEnum = getJobList(command);
try {
List<Job> jobList = new ArrayList<Job>(0);
Calendar now = Calendar.getInstance();
while (jobEnum.hasMoreJobs()) {
Job job = jobEnum.nextJob();
JobCommand jobCmd = new JobCommand();
jobCmd.setJobId(job.getId());
jobCmd.setCreationTime(command.getCreationTime());
jobCmd.setDescription(command.getDescription());
jobCmd.setStartSchedulingTime(command.getStartProcessingTime());
jobCmd.setStartProcessingTime(now);
jobCmd.setType(cmdType);
jobCmd.setCommandExecutorName(getName());
if (!isAdmin || job.getUserId().equals(command.getUserId())) {
jobCmd.setUserId(command.getUserId());
}
if ((JobCommandConstant.JOB_CANCEL.equals(command.getName())) && (jobCmd.getDescription() == null)) {
if (!isAdmin || job.getUserId().equals(command.getUserId())) {
jobCmd.setDescription("Cancelled by user");
} else {
jobCmd.setDescription("Cancelled by CE admin");
}
}
logger.debug("Calling jobDB.insertJobCommand.");
try {
jobDB.insertJobCommand(jobCmd);
} catch (Throwable e) {
logger.error(e.getMessage());
continue;
}
logger.debug("jobDB.insertJobCommand has been executed.");
if (jobCmd.getStatus() != JobCommand.ERROR) {
job.addCommandHistory(jobCmd);
jobList.add(job);
}
}
for (Job j : jobList) {
JobCommand jobCmd = j.getLastCommand();
if (jobCmd == null) {
continue;
}
jobCmd.setStatus(JobCommand.PROCESSING);
if (LBLogger.isEnabled()) {
try {
LBLogger.getInstance().execute(j, command, LBLogger.START, null, null);
} catch (Throwable t) {
logger.warn("LBLogger.execute() failed: " + t.getMessage());
}
}
try {
if (JobCommandConstant.JOB_CANCEL.equals(command.getName())) {
if (j.getLastStatus() != null && j.getLastStatus().getType() == JobStatus.REGISTERED) {
JobStatus status = new JobStatus(JobStatus.CANCELLED, j.getId(), now);
status.setDescription(jobCmd.getDescription());
doOnJobStatusChanged(status, j);
} else {
cancel(j);
}