Search in sources :

Example 1 with NodeEventView

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

the class StringUtility method string.

public static String string(NodeEventView[] nodeEvents) {
    ObjectArrayFormatter formatter = new ObjectArrayFormatter();
    formatter.setMaxColumnLength(300);
    formatter.setSpace(4);
    List<String> titles = new ArrayList<>(7);
    titles.add("SOURCE_NAME");
    titles.add("HOST_NAME");
    titles.add("STATE");
    titles.add("SINCE");
    titles.add("LOCKED");
    titles.add("LOCKED_BY");
    titles.add("LOCK_TIME");
    titles.add("URL");
    titles.add("PROVIDER");
    titles.add("USED_BY");
    formatter.setTitle(titles);
    formatter.addEmptyLine();
    if (nodeEvents != null) {
        for (NodeEventView nodeEvent : nodeEvents) {
            List<String> line = new ArrayList<>(10);
            line.add(nodeEvent.getNodeSource());
            line.add(nodeEvent.getHostName());
            line.add(nodeEvent.getNodeState());
            line.add(getStateChangeTime(nodeEvent));
            line.add(nodeEvent.isLocked());
            line.add(toStringNullable(nodeEvent.getNodeLocker()));
            line.add(getLockTime(nodeEvent));
            line.add(nodeEvent.getNodeUrl());
            line.add(toStringNullable(nodeEvent.getNodeProvider()));
            line.add(toStringNullable(nodeEvent.getNodeOwner()));
            formatter.addLine(line);
        }
    }
    return Tools.getStringAsArray(formatter);
}
Also used : ArrayList(java.util.ArrayList) NodeEventView(org.ow2.proactive_grid_cloud_portal.cli.json.NodeEventView) ObjectArrayFormatter(org.ow2.proactive.utils.ObjectArrayFormatter)

Example 2 with NodeEventView

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

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

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