use of org.ow2.proactive.scheduler.core.db.JobContent in project scheduling by ow2-proactive.
the class JobData method toInternalJob.
InternalJob toInternalJob() {
JobId jobIdInstance = new JobIdImpl(getId(), getJobName());
JobInfoImpl jobInfo = createJobInfo(jobIdInstance);
InternalJob internalJob = new InternalTaskFlowJob();
internalJob.setCredentials(getCredentials());
internalJob.setJobInfo(jobInfo);
internalJob.setParentId(getParentId());
internalJob.setGenericInformation(getGenericInformation());
internalJob.setVariables(variablesToJobVariables());
internalJob.setProjectName(getProjectName());
internalJob.setOwner(getOwner());
internalJob.setDescription(getDescription());
internalJob.setInputSpace(getInputSpace());
internalJob.setOutputSpace(getOutputSpace());
internalJob.setGlobalSpace(getGlobalSpace());
internalJob.setUserSpace(getGlobalSpace());
internalJob.setMaxNumberOfExecution(getMaxNumberOfExecution());
internalJob.setOnTaskError(OnTaskError.getInstance(this.onTaskErrorString));
if (getTaskRetryDelay() != null) {
internalJob.setTaskRetryDelay(getTaskRetryDelay());
}
internalJob.setScheduledTimeForRemoval(getScheduledTimeForRemoval());
try {
internalJob.setResultMap(SerializationUtil.deserializeVariableMap(getResultMap()));
} catch (IOException | ClassNotFoundException e) {
logger.error("error when serializing result map variables " + e);
}
List<JobContent> jobContentList = getJobContent();
if (jobContentList != null && jobContentList.size() > 0) {
internalJob.setJobContent(jobContentList.get(0).getInitJobContent());
if (internalJob.getJobContent() != null) {
GlobalVariablesData globalVariablesData = GlobalVariablesParser.getInstance().getVariablesFor(internalJob.getJobContent());
Map<String, JobVariable> globalVariables = new LinkedHashMap<>();
Map<String, JobVariable> configuredGlobalVariables = globalVariablesData.getVariables();
for (String variableName : configuredGlobalVariables.keySet()) {
if (internalJob.getVariables().containsKey(variableName)) {
globalVariables.put(variableName, internalJob.getVariables().get(variableName));
} else {
globalVariables.put(variableName, configuredGlobalVariables.get(variableName));
}
}
internalJob.setGlobalVariables(globalVariables);
Map<String, String> globalGenericInfo = new LinkedHashMap<>();
Map<String, String> configuredGlobalGenericInfo = globalVariablesData.getGenericInformation();
for (String giName : configuredGlobalGenericInfo.keySet()) {
if (internalJob.getGenericInformation().containsKey(giName)) {
globalGenericInfo.put(giName, internalJob.getGenericInformation().get(giName));
} else {
globalGenericInfo.put(giName, configuredGlobalGenericInfo.get(giName));
}
}
internalJob.setGlobalGenericInformation(globalGenericInfo);
}
}
return internalJob;
}
use of org.ow2.proactive.scheduler.core.db.JobContent in project scheduling by ow2-proactive.
the class SchedulerFrontend method reSubmit.
/**
* {@inheritDoc}
*/
@Override
@ImmediateService
public JobId reSubmit(JobId currentJobId, Map<String, String> jobVariables, Map<String, String> jobGenericInfos, String sessionId) throws NotConnectedException, UnknownJobException, PermissionException, JobCreationException, SubmissionClosedException {
final String jobContent = getJobContent(currentJobId);
final Job job = JobFactory.getFactory().createJob(IOUtils.toInputStream(jobContent, Charset.forName("UTF-8")), jobVariables, jobGenericInfos, this, this, sessionId);
return submit(job);
}
use of org.ow2.proactive.scheduler.core.db.JobContent in project scheduling by ow2-proactive.
the class SchedulerFrontend method updateJobSchemaVersionToLatest.
/**
* Use XSLT to change the schema version of the job descriptor to the latest.
* Specifically, it's to change "xmlns" and "xsi:schemaLocation" to the "dev" version.
* This function is used to fix the potential problem of schema version mismatch between global variables and job descriptor.
* Since the schema change is backward compatible, updating the job to the latest version will fix the version mismatch problem.
*
* @param jobContent the String content of job descriptor (in xml)
* @return the updated String content of job descriptor (in xml) which is changed to the latest version
*/
private String updateJobSchemaVersionToLatest(String jobContent) {
try {
StreamSource xslSource = new StreamSource(this.getClass().getClassLoader().getResourceAsStream(xslFilePath));
StreamSource xmlInput = new StreamSource(new StringReader(jobContent));
StringWriter xmlOutput = new StringWriter();
Result result = new StreamResult(xmlOutput);
TransformerFactory factory = TransformerFactory.newInstance(saxonFactoryClassName, null);
Transformer transformer = factory.newTransformer(xslSource);
transformer.transform(xmlInput, result);
return xmlOutput.toString();
} catch (Exception e) {
logger.warn("Error during transforming the job descriptor schema to the latest version, it's kept unchanged.", e);
return jobContent;
}
}
use of org.ow2.proactive.scheduler.core.db.JobContent in project scheduling by ow2-proactive.
the class SchedulerClientTest method testReSubmitJob.
@Test
public void testReSubmitJob() throws Exception {
ISchedulerClient client = clientInstance();
Job job = nodeClientJob("/functionaltests/descriptors/dataspace_client_node_push_delete.groovy", "/functionaltests/descriptors/dataspace_client_node_fork.groovy", null);
JobId jobId = submitJob(job, client);
JobId jobId1 = client.reSubmit(jobId, Collections.emptyMap(), Collections.emptyMap(), null);
String jobContent = client.getJobContent(jobId).replaceAll("\\s+", "");
String jobContent1 = client.getJobContent(jobId1).replaceAll("\\s+", "");
assertEquals(jobContent, jobContent1);
}
use of org.ow2.proactive.scheduler.core.db.JobContent in project scheduling by ow2-proactive.
the class StaxJobFactory method createJob.
/**
* Start parsing and creating the job.
*
* @throws JobCreationException if an error occurred during job creation process.
*/
private Job createJob(XMLStreamReader cursorRoot, Map<String, String> replacementVariables, Map<String, String> replacementGenericInfos, Map<String, ArrayList<String>> dependencies, String jobContent) throws JobCreationException {
String current = null;
GlobalVariablesData globalVariablesData = getConfiguredGlobalVariablesData(jobContent);
// start parsing
try {
int eventType;
Job job = null;
while (cursorRoot.hasNext()) {
eventType = cursorRoot.next();
if (eventType == XMLEvent.START_ELEMENT) {
current = cursorRoot.getLocalName();
if (XMLTags.JOB.matches(current)) {
// first tag of the job.
job = createAndFillJob(cursorRoot, replacementVariables, replacementGenericInfos, jobContent, globalVariablesData);
} else if (XMLTags.TASK.matches(current)) {
// once here, the job instance has been created
fillJobWithTasks(cursorRoot, job, dependencies, globalVariablesData);
} else if (XMLTags.METADATA_VISUALIZATION.matches(current) && job != null) {
// Add workflow visualization's embedded html
job.setVisualization(getJobVisualization(cursorRoot));
// Metadata is the last element to parse
break;
}
}
}
if (job != null) {
resolveCleaningScripts((TaskFlowJob) job, job.getVariablesAsReplacementMap());
}
Map<String, JobVariable> globalVariables = new LinkedHashMap<>();
for (String globalVariable : globalVariablesData.getVariables().keySet()) {
globalVariables.put(globalVariable, job.getVariables().get(globalVariable));
}
job.setGlobalVariables(globalVariables);
Map<String, String> globalGenericInfoMap = new LinkedHashMap<>();
for (String globalGenericInfo : globalVariablesData.getGenericInformation().keySet()) {
globalGenericInfoMap.put(globalGenericInfo, job.getGenericInformation().get(globalGenericInfo));
}
job.setGlobalGenericInformation(globalGenericInfoMap);
return job;
} catch (JobCreationException jce) {
if (XMLTags.TASK.matches(current)) {
jce.pushTag(XMLTags.TASK_FLOW.getXMLName());
}
throw jce;
} catch (Exception e) {
throw new JobCreationException(current, null, e);
}
}
Aggregations