use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class StaticSelectionScriptTest method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
int nodeNumber = rmHelper.createNodeSource("StaticSelectionScriptTest");
String node1Name = "node1";
String node2Name = "node2";
HashMap<String, String> vmProperties = new HashMap<>();
String vmPropKey = "myProperty";
String vmPropValue = "myValue";
vmProperties.put(vmPropKey, vmPropValue);
TestNode node1 = rmHelper.createNode(node1Name, vmProperties);
testNodes.add(node1);
String node1URL = node1.getNode().getNodeInformation().getURL();
resourceManager.addNode(node1URL);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// create the static selection script object
SelectionScript sScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, false);
log("Test 1");
NodeSet nodes = resourceManager.getAtMostNodes(1, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
// wait for node busy event
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNode(nodes.get(0));
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
log("Test 2");
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
// wait for node busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNode(nodes.get(0));
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
log("Test 3");
// add a second with JVM env var
TestNode node2 = rmHelper.createNode(node2Name, vmProperties);
testNodes.add(node2);
String node2URL = node2.getNode().getNodeInformation().getURL();
resourceManager.addNode(node2URL);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(2, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
// wait for node busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNodes(nodes);
// wait for nodes free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
Assert.assertEquals(NodeState.FREE, evt.getNodeState());
log("Test 4");
resourceManager.removeNode(node1URL, true);
resourceManager.removeNode(node2URL, true);
// wait for node removed event
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node1URL);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node2URL);
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 5");
// create the bad static selection script object
SelectionScript badScript = new SelectionScript(new File(badSelectionScriptpath.toURI()), new String[] {}, false);
nodes = resourceManager.getAtMostNodes(3, badScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 6");
// create the static selection script object that doesn't define 'selected'
SelectionScript noSelectedScript = new SelectionScript(new File(withoutSelectedSelectionScriptpath.toURI()), new String[] {}, false);
nodes = resourceManager.getAtMostNodes(3, noSelectedScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
}
use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class RMCoreTest method testGetAtMostNodes.
@Test
public void testGetAtMostNodes() {
NodeSet nodeSet = rmCore.getAtMostNodes(1, TopologyDescriptor.ARBITRARY, null, null);
// we don't check nodeSet as its content is also tested in SelectionManagerTest
assertEquals(0, nodeSet.size());
}
use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class RMCore method releaseNodes.
/**
* {@inheritDoc}
*/
public BooleanWrapper releaseNodes(NodeSet nodes) {
if (nodes.getExtraNodes() != null) {
// do not forget to release extra nodes
nodes.addAll(nodes.getExtraNodes());
}
// exception to throw in case of problems
RuntimeException exception = null;
NodeSet nodesReleased = new NodeSet();
NodeSet nodesFailedToRelease = new NodeSet();
for (Node node : nodes) {
String nodeURL = null;
try {
nodeURL = node.getNodeInformation().getURL();
logger.debug("Releasing node " + nodeURL);
} catch (RuntimeException e) {
logger.debug("A Runtime exception occurred while obtaining information on the node," + "the node must be down (it will be detected later)", e);
// node is down, will be detected by pinger
exception = new IllegalStateException(e.getMessage(), e);
nodesFailedToRelease.add(node);
}
// verify whether the node has not been removed from the RM
if (this.allNodes.containsKey(nodeURL)) {
RMNode rmnode = this.getNodebyUrl(nodeURL);
// free
if (rmnode.isFree()) {
logger.warn("Client " + caller + " tries to release the already free node " + nodeURL);
nodesFailedToRelease.add(node);
} else if (rmnode.isDown()) {
logger.warn("Node was down, it cannot be released");
nodesFailedToRelease.add(node);
} else {
Set<? extends IdentityPrincipal> userPrincipal = rmnode.getOwner().getSubject().getPrincipals(UserNamePrincipal.class);
Permission ownerPermission = new PrincipalPermission(rmnode.getOwner().getName(), userPrincipal);
try {
caller.checkPermission(ownerPermission, caller + " is not authorized to free node " + node.getNodeInformation().getURL());
if (rmnode.isToRemove()) {
removeNodeFromCoreAndSource(rmnode, caller);
nodesReleased.add(node);
} else {
internalSetFree(rmnode);
nodesReleased.add(node);
}
} catch (SecurityException ex) {
logger.error(ex.getMessage(), ex);
nodesFailedToRelease.add(node);
exception = ex;
}
}
} else {
logger.warn("Cannot release unknown node " + nodeURL);
nodesFailedToRelease.add(node);
exception = new IllegalArgumentException("Cannot release unknown node " + nodeURL);
}
}
logger.info("Nodes released : " + nodesReleased);
if (!nodesFailedToRelease.isEmpty()) {
logger.warn("Nodes failed to release : " + nodesFailedToRelease);
}
if (exception != null) {
// throwing the latest exception we had
throw exception;
}
return new BooleanWrapper(true);
}
use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class RMCore method releaseNode.
/**
* {@inheritDoc}
*/
public BooleanWrapper releaseNode(Node node) {
NodeSet nodes = new NodeSet();
nodes.add(node);
return releaseNodes(nodes);
}
use of org.ow2.proactive.utils.NodeSet in project scheduling by ow2-proactive.
the class RMCore method releaseBusyNodesNotInList.
@Override
public void releaseBusyNodesNotInList(List<NodeSet> nodesToNotRelease) {
Set<String> nodesUrlToNotRelease = new HashSet<>();
for (NodeSet nodeSet : nodesToNotRelease) {
nodesUrlToNotRelease.addAll(nodeSet.getAllNodesUrls());
}
List<RMNode> busyNodesToRelease = findBusyNodesNotInSet(nodesUrlToNotRelease);
nodesCleaner.cleanAndRelease(busyNodesToRelease);
}
Aggregations