Example usage for org.apache.hadoop.yarn.api.protocolrecords GetClusterMetricsResponse getClusterMetrics

List of usage examples for org.apache.hadoop.yarn.api.protocolrecords GetClusterMetricsResponse getClusterMetrics

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.protocolrecords GetClusterMetricsResponse getClusterMetrics.

Prototype

@Public
@Stable
public abstract YarnClusterMetrics getClusterMetrics();

Source Link

Document

Get the YarnClusterMetrics for the cluster.

Usage

From source file:org.huahinframework.manager.rest.service.ApplicationService.java

License:Apache License

@Path("/cluster")
@GET/*from   ww  w . jav a2s .  c  o m*/
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getCluster() {
    JSONObject jsonObject = new JSONObject();

    try {
        GetClusterMetricsRequest metricsRequest = recordFactory
                .newRecordInstance(GetClusterMetricsRequest.class);
        GetClusterMetricsResponse metricsResponse = applicationsManager.getClusterMetrics(metricsRequest);

        jsonObject.put(Response.NUM_NODE_MANAGERS, metricsResponse.getClusterMetrics().getNumNodeManagers());

        GetClusterNodesRequest nodeRequest = recordFactory.newRecordInstance(GetClusterNodesRequest.class);
        GetClusterNodesResponse nodeResponse = applicationsManager.getClusterNodes(nodeRequest);

        List<JSONObject> reports = new ArrayList<JSONObject>();
        for (NodeReport report : nodeResponse.getNodeReports()) {
            JSONObject nr = new JSONObject();
            nr.put(Response.HTTP_ADDRESS, report.getHttpAddress());
            nr.put(Response.NUM_CONTAINERS, report.getNumContainers());
            nr.put(Response.RACK_NAME, report.getRackName());
            nr.put(Response.CAPABILITY, report.getCapability().getMemory());
            nr.put(Response.HEALTH_REPORT, report.getNodeHealthStatus().getHealthReport());
            nr.put(Response.IS_NODE_HEALTHY, report.getNodeHealthStatus().getIsNodeHealthy());
            nr.put(Response.LAST_HEALTH_REPORT_TIME,
                    new Date(report.getNodeHealthStatus().getLastHealthReportTime()));
            nr.put(Response.NODE_ID, report.getNodeId());
            nr.put(Response.NODE_STATE, report.getNodeState());
            nr.put(Response.NODE_STATE, report.getNodeState());
            nr.put(Response.USED, report.getUsed());
            reports.add(nr);
        }

        jsonObject.put(Response.NODES, reports);
    } catch (Exception e) {
        e.printStackTrace();
        log.error(e);
        Map<String, String> status = new HashMap<String, String>();
        status.put(Response.STATUS, e.getMessage());
        jsonObject = new JSONObject(status);
    }

    return jsonObject;
}