Search in sources :

Example 6 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable in project scheduling by ow2-proactive.

the class TestStaxJobFactory method testTaskVariables.

@Test
public void testTaskVariables() throws URISyntaxException, JobCreationException {
    TaskFlowJob job = (TaskFlowJob) factory.createJob(getResource("task_variables.xml"));
    Map<String, TaskVariable> taskVariables = job.getTask("task").getVariables();
    assertEquals(2, taskVariables.size());
    TaskVariable taskVariable = taskVariables.get("name1");
    assertNotNull(taskVariable);
    assertEquals("name1", taskVariable.getName());
    assertEquals("value1", taskVariable.getValue());
    assertEquals("model1", taskVariable.getModel());
    assertFalse(taskVariable.isJobInherited());
    taskVariable = taskVariables.get("name2");
    assertNotNull(taskVariable);
    assertEquals("name2", taskVariable.getName());
    assertEquals("value2", taskVariable.getValue());
    assertEquals("model2", taskVariable.getModel());
    assertTrue(taskVariable.isJobInherited());
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) Test(org.junit.Test)

Example 7 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable in project scheduling by ow2-proactive.

the class DefaultModelJobValidatorServiceProviderTest method createJobWithTaskModelVariable.

private TaskFlowJob createJobWithTaskModelVariable(String value, String model) throws UserException {
    TaskFlowJob job = new TaskFlowJob();
    TaskVariable variable = new TaskVariable("VAR", value, model, false);
    Task task = new ScriptTask();
    task.setName("ModelTask");
    task.setVariables(Collections.singletonMap(variable.getName(), variable));
    job.addTask(task);
    return job;
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable)

Example 8 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable in project scheduling by ow2-proactive.

the class TestTaskAttributes method testTaskVariables.

@Test
public void testTaskVariables() throws Exception {
    JavaTask task = createDefaultTask("task");
    Map<String, TaskVariable> variables;
    InternalTask taskData;
    variables = new HashMap<>();
    task.setVariables(variables);
    taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertNotNull(taskData.getVariables());
    Assert.assertTrue(taskData.getVariables().isEmpty());
    variables = new HashMap<>();
    TaskVariable v1 = new TaskVariable();
    v1.setName("p1");
    v1.setValue("v1");
    TaskVariable v2 = new TaskVariable();
    v2.setName("p2");
    v2.setValue("v2");
    variables.put("p1", v1);
    variables.put("p2", v2);
    TaskVariable v3 = new TaskVariable();
    v3.setName("emptyvar");
    variables.put("emptyvar", v3);
    task.setVariables(variables);
    taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertEquals(3, taskData.getVariables().size());
    Assert.assertEquals("p1", taskData.getVariables().get("p1").getName());
    Assert.assertEquals("p2", taskData.getVariables().get("p2").getName());
    Assert.assertEquals("v1", taskData.getVariables().get("p1").getValue());
    Assert.assertEquals("v2", taskData.getVariables().get("p2").getValue());
    Assert.assertEquals("emptyvar", taskData.getVariables().get("emptyvar").getName());
    Assert.assertNull(taskData.getVariables().get("emptyvar").getValue());
    StringBuilder longString = buildLongString();
    variables = new HashMap<>();
    TaskVariable longVariable = new TaskVariable();
    longVariable.setName("longProperty");
    longVariable.setValue(longString.toString());
    variables.put("longProperty", longVariable);
    task.setVariables(variables);
    taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertEquals(1, taskData.getVariables().size());
    Assert.assertEquals(longString.toString(), taskData.getVariables().get("longProperty").getValue());
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Example 9 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable in project scheduling by ow2-proactive.

the class StaxJobFactory method createTask.

/**
 * Fill the given task by the information that are at the given cursorTask.
 * Leave the method with the cursor at the end of 'ELEMENT_TASK' tag.
 *
 * @param cursorTask the streamReader with the cursor on the 'ELEMENT_TASK' tag.
 * @return The newly created task that can be any type.
 */
private Task createTask(XMLStreamReader cursorTask, Job job, Map<String, ArrayList<String>> dependencies) throws JobCreationException {
    int i = 0;
    XMLTags currentTag = null;
    String current = null;
    String taskName = null;
    try {
        Task toReturn = null;
        Task tmpTask = new Task() {
        };
        // parse job attributes and fill the temporary one
        int attrLen = cursorTask.getAttributeCount();
        for (i = 0; i < attrLen; i++) {
            String attributeName = cursorTask.getAttributeLocalName(i);
            String attributeValue = cursorTask.getAttributeValue(i);
            if (XMLAttributes.COMMON_NAME.matches(attributeName)) {
                tmpTask.setName(attributeValue);
                taskName = attributeValue;
            } else if (XMLAttributes.TASK_NB_NODES.matches(attributeName)) {
                int numberOfNodesNeeded = Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job)));
                tmpTask.setParallelEnvironment(new ParallelEnvironment(numberOfNodesNeeded));
            } else if (XMLAttributes.COMMON_CANCEL_JOB_ON_ERROR.matches(attributeName)) {
                handleCancelJobOnErrorAttribute(tmpTask, attributeValue);
            } else if (XMLAttributes.COMMON_ON_TASK_ERROR.matches(attributeName)) {
                tmpTask.setOnTaskError(OnTaskError.getInstance(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.COMMON_RESTART_TASK_ON_ERROR.matches(attributeName)) {
                tmpTask.setRestartTaskOnError(RestartMode.getMode(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.COMMON_MAX_NUMBER_OF_EXECUTION.matches(attributeName)) {
                tmpTask.setMaxNumberOfExecution(Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_PRECIOUS_RESULT.matches(attributeName)) {
                tmpTask.setPreciousResult(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_PRECIOUS_LOGS.matches(attributeName)) {
                tmpTask.setPreciousLogs(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_WALLTIME.matches(attributeName)) {
                tmpTask.setWallTime(Tools.formatDate(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_RUN_AS_ME.matches(attributeName)) {
                tmpTask.setRunAsMe(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            }
        }
        int eventType;
        boolean shouldContinue = true;
        while (shouldContinue && cursorTask.hasNext()) {
            eventType = cursorTask.next();
            switch(eventType) {
                case XMLEvent.START_ELEMENT:
                    current = cursorTask.getLocalName();
                    currentTag = null;
                    if (XMLTags.COMMON_GENERIC_INFORMATION.matches(current)) {
                        tmpTask.setGenericInformation(getGenericInformation(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.VARIABLES.matches(current)) {
                        Map<String, TaskVariable> taskVariablesMap = createTaskVariables(cursorTask, tmpTask.getVariablesOverriden(job));
                        tmpTask.setVariables(taskVariablesMap);
                    } else if (XMLTags.COMMON_DESCRIPTION.matches(current)) {
                        tmpTask.setDescription(getDescription(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.DS_INPUT_FILES.matches(current)) {
                        setIOFIles(cursorTask, XMLTags.DS_INPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
                    } else if (XMLTags.DS_OUTPUT_FILES.matches(current)) {
                        setIOFIles(cursorTask, XMLTags.DS_OUTPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
                    } else if (XMLTags.PARALLEL_ENV.matches(current)) {
                        tmpTask.setParallelEnvironment(createParallelEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_SELECTION.matches(current)) {
                        tmpTask.setSelectionScripts(createSelectionScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.FORK_ENVIRONMENT.matches(current)) {
                        tmpTask.setForkEnvironment(createForkEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_PRE.matches(current)) {
                        tmpTask.setPreScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_POST.matches(current)) {
                        tmpTask.setPostScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_CLEANING.matches(current)) {
                        tmpTask.setCleaningScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.FLOW.matches(current)) {
                        tmpTask.setFlowScript(createControlFlowScript(cursorTask, tmpTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.TASK_DEPENDENCES.matches(current)) {
                        currentTag = XMLTags.TASK_DEPENDENCES;
                        dependencies.putAll(createDependences(cursorTask, tmpTask));
                    } else if (XMLTags.JAVA_EXECUTABLE.matches(current)) {
                        toReturn = new JavaTask();
                        setJavaExecutable((JavaTask) toReturn, cursorTask, tmpTask.getVariablesOverriden(job));
                    } else if (XMLTags.NATIVE_EXECUTABLE.matches(current)) {
                        toReturn = new NativeTask();
                        setNativeExecutable((NativeTask) toReturn, cursorTask);
                    } else if (XMLTags.SCRIPT_EXECUTABLE.matches(current)) {
                        toReturn = new ScriptTask();
                        ((ScriptTask) toReturn).setScript(new TaskScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job))));
                    }
                    break;
                case XMLEvent.END_ELEMENT:
                    current = cursorTask.getLocalName();
                    if (XMLTags.TASK.matches(cursorTask.getLocalName())) {
                        shouldContinue = false;
                    }
                    break;
            }
        }
        // fill the real task with common attribute if it is a new one
        autoCopyfields(CommonAttribute.class, tmpTask, toReturn);
        autoCopyfields(Task.class, tmpTask, toReturn);
        if (toReturn != null) {
            if (toReturn.getRestartTaskOnErrorProperty().isSet()) {
                toReturn.setRestartTaskOnError(toReturn.getRestartTaskOnError());
            }
            if (toReturn.getMaxNumberOfExecutionProperty().isSet()) {
                toReturn.setMaxNumberOfExecution(toReturn.getMaxNumberOfExecution());
            }
        }
        return toReturn;
    } catch (JobCreationException jce) {
        jce.setTaskName(taskName);
        if (currentTag != null) {
            jce.pushTag(currentTag);
        } else {
            jce.pushTag(current);
        }
        throw jce;
    } catch (Exception e) {
        String attrtmp = null;
        if (cursorTask.isStartElement() && cursorTask.getAttributeCount() > i) {
            attrtmp = cursorTask.getAttributeLocalName(i);
        }
        if (currentTag != null) {
            throw new JobCreationException(currentTag, attrtmp, e);
        } else {
            throw new JobCreationException(current, attrtmp, 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) TaskScript(org.ow2.proactive.scripting.TaskScript) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) 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) ParallelEnvironment(org.ow2.proactive.scheduler.common.task.ParallelEnvironment) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable in project scheduling by ow2-proactive.

the class StaxJobFactory method getTaskVariable.

private TaskVariable getTaskVariable(XMLStreamReader cursorVariables, Map<String, String> variables) throws JobCreationException {
    TaskVariable taskVariable = new TaskVariable();
    Map<String, String> attributesAsMap = getAttributesAsMap(cursorVariables, variables);
    taskVariable.setName(attributesAsMap.get(XMLAttributes.VARIABLE_NAME.getXMLName()));
    taskVariable.setValue(attributesAsMap.get(XMLAttributes.VARIABLE_VALUE.getXMLName()));
    taskVariable.setModel(attributesAsMap.get(XMLAttributes.VARIABLE_MODEL.getXMLName()));
    if (attributesAsMap.containsKey(XMLAttributes.VARIABLE_JOB_INHERITED.getXMLName())) {
        taskVariable.setJobInherited(Boolean.valueOf(attributesAsMap.get(XMLAttributes.VARIABLE_JOB_INHERITED.getXMLName())));
    }
    return taskVariable;
}
Also used : TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable)

Aggregations

TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)13 HashMap (java.util.HashMap)6 Task (org.ow2.proactive.scheduler.common.task.Task)5 Test (org.junit.Test)3 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)3 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)3 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)3 FileNotFoundException (java.io.FileNotFoundException)2 LinkedHashMap (java.util.LinkedHashMap)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)2 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)2 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)2 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Map (java.util.Map)1 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)1