use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication in project scheduling by ow2-proactive.
the class ResourceManagerJMXTest method action.
@Test
public void action() throws Exception {
final RMAuthentication auth = rmHelper.getRMAuth();
final PublicKey pubKey = auth.getPublicKey();
final Credentials adminCreds = Credentials.createCredentials(new CredData(TestUsers.TEST.username, TestUsers.TEST.password), pubKey);
final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
final JMXServiceURL jmxRoServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RO));
final ObjectName allAccountsMBeanName = new ObjectName(RMJMXBeans.ALLACCOUNTS_MBEAN_NAME);
final ObjectName myAccountMBeanName = new ObjectName(RMJMXBeans.MYACCOUNT_MBEAN_NAME);
final ObjectName runtimeDataMBeanName = new ObjectName(RMJMXBeans.RUNTIMEDATA_MBEAN_NAME);
final ObjectName managementMBeanName = new ObjectName(RMJMXBeans.MANAGEMENT_MBEAN_NAME);
final String suffix = "/" + PAResourceManagerProperties.RM_JMX_CONNECTOR_NAME.getValueAsString();
jmxURLsAreWellFormed(jmxRmiServiceURL, jmxRoServiceURL, suffix);
jmxAuthInvalidCreds(jmxRmiServiceURL);
jmxAuthNullLoginPassword(jmxRmiServiceURL);
jmxAuthInvalidLoginPassword(jmxRmiServiceURL);
jmxRMIAsUser(jmxRmiServiceURL, allAccountsMBeanName, myAccountMBeanName, runtimeDataMBeanName);
jmxRemoteObjectAsAdmin(adminCreds, jmxRoServiceURL, allAccountsMBeanName, managementMBeanName);
simultaneousRMIAndROConnections(adminCreds, jmxRmiServiceURL, jmxRoServiceURL);
jmxClientHelper(auth, adminCreds);
}
use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication in project scheduling by ow2-proactive.
the class AddGetDownRemoveTest method action.
@Test
public void action() throws Exception {
// The username and thr password must be the same a used to connect to the RM
final ResourceManager rm = rmHelper.getResourceManager();
// All accounting values are checked through JMX
final RMAuthentication auth = rmHelper.getRMAuth();
final PublicKey pubKey = auth.getPublicKey();
final Credentials adminCreds = Credentials.createCredentials(new CredData(TestUsers.TEST.username, TestUsers.TEST.password), pubKey);
final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
final HashMap<String, Object> env = new HashMap<>(1);
env.put(JMXConnector.CREDENTIALS, new Object[] { TestUsers.TEST.username, 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();
long usedNodeTime = (Long) conn.getAttribute(myAccountMBeanName, "UsedNodeTime");
// ADD, GET, DOWN, REMOVE
// 1) ADD
final String name = "AddGetDownRemoveTest";
testNode = rmHelper.createNode(name);
Node node = testNode.getNode();
final String nodeURL = node.getNodeInformation().getURL();
rm.addNode(nodeURL).getBooleanValue();
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, NodeSource.DEFAULT);
rm.setNodeSourcePingFrequency(5000, NodeSource.DEFAULT);
// wait for node from configuring to free
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeURL);
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// 2) GET the same node
final long beforeGetTime = System.currentTimeMillis();
node = rm.getNodes(new Criteria(1)).get(0);
// Sleep a certain amount of time that will be the minimum amount of the GET->RELEASE duration
Thread.sleep(GR_DURATION);
// 3) Kill the node to ensure that the RM considers it as being DOWN
try {
node.getProActiveRuntime().killNode(node.getNodeInformation().getName());
} catch (Exception e) {
}
while (rm.nodeIsAvailable(nodeURL).getBooleanValue()) {
RMTHelper.log("Node is available " + nodeURL);
Thread.sleep(100);
}
final long getDownMaxDuration = System.currentTimeMillis() - beforeGetTime;
// 4) REMOVE
rm.removeNode(nodeURL, true).getBooleanValue();
// Refresh the account manager
conn.invoke(managementMBeanName, "clearAccoutingCache", null, null);
// Check account values validity
usedNodeTime = (Long) conn.getAttribute(myAccountMBeanName, "UsedNodeTime") - usedNodeTime;
Assert.assertTrue("Invalid value of the usedNodeTime attribute : " + usedNodeTime + " while expected is " + GR_DURATION, (usedNodeTime >= GR_DURATION) && (usedNodeTime <= getDownMaxDuration));
}
use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication in project scheduling by ow2-proactive.
the class AddGetTest method action.
/**
* Test function.
* @throws Exception
*/
@org.junit.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 = (RMAuthentication) 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();
// Tests on database
// (nodeprovider=demo)
// Ensure that no refreshes was done and all account values are correctly initialized
AttributeList atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
long usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue();
long providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue();
int providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue();
Assert.assertEquals("The accounts must not be refreshed automatically therefore the LastRefreshDurationInMilliseconds must be 0", (Long) 0l, (Long) conn.getAttribute(managementMBeanName, "LastRefreshDurationInMilliseconds"));
Assert.assertTrue("The usedNodeTime attribute must be 0", usedNodeTime == 0);
Assert.assertTrue("The providedNodeTime attribute must be 0", providedNodeTime == 0);
Assert.assertTrue("The providedNodesCount attribute must be 0", providedNodesCount == 0);
// ADD, GET
// 1) ADD
final long beforeAddTime = System.currentTimeMillis();
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.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// 2) GET
final long beforeGetTime = System.currentTimeMillis();
node = rm.getAtMostNodes(1, null).get(0);
// Sleep a certain amount of time that will be the minimum amount of the GET duration
Thread.sleep(GR_DURATION);
// Refresh the account manager
conn.invoke(managementMBeanName, "clearAccoutingCache", null, null);
final long currentTime = System.currentTimeMillis();
final long addRefreshMaxDuration = currentTime - beforeAddTime;
final long getRefreshMaxDuration = currentTime - beforeGetTime;
// Check account values validity
atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue();
providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue();
providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue();
Assert.assertTrue("Invalid value of the usedNodeTime attribute", (usedNodeTime >= GR_DURATION) && (usedNodeTime <= addRefreshMaxDuration));
Assert.assertTrue("Invalid value of the providedNodeTime attribute", (providedNodeTime >= usedNodeTime) && (providedNodeTime <= getRefreshMaxDuration));
Assert.assertTrue("Invalid value of the providedNodesCount attribute", (providedNodesCount == 1));
}
use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication in project scheduling by ow2-proactive.
the class GetAllNodes method main.
public static void main(String[] args) {
RMAuthentication auth;
try {
auth = RMConnection.join(RMTHelper.getLocalUrl());
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
ResourceManager rm = auth.login(cred);
NodeSet nodes = rm.getNodes(new Criteria(rm.getState().getFreeNodesNumber()));
// use nodes to block until the future is available
System.out.println("Got " + nodes.size());
} catch (Exception e) {
e.printStackTrace();
}
System.exit(1);
}
use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication in project scheduling by ow2-proactive.
the class TestConcurrentUsers method testConcurrency.
@Test
public void testConcurrency() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
String nsName = "TestConcurrentUsers";
String node1Name = "node1";
testNode = rmHelper.createNode(node1Name);
String node1URL = testNode.getNode().getNodeInformation().getURL();
resourceManager.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
resourceManager.addNode(node1URL, nsName);
// waiting for node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// waiting for the node to be free
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertTrue(resourceManager.getState().getTotalNodesNumber() == 1);
assertTrue(resourceManager.getState().getFreeNodesNumber() == 1);
log("Test 1 - releasing of the foreign node");
// acquiring a node
final NodeSet ns = resourceManager.getAtMostNodes(1, null);
// waiting for node busy event
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(evt.getNodeState(), NodeState.BUSY);
assertEquals(ns.size(), 1);
assertTrue(resourceManager.getState().getTotalNodesNumber() == 1);
assertTrue(resourceManager.getState().getFreeNodesNumber() == 0);
Thread t = new Thread() {
@Override
public void run() {
try {
Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin("user"), CredData.parseDomain("user"), "pwd"), TestConcurrentUsers.this.rmHelper.getRMAuth().getPublicKey());
ResourceManager rm2 = TestConcurrentUsers.this.rmHelper.getRMAuth().login(cred);
rm2.releaseNode(ns.get(0)).getBooleanValue();
Assert.assertTrue("Should not be able to release foreign node", false);
} catch (Exception e) {
log(e.getMessage());
}
}
};
t.start();
t.join();
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(ns);
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(evt.getNodeState(), NodeState.FREE);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 2 - releasing node twice");
resourceManager.releaseNodes(ns);
// to make sure everything has been processed
Thread.sleep(1000);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 3 - client crash detection");
JVMProcessImpl nodeProcess = new JVMProcessImpl(new org.objectweb.proactive.core.process.AbstractExternalProcess.StandardOutputMessageLogger());
nodeProcess.setJvmOptions(Collections.singletonList(PAResourceManagerProperties.RM_HOME.getCmdLine() + PAResourceManagerProperties.RM_HOME.getValueAsString()));
nodeProcess.setClassname(GetAllNodes.class.getName());
nodeProcess.startProcess();
// node busy event
for (int i = 0; i < 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(evt.getNodeState(), NodeState.BUSY);
}
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
// client does not exist anymore
log("Client does not exist anymore. Waiting for client crash detection.");
// waiting for node free event
for (int i = 0; i < 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(NodeState.FREE, evt.getNodeState());
}
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 4 - disconnecting");
NodeSet ns2 = resourceManager.getAtMostNodes(1, null);
RMNodeEvent event = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 10000);
Assert.assertTrue(event.getNodeState() == NodeState.BUSY);
PAFuture.waitFor(ns2);
log("Number of found nodes " + ns2.size());
assertEquals(1, ns2.size());
t = new Thread() {
public void run() {
try {
RMAuthentication auth = rmHelper.getRMAuth();
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.TEST.username, TestUsers.TEST.password), auth.getPublicKey());
ResourceManager rm = auth.login(cred);
rm.disconnect().getBooleanValue();
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
t.join();
try {
event = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 10000);
fail("Unexpected event: " + event);
} catch (ProActiveTimeoutException e) {
}
}
Aggregations