|
@@ -19,8 +19,19 @@
|
|
|
package org.apache.hadoop.yarn.server.router.clientrm;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse;
|
|
|
import org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsResponse;
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport;
|
|
|
+import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
|
|
|
+import org.apache.hadoop.yarn.api.records.Resource;
|
|
|
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
|
|
import org.apache.hadoop.yarn.api.records.YarnClusterMetrics;
|
|
|
+import org.apache.hadoop.yarn.server.uam.UnmanagedApplicationManager;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
|
|
@@ -29,6 +40,8 @@ import org.junit.Test;
|
|
|
*/
|
|
|
public class TestRouterYarnClientUtils {
|
|
|
|
|
|
+ private final static String PARTIAL_REPORT = "Partial Report ";
|
|
|
+
|
|
|
@Test
|
|
|
public void testClusterMetricsMerge() {
|
|
|
ArrayList<GetClusterMetricsResponse> responses = new ArrayList<>();
|
|
@@ -54,4 +67,108 @@ public class TestRouterYarnClientUtils {
|
|
|
metrics.setNumNodeManagers(value);
|
|
|
return GetClusterMetricsResponse.newInstance(metrics);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This test validates the correctness of
|
|
|
+ * RouterYarnClientUtils#mergeApplications.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testMergeApplications() {
|
|
|
+ ArrayList<GetApplicationsResponse> responses = new ArrayList<>();
|
|
|
+ responses.add(getApplicationsResponse(1, false));
|
|
|
+ responses.add(getApplicationsResponse(2, false));
|
|
|
+ GetApplicationsResponse result = RouterYarnClientUtils.
|
|
|
+ mergeApplications(responses, false);
|
|
|
+ Assert.assertNotNull(result);
|
|
|
+ Assert.assertEquals(2, result.getApplicationList().size());
|
|
|
+
|
|
|
+ String appName1 = result.getApplicationList().get(0).getName();
|
|
|
+ String appName2 = result.getApplicationList().get(1).getName();
|
|
|
+
|
|
|
+ // Check that no Unmanaged applications are added to the result
|
|
|
+ Assert.assertEquals(false,
|
|
|
+ appName1.contains(UnmanagedApplicationManager.APP_NAME));
|
|
|
+ Assert.assertEquals(false,
|
|
|
+ appName2.contains(UnmanagedApplicationManager.APP_NAME));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This test validates the correctness of
|
|
|
+ * RouterYarnClientUtils#mergeApplications.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testMergeUnmanagedApplications() {
|
|
|
+ ArrayList<GetApplicationsResponse> responses = new ArrayList<>();
|
|
|
+ responses.add(getApplicationsResponse(1, true));
|
|
|
+
|
|
|
+ // Check response if partial results are enabled
|
|
|
+ GetApplicationsResponse result = RouterYarnClientUtils.
|
|
|
+ mergeApplications(responses, true);
|
|
|
+ Assert.assertNotNull(result);
|
|
|
+ Assert.assertEquals(1, result.getApplicationList().size());
|
|
|
+ ApplicationReport appReport = result.getApplicationList().iterator().next();
|
|
|
+ String appName = appReport.getName();
|
|
|
+ Assert.assertTrue(appName.startsWith(PARTIAL_REPORT));
|
|
|
+
|
|
|
+ // Check ApplicationResourceUsageReport merge
|
|
|
+ ApplicationResourceUsageReport resourceUsageReport =
|
|
|
+ appReport.getApplicationResourceUsageReport();
|
|
|
+
|
|
|
+ Assert.assertEquals(2, resourceUsageReport.getNumUsedContainers());
|
|
|
+ Assert.assertEquals(4, resourceUsageReport.getNumReservedContainers());
|
|
|
+
|
|
|
+ // Check response if partial results are disabled
|
|
|
+ result = RouterYarnClientUtils.
|
|
|
+ mergeApplications(responses, false);
|
|
|
+ Assert.assertNotNull(result);
|
|
|
+ Assert.assertTrue(result.getApplicationList().isEmpty());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This generates a GetApplicationsResponse with 2 applications with
|
|
|
+ * same ApplicationId.
|
|
|
+ * @param value Used as Id in ApplicationId
|
|
|
+ * @param uamOnly If set to true, only unmanaged applications are added in
|
|
|
+ * response, else one managed and one unmanaged applications
|
|
|
+ * are added with same ApplicationId.
|
|
|
+ * @return GetApplicationsResponse
|
|
|
+ */
|
|
|
+ private GetApplicationsResponse getApplicationsResponse(int value,
|
|
|
+ boolean uamOnly) {
|
|
|
+ String appName = uamOnly? UnmanagedApplicationManager.APP_NAME: "appname";
|
|
|
+ List<ApplicationReport> applications = new ArrayList<>();
|
|
|
+
|
|
|
+ // Create first application report. This is a managed app by default.
|
|
|
+ // If uamOnly is true, this becomes unmanaged application.
|
|
|
+ ApplicationId appId = ApplicationId.newInstance(1234, value);
|
|
|
+ Resource resource = Resource.newInstance(1024, 1);
|
|
|
+ ApplicationResourceUsageReport appResourceUsageReport =
|
|
|
+ ApplicationResourceUsageReport.newInstance(
|
|
|
+ 1, 2, resource, resource,
|
|
|
+ resource, null, 0.1f,
|
|
|
+ 0.1f, null);
|
|
|
+
|
|
|
+ ApplicationReport appReport = ApplicationReport.newInstance(
|
|
|
+ appId, ApplicationAttemptId.newInstance(appId, 1),
|
|
|
+ "user", "queue", appName, "host",
|
|
|
+ 124, null, YarnApplicationState.RUNNING,
|
|
|
+ "diagnostics", "url", 0, 0,
|
|
|
+ 0, FinalApplicationStatus.SUCCEEDED, appResourceUsageReport, "N/A",
|
|
|
+ 0.53789f, "YARN", null, null, uamOnly, null, null, null);
|
|
|
+
|
|
|
+ // Create second application report. This is always unmanaged application.
|
|
|
+ ApplicationId appId2 = ApplicationId.newInstance(1234, value);
|
|
|
+ ApplicationReport appReport2 = ApplicationReport.newInstance(
|
|
|
+ appId2, ApplicationAttemptId.newInstance(appId, 1),
|
|
|
+ "user", "queue", UnmanagedApplicationManager.APP_NAME, "host",
|
|
|
+ 124, null, YarnApplicationState.RUNNING,
|
|
|
+ "diagnostics", "url", 0, 0,
|
|
|
+ 0, FinalApplicationStatus.SUCCEEDED, appResourceUsageReport, "N/A",
|
|
|
+ 0.53789f, "YARN", null, null, true, null, null, null);
|
|
|
+
|
|
|
+ applications.add(appReport);
|
|
|
+ applications.add(appReport2);
|
|
|
+
|
|
|
+ return GetApplicationsResponse.newInstance(applications);
|
|
|
+ }
|
|
|
}
|