use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class RestartDownNodesPolicy method activate.
/**
* Activates static policy. Register a listener in RMMonitoring
*/
@Override
public BooleanWrapper activate() {
acquireAllNodes();
timer.schedule(new TimerTask() {
@Override
public void run() {
int numberOfNodesToDeploy = 0;
for (Node downNode : nodeSource.getDownNodes()) {
String nodeUrl = downNode.getNodeInformation().getURL();
logger.info("Removing down node " + nodeUrl);
BooleanWrapper removed = nodeSource.getRMCore().removeNode(nodeUrl, true);
if (removed.getBooleanValue()) {
logger.info("Down node removed " + nodeUrl);
numberOfNodesToDeploy++;
}
}
for (RMDeployingNode lostNode : nodeSource.getDeployingAndLostNodes()) {
if (!lostNode.isLost()) {
continue;
}
String nodeUrl = lostNode.getNodeURL();
logger.info("Removing lost node " + nodeUrl);
BooleanWrapper removed = nodeSource.getRMCore().removeNode(nodeUrl, true);
if (removed.getBooleanValue()) {
logger.info("Lost node removed " + nodeUrl);
numberOfNodesToDeploy++;
}
}
if (numberOfNodesToDeploy > 0) {
logger.info("Acquiring " + numberOfNodesToDeploy + " nodes");
acquireNodes(numberOfNodesToDeploy);
}
}
}, checkNodeStateEach, checkNodeStateEach);
return new BooleanWrapper(true);
}
use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class TopologyManager method getNodeSetWithExtraNodes.
private NodeSet getNodeSetWithExtraNodes(Set<Node> nodes, int numberOfNodesToExtract) {
Set<Node> main = subListLHS(nodes, 0, numberOfNodesToExtract);
Set<Node> extra = subListLHS(nodes, numberOfNodesToExtract, nodes.size());
NodeSet result = new NodeSet(main);
result.setExtraNodes(extra);
return result;
}
use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class TopologyManager method removeNode.
/**
* Node is removed or down. Method removes corresponding topology information.
*/
public void removeNode(Node node) {
try {
rwLock.writeLock().lock();
if (!PAResourceManagerProperties.RM_TOPOLOGY_ENABLED.getValueAsBoolean()) {
// do not do anything if topology disabled
return;
}
if (logger.isDebugEnabled()) {
logger.debug("Removing Node " + node.getNodeInformation().getURL() + " from topology");
}
InetAddress host = node.getVMInformation().getInetAddress();
if (!topology.knownHost(host)) {
logger.warn("Topology info does not exist for node " + node.getNodeInformation().getURL());
} else {
Set<Node> nodes = nodesOnHost.get(host);
nodes.remove(node);
if (nodes.isEmpty()) {
// no more nodes on the host
topology.removeHostTopology(node.getVMInformation().getHostName(), host);
nodesOnHost.remove(host);
}
}
} finally {
rwLock.writeLock().unlock();
}
if (logger.isDebugEnabled()) {
logger.debug("Node " + node.getNodeInformation().getURL() + " removed.");
}
}
use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class ResourceManagerJMXTest method jmxRMIAsUser.
private void jmxRMIAsUser(JMXServiceURL jmxRmiServiceURL, ObjectName allAccountsMBeanName, ObjectName myAccountMBeanName, ObjectName runtimeDataMBeanName) throws Exception {
// Tests as user over RMI
RMTHelper.log("Test as user 1 - Auth with login/pass over RMI and check connection");
// Create the environment
final HashMap<String, Object> env = new HashMap<>(1);
env.put(JMXConnector.CREDENTIALS, new Object[] { TestUsers.DEMO.username, TestUsers.DEMO.password });
// Connect to the JMX RMI Connector Server
final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
// Check that the MBean Server connection is not null
assertNotNull("Unable to obtain the MBean server connection over RMI", conn);
RMTHelper.log("Test as user 2 - Check MyAccountMBean is registered in the MBean server");
assertTrue("MyAccountMBean must be registered in the MBean server", conn.isRegistered(myAccountMBeanName));
RMTHelper.log("Test as user 3 - Check MyAccountMBean attributes do not throw exceptions");
final MBeanInfo info = conn.getMBeanInfo(myAccountMBeanName);
for (final MBeanAttributeInfo att : info.getAttributes()) {
final String attName = att.getName();
try {
conn.getAttribute(myAccountMBeanName, attName);
} catch (Exception e) {
fail("The attribute " + attName + " of MyAccountMBean must not throw " + e);
}
}
RMTHelper.log("Test as user 3 - Check RuntimeDataMBean is registered in the MBean server");
assertTrue("RuntimeDataMBean must be registered in the MBean server", conn.isRegistered(runtimeDataMBeanName));
RMTHelper.log("Test as user 4 - Check RuntimeDataMBean attributes are correct");
// Start a new node and add it to the rmHelper
testNode = rmHelper.createNode("test");
final Node node = testNode.getNode();
final String nodeURL = node.getNodeInformation().getURL();
// force sync, now the node is in configuring state
rmHelper.getResourceManager().addNode(nodeURL).getBooleanValue();
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
// We eat configuring to free events
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// Get all attributes to test
AttributeList list = conn.getAttributes(runtimeDataMBeanName, new String[] { "Status", "AvailableNodesCount", "FreeNodesCount" });
// Check RMStatus
Attribute attribute = (Attribute) list.get(0);
assertEquals("Incorrect value of " + attribute.getName() + " attribute", "STARTED", attribute.getValue());
// Check AvailableNodesCount
attribute = (Attribute) list.get(1);
assertEquals("Incorrect value of " + attribute.getName() + " attribute", 1, attribute.getValue());
// Check FreeNodesCount
attribute = (Attribute) list.get(2);
assertEquals("Incorrect value of " + attribute.getName() + " attribute", 1, attribute.getValue());
rmHelper.getResourceManager().removeNode(nodeURL, false);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, nodeURL);
// Get all attributes to test
list = conn.getAttributes(runtimeDataMBeanName, new String[] { "AvailableNodesCount", "FreeNodesCount" });
// Check AvailableNodesCount
attribute = (Attribute) list.get(0);
assertEquals("Incorrect value of " + attribute.getName() + " attribute", 0, attribute.getValue());
// Check FreeNodesCount
attribute = (Attribute) list.get(1);
assertEquals("Incorrect value of " + attribute.getName() + " attribute", 0, attribute.getValue());
RMTHelper.log("Test as user 5 - Check AllAccountsMBean attributes are not accessible");
final MBeanInfo mBeanInfo = conn.getMBeanInfo(allAccountsMBeanName);
for (final MBeanAttributeInfo att : mBeanInfo.getAttributes()) {
final String attName = att.getName();
try {
conn.getAttribute(allAccountsMBeanName, attName);
} catch (Exception e) {
assertTrue("The attribute " + attName + " must not be accessible with user-level permissions", e instanceof RuntimeException);
}
}
jmxConnector.close();
}
use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class AddGetReleaseRemoveTest 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();
// 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();
// ADD, GET, RELEASE, REMOVE
// 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 event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeURL);
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// 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->RELEASE duration
Thread.sleep(GR_DURATION);
// 3) RELEASE
rm.releaseNode(node).getBooleanValue();
final long getReleaseMaxDuration = System.currentTimeMillis() - beforeGetTime;
// 4) REMOVE
rm.removeNode(nodeURL, true).getBooleanValue();
final long addRemoveMaxDuration = System.currentTimeMillis() - beforeAddTime;
// Refresh the account manager
conn.invoke(managementMBeanName, "clearAccoutingCache", null, null);
// Check account values validity
atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue() - usedNodeTime;
providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue() - providedNodeTime;
providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue() - providedNodesCount;
Assert.assertTrue("Invalid value of the usedNodeTime attribute (usedNodeTime=" + usedNodeTime + ")", (usedNodeTime >= GR_DURATION));
Assert.assertTrue("Invalid value of the usedNodeTime attribute (getReleaseMaxDuration=" + getReleaseMaxDuration + ")", (usedNodeTime <= getReleaseMaxDuration));
Assert.assertTrue("Invalid value of the providedNodeTime attribute", (providedNodeTime >= usedNodeTime) && (providedNodeTime <= addRemoveMaxDuration));
}
Aggregations