use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class AddGetRemoveTest method action.
@Test
public void action() throws Exception {
final ResourceManager rm = rmHelper.getResourceManager();
// The username and thr password must be the same a used to connect to the RM
final String adminLogin = TestUsers.TEST.username;
final String adminPassword = TestUsers.TEST.password;
// All accounting values are checked through JMX
final RMAuthentication auth = rmHelper.getRMAuth();
final PublicKey pubKey = auth.getPublicKey();
final Credentials adminCreds = Credentials.createCredentials(new CredData(adminLogin, adminPassword), pubKey);
final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
final HashMap<String, Object> env = new HashMap<>(1);
env.put(JMXConnector.CREDENTIALS, new Object[] { adminLogin, adminCreds });
// Connect to the JMX RMI Connector Server
final ObjectName myAccountMBeanName = new ObjectName(RMJMXBeans.MYACCOUNT_MBEAN_NAME);
final ObjectName managementMBeanName = new ObjectName(RMJMXBeans.MANAGEMENT_MBEAN_NAME);
final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
// ADD, GET, RELEASE
// 1) ADD
testNode = rmHelper.createNode("test");
Node node = testNode.getNode();
final String nodeURL = node.getNodeInformation().getURL();
rm.addNode(nodeURL).getBooleanValue();
// we eat the configuring to free
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeURL);
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// 2) GET
final long beforeGetTime = System.currentTimeMillis();
long originalUsedNodeTime = getUsedNodeTime(myAccountMBeanName, managementMBeanName, conn);
NodeSet nodes = rm.getNodes(new Criteria(1));
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// Sleep a certain amount of time that will be the minimum amount of the GET->RELEASE duration
Thread.sleep(GR_DURATION);
rm.releaseNodes(nodes);
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// Check account values validity
long usedNodeTime = getUsedNodeTime(myAccountMBeanName, managementMBeanName, conn) - originalUsedNodeTime;
// 3) REMOVE
rm.removeNode(nodeURL, true).getBooleanValue();
final long getRemoveMaxDuration = System.currentTimeMillis() - beforeGetTime;
assertThat("Invalid value of the usedNodeTime attribute", usedNodeTime, greaterThan(GR_DURATION));
assertThat("Invalid value of the usedNodeTime attribute", usedNodeTime, lessThan(getRemoveMaxDuration));
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class TestSSHInfrastructureV2 method testSSHInfrastructureV2.
@Test
public void testSSHInfrastructureV2() throws Exception {
nsname = "testSSHInfra";
resourceManager = this.rmHelper.getResourceManager();
RMTHelper.log("Test - Create SSH infrastructure on ssh://localhost on port " + this.port);
resourceManager.createNodeSource(nsname, SSHInfrastructureV2.class.getName(), infraParams, StaticPolicy.class.getName(), policyParameters, NODES_NOT_RECOVERABLE);
this.rmHelper.waitForNodeSourceCreation(nsname, NB_NODES, this.rmHelper.getMonitorsHandler());
RMTHelper.log("Checking scheduler state after node source creation");
RMState s = resourceManager.getState();
assertEquals(NB_NODES, s.getTotalNodesNumber());
assertEquals(NB_NODES, s.getFreeNodesNumber());
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class TestSSHInfrastructureV2RestartDownNodesPolicy method testSSHInfrastructureV2WithRestartDownNodes.
@Test
public void testSSHInfrastructureV2WithRestartDownNodes() throws Exception {
nsname = "testSSHInfraRestart";
resourceManager = this.rmHelper.getResourceManager();
RMTHelper.log("Test - Create SSH infrastructure with RestartDownNodes policy on ssh://localhost on port " + TestSSHInfrastructureV2.port);
resourceManager.createNodeSource(nsname, SSHInfrastructureV2.class.getName(), TestSSHInfrastructureV2.infraParams, RestartDownNodesPolicy.class.getName(), TestSSHInfrastructureV2.policyParameters, NODES_NOT_RECOVERABLE);
RMMonitorsHandler monitorsHandler = this.rmHelper.getMonitorsHandler();
this.rmHelper.waitForNodeSourceCreation(nsname, NB_NODES, monitorsHandler);
RMState s = resourceManager.getState();
assertEquals(NB_NODES, s.getTotalNodesNumber());
assertEquals(NB_NODES, s.getFreeNodesNumber());
NodeSet nodeset = resourceManager.getNodes(new Criteria(NB_NODES));
if (nodeset.size() != NB_NODES) {
RMTHelper.log("Illegal state : the infrastructure could not deploy nodes or they died immediately. Ending test");
throw new RuntimeException("Illegal state : the infrastructure could not deploy nodes or they died immediately. Ending test");
}
for (Node n : nodeset) {
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL(), 60000, monitorsHandler);
}
String nodeUrl = nodeset.get(0).getNodeInformation().getURL();
RMTHelper.log("Killing nodes");
// Nodes will be redeployed only if we kill the whole runtime
rmHelper.killRuntime(nodeUrl);
RMTHelper.log("Wait for down nodes detection by the rm");
for (Node n : nodeset) {
RMNodeEvent ev = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL(), 120000, monitorsHandler);
assertEquals(NodeState.DOWN, ev.getNodeState());
}
for (Node n : nodeset) {
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, n.getNodeInformation().getURL(), 120000, monitorsHandler);
}
RMTHelper.log("Dumping events not consumed yet");
monitorsHandler.dumpEvents();
RMTHelper.log("Wait for nodes restart by the policy");
rmHelper.waitForAnyMultipleNodeEvent(RMEventType.NODE_ADDED, NB_NODES, monitorsHandler);
for (int i = 0; i < NB_NODES; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED, monitorsHandler);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED, monitorsHandler);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, monitorsHandler);
}
RMTHelper.log("Final checks on the scheduler state");
nodeset = resourceManager.getNodes(new Criteria(NB_NODES));
for (Node n : nodeset) {
System.out.println("NODE::" + n.getNodeInformation().getURL());
}
s = resourceManager.getState();
assertEquals(NB_NODES, s.getTotalNodesNumber());
// check amount of all nodes that are not down
assertEquals(NB_NODES, s.getTotalAliveNodesNumber());
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class NodesRecoveryPropertyTest method startRmAndCheckInitialState.
private void startRmAndCheckInitialState(String rmConfigPath, boolean nodesRecoverable) throws Exception {
// start RM
startRmWithConfig(rmConfigPath);
assertThat(PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean()).isTrue();
assertThat(rmHelper.isRMStarted()).isTrue();
// check the initial state of the RM
assertThat(resourceManager.getState().getAllNodes().size()).isEqualTo(0);
if (nodesRecoverable) {
rmHelper.createNodeSourceWithNodesRecoverable(NODE_SOURCE_NAME, NODE_NUMBER);
} else {
rmHelper.createNodeSource(NODE_SOURCE_NAME, NODE_NUMBER);
}
RMMonitorEventReceiver resourceManagerMonitor = (RMMonitorEventReceiver) resourceManager;
List<RMNodeSourceEvent> nodeSourceEventPerNodeSource = resourceManagerMonitor.getInitialState().getNodeSourceEvents();
assertThat(nodeSourceEventPerNodeSource.size()).isEqualTo(1);
assertThat(nodeSourceEventPerNodeSource.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
assertThat(resourceManagerMonitor.getState().getAllNodes().size()).isEqualTo(NODE_NUMBER);
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class TestNodeSourcesActions method testAddRemoveNodesPreemptively.
@Test
public void testAddRemoveNodesPreemptively() throws Exception {
String nodeSourceName = "TestNodeSourcesActions";
ResourceManager resourceManager = rmHelper.getResourceManager();
int nodeNumber = 5;
int pingFrequency = 5000;
byte[] creds = FileToBytesConverter.convertFileToByteArray(new File(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
resourceManager.createNodeSource(nodeSourceName, LocalInfrastructure.class.getName(), new Object[] { creds, nodeNumber, RMTHelper.DEFAULT_NODES_TIMEOUT, "" }, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
// wait for creation of GCM Node Source event, and deployment of its nodes
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nodeSourceName);
resourceManager.setNodeSourcePingFrequency(pingFrequency, nodeSourceName);
RMTHelper.log("Test 1");
for (int i = 0; i < nodeNumber; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
}
assertEquals(nodeNumber, resourceManager.getState().getTotalNodesNumber());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
// book 3 nodes
NodeSet nodes = resourceManager.getAtMostNodes(3, null);
PAFuture.waitFor(nodes);
assertEquals(3, nodes.size());
assertEquals(nodeNumber - 3, resourceManager.getState().getFreeNodesNumber());
assertEquals(nodeNumber, resourceManager.getState().getTotalNodesNumber());
for (int i = 0; i < 3; i++) {
RMNodeEvent evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(evt.getNodeState(), NodeState.BUSY);
}
// put one of the busy node in 'to release' state
Node n1 = nodes.remove(0);
resourceManager.removeNode(n1.getNodeInformation().getURL(), false);
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n1.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.TO_BE_REMOVED);
// put one of the busy node in 'down' state
Node n2 = nodes.remove(0);
try {
n2.getProActiveRuntime().killNode(n2.getNodeInformation().getName());
} catch (Exception e) {
e.printStackTrace();
}
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n2.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.DOWN);
// kill preemptively the node source
resourceManager.removeNodeSource(nodeSourceName, true);
for (int i = 0; i < nodeNumber; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
}
// wait for the event of the node source removal
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_REMOVED, nodeSourceName);
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
assertEquals(0, resourceManager.getState().getTotalNodesNumber());
// test the non preemptive node source removal
RMTHelper.log("Test 2");
String nodeSourceName2 = "TestNodeSourcesActions2";
// first im parameter is default rmHelper url
int expectedNodeNumber = 3;
rmHelper.createNodeSource(nodeSourceName2, expectedNodeNumber);
resourceManager.setNodeSourcePingFrequency(pingFrequency, nodeSourceName2);
assertEquals(expectedNodeNumber, resourceManager.getState().getTotalNodesNumber());
assertEquals(expectedNodeNumber, resourceManager.getState().getFreeNodesNumber());
// book 3 nodes
nodes = resourceManager.getAtMostNodes(3, null);
PAFuture.waitFor(nodes);
for (int i = 0; i < 3; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(evt.getNodeState(), NodeState.BUSY);
}
assertEquals(3, nodes.size());
assertEquals(expectedNodeNumber - 3, resourceManager.getState().getFreeNodesNumber());
assertEquals(expectedNodeNumber, resourceManager.getState().getTotalNodesNumber());
// put one of the busy node in 'to release' state
n1 = nodes.remove(0);
resourceManager.removeNode(n1.getNodeInformation().getURL(), false);
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n1.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.TO_BE_REMOVED);
// put one of the busy node in 'down' state
n2 = nodes.remove(0);
Node n3 = nodes.remove(0);
try {
n2.getProActiveRuntime().killNode(n2.getNodeInformation().getName());
} catch (Exception e) {
e.printStackTrace();
}
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n2.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.DOWN);
// kill non preemptively the node source
resourceManager.removeNodeSource(nodeSourceName2, false);
// the two free nodes and the down node (n2) are removed immediately
for (int i = 0; i < expectedNodeNumber - 2; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
}
// the 'to release' node (n1) keeps the same state
// the busy node (n3) becomes a 'to release' node
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n3.getNodeInformation().getURL());
assertEquals(evt.getNodeState(), NodeState.TO_BE_REMOVED);
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
assertEquals(2, resourceManager.getState().getTotalNodesNumber());
// give back the two nodes in 'to release' state, they are directly removed
resourceManager.releaseNode(n1);
resourceManager.releaseNode(n3);
for (int i = 0; i < 2; i++) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED);
}
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
assertEquals(0, resourceManager.getState().getTotalNodesNumber());
}
Aggregations