} catch (Throwable e) {
logger.error(e.getMessage());
}
} catch (IllegalArgumentException e) {
logger.error(e);
throw new JobManagementException(e);
} catch (DatabaseException e) {
logger.error(e.getMessage());
throw new JobManagementException("database error occurred");
}
}
} else {
if (lastStatus != null && (lastStatus.getType() == JobStatus.ABORTED || lastStatus.getType() == JobStatus.CANCELLED ||
lastStatus.getType() == JobStatus.DONE_OK || lastStatus.getType() == JobStatus.DONE_FAILED)) {
return statusUpdated;
}
switch (status.getType()) {
case JobStatus.ABORTED:
setLeaseExpired(job);
break;
case JobStatus.CANCELLED:
status.setDescription("Cancelled by CE admin");
int cancelType = getCommandType(JobCommandConstant.JOB_CANCEL);
for (int i = job.getCommandHistoryCount() - 1; i >= 0; i--) {
if (job.getCommandHistoryAt(i).getType() == cancelType) {
status.setDescription(job.getCommandHistoryAt(i).getDescription());
break;
}
}
setLeaseExpired(job);
break;
case JobStatus.DONE_OK:
case JobStatus.DONE_FAILED:
if (status.getType() == JobStatus.DONE_FAILED) {
int cancelledType = getCommandType(JobCommandConstant.JOB_CANCEL);
for (int i = job.getCommandHistoryCount() - 1; i >= 0; i--) {
if (job.getCommandHistoryAt(i).getType() == cancelledType) {
status.setType(JobStatus.CANCELLED);
status.setExitCode(null);
status.setDescription(job.getCommandHistoryAt(i).getDescription());
break;
}
}
}
if ("W".equalsIgnoreCase(status.getExitCode())) {
Calendar time = Calendar.getInstance();
time.add(Calendar.MINUTE, 1);
timer.schedule(new GetSTDTask(status.getJobId()), time.getTime());
timer.purge();
}
setLeaseExpired(job);
break;
case JobStatus.REALLY_RUNNING:
if (lastStatus != null && (lastStatus.getType() == JobStatus.ABORTED || lastStatus.getType() == JobStatus.CANCELLED ||
lastStatus.getType() == JobStatus.DONE_OK || lastStatus.getType() == JobStatus.DONE_FAILED)) {
return statusUpdated;
}
break;
case JobStatus.RUNNING:
if (status.getTimestamp().compareTo(lastStatus.getTimestamp()) <= 0) {
return statusUpdated;
}
if (lastStatus != null && (lastStatus.getType() == JobStatus.REALLY_RUNNING || lastStatus.getType() == JobStatus.ABORTED ||
lastStatus.getType() == JobStatus.CANCELLED || lastStatus.getType() == JobStatus.DONE_OK || lastStatus.getType() == JobStatus.DONE_FAILED)) {
return statusUpdated;
}
try {
List<JobStatus> statusList = jobDB.retrieveJobStatusHistory(status.getJobId(), null);
if (statusList != null && statusList.size() > 2) {
JobStatus oldStatus = statusList.get(statusList.size() - 2);
status.setType(oldStatus.getType() == JobStatus.REALLY_RUNNING ? JobStatus.REALLY_RUNNING : JobStatus.RUNNING);
}
} catch (DatabaseException e) {
logger.error(e.getMessage());
throw new JobManagementException("database error occurred");
}
break;
case JobStatus.HELD:
case JobStatus.IDLE:
case JobStatus.PENDING:
case JobStatus.REGISTERED:
if (lastStatus != null && (status.getTimestamp().compareTo(lastStatus.getTimestamp()) < 0)) {
logger.warn("the timestamp of the new status " + status.getName() + " for the JOB " + status.getJobId() + " is older than the last one");
return statusUpdated;
}
break;
}
try {
job.addStatus(status);
logger.debug("inserting new status " + status.getName() + " for the JOB " + status.getJobId());
jobDB.insertStatus(status, null);
statusUpdated = true;
if (LBLogger.isEnabled()) {
try {
LBLogger.getInstance().statusChanged(job, status, null, LBLogger.START);
} catch (Exception e) {
logger.warn("LBLogger.statusChanged failed: " + e.getMessage());
}
}
StringBuffer logInfo = new StringBuffer("JOB ");
logInfo.append(status.getJobId());
if (lastStatus == null) {
logInfo.append(" STATUS CHANGED: -- => ").append(status.getName());
} else {
logInfo.append(" STATUS CHANGED: ").append(lastStatus.getName()).append(" => ").append(status.getName());
}
if (!isEmptyField(status.getDescription())) {
logInfo.append(" [description=").append(status.getDescription()).append("]");
}
if (!isEmptyField(status.getFailureReason())) {
logInfo.append(" [failureReason=" + status.getFailureReason() + "]");
}
if (!isEmptyField(status.getExitCode())) {
logInfo.append(" [exitCode=").append(status.getExitCode()).append("]");
}
if (!isEmptyField(job.getLocalUser())) {
logInfo.append(" [localUser=" + job.getLocalUser() + "]");
}
if (!isEmptyField(job.getGridJobId())) {
logInfo.append(" [gridJobId=" + job.getGridJobId() + "]");
}
if (!isEmptyField(job.getLRMSJobId())) {
logInfo.append(" [lrmsJobId=").append(job.getLRMSJobId()).append("]");
}
if (!isEmptyField(job.getWorkerNode())) {
logInfo.append(" [workerNode=").append(job.getWorkerNode()).append("]");
}
if (!isEmptyField(job.getDelegationProxyId())) {
logInfo.append(" [delegationId=").append(job.getDelegationProxyId()).append("]");
}
logger.info(logInfo.toString());
} catch (IllegalArgumentException e) {
logger.error(e);
throw new JobManagementException(e);
} catch (DatabaseException e) {
logger.error(e.getMessage());
throw new JobManagementException("database error occurred");
}
try {
sendNotification(job);
} catch (Throwable e) {