use of org.ow2.proactive.resourcemanager.exception.AddingNodesException in project scheduling by ow2-proactive.
the class RMNodeStarter method addNodeToResourceManager.
private void addNodeToResourceManager(String rmURL, Node node, ResourceManager rm) {
// Add the created node to the Resource Manager with a specified
// number of attempts and a timeout between each attempt
boolean isNodeAdded = false;
int attempts = 0;
String nodeUrl = node.getNodeInformation().getURL();
String nodeName = node.getNodeInformation().getName();
logger.info("Adding node " + nodeName + " to Resource Manager.");
while ((!isNodeAdded) && (attempts < NB_OF_ADD_NODE_ATTEMPTS)) {
attempts++;
try {
if (this.nodeSourceName != null) {
isNodeAdded = rm.addNode(nodeUrl, this.nodeSourceName).getBooleanValue();
} else {
isNodeAdded = rm.addNode(nodeUrl).getBooleanValue();
}
} catch (AddingNodesException addException) {
addException.printStackTrace();
System.exit(ExitStatus.RMNODE_ADD_ERROR.exitCode);
}
if (isNodeAdded) {
if (removePrevious) {
// try to remove previous URL if different...
String previousURL = this.getAndDeleteNodeURL(nodeName, rank);
if (previousURL != null && !previousURL.equals(nodeUrl)) {
logger.info("Different previous URL registered by this agent has been found. Remove previous registration.");
rm.removeNode(previousURL, true);
}
// store the node URL
this.storeNodeURL(nodeName, rank, nodeUrl);
logger.info("Node " + nodeUrl + " added. URL is stored in " + getNodeURLFilename(nodeName, rank));
} else {
logger.info("Node " + nodeUrl + " added.");
}
} else {
// not yet registered
logger.info("Attempt number " + attempts + " out of " + NB_OF_ADD_NODE_ATTEMPTS + " to add the local node to the Resource Manager at " + rmURL + " has failed.");
try {
Thread.sleep(ADD_NODE_ATTEMPTS_DELAY_IN_MS);
} catch (InterruptedException e) {
logger.info("Interrupted", e);
}
}
}
if (!isNodeAdded) {
// if not registered
logger.error("The Resource Manager was unable to add the local node " + nodeUrl + " after " + NB_OF_ADD_NODE_ATTEMPTS + " attempts. The application will exit.");
System.exit(ExitStatus.RMNODE_ADD_ERROR.exitCode);
}
}
use of org.ow2.proactive.resourcemanager.exception.AddingNodesException in project scheduling by ow2-proactive.
the class NodeSource method acquireNode.
/**
* Acquires the existing node with specific url. The node have to be up and running.
*
* @param nodeUrl the url of the node
* @param provider
*/
public BooleanWrapper acquireNode(String nodeUrl, Client provider) {
if (toShutdown) {
throw new AddingNodesException("[" + name + "] node " + nodeUrl + " adding request discarded because node source is shutting down");
}
// checking that client has a right to change this node source
// if the provider is the administrator of the node source it always has this permission
provider.checkPermission(providerPermission, provider + " is not authorized to add node " + nodeUrl + " to " + name);
// lookup for a new Node
int lookUpTimeout = PAResourceManagerProperties.RM_NODELOOKUP_TIMEOUT.getValueAsInt();
Node nodeToAdd = null;
try {
logger.info("Looking up the node " + nodeUrl + " with " + lookUpTimeout + " ms timeout");
nodeToAdd = lookupNode(nodeUrl, lookUpTimeout);
logger.info("The node " + nodeUrl + " has been successfully looked up");
} catch (Exception e) {
logger.warn("Cannot look up the node " + nodeUrl + " within " + lookUpTimeout + " ms due to " + e.getMessage(), e);
throw new AddingNodesException(e);
}
// node should be not null at this point...
if (nodeToAdd == null) {
throw new AddingNodesException("Cannot lookup node for unknown reason : " + nodeUrl);
}
// now checking if this node has been registered before in the node source
if (downNodes.containsKey(nodeUrl)) {
// it was registered but detected as down node,
// so basically the node was restarted.
// adding a new node and removing old one from the down list
logger.debug("Removing existing node from down nodes list");
BooleanWrapper result = rmcore.removeNodeFromCore(nodeUrl);
if (result.getBooleanValue()) {
if (logger.isDebugEnabled())
logger.debug("[" + name + "] successfully removed node " + nodeUrl + " from the core");
// just removing it from down nodes list
removeNode(nodeUrl, provider);
}
} else if (nodes.containsKey(nodeUrl)) {
// adding a node which exists in node source
Node existingNode = nodes.get(nodeUrl);
if (nodeToAdd.equals(existingNode)) {
// don't do anything
if (logger.isDebugEnabled())
logger.debug("An attempt to add the same node twice " + nodeUrl + " - ignoring");
return new BooleanWrapper(false);
} else {
// adding another node with the same url
// replacing the old node by the new one
logger.debug("Removing existing node from the RM without request propagation to the infrastructure manager");
BooleanWrapper result = rmcore.removeNodeFromCore(nodeUrl);
if (result.getBooleanValue()) {
if (logger.isDebugEnabled())
logger.debug("[" + name + "] successfully removed node " + nodeUrl + " from the core");
// removing it from the nodes list but don't propagate
// the request the the infrastructure because the restarted node will be killed
nodes.remove(nodeUrl);
}
}
}
// if any exception occurs in internalAddNode(node) do not add the node to the core
RMDeployingNode deployingNode;
try {
deployingNode = internalAddNode(nodeToAdd);
} catch (RMException e) {
throw new AddingNodesException(e);
}
// we build the rmnode
RMNode rmNode = buildRMNode(nodeToAdd, provider);
if (deployingNode != null) {
// inherit locking status from associated deploying node created before
((AbstractRMNode) rmNode).copyLockStatusFrom(deployingNode);
}
boolean isNodeAdded = rmcore.registerAvailableNode(rmNode).getBooleanValue();
if (isNodeAdded) {
// if the node is successfully added we can let it configure
// asynchronously. It will then be seen as "configuring"
rmcore.internalRegisterConfiguringNode(rmNode);
return new BooleanWrapper(true);
} else {
return new BooleanWrapper(false);
}
}
use of org.ow2.proactive.resourcemanager.exception.AddingNodesException in project scheduling by ow2-proactive.
the class NodeSource method buildRMNode.
/**
* Builds a RMNode from a raw Node
* @param node the node object
* @param provider the client of the request
* @return the expected RMNode
*/
private RMNode buildRMNode(Node node, Client provider) {
// creating a node access permission
// it could be either PROVIDER/PROVIDER_GROUPS and in this case
// the provider principals will be taken or
// ME/MY_GROUPS (ns creator/ns creator groups) and in this case
// creator's principals will be used
Client permissionOwner = administrator;
if (nodeUserAccessType.equals(AccessType.PROVIDER) || nodeUserAccessType.equals(AccessType.PROVIDER_GROUPS)) {
permissionOwner = provider;
}
// now selecting the type (user or group) and construct the permission
Set<IdentityPrincipal> principals = (Set<IdentityPrincipal>) nodeUserAccessType.getIdentityPrincipals(permissionOwner);
boolean tokenInNode = false;
boolean tokenInNodeSource = nodeUserAccessType.getTokens() != null && nodeUserAccessType.getTokens().length > 0;
try {
String nodeAccessToken = node.getProperty(RMNodeStarter.NODE_ACCESS_TOKEN);
tokenInNode = nodeAccessToken != null && nodeAccessToken.length() > 0;
if (tokenInNode) {
logger.debug("Node " + node.getNodeInformation().getURL() + " is protected by access token " + nodeAccessToken);
// it overrides all other principals
principals.clear();
principals.add(new TokenPrincipal(nodeAccessToken));
}
} catch (Exception e) {
throw new AddingNodesException(e);
}
PrincipalPermission nodeAccessPermission = new PrincipalPermission(node.getNodeInformation().getURL(), principals);
RMNodeImpl rmnode = new RMNodeImpl(node, stub, provider, nodeAccessPermission);
rmnode.setProtectedByToken(tokenInNode || tokenInNodeSource);
return rmnode;
}
use of org.ow2.proactive.resourcemanager.exception.AddingNodesException in project scheduling by ow2-proactive.
the class RMCore method internalAddNodeToCore.
/**
* Internal operation of registering a new node in the Core
* This step is done after node configuration ran by {@link RMNodeConfigurator} active object.
*
* @param configuredNode the node that is going to be added.
*/
public void internalAddNodeToCore(RMNode configuredNode) {
String nodeURL = configuredNode.getNodeURL();
if (!this.allNodes.containsKey(nodeURL)) {
// does nothing, the node has been removed preemptively
// during its configuration
logger.debug("internalAddNodeToCore returned immediately because the node " + nodeURL + " was not known");
return;
}
// was added during internalRegisterConfiguringNode
RMNode rmnode = this.allNodes.get(nodeURL);
registerAvailableNode(configuredNode);
if (toShutDown) {
logger.warn("Node " + rmnode.getNodeURL() + " will not be added to the core as the resource manager is shutting down");
removeNodeFromCoreAndSource(rmnode, rmnode.getProvider());
return;
}
// noinspection ConstantConditions
if (isNumberOfNodesLimited() && isMaximumNumberOfNodesReachedIncludingAskingNode()) {
logger.warn("Node " + rmnode.getNodeURL() + " is removed because the Resource Manager is limited to " + maximumNumberOfNodes + " nodes." + CONTACT_UPGRADE_MESSAGE);
removeNodeFromCoreAndSource(rmnode, rmnode.getProvider());
throw new AddingNodesException("Maximum number of nodes reached: " + maximumNumberOfNodes + ". " + CONTACT_UPGRADE_MESSAGE);
}
// during the configuration process, the rmnode can be removed. Its state would be toRemove
if (rmnode.isToRemove()) {
removeNodeFromCoreAndSource(rmnode, rmnode.getProvider());
return;
}
// discarding the registration
if (rmnode.isDown()) {
logger.debug("internalAddNodeToCore returned immediately because the node " + nodeURL + " is already down");
return;
}
internalSetFree(configuredNode);
}
Aggregations