Search in sources :

Example 21 with NodeSet

use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.

the class SchedulingService method kill.

public boolean kill() {
    if (status.isKilled()) {
        return false;
    }
    status = SchedulerStatus.KILLED;
    pinger.interrupt();
    schedulingThread.interrupt();
    logger.info("Killing all running task processes...");
    for (RunningTaskData taskData : jobs.getRunningTasks()) {
        NodeSet nodes = taskData.getTask().getExecuterInformation().getNodes();
        try {
            taskData.getLauncher().kill();
        } catch (Throwable t) {
            logger.error("Failed to terminate launcher", t);
        }
        try {
            infrastructure.getRMProxiesManager().getUserRMProxy(taskData.getUser(), taskData.getCredentials()).releaseNodes(nodes, taskData.getTask().getCleaningScript(), addThirdPartyCredentials(taskData.getCredentials()));
        } catch (Throwable t) {
            logger.error("Failed to release nodes", t);
        }
    }
    listenJobLogsSupport.shutdown();
    infrastructure.shutdown();
    listener.schedulerStateUpdated(SchedulerEvent.KILLED);
    return true;
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet)

Example 22 with NodeSet

use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.

the class SchedulerStateRecoverHelper method runningTaskMustBeResetToPending.

private boolean runningTaskMustBeResetToPending(InternalTask task, RMProxy rmProxy) {
    boolean resetToPending;
    if (rmProxy != null) {
        NodeSet nodes = task.getExecuterInformation().getNodes();
        boolean taskNodesKnownByRM = rmProxy.areNodesKnown(nodes);
        if (taskNodesKnownByRM) {
            TaskLauncher launcher = task.getExecuterInformation().getLauncher();
            logger.debug("Checking whether task launcher has called its doTask method: " + launcher.isTaskStarted());
            if (launcher.isTaskStarted()) {
                logger.info("Recover running task " + task.getId() + " (" + task.getName() + ") successfully with task launcher " + launcher);
                resetToPending = false;
            } else {
                logger.info(FAIL_TO_RECOVER_RUNNING_TASK_STRING + task.getId() + " (" + task.getName() + ") because its task launcher has not started to execute the task");
                resetToPending = true;
            }
        } else {
            logger.info(FAIL_TO_RECOVER_RUNNING_TASK_STRING + task.getId() + " (" + task.getName() + ") because the task's node is not known by the resource manager");
            resetToPending = true;
        }
    } else {
        logger.info(FAIL_TO_RECOVER_RUNNING_TASK_STRING + task.getId() + " (" + task.getName() + ") because the resource manager is not reachable");
        resetToPending = true;
    }
    return resetToPending;
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher)

Example 23 with NodeSet

use of org.ow2.proactive.utils.NodeSet 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 24 with NodeSet

use of org.ow2.proactive.utils.NodeSet 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 25 with NodeSet

use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.

the class TestRMProxy method requestWithExtraNodes.

private void requestWithExtraNodes(RMProxy proxy, ResourceManager rm) throws Exception {
    log("Request NodeSet with extra nodes");
    TopologyDescriptor topology = TopologyDescriptor.SINGLE_HOST_EXCLUSIVE;
    Criteria criteria = new Criteria(1);
    criteria.setTopology(topology);
    NodeSet nodeSet = proxy.getNodes(criteria);
    PAFuture.waitFor(nodeSet);
    assertEquals(1, nodeSet.size());
    Assert.assertNotNull("Extra nodes are expected", nodeSet.getExtraNodes());
    assertEquals(NODES_NUMBER - 1, nodeSet.getExtraNodes().size());
    assertEquals(0, rm.getState().getFreeNodesNumber());
    proxy.releaseNodes(nodeSet);
    waitWhenNodesAreReleased(NODES_NUMBER);
    assertEquals(NODES_NUMBER, rm.getState().getFreeNodesNumber());
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Criteria(org.ow2.proactive.utils.Criteria) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor)

Aggregations

NodeSet (org.ow2.proactive.utils.NodeSet)51 Test (org.junit.Test)28 Criteria (org.ow2.proactive.utils.Criteria)23 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)20 Node (org.objectweb.proactive.core.node.Node)18 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)17 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 SelectionScript (org.ow2.proactive.scripting.SelectionScript)10 File (java.io.File)9 TestNode (functionaltests.utils.TestNode)8 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)7 RMCore (org.ow2.proactive.resourcemanager.core.RMCore)5 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)5 ProActiveTimeoutException (org.objectweb.proactive.core.ProActiveTimeoutException)4 RMState (org.ow2.proactive.resourcemanager.common.RMState)4 IOException (java.io.IOException)3 Permission (java.security.Permission)3 HashSet (java.util.HashSet)3