YARN-10829. Follow up: Adding null checks before merging ResourceUsage Report (#3252)
This commit is contained in:
parent
2ff3fc50e4
commit
a186460004
@ -133,6 +133,10 @@ private static void mergeAMWithUAM(ApplicationReport am,
|
||||
ApplicationResourceUsageReport uamResourceReport =
|
||||
uam.getApplicationResourceUsageReport();
|
||||
|
||||
if (amResourceReport == null) {
|
||||
am.setApplicationResourceUsageReport(uamResourceReport);
|
||||
} else if (uamResourceReport != null) {
|
||||
|
||||
amResourceReport.setNumUsedContainers(
|
||||
amResourceReport.getNumUsedContainers() +
|
||||
uamResourceReport.getNumUsedContainers());
|
||||
@ -171,6 +175,7 @@ private static void mergeAMWithUAM(ApplicationReport am,
|
||||
|
||||
am.setApplicationResourceUsageReport(amResourceReport);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not to add an unmanaged application to the report.
|
||||
|
@ -124,6 +124,48 @@ public void testMergeUnmanagedApplications() {
|
||||
Assert.assertTrue(result.getApplicationList().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test validates the correctness of
|
||||
* RouterYarnClientUtils#mergeApplications when
|
||||
* ApplicationResourceUsageReport might be null.
|
||||
*/
|
||||
@Test
|
||||
public void testMergeApplicationsNullResourceUsage() {
|
||||
ApplicationId appId = ApplicationId.newInstance(1234, 1);
|
||||
ApplicationReport appReport = ApplicationReport.newInstance(
|
||||
appId, ApplicationAttemptId.newInstance(appId, 1),
|
||||
"user", "queue", "app1", "host",
|
||||
124, null, YarnApplicationState.RUNNING,
|
||||
"diagnostics", "url", 0, 0,
|
||||
0, FinalApplicationStatus.SUCCEEDED, null, "N/A",
|
||||
0.53789f, "YARN", null, null, false, null, null, null);
|
||||
|
||||
ApplicationReport uamAppReport = ApplicationReport.newInstance(
|
||||
appId, ApplicationAttemptId.newInstance(appId, 1),
|
||||
"user", "queue", "app1", "host",
|
||||
124, null, YarnApplicationState.RUNNING,
|
||||
"diagnostics", "url", 0, 0,
|
||||
0, FinalApplicationStatus.SUCCEEDED, null, "N/A",
|
||||
0.53789f, "YARN", null, null, true, null, null, null);
|
||||
|
||||
|
||||
ArrayList<GetApplicationsResponse> responses = new ArrayList<>();
|
||||
List<ApplicationReport> applications = new ArrayList<>();
|
||||
applications.add(appReport);
|
||||
applications.add(uamAppReport);
|
||||
responses.add(GetApplicationsResponse.newInstance(applications));
|
||||
|
||||
GetApplicationsResponse result = RouterYarnClientUtils.
|
||||
mergeApplications(responses, false);
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(1, result.getApplicationList().size());
|
||||
|
||||
String appName = result.getApplicationList().get(0).getName();
|
||||
|
||||
// Check that no Unmanaged applications are added to the result
|
||||
Assert.assertFalse(appName.contains(UnmanagedApplicationManager.APP_NAME));
|
||||
}
|
||||
|
||||
/**
|
||||
* This generates a GetApplicationsResponse with 2 applications with
|
||||
* same ApplicationId.
|
||||
|
Loading…
Reference in New Issue
Block a user