Search in sources :

Example 16 with Script

use of org.ow2.proactive.scripting.Script in project scheduling by ow2-proactive.

the class ScriptSerializer method deserialize.

@Override
public Script deserialize(File f, String id) throws IOException {
    String name = f.getName();
    String absolutePath = f.getAbsolutePath();
    String content = FileUtils.readFileToString(new File(absolutePath));
    return new Script(name, content, absolutePath);
}
Also used : Script(org.ow2.proactive_grid_cloud_portal.studio.Script) File(java.io.File)

Example 17 with Script

use of org.ow2.proactive.scripting.Script in project scheduling by ow2-proactive.

the class Attribute method createScriptElement.

/**
 * Corresponds to <element name="script">
 *
 * The schema allows the specification of a script either by writing the
 * script code either by providing a file with arguments. Both will result
 * in the same {@link org.ow2.proactive.scripting.Script} object. In the
 * current translation we will always translate a Script object by inlining
 * the script code using a "codeScript"element (first option).
 *
 * The xml specification does not allow addding arguments to a script
 * defined by its code. Therefore, when we translate the script object to
 * xml, if we encounter arguments, we will insert their value directly in
 * the script's code by inserting a line like:
 * <p/>
 * var args = ["argument_1",...,"argument_n"];
 */
private Element createScriptElement(Document doc, Script script) {
    Element scriptElement = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_SCRIPT.getXMLName());
    if (script.getScriptUrl() != null && script.getScript() == null) {
        Element fileE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_FILE.getXMLName());
        setAttribute(fileE, XMLAttributes.SCRIPT_URL, script.getScriptUrl().toExternalForm(), true);
        if (script.getEngineName() != null) {
            setAttribute(fileE, XMLAttributes.LANGUAGE, script.getEngineName(), true);
        }
        Serializable[] params = script.getParameters();
        if (params != null) {
            Element parametersE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_ARGUMENTS.getXMLName());
            for (Serializable param : params) {
                Element parameterE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_ARGUMENT.getXMLName());
                setAttribute(parameterE, XMLAttributes.COMMON_VALUE, param.toString(), true);
                parametersE.appendChild(parameterE);
            }
            fileE.appendChild(parametersE);
        }
        scriptElement.appendChild(fileE);
    } else {
        if (script instanceof SelectionScript) {
            setAttribute(scriptElement, XMLAttributes.TYPE, ((SelectionScript) script).isDynamic() ? "dynamic" : "static", true);
        }
        Element codeE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_CODE.getXMLName());
        setAttribute(codeE, XMLAttributes.LANGUAGE, script.getEngineName(), true);
        codeE.appendChild(doc.createCDATASection(script.getScript()));
        scriptElement.appendChild(codeE);
        Serializable[] params = script.getParameters();
        if (params != null) {
            Element parametersE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_ARGUMENTS.getXMLName());
            for (Serializable param : params) {
                Element parameterE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_ARGUMENT.getXMLName());
                setAttribute(parameterE, XMLAttributes.COMMON_VALUE, param.toString(), true);
                parametersE.appendChild(parameterE);
            }
            scriptElement.appendChild(parametersE);
        }
    }
    return scriptElement;
}
Also used : Serializable(java.io.Serializable) SelectionScript(org.ow2.proactive.scripting.SelectionScript) Element(org.w3c.dom.Element)

Example 18 with Script

use of org.ow2.proactive.scripting.Script 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());
    }
    if (task.getTaskRetryDelayProperty().isSet()) {
        setAttribute(taskE, XMLAttributes.COMMON_TASK_RETRY_DELAY, formatDate(task.getTaskRetryDelay()));
    }
    // *** 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.isFork() != null && task.isFork()) {
        setAttribute(taskE, XMLAttributes.TASK_FORK, "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 = createCDataElement(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 19 with Script

use of org.ow2.proactive.scripting.Script in project scheduling by ow2-proactive.

the class ProbabilisticSelectionManagerTest method testDecreasingProbabilityDynamicScriptWithoutDynamicityStorage.

@Test
public void testDecreasingProbabilityDynamicScriptWithoutDynamicityStorage() throws Exception {
    int nbNodes = 10;
    PAResourceManagerProperties.RM_SELECT_SCRIPT_NODE_DYNAMICITY.updateProperty("0");
    try {
        SelectionScript script = new SelectionScript("test", "groovy", true);
        ManagerObjects managerObjects = new ManagerObjects(nbNodes).invoke();
        SelectionManager selectionManager = managerObjects.getSelectionManager();
        ArrayList<RMNode> freeNodes = managerObjects.getFreeNodes();
        for (int i = 0; i < nbNodes; i++) {
            // we decrease the probability for each node, lowest node has the max number of false results
            for (int j = i; j < nbNodes; j++) {
                selectionManager.processScriptResult(script, Collections.EMPTY_MAP, new ScriptResult<>(false), freeNodes.get(i));
            }
        }
        List<RMNode> arrangedNodes = selectionManager.arrangeNodesForScriptExecution(freeNodes, Collections.singletonList(script), Collections.EMPTY_MAP);
        // list is supposed to contain all nodes because of dynamicity == 0
        Assert.assertEquals(freeNodes.size(), arrangedNodes.size());
        // nodes are expected to be sorted in reverse order
        for (int i = 0; i < nbNodes; i++) {
            Assert.assertEquals("mocked-node-" + (nbNodes - i), arrangedNodes.get(i).getNodeName());
            Assert.assertFalse(selectionManager.isPassed(script, Collections.EMPTY_MAP, arrangedNodes.get(i)));
        }
    } finally {
        PAResourceManagerProperties.RM_SELECT_SCRIPT_NODE_DYNAMICITY.updateProperty("300000");
    }
}
Also used : SelectionManager(org.ow2.proactive.resourcemanager.selection.SelectionManager) SelectionScript(org.ow2.proactive.scripting.SelectionScript) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) SelectionManagerTest(org.ow2.proactive.resourcemanager.selection.SelectionManagerTest) Test(org.junit.Test)

Example 20 with Script

use of org.ow2.proactive.scripting.Script in project scheduling by ow2-proactive.

the class ProbabilisticSelectionManagerTest method testDecreasingProbabilityDynamicScriptWithDynamicityStorage.

@Test
public void testDecreasingProbabilityDynamicScriptWithDynamicityStorage() throws Exception {
    int nbNodes = 10;
    SelectionScript script = new SelectionScript("test", "groovy", true);
    ManagerObjects managerObjects = new ManagerObjects(nbNodes).invoke();
    SelectionManager selectionManager = managerObjects.getSelectionManager();
    ArrayList<RMNode> freeNodes = managerObjects.getFreeNodes();
    for (int i = 0; i < nbNodes; i++) {
        // we decrease the probability for each node, lowest node has the max number of false results
        for (int j = i; j < nbNodes; j++) {
            selectionManager.processScriptResult(script, Collections.EMPTY_MAP, new ScriptResult<>(false), freeNodes.get(i));
        }
    }
    List<RMNode> arrangedNodes = selectionManager.arrangeNodesForScriptExecution(freeNodes, Collections.singletonList(script), Collections.EMPTY_MAP);
    // list is supposed to be empty because of dynamicity != 0
    Assert.assertEquals(0, arrangedNodes.size());
}
Also used : SelectionManager(org.ow2.proactive.resourcemanager.selection.SelectionManager) SelectionScript(org.ow2.proactive.scripting.SelectionScript) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) SelectionManagerTest(org.ow2.proactive.resourcemanager.selection.SelectionManagerTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)46 SelectionScript (org.ow2.proactive.scripting.SelectionScript)40 File (java.io.File)38 SimpleScript (org.ow2.proactive.scripting.SimpleScript)33 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)27 ScriptResult (org.ow2.proactive.scripting.ScriptResult)21 IOException (java.io.IOException)18 HashMap (java.util.HashMap)18 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)16 Script (org.ow2.proactive.scripting.Script)16 JobId (org.ow2.proactive.scheduler.common.job.JobId)13 FlowScript (org.ow2.proactive.scheduler.common.task.flow.FlowScript)13 ArrayList (java.util.ArrayList)12 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)12 Serializable (java.io.Serializable)11 TaskScript (org.ow2.proactive.scripting.TaskScript)11 NodeSet (org.ow2.proactive.utils.NodeSet)11 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)10 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)10 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)9