Search in sources :

Example 16 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.

the class NodeSource method buildRMNode.

/**
 * Builds a RMNode from a raw Node
 * @param node the node object
 * @param provider the client of the request
 * @return the expected RMNode
 */
private RMNode buildRMNode(Node node, Client provider) {
    // creating a node access permission
    // it could be either PROVIDER/PROVIDER_GROUPS and in this case
    // the provider principals will be taken or
    // ME/MY_GROUPS (ns creator/ns creator groups) and in this case
    // creator's principals will be used
    Client permissionOwner = administrator;
    if (nodeUserAccessType.equals(AccessType.PROVIDER) || nodeUserAccessType.equals(AccessType.PROVIDER_GROUPS)) {
        permissionOwner = provider;
    }
    // now selecting the type (user or group) and construct the permission
    Set<IdentityPrincipal> principals = (Set<IdentityPrincipal>) nodeUserAccessType.getIdentityPrincipals(permissionOwner);
    boolean tokenInNode = false;
    boolean tokenInNodeSource = nodeUserAccessType.getTokens() != null && nodeUserAccessType.getTokens().length > 0;
    try {
        String nodeAccessToken = node.getProperty(RMNodeStarter.NODE_ACCESS_TOKEN);
        tokenInNode = nodeAccessToken != null && nodeAccessToken.length() > 0;
        if (tokenInNode) {
            logger.debug("Node " + node.getNodeInformation().getURL() + " is protected by access token " + nodeAccessToken);
            // it overrides all other principals
            principals.clear();
            principals.add(new TokenPrincipal(nodeAccessToken));
        }
    } catch (Exception e) {
        throw new AddingNodesException(e);
    }
    PrincipalPermission nodeAccessPermission = new PrincipalPermission(node.getNodeInformation().getURL(), principals);
    RMNodeImpl rmnode = new RMNodeImpl(node, stub, provider, nodeAccessPermission);
    rmnode.setProtectedByToken(tokenInNode || tokenInNodeSource);
    return rmnode;
}
Also used : Set(java.util.Set) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) TokenPrincipal(org.ow2.proactive.authentication.principals.TokenPrincipal) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) Client(org.ow2.proactive.resourcemanager.authentication.Client) IdentityPrincipal(org.ow2.proactive.authentication.principals.IdentityPrincipal) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) RMException(org.ow2.proactive.resourcemanager.exception.RMException)

Example 17 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.

the class NodeSource method internalAddNodeAfterRecovery.

/**
 * Recover the internal data structure of the node source so that
 * recovered nodes and RMnodes are linked again to the node source.
 * @return the {@link RMNode} that could be recovered.
 */
public RMNode internalAddNodeAfterRecovery(Node node, RMNodeData rmNodeData) {
    RMNode recoveredRmNode;
    String nodeUrl = node.getNodeInformation().getURL();
    // the infrastructure manager is up to date already because it was
    // saved in database, contrarily to the node source internal data structures
    RMNode rmNode = infrastructureManager.searchForNotAcquiredRmNode(nodeUrl);
    if (rmNode != null) {
        // Deploying or lost RMNodes can be directly found in the saved infrastructure.
        recoveredRmNode = rmNode;
    } else {
        // the node is acquired in the infrastructure. We can recover the
        // RMNode representation on top of it and save it in the node source
        recoveredRmNode = buildRMNodeAfterRecovery(node, rmNodeData);
    }
    // we finally put back the node in the data structure of the node source
    nodes.put(nodeUrl, node);
    return recoveredRmNode;
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) AbstractRMNode(org.ow2.proactive.resourcemanager.rmnode.AbstractRMNode)

Example 18 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.

the class InfrastructureManager method update.

/**
 * Updates a deploying node.
 * <p>
 * The update is performed on deploying nodes first.
 * If no node if found, lost nodes are considered.
 *
 * @param rmNode the new deploying node instance to use.
 * @return the previous value or {@code null}.
 */
public RMDeployingNode update(RMDeployingNode rmNode) {
    String nodeUrl = rmNode.getNodeURL();
    RMDeployingNode previousDeployingNode;
    if (rmNode.isLost() && containsLostNodeWithLock(nodeUrl)) {
        previousDeployingNode = addLostNodeWithLockAndPersist(nodeUrl, rmNode);
    } else if (containsDeployingNodeWithLock(nodeUrl)) {
        previousDeployingNode = addDeployingNodeWithLockAndPersist(nodeUrl, rmNode);
    } else {
        previousDeployingNode = null;
    }
    return previousDeployingNode;
}
Also used : RMDeployingNode(org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)

Example 19 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.

the class ScriptExecutor method executeScripts.

/**
 * Runs selection scripts and process the results
 * returns node if it matches, null otherwise
 */
private Node executeScripts() {
    boolean selectionScriptSpecified = selectionScriptList != null && selectionScriptList.size() > 0;
    boolean nodeMatch = true;
    ScriptException exception = null;
    if (selectionScriptSpecified) {
        // initializing parallel script execution
        for (SelectionScript script : selectionScriptList) {
            if (manager.isPassed(script, criteria.getBindings(), rmnode)) {
                // already executed static script
                logger.debug(rmnode.getNodeURL() + " : " + script.hashCode() + " skipping script execution");
                continue;
            }
            logger.info(rmnode.getNodeURL() + " : " + script.hashCode() + " executing");
            try {
                ScriptResult<Boolean> scriptResult = rmnode.executeScript(script, criteria.getBindings());
                // processing the results
                if (!MOP.isReifiedObject(scriptResult) && scriptResult.getException() != null) {
                    // could not create script execution handler
                    // probably the node id down
                    logger.warn(rmnode.getNodeURL() + " : " + script.hashCode() + " exception", scriptResult.getException());
                    logger.warn(rmnode.getNodeURL() + " : pinging the node");
                    rmnode.getNodeSource().pingNode(rmnode.getNode());
                    nodeMatch = false;
                    break;
                } else {
                    try {
                        PAFuture.waitFor(scriptResult, PAResourceManagerProperties.RM_SELECT_SCRIPT_TIMEOUT.getValueAsLong());
                    } catch (ProActiveTimeoutException e) {
                        logger.warn("Timeout on " + rmnode.getNodeURL());
                        // do not produce an exception here
                        nodeMatch = false;
                        break;
                    }
                    // display the script result and output in the scheduler logs
                    if (scriptResult != null && logger.isInfoEnabled()) {
                        logger.info(rmnode.getNodeURL() + " : " + script.hashCode() + " result " + scriptResult.getResult());
                        if (scriptResult.getOutput() != null && scriptResult.getOutput().length() > 0) {
                            logger.info(rmnode.getNodeURL() + " : " + script.hashCode() + " output\n" + scriptResult.getOutput());
                        }
                    }
                    if (scriptResult != null && scriptResult.errorOccured()) {
                        nodeMatch = false;
                        exception = new ScriptException(scriptResult.getException());
                        logger.warn(rmnode.getNodeURL() + " : exception during the script execution", scriptResult.getException());
                    }
                    // selection manager at the same time. Returns whether node is selected.
                    if (!manager.processScriptResult(script, criteria.getBindings(), scriptResult, rmnode)) {
                        nodeMatch = false;
                        break;
                    }
                }
            } catch (Exception ex) {
                // proactive or network exception occurred when script was executed
                logger.warn(rmnode.getNodeURL() + " : " + script.hashCode() + " exception", ex);
                nodeMatch = false;
                exception = new ScriptException(ex);
                break;
            }
        }
    }
    manager.scriptExecutionFinished(rmnode.getNodeURL());
    if (selectionScriptSpecified && logger.isDebugEnabled()) {
        if (nodeMatch) {
            logger.debug(rmnode.getNodeURL() + " : selected");
        } else {
            logger.debug(rmnode.getNodeURL() + " : not selected");
        }
    }
    // cleaning the node
    try {
        rmnode.clean();
    } catch (Throwable t) {
        logger.warn(rmnode.getNodeURL() + " : exception in cleaning", t);
        logger.warn(rmnode.getNodeURL() + " : pinging the node");
        try {
            // 'pingNode' call can fail with exception if NodeSource was destroyed
            rmnode.getNodeSource().pingNode(rmnode.getNode());
        } catch (Throwable pingError) {
            logger.warn(rmnode.getNodeURL() + " : nodeSource " + rmnode.getNodeSourceName() + " seems to be removed ", pingError);
        }
        return null;
    }
    if (exception != null) {
        throw exception;
    }
    if (nodeMatch) {
        return rmnode.getNode();
    } else {
        return null;
    }
}
Also used : ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) ScriptException(org.ow2.proactive.scripting.ScriptException) SelectionScript(org.ow2.proactive.scripting.SelectionScript) ScriptException(org.ow2.proactive.scripting.ScriptException) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException)

Example 20 with RMNode

use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.

the class SelectionManager method executeScript.

public <T> List<ScriptResult<T>> executeScript(final Script<T> script, final Collection<RMNode> nodes, final Map<String, Serializable> bindings) {
    // TODO: add a specific timeout for script execution
    final long timeout = PAResourceManagerProperties.RM_EXECUTE_SCRIPT_TIMEOUT.getValueAsLong();
    final ArrayList<Callable<ScriptResult<T>>> scriptExecutors = new ArrayList<>(nodes.size());
    // Execute the script on each selected node
    for (final RMNode node : nodes) {
        scriptExecutors.add(new Callable<ScriptResult<T>>() {

            @Override
            public ScriptResult<T> call() throws Exception {
                // treated as ExecutionException
                try {
                    ScriptResult<T> res = node.executeScript(script, bindings);
                    PAFuture.waitFor(res, timeout);
                    return res;
                // return PAFuture.getFutureValue(res, timeout);
                } finally {
                    // cleaning the node
                    try {
                        node.clean();
                    } catch (Throwable ex) {
                        logger.error("Cannot clean the node " + node.getNodeURL(), ex);
                    }
                    SelectionManager.this.rmcore.unlockNodes(Collections.singleton(node.getNodeURL()));
                }
            }

            @Override
            public String toString() {
                return "executing script on " + node.getNodeURL();
            }
        });
    }
    // Invoke all Callables and get the list of futures
    List<Future<ScriptResult<T>>> futures = null;
    try {
        futures = this.scriptExecutorThreadPool.invokeAll(scriptExecutors, timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        logger.warn("Interrupted while waiting, unable to execute all scripts", e);
        Thread.currentThread().interrupt();
    }
    final List<ScriptResult<T>> results = new LinkedList<>();
    int index = 0;
    // waiting for the results
    for (final Future<ScriptResult<T>> future : futures) {
        final String description = scriptExecutors.get(index++).toString();
        ScriptResult<T> result = null;
        try {
            result = future.get();
        } catch (CancellationException e) {
            result = new ScriptResult<>(new ScriptException("Cancelled due to timeout expiration when " + description, e));
        } catch (InterruptedException e) {
            result = new ScriptResult<>(new ScriptException("Cancelled due to interruption when " + description));
        } catch (ExecutionException e) {
            // Unwrap the root exception
            Throwable rex = e.getCause();
            result = new ScriptResult<>(new ScriptException("Exception occured in script call when " + description, rex));
        }
        results.add(result);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ScriptException(org.ow2.proactive.scripting.ScriptException) NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) LinkedList(java.util.LinkedList) ScriptResult(org.ow2.proactive.scripting.ScriptResult) ScriptException(org.ow2.proactive.scripting.ScriptException) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) CancellationException(java.util.concurrent.CancellationException) PAFuture(org.objectweb.proactive.api.PAFuture) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)55 Test (org.junit.Test)27 Node (org.objectweb.proactive.core.node.Node)12 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)12 Client (org.ow2.proactive.resourcemanager.authentication.Client)12 SelectionScript (org.ow2.proactive.scripting.SelectionScript)12 ArrayList (java.util.ArrayList)11 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)11 LinkedList (java.util.LinkedList)10 RMNodeImpl (org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)10 SelectionManager (org.ow2.proactive.resourcemanager.selection.SelectionManager)8 NodeState (org.ow2.proactive.resourcemanager.common.NodeState)7 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)7 Permission (java.security.Permission)6 SelectionManagerTest (org.ow2.proactive.resourcemanager.selection.SelectionManagerTest)6 NodeSet (org.ow2.proactive.utils.NodeSet)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 MutableInteger (org.objectweb.proactive.core.util.MutableInteger)5 PrincipalPermission (org.ow2.proactive.permissions.PrincipalPermission)5