Search in sources :

Example 21 with Criteria

use of org.ow2.proactive.utils.Criteria 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 22 with Criteria

use of org.ow2.proactive.utils.Criteria 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 23 with Criteria

use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.

the class TestLocalInfrastructureRestartDownNodesPolicy method testRestartDownNodesPolicy.

@Test
public void testRestartDownNodesPolicy() throws Exception {
    nodeSourceName = "Node_source_1";
    RMTHelper.log("Test 1 - restart down nodes policy");
    createNodeSourceWithNodes(nodeSourceName, new Object[] { "ALL", "ALL", "10000" });
    RMState stateTest1 = resourceManager.getState();
    assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalNodesNumber());
    assertEquals(defaultDescriptorNodesNb, stateTest1.getFreeNodesNumber());
    NodeSet ns = resourceManager.getNodes(new Criteria(defaultDescriptorNodesNb));
    for (Node n : ns) {
        rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
    }
    String nodeUrl = ns.get(0).getNodeInformation().getURL();
    // Nodes will be redeployed only if we kill the whole runtime
    rmHelper.killRuntime(nodeUrl);
    RMNodeEvent ev = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeUrl);
    assertEquals(NodeState.DOWN, ev.getNodeState());
    // one node is down - the policy should detect it and redeploy
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
    rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalNodesNumber());
    assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalAliveNodesNumber());
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Node(org.objectweb.proactive.core.node.Node) Criteria(org.ow2.proactive.utils.Criteria) RMState(org.ow2.proactive.resourcemanager.common.RMState) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 24 with Criteria

use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.

the class GetAllNodes method main.

public static void main(String[] args) {
    RMAuthentication auth;
    try {
        auth = RMConnection.join(RMTHelper.getLocalUrl());
        Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
        ResourceManager rm = auth.login(cred);
        NodeSet nodes = rm.getNodes(new Criteria(rm.getState().getFreeNodesNumber()));
        // use nodes to block until the future is available
        System.out.println("Got " + nodes.size());
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.exit(1);
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) CredData(org.ow2.proactive.authentication.crypto.CredData) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Criteria(org.ow2.proactive.utils.Criteria) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 25 with Criteria

use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.

the class RMCore method getNodes.

/**
 * {@inheritDoc}
 */
public NodeSet getNodes(int number, TopologyDescriptor topology, List<SelectionScript> selectionScrips, NodeSet exclusion, boolean bestEffort) {
    Criteria criteria = new Criteria(number);
    criteria.setTopology(topology);
    criteria.setScripts(selectionScrips);
    criteria.setBlackList(exclusion);
    criteria.setBestEffort(bestEffort);
    return getNodes(criteria);
}
Also used : Criteria(org.ow2.proactive.utils.Criteria)

Aggregations

Criteria (org.ow2.proactive.utils.Criteria)25 NodeSet (org.ow2.proactive.utils.NodeSet)23 Test (org.junit.Test)16 Node (org.objectweb.proactive.core.node.Node)9 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)7 ArrayList (java.util.ArrayList)7 RMCore (org.ow2.proactive.resourcemanager.core.RMCore)6 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)6 CredData (org.ow2.proactive.authentication.crypto.CredData)5 Credentials (org.ow2.proactive.authentication.crypto.Credentials)5 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)5 Client (org.ow2.proactive.resourcemanager.authentication.Client)4 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)4 LinkedList (java.util.LinkedList)3 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)3 RMState (org.ow2.proactive.resourcemanager.common.RMState)3 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)3 PublicKey (java.security.PublicKey)2 HashMap (java.util.HashMap)2 List (java.util.List)2