throw new CommandException("userId not defined!");
}
Job job = makeJobFromCmd(cmd);
JobStatus status = new JobStatus(JobStatus.REGISTERED, job.getId());
job.setUserId(userId);
job.setLocalUser(cmd.getParameterAsString("LOCAL_USER"));
job.setJDL(cmd.getParameterAsString("JDL"));
job.setICEId(cmd.getParameterAsString("ICE_ID"));
job.addCommandHistory(jobCmd);
if (cmd.containsParameterKey("USER_VO")) {
job.setVirtualOrganization(cmd.getParameterAsString("USER_VO"));
}
if (isEmptyField(job.getBatchSystem())) {
throw new CommandException("\"BatchSystem\" attribute not defined into the JDL");
}
if (isEmptyField(job.getQueue())) {
throw new CommandException("\"QueueName\" attribute not defined into the JDL");
}
if (!isBatchSystemSupported(job.getBatchSystem())) {
throw new CommandException("Batch System " + job.getBatchSystem() + " not supported!");
}
String cream_sandbox_dir = getParameterValueAsString("CREAM_SANDBOX_DIR");
if (cream_sandbox_dir == null) {
throw new CommandException("parameter \"CREAM_SANDBOX_DIR\" not defined!");
}
job.setCreamURL(cmd.getParameterAsString("CREAM_URL"));
job.setDelegationProxyId(cmd.getParameterAsString("DELEGATION_PROXY_ID"));
job.setDelegationProxyInfo(cmd.getParameterAsString("DELEGATION_PROXY_INFO"));
job.setDelegationProxyCertPath(cmd.getParameterAsString("DELEGATION_PROXY_PATH"));
job.setLRMSAbsLayerJobId(Job.NOT_AVAILABLE_VALUE);
job.setLRMSJobId(Job.NOT_AVAILABLE_VALUE);
job.setWorkerNode(Job.NOT_AVAILABLE_VALUE);
job.setWorkingDirectory(Job.NOT_AVAILABLE_VALUE);
if (cmd.containsParameterKey("USER_DN")) {
job.addExtraAttribute("USER_DN", cmd.getParameterAsString("USER_DN").replaceAll("\\s+", "\\\\ "));
}
if (cmd.containsParameterKey("USER_DN_X500")) {
job.addExtraAttribute("USER_DN_X500", cmd.getParameterAsString("USER_DN_X500").replaceAll("\\s+", "\\\\ "));
}
if (cmd.containsParameterKey("LOCAL_USER_GROUP")) {
job.addExtraAttribute("LOCAL_USER_GROUP", cmd.getParameterAsString("LOCAL_USER_GROUP"));
}
if (cmd.containsParameterKey("USER_FQAN")) {
List<String> fqanList = cmd.getParameterMultivalue("USER_FQAN");
if (fqanList != null && fqanList.size() > 0) {
StringBuffer fqanBuffer = new StringBuffer();
for (String fqan : fqanList) {
fqanBuffer.append("\\\"userFQAN=").append(fqan.replaceAll("\\s+", "\\\\ ")).append("\\\"\\ ");
}
fqanBuffer.deleteCharAt(fqanBuffer.length() - 1);
fqanBuffer.deleteCharAt(fqanBuffer.length() - 1);
job.addExtraAttribute("USER_FQAN", fqanBuffer.toString());
}
}
if (this.containsParameterKey("LRMS_EVENT_LISTENER_PORT")) {
job.setLoggerDestURI(InetAddress.getLocalHost().getHostAddress() + ":" + getParameterValueAsString("LRMS_EVENT_LISTENER_PORT"));
}
if (job.getCreamURL() != null) {
try {
URL url = new URL(job.getCreamURL());
job.setCeId(url.getHost() + ":" + url.getPort() + "/cream-" + job.getBatchSystem() + "-" + job.getQueue());
} catch (MalformedURLException e) {
}
}
if (cmd.containsParameterKey("LEASE_ID")) {
String leaseId = cmd.getParameterAsString("LEASE_ID");
if (leaseId != null && leaseId.length() > 0) {
Lease lease = jobDB.retrieveJobLease(leaseId, userId);
if (lease != null) {
logger.debug("found lease \"" + leaseId + "\" = " + lease.getLeaseTime().getTime());
job.setLease(lease);
} else {
throw new CommandException("lease id \"" + leaseId + "\" not found!");
}
}
}
boolean jobInserted = false;
int count = 0;
while (!jobInserted && count < 5) {
try {
jobDB.insert(job);
jobInserted = true;
} catch (DatabaseException de) {
if (de.getMessage().indexOf("Duplicate entry") > -1) {
job.setId(job.generateJobId());
count++;
} else {
logger.error(de.getMessage());
throw new CommandException("database error occurred");
}
} catch (IllegalArgumentException ie) {
throw new CommandException(ie.getMessage());
}
}
if (!jobInserted) {
throw new CommandException("Duplicate jobId error: cannot insert the new job (" + job.getId() + ") into the database");
}
jobCmd.setJobId(job.getId());
jobCmd.setStatus(JobCommand.SUCCESSFULL);
if (LBLogger.isEnabled()) {
try {
LBLogger.getInstance().register(job);
} catch (Throwable e) {
logger.warn("LBLogger.register() failed: " + e.getMessage());
}
try {
LBLogger.getInstance().accept(job);
} catch (Throwable e) {
logger.warn("LBLogger.accept() failed: " + e.getMessage());
}
}
try {
createJobSandboxDir(job, cmd.getParameterAsString("GSI_FTP_CREAM_URL"));
} catch (Throwable e) {
jobCmd.setStatus(JobCommand.ERROR);
jobCmd.setFailureReason(e.getMessage());
status.setType(JobStatus.ABORTED);
status.setFailureReason(e.getMessage());
doOnJobStatusChanged(status, job);
throw new CommandException(e.getMessage());
} finally {