From 7093afd8746cc120875eb27053bad692482d2aab Mon Sep 17 00:00:00 2001 From: bibinchundatt Date: Fri, 28 Sep 2018 12:32:37 +0530 Subject: [PATCH] YARN-8829. Cluster metrics can fail with IndexOutOfBoundsException. Contributed by Akshay Agarwal. --- .../router/clientrm/FederationClientInterceptor.java | 2 +- .../router/clientrm/TestFederationClientInterceptor.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java index 3d9b3946f4e..797b1aa8b71 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java +++ b/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); } } - if (results.isEmpty()) { + if (results.isEmpty() && !clusterIds.isEmpty()) { SubClusterId subClusterId = clusterIds.get(0); IOException ioe = exceptions.get(subClusterId); if (ioe != null) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java index 8f19ecc46e1..c49fe4e8320 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java +++ b/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.List; +import java.util.Map; import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest; import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse; import org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsRequest; @@ -412,5 +413,13 @@ public class TestFederationClientInterceptor extends BaseRouterClientRMTest { interceptor.getClusterMetrics(GetClusterMetricsRequest.newInstance()); Assert.assertEquals(subClusters.size(), response.getClusterMetrics().getNumNodeManagers()); + + ClientMethod remoteMethod = new ClientMethod("getClusterMetrics", + new Class[] {GetClusterMetricsRequest.class}, + new Object[] {GetClusterMetricsRequest.newInstance()}); + Map clusterMetrics =interceptor. + invokeConcurrent(new ArrayList<>(), remoteMethod, + GetClusterMetricsResponse.class); + Assert.assertEquals(true, clusterMetrics.isEmpty()); } }