Search in sources :

Example 6 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.

the class StaxJobFactory method fillJobWithTasks.

/**
 * Fill the created Job with coming tasks..
 * Leave the method with the cursor at the end of the file (nothing more has to be parsed).
 *
 * @param cursorTask the streamReader with the cursor on the first 'ELEMENT_TASK' tag.
 */
private void fillJobWithTasks(XMLStreamReader cursorTask, Job job, Map<String, ArrayList<String>> dependencies) throws JobCreationException {
    if (job == null) {
        throw new JobCreationException(XMLTags.JOB.getXMLName(), null, null);
    }
    XMLTags current = null;
    try {
        int eventType = -1;
        while (cursorTask.hasNext()) {
            // if use to keep the cursor on the task tag for the first loop
            if (eventType == -1) {
                eventType = cursorTask.getEventType();
            } else {
                eventType = cursorTask.next();
            }
            if (eventType == XMLEvent.START_ELEMENT && XMLTags.TASK.matches(cursorTask.getLocalName())) {
                Task t;
                switch(job.getType()) {
                    case TASKSFLOW:
                        current = XMLTags.TASK;
                        // create new task
                        t = createTask(cursorTask, job, dependencies);
                        // add task to the job
                        ((TaskFlowJob) job).addTask(t);
                        break;
                    case PARAMETER_SWEEPING:
                        current = XMLTags.TASK;
                        throw new RuntimeException("Job parameter sweeping is not yet implemented!");
                    default:
                }
            }
        }
    } catch (JobCreationException jce) {
        jce.pushTag(current);
        throw jce;
    } catch (Exception e) {
        throw new JobCreationException(current, null, e);
    }
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) 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) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException)

Example 7 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.

the class StaxJobFactory method createJob.

private Job createJob(File file, Map<String, String> replacementVariables) throws JobCreationException {
    try {
        // Check if the file exist
        if (!file.exists()) {
            throw new FileNotFoundException("This file has not been found: " + file.getAbsolutePath());
        }
        // validate content using the proper XML schema
        File updatedFile = validate(file);
        // set relative path
        relativePathRoot = updatedFile.getParentFile().getAbsolutePath();
        // create and get XML STAX reader
        XMLStreamReader xmlsr;
        Map<String, ArrayList<String>> dependencies = new HashMap<>();
        Job job;
        try (InputStream inputStream = new FileInputStream(updatedFile)) {
            // use the server side property to accept encoding
            if (PASchedulerProperties.FILE_ENCODING.isSet()) {
                xmlsr = xmlInputFactory.createXMLStreamReader(inputStream, PASchedulerProperties.FILE_ENCODING.getValueAsString());
            } else {
                xmlsr = xmlInputFactory.createXMLStreamReader(inputStream);
            }
            // Create the job starting at the first cursor position of the XML Stream reader
            job = createJob(xmlsr, replacementVariables, dependencies);
            // Close the stream
            xmlsr.close();
        }
        // make dependencies
        makeDependences(job, dependencies);
        validate((TaskFlowJob) job);
        logger.debug("Job successfully created!");
        // debug mode only
        displayJobInfo(job);
        return job;
    } catch (JobCreationException jce) {
        jce.pushTag(XMLTags.JOB.getXMLName());
        throw jce;
    } catch (Exception e) {
        throw new JobCreationException(e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Job(org.ow2.proactive.scheduler.common.job.Job) File(java.io.File) FileInputStream(java.io.FileInputStream) 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) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException)

Example 8 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.

the class SchedulerClientTest method nodeClientJob.

protected Job nodeClientJob(String groovyScript, String forkScript) throws Exception {
    URL scriptURL = SchedulerClientTest.class.getResource(groovyScript);
    URL forkScriptURL = SchedulerClientTest.class.getResource(forkScript);
    TaskFlowJob job = new TaskFlowJob();
    job.setName("NodeClientJob");
    ScriptTask task = new ScriptTask();
    task.setName("NodeClientTask");
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.setEnvScript(new SimpleScript(IOUtils.toString(forkScriptURL.toURI()), "groovy"));
    task.setForkEnvironment(forkEnvironment);
    task.setScript(new TaskScript(new SimpleScript(IOUtils.toString(scriptURL.toURI()), "groovy")));
    // add CleanScript to test external APIs
    task.setCleaningScript(new SimpleScript("" + "schedulerapi.connect();\n" + "print(\"SCHEDULERAPI_URI_LIST_NOT_NULL=\"+(schedulerapi.getGlobalSpaceURIs()!=null));\n" + "\n" + "userspaceapi.connect();\n" + "print(\"USERSPACE_FILE_LIST_NOT_NULL=\"+(userspaceapi.listFiles(\".\", \"*\")!=null));\n" + "\n" + "globalspaceapi.connect();\n" + "print(\"GLOBALSPACE_FILE_LIST_NOT_NULL=\"+(globalspaceapi.listFiles(\".\", \"*\")!=null));\n" + "print(\"TEST_CREDS=\"+(credentials.get(\"TEST_CREDS\")));\n", "js"));
    job.addTask(task);
    return job;
}
Also used : ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) URL(java.net.URL)

Example 9 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.

the class DefaultModelJobValidatorServiceProvider method validateJob.

@Override
public TaskFlowJob validateJob(TaskFlowJob job) throws JobValidationException {
    ModelValidatorContext context = new ModelValidatorContext(job);
    for (JobVariable jobVariable : job.getVariables().values()) {
        checkVariableFormat(null, jobVariable, context);
        context.updateJobWithContext(job);
    }
    for (Task task : job.getTasks()) {
        context = new ModelValidatorContext(task);
        for (TaskVariable taskVariable : task.getVariables().values()) {
            checkVariableFormat(task, taskVariable, context);
            context.updateTaskWithContext(task);
        }
    }
    return job;
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 10 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.

the class Job2XMLTransformerTest method checkTaskVariables.

@Test
public void checkTaskVariables() throws Exception {
    File xmlFile = tmpFolder.newFile();
    Map<String, TaskVariable> variablesMap = new HashMap<>();
    TaskVariable taskVariable1 = new TaskVariable();
    taskVariable1.setName("name1");
    taskVariable1.setValue("value1");
    taskVariable1.setJobInherited(false);
    taskVariable1.setModel("model1");
    TaskVariable taskVariable2 = new TaskVariable();
    taskVariable2.setName("name2");
    taskVariable2.setValue("value2");
    taskVariable2.setJobInherited(true);
    taskVariable2.setModel("model2");
    variablesMap.put(taskVariable1.getName(), taskVariable1);
    variablesMap.put(taskVariable2.getName(), taskVariable2);
    TaskFlowJob job = new TaskFlowJob();
    JavaTask task = new JavaTask();
    task.setName("task");
    task.setExecutableClassName("oo.Bar");
    task.setVariables(variablesMap);
    job.addTask(task);
    new Job2XMLTransformer().job2xmlFile(job, xmlFile);
    TaskFlowJob recreatedJob = (TaskFlowJob) (JobFactory.getFactory().createJob(xmlFile.getAbsolutePath()));
    Map<String, TaskVariable> resVariables = recreatedJob.getTask("task").getVariables();
    assertEquals(2, resVariables.size());
    assertEquals(taskVariable1, resVariables.get("name1"));
    assertEquals(taskVariable2, resVariables.get("name2"));
}
Also used : HashMap(java.util.HashMap) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) File(java.io.File) Test(org.junit.Test)

Aggregations

TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)184 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)92 Test (org.junit.Test)81 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)49 JobId (org.ow2.proactive.scheduler.common.job.JobId)33 File (java.io.File)31 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)25 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)22 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)21 SimpleScript (org.ow2.proactive.scripting.SimpleScript)20 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)18 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)16 Task (org.ow2.proactive.scheduler.common.task.Task)16 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)13 TaskScript (org.ow2.proactive.scripting.TaskScript)13 JobState (org.ow2.proactive.scheduler.common.job.JobState)12 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)12 ArrayList (java.util.ArrayList)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)11 HashMap (java.util.HashMap)10