FederationInterceptorREST extends AbstractRESTRequestInterceptor { @Override public ClusterMetricsInfo getClusterMetricsInfo() { ClusterMetricsInfo metrics = new ClusterMetricsInfo(); Map<SubClusterId, SubClusterInfo> subClustersActive = null; try { subClustersActive = federationFacade.getSubClusters(true); } catch (YarnException e) { LOG.error(e.getLocalizedMessage()); return metrics; } CompletionService<ClusterMetricsInfo> compSvc = new ExecutorCompletionService<ClusterMetricsInfo>(this.threadpool); for (final SubClusterInfo info : subClustersActive.values()) { compSvc.submit(new Callable<ClusterMetricsInfo>() { @Override public ClusterMetricsInfo call() { DefaultRequestInterceptorREST interceptor = getOrCreateInterceptorForSubCluster( info.getSubClusterId(), info.getRMWebServiceAddress()); try { ClusterMetricsInfo metrics = interceptor.getClusterMetricsInfo(); return metrics; } catch (Exception e) { LOG.error("Subcluster {} failed to return Cluster Metrics.", info.getSubClusterId()); return null; } } }); } for (int i = 0; i < subClustersActive.size(); i++) { try { Future<ClusterMetricsInfo> future = compSvc.take(); ClusterMetricsInfo metricsResponse = future.get(); if (metricsResponse != null) { RouterWebServiceUtil.mergeMetrics(metrics, metricsResponse); } } catch (Throwable e) { LOG.warn("Failed to get nodes report ", e); } } return metrics; }  @Override void init(String user); @Override Response createNewApplication(HttpServletRequest hsr); @Override Response submitApplication(ApplicationSubmissionContextInfo newApp,
      HttpServletRequest hsr); @Override AppInfo getApp(HttpServletRequest hsr, String appId,
      Set<String> unselectedFields); @Override Response updateAppState(AppState targetState, HttpServletRequest hsr,
      String appId); @Override AppsInfo getApps(HttpServletRequest hsr, String stateQuery,
      Set<String> statesQuery, String finalStatusQuery, String userQuery,
      String queueQuery, String count, String startedBegin, String startedEnd,
      String finishBegin, String finishEnd, Set<String> applicationTypes,
      Set<String> applicationTags, Set<String> unselectedFields); @Override NodeInfo getNode(String nodeId); @Override NodesInfo getNodes(String states); @Override ClusterMetricsInfo getClusterMetricsInfo(); @Override AppState getAppState(HttpServletRequest hsr, String appId); @Override ClusterInfo get(); @Override ClusterInfo getClusterInfo(); @Override ClusterUserInfo getClusterUserInfo(HttpServletRequest hsr); @Override SchedulerTypeInfo getSchedulerInfo(); @Override String dumpSchedulerLogs(String time, HttpServletRequest hsr); @Override ActivitiesInfo getActivities(HttpServletRequest hsr, String nodeId); @Override AppActivitiesInfo getAppActivities(HttpServletRequest hsr,
      String appId, String time); @Override ApplicationStatisticsInfo getAppStatistics(HttpServletRequest hsr,
      Set<String> stateQueries, Set<String> typeQueries); @Override NodeToLabelsInfo getNodeToLabels(HttpServletRequest hsr); @Override LabelsToNodesInfo getLabelsToNodes(Set<String> labels); @Override Response replaceLabelsOnNodes(NodeToLabelsEntryList newNodeToLabels,
      HttpServletRequest hsr); @Override Response replaceLabelsOnNode(Set<String> newNodeLabelsName,
      HttpServletRequest hsr, String nodeId); @Override NodeLabelsInfo getClusterNodeLabels(HttpServletRequest hsr); @Override Response addToClusterNodeLabels(NodeLabelsInfo newNodeLabels,
      HttpServletRequest hsr); @Override Response removeFromCluserNodeLabels(Set<String> oldNodeLabels,
      HttpServletRequest hsr); @Override NodeLabelsInfo getLabelsOnNode(HttpServletRequest hsr, String nodeId); @Override AppPriority getAppPriority(HttpServletRequest hsr, String appId); @Override Response updateApplicationPriority(AppPriority targetPriority,
      HttpServletRequest hsr, String appId); @Override AppQueue getAppQueue(HttpServletRequest hsr, String appId); @Override Response updateAppQueue(AppQueue targetQueue, HttpServletRequest hsr,
      String appId); @Override Response postDelegationToken(DelegationToken tokenData,
      HttpServletRequest hsr); @Override Response postDelegationTokenExpiration(HttpServletRequest hsr); @Override Response cancelDelegationToken(HttpServletRequest hsr); @Override Response createNewReservation(HttpServletRequest hsr); @Override Response submitReservation(ReservationSubmissionRequestInfo resContext,
      HttpServletRequest hsr); @Override Response updateReservation(ReservationUpdateRequestInfo resContext,
      HttpServletRequest hsr); @Override Response deleteReservation(ReservationDeleteRequestInfo resContext,
      HttpServletRequest hsr); @Override Response listReservation(String queue, String reservationId,
      long startTime, long endTime, boolean includeResourceAllocations,
      HttpServletRequest hsr); @Override AppTimeoutInfo getAppTimeout(HttpServletRequest hsr, String appId,
      String type); @Override AppTimeoutsInfo getAppTimeouts(HttpServletRequest hsr, String appId); @Override Response updateApplicationTimeout(AppTimeoutInfo appTimeout,
      HttpServletRequest hsr, String appId); @Override AppAttemptsInfo getAppAttempts(HttpServletRequest hsr, String appId); @Override RMQueueAclInfo checkUserAccessToQueue(String queue, String username,
      String queueAclType, HttpServletRequest hsr); @Override AppAttemptInfo getAppAttempt(HttpServletRequest req,
      HttpServletResponse res, String appId, String appAttemptId); @Override ContainersInfo getContainers(HttpServletRequest req,
      HttpServletResponse res, String appId, String appAttemptId); @Override ContainerInfo getContainer(HttpServletRequest req,
      HttpServletResponse res, String appId, String appAttemptId,
      String containerId); @Override void setNextInterceptor(RESTRequestInterceptor next); @Override void shutdown();  }
@Test public void testGetClusterMetrics() { ClusterMetricsInfo responseGet = interceptor.getClusterMetricsInfo(); Assert.assertNotNull(responseGet); int expectedAppSubmitted = 0; for (int i = 0; i < NUM_SUBCLUSTER; i++) { expectedAppSubmitted += i; } Assert.assertEquals(expectedAppSubmitted, responseGet.getAppsSubmitted()); }