use of org.ow2.proactive_grid_cloud_portal.cli.json.TopologyView in project scheduling by ow2-proactive.
the class GetTopologyCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpGet request = new HttpGet(currentContext.getResourceUrl("topology"));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
TopologyView topology = readValue(response, TopologyView.class, currentContext);
resultStack(currentContext).push(topology);
if (!currentContext.isSilent()) {
writeLine(currentContext, "%s", StringUtility.string(topology));
}
} else {
handleError("An error occurred while retrieving the topology:", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.TopologyView in project scheduling by ow2-proactive.
the class StringUtility method string.
public static String string(TopologyView topology) {
StringBuilder buffer = new StringBuilder();
Set<String> hostList = topology.getDistances().keySet();
buffer.append(String.format("%nHost list(%d):", hostList.size()));
for (String host : hostList) {
buffer.append(String.format("%s", host));
}
ObjectArrayFormatter formatter = new ObjectArrayFormatter();
formatter.setMaxColumnLength(80);
formatter.setSpace(4);
List<String> titles = new ArrayList<>(3);
titles.add("Host");
titles.add("Distance (µs)");
titles.add("Host");
formatter.setTitle(titles);
formatter.addEmptyLine();
List<String> line;
for (String host : hostList) {
Map<String, String> hostTopology = topology.getDistances().get(host);
if (hostTopology != null) {
for (String anotherHost : hostTopology.keySet()) {
line = new ArrayList<>(3);
line.add(host);
line.add(hostTopology.get(anotherHost));
line.add(anotherHost);
formatter.addLine(line);
}
}
}
buffer.append(objectArrayFormatterAsString(formatter));
return buffer.toString();
}
Aggregations