Search in sources :

Example 1 with InputSelector

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

the class Attribute method createTaskElement.

/**
 * Creates the task element, corressponding to <define name="task">
 */
private Element createTaskElement(Document doc, Task task) {
    Element taskE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK.getXMLName());
    if (task.getOnTaskErrorProperty().isSet()) {
        setAttribute(taskE, XMLAttributes.COMMON_ON_TASK_ERROR, task.getOnTaskErrorProperty().getValue().toString(), true);
    }
    if (task.getMaxNumberOfExecutionProperty().isSet()) {
        setAttribute(taskE, XMLAttributes.COMMON_MAX_NUMBER_OF_EXECUTION, Integer.toString(task.getMaxNumberOfExecution()));
    }
    setAttribute(taskE, XMLAttributes.COMMON_NAME, task.getName(), true);
    if (task.getRestartTaskOnErrorProperty().isSet()) {
        setAttribute(taskE, XMLAttributes.COMMON_RESTART_TASK_ON_ERROR, task.getRestartTaskOnError().toString());
    }
    // *** task attributes ***
    if (task.getWallTime() != 0) {
        setAttribute(taskE, XMLAttributes.TASK_WALLTIME, formatDate(task.getWallTime()));
    }
    if (task.isRunAsMe()) {
        setAttribute(taskE, XMLAttributes.TASK_RUN_AS_ME, "true");
    }
    if (task.isPreciousResult()) {
        setAttribute(taskE, XMLAttributes.TASK_PRECIOUS_RESULT, "true");
    }
    if (task.isPreciousLogs()) {
        setAttribute(taskE, XMLAttributes.TASK_PRECIOUS_LOGS, "true");
    }
    // <ref name="taskDescription"/>
    if (task.getDescription() != null) {
        Element descrNode = createElement(doc, XMLTags.COMMON_DESCRIPTION.getXMLName(), task.getDescription());
        taskE.appendChild(descrNode);
    }
    // <ref name="variables"/>
    if (task.getVariables() != null && !task.getVariables().isEmpty()) {
        Element variablesE = createTaskVariablesElement(doc, task.getVariables());
        taskE.appendChild(variablesE);
    }
    // <ref name="genericInformation"/>
    if ((task.getGenericInformation() != null) && (task.getGenericInformation().size() > 0)) {
        Element genericInfoE = createGenericInformation(doc, task.getGenericInformation());
        taskE.appendChild(genericInfoE);
    }
    // <ref name="depends"/>
    List<Task> dependencies = task.getDependencesList();
    if ((dependencies != null) && (dependencies.size() > 0)) {
        Element dependsE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK_DEPENDENCES.getXMLName());
        for (Task dep : dependencies) {
            Element dependsTask = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK_DEPENDENCES_TASK.getXMLName());
            setAttribute(dependsTask, XMLAttributes.TASK_DEPENDS_REF, dep.getName(), true);
            dependsE.appendChild(dependsTask);
        }
        taskE.appendChild(dependsE);
    }
    // if has dependencies
    // <ref name="inputFiles"/>
    List<InputSelector> inputFiles = task.getInputFilesList();
    if (inputFiles != null) {
        Element inputFilesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_INPUT_FILES.getXMLName());
        for (InputSelector inputSelector : inputFiles) {
            FileSelector fs = inputSelector.getInputFiles();
            Element filesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_FILES.getXMLName());
            // pattern
            if (!fs.getIncludes().isEmpty())
                setAttribute(filesE, XMLAttributes.DS_INCLUDES, fs.getIncludes().iterator().next(), true);
            if (!fs.getExcludes().isEmpty())
                setAttribute(filesE, XMLAttributes.DS_EXCLUDES, fs.getExcludes().iterator().next(), true);
            if (inputSelector.getMode() != null) {
                setAttribute(filesE, XMLAttributes.DS_ACCESS_MODE, inputSelector.getMode().toString(), true);
            }
            inputFilesE.appendChild(filesE);
        }
        taskE.appendChild(inputFilesE);
    }
    // <ref name="parallel"/>
    Element parallelEnvE = createParallelEnvironment(doc, task);
    if (parallelEnvE != null)
        taskE.appendChild(parallelEnvE);
    // <ref name="selection"/>
    List<SelectionScript> selectionScripts = task.getSelectionScripts();
    if (selectionScripts != null && selectionScripts.size() > 0) {
        Element selectionE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_SELECTION.getXMLName());
        for (SelectionScript selectionScript : selectionScripts) {
            Element scriptE = createScriptElement(doc, selectionScript);
            selectionE.appendChild(scriptE);
        }
        taskE.appendChild(selectionE);
    }
    // <ref name="forkEnvironment"/>
    if (task.getForkEnvironment() != null) {
        Element forkEnvE = createForkEnvironmentElement(doc, task.getForkEnvironment());
        taskE.appendChild(forkEnvE);
    }
    // <ref name="pre"/>
    Script preScript = task.getPreScript();
    if (preScript != null) {
        Element preE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_PRE.getXMLName());
        Element scriptE = createScriptElement(doc, preScript);
        preE.appendChild(scriptE);
        taskE.appendChild(preE);
    }
    // <ref name="executable"/>
    Element executableE = null;
    if (task instanceof JavaTask) {
        executableE = createJavaExecutableElement(doc, (JavaTask) task);
    } else if (task instanceof NativeTask) {
        executableE = createNativeExecutableElement(doc, (NativeTask) task);
    } else if (task instanceof ScriptTask) {
        executableE = createScriptExecutableElement(doc, (ScriptTask) task);
    }
    taskE.appendChild(executableE);
    // <ref name="flow"/>
    Element controlFlowE = createFlowControlElement(doc, task);
    if (controlFlowE != null)
        taskE.appendChild(controlFlowE);
    // <ref name="post"/>
    Script postScript = task.getPostScript();
    if (postScript != null) {
        Element postE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_POST.getXMLName());
        Element scriptE = createScriptElement(doc, postScript);
        postE.appendChild(scriptE);
        taskE.appendChild(postE);
    }
    // <ref name="cleaning"/>
    Script cleanScript = task.getCleaningScript();
    if (cleanScript != null) {
        Element cleanE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_CLEANING.getXMLName());
        Element scriptE = createScriptElement(doc, cleanScript);
        cleanE.appendChild(scriptE);
        taskE.appendChild(cleanE);
    }
    // <ref name="outputFiles"/>
    List<OutputSelector> outputFiles = task.getOutputFilesList();
    if (outputFiles != null) {
        Element outputFilesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_OUTPUT_FILES.getXMLName());
        for (OutputSelector outputSelector : outputFiles) {
            FileSelector fs = outputSelector.getOutputFiles();
            Element filesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_FILES.getXMLName());
            // pattern
            if (!fs.getIncludes().isEmpty())
                setAttribute(filesE, XMLAttributes.DS_INCLUDES, fs.getIncludes().iterator().next(), true);
            if (!fs.getExcludes().isEmpty())
                setAttribute(filesE, XMLAttributes.DS_EXCLUDES, fs.getExcludes().iterator().next(), true);
            if (outputSelector.getMode() != null) {
                setAttribute(filesE, XMLAttributes.DS_ACCESS_MODE, outputSelector.getMode().toString(), true);
            }
            outputFilesE.appendChild(filesE);
        }
        taskE.appendChild(outputFilesE);
    }
    return taskE;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) Script(org.ow2.proactive.scripting.Script) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript) 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) Element(org.w3c.dom.Element) FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) SelectionScript(org.ow2.proactive.scripting.SelectionScript) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector)

Example 2 with InputSelector

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

the class TaskLauncherDataSpacesTest method input_file_using_variable_in_its_selector.

@Test
public void input_file_using_variable_in_its_selector() throws Throwable {
    ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("println new File('.').listFiles();", "groovy")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    initializer.setJobVariables(singletonMap("aVar", new JobVariable("aVar", "foo")));
    initializer.setTaskInputFiles(singletonList(new InputSelector(new FileSelector("input_${aVar}_${aResultVar}.txt"), InputAccessMode.TransferFromInputSpace)));
    File inputFile = new File(taskLauncherFactory.getDataSpaces().getInputURI(), "input_foo_bar.txt");
    assertTrue(inputFile.createNewFile());
    TaskResultImpl previousTaskResult = taskResult(Collections.<String, Serializable>singletonMap("aResultVar", "bar"));
    TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, taskLauncherFactory), executableContainer, previousTaskResult);
    assertTaskResultOk(taskResult);
    assertTrue(taskResult.getOutput().getAllLogs(false).contains("input_foo_bar.txt"));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) File(java.io.File) Test(org.junit.Test)

Example 3 with InputSelector

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

the class TaskLauncherDataSpacesTest method input_file_using_job_id_in_its_selector.

@Test
public void input_file_using_job_id_in_its_selector() throws Throwable {
    ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("println new File('.').listFiles();", "groovy")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    initializer.setTaskInputFiles(singletonList(new InputSelector(new FileSelector("input_$PA_JOB_ID.txt"), InputAccessMode.TransferFromInputSpace)));
    File inputFile = new File(taskLauncherFactory.getDataSpaces().getInputURI(), "input_1000.txt");
    assertTrue(inputFile.createNewFile());
    TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, taskLauncherFactory), executableContainer);
    assertFalse(taskResult.hadException());
    assertTrue(taskResult.getOutput().getAllLogs(false).contains("input_1000.txt"));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector) File(java.io.File) Test(org.junit.Test)

Example 4 with InputSelector

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

the class TaskLauncherInitializerTest method input_files_can_be_filtered.

@Test
public void input_files_can_be_filtered() throws Exception {
    initializer.setTaskInputFiles(inputSelectors("$TEST/a", "b"));
    initializer.getTaskInputFiles().get(0).getInputFiles().setExcludes("$TEST/excluded");
    List<InputSelector> filteredInputFiles = initializer.getFilteredInputFiles(Collections.<String, Serializable>singletonMap("TEST", "folder"));
    InputSelector selector = filteredInputFiles.get(0);
    assertEquals(ImmutableSet.of("folder/a", "b"), selector.getInputFiles().getIncludes());
    assertEquals(ImmutableSet.of("folder/excluded"), selector.getInputFiles().getExcludes());
}
Also used : InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector) Test(org.junit.Test)

Example 5 with InputSelector

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

the class SelectorData method createInputSelector.

InputSelector createInputSelector() {
    if (!type.equals(INPUT_TYPE)) {
        throw new IllegalStateException("Not input selector: " + type);
    }
    FileSelector fileSelector = new FileSelector(getIncludes(), getExcludes());
    InputSelector selector = new InputSelector(fileSelector, InputAccessMode.valueOf(getAccessMode()));
    return selector;
}
Also used : FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector)

Aggregations

InputSelector (org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector)14 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 FileSelector (org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector)4 Task (org.ow2.proactive.scheduler.common.task.Task)3 OutputSelector (org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector)3 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)3 File (java.io.File)2 Future (java.util.concurrent.Future)2 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)2 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 AwaitedTask (org.ow2.proactive.scheduler.smartproxy.common.AwaitedTask)2 SelectionScript (org.ow2.proactive.scripting.SelectionScript)2 SimpleScript (org.ow2.proactive.scripting.SimpleScript)2 TaskScript (org.ow2.proactive.scripting.TaskScript)2 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSelector (org.apache.commons.vfs2.FileSelector)1 DataSpacesFileObject (org.objectweb.proactive.extensions.dataspaces.api.DataSpacesFileObject)1