logger.debug("Calling jobInfo.");
getJobList(command);
} else if (JobCommandConstant.JOB_STATUS.equals(command.getName())) {
logger.debug("Calling jobStatus.");
JobEnumeration jobEnum = getJobList(command);
String user = null;
if (!isAdmin) {
user = userId;
}
try {
List<JobStatus> jobStatusList = jobDB.retrieveLastJobStatus(jobEnum.getJobIdList(), user);
command.getResult().addParameter("JOB_STATUS_LIST", jobStatusList);
if (command.containsParameterKey("JOB_ID") || command.containsParameterKey("JOB_ID_LIST")) {
if (jobStatusList.size() < jobEnum.getJobIdList().size()) {
List<String> jobIdList = new ArrayList<String>(jobStatusList.size());
for (JobStatus status : jobStatusList) {
jobIdList.add(status.getJobId());
}
jobEnum.getJobIdList().removeAll(jobIdList);
int found = 0;
List<JobIdFilterResult> jobIdFilterResultList = (List<JobIdFilterResult>) command.getResult().getParameter("JOBID_FILTER_RESULT_LIST");
for (JobIdFilterResult filterResult : jobIdFilterResultList) {
if (jobEnum.getJobIdList().contains(filterResult.getJobId())) {
filterResult.setErrorCode(JobIdFilterFailure.JOBID_ERRORCODE);
filterResult.setFailureReason(JobIdFilterFailure.failureReason[JobIdFilterFailure.JOBID_ERRORCODE]);
if (++found == jobEnum.getJobIdList().size()) {
break;
}
}
}
command.getResult().addParameter("JOB_ENUM", new JobEnumeration(jobIdList, jobDB));
}
}
} catch (DatabaseException e) {
logger.error(e.getMessage());
throw new CommandException("database error occurred");
}
} else if (JobCommandConstant.QUERY_EVENT.equals(command.getName())) {
logger.debug("Calling queryEvent.");
int maxEvents = 100;
try {
maxEvents = Integer.parseInt(command.getParameterAsString("MAX_QUERY_EVENT_RESULT_SIZE"));
} catch (Throwable t) {
logger.warn("queryEvent: wrong value for MAX_QUERY_EVENT_RESULT_SIZE");
}
int[] jobStatusTypeArray = null;
if (command.containsParameterKey("statusList")) {
List<String> statusList = command.getParameterMultivalue("statusList");
jobStatusTypeArray = new int[statusList.size()];
for (int i = 0; i < statusList.size(); i++) {
jobStatusTypeArray[i] = -1;
for (int x = 0; x < JobStatus.statusName.length; x++) {
if (statusList.get(i).equals(JobStatus.getNameByType(x))) {
jobStatusTypeArray[i] = x;
continue;
}
}
}
}
JobStatusEventManagerInterface jobStatusEventManager = (JobStatusEventManagerInterface) EventManagerFactory.getEventManager("JOB_STATUS_EVENT_MANAGER");
List<Event> eventList = null;
try {
eventList = jobStatusEventManager.getEvents(command.getParameterAsString("FROM_EVENT_ID"), command.getParameterAsString("TO_EVENT_ID"),
makeDate(command.getParameterAsString("FROM_DATE")), makeDate(command.getParameterAsString("TO_DATE")), jobStatusTypeArray,
maxEvents, userId);
} catch (EventManagerException e) {
throw new CommandException(e.getMessage());
}
command.getResult().addParameter("EVENT_LIST", eventList);
} else if (JobCommandConstant.SET_JOB_STATUS.equals(command.getName())) {
logger.debug("Calling setJobStatus.");
int statusType = Integer.valueOf(command.getParameterAsString("STATUS_TYPE"));
String jobId = command.getParameterAsString("JOB_ID");
String workerNode = command.getParameterAsString("WORKER_NODE");
String lrmsJobId = command.getParameterAsString("LRMS_JOB_ID");
String exitCode = command.getParameterAsString("EXIT_CODE");
String failureReason = command.getParameterAsString("FAILURE_REASON");
Calendar changeTime = null;
if (command.containsParameterKey("STATUS_CHANGE_TIME")) {
changeTime = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setCalendar(changeTime);
try {
dateFormat.parse(command.getParameterAsString("STATUS_CHANGE_TIME"));
} 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());