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));
}
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());
}
}
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");
}
}
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);
}
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;
}
Aggregations