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);
}
}
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);
}
Aggregations