Search in sources :

Example 46 with Node

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

the class SelectionManager method runScripts.

/**
 * Runs scripts on given set of nodes and returns matched nodes. It blocks
 * until all results are obtained.
 *
 * @param candidates
 *            nodes to execute scripts on
 * @param criteria
 *            contains a set of scripts to execute on each node
 * @return nodes matched to all scripts
 */
private List<Node> runScripts(List<RMNode> candidates, Criteria criteria) {
    List<Node> matched = new LinkedList<>();
    if (candidates.size() == 0) {
        return matched;
    }
    // creating script executors object to be run in dedicated thread pool
    List<Callable<Node>> scriptExecutors = new LinkedList<>();
    synchronized (inProgress) {
        if (inProgress.size() > 0) {
            logger.warn(inProgress.size() + " nodes are in process of script execution");
            for (String nodeName : inProgress) {
                logger.warn(nodeName);
            }
            logger.warn("Something is wrong on these nodes");
        }
        for (RMNode node : candidates) {
            if (!inProgress.contains(node.getNodeURL())) {
                inProgress.add(node.getNodeURL());
                scriptExecutors.add(new ScriptExecutor(node, criteria, this));
            }
        }
    }
    try {
        // launching
        Collection<Future<Node>> matchedNodes = scriptExecutorThreadPool.invokeAll(scriptExecutors);
        // waiting for the results
        for (Future<Node> futureNode : matchedNodes) {
            Node node;
            try {
                node = futureNode.get();
                if (node != null) {
                    matched.add(node);
                }
            } catch (InterruptedException e) {
                logger.warn("Interrupting the selection manager");
                return matched;
            } catch (ExecutionException e) {
                logger.warn("Ignoring exception in selection script: " + e.getMessage());
            }
        }
    } catch (InterruptedException e1) {
        logger.warn("Interrupting the selection manager");
    }
    return matched;
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Node(org.objectweb.proactive.core.node.Node) LinkedList(java.util.LinkedList) Callable(java.util.concurrent.Callable) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) PAFuture(org.objectweb.proactive.api.PAFuture) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Example 47 with Node

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

the class TopologyManager method addNode.

/**
 * Updates the topology for new node. Executes the pinger on new node when this node belongs
 * to unknow host.
 */
public void addNode(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("Adding Node " + node.getNodeInformation().getURL() + " to topology");
        }
        InetAddress host = node.getVMInformation().getInetAddress();
        if (topology.knownHost(host)) {
            // host topology is already known
            if (logger.isDebugEnabled()) {
                logger.debug("The topology information has been already added for node " + node.getNodeInformation().getURL());
            }
            nodesOnHost.get(host).add(node);
            return;
        }
        // unknown host => start pinging process
        NodeSet toPing = new NodeSet();
        HashMap<InetAddress, Long> hostsTopology = new HashMap<>();
        // adding one node from each host
        for (InetAddress h : nodesOnHost.keySet()) {
            // always have at least one node on each host
            if (nodesOnHost.get(h) != null && !nodesOnHost.get(h).isEmpty()) {
                toPing.add(nodesOnHost.get(h).iterator().next());
                hostsTopology.put(h, Long.MAX_VALUE);
            }
        }
        if (PAResourceManagerProperties.RM_TOPOLOGY_DISTANCE_ENABLED.getValueAsBoolean()) {
            hostsTopology = pingNode(node, toPing);
        }
        topology.addHostTopology(node.getVMInformation().getHostName(), host, hostsTopology);
        Set<Node> nodesList = new LinkedHashSet<>();
        nodesList.add(node);
        nodesOnHost.put(node.getVMInformation().getInetAddress(), nodesList);
    } finally {
        rwLock.writeLock().unlock();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Node " + node.getNodeInformation().getURL() + " added.");
    }
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Node(org.objectweb.proactive.core.node.Node) InetAddress(java.net.InetAddress)

Example 48 with Node

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

the class TopologyManager method subListLHS.

private Set<Node> subListLHS(Set<Node> nodes, int begin, int end) {
    Set<Node> result = new LinkedHashSet<>();
    if (begin > end) {
        throw new IllegalArgumentException("First index must be smaller.");
    }
    int i = 0;
    for (Node n : nodes) {
        if ((i >= begin) && (i < end)) {
            result.add(n);
        }
        i++;
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Node(org.objectweb.proactive.core.node.Node)

Example 49 with Node

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

the class AddGetDownRemoveTest method action.

@Test
public void action() throws Exception {
    // The username and thr password must be the same a used to connect to the RM
    final ResourceManager rm = rmHelper.getResourceManager();
    // All accounting values are checked through JMX
    final RMAuthentication auth = rmHelper.getRMAuth();
    final PublicKey pubKey = auth.getPublicKey();
    final Credentials adminCreds = Credentials.createCredentials(new CredData(TestUsers.TEST.username, TestUsers.TEST.password), pubKey);
    final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
    final HashMap<String, Object> env = new HashMap<>(1);
    env.put(JMXConnector.CREDENTIALS, new Object[] { TestUsers.TEST.username, 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();
    long usedNodeTime = (Long) conn.getAttribute(myAccountMBeanName, "UsedNodeTime");
    // ADD, GET, DOWN, REMOVE
    // 1) ADD
    final String name = "AddGetDownRemoveTest";
    testNode = rmHelper.createNode(name);
    Node node = testNode.getNode();
    final String nodeURL = node.getNodeInformation().getURL();
    rm.addNode(nodeURL).getBooleanValue();
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, NodeSource.DEFAULT);
    rm.setNodeSourcePingFrequency(5000, NodeSource.DEFAULT);
    // wait for node from configuring to free
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeURL);
    rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
    // 2) GET the same node
    final long beforeGetTime = System.currentTimeMillis();
    node = rm.getNodes(new Criteria(1)).get(0);
    // Sleep a certain amount of time that will be the minimum amount of the GET->RELEASE duration
    Thread.sleep(GR_DURATION);
    // 3) Kill the node to ensure that the RM considers it as being DOWN
    try {
        node.getProActiveRuntime().killNode(node.getNodeInformation().getName());
    } catch (Exception e) {
    }
    while (rm.nodeIsAvailable(nodeURL).getBooleanValue()) {
        RMTHelper.log("Node is available " + nodeURL);
        Thread.sleep(100);
    }
    final long getDownMaxDuration = System.currentTimeMillis() - beforeGetTime;
    // 4) REMOVE
    rm.removeNode(nodeURL, true).getBooleanValue();
    // Refresh the account manager
    conn.invoke(managementMBeanName, "clearAccoutingCache", null, null);
    // Check account values validity
    usedNodeTime = (Long) conn.getAttribute(myAccountMBeanName, "UsedNodeTime") - usedNodeTime;
    Assert.assertTrue("Invalid value of the usedNodeTime attribute : " + usedNodeTime + " while expected is " + GR_DURATION, (usedNodeTime >= GR_DURATION) && (usedNodeTime <= getDownMaxDuration));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) PublicKey(java.security.PublicKey) Node(org.objectweb.proactive.core.node.Node) CredData(org.ow2.proactive.authentication.crypto.CredData) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Criteria(org.ow2.proactive.utils.Criteria) 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)

Example 50 with Node

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

the class AddGetTest method action.

/**
 * Test function.
 * @throws Exception
 */
@org.junit.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 = (RMAuthentication) 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();
    // Tests on database
    // (nodeprovider=demo)
    // 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();
    Assert.assertEquals("The accounts must not be refreshed automatically therefore the LastRefreshDurationInMilliseconds must be 0", (Long) 0l, (Long) conn.getAttribute(managementMBeanName, "LastRefreshDurationInMilliseconds"));
    Assert.assertTrue("The usedNodeTime attribute must be 0", usedNodeTime == 0);
    Assert.assertTrue("The providedNodeTime attribute must be 0", providedNodeTime == 0);
    Assert.assertTrue("The providedNodesCount attribute must be 0", providedNodesCount == 0);
    // ADD, GET
    // 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
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // 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 duration
    Thread.sleep(GR_DURATION);
    // Refresh the account manager
    conn.invoke(managementMBeanName, "clearAccoutingCache", null, null);
    final long currentTime = System.currentTimeMillis();
    final long addRefreshMaxDuration = currentTime - beforeAddTime;
    final long getRefreshMaxDuration = currentTime - beforeGetTime;
    // Check account values validity
    atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
    usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue();
    providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue();
    providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue();
    Assert.assertTrue("Invalid value of the usedNodeTime attribute", (usedNodeTime >= GR_DURATION) && (usedNodeTime <= addRefreshMaxDuration));
    Assert.assertTrue("Invalid value of the providedNodeTime attribute", (providedNodeTime >= usedNodeTime) && (providedNodeTime <= getRefreshMaxDuration));
    Assert.assertTrue("Invalid value of the providedNodesCount attribute", (providedNodesCount == 1));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) Attribute(javax.management.Attribute) 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)

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