Skip to content

Commit 975d9bf

Browse files
author
slfan1989
committed
YARN-11180. Fix CheckStyle.
1 parent a8150e4 commit 975d9bf

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,13 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
669669
federationFacade.getSubClusters(true);
670670
ClientMethod remoteMethod = new ClientMethod("getApplications",
671671
new Class[] {GetApplicationsRequest.class}, new Object[] {request});
672-
Map<SubClusterId, GetApplicationsResponse> applications;
672+
Map<SubClusterId, GetApplicationsResponse> applications = null;
673673
try {
674674
applications = invokeConcurrent(subclusters.keySet(), remoteMethod,
675675
GetApplicationsResponse.class);
676676
} catch (Exception ex) {
677677
routerMetrics.incrMultipleAppsFailedRetrieved();
678-
LOG.error("Unable to get applications due to exception.", ex);
679-
throw ex;
678+
RouterServerUtil.logAndThrowException("Unable to get applications due to exception.", ex);
680679
}
681680
long stopTime = clock.getTime();
682681
routerMetrics.succeededMultipleAppsRetrieved(stopTime - startTime);
@@ -687,23 +686,23 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
687686
@Override
688687
public GetClusterMetricsResponse getClusterMetrics(
689688
GetClusterMetricsRequest request) throws YarnException, IOException {
689+
if (request == null) {
690+
routerMetrics.incrGetClusterMetricsFailedRetrieved();
691+
RouterServerUtil.logAndThrowException("Missing getClusterMetrics request.", null);
692+
}
690693
long startTime = clock.getTime();
691-
Map<SubClusterId, SubClusterInfo> subclusters =
694+
Map<SubClusterId, SubClusterInfo> subClusters =
692695
federationFacade.getSubClusters(true);
693696
ClientMethod remoteMethod = new ClientMethod("getClusterMetrics",
694697
new Class[] {GetClusterMetricsRequest.class}, new Object[] {request});
695-
Map<SubClusterId, GetClusterMetricsResponse> clusterMetrics;
696-
698+
Map<SubClusterId, GetClusterMetricsResponse> clusterMetrics = null;
697699
try {
698-
clusterMetrics = invokeConcurrent(subclusters.keySet(), remoteMethod,
700+
clusterMetrics = invokeConcurrent(subClusters.keySet(), remoteMethod,
699701
GetClusterMetricsResponse.class);
700-
701702
} catch (Exception ex) {
702703
routerMetrics.incrGetClusterMetricsFailedRetrieved();
703-
LOG.error("Unable to get cluster metrics due to exception.", ex);
704-
throw ex;
704+
RouterServerUtil.logAndThrowException("Unable to get cluster metrics due to exception.", ex);
705705
}
706-
707706
long stopTime = clock.getTime();
708707
routerMetrics.succeededGetClusterMetricsRetrieved(stopTime - startTime);
709708
return RouterYarnClientUtils.merge(clusterMetrics.values());

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,14 @@ public void testGetApplicationAttemptEmptyRequest()
580580

581581

582582
@Test
583-
public void testGetClusterMetricsRequest() throws YarnException, IOException {
583+
public void testGetClusterMetricsRequest() throws Exception {
584584
LOG.info("Test FederationClientInterceptor : Get Cluster Metrics request");
585585
// null request
586-
GetClusterMetricsResponse response = interceptor.getClusterMetrics(null);
587-
Assert.assertEquals(subClusters.size(),
588-
response.getClusterMetrics().getNumNodeManagers());
586+
LambdaTestUtils.intercept(YarnException.class, "Missing getClusterMetrics request.",
587+
() -> interceptor.getClusterMetrics(null));
588+
589589
// normal request.
590-
response =
590+
GetClusterMetricsResponse response =
591591
interceptor.getClusterMetrics(GetClusterMetricsRequest.newInstance());
592592
Assert.assertEquals(subClusters.size(),
593593
response.getClusterMetrics().getNumNodeManagers());

0 commit comments

Comments
 (0)