Search in sources :

Example 16 with Node

use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.

the class RestartDownNodesPolicy method activate.

/**
 * Activates static policy. Register a listener in RMMonitoring
 */
@Override
public BooleanWrapper activate() {
    acquireAllNodes();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            int numberOfNodesToDeploy = 0;
            for (Node downNode : nodeSource.getDownNodes()) {
                String nodeUrl = downNode.getNodeInformation().getURL();
                logger.info("Removing down node " + nodeUrl);
                BooleanWrapper removed = nodeSource.getRMCore().removeNode(nodeUrl, true);
                if (removed.getBooleanValue()) {
                    logger.info("Down node removed " + nodeUrl);
                    numberOfNodesToDeploy++;
                }
            }
            for (RMDeployingNode lostNode : nodeSource.getDeployingAndLostNodes()) {
                if (!lostNode.isLost()) {
                    continue;
                }
                String nodeUrl = lostNode.getNodeURL();
                logger.info("Removing lost node " + nodeUrl);
                BooleanWrapper removed = nodeSource.getRMCore().removeNode(nodeUrl, true);
                if (removed.getBooleanValue()) {
                    logger.info("Lost node removed " + nodeUrl);
                    numberOfNodesToDeploy++;
                }
            }
            if (numberOfNodesToDeploy > 0) {
                logger.info("Acquiring " + numberOfNodesToDeploy + " nodes");
                acquireNodes(numberOfNodesToDeploy);
            }
        }
    }, checkNodeStateEach, checkNodeStateEach);
    return new BooleanWrapper(true);
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) TimerTask(java.util.TimerTask) RMDeployingNode(org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode) Node(org.objectweb.proactive.core.node.Node) RMDeployingNode(org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)

Example 17 with Node

use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.

the class TopologyManager method getNodeSetWithExtraNodes.

private NodeSet getNodeSetWithExtraNodes(Set<Node> nodes, int numberOfNodesToExtract) {
    Set<Node> main = subListLHS(nodes, 0, numberOfNodesToExtract);
    Set<Node> extra = subListLHS(nodes, numberOfNodesToExtract, nodes.size());
    NodeSet result = new NodeSet(main);
    result.setExtraNodes(extra);
    return result;
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Node(org.objectweb.proactive.core.node.Node)

Example 18 with Node

use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.

the class TopologyManager method removeNode.

/**
 * Node is removed or down. Method removes corresponding topology information.
 */
public void removeNode(Node node) {
    try {
        rwLock.writeLock().lock();
        if (!PAResourceManagerProperties.RM_TOPOLOGY_ENABLED.getValueAsBoolean()) {
            // do not do anything if topology disabled
            return;
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Removing Node " + node.getNodeInformation().getURL() + " from topology");
        }
        InetAddress host = node.getVMInformation().getInetAddress();
        if (!topology.knownHost(host)) {
            logger.warn("Topology info does not exist for node " + node.getNodeInformation().getURL());
        } else {
            Set<Node> nodes = nodesOnHost.get(host);
            nodes.remove(node);
            if (nodes.isEmpty()) {
                // no more nodes on the host
                topology.removeHostTopology(node.getVMInformation().getHostName(), host);
                nodesOnHost.remove(host);
            }
        }
    } finally {
        rwLock.writeLock().unlock();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Node " + node.getNodeInformation().getURL() + " removed.");
    }
}
Also used : Node(org.objectweb.proactive.core.node.Node) InetAddress(java.net.InetAddress)

Example 19 with Node

use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.

the class ResourceManagerJMXTest method jmxRMIAsUser.

private void jmxRMIAsUser(JMXServiceURL jmxRmiServiceURL, ObjectName allAccountsMBeanName, ObjectName myAccountMBeanName, ObjectName runtimeDataMBeanName) throws Exception {
    // Tests as user over RMI
    RMTHelper.log("Test as user 1 - Auth with login/pass over RMI and check connection");
    // Create the environment
    final HashMap<String, Object> env = new HashMap<>(1);
    env.put(JMXConnector.CREDENTIALS, new Object[] { TestUsers.DEMO.username, TestUsers.DEMO.password });
    // Connect to the JMX RMI Connector Server
    final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
    final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
    // Check that the MBean Server connection is not null
    assertNotNull("Unable to obtain the MBean server connection over RMI", conn);
    RMTHelper.log("Test as user 2 - Check MyAccountMBean is registered in the MBean server");
    assertTrue("MyAccountMBean must be registered in the MBean server", conn.isRegistered(myAccountMBeanName));
    RMTHelper.log("Test as user 3 - Check MyAccountMBean attributes do not throw exceptions");
    final MBeanInfo info = conn.getMBeanInfo(myAccountMBeanName);
    for (final MBeanAttributeInfo att : info.getAttributes()) {
        final String attName = att.getName();
        try {
            conn.getAttribute(myAccountMBeanName, attName);
        } catch (Exception e) {
            fail("The attribute " + attName + " of MyAccountMBean must not throw " + e);
        }
    }
    RMTHelper.log("Test as user 3 - Check RuntimeDataMBean is registered in the MBean server");
    assertTrue("RuntimeDataMBean must be registered in the MBean server", conn.isRegistered(runtimeDataMBeanName));
    RMTHelper.log("Test as user 4 - Check RuntimeDataMBean attributes are correct");
    // Start a new node and add it to the rmHelper
    testNode = rmHelper.createNode("test");
    final Node node = testNode.getNode();
    final String nodeURL = node.getNodeInformation().getURL();
    // force sync, now the node is in configuring state
    rmHelper.getResourceManager().addNode(nodeURL).getBooleanValue();
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    // We eat configuring to free events
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // Get all attributes to test
    AttributeList list = conn.getAttributes(runtimeDataMBeanName, new String[] { "Status", "AvailableNodesCount", "FreeNodesCount" });
    // Check RMStatus
    Attribute attribute = (Attribute) list.get(0);
    assertEquals("Incorrect value of " + attribute.getName() + " attribute", "STARTED", attribute.getValue());
    // Check AvailableNodesCount
    attribute = (Attribute) list.get(1);
    assertEquals("Incorrect value of " + attribute.getName() + " attribute", 1, attribute.getValue());
    // Check FreeNodesCount
    attribute = (Attribute) list.get(2);
    assertEquals("Incorrect value of " + attribute.getName() + " attribute", 1, attribute.getValue());
    rmHelper.getResourceManager().removeNode(nodeURL, false);
    rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, nodeURL);
    // Get all attributes to test
    list = conn.getAttributes(runtimeDataMBeanName, new String[] { "AvailableNodesCount", "FreeNodesCount" });
    // Check AvailableNodesCount
    attribute = (Attribute) list.get(0);
    assertEquals("Incorrect value of " + attribute.getName() + " attribute", 0, attribute.getValue());
    // Check FreeNodesCount
    attribute = (Attribute) list.get(1);
    assertEquals("Incorrect value of " + attribute.getName() + " attribute", 0, attribute.getValue());
    RMTHelper.log("Test as user 5 - Check AllAccountsMBean attributes are not accessible");
    final MBeanInfo mBeanInfo = conn.getMBeanInfo(allAccountsMBeanName);
    for (final MBeanAttributeInfo att : mBeanInfo.getAttributes()) {
        final String attName = att.getName();
        try {
            conn.getAttribute(allAccountsMBeanName, attName);
        } catch (Exception e) {
            assertTrue("The attribute " + attName + " must not be accessible with user-level permissions", e instanceof RuntimeException);
        }
    }
    jmxConnector.close();
}
Also used : HashMap(java.util.HashMap) Node(org.objectweb.proactive.core.node.Node) IOException(java.io.IOException) JMXConnector(javax.management.remote.JMXConnector)

Example 20 with Node

use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.

the class AddGetReleaseRemoveTest method action.

@Test
public void action() throws Exception {
    final ResourceManager rm = rmHelper.getResourceManager();
    // The username and thr password must be the same a used to connect to the RM
    final String adminLogin = TestUsers.TEST.username;
    final String adminPassword = TestUsers.TEST.password;
    // All accounting values are checked through JMX
    final RMAuthentication auth = rmHelper.getRMAuth();
    final PublicKey pubKey = auth.getPublicKey();
    final Credentials adminCreds = Credentials.createCredentials(new CredData(adminLogin, adminPassword), pubKey);
    final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
    final HashMap<String, Object> env = new HashMap<>(1);
    env.put(JMXConnector.CREDENTIALS, new Object[] { adminLogin, adminCreds });
    // Connect to the JMX RMI Connector Server
    final ObjectName myAccountMBeanName = new ObjectName(RMJMXBeans.MYACCOUNT_MBEAN_NAME);
    final ObjectName managementMBeanName = new ObjectName(RMJMXBeans.MANAGEMENT_MBEAN_NAME);
    final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
    final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
    // Ensure that no refreshes was done and all account values are correctly initialized
    AttributeList atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
    long usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue();
    long providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue();
    int providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue();
    // ADD, GET, RELEASE, REMOVE
    // 1) ADD
    final long beforeAddTime = System.currentTimeMillis();
    testNode = rmHelper.createNode("test");
    Node node = testNode.getNode();
    final String nodeURL = node.getNodeInformation().getURL();
    rm.addNode(nodeURL).getBooleanValue();
    // We eat the configuring to free event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeURL);
    rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
    // 2) GET
    final long beforeGetTime = System.currentTimeMillis();
    node = rm.getAtMostNodes(1, null).get(0);
    // Sleep a certain amount of time that will be the minimum amount of the GET->RELEASE duration
    Thread.sleep(GR_DURATION);
    // 3) RELEASE
    rm.releaseNode(node).getBooleanValue();
    final long getReleaseMaxDuration = System.currentTimeMillis() - beforeGetTime;
    // 4) REMOVE
    rm.removeNode(nodeURL, true).getBooleanValue();
    final long addRemoveMaxDuration = System.currentTimeMillis() - beforeAddTime;
    // Refresh the account manager
    conn.invoke(managementMBeanName, "clearAccoutingCache", null, null);
    // Check account values validity
    atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
    usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue() - usedNodeTime;
    providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue() - providedNodeTime;
    providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue() - providedNodesCount;
    Assert.assertTrue("Invalid value of the usedNodeTime attribute (usedNodeTime=" + usedNodeTime + ")", (usedNodeTime >= GR_DURATION));
    Assert.assertTrue("Invalid value of the usedNodeTime attribute (getReleaseMaxDuration=" + getReleaseMaxDuration + ")", (usedNodeTime <= getReleaseMaxDuration));
    Assert.assertTrue("Invalid value of the providedNodeTime attribute", (providedNodeTime >= usedNodeTime) && (providedNodeTime <= addRemoveMaxDuration));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) PublicKey(java.security.PublicKey) AttributeList(javax.management.AttributeList) Node(org.objectweb.proactive.core.node.Node) CredData(org.ow2.proactive.authentication.crypto.CredData) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) ObjectName(javax.management.ObjectName) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) JMXConnector(javax.management.remote.JMXConnector) Credentials(org.ow2.proactive.authentication.crypto.Credentials) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Aggregations

Node (org.objectweb.proactive.core.node.Node)80 Test (org.junit.Test)28 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)21 NodeSet (org.ow2.proactive.utils.NodeSet)19 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)18 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)16 HashMap (java.util.HashMap)15 TestNode (functionaltests.utils.TestNode)11 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)11 NodeException (org.objectweb.proactive.core.node.NodeException)9 DefaultInfrastructureManager (org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager)9 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)9 Criteria (org.ow2.proactive.utils.Criteria)8 IOException (java.io.IOException)7 LinkedList (java.util.LinkedList)7 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)7 RMException (org.ow2.proactive.resourcemanager.exception.RMException)7 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)6 InetAddress (java.net.InetAddress)5 ArrayList (java.util.ArrayList)5