Search in sources :

Example 1 with TopologyView

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);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet) TopologyView(org.ow2.proactive_grid_cloud_portal.cli.json.TopologyView)

Example 2 with TopologyView

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();
}
Also used : ArrayList(java.util.ArrayList) ObjectArrayFormatter(org.ow2.proactive.utils.ObjectArrayFormatter)

Aggregations

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