Search in sources :

Example 1 with TopologyManager

use of org.ow2.proactive.resourcemanager.selection.topology.TopologyManager in project scheduling by ow2-proactive.

the class topologyConcurrencyTest method action.

@Test
public void action() throws Exception {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();
    Logger.getLogger(TopologyManager.class).setLevel(Level.DEBUG);
    PAResourceManagerProperties.RM_TOPOLOGY_PINGER.updateProperty(HostsPinger.class.getName());
    PAResourceManagerProperties.RM_TOPOLOGY_ENABLED.updateProperty("true");
    PAResourceManagerProperties.RM_TOPOLOGY_DISTANCE_ENABLED.updateProperty("false");
    final ProActiveRuntimeImpl runtime = mock(ProActiveRuntimeImpl.class);
    when(runtime.getVMInformation()).thenReturn(new DummyVMInfo());
    final TopologyManager manager = new TopologyManager();
    List<Callable<Boolean>> calls = new ArrayList<>(total);
    // first set of tasks, add nodes and remove them
    for (int i = 0; i < total; i++) {
        final int j = i;
        calls.add(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                try {
                    int index = j - (j % collisionSize);
                    Node node = new NodeImpl(runtime, baseUrl + index);
                    if ((j % (collisionSize / 2)) == 0) {
                        manager.addNode(node);
                    } else {
                        // more remove than add, to try to reproduce empty list problems
                        manager.removeNode(node);
                    }
                    // launch some selections on the node just added or removed to trigger ConcurrentModficationExceptions if any
                    NodeSet set = manager.getHandler(TopologyDescriptor.SINGLE_HOST).select(1, Collections.singletonList(node));
                    System.out.println(set);
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }
                return true;
            }
        });
    }
    List<Future<Boolean>> futures = s.invokeAll(calls);
    for (Future<Boolean> fut : futures) {
        Assert.assertTrue(fut.get());
    }
    calls = new ArrayList<>(nbThreads * nodeFactor);
    // second set of task remove all nodes created
    for (int i = 0; i < total; i += collisionSize) {
        final int j = i;
        calls.add(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                try {
                    int index = j;
                    Node node = new NodeImpl(runtime, baseUrl + index);
                    manager.removeNode(node);
                    NodeSet set = manager.getHandler(TopologyDescriptor.SINGLE_HOST).select(1, Collections.singletonList(node));
                    System.out.println(set);
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }
                return true;
            }
        });
    }
    futures = s.invokeAll(calls);
    for (Future<Boolean> fut : futures) {
        Assert.assertTrue(fut.get());
    }
    System.out.println(manager.getTopology().getHosts());
    // finally verify that the nodes on host structure is empty (null)
    Assert.assertNull(manager.getNodesOnHost(DummyVMInfo.address));
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) NodeImpl(org.objectweb.proactive.core.node.NodeImpl) Node(org.objectweb.proactive.core.node.Node) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) TopologyManager(org.ow2.proactive.resourcemanager.selection.topology.TopologyManager) HostsPinger(org.ow2.proactive.resourcemanager.frontend.topology.pinging.HostsPinger) Future(java.util.concurrent.Future) ProActiveRuntimeImpl(org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl) Test(org.junit.Test)

Example 2 with TopologyManager

use of org.ow2.proactive.resourcemanager.selection.topology.TopologyManager in project scheduling by ow2-proactive.

the class TopologyNodesTest method unifedTopologyTestMethod.

private void unifedTopologyTestMethod(TopologyDescriptor topology, int requiredNodesNumber, Map<String, Integer> groupedNodeByHost, int outputNodesNumber) throws ClassNotFoundException {
    Criteria crit = new Criteria(requiredNodesNumber);
    crit.setTopology(topology);
    crit.setScripts(null);
    crit.setBlackList(null);
    crit.setBestEffort(false);
    List<Node> arrangedNodes = new ArrayList<>();
    for (String host : groupedNodeByHost.keySet()) {
        for (int i = 0; i < groupedNodeByHost.get(host); i++) {
            arrangedNodes.add(createMockeNode(host));
        }
    }
    // simulate what the selection manager is doing
    TopologyManager manager = new TopologyManager();
    for (Node node : arrangedNodes) {
        manager.addNode(node);
    }
    TopologyHandler handler = manager.getHandler(crit.getTopology());
    NodeSet selectedNodes = handler.select(crit.getSize(), arrangedNodes);
    if (selectedNodes.size() < crit.getSize() && !crit.isBestEffort()) {
        selectedNodes.clear();
        if (selectedNodes.getExtraNodes() != null) {
            selectedNodes.getExtraNodes().clear();
        }
    }
    Set<Node> allNodes = new HashSet<>(selectedNodes);
    if (selectedNodes.getExtraNodes() != null) {
        allNodes.addAll((selectedNodes.getExtraNodes()));
    }
    System.out.println("Selected nodes : " + allNodes);
    if (outputNodesNumber >= 0) {
        assertEquals(outputNodesNumber, allNodes.size());
    } else {
        // different host exclusive test
        Map<String, Integer> checkNodesByHost = new HashMap<>(groupedNodeByHost);
        for (Node node : allNodes) {
            String hostName = node.getVMInformation().getHostName();
            checkNodesByHost.put(hostName, checkNodesByHost.get(hostName) - 1);
        }
        System.out.println("Free nodes after selection : " + checkNodesByHost);
        Assert.assertEquals(requiredNodesNumber, checkNodesByHost.entrySet().stream().filter(entry -> entry.getValue() == 0).collect(Collectors.toList()).size());
    }
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) Criteria(org.ow2.proactive.utils.Criteria) BeforeClass(org.junit.BeforeClass) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) NodeSet(org.ow2.proactive.utils.NodeSet) ImmutableMap(com.google.common.collect.ImmutableMap) VMInformation(org.objectweb.proactive.core.runtime.VMInformation) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Node(org.objectweb.proactive.core.node.Node) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) PAResourceManagerProperties(org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties) List(java.util.List) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor) NodeInformation(org.objectweb.proactive.core.node.NodeInformation) Map(java.util.Map) HostsPinger(org.ow2.proactive.resourcemanager.frontend.topology.pinging.HostsPinger) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Node(org.objectweb.proactive.core.node.Node) ArrayList(java.util.ArrayList) Criteria(org.ow2.proactive.utils.Criteria) HashSet(java.util.HashSet)

Example 3 with TopologyManager

use of org.ow2.proactive.resourcemanager.selection.topology.TopologyManager in project scheduling by ow2-proactive.

the class RMCore method initActivity.

/**
 * Initialization part of the RMCore active object.
 * Create RM's active objects and the default static Node Source named
 * {@link RMConstants#DEFAULT_STATIC_SOURCE_NAME}. Finally, it throws the RM
 * started event.
 *
 * @param body the active object's body.
 */
public void initActivity(Body body) {
    if (logger.isDebugEnabled()) {
        logger.debug("RMCore start : initActivity");
    }
    try {
        // setting up the policy
        logger.debug("Setting up the resource manager security policy");
        ClientsPolicy.init();
        StubObject rmCoreStub = PAActiveObject.getStubOnThis();
        PAActiveObject.registerByName(rmCoreStub, RMConstants.NAME_ACTIVE_OBJECT_RMCORE);
        dbManager = RMDBManager.getInstance();
        if (logger.isDebugEnabled()) {
            logger.debug("Creating RMAuthentication active object");
        }
        authentication = (RMAuthenticationImpl) PAActiveObject.newActive(RMAuthenticationImpl.class.getName(), new Object[] { rmCoreStub }, nodeRM);
        if (logger.isDebugEnabled()) {
            logger.debug("Creating RMMonitoring active object");
        }
        // Boot the JMX infrastructure
        this.jmxHelper.boot(authentication);
        monitoring = (RMMonitoringImpl) PAActiveObject.newActive(RMMonitoringImpl.class.getName(), new Object[] { rmCoreStub }, nodeRM);
        if (logger.isDebugEnabled()) {
            logger.debug("Creating SelectionManager active object");
        }
        selectionManager = (SelectionManager) PAActiveObject.newActive(ProbablisticSelectionManager.class.getName(), new Object[] { rmCoreStub }, nodeRM);
        if (logger.isDebugEnabled()) {
            logger.debug("Creating ClientPinger active object");
        }
        clientPinger = (ClientPinger) PAActiveObject.newActive(ClientPinger.class.getName(), new Object[] { rmCoreStub }, nodeRM);
        if (logger.isDebugEnabled()) {
            logger.debug("Creating NodeCleaner active object");
        }
        nodesCleaner = (NodesCleaner) PAActiveObject.newActive(NodesCleaner.class.getName(), new Object[] { rmCoreStub }, nodeRM);
        topologyManager = new TopologyManager();
        nodeConfigurator = (RMNodeConfigurator) PAActiveObject.newActive(RMNodeConfigurator.class.getName(), new Object[] { rmCoreStub }, nodeRM);
        // adding shutdown hook
        final RMCore rmcoreStub = (RMCore) rmCoreStub;
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                if (!toShutDown) {
                    PAFuture.waitFor(rmcoreStub.shutdown(true), PAResourceManagerProperties.RM_SHUTDOWN_TIMEOUT.getValueAsInt() * 1000L);
                }
            }
        });
        // Creating RM started event
        this.monitoring.rmEvent(new RMEvent(RMEventType.STARTED));
        authentication.setActivated(true);
        clientPinger.ping();
        nodeSourceParameterHelper = new NodeSourceParameterHelper();
        nodesHouseKeepingService = new NodesHouseKeepingService(rmcoreStub);
        nodesHouseKeepingService.start();
        initiateRecoveryIfRequired();
    } catch (ActiveObjectCreationException e) {
        logger.error("", e);
    } catch (NodeException e) {
        logger.error("", e);
    } catch (ProActiveException e) {
        logger.error("", e);
    } catch (ClassNotFoundException e) {
        logger.error("", e);
    } finally {
        signalRMCoreIsInitialized();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("RMCore end: initActivity");
    }
}
Also used : ProbablisticSelectionManager(org.ow2.proactive.resourcemanager.selection.statistics.ProbablisticSelectionManager) ClientPinger(org.ow2.proactive.resourcemanager.utils.ClientPinger) RMMonitoringImpl(org.ow2.proactive.resourcemanager.frontend.RMMonitoringImpl) NodeException(org.objectweb.proactive.core.node.NodeException) ProActiveException(org.objectweb.proactive.core.ProActiveException) RMAuthenticationImpl(org.ow2.proactive.resourcemanager.authentication.RMAuthenticationImpl) StubObject(org.objectweb.proactive.core.mop.StubObject) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) NodesCleaner(org.ow2.proactive.resourcemanager.cleaning.NodesCleaner) TopologyManager(org.ow2.proactive.resourcemanager.selection.topology.TopologyManager) NodesHouseKeepingService(org.ow2.proactive.resourcemanager.housekeeping.NodesHouseKeepingService) RMEvent(org.ow2.proactive.resourcemanager.common.event.RMEvent) RMNodeConfigurator(org.ow2.proactive.resourcemanager.nodesource.RMNodeConfigurator)

Example 4 with TopologyManager

use of org.ow2.proactive.resourcemanager.selection.topology.TopologyManager in project scheduling by ow2-proactive.

the class NodeSourceTest method setUp.

@Before
public void setUp() {
    PAResourceManagerProperties.RM_TOPOLOGY_ENABLED.updateProperty("false");
    infrastructureManager = mock(InfrastructureManager.class);
    when(infrastructureManager.isUsingDeployingNode()).thenReturn(false);
    NodeSourcePolicy nodeSourcePolicy = mock(NodeSourcePolicy.class);
    when(nodeSourcePolicy.getProviderAccessType()).thenReturn(AccessType.ALL);
    client = new Client(Subjects.create("user"), false);
    nodeSource = createNodeSource(infrastructureManager, nodeSourcePolicy, client);
    RMCore.topologyManager = new TopologyManager(HostsPinger.class);
}
Also used : TopologyManager(org.ow2.proactive.resourcemanager.selection.topology.TopologyManager) HostsPinger(org.ow2.proactive.resourcemanager.frontend.topology.pinging.HostsPinger) InfrastructureManager(org.ow2.proactive.resourcemanager.nodesource.infrastructure.InfrastructureManager) Client(org.ow2.proactive.resourcemanager.authentication.Client) NodeSourcePolicy(org.ow2.proactive.resourcemanager.nodesource.policy.NodeSourcePolicy) Before(org.junit.Before)

Example 5 with TopologyManager

use of org.ow2.proactive.resourcemanager.selection.topology.TopologyManager in project scheduling by ow2-proactive.

the class SelectionManagerTest method newMockedRMCore.

public static RMCore newMockedRMCore(int nbNodes) {
    RMCore mockedRMCore = Mockito.mock(RMCore.class);
    TopologyManager mockedTopologyManager = Mockito.mock(TopologyManager.class);
    when(mockedTopologyManager.getHandler(Matchers.any(TopologyDescriptor.class))).thenReturn(selectAllTopology());
    RMCore.topologyManager = mockedTopologyManager;
    if (nbNodes > 0) {
        ArrayList<RMNode> freeNodes = new ArrayList<RMNode>(nbNodes);
        for (int i = 0; i < nbNodes; i++) {
            freeNodes.add(createMockedNode("user", "mocked-node-" + (i + 1), "mocked-node-" + (i + 1)));
        }
        when(mockedRMCore.getFreeNodes()).thenReturn(freeNodes);
    }
    return mockedRMCore;
}
Also used : RMCore(org.ow2.proactive.resourcemanager.core.RMCore) TopologyManager(org.ow2.proactive.resourcemanager.selection.topology.TopologyManager) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) ArrayList(java.util.ArrayList) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor)

Aggregations

TopologyManager (org.ow2.proactive.resourcemanager.selection.topology.TopologyManager)5 ArrayList (java.util.ArrayList)4 HostsPinger (org.ow2.proactive.resourcemanager.frontend.topology.pinging.HostsPinger)4 Test (org.junit.Test)3 Node (org.objectweb.proactive.core.node.Node)3 NodeSet (org.ow2.proactive.utils.NodeSet)3 Callable (java.util.concurrent.Callable)2 Future (java.util.concurrent.Future)2 NodeImpl (org.objectweb.proactive.core.node.NodeImpl)2 ProActiveRuntimeImpl (org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl)2 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)2 TopologyDescriptor (org.ow2.proactive.topology.descriptor.TopologyDescriptor)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1