From e22ee3f02d04d6a767df0310fd30cd94d9714e62 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Fri, 29 Apr 2022 18:51:50 -0700 Subject: [PATCH 1/4] YARN-11121:Conditional judgment Add in getClusterMetrics --- .../clientrm/FederationClientInterceptor.java | 6 ++++++ .../clientrm/TestFederationClientInterceptor.java | 13 +++++++++++++ 2 files changed, 19 insertions(+) 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 de80a35f49b78..4ea97cdfc9362 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 @@ -703,6 +703,12 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request) @Override public GetClusterMetricsResponse getClusterMetrics( GetClusterMetricsRequest request) throws YarnException, IOException { + if(request == null) { + routerMetrics.incrGetClusterMetricsFailedRetrieved(); + RouterServerUtil.logAndThrowException( + "Missing getClusterMetrics request.", + null); + } long startTime = clock.getTime(); Map subclusters = federationFacade.getSubClusters(true); 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 74d10a44c52b5..af86e10af3428 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 @@ -641,4 +641,17 @@ public void testGetApplicationsApplicationStateNotExists() throws Exception{ Assert.assertNotNull(responseGet); Assert.assertTrue(responseGet.getApplicationList().isEmpty()); } + + @Test + public void testGetClusterMetricsRequestNull() throws YarnException, IOException { + LOG.info( + "Test FederationClientInterceptor: GetClusterMetrics - Empty"); + try { + interceptor.getClusterMetrics(null); + Assert.fail(); + } catch (YarnException e) { + Assert.assertTrue( + e.getMessage().startsWith("Missing getClusterMetrics request")); + } + } } From 31492ab1deb158708ddecba627c3af0f6bae5f75 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sun, 1 May 2022 23:29:26 -0700 Subject: [PATCH 2/4] YARN-11121:When the request request is null, should not get the results of the metrics, modify the Unit Test so that the test meets the expectations --- .../TestFederationClientInterceptor.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 af86e10af3428..c1171644541f7 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 @@ -516,14 +516,15 @@ public void testGetApplicationAttemptEmptyRequest() @Test - public void testGetClusterMetricsRequest() throws YarnException, IOException { + public void testGetClusterMetricsRequest() throws Exception { LOG.info("Test FederationClientInterceptor : Get Cluster Metrics request"); // null request - GetClusterMetricsResponse response = interceptor.getClusterMetrics(null); - Assert.assertEquals(subClusters.size(), - response.getClusterMetrics().getNumNodeManagers()); + LambdaTestUtils.intercept(YarnException.class, + "Missing getClusterMetrics request." , + () -> interceptor.getClusterMetrics(null)); + // normal request. - response = + GetClusterMetricsResponse response = interceptor.getClusterMetrics(GetClusterMetricsRequest.newInstance()); Assert.assertEquals(subClusters.size(), response.getClusterMetrics().getNumNodeManagers()); @@ -642,6 +643,11 @@ public void testGetApplicationsApplicationStateNotExists() throws Exception{ Assert.assertTrue(responseGet.getApplicationList().isEmpty()); } + /** + * + * @throws YarnException + * @throws IOException + */ @Test public void testGetClusterMetricsRequestNull() throws YarnException, IOException { LOG.info( From 38b5d97b524ad87252e9371e29a6e1bcb8f2556b Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Thu, 5 May 2022 17:49:40 -0700 Subject: [PATCH 3/4] YARN-11122:checkstyle fix. --- .../router/clientrm/TestFederationClientInterceptor.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 c1171644541f7..7a8ce96162e68 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 @@ -520,8 +520,7 @@ public void testGetClusterMetricsRequest() throws Exception { LOG.info("Test FederationClientInterceptor : Get Cluster Metrics request"); // null request LambdaTestUtils.intercept(YarnException.class, - "Missing getClusterMetrics request." , - () -> interceptor.getClusterMetrics(null)); + "Missing getClusterMetrics request.", () -> interceptor.getClusterMetrics(null)); // normal request. GetClusterMetricsResponse response = @@ -644,6 +643,9 @@ public void testGetApplicationsApplicationStateNotExists() throws Exception{ } /** + * This test validates that if the request is null, + * calling the interface for obtaining cluster metrics should throw an exception, + * verifying that the exception is as expected. * * @throws YarnException * @throws IOException From 3264e04f0a664f92ddca742c65343b0348c876da Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Thu, 5 May 2022 17:49:40 -0700 Subject: [PATCH 4/4] YARN-11121:checkstyle fix. --- .../router/clientrm/TestFederationClientInterceptor.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 c1171644541f7..7a8ce96162e68 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 @@ -520,8 +520,7 @@ public void testGetClusterMetricsRequest() throws Exception { LOG.info("Test FederationClientInterceptor : Get Cluster Metrics request"); // null request LambdaTestUtils.intercept(YarnException.class, - "Missing getClusterMetrics request." , - () -> interceptor.getClusterMetrics(null)); + "Missing getClusterMetrics request.", () -> interceptor.getClusterMetrics(null)); // normal request. GetClusterMetricsResponse response = @@ -644,6 +643,9 @@ public void testGetApplicationsApplicationStateNotExists() throws Exception{ } /** + * This test validates that if the request is null, + * calling the interface for obtaining cluster metrics should throw an exception, + * verifying that the exception is as expected. * * @throws YarnException * @throws IOException