Search in sources :

Example 26 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class RMCore method internalSetFree.

/**
 * Change the state of the node to free, after a Task has been completed by the specified node.
 * The node passed as parameter is moved to the list of nodes which are eligible for scheduling if it is not locked.
 * In all cases, an event informing the node state's change is propagated to RMMonitoring.
 *
 * @param rmNode node to set free.
 * @return true if the node successfully set as free, false if it was down before.
 */
@VisibleForTesting
BooleanWrapper internalSetFree(final RMNode rmNode) {
    if (logger.isDebugEnabled()) {
        logger.debug("Current node state " + rmNode.getState() + " " + rmNode.getNodeURL());
        logger.debug("Setting node state to free " + rmNode.getNodeURL());
    }
    // If the node is already free no need to go further
    if (rmNode.isFree()) {
        return new BooleanWrapper(true);
    }
    // Get the previous state of the node needed for the event
    final NodeState previousNodeState = rmNode.getState();
    Client client = rmNode.getOwner();
    if (client == null) {
        // node has been just configured, so the user initiated this action is the node provider
        client = rmNode.getProvider();
    }
    // resetting owner here
    rmNode.setFree();
    // an eligible node is a node that is free and not locked
    if (!rmNode.isLocked()) {
        this.eligibleNodes.add(rmNode);
    }
    persistUpdatedRMNodeIfRecoveryEnabled(rmNode);
    this.registerAndEmitNodeEvent(rmNode.createNodeEvent(RMEventType.NODE_STATE_CHANGED, previousNodeState, client.getName()));
    return new BooleanWrapper(true);
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) NodeState(org.ow2.proactive.resourcemanager.common.NodeState) Client(org.ow2.proactive.resourcemanager.authentication.Client) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 27 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class RMCore method releaseNodes.

/**
 * {@inheritDoc}
 */
public BooleanWrapper releaseNodes(NodeSet nodes) {
    if (nodes.getExtraNodes() != null) {
        // do not forget to release extra nodes
        nodes.addAll(nodes.getExtraNodes());
    }
    // exception to throw in case of problems
    RuntimeException exception = null;
    NodeSet nodesReleased = new NodeSet();
    NodeSet nodesFailedToRelease = new NodeSet();
    for (Node node : nodes) {
        String nodeURL = null;
        try {
            nodeURL = node.getNodeInformation().getURL();
            logger.debug("Releasing node " + nodeURL);
        } catch (RuntimeException e) {
            logger.debug("A Runtime exception occurred while obtaining information on the node," + "the node must be down (it will be detected later)", e);
            // node is down, will be detected by pinger
            exception = new IllegalStateException(e.getMessage(), e);
            nodesFailedToRelease.add(node);
        }
        // verify whether the node has not been removed from the RM
        if (this.allNodes.containsKey(nodeURL)) {
            RMNode rmnode = this.getNodebyUrl(nodeURL);
            // free
            if (rmnode.isFree()) {
                logger.warn("Client " + caller + " tries to release the already free node " + nodeURL);
                nodesFailedToRelease.add(node);
            } else if (rmnode.isDown()) {
                logger.warn("Node was down, it cannot be released");
                nodesFailedToRelease.add(node);
            } else {
                Set<? extends IdentityPrincipal> userPrincipal = rmnode.getOwner().getSubject().getPrincipals(UserNamePrincipal.class);
                Permission ownerPermission = new PrincipalPermission(rmnode.getOwner().getName(), userPrincipal);
                try {
                    caller.checkPermission(ownerPermission, caller + " is not authorized to free node " + node.getNodeInformation().getURL());
                    if (rmnode.isToRemove()) {
                        removeNodeFromCoreAndSource(rmnode, caller);
                        nodesReleased.add(node);
                    } else {
                        internalSetFree(rmnode);
                        nodesReleased.add(node);
                    }
                } catch (SecurityException ex) {
                    logger.error(ex.getMessage(), ex);
                    nodesFailedToRelease.add(node);
                    exception = ex;
                }
            }
        } else {
            logger.warn("Cannot release unknown node " + nodeURL);
            nodesFailedToRelease.add(node);
            exception = new IllegalArgumentException("Cannot release unknown node " + nodeURL);
        }
    }
    logger.info("Nodes released : " + nodesReleased);
    if (!nodesFailedToRelease.isEmpty()) {
        logger.warn("Nodes failed to release : " + nodesFailedToRelease);
    }
    if (exception != null) {
        // throwing the latest exception we had
        throw exception;
    }
    return new BooleanWrapper(true);
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) NodeSet(org.ow2.proactive.utils.NodeSet) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) RMDeployingNode(org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode) Node(org.objectweb.proactive.core.node.Node) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) UserNamePrincipal(org.ow2.proactive.authentication.principals.UserNamePrincipal) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Permission(java.security.Permission) MethodCallPermission(org.ow2.proactive.permissions.MethodCallPermission) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) IdentityPrincipal(org.ow2.proactive.authentication.principals.IdentityPrincipal)

Example 28 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class RMCore method undeployNodeSource.

/**
 * {@inheritDoc}
 */
public BooleanWrapper undeployNodeSource(String nodeSourceName, boolean preempt) {
    if (!this.definedNodeSources.containsKey(nodeSourceName)) {
        throw new IllegalArgumentException("Unknown node source " + nodeSourceName);
    }
    if (this.deployedNodeSources.containsKey(nodeSourceName)) {
        NodeSource nodeSourceToRemove = this.deployedNodeSources.get(nodeSourceName);
        this.caller.checkPermission(nodeSourceToRemove.getAdminPermission(), this.caller + " is not authorized to remove " + nodeSourceName);
        logger.info("Undeploy node source " + nodeSourceName + " with preempt=" + preempt + REQUESTED_BY_STRING + this.caller.getName());
        nodeSourceToRemove.setStatus(NodeSourceStatus.NODES_UNDEPLOYED);
        this.removeAllNodes(nodeSourceName, preempt);
        // delegate the removal process to the node source that will
        // eventually call back the RMCore to unregister the deployed node
        // source
        nodeSourceToRemove.shutdown(this.caller);
        this.updateNodeSourceDescriptorWithStatusAndPersist(this.definedNodeSources.get(nodeSourceName).getDescriptor(), NodeSourceStatus.NODES_UNDEPLOYED);
        logger.info(NODE_SOURCE_STRING + nodeSourceName + " has been successfully undeployed");
    }
    return new BooleanWrapper(true);
}
Also used : NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper)

Example 29 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class RMCore method shutdown.

/**
 * Shutdown the resource manager
 */
public BooleanWrapper shutdown(boolean preempt) {
    // this method could be called twice from shutdown hook and user action
    if (toShutDown)
        return new BooleanWrapper(false);
    logger.info("RMCore shutdown request");
    this.monitoring.rmEvent(new RMEvent(RMEventType.SHUTTING_DOWN));
    this.toShutDown = true;
    if (PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean() || this.deployedNodeSources.size() == 0) {
        finalizeShutdown();
    } else {
        for (Entry<String, NodeSource> entry : this.deployedNodeSources.entrySet()) {
            removeAllNodes(entry.getKey(), preempt, true);
            entry.getValue().shutdown(caller);
        }
    }
    return new BooleanWrapper(true);
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) RMEvent(org.ow2.proactive.resourcemanager.common.event.RMEvent)

Example 30 with BooleanWrapper

use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.

the class RMCore method setFreeNodes.

/**
 * Mark nodes as free after cleaning procedure.
 *
 * @param nodes to be free
 * @return true if all successful, false if there is a down node among nodes
 */
public BooleanWrapper setFreeNodes(List<RMNode> nodes) {
    boolean result = true;
    for (RMNode node : nodes) {
        // getting the correct instance
        RMNode rmnode = this.getNodebyUrl(node.getNodeURL());
        // freeing it
        result &= internalSetFree(rmnode).getBooleanValue();
    }
    return new BooleanWrapper(result);
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode)

Aggregations

BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)36 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)10 Test (org.junit.Test)9 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)7 Matchers.anyString (org.mockito.Matchers.anyString)5 Node (org.objectweb.proactive.core.node.Node)5 HashSet (java.util.HashSet)4 Client (org.ow2.proactive.resourcemanager.authentication.Client)4 RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)4 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)4 NodeSet (org.ow2.proactive.utils.NodeSet)4 RMMonitorEventReceiver (functionaltests.monitor.RMMonitorEventReceiver)3 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)3 RMProxyUserInterface (org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)3 RMTHelper (functionaltests.utils.RMTHelper)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 HttpResponse (org.apache.http.HttpResponse)2 ProActiveTimeoutException (org.objectweb.proactive.core.ProActiveTimeoutException)2 RMNodeImpl (org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)2