use of org.ow2.proactive.utils.Criteria in project scheduling by ow2-proactive.
the class SelectionManager method runScripts.
/**
* Runs scripts on given set of nodes and returns matched nodes. It blocks
* until all results are obtained.
*
* @param candidates
* nodes to execute scripts on
* @param criteria
* contains a set of scripts to execute on each node
* @return nodes matched to all scripts
*/
private List<Node> runScripts(List<RMNode> candidates, Criteria criteria) {
List<Node> matched = new LinkedList<>();
if (candidates.size() == 0) {
return matched;
}
// creating script executors object to be run in dedicated thread pool
List<Callable<Node>> scriptExecutors = new LinkedList<>();
synchronized (inProgress) {
if (inProgress.size() > 0) {
logger.warn(inProgress.size() + " nodes are in process of script execution");
for (String nodeName : inProgress) {
logger.warn(nodeName);
}
logger.warn("Something is wrong on these nodes");
}
for (RMNode node : candidates) {
if (!inProgress.contains(node.getNodeURL())) {
inProgress.add(node.getNodeURL());
scriptExecutors.add(new ScriptExecutor(node, criteria, this));
}
}
}
try {
// launching
Collection<Future<Node>> matchedNodes = scriptExecutorThreadPool.invokeAll(scriptExecutors);
// waiting for the results
for (Future<Node> futureNode : matchedNodes) {
Node node;
try {
node = futureNode.get();
if (node != null) {
matched.add(node);
}
} catch (InterruptedException e) {
logger.warn("Interrupting the selection manager");
return matched;
} catch (ExecutionException e) {
logger.warn("Ignoring exception in selection script: " + e.getMessage());
}
}
} catch (InterruptedException e1) {
logger.warn("Interrupting the selection manager");
}
return matched;
}
use of org.ow2.proactive.utils.Criteria 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.utils.Criteria in project scheduling by ow2-proactive.
the class TestLocalInfrastructureRestartDownNodesPolicy method testRestartDownNodesPolicy.
@Test
public void testRestartDownNodesPolicy() throws Exception {
nodeSourceName = "Node_source_1";
RMTHelper.log("Test 1 - restart down nodes policy");
createNodeSourceWithNodes(nodeSourceName, new Object[] { "ALL", "ALL", "10000" });
RMState stateTest1 = resourceManager.getState();
assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalNodesNumber());
assertEquals(defaultDescriptorNodesNb, stateTest1.getFreeNodesNumber());
NodeSet ns = resourceManager.getNodes(new Criteria(defaultDescriptorNodesNb));
for (Node n : ns) {
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, n.getNodeInformation().getURL());
}
String nodeUrl = ns.get(0).getNodeInformation().getURL();
// Nodes will be redeployed only if we kill the whole runtime
rmHelper.killRuntime(nodeUrl);
RMNodeEvent ev = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeUrl);
assertEquals(NodeState.DOWN, ev.getNodeState());
// one node is down - the policy should detect it and redeploy
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalNodesNumber());
assertEquals(defaultDescriptorNodesNb, stateTest1.getTotalAliveNodesNumber());
}
use of org.ow2.proactive.utils.Criteria 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.utils.Criteria in project scheduling by ow2-proactive.
the class RMCore method getNodes.
/**
* {@inheritDoc}
*/
public NodeSet getNodes(int number, TopologyDescriptor topology, List<SelectionScript> selectionScrips, NodeSet exclusion, boolean bestEffort) {
Criteria criteria = new Criteria(number);
criteria.setTopology(topology);
criteria.setScripts(selectionScrips);
criteria.setBlackList(exclusion);
criteria.setBestEffort(bestEffort);
return getNodes(criteria);
}
Aggregations