}
jobAd.setLocalAccess(false);
jobAd.checkAll(new String[] { Jdl.EXECUTABLE, Jdl.QUEUENAME, Jdl.JOBTYPE, "BatchSystem" });
Job job = new Job();
job.setLRMSAbsLayerJobId("N/A");
job.setLRMSJobId("N/A");
job.setWorkerNode("N/A");
// if (creamURL == null) {
// setCREAMJobId(getId());
// } else {
// setCREAMJobId(creamURL + (creamURL.endsWith("/") ? "" : "/")
// + getId());
// }
// setId(getAttributeValue(job, Jdl.JOBID));
job.setType(getAttributeValue(jobAd, Jdl.JOBTYPE));
job.setBatchSystem(getAttributeValue(jobAd, "BatchSystem"));
job.setQueue(getAttributeValue(jobAd, Jdl.QUEUENAME));
job.setVirtualOrganization(getAttributeValue(jobAd, Jdl.VIRTUAL_ORGANISATION));
job.setStandardError(getAttributeValue(jobAd, Jdl.STDERROR));
job.setStandardInput(getAttributeValue(jobAd, Jdl.STDINPUT));
job.setStandardOutput(getAttributeValue(jobAd, Jdl.STDOUTPUT));
job.setExecutable(getAttributeValue(jobAd, Jdl.EXECUTABLE));
job.setCeRequirements(getAttributeValue(jobAd, Jdl.CE_REQUIREMENTS));
job.setInputSandboxBaseURI(getBaseURL(jobAd, "InputSandboxBaseURI"));
job.setOutputSandboxBaseDestURI(getBaseURL(jobAd, "OutputSandboxBaseDestURI"));
job.setOutputSandboxDestURI(getBaseURLs(jobAd, "OutputSandboxDestURI"));
job.setInputFiles(getFiles(jobAd, Jdl.INPUTSB));
job.setOutputFiles(getFiles(jobAd, Jdl.OUTPUTSB));
job.setHlrLocation(getAttributeValue(jobAd, Jdl.HLR_LOCATION));
job.setMyProxyServer(getAttributeValue(jobAd, Jdl.MYPROXY));
job.setPrologue(getAttributeValue(jobAd, "Prologue"));
job.setPrologueArguments(getAttributeValue(jobAd, "PrologueArguments"));
job.setEpilogue(getAttributeValue(jobAd, "Epilogue"));
job.setEpilogueArguments(getAttributeValue(jobAd, "EpilogueArguments"));
job.setSequenceCode(getAttributeValue(jobAd, "LB_sequence_code"));
job.setTokenURL(getAttributeValue(jobAd, "ReallyRunningToken"));
String mwVersion = getAttributeValue(jobAd, Jdl.MW_VERSION);
if (mwVersion != null) {
job.addExtraAttribute(Jdl.MW_VERSION, mwVersion);
}
String lbAddress = getAttributeValue(jobAd, Jdl.LB_ADDRESS);
if (lbAddress != null) {
job.addVolatileProperty(Job.LB_ADDRESS, lbAddress);
}
ArrayList<OutputDataRecord> outputData = getOutputData(jobAd, Jdl.OUTPUTDATA);
if (outputData != null){
job.addVolatileProperty(Job.OUTPUT_DATA, outputData);
}
String wmsHostname = getAttributeValue(jobAd, Jdl.WMS_HOSTNAME);
if (wmsHostname != null) {
job.addVolatileProperty(Job.WMS_HOSTNAME, wmsHostname);
}
String maxOutputSandboxSize = getAttributeValue(jobAd, Jdl.MAX_OUTPUT_SANDBOX_SIZE);
if (maxOutputSandboxSize != null) {
job.addVolatileProperty(Job.MAX_OUTPUT_SANDBOX_SIZE, maxOutputSandboxSize);
}
if (job.getOutputFiles().size() > 0) {
if (job.getOutputSandboxBaseDestURI() != null && job.getOutputSandboxBaseDestURI().length() > 0) {
if (job.getOutputSandboxDestURI().size() > 0) {
throw new Exception("the OutputSandboxDestURI and OutputSandboxBaseDestURI attributes cannot be specified together in the same JDL");
}
} else {
if (job.getOutputSandboxDestURI().size() == 0) {
throw new Exception("the OutputSandbox attribute requires the specification in the same JDL of one of the following attributes: OutputSandboxDestURI or OutputSandboxBaseDestURI");
} else if (job.getOutputSandboxDestURI().size() != job.getOutputFiles().size()) {
throw new Exception("the OutputSandbox and OutputSandboxDestURI attributes must have the same cardinality");
}
}
}
String args = getAttributeValue(jobAd, Jdl.ARGUMENTS);
if (args != null && args.length() > 0) {
List<String> argsList = new ArrayList<String>(1);
argsList.add(args);
job.setArguments(argsList);
}
String edg_jobid = getAttributeValue(jobAd, "edg_jobid");
if (edg_jobid == null) {
edg_jobid = "N/A";
}
job.setGridJobId(edg_jobid);
if (job.getType() == null) {
job.setType("normal");
}
Expr expression = jobAd.lookup(Jdl.ENVIRONMENT);
if (expression != null && expression instanceof ListExpr) {
Iterator item = ((ListExpr) expression).iterator();
while (item.hasNext()) {
String tmps = ((Constant) item.next()).stringValue();
String[] tokens = tmps.split("=", 2);
job.addEnvironmentAttribute(tokens[0].trim(), tokens[1].trim());
}
}
job.setNodeNumber(1);
expression = jobAd.lookup(Jdl.CPUNUMB);
if (expression != null) {
if (expression.type != Expr.INTEGER || expression.intValue() <= 0) {
throw new Exception("wrong value for " + Jdl.CPUNUMB + ": it must be >=1");
}
job.setNodeNumber(expression.intValue());
} else {
expression = jobAd.lookup(Jdl.NODENUMB);
if (expression != null) {
if (expression.type != Expr.INTEGER || expression.intValue() <= 0) {
throw new Exception("wrong value for " + Jdl.NODENUMB + ": it must be >=1");
}
job.setNodeNumber(expression.intValue());
}
}
boolean wholeNodes = false;
expression = jobAd.lookup(Jdl.WHOLE_NODES);
if (expression != null && expression.type == Expr.BOOLEAN && expression.isTrue()) {
wholeNodes = true;
}
job.addExtraAttribute(Jdl.WHOLE_NODES, Boolean.toString(wholeNodes));
expression = jobAd.lookup(Jdl.SMP_GRANULARITY);
if (expression != null) {
if (expression.type != Expr.INTEGER || expression.intValue() <= 0) {
throw new Exception("wrong value for " + Jdl.SMP_GRANULARITY + ": it must be >=1");
}
job.addExtraAttribute(Jdl.SMP_GRANULARITY, "" + expression.intValue());
}
expression = jobAd.lookup(Jdl.HOST_NUMBER);
if (expression != null) {
if (expression.type != Expr.INTEGER || expression.intValue() <= 0) {
throw new Exception("wrong value for " + Jdl.HOST_NUMBER + ": it must be >=1");
}
job.addExtraAttribute(Jdl.HOST_NUMBER, "" + expression.intValue());
}
if (!wholeNodes && job.containsExtraAttribute(Jdl.SMP_GRANULARITY) && job.containsExtraAttribute(Jdl.HOST_NUMBER)) {
throw new Exception("the SMPGranularity and HostNumber attributes cannot be specified together when WholeNodes=false");
}
expression = jobAd.lookup("PerusalFileEnable");
if (expression != null && expression.type == Expr.BOOLEAN && expression.isTrue()) {
expression = jobAd.lookup("PerusalTimeInterval");
if (expression != null && expression instanceof Constant) {
job.setPerusalTimeInterval(expression.intValue());
} else {
job.setPerusalTimeInterval(5);
}
job.setPerusalFilesDestURI(getAttributeValue(jobAd, "PerusalFilesDestURI"));
job.setPerusalListFileURI(getAttributeValue(jobAd, "PerusalListFileURI"));
} else {
job.setPerusalFilesDestURI(null);
}
return job;
}