YARN-10829. Follow up: Adding null checks before merging ResourceUsage Report (#3252)
This commit is contained in:
parent
2ff3fc50e4
commit
a186460004
@ -133,43 +133,48 @@ private static void mergeAMWithUAM(ApplicationReport am,
|
|||||||
ApplicationResourceUsageReport uamResourceReport =
|
ApplicationResourceUsageReport uamResourceReport =
|
||||||
uam.getApplicationResourceUsageReport();
|
uam.getApplicationResourceUsageReport();
|
||||||
|
|
||||||
amResourceReport.setNumUsedContainers(
|
if (amResourceReport == null) {
|
||||||
amResourceReport.getNumUsedContainers() +
|
am.setApplicationResourceUsageReport(uamResourceReport);
|
||||||
uamResourceReport.getNumUsedContainers());
|
} else if (uamResourceReport != null) {
|
||||||
|
|
||||||
amResourceReport.setNumReservedContainers(
|
amResourceReport.setNumUsedContainers(
|
||||||
amResourceReport.getNumReservedContainers() +
|
amResourceReport.getNumUsedContainers() +
|
||||||
uamResourceReport.getNumReservedContainers());
|
uamResourceReport.getNumUsedContainers());
|
||||||
|
|
||||||
amResourceReport.setUsedResources(Resources.add(
|
amResourceReport.setNumReservedContainers(
|
||||||
amResourceReport.getUsedResources(),
|
amResourceReport.getNumReservedContainers() +
|
||||||
uamResourceReport.getUsedResources()));
|
uamResourceReport.getNumReservedContainers());
|
||||||
|
|
||||||
amResourceReport.setReservedResources(Resources.add(
|
amResourceReport.setUsedResources(Resources.add(
|
||||||
amResourceReport.getReservedResources(),
|
amResourceReport.getUsedResources(),
|
||||||
uamResourceReport.getReservedResources()));
|
uamResourceReport.getUsedResources()));
|
||||||
|
|
||||||
amResourceReport.setNeededResources(Resources.add(
|
amResourceReport.setReservedResources(Resources.add(
|
||||||
amResourceReport.getNeededResources(),
|
amResourceReport.getReservedResources(),
|
||||||
uamResourceReport.getNeededResources()));
|
uamResourceReport.getReservedResources()));
|
||||||
|
|
||||||
amResourceReport.setMemorySeconds(
|
amResourceReport.setNeededResources(Resources.add(
|
||||||
amResourceReport.getMemorySeconds() +
|
amResourceReport.getNeededResources(),
|
||||||
uamResourceReport.getMemorySeconds());
|
uamResourceReport.getNeededResources()));
|
||||||
|
|
||||||
amResourceReport.setVcoreSeconds(
|
amResourceReport.setMemorySeconds(
|
||||||
amResourceReport.getVcoreSeconds() +
|
amResourceReport.getMemorySeconds() +
|
||||||
uamResourceReport.getVcoreSeconds());
|
uamResourceReport.getMemorySeconds());
|
||||||
|
|
||||||
amResourceReport.setQueueUsagePercentage(
|
amResourceReport.setVcoreSeconds(
|
||||||
amResourceReport.getQueueUsagePercentage() +
|
amResourceReport.getVcoreSeconds() +
|
||||||
uamResourceReport.getQueueUsagePercentage());
|
uamResourceReport.getVcoreSeconds());
|
||||||
|
|
||||||
amResourceReport.setClusterUsagePercentage(
|
amResourceReport.setQueueUsagePercentage(
|
||||||
amResourceReport.getClusterUsagePercentage() +
|
amResourceReport.getQueueUsagePercentage() +
|
||||||
uamResourceReport.getClusterUsagePercentage());
|
uamResourceReport.getQueueUsagePercentage());
|
||||||
|
|
||||||
am.setApplicationResourceUsageReport(amResourceReport);
|
amResourceReport.setClusterUsagePercentage(
|
||||||
|
amResourceReport.getClusterUsagePercentage() +
|
||||||
|
uamResourceReport.getClusterUsagePercentage());
|
||||||
|
|
||||||
|
am.setApplicationResourceUsageReport(amResourceReport);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,6 +124,48 @@ public void testMergeUnmanagedApplications() {
|
|||||||
Assert.assertTrue(result.getApplicationList().isEmpty());
|
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
|
* This generates a GetApplicationsResponse with 2 applications with
|
||||||
* same ApplicationId.
|
* same ApplicationId.
|
||||||
|
Loading…
Reference in New Issue
Block a user