Search in sources :

Example 1 with RmStateView

use of org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView in project scheduling by ow2-proactive.

the class GetNodeInfoCommand 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 target = null;
        for (NodeEventView nodeEvent : nodeEvents) {
            if (nodeUrl.equals(nodeEvent.getNodeUrl())) {
                target = nodeEvent;
                break;
            }
        }
        if (target == null) {
            writeLine(currentContext, "Cannot find node: '%s'", nodeUrl);
            return;
        }
        resultStack(currentContext).push(target);
        writeLine(currentContext, "%s", target.getNodeInfo());
    } else {
        handleError("An error occurred while retrieving node info.", response, currentContext);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet) NodeEventView(org.ow2.proactive_grid_cloud_portal.cli.json.NodeEventView) RmStateView(org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView)

Example 2 with RmStateView

use of org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView in project scheduling by ow2-proactive.

the class ListNodeSourceCommand 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);
        NodeSourceView[] nodeSources = state.getNodeSource();
        // filter out all node source events that was removed
        // so rm client does not display them
        List<NodeSourceView> filtered = new ArrayList<>(nodeSources.length);
        for (NodeSourceView nodeSourceEvent : nodeSources) {
            if (!nodeSourceEvent.isRemoved()) {
                filtered.add(nodeSourceEvent);
            }
        }
        NodeSourceView[] result = new NodeSourceView[filtered.size()];
        result = filtered.toArray(result);
        resultStack(currentContext).push(result);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", StringUtility.string(result));
        }
    } else {
        handleError("An error occurred while retrieving node sources:", response, currentContext);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet) NodeSourceView(org.ow2.proactive_grid_cloud_portal.cli.json.NodeSourceView) ArrayList(java.util.ArrayList) RmStateView(org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView)

Example 3 with RmStateView

use of org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView 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

HttpGet (org.apache.http.client.methods.HttpGet)3 RmStateView (org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView)3 HttpResponseWrapper (org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper)3 ArrayList (java.util.ArrayList)2 NodeEventView (org.ow2.proactive_grid_cloud_portal.cli.json.NodeEventView)2 NodeSourceView (org.ow2.proactive_grid_cloud_portal.cli.json.NodeSourceView)1