Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YARN-11121:Check GetClusterMetrics Request parameter is null #4250

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubClusterId, SubClusterInfo> subclusters =
federationFacade.getSubClusters(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,14 @@ 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());
Expand Down Expand Up @@ -641,4 +641,25 @@ public void testGetApplicationsApplicationStateNotExists() throws Exception{
Assert.assertNotNull(responseGet);
Assert.assertTrue(responseGet.getApplicationList().isEmpty());
}

/**
* 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
*/
@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"));
}
}
}