Search in sources :

Example 6 with JobContent

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;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) GlobalVariablesData(org.ow2.proactive.scheduler.common.job.factories.globalvariables.GlobalVariablesData) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 7 with JobContent

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);
}
Also used : Job(org.ow2.proactive.scheduler.common.job.Job) IdentifiedJob(org.ow2.proactive.scheduler.job.IdentifiedJob) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) ImmediateService(org.objectweb.proactive.annotation.ImmediateService)

Example 8 with JobContent

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;
    }
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) FileSystemException(org.objectweb.proactive.extensions.dataspaces.exceptions.FileSystemException) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) TaskCouldNotRestartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotRestartException) InvalidChannelException(org.ow2.proactive.scheduler.synchronization.InvalidChannelException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) AlreadyConnectedException(org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskCouldNotStartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotStartException) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) TaskSkippedException(org.ow2.proactive.scheduler.common.exception.TaskSkippedException) ProActiveException(org.objectweb.proactive.core.ProActiveException) SignalApiException(org.ow2.proactive.scheduler.signal.SignalApiException) StreamResult(javax.xml.transform.stream.StreamResult) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobResult(org.ow2.proactive.scheduler.common.job.JobResult)

Example 9 with 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);
}
Also used : ISchedulerClient(org.ow2.proactive.scheduler.rest.ISchedulerClient) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleJob(functionaltests.jobs.SimpleJob) Job(org.ow2.proactive.scheduler.common.job.Job) NonTerminatingJob(functionaltests.jobs.NonTerminatingJob) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 10 with JobContent

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);
    }
}
Also used : GlobalVariablesData(org.ow2.proactive.scheduler.common.job.factories.globalvariables.GlobalVariablesData) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Job(org.ow2.proactive.scheduler.common.job.Job) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) XMLStreamException(javax.xml.stream.XMLStreamException) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) FileNotFoundException(java.io.FileNotFoundException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Test (org.junit.Test)8 JobId (org.ow2.proactive.scheduler.common.job.JobId)7 HashMap (java.util.HashMap)6 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)6 File (java.io.File)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 Job (org.ow2.proactive.scheduler.common.job.Job)4 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)3 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)3 FileNotFoundException (java.io.FileNotFoundException)2 URL (java.net.URL)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 DatabaseManagerException (org.ow2.proactive.db.DatabaseManagerException)2 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)2 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)1 SimpleJob (functionaltests.jobs.SimpleJob)1 StringReader (java.io.StringReader)1