Search in sources :

Example 1 with NodeSourceView

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

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

the class StringUtility method string.

public static String string(NodeSourceView[] nodeSources) {
    ObjectArrayFormatter formatter = new ObjectArrayFormatter();
    formatter.setMaxColumnLength(80);
    formatter.setSpace(4);
    List<String> titles = new ArrayList<>(3);
    titles.add("SOURCE_NAME");
    titles.add("DESCRIPTION");
    titles.add("ADMINISTRATOR");
    formatter.setTitle(titles);
    formatter.addEmptyLine();
    for (NodeSourceView ns : nodeSources) {
        List<String> line = new ArrayList<>(3);
        line.add(ns.getSourceName());
        line.add(ns.getSourceDescription());
        line.add(ns.getNodeSourceAdmin());
        formatter.addLine(line);
    }
    return Tools.getStringAsArray(formatter);
}
Also used : NodeSourceView(org.ow2.proactive_grid_cloud_portal.cli.json.NodeSourceView) ArrayList(java.util.ArrayList) ObjectArrayFormatter(org.ow2.proactive.utils.ObjectArrayFormatter)

Aggregations

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