use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class SelectionWithSeveralScriptsTest2 method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
String nodeSourceName = "SelectionWithSeveralScriptsTest2";
resourceManager.createNodeSource(nodeSourceName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nodeSourceName);
String node1Name = "node-sel2-1";
String node2Name = "node-sel2-2";
// ---------------------------------------------------
// create a first node with one VM property
// ---------------------------------------------------
HashMap<String, String> vmProp1 = new HashMap<>();
String vmPropKey1 = "myProperty1";
String vmPropValue1 = "myValue1";
vmProp1.put(vmPropKey1, vmPropValue1);
TestNode node1 = rmHelper.createNode(node1Name, vmProp1);
testNodes.add(node1);
String node1URL = node1.getNode().getNodeInformation().getURL();
resourceManager.addNode(node1URL, nodeSourceName);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// --------------------------------------------------
// create a second node with two VM properties
// ---------------------------------------------------
HashMap<String, String> vmTwoProperties = new HashMap<>();
vmTwoProperties.put(vmPropKey1, vmPropValue1);
String vmPropKey2 = "myProperty2";
String vmPropValue2 = "myValue2";
vmTwoProperties.put(vmPropKey2, vmPropValue2);
TestNode node2 = rmHelper.createNode(node2Name, vmTwoProperties);
testNodes.add(node2);
String node2URL = node2.getNode().getNodeInformation().getURL();
resourceManager.addNode(node2URL, nodeSourceName);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// create the static selection script object that check vm prop1
SelectionScript sScript1 = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey1, vmPropValue1 }, true);
// create the static selection script object prop2
SelectionScript sScript2 = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey2, vmPropValue2 }, false);
log("Test 1");
ArrayList<SelectionScript> scriptsList = new ArrayList<>();
scriptsList.add(sScript1);
scriptsList.add(sScript2);
NodeSet nodes = resourceManager.getAtMostNodes(1, scriptsList, null);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(node2URL, nodes.get(0).getNodeInformation().getURL());
// wait for node busy event
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(nodes);
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.FREE, evt.getNodeState());
assertEquals(2, resourceManager.getState().getFreeNodesNumber());
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class RMCoreTest method createRmNodeEvent.
private RMNodeEvent createRmNodeEvent(NodeState previousNodeState) {
RMNodeDescriptor rmNodeDescriptor = new RMNodeDescriptor();
rmNodeDescriptor.setState(NodeState.DOWN);
return new RMNodeEvent(rmNodeDescriptor, RMEventType.NODE_STATE_CHANGED, previousNodeState, "initiator");
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent 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()) {
logger.info("Cleaning RM State");
// force reconnection
rmHelper.disconnect();
ResourceManager rm = rmHelper.getResourceManager();
RMInitialState state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
List<RMNodeEvent> allNodes = state.getNodeEvents();
for (RMNodeSourceEvent sourceEvent : state.getNodeSourceEvents()) {
String nodeSource = sourceEvent.getSourceName();
rm.removeNodeSource(nodeSource, true);
for (RMNodeEvent nodeEvent : allNodes) {
if (nodeSource.equals(nodeEvent.getNodeSource())) {
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, nodeEvent.getNodeUrl());
}
}
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nodeSource);
}
state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
Assert.assertEquals(0, state.getNodeSourceEvents().size());
if (state.getNodeEvents().size() > 0) {
for (RMNodeEvent remainingNode : state.getNodeEvents()) {
rm.removeNode(remainingNode.getNodeUrl(), true);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, remainingNode.getNodeUrl());
}
}
state = ((RMMonitorEventReceiver) rmHelper.getResourceManager()).getInitialState();
Assert.assertEquals(0, state.getNodeEvents().size());
logger.info("RM State cleaned");
}
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class TestExecuteScriptsOnBusyNode method testExecuteScriptOnBusyNode.
@Test
public void testExecuteScriptOnBusyNode() throws Exception {
FileLock fileLock = new FileLock();
Path fileLockPath = fileLock.lock();
log("Submit job");
final JobId jobId = schedulerHelper.submitJob(createJobWithLock(fileLockPath.toString()));
log("Wait when node becomes busy");
RMNodeEvent event;
do {
event = schedulerHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, TIMEOUT);
} while (!event.getNodeState().equals(NodeState.BUSY));
log("Wait when task starts");
schedulerHelper.waitForEventTaskRunning(jobId, "Test task");
log("Wait some time until task launcher is started");
Thread.sleep(5000);
List<ScriptResult<Object>> results = schedulerHelper.getResourceManager().executeScript("println \"Executing Script\";", "groovy", TargetType.NODE_URL.name(), Sets.newSet(testNode.getNodeURL()));
Assert.assertEquals(1, results.size());
ScriptResult result = results.get(0);
if (result.errorOccured()) {
result.getException().printStackTrace();
Assert.fail("Script execution failed");
}
log("Let task finish");
fileLock.unlock();
log("Wait when job finish");
schedulerHelper.waitForEventJobFinished(jobId, TIMEOUT);
schedulerHelper.waitUntilState(testNode.getNodeURL(), NodeState.FREE, TIMEOUT);
log("Check job result");
checkJobResult(schedulerHelper.getSchedulerInterface(), jobId);
checkActiveObjects();
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeEvent in project scheduling by ow2-proactive.
the class RecoverSSHInfrastructureV2Test method restartRmAndCheckFinalState.
private void restartRmAndCheckFinalState(int expectedNbAliveNodes, int expectedNbDownNodes) throws Exception {
// restart RM
rmHelper = new RMTHelper();
startRmWithConfig(RESTART_CONFIG);
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
assertThat(nodeSourceEvent.size()).isEqualTo(1);
assertThat(nodeSourceEvent.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
// the nodes should have been recovered too, and should be alive or down
Set<String> allNodes = resourceManagerMonitor.getState().getAllNodes();
assertThat(allNodes.size()).isEqualTo(TestSSHInfrastructureV2.NB_NODES);
Set<String> nodeSourceNames = new HashSet<>();
nodeSourceNames.add(NODE_SOURCE_NAME);
List<RMNodeEvent> nodeEvents = resourceManagerMonitor.getInitialState().getNodeEvents();
long nbFreeNodes = nodeEvents.stream().filter(nodeEvent -> nodeEvent.getNodeState().equals(NodeState.FREE)).count();
assertThat(nbFreeNodes).isEqualTo(expectedNbAliveNodes);
long nbDownNodes = nodeEvents.stream().filter(nodeEvent -> nodeEvent.getNodeState().equals(NodeState.DOWN)).count();
assertThat(nbDownNodes).isEqualTo(expectedNbDownNodes);
// 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));
}
Aggregations