Search in sources :

Example 66 with NodeSource

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;
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode)

Example 67 with NodeSource

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;
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode)

Example 68 with NodeSource

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);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) NSStateView(org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)

Example 69 with NodeSource

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);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) NodeEventView(org.ow2.proactive_grid_cloud_portal.cli.json.NodeEventView) RmStateView(org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView)

Aggregations

NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)21 Test (org.junit.Test)17 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)13 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)11 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)11 Client (org.ow2.proactive.resourcemanager.authentication.Client)9 Node (org.objectweb.proactive.core.node.Node)8 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)7 ArrayList (java.util.ArrayList)6 RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)6 Permission (java.security.Permission)5 NodeSourceData (org.ow2.proactive.resourcemanager.db.NodeSourceData)5 RMException (org.ow2.proactive.resourcemanager.exception.RMException)5 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Matchers.anyString (org.mockito.Matchers.anyString)4