use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.
the class RMCore method internalSetFree.
/**
* Change the state of the node to free, after a Task has been completed by the specified node.
* The node passed as parameter is moved to the list of nodes which are eligible for scheduling if it is not locked.
* In all cases, an event informing the node state's change is propagated to RMMonitoring.
*
* @param rmNode node to set free.
* @return true if the node successfully set as free, false if it was down before.
*/
@VisibleForTesting
BooleanWrapper internalSetFree(final RMNode rmNode) {
if (logger.isDebugEnabled()) {
logger.debug("Current node state " + rmNode.getState() + " " + rmNode.getNodeURL());
logger.debug("Setting node state to free " + rmNode.getNodeURL());
}
// If the node is already free no need to go further
if (rmNode.isFree()) {
return new BooleanWrapper(true);
}
// Get the previous state of the node needed for the event
final NodeState previousNodeState = rmNode.getState();
Client client = rmNode.getOwner();
if (client == null) {
// node has been just configured, so the user initiated this action is the node provider
client = rmNode.getProvider();
}
// resetting owner here
rmNode.setFree();
// an eligible node is a node that is free and not locked
if (!rmNode.isLocked()) {
this.eligibleNodes.add(rmNode);
}
persistUpdatedRMNodeIfRecoveryEnabled(rmNode);
this.registerAndEmitNodeEvent(rmNode.createNodeEvent(RMEventType.NODE_STATE_CHANGED, previousNodeState, client.getName()));
return new BooleanWrapper(true);
}
use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.
the class RMCore method releaseNodes.
/**
* {@inheritDoc}
*/
public BooleanWrapper releaseNodes(NodeSet nodes) {
if (nodes.getExtraNodes() != null) {
// do not forget to release extra nodes
nodes.addAll(nodes.getExtraNodes());
}
// exception to throw in case of problems
RuntimeException exception = null;
NodeSet nodesReleased = new NodeSet();
NodeSet nodesFailedToRelease = new NodeSet();
for (Node node : nodes) {
String nodeURL = null;
try {
nodeURL = node.getNodeInformation().getURL();
logger.debug("Releasing node " + nodeURL);
} catch (RuntimeException e) {
logger.debug("A Runtime exception occurred while obtaining information on the node," + "the node must be down (it will be detected later)", e);
// node is down, will be detected by pinger
exception = new IllegalStateException(e.getMessage(), e);
nodesFailedToRelease.add(node);
}
// verify whether the node has not been removed from the RM
if (this.allNodes.containsKey(nodeURL)) {
RMNode rmnode = this.getNodebyUrl(nodeURL);
// free
if (rmnode.isFree()) {
logger.warn("Client " + caller + " tries to release the already free node " + nodeURL);
nodesFailedToRelease.add(node);
} else if (rmnode.isDown()) {
logger.warn("Node was down, it cannot be released");
nodesFailedToRelease.add(node);
} else {
Set<? extends IdentityPrincipal> userPrincipal = rmnode.getOwner().getSubject().getPrincipals(UserNamePrincipal.class);
Permission ownerPermission = new PrincipalPermission(rmnode.getOwner().getName(), userPrincipal);
try {
caller.checkPermission(ownerPermission, caller + " is not authorized to free node " + node.getNodeInformation().getURL());
if (rmnode.isToRemove()) {
removeNodeFromCoreAndSource(rmnode, caller);
nodesReleased.add(node);
} else {
internalSetFree(rmnode);
nodesReleased.add(node);
}
} catch (SecurityException ex) {
logger.error(ex.getMessage(), ex);
nodesFailedToRelease.add(node);
exception = ex;
}
}
} else {
logger.warn("Cannot release unknown node " + nodeURL);
nodesFailedToRelease.add(node);
exception = new IllegalArgumentException("Cannot release unknown node " + nodeURL);
}
}
logger.info("Nodes released : " + nodesReleased);
if (!nodesFailedToRelease.isEmpty()) {
logger.warn("Nodes failed to release : " + nodesFailedToRelease);
}
if (exception != null) {
// throwing the latest exception we had
throw exception;
}
return new BooleanWrapper(true);
}
use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.
the class RMCore method undeployNodeSource.
/**
* {@inheritDoc}
*/
public BooleanWrapper undeployNodeSource(String nodeSourceName, boolean preempt) {
if (!this.definedNodeSources.containsKey(nodeSourceName)) {
throw new IllegalArgumentException("Unknown node source " + nodeSourceName);
}
if (this.deployedNodeSources.containsKey(nodeSourceName)) {
NodeSource nodeSourceToRemove = this.deployedNodeSources.get(nodeSourceName);
this.caller.checkPermission(nodeSourceToRemove.getAdminPermission(), this.caller + " is not authorized to remove " + nodeSourceName);
logger.info("Undeploy node source " + nodeSourceName + " with preempt=" + preempt + REQUESTED_BY_STRING + this.caller.getName());
nodeSourceToRemove.setStatus(NodeSourceStatus.NODES_UNDEPLOYED);
this.removeAllNodes(nodeSourceName, preempt);
// delegate the removal process to the node source that will
// eventually call back the RMCore to unregister the deployed node
// source
nodeSourceToRemove.shutdown(this.caller);
this.updateNodeSourceDescriptorWithStatusAndPersist(this.definedNodeSources.get(nodeSourceName).getDescriptor(), NodeSourceStatus.NODES_UNDEPLOYED);
logger.info(NODE_SOURCE_STRING + nodeSourceName + " has been successfully undeployed");
}
return new BooleanWrapper(true);
}
use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.
the class RMCore method shutdown.
/**
* Shutdown the resource manager
*/
public BooleanWrapper shutdown(boolean preempt) {
// this method could be called twice from shutdown hook and user action
if (toShutDown)
return new BooleanWrapper(false);
logger.info("RMCore shutdown request");
this.monitoring.rmEvent(new RMEvent(RMEventType.SHUTTING_DOWN));
this.toShutDown = true;
if (PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean() || this.deployedNodeSources.size() == 0) {
finalizeShutdown();
} else {
for (Entry<String, NodeSource> entry : this.deployedNodeSources.entrySet()) {
removeAllNodes(entry.getKey(), preempt, true);
entry.getValue().shutdown(caller);
}
}
return new BooleanWrapper(true);
}
use of org.objectweb.proactive.core.util.wrapper.BooleanWrapper in project scheduling by ow2-proactive.
the class RMCore method setFreeNodes.
/**
* Mark nodes as free after cleaning procedure.
*
* @param nodes to be free
* @return true if all successful, false if there is a down node among nodes
*/
public BooleanWrapper setFreeNodes(List<RMNode> nodes) {
boolean result = true;
for (RMNode node : nodes) {
// getting the correct instance
RMNode rmnode = this.getNodebyUrl(node.getNodeURL());
// freeing it
result &= internalSetFree(rmnode).getBooleanValue();
}
return new BooleanWrapper(result);
}
Aggregations