YARN-10829. Follow up: Adding null checks before merging ResourceUsage Report (#3252)

This commit is contained in:
Akshat Bordia 2021-09-08 23:06:56 +05:30 committed by GitHub
parent 2ff3fc50e4
commit a186460004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 28 deletions

View File

@ -133,43 +133,48 @@ public final class RouterYarnClientUtils {
ApplicationResourceUsageReport uamResourceReport =
uam.getApplicationResourceUsageReport();
amResourceReport.setNumUsedContainers(
amResourceReport.getNumUsedContainers() +
uamResourceReport.getNumUsedContainers());
if (amResourceReport == null) {
am.setApplicationResourceUsageReport(uamResourceReport);
} else if (uamResourceReport != null) {
amResourceReport.setNumReservedContainers(
amResourceReport.getNumReservedContainers() +
uamResourceReport.getNumReservedContainers());
amResourceReport.setNumUsedContainers(
amResourceReport.getNumUsedContainers() +
uamResourceReport.getNumUsedContainers());
amResourceReport.setUsedResources(Resources.add(
amResourceReport.getUsedResources(),
uamResourceReport.getUsedResources()));
amResourceReport.setNumReservedContainers(
amResourceReport.getNumReservedContainers() +
uamResourceReport.getNumReservedContainers());
amResourceReport.setReservedResources(Resources.add(
amResourceReport.getReservedResources(),
uamResourceReport.getReservedResources()));
amResourceReport.setUsedResources(Resources.add(
amResourceReport.getUsedResources(),
uamResourceReport.getUsedResources()));
amResourceReport.setNeededResources(Resources.add(
amResourceReport.getNeededResources(),
uamResourceReport.getNeededResources()));
amResourceReport.setReservedResources(Resources.add(
amResourceReport.getReservedResources(),
uamResourceReport.getReservedResources()));
amResourceReport.setMemorySeconds(
amResourceReport.getMemorySeconds() +
uamResourceReport.getMemorySeconds());
amResourceReport.setNeededResources(Resources.add(
amResourceReport.getNeededResources(),
uamResourceReport.getNeededResources()));
amResourceReport.setVcoreSeconds(
amResourceReport.getVcoreSeconds() +
uamResourceReport.getVcoreSeconds());
amResourceReport.setMemorySeconds(
amResourceReport.getMemorySeconds() +
uamResourceReport.getMemorySeconds());
amResourceReport.setQueueUsagePercentage(
amResourceReport.getQueueUsagePercentage() +
uamResourceReport.getQueueUsagePercentage());
amResourceReport.setVcoreSeconds(
amResourceReport.getVcoreSeconds() +
uamResourceReport.getVcoreSeconds());
amResourceReport.setClusterUsagePercentage(
amResourceReport.getClusterUsagePercentage() +
uamResourceReport.getClusterUsagePercentage());
amResourceReport.setQueueUsagePercentage(
amResourceReport.getQueueUsagePercentage() +
uamResourceReport.getQueueUsagePercentage());
am.setApplicationResourceUsageReport(amResourceReport);
amResourceReport.setClusterUsagePercentage(
amResourceReport.getClusterUsagePercentage() +
uamResourceReport.getClusterUsagePercentage());
am.setApplicationResourceUsageReport(amResourceReport);
}
}
/**

View File

@ -124,6 +124,48 @@ public class TestRouterYarnClientUtils {
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.