|
@@ -0,0 +1,311 @@
|
|
|
+/**
|
|
|
+ * Licensed to the Apache Software Foundation (ASF) under one
|
|
|
+ * or more contributor license agreements. See the NOTICE file
|
|
|
+ * distributed with this work for additional information
|
|
|
+ * regarding copyright ownership. The ASF licenses this file
|
|
|
+ * to you under the Apache License, Version 2.0 (the
|
|
|
+ * "License"); you may not use this file except in compliance
|
|
|
+ * with the License. You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ */
|
|
|
+
|
|
|
+package org.apache.hadoop.yarn.server.router.webapp;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppInfo;
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppsInfo;
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceRequestInfo;
|
|
|
+import org.apache.hadoop.yarn.server.uam.UnmanagedApplicationManager;
|
|
|
+import org.junit.Assert;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test class to validate RouterWebServiceUtil methods.
|
|
|
+ */
|
|
|
+public class TestRouterWebServiceUtil {
|
|
|
+
|
|
|
+ private static final ApplicationId APPID1 = ApplicationId.newInstance(1, 1);
|
|
|
+ private static final ApplicationId APPID2 = ApplicationId.newInstance(2, 1);
|
|
|
+ private static final ApplicationId APPID3 = ApplicationId.newInstance(3, 1);
|
|
|
+ private static final ApplicationId APPID4 = ApplicationId.newInstance(4, 1);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This test validates the correctness of RouterWebServiceUtil#mergeAppsInfo
|
|
|
+ * in case we want to merge 4 AMs. The expected result would be the same 4
|
|
|
+ * AMs.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testMerge4DifferentApps() {
|
|
|
+
|
|
|
+ AppsInfo apps = new AppsInfo();
|
|
|
+ int value = 1000;
|
|
|
+
|
|
|
+ AppInfo app1 = new AppInfo();
|
|
|
+ app1.setAppId(APPID1.toString());
|
|
|
+ app1.setAMHostHttpAddress("http://i_am_the_AM1:1234");
|
|
|
+ app1.setState(YarnApplicationState.FINISHED);
|
|
|
+ app1.setNumAMContainerPreempted(value);
|
|
|
+ apps.add(app1);
|
|
|
+
|
|
|
+ AppInfo app2 = new AppInfo();
|
|
|
+ app2.setAppId(APPID2.toString());
|
|
|
+ app2.setAMHostHttpAddress("http://i_am_the_AM2:1234");
|
|
|
+ app2.setState(YarnApplicationState.ACCEPTED);
|
|
|
+ app2.setAllocatedVCores(2 * value);
|
|
|
+
|
|
|
+ apps.add(app2);
|
|
|
+
|
|
|
+ AppInfo app3 = new AppInfo();
|
|
|
+ app3.setAppId(APPID3.toString());
|
|
|
+ app3.setAMHostHttpAddress("http://i_am_the_AM3:1234");
|
|
|
+ app3.setState(YarnApplicationState.RUNNING);
|
|
|
+ app3.setReservedMB(3 * value);
|
|
|
+ apps.add(app3);
|
|
|
+
|
|
|
+ AppInfo app4 = new AppInfo();
|
|
|
+ app4.setAppId(APPID4.toString());
|
|
|
+ app4.setAMHostHttpAddress("http://i_am_the_AM4:1234");
|
|
|
+ app4.setState(YarnApplicationState.NEW);
|
|
|
+ app4.setAllocatedMB(4 * value);
|
|
|
+ apps.add(app4);
|
|
|
+
|
|
|
+ AppsInfo result = RouterWebServiceUtil.mergeAppsInfo(apps.getApps(), false);
|
|
|
+ Assert.assertNotNull(result);
|
|
|
+ Assert.assertEquals(4, result.getApps().size());
|
|
|
+
|
|
|
+ List<String> appIds = new ArrayList<String>();
|
|
|
+ AppInfo appInfo1 = null, appInfo2 = null, appInfo3 = null, appInfo4 = null;
|
|
|
+ for (AppInfo app : result.getApps()) {
|
|
|
+ appIds.add(app.getAppId());
|
|
|
+ if (app.getAppId().equals(APPID1.toString())) {
|
|
|
+ appInfo1 = app;
|
|
|
+ }
|
|
|
+ if (app.getAppId().equals(APPID2.toString())) {
|
|
|
+ appInfo2 = app;
|
|
|
+ }
|
|
|
+ if (app.getAppId().equals(APPID3.toString())) {
|
|
|
+ appInfo3 = app;
|
|
|
+ }
|
|
|
+ if (app.getAppId().equals(APPID4.toString())) {
|
|
|
+ appInfo4 = app;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Assert.assertTrue(appIds.contains(APPID1.toString()));
|
|
|
+ Assert.assertTrue(appIds.contains(APPID2.toString()));
|
|
|
+ Assert.assertTrue(appIds.contains(APPID3.toString()));
|
|
|
+ Assert.assertTrue(appIds.contains(APPID4.toString()));
|
|
|
+
|
|
|
+ // Check preservations APP1
|
|
|
+ Assert.assertEquals(app1.getState(), appInfo1.getState());
|
|
|
+ Assert.assertEquals(app1.getNumAMContainerPreempted(),
|
|
|
+ appInfo1.getNumAMContainerPreempted());
|
|
|
+
|
|
|
+ // Check preservations APP2
|
|
|
+ Assert.assertEquals(app2.getState(), appInfo2.getState());
|
|
|
+ Assert.assertEquals(app3.getAllocatedVCores(),
|
|
|
+ appInfo3.getAllocatedVCores());
|
|
|
+
|
|
|
+ // Check preservations APP3
|
|
|
+ Assert.assertEquals(app3.getState(), appInfo3.getState());
|
|
|
+ Assert.assertEquals(app3.getReservedMB(), appInfo3.getReservedMB());
|
|
|
+
|
|
|
+ // Check preservations APP3
|
|
|
+ Assert.assertEquals(app4.getState(), appInfo4.getState());
|
|
|
+ Assert.assertEquals(app3.getAllocatedMB(), appInfo3.getAllocatedMB());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This test validates the correctness of RouterWebServiceUtil#mergeAppsInfo
|
|
|
+ * in case we want to merge 2 UAMs and their own AM. The status of the AM is
|
|
|
+ * FINISHED, so we check the correctness of the merging of the historical
|
|
|
+ * values. The expected result would be 1 report with the merged information.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testMergeAppsFinished() {
|
|
|
+
|
|
|
+ AppsInfo apps = new AppsInfo();
|
|
|
+
|
|
|
+ String amHost = "http://i_am_the_AM1:1234";
|
|
|
+ AppInfo am = new AppInfo();
|
|
|
+ am.setAppId(APPID1.toString());
|
|
|
+ am.setAMHostHttpAddress(amHost);
|
|
|
+ am.setState(YarnApplicationState.FINISHED);
|
|
|
+
|
|
|
+ int value = 1000;
|
|
|
+ setAppInfoFinished(am, value);
|
|
|
+
|
|
|
+ apps.add(am);
|
|
|
+
|
|
|
+ AppInfo uam1 = new AppInfo();
|
|
|
+ uam1.setAppId(APPID1.toString());
|
|
|
+ apps.add(uam1);
|
|
|
+
|
|
|
+ setAppInfoFinished(uam1, value);
|
|
|
+
|
|
|
+ AppInfo uam2 = new AppInfo();
|
|
|
+ uam2.setAppId(APPID1.toString());
|
|
|
+ apps.add(uam2);
|
|
|
+
|
|
|
+ setAppInfoFinished(uam2, value);
|
|
|
+
|
|
|
+ // in this case the result does not change if we enable partial result
|
|
|
+ AppsInfo result = RouterWebServiceUtil.mergeAppsInfo(apps.getApps(), false);
|
|
|
+ Assert.assertNotNull(result);
|
|
|
+ Assert.assertEquals(1, result.getApps().size());
|
|
|
+
|
|
|
+ AppInfo app = result.getApps().get(0);
|
|
|
+
|
|
|
+ Assert.assertEquals(APPID1.toString(), app.getAppId());
|
|
|
+ Assert.assertEquals(amHost, app.getAMHostHttpAddress());
|
|
|
+ Assert.assertEquals(value * 3, app.getPreemptedResourceMB());
|
|
|
+ Assert.assertEquals(value * 3, app.getPreemptedResourceVCores());
|
|
|
+ Assert.assertEquals(value * 3, app.getNumNonAMContainerPreempted());
|
|
|
+ Assert.assertEquals(value * 3, app.getNumAMContainerPreempted());
|
|
|
+ Assert.assertEquals(value * 3, app.getPreemptedMemorySeconds());
|
|
|
+ Assert.assertEquals(value * 3, app.getPreemptedVcoreSeconds());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setAppInfoFinished(AppInfo am, int value) {
|
|
|
+ am.setPreemptedResourceMB(value);
|
|
|
+ am.setPreemptedResourceVCores(value);
|
|
|
+ am.setNumNonAMContainerPreempted(value);
|
|
|
+ am.setNumAMContainerPreempted(value);
|
|
|
+ am.setPreemptedMemorySeconds(value);
|
|
|
+ am.setPreemptedVcoreSeconds(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This test validates the correctness of RouterWebServiceUtil#mergeAppsInfo
|
|
|
+ * in case we want to merge 2 UAMs and their own AM. The status of the AM is
|
|
|
+ * RUNNING, so we check the correctness of the merging of the runtime values.
|
|
|
+ * The expected result would be 1 report with the merged information.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testMergeAppsRunning() {
|
|
|
+
|
|
|
+ AppsInfo apps = new AppsInfo();
|
|
|
+
|
|
|
+ String amHost = "http://i_am_the_AM2:1234";
|
|
|
+ AppInfo am = new AppInfo();
|
|
|
+ am.setAppId(APPID2.toString());
|
|
|
+ am.setAMHostHttpAddress(amHost);
|
|
|
+ am.setState(YarnApplicationState.RUNNING);
|
|
|
+
|
|
|
+ int value = 1000;
|
|
|
+ setAppInfoRunning(am, value);
|
|
|
+
|
|
|
+ apps.add(am);
|
|
|
+
|
|
|
+ AppInfo uam1 = new AppInfo();
|
|
|
+ uam1.setAppId(APPID2.toString());
|
|
|
+ uam1.setState(YarnApplicationState.RUNNING);
|
|
|
+ apps.add(uam1);
|
|
|
+
|
|
|
+ setAppInfoRunning(uam1, value);
|
|
|
+
|
|
|
+ AppInfo uam2 = new AppInfo();
|
|
|
+ uam2.setAppId(APPID2.toString());
|
|
|
+ uam2.setState(YarnApplicationState.RUNNING);
|
|
|
+ apps.add(uam2);
|
|
|
+
|
|
|
+ setAppInfoRunning(uam2, value);
|
|
|
+
|
|
|
+ // in this case the result does not change if we enable partial result
|
|
|
+ AppsInfo result = RouterWebServiceUtil.mergeAppsInfo(apps.getApps(), false);
|
|
|
+ Assert.assertNotNull(result);
|
|
|
+ Assert.assertEquals(1, result.getApps().size());
|
|
|
+
|
|
|
+ AppInfo app = result.getApps().get(0);
|
|
|
+
|
|
|
+ Assert.assertEquals(APPID2.toString(), app.getAppId());
|
|
|
+ Assert.assertEquals(amHost, app.getAMHostHttpAddress());
|
|
|
+ Assert.assertEquals(value * 3, app.getAllocatedMB());
|
|
|
+ Assert.assertEquals(value * 3, app.getAllocatedVCores());
|
|
|
+ Assert.assertEquals(value * 3, app.getReservedMB());
|
|
|
+ Assert.assertEquals(value * 3, app.getReservedVCores());
|
|
|
+ Assert.assertEquals(value * 3, app.getRunningContainers());
|
|
|
+ Assert.assertEquals(value * 3, app.getMemorySeconds());
|
|
|
+ Assert.assertEquals(value * 3, app.getVcoreSeconds());
|
|
|
+ Assert.assertEquals(3, app.getResourceRequests().size());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setAppInfoRunning(AppInfo am, int value) {
|
|
|
+ am.getResourceRequests().add(new ResourceRequestInfo());
|
|
|
+ am.setAllocatedMB(value);
|
|
|
+ am.setAllocatedVCores(value);
|
|
|
+ am.setReservedMB(value);
|
|
|
+ am.setReservedVCores(value);
|
|
|
+ am.setRunningContainers(value);
|
|
|
+ am.setMemorySeconds(value);
|
|
|
+ am.setVcoreSeconds(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This test validates the correctness of RouterWebServiceUtil#mergeAppsInfo
|
|
|
+ * in case we want to merge 2 UAMs without their own AM. The expected result
|
|
|
+ * would be an empty report or a partial report of the 2 UAMs depending on the
|
|
|
+ * selected policy.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testMerge2UAM() {
|
|
|
+
|
|
|
+ AppsInfo apps = new AppsInfo();
|
|
|
+
|
|
|
+ AppInfo app1 = new AppInfo();
|
|
|
+ app1.setAppId(APPID1.toString());
|
|
|
+ app1.setName(UnmanagedApplicationManager.APP_NAME);
|
|
|
+ app1.setState(YarnApplicationState.RUNNING);
|
|
|
+ apps.add(app1);
|
|
|
+
|
|
|
+ AppInfo app2 = new AppInfo();
|
|
|
+ app2.setAppId(APPID1.toString());
|
|
|
+ app2.setName(UnmanagedApplicationManager.APP_NAME);
|
|
|
+ app2.setState(YarnApplicationState.RUNNING);
|
|
|
+ apps.add(app2);
|
|
|
+
|
|
|
+ AppsInfo result = RouterWebServiceUtil.mergeAppsInfo(apps.getApps(), false);
|
|
|
+ Assert.assertNotNull(result);
|
|
|
+ Assert.assertEquals(0, result.getApps().size());
|
|
|
+
|
|
|
+ // By enabling partial result, the expected result would be a partial report
|
|
|
+ // of the 2 UAMs
|
|
|
+ AppsInfo result2 = RouterWebServiceUtil.mergeAppsInfo(apps.getApps(), true);
|
|
|
+ Assert.assertNotNull(result2);
|
|
|
+ Assert.assertEquals(1, result2.getApps().size());
|
|
|
+ Assert.assertEquals(YarnApplicationState.RUNNING,
|
|
|
+ result2.getApps().get(0).getState());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This test validates the correctness of RouterWebServiceUtil#mergeAppsInfo
|
|
|
+ * in case we want to merge 1 UAM that does not depend on Federation. The
|
|
|
+ * excepted result would be the same app report.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testMergeUAM() {
|
|
|
+
|
|
|
+ AppsInfo apps = new AppsInfo();
|
|
|
+
|
|
|
+ AppInfo app1 = new AppInfo();
|
|
|
+ app1.setAppId(APPID1.toString());
|
|
|
+ app1.setName("Test");
|
|
|
+ apps.add(app1);
|
|
|
+
|
|
|
+ // in this case the result does not change if we enable partial result
|
|
|
+ AppsInfo result = RouterWebServiceUtil.mergeAppsInfo(apps.getApps(), false);
|
|
|
+ Assert.assertNotNull(result);
|
|
|
+ Assert.assertEquals(1, result.getApps().size());
|
|
|
+ }
|
|
|
+}
|