Search in sources :

Example 1 with ScriptResult

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

the class RMProxyActiveObject method printCleaningScriptInformations.

private void printCleaningScriptInformations(NodeSet nodes, ScriptResult<?> sResult, TaskId taskId) {
    if (logger.isInfoEnabled()) {
        TaskLogger instance = TaskLogger.getInstance();
        String nodeUrl = nodes.get(0).getNodeInformation().getURL();
        if (sResult.errorOccured()) {
            instance.error(taskId, "Exception while running cleaning script on " + nodeUrl, sResult.getException());
        } else {
            instance.info(taskId, "Cleaning script successful.");
        }
        if (sResult.getOutput() != null && !sResult.getOutput().isEmpty()) {
            instance.info(taskId, "Cleaning script output on node " + nodeUrl + ":");
            instance.info(taskId, sResult.getOutput());
        }
    }
}
Also used : TaskLogger(org.ow2.proactive.scheduler.util.TaskLogger)

Example 2 with ScriptResult

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

the class RMProxyActiveObject method handleCleaningScript.

/**
 * Execute the given script on the given node.
 * Also register a callback on {@link #cleanCallBack(Future, NodeSet)} method when script has returned.
 * @param nodes           the nodeset on which to start the script
 * @param cleaningScript the script to be executed
 * @param variables
 * @param genericInformation
 * @param taskId
 * @param creds credentials with CredData containing third party credentials
 */
private void handleCleaningScript(NodeSet nodes, Script<?> cleaningScript, VariablesMap variables, Map<String, String> genericInformation, TaskId taskId, Credentials creds) {
    TaskLogger instance = TaskLogger.getInstance();
    try {
        this.nodesTaskId.put(nodes, taskId);
        // create a decrypter to access scheduler and retrieve Third Party User Credentials
        String privateKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PRIVKEY_PATH.getValueAsString());
        Decrypter decrypter = new Decrypter(Credentials.getPrivateKey(privateKeyPath));
        decrypter.setCredentials(creds);
        HashMap<String, Serializable> dictionary = new HashMap<>();
        dictionary.putAll(variables.getScriptMap());
        dictionary.putAll(variables.getInheritedMap());
        dictionary.putAll(variables.getPropagatedVariables());
        dictionary.putAll(variables.getScopeMap());
        // start handler for binding
        ScriptHandler handler = ScriptLoader.createHandler(nodes.get(0));
        VariablesMap resolvedMap = new VariablesMap();
        resolvedMap.setInheritedMap(VariableSubstitutor.resolveVariables(variables.getInheritedMap(), dictionary));
        resolvedMap.setScopeMap(VariableSubstitutor.resolveVariables(variables.getScopeMap(), dictionary));
        handler.addBinding(SchedulerConstants.VARIABLES_BINDING_NAME, (Serializable) resolvedMap);
        handler.addBinding(SchedulerConstants.GENERIC_INFO_BINDING_NAME, (Serializable) genericInformation);
        // retrieve scheduler URL to bind with schedulerapi, globalspaceapi, and userspaceapi
        String schedulerUrl = PASchedulerProperties.SCHEDULER_REST_URL.getValueAsString();
        logger.debug("Binding schedulerapi...");
        SchedulerNodeClient client = new SchedulerNodeClient(decrypter, schedulerUrl);
        handler.addBinding(SchedulerConstants.SCHEDULER_CLIENT_BINDING_NAME, (Serializable) client);
        logger.debug("Binding globalspaceapi...");
        RemoteSpace globalSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.GLOBAL, schedulerUrl);
        handler.addBinding(SchedulerConstants.DS_GLOBAL_API_BINDING_NAME, (Serializable) globalSpaceClient);
        logger.debug("Binding userspaceapi...");
        RemoteSpace userSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.USER, schedulerUrl);
        handler.addBinding(SchedulerConstants.DS_USER_API_BINDING_NAME, (Serializable) userSpaceClient);
        logger.debug("Binding credentials...");
        Map<String, String> resolvedThirdPartyCredentials = VariableSubstitutor.filterAndUpdate(decrypter.decrypt().getThirdPartyCredentials(), dictionary);
        handler.addBinding(SchedulerConstants.CREDENTIALS_VARIABLE, (Serializable) resolvedThirdPartyCredentials);
        ScriptResult<?> future = handler.handle(cleaningScript);
        try {
            PAEventProgramming.addActionOnFuture(future, "cleanCallBack", nodes);
        } catch (IllegalArgumentException e) {
            // TODO - linked to PROACTIVE-936 -> IllegalArgumentException is raised if method name is unknown
            // should be replaced by checked exception
            instance.error(taskId, "ERROR : Callback method won't be executed, node won't be released. This is a critical state, check the callback method name", e);
        }
        instance.info(taskId, "Cleaning Script started on node " + nodes.get(0).getNodeInformation().getURL());
    } catch (Exception e) {
        // if active object cannot be created or script has failed
        instance.error(taskId, "Error while starting cleaning script for task " + taskId + " on " + nodes.get(0), e);
        releaseNodes(nodes).booleanValue();
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SchedulerNodeClient(org.ow2.proactive.scheduler.task.client.SchedulerNodeClient) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) LoginException(javax.security.auth.login.LoginException) TaskLogger(org.ow2.proactive.scheduler.util.TaskLogger) RemoteSpace(org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) DataSpaceNodeClient(org.ow2.proactive.scheduler.task.client.DataSpaceNodeClient) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 3 with ScriptResult

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

the class SchedulerStarter method executeStartScripts.

private static void executeStartScripts() throws InvalidScriptException, IOException {
    // Nothing to do if no script path is specified
    if (!PASchedulerProperties.SCHEDULER_STARTSCRIPTS_PATHS.isSet())
        return;
    // Retrieve the start scripts paths
    List<String> scriptsPaths = PASchedulerProperties.SCHEDULER_STARTSCRIPTS_PATHS.getValueAsList(";");
    // Scripts binding
    ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
    scriptHandler.addBindings(PASchedulerProperties.getPropertiesAsHashMap());
    scriptHandler.addBindings(PAResourceManagerProperties.getPropertiesAsHashMap());
    scriptHandler.addBindings(WebProperties.getPropertiesAsHashMap());
    // Execute all the listed scripts
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os, true);
    ScriptResult scriptResult;
    File scriptFile;
    for (String scriptPath : scriptsPaths) {
        scriptFile = new File(PASchedulerProperties.getAbsolutePath(scriptPath));
        if (scriptFile.exists()) {
            LOGGER.info("Executing " + scriptPath);
            scriptResult = scriptHandler.handle(new SimpleScript(scriptFile, new String[0]), ps, ps);
            if (scriptResult.errorOccured()) {
                // Close streams before throwing
                os.close();
                ps.close();
                throw new InvalidScriptException("Failed to execute script: " + scriptResult.getException().getMessage(), scriptResult.getException());
            }
            LOGGER.info(os.toString());
            os.reset();
        } else
            LOGGER.warn("Start script " + scriptPath + " not found");
    }
    // Close streams
    os.close();
    ps.close();
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) PrintStream(java.io.PrintStream) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 4 with ScriptResult

use of org.ow2.proactive.scripting.ScriptResult 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)

Example 5 with ScriptResult

use of org.ow2.proactive.scripting.ScriptResult 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)

Aggregations

ScriptResult (org.ow2.proactive.scripting.ScriptResult)18 SelectionScript (org.ow2.proactive.scripting.SelectionScript)10 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)8 Test (org.junit.Test)7 SimpleScript (org.ow2.proactive.scripting.SimpleScript)7 SelectionManager (org.ow2.proactive.resourcemanager.selection.SelectionManager)6 SelectionManagerTest (org.ow2.proactive.resourcemanager.selection.SelectionManagerTest)6 File (java.io.File)5 Serializable (java.io.Serializable)4 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)4 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)4 IOException (java.io.IOException)3 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 LoginException (javax.security.auth.login.LoginException)2 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)2 RemoteSpace (org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace)2