use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.
the class SelectionManager method filterOut.
/**
* Removes exclusion nodes and nodes not accessible for the client
*/
private List<RMNode> filterOut(List<RMNode> freeNodes, Criteria criteria, Client client) {
NodeSet exclusion = criteria.getBlackList();
Set<String> inclusion = criteria.getAcceptableNodesUrls();
boolean nodeWithTokenRequested = criteria.getNodeAccessToken() != null && criteria.getNodeAccessToken().length() > 0;
TokenPrincipal tokenPrincipal = null;
if (nodeWithTokenRequested) {
logger.debug("Node access token specified " + criteria.getNodeAccessToken());
tokenPrincipal = new TokenPrincipal(criteria.getNodeAccessToken());
client.getSubject().getPrincipals().add(tokenPrincipal);
}
List<RMNode> filteredList = new ArrayList<>();
HashSet<Permission> clientPermissions = new HashSet<>();
for (RMNode node : freeNodes) {
// checking the permission
try {
if (!clientPermissions.contains(node.getUserPermission())) {
client.checkPermission(node.getUserPermission(), client + " is not authorized to get the node " + node.getNodeURL() + " from " + node.getNodeSource().getName());
clientPermissions.add(node.getUserPermission());
}
} catch (SecurityException e) {
// client does not have an access to this node
logger.debug(e.getMessage());
continue;
}
// with other tokens but must also filter out nodes without tokens
if (nodeWithTokenRequested && !node.isProtectedByToken()) {
continue;
}
// we will avoid it here
if (nodeWithTokenRequested) {
PrincipalPermission perm = (PrincipalPermission) node.getUserPermission();
// checking explicitly that node has this token identity
if (!perm.hasPrincipal(tokenPrincipal)) {
if (logger.isDebugEnabled()) {
logger.debug(client + " does not have required token to get the node " + node.getNodeURL() + " from " + node.getNodeSource().getName());
}
continue;
}
}
if (!contains(exclusion, node) && ((inclusion != null) ? inclusion.contains(node.getNodeURL()) : true)) {
filteredList.add(node);
}
}
return filteredList;
}
use of org.ow2.proactive.resourcemanager.rmnode.RMNode 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.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.
the class ProbablisticSelectionManager method processScriptResult.
/**
* Processes script result and updates knowledge base of
* selection manager at the same time.
*
* @param script - executed script
* @param scriptResult - obtained script result
* @param rmnode - node on which script has been executed
* @return whether node is selected
*/
@Override
public synchronized boolean processScriptResult(SelectionScript script, Map<String, Serializable> bindings, ScriptResult<Boolean> scriptResult, RMNode rmnode) {
boolean result = false;
SelectionScript scriptWithReplacedBindings = replaceBindings(script, bindings);
try {
String digest = new String(scriptWithReplacedBindings.digest());
Probability probability = new Probability(Probability.defaultValue());
if (probabilities.containsKey(digest) && probabilities.get(digest).containsKey(rmnode.getNodeURL())) {
probability = probabilities.get(digest).get(rmnode.getNodeURL());
assert (probability.value() >= 0 && probability.value() <= 1);
}
if (scriptResult == null || scriptResult.errorOccured() || !scriptResult.getResult()) {
// error during script execution or script returned false
if (scriptWithReplacedBindings.isDynamic()) {
probability.decrease();
} else {
probability = Probability.ZERO;
}
} else {
// script passed
result = true;
if (scriptWithReplacedBindings.isDynamic()) {
probability.increase();
} else {
probability = Probability.ONE;
}
}
if (!probabilities.containsKey(digest)) {
// checking if the number of selection script does not exceeded the maximum
if (probabilities.size() >= PAResourceManagerProperties.RM_SELECT_SCRIPT_CACHE_SIZE.getValueAsInt()) {
String oldest = digestQueue.poll();
probabilities.remove(oldest);
if (logger.isDebugEnabled()) {
logger.debug("Removing the script: " + scriptWithReplacedBindings.hashCode() + " from the data base because the limit is reached");
}
}
// adding a new script record
probabilities.put(digest, new HashMap<String, Probability>());
logger.debug("Scripts cache size " + probabilities.size());
digestQueue.offer(digest);
}
if (logger.isDebugEnabled()) {
logger.debug(rmnode.getNodeURL() + " : script " + scriptWithReplacedBindings.hashCode() + ", probability " + probability);
}
probabilities.get(digest).put(rmnode.getNodeURL().intern(), probability);
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage(), e);
}
return result;
}
use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.
the class ProbablisticSelectionManager method arrangeNodesForScriptExecution.
/**
* Find appropriate candidates nodes for script execution, taking into
* account "free" and "exclusion" nodes lists.
*
* @param scripts set of scripts to execute
* @param nodes free nodes list provided by resource manager
* @return candidates node list for script execution
*/
@Override
public List<RMNode> arrangeNodesForScriptExecution(final List<RMNode> nodes, List<SelectionScript> scripts, Map<String, Serializable> bindings) {
long startTime = System.currentTimeMillis();
boolean scriptSpecified = scripts != null && scripts.size() > 0;
// if no scripts are specified return filtered free nodes
if (!scriptSpecified) {
return nodes;
}
try {
// finding intersection
HashMap<RMNode, Probability> intersectionMap = new LinkedHashMap<>();
for (RMNode rmnode : nodes) {
boolean intersection = true;
double intersectionProbability = 1;
for (SelectionScript script : scripts) {
SelectionScript scriptWithReplacedBindings = replaceBindings(script, bindings);
String digest = new String(scriptWithReplacedBindings.digest());
if (probabilities.containsKey(digest) && probabilities.get(digest).containsKey(rmnode.getNodeURL())) {
double probability = probabilities.get(digest).get(rmnode.getNodeURL()).value();
if (probability == 0) {
intersection = false;
break;
} else {
intersectionProbability *= probability;
}
} else {
intersectionProbability *= Probability.defaultValue();
}
}
if (intersection) {
intersectionMap.put(rmnode, new Probability(intersectionProbability));
}
}
// sorting results based on calculated probability
Set<RMNode> nodeSet = intersectionMap.keySet();
List<RMNode> res = new ArrayList<>(nodeSet.size());
res.addAll(nodeSet);
Collections.sort(res, new NodeProbabilityComparator(intersectionMap));
if (logger.isDebugEnabled()) {
logger.debug("The following nodes are selected for scripts execution (time is " + (System.currentTimeMillis() - startTime) + " ms) :");
if (res.size() > 0) {
for (RMNode rmnode : res) {
logger.debug(rmnode.getNodeURL() + " : probability " + intersectionMap.get(rmnode));
}
} else {
logger.debug("None");
}
}
return res;
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage(), e);
return new ArrayList<>(0);
}
}
use of org.ow2.proactive.resourcemanager.rmnode.RMNode in project scheduling by ow2-proactive.
the class NodesLockRestorationManagerTest method testLockNodeSucceeds.
@Test
public void testLockNodeSucceeds() {
doReturn(new BooleanWrapper(true)).when(rmCore).lockNodes(anySetOf(String.class), eq(caller));
verify(rmCore, never()).lockNodes(anySetOf(String.class), eq(caller));
RMNode rmNode = RMNodeHelper.basicWithMockedInternals().getLeft();
boolean lockResult = nodesLockRestorationManager.lockNode(rmNode, caller);
assertThat(lockResult).isTrue();
verify(rmCore).lockNodes(anySetOf(String.class), eq(caller));
}
Aggregations