use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class HAC method select.
/**
* Selects a set of closest nodes from specified list.
* The proximity between nodes is defined by distance function.
*
* @param number desired nodes number
* @param from list of "free" nodes
* @return list of nodes to be provided to the client
*/
public List<Node> select(int number, List<Node> from) {
if (from.size() == 0) {
// return empty list
return new LinkedList<>();
}
// initializing cluster distances map
// cluster is a group of nodes, initially each cluster consist of one node
logger.debug("Initializing clusters map");
HashMap<Cluster<Node>, HashMap<Cluster<Node>, Long>> clusterDistances = initClusterDistances(from);
// no topology information for provided nodes
if (from.size() > 0 && clusterDistances.size() == 0) {
throw new TopologyException("Topology information is not available");
}
Cluster<Node> target = null;
if (pivot.size() > 0) {
// fixed orientation clustering
Iterator<Node> it = pivot.iterator();
Node pivotNode = it.next();
target = new Cluster<>(getNodeId(pivotNode), pivotNode);
// merging pivot nodes into one cluster and recalculating distances
logger.debug("Merging pivot nodes into one cluster");
while (it.hasNext()) {
// merging clusters and recalculating distances between others
pivotNode = it.next();
Cluster<Node> pivotCluster = new Cluster<>(getNodeId(pivotNode), pivotNode);
target = recalculateDistances(target, pivotCluster, clusterDistances);
}
// clustering centralized to the pivot
logger.debug("Begin centralized hierarchical agglomerative clustering");
while (clusterDistances.size() > 1 && target.size() < (number + pivot.size())) {
Cluster<Node> closest = findClosestClustersTo(target, clusterDistances);
if (closest == null) {
// no clusters found => cannot merge anything => stop where we are
break;
}
// merging clusters and recalculating distances between others
target = recalculateDistances(target, closest, clusterDistances);
}
// removing pivot nodes from the result
target.remove(pivot);
} else {
logger.debug("Begin hierarchical agglomerative clustering");
target = (Cluster<Node>) clusterDistances.keySet().iterator().next();
Cluster<Node> largest = target;
// floating clustering
while (clusterDistances.size() > 1) {
// finding two clusters to merge according
Cluster<Node>[] clustersToMerge = findClosestClusters(clusterDistances);
if (clustersToMerge == null) {
// stop the process
break;
}
// merging clusters and recalculating distances between others
target = recalculateDistances(clustersToMerge[0], clustersToMerge[1], clusterDistances);
if (target.size() >= largest.size()) {
largest = target;
}
if (target.size() == number) {
// found all the nodes we need
break;
} else if (target.size() > number) {
// found more nodes that we need,
// target cluster contains all nodes from another cluster
// largest is the target here
logger.debug("Number of node in the cluster exceeded required node number " + target.size() + " vs " + number);
Cluster<Node> anotherCluster = clustersToMerge[0] == target ? clustersToMerge[1] : clustersToMerge[0];
target.removeLast(anotherCluster.size());
final Cluster<Node> finalTarget = target;
Comparator<Node> nodeDistanceComparator = new Comparator<Node>() {
public int compare(Node n1, Node n2) {
long res = getDistance(n1, finalTarget) - getDistance(n2, finalTarget);
if (res < 0) {
return -1;
} else if (res > 0) {
return 1;
} else {
return 0;
}
}
};
// sorting nodes in the smaller cluster according to their distances to target
Collections.sort(anotherCluster.getElements(), nodeDistanceComparator);
int neededNodesNumber = number - target.size();
target.add(anotherCluster.getElements().subList(0, neededNodesNumber));
break;
}
}
target = largest;
}
if (logger.isDebugEnabled()) {
logger.debug("Found " + target.size() + " nodes out of " + number + ": " + target);
}
return target.getElements();
}
use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class NodesPinger method ping.
/**
* Pings remote nodes and returns distances to hosts where these nodes are located.
*
* @param nodes to ping
* @return distances map to hosts where these nodes are located
*/
public HashMap<InetAddress, Long> ping(NodeSet nodes) {
HashMap<InetAddress, Long> results = new HashMap<>();
for (Node node : nodes) {
try {
InetAddress current = NodeFactory.getDefaultNode().getVMInformation().getInetAddress();
InetAddress nodeAddress = node.getVMInformation().getInetAddress();
if (current.equals(nodeAddress)) {
// nodes on the same host
results.put(nodeAddress, new Long(0));
} else {
results.put(nodeAddress, pingNode(node));
}
} catch (NodeException e) {
}
}
return results;
}
use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class DataSpaceNodeConfigurationAgent method configureNode.
public boolean configureNode() {
try {
Node node = PAActiveObject.getActiveObjectNode(PAActiveObject.getStubOnThis());
logger.info("Start configuration of data space for node " + node.getNodeInformation().getURL());
// configure node for Data Spaces
String baseScratchDir = getBaseScratchDir();
final BaseScratchSpaceConfiguration scratchConf = new BaseScratchSpaceConfiguration((String) null, baseScratchDir);
DataSpacesNodes.configureNode(node, scratchConf);
logger.info("Data space configuration for node " + node.getNodeInformation().getURL() + " successful");
} catch (Throwable t) {
logger.error("Cannot configure dataSpace", t);
return false;
}
startCacheSpace();
return true;
}
use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class RMNodeStarter method createLocalNode.
/**
* Creates the node with the name given as parameter and returns it.
* @param nodeName The expected name of the node
* @return the newly created node.
*/
protected Node createLocalNode(String nodeName) {
Node localNode = null;
try {
localNode = NodeFactory.createLocalNode(nodeName, false, null, nodeName + "vnname");
if (localNode == null) {
logger.error(ExitStatus.RMNODE_NULL.description);
System.exit(ExitStatus.RMNODE_NULL.exitCode);
}
// setting system properties to node (they will be accessible remotely)
for (Object key : System.getProperties().keySet()) {
localNode.setProperty(key.toString(), System.getProperty(key.toString()));
}
} catch (Throwable t) {
logger.error("Unable to create the local node " + nodeName, t);
System.exit(ExitStatus.RMNODE_ADD_ERROR.exitCode);
}
return localNode;
}
use of org.objectweb.proactive.core.node.Node in project scheduling by ow2-proactive.
the class RMNodeStarter method registerInRM.
/**
* Tries to join to the Resource Manager with a specified timeout
* at the given URL, logs with provided credentials and adds the local node to
* the Resource Manager. Handles all errors/exceptions.
*/
protected ResourceManager registerInRM(final Credentials credentials, final String rmURL, final String nodeName, final Collection<Node> nodes) {
RMAuthentication auth = joinResourceManager(rmURL);
final ResourceManager rm = loginToResourceManager(credentials, auth);
SigarExposer sigarExposer = null;
if (!disabledMonitoring) {
// initializing JMX server with Sigar beans
sigarExposer = new SigarExposer(nodeName);
final RMAuthentication rmAuth = auth;
sigarExposer.boot(auth, false, new PermissionChecker() {
@Override
public boolean checkPermission(Credentials cred) {
ResourceManager rm = null;
try {
rm = rmAuth.login(cred);
if (NB_OF_ADD_NODE_ATTEMPTS == 0)
return true;
boolean isAdmin = rm.isNodeAdmin(nodes.iterator().next().getNodeInformation().getURL()).getBooleanValue();
if (!isAdmin) {
throw new SecurityException("Permission denied");
}
return true;
} catch (LoginException e) {
throw new SecurityException(e);
} finally {
if (rm != null) {
rm.disconnect();
}
}
}
});
} else {
logger.info("JMX monitoring is disabled.");
}
for (final Node node : nodes) {
nodeSetJmxUrl(sigarExposer, node);
addNodeToResourceManager(rmURL, node, rm);
}
return rm;
}
Aggregations