Search in sources :

Example 26 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager 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 27 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager 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)

Example 28 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class TestRMMonitoring method action.

@Test
public void action() throws Exception {
    log("Deployment");
    RMMonitorEventReceiver resourceManager = (RMMonitorEventReceiver) rmHelper.getResourceManager();
    rmHelper.createNodeSource("TestRMMonitoring");
    Set<String> nodesUrls = rmHelper.listAliveNodesUrls();
    // we received all event as we are here
    log("Test 1 - subscribing only to 'node remove' event");
    resourceManager.removeRMEventListener();
    resourceManager.addRMEventListener(rmHelper.getEventReceiver(), RMEventType.NODE_REMOVED);
    String url = nodesUrls.iterator().next();
    BooleanWrapper status = resourceManager.removeNode(url, true);
    if (status.getBooleanValue()) {
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED, 10000);
        log("Test 1 - success");
    }
    NodeSet ns = resourceManager.getAtMostNodes(5, null);
    log("Got " + ns.size() + " nodes");
    // must not receive "node busy" event
    try {
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 2000);
        fail("Must not receive this type of event");
    } catch (ProActiveTimeoutException ex) {
        log("Test 2 - success");
    }
    resourceManager.releaseNodes(ns).getBooleanValue();
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 29 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class TestLocalInfrastructureStaticPolicy method action.

@Test
public void action() throws Exception {
    String source1 = "Node_source_1";
    ResourceManager resourceManager = rmHelper.getResourceManager();
    log("Test 1 - creation/removal of empty node source");
    log("creation");
    createEmptyNodeSource(source1);
    log("removal");
    resourceManager.removeNodeSource(source1, true);
    log("ask to remove NS");
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source1);
    log("NS removed");
    String source2 = "Node_source_2";
    log("Test 2 - creation/removal of the node source with nodes");
    createNodeSourceWithNodes(source1);
    RMState s = resourceManager.getState();
    assertEquals(defaultDescriptorNodesNb, s.getTotalNodesNumber());
    assertEquals(defaultDescriptorNodesNb, s.getFreeNodesNumber());
    // releasing some nodes
    NodeSet ns = resourceManager.getAtMostNodes(defaultDescriptorNodesNb, null);
    for (Node n : ns) {
        // eat the freeToBusy event
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
        resourceManager.removeNode(n.getNodeInformation().getURL(), true);
        rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n.getNodeInformation().getURL());
    }
    assertEquals(0, resourceManager.getState().getTotalNodesNumber());
    assertEquals(0, resourceManager.getState().getFreeNodesNumber());
    log("removal");
    resourceManager.removeNodeSource(source1, true);
    log("ask to remove NS");
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source1);
    log("NS removed");
    log("Test 3 - several node sources");
    createNodeSourceWithNodes(source1);
    createNodeSourceWithNodes(source2);
    assertEquals(2 * defaultDescriptorNodesNb, resourceManager.getState().getTotalNodesNumber());
    assertEquals(2 * defaultDescriptorNodesNb, resourceManager.getState().getFreeNodesNumber());
    resourceManager.removeNodeSource(source1, true);
    // wait the n events of the n nodes removals of the node source
    for (int i = 0; i < defaultDescriptorNodesNb; i++) {
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    }
    // wait for the event of the node source removal
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source1);
    resourceManager.removeNodeSource(source2, true);
    for (int i = 0; i < defaultDescriptorNodesNb; i++) {
        rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
    }
    // wait for the event of the node source removal
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, source2);
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Node(org.objectweb.proactive.core.node.Node) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMState(org.ow2.proactive.resourcemanager.common.RMState) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Example 30 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class NodesRecoveryPropertyTest method restartRmAndCheckFinalState.

private void restartRmAndCheckFinalState(String rmConfigPath, boolean nodesShouldBeRecreated) throws Exception {
    // restart RM
    rmHelper = new RMTHelper();
    startRmWithConfig(rmConfigPath);
    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
    if (PAResourceManagerProperties.RM_NODES_RECOVERY.getValueAsBoolean()) {
        assertThat(nodeSourceEvent.size()).isEqualTo(1);
    }
    assertThat(nodeSourceEvent.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
    // wait for nodes to be recreated if needed
    if (nodesShouldBeRecreated) {
        rmHelper.waitForAnyMultipleNodeEvent(RMEventType.NODE_STATE_CHANGED, NODE_NUMBER);
    }
    // the nodes should have been recovered too, and should be alive
    Set<String> allNodes = resourceManagerMonitor.getState().getAllNodes();
    assertThat(allNodes.size()).isEqualTo(NODE_NUMBER);
    Set<String> nodeSourceNames = new HashSet<>();
    nodeSourceNames.add(NODE_SOURCE_NAME);
    Set<String> aliveNodeUrls = resourceManager.listAliveNodeUrls(nodeSourceNames);
    assertThat(aliveNodeUrls.size()).isEqualTo(NODE_NUMBER);
    // 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 : RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMTHelper(functionaltests.utils.RMTHelper) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver) HashSet(java.util.HashSet)

Aggregations

ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)45 NodeSet (org.ow2.proactive.utils.NodeSet)26 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)25 Test (org.junit.Test)25 Node (org.objectweb.proactive.core.node.Node)16 File (java.io.File)14 Credentials (org.ow2.proactive.authentication.crypto.Credentials)14 Criteria (org.ow2.proactive.utils.Criteria)13 HashMap (java.util.HashMap)11 CredData (org.ow2.proactive.authentication.crypto.CredData)11 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)11 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)10 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)10 TestNode (functionaltests.utils.TestNode)9 SelectionScript (org.ow2.proactive.scripting.SelectionScript)9 RMMonitorEventReceiver (functionaltests.monitor.RMMonitorEventReceiver)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)5 PublicKey (java.security.PublicKey)4