RouterYarnClientUtils { public static GetClusterMetricsResponse merge( Collection<GetClusterMetricsResponse> responses) { YarnClusterMetrics tmp = YarnClusterMetrics.newInstance(0); for (GetClusterMetricsResponse response : responses) { YarnClusterMetrics metrics = response.getClusterMetrics(); tmp.setNumNodeManagers( tmp.getNumNodeManagers() + metrics.getNumNodeManagers()); tmp.setNumActiveNodeManagers( tmp.getNumActiveNodeManagers() + metrics.getNumActiveNodeManagers()); tmp.setNumDecommissionedNodeManagers( tmp.getNumDecommissionedNodeManagers() + metrics .getNumDecommissionedNodeManagers()); tmp.setNumLostNodeManagers( tmp.getNumLostNodeManagers() + metrics.getNumLostNodeManagers()); tmp.setNumRebootedNodeManagers(tmp.getNumRebootedNodeManagers() + metrics .getNumRebootedNodeManagers()); tmp.setNumUnhealthyNodeManagers( tmp.getNumUnhealthyNodeManagers() + metrics .getNumUnhealthyNodeManagers()); } return GetClusterMetricsResponse.newInstance(tmp); } private  RouterYarnClientUtils(); static GetClusterMetricsResponse merge(
      Collection<GetClusterMetricsResponse> responses);  }
@Test public void testClusterMetricsMerge() { ArrayList<GetClusterMetricsResponse> responses = new ArrayList<>(); responses.add(getClusterMetricsResponse(1)); responses.add(getClusterMetricsResponse(2)); GetClusterMetricsResponse result = RouterYarnClientUtils.merge(responses); YarnClusterMetrics resultMetrics = result.getClusterMetrics(); Assert.assertEquals(3, resultMetrics.getNumNodeManagers()); Assert.assertEquals(3, resultMetrics.getNumActiveNodeManagers()); Assert.assertEquals(3, resultMetrics.getNumDecommissionedNodeManagers()); Assert.assertEquals(3, resultMetrics.getNumLostNodeManagers()); Assert.assertEquals(3, resultMetrics.getNumRebootedNodeManagers()); Assert.assertEquals(3, resultMetrics.getNumUnhealthyNodeManagers()); }