Search in sources :

Example 41 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class TestAddRemoveAll method testCreateNodeSource.

@Test
public void testCreateNodeSource() throws Exception {
    ResourceManager resourceManager = rmHelper.getResourceManager();
    int pingFrequency = 6000;
    log("Add/RemoveAll");
    resourceManager.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
    resourceManager.setNodeSourcePingFrequency(pingFrequency, nsName);
    testNode = rmHelper.createNode(nodeName);
    Node nodeToAdd = testNode.getNode();
    resourceManager.addNode(nodeToAdd.getNodeInformation().getURL(), nsName).getBooleanValue();
    // at this time, nodes maybe fully added in the nodesource but not in the core
    // the next removal may fail for some nodes that are not known by the core...
    resourceManager.removeNodeSource(nsName, true);
    rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nsName);
    Thread.sleep(pingFrequency * 2);
    if (resourceManager.getState().getTotalNodesNumber() != 0) {
        log("The removeAll method in RMCore didn't removed all nodes");
        fail();
    } else {
        log("The removeAll method in RMCore did its job well");
    }
}
Also used : DefaultInfrastructureManager(org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) Node(org.objectweb.proactive.core.node.Node) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 42 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class RMFunctionalTest method cleanState.

/**
 * Remove all node sources and nodes in the RM
 *
 * @throws Exception
 */
private void cleanState() throws Exception {
    if (rmHelper.isRMStarted()) {
        // force reconnection
        rmHelper.disconnect();
        ResourceManager rm = rmHelper.getResourceManager();
        int nodeNumber = rm.getState().getTotalNodesNumber();
        RMInitialState state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
        for (RMNodeSourceEvent sourceEvent : state.getNodeSourceEvents()) {
            String nodeSource = sourceEvent.getSourceName();
            rm.removeNodeSource(nodeSource, true);
            rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nodeSource);
        }
        for (int i = 0; i < nodeNumber; i++) {
            rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
        }
    }
}
Also used : RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) RMInitialState(org.ow2.proactive.resourcemanager.common.event.RMInitialState) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) RMMonitorEventReceiver(functionaltests.monitor.RMMonitorEventReceiver)

Example 43 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class RMCoreTest method testLockNodeState.

private void testLockNodeState(NodeState nodeState) {
    RMNodeImpl rmNode = spy(RMNodeHelper.basicWithMockedInternals().getLeft());
    rmNode.setState(nodeState);
    HashMap<String, RMNode> allNodes = new HashMap<>();
    allNodes.put(rmNode.getNodeURL(), rmNode);
    ArrayList<RMNode> freeNodes = Lists.newArrayList((RMNode) rmNode);
    RMCore rmCore = new RMCore(new HashMap<String, NodeSource>(), allNodes, Mockito.mock(Client.class), Mockito.mock(RMMonitoringImpl.class), Mockito.mock(SelectionManager.class), freeNodes, Mockito.mock(RMDBManager.class));
    rmCore.signalRMCoreIsInitialized();
    BooleanWrapper lockResult = rmCore.lockNodes(ImmutableSet.of(rmNode.getNodeURL()));
    assertThat(lockResult.getBooleanValue()).isTrue();
    assertThat(rmNode.getState()).isEqualTo(nodeState);
    assertThat(rmNode.isLocked()).isTrue();
    assertThat(freeNodes).isEmpty();
}
Also used : RMDBManager(org.ow2.proactive.resourcemanager.db.RMDBManager) SelectionManager(org.ow2.proactive.resourcemanager.selection.SelectionManager) HashMap(java.util.HashMap) RMMonitoringImpl(org.ow2.proactive.resourcemanager.frontend.RMMonitoringImpl) Matchers.anyString(org.mockito.Matchers.anyString) NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 44 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class RMRestTest method testAddNodeOverloading.

// PORTAL-326
@Test
public void testAddNodeOverloading() throws Exception {
    RMProxyUserInterface rm = mock(RMProxyUserInterface.class);
    String sessionId = SharedSessionStoreTestUtils.createValidSession(rm);
    when(rm.addNode(anyString())).thenReturn(new BooleanWrapper(true));
    List<NameValuePair> firstCall = Collections.<NameValuePair>singletonList(new BasicNameValuePair("nodeurl", "url"));
    callHttpPostMethod("node", sessionId, firstCall);
    verify(rm).addNode("url");
    reset(rm);
    when(rm.addNode(anyString(), anyString())).thenReturn(new BooleanWrapper(true));
    List<NameValuePair> secondCall = new ArrayList<>();
    secondCall.add(new BasicNameValuePair("nodeurl", "urlwithnsname"));
    secondCall.add(new BasicNameValuePair("nodesource", "ns"));
    callHttpPostMethod("node", sessionId, secondCall);
    verify(rm).addNode("urlwithnsname", "ns");
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 45 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class RMCore method removeDeployingNode.

/**
 * To handle the deploying node removal
 *
 * @param url the url of the deploying node to remove
 * @return true if successful, false otherwise
 */
private boolean removeDeployingNode(String url) {
    String nsName = "";
    try {
        URI urlObj = new URI(url);
        nsName = urlObj.getHost();
    } catch (URISyntaxException e) {
        logger.warn("No such deploying node: " + url);
        return false;
    }
    if (nsName == null) {
        // cannot compute the nsName using URI, try using Pattern
        Matcher matcher = Pattern.compile(RMDeployingNode.PROTOCOL_ID + "://([-\\w]+)/.+").matcher(url);
        if (matcher.find()) {
            try {
                nsName = matcher.group(1);
            } catch (IndexOutOfBoundsException e) {
                logger.debug("Was not able to determine nodesource's name for url " + url);
            }
        }
    }
    NodeSource ns = this.deployedNodeSources.get(nsName);
    if (ns == null) {
        logger.warn("No such nodesource: " + nsName + ", cannot remove the deploying node with url: " + url);
        return false;
    }
    return ns.removeDeployingNode(url);
}
Also used : NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) Matcher(java.util.regex.Matcher) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)21 Test (org.junit.Test)17 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)13 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)11 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)11 Client (org.ow2.proactive.resourcemanager.authentication.Client)9 Node (org.objectweb.proactive.core.node.Node)8 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)7 ArrayList (java.util.ArrayList)6 RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)6 Permission (java.security.Permission)5 NodeSourceData (org.ow2.proactive.resourcemanager.db.NodeSourceData)5 RMException (org.ow2.proactive.resourcemanager.exception.RMException)5 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Matchers.anyString (org.mockito.Matchers.anyString)4