Search in sources :

Example 16 with RMNodeSourceEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent in project scheduling by ow2-proactive.

the class RecoverSSHInfrastructureV2Test method startRmAndCheckInitialState.

private void startRmAndCheckInitialState(boolean restartDownNodesPolicy) throws Exception {
    // start RM
    startRmWithConfig(START_CONFIG);
    assertThat(PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean()).isTrue();
    assertThat(rmHelper.isRMStarted()).isTrue();
    // check the initial state of the RM
    assertThat(resourceManager.getState().getAllNodes().size()).isEqualTo(0);
    resourceManager.createNodeSource(NODE_SOURCE_NAME, SSHInfrastructureV2.class.getName(), TestSSHInfrastructureV2.infraParams, restartDownNodesPolicy ? RestartDownNodesPolicy.class.getName() : StaticPolicy.class.getName(), TestSSHInfrastructureV2.policyParameters, NODES_RECOVERABLE);
    RMTHelper.waitForNodeSourceCreation(NODE_SOURCE_NAME, TestSSHInfrastructureV2.NB_NODES, this.rmHelper.getMonitorsHandler());
    RMMonitorEventReceiver resourceManagerMonitor = (RMMonitorEventReceiver) resourceManager;
    List<RMNodeSourceEvent> nodeSourceEvent = resourceManagerMonitor.getInitialState().getNodeSourceEvents();
    assertThat(nodeSourceEvent.size()).isEqualTo(1);
    assertThat(nodeSourceEvent.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
    assertThat(resourceManagerMonitor.getState().getAllNodes().size()).isEqualTo(TestSSHInfrastructureV2.NB_NODES);
}
Also used : RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) TestSSHInfrastructureV2(functionaltests.nodesource.TestSSHInfrastructureV2) SSHInfrastructureV2(org.ow2.proactive.resourcemanager.nodesource.infrastructure.SSHInfrastructureV2) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver)

Example 17 with RMNodeSourceEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent in project scheduling by ow2-proactive.

the class RecoverSSHInfrastructureV2Test method restartRmAndCheckFinalState.

private void restartRmAndCheckFinalState(int expectedNbAliveNodes, int expectedNbDownNodes) throws Exception {
    // restart RM
    rmHelper = new RMTHelper();
    startRmWithConfig(RESTART_CONFIG);
    assertThat(PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean()).isFalse();
    assertThat(rmHelper.isRMStarted()).isTrue();
    // re-snapshot the RM state
    RMMonitorEventReceiver resourceManagerMonitor = (RMMonitorEventReceiver) resourceManager;
    List<RMNodeSourceEvent> nodeSourceEvent = resourceManagerMonitor.getInitialState().getNodeSourceEvents();
    // the node source has been recovered on restart: we should have one node source with the same name
    assertThat(nodeSourceEvent.size()).isEqualTo(1);
    assertThat(nodeSourceEvent.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
    // the nodes should have been recovered too, and should be alive or down
    Set<String> allNodes = resourceManagerMonitor.getState().getAllNodes();
    assertThat(allNodes.size()).isEqualTo(TestSSHInfrastructureV2.NB_NODES);
    Set<String> nodeSourceNames = new HashSet<>();
    nodeSourceNames.add(NODE_SOURCE_NAME);
    List<RMNodeEvent> nodeEvents = resourceManagerMonitor.getInitialState().getNodeEvents();
    long nbFreeNodes = nodeEvents.stream().filter(nodeEvent -> nodeEvent.getNodeState().equals(NodeState.FREE)).count();
    assertThat(nbFreeNodes).isEqualTo(expectedNbAliveNodes);
    long nbDownNodes = nodeEvents.stream().filter(nodeEvent -> nodeEvent.getNodeState().equals(NodeState.DOWN)).count();
    assertThat(nbDownNodes).isEqualTo(expectedNbDownNodes);
    // the recovered nodes should be usable, try to lock/unlock them to see
    BooleanWrapper lockSucceeded = resourceManager.lockNodes(allNodes);
    assertThat(lockSucceeded).isEqualTo(new BooleanWrapper(true));
    BooleanWrapper unlockSucceeded = resourceManager.unlockNodes(allNodes);
    assertThat(unlockSucceeded).isEqualTo(new BooleanWrapper(true));
}
Also used : RestartDownNodesPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.RestartDownNodesPolicy) TestSSHInfrastructureV2(functionaltests.nodesource.TestSSHInfrastructureV2) SSHInfrastructureV2(org.ow2.proactive.resourcemanager.nodesource.infrastructure.SSHInfrastructureV2) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) Set(java.util.Set) Test(org.junit.Test) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) Truth.assertThat(com.google.common.truth.Truth.assertThat) NodeState(org.ow2.proactive.resourcemanager.common.NodeState) File(java.io.File) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver) HashSet(java.util.HashSet) PAResourceManagerProperties(org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) List(java.util.List) NODES_RECOVERABLE(functionaltests.nodesrecovery.RecoverInfrastructureTestHelper.NODES_RECOVERABLE) RMTHelper(functionaltests.utils.RMTHelper) After(org.junit.After) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) Before(org.junit.Before) RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMTHelper(functionaltests.utils.RMTHelper) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver) HashSet(java.util.HashSet)

Example 18 with RMNodeSourceEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent in project scheduling by ow2-proactive.

the class RecoverDefaultInfrastructureTest method restartRmAndCheckFinalState.

private void restartRmAndCheckFinalState() throws Exception {
    // restart RM
    this.rmHelper = new RMTHelper();
    this.startRmWithConfig(RESTART_CONFIG);
    assertThat(PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean()).isFalse();
    assertThat(this.rmHelper.isRMStarted()).isTrue();
    // re-snapshot the RM state
    RMMonitorEventReceiver resourceManagerMonitor = (RMMonitorEventReceiver) this.resourceManager;
    List<RMNodeSourceEvent> nodeSourceEvent = resourceManagerMonitor.getInitialState().getNodeSourceEvents();
    // the node source has been recovered on restart: we should have one node source with the same name
    assertThat(nodeSourceEvent.size()).isEqualTo(1);
    assertThat(nodeSourceEvent.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
    assertThat(nodeSourceEvent.get(0).getNodeSourceDescription().contains(NODE_SOURCE_USER_ACCESS_TYPE));
}
Also used : RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) RMTHelper(functionaltests.utils.RMTHelper) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver)

Example 19 with RMNodeSourceEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent in project scheduling by ow2-proactive.

the class RecoverLocalInfrastructureTest method restartRmAndCheckFinalState.

private void restartRmAndCheckFinalState() throws Exception {
    // restart RM
    this.rmHelper = new RMTHelper();
    this.startRmWithConfig(RESTART_CONFIG);
    assertThat(PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean()).isFalse();
    assertThat(this.rmHelper.isRMStarted()).isTrue();
    // re-snapshot the RM state
    RMMonitorEventReceiver resourceManagerMonitor = (RMMonitorEventReceiver) this.resourceManager;
    List<RMNodeSourceEvent> nodeSourceEvent = resourceManagerMonitor.getInitialState().getNodeSourceEvents();
    // the node source has been recovered on restart: we should have one node source with the same name
    assertThat(nodeSourceEvent.size()).isEqualTo(1);
    assertThat(nodeSourceEvent.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
    assertThat(nodeSourceEvent.get(0).getNodeSourceDescription().contains(NODE_SOURCE_USER_ACCESS_TYPE));
}
Also used : RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) RMTHelper(functionaltests.utils.RMTHelper) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver)

Example 20 with RMNodeSourceEvent

use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent 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(), new RMCoreAllPermission(), new NodeUserAllPermission(), new NSAdminPermission());
                    if (rmnode.isToRemove()) {
                        removeNodeFromCoreAndSource(rmnode, caller);
                        nodesReleased.add(node);
                        if (delayedNodeSourceRemovalEvents.containsKey(rmnode.getNodeSourceName()) && nodeSourceCanBeRemoved(rmnode.getNodeSourceName())) {
                            logger.debug(NODE_SOURCE_STRING + rmnode.getNodeSourceName() + " is eligible to remove.");
                            final Entry<RMNodeSourceEvent, NodeSource> remove = delayedNodeSourceRemovalEvents.remove(rmnode.getNodeSourceName());
                            final RMNodeSourceEvent removedEvent = remove.getKey();
                            final NodeSource nodeSource = remove.getValue();
                            logger.info(NODE_SOURCE_STRING + rmnode.getNodeSourceName() + HAS_BEEN_SUCCESSFULLY + removedEvent.getEventType().getDescription());
                            this.monitoring.nodeSourceEvent(removedEvent);
                            nodeSource.shutdown(this.caller);
                        } else if (delayedNodeSourceUndeploying.containsKey(rmnode.getNodeSourceName()) && nodeSourceCanBeRemoved(rmnode.getNodeSourceName())) {
                            logger.debug(NODE_SOURCE_STRING + rmnode.getNodeSourceName() + " is eligible to undeploy.");
                            final NodeSource nodeSource = delayedNodeSourceUndeploying.remove(rmnode.getNodeSourceName());
                            logger.info(NODE_SOURCE_STRING + rmnode.getNodeSourceName() + HAS_BEEN_SUCCESSFULLY + "undeployed.");
                            nodeSource.shutdown(this.caller);
                        }
                    } 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) RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) 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) NodeUserAllPermission(org.ow2.proactive.permissions.NodeUserAllPermission) UserNamePrincipal(org.ow2.proactive.authentication.principals.UserNamePrincipal) RMCoreAllPermission(org.ow2.proactive.permissions.RMCoreAllPermission) NSAdminPermission(org.ow2.proactive.permissions.NSAdminPermission) NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Entry(java.util.Map.Entry) Permission(java.security.Permission) NSAdminPermission(org.ow2.proactive.permissions.NSAdminPermission) NodeUserAllPermission(org.ow2.proactive.permissions.NodeUserAllPermission) MethodCallPermission(org.ow2.proactive.permissions.MethodCallPermission) RMCoreAllPermission(org.ow2.proactive.permissions.RMCoreAllPermission) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) IdentityPrincipal(org.ow2.proactive.authentication.principals.IdentityPrincipal)

Aggregations

RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)24 RMMonitorEventReceiver (functionaltests.monitor.RMMonitorEventReceiver)14 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)8 RMTHelper (functionaltests.utils.RMTHelper)6 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)6 HashSet (java.util.HashSet)5 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)5 TestSSHInfrastructureV2 (functionaltests.nodesource.TestSSHInfrastructureV2)3 Set (java.util.Set)3 NSAdminPermission (org.ow2.proactive.permissions.NSAdminPermission)3 RMCoreAllPermission (org.ow2.proactive.permissions.RMCoreAllPermission)3 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)3 SSHInfrastructureV2 (org.ow2.proactive.resourcemanager.nodesource.infrastructure.SSHInfrastructureV2)3 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 File (java.io.File)2 Permission (java.security.Permission)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Node (org.objectweb.proactive.core.node.Node)2