use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class NodesRecoveryManager method recoverNodeInternally.
private RMNode recoverNodeInternally(NodeSource nodeSource, RMNodeData rmNodeData, String nodeUrl, Node node) {
RMNode rmNode = null;
// information to the node data retrieved in database.
if (rmNodeData.equalsToNode(node)) {
logger.info("Node to recover could successfully be looked up at URL: " + nodeUrl);
rmNode = nodeSource.internalAddNodeAfterRecovery(node, rmNodeData);
this.rmCore.registerAvailableNode(rmNode);
} else {
logger.error("The node that has been looked up does not have the same information as the node to recover: " + node.getNodeInformation().getName() + " is not equal to " + rmNodeData.getName() + " or " + node.getNodeInformation().getURL() + " is not equal to " + rmNodeData.getNodeUrl());
}
return rmNode;
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class NodesRecoveryManager method recoverRMNode.
private RMNode recoverRMNode(NodeSource nodeSource, Map<NodeState, Integer> nodeStates, RMNodeData rmNodeData, String nodeUrl, Node node) {
RMNode rmnode = null;
if (node != null) {
rmnode = this.recoverNodeInternally(nodeSource, rmNodeData, nodeUrl, node);
this.nodesLockRestorationManager.handle(rmnode, rmNodeData.getProvider());
this.updateRecoveredNodeStateCounter(nodeStates, rmnode.getState());
} else {
// the node is not recoverable and does not appear in any data
// structures: we can remove it safely from database
this.rmCore.getDbManager().removeNode(rmNodeData, rmNodeData.getNodeSource().getName());
this.markNodesNotInDeployingStateAsDown(nodeSource, rmNodeData, nodeUrl);
this.updateRecoveredNodeStateCounter(nodeStates, NodeState.DOWN);
}
return rmnode;
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class DefineNodeSourceCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
QueryStringBuilder infrastructure = currentContext.getProperty(SET_INFRASTRUCTURE, QueryStringBuilder.class);
QueryStringBuilder policy = currentContext.getProperty(SET_POLICY, QueryStringBuilder.class);
if (infrastructure == null) {
throw new CLIException(REASON_INVALID_ARGUMENTS, "Infrastructure not specified");
}
if (policy == null) {
throw new CLIException(REASON_INVALID_ARGUMENTS, "Policy not specified");
}
if (currentContext.getProperty(SET_NODE_SOURCE, String.class) != null) {
nodeSource = currentContext.getProperty(SET_NODE_SOURCE, String.class);
}
HttpPost request = new HttpPost(currentContext.getResourceUrl(RM_REST_ENDPOINT));
QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
queryStringBuilder.add("nodeSourceName", nodeSource).addAll(infrastructure).addAll(policy).add("nodesRecoverable", nodesRecoverable);
request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
NSStateView nsState = readValue(response, NSStateView.class, currentContext);
boolean success = nsState.isResult();
resultStack(currentContext).push(success);
if (success) {
writeLine(currentContext, "Node source successfully defined.");
} else {
writeLine(currentContext, "%s %s", "Cannot define node source:", nodeSource);
}
} else {
handleError("An error occurred while defining node source:", response, currentContext);
}
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class ListNodeCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpGet request = new HttpGet(currentContext.getResourceUrl("monitoring"));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
RmStateView state = readValue(response, RmStateView.class, currentContext);
NodeEventView[] nodeEvents = state.getNodesEvents();
NodeEventView[] selectedNodeEvents = null;
if (nodeEvents != null) {
if (nodeSource == null) {
selectedNodeEvents = nodeEvents;
} else {
List<NodeEventView> selectedList = new ArrayList<>();
for (NodeEventView nodeEvent : nodeEvents) {
if (!nodeSource.equals(nodeEvent.getNodeSource())) {
// node source doesn't match
continue;
} else {
selectedList.add(nodeEvent);
}
}
selectedNodeEvents = selectedList.toArray(new NodeEventView[selectedList.size()]);
}
}
// filter out all node events that was removed
// so rm client does not display them
List<NodeEventView> filtered = new ArrayList<>();
for (NodeEventView nodeEvent : selectedNodeEvents) {
if (!nodeEvent.isRemoved()) {
filtered.add(nodeEvent);
}
}
NodeEventView[] result = new NodeEventView[filtered.size()];
result = filtered.toArray(result);
resultStack(currentContext).push(result);
writeLine(currentContext, "%s", StringUtility.string(result));
} else {
handleError("An error occurred while retrieving nodes:", response, currentContext);
}
}
Aggregations