Search in sources :

Example 1 with MBeanInfoView

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

the class StringUtility method mBeanInfoAsString.

public static String mBeanInfoAsString(MBeanInfoView[] infoViews) {
    ObjectArrayFormatter formatter = new ObjectArrayFormatter();
    formatter.setMaxColumnLength(80);
    formatter.setSpace(4);
    List<String> titles = new ArrayList<>(2);
    titles.add("Stats:");
    titles.add("");
    formatter.setTitle(titles);
    formatter.addEmptyLine();
    for (MBeanInfoView infoView : infoViews) {
        List<String> line = new ArrayList<>();
        line.add("" + infoView.getName());
        line.add("" + infoView.getValue());
        formatter.addLine(line);
    }
    return Tools.getStringAsArray(formatter);
}
Also used : MBeanInfoView(org.ow2.proactive_grid_cloud_portal.cli.json.MBeanInfoView) ArrayList(java.util.ArrayList) ObjectArrayFormatter(org.ow2.proactive.utils.ObjectArrayFormatter)

Example 2 with MBeanInfoView

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

the class RmStatsCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    StringBuilder url = new StringBuilder();
    url.append("info/ProActiveResourceManager:name=RuntimeData?");
    QueryStringBuilder builder = new QueryStringBuilder();
    for (String attr : RUNTIME_DATA_ATTR) {
        builder.add("attr", attr);
    }
    url.append(builder.buildString());
    HttpGet request = new HttpGet(currentContext.getResourceUrl(url.toString()));
    HttpResponseWrapper response = execute(request, currentContext);
    if (statusCode(OK) == statusCode(response)) {
        List<MBeanInfoView> infoList = readValue(response, new TypeReference<List<MBeanInfoView>>() {
        }, currentContext);
        MBeanInfoView[] stats = infoList.toArray(new MBeanInfoView[infoList.size()]);
        resultStack(currentContext).push(stats);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", StringUtility.mBeanInfoAsString(stats));
        }
    } else {
        handleError("An error occurred while retrieving stats:", response, currentContext);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) MBeanInfoView(org.ow2.proactive_grid_cloud_portal.cli.json.MBeanInfoView) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder) HttpGet(org.apache.http.client.methods.HttpGet) List(java.util.List) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)

Aggregations

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