Browse Source

YARN-8829. Cluster metrics can fail with IndexOutOfBoundsException. Contributed by Akshay Agarwal.

bibinchundatt 6 years ago
parent
commit
7093afd874

+ 1 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java

@@ -654,7 +654,7 @@ public class FederationClientInterceptor
           exceptions.put(subClusterId, ioe);
           exceptions.put(subClusterId, ioe);
         }
         }
       }
       }
-      if (results.isEmpty()) {
+      if (results.isEmpty() && !clusterIds.isEmpty()) {
         SubClusterId subClusterId = clusterIds.get(0);
         SubClusterId subClusterId = clusterIds.get(0);
         IOException ioe = exceptions.get(subClusterId);
         IOException ioe = exceptions.get(subClusterId);
         if (ioe != null) {
         if (ioe != null) {

+ 9 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java

@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
 
 
+import java.util.Map;
 import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse;
 import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse;
 import org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsRequest;
@@ -412,5 +413,13 @@ public class TestFederationClientInterceptor extends BaseRouterClientRMTest {
         interceptor.getClusterMetrics(GetClusterMetricsRequest.newInstance());
         interceptor.getClusterMetrics(GetClusterMetricsRequest.newInstance());
     Assert.assertEquals(subClusters.size(),
     Assert.assertEquals(subClusters.size(),
         response.getClusterMetrics().getNumNodeManagers());
         response.getClusterMetrics().getNumNodeManagers());
+
+    ClientMethod remoteMethod = new ClientMethod("getClusterMetrics",
+        new Class[] {GetClusterMetricsRequest.class},
+        new Object[] {GetClusterMetricsRequest.newInstance()});
+    Map<SubClusterId, GetClusterMetricsResponse> clusterMetrics =interceptor.
+        invokeConcurrent(new ArrayList<>(), remoteMethod,
+            GetClusterMetricsResponse.class);
+    Assert.assertEquals(true, clusterMetrics.isEmpty());
   }
   }
 }
 }