From 52ce763a5406432df5cc8546d8b71c017b00b3b1 Mon Sep 17 00:00:00 2001 From: Junping Du Date: Thu, 17 Mar 2016 09:04:41 -0700 Subject: [PATCH] YARN-4785. inconsistent value type of the type field for LeafQueueInfo in response of RM REST API. (cherry picked from commit ca8106d2dd03458944303d93679daa03b1d82ad5) (cherry picked from commit 66257613b420ea8e0754f6ea8fc2d6816f0741e0) --- .../webapp/dao/CapacitySchedulerInfo.java | 26 ++++++++++++++++--- .../TestRMWebServicesCapacitySched.java | 3 +++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/CapacitySchedulerInfo.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/CapacitySchedulerInfo.java index f6332c11ab5..32e4ac5bb36 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/CapacitySchedulerInfo.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/CapacitySchedulerInfo.java @@ -28,6 +28,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueue; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.LeafQueue; +import java.util.ArrayList; +import java.util.List; + @XmlRootElement(name = "capacityScheduler") @XmlType(name = "capacityScheduler") @XmlAccessorType(XmlAccessType.FIELD) @@ -86,14 +89,29 @@ public class CapacitySchedulerInfo extends SchedulerInfo { } protected CapacitySchedulerQueueInfoList getQueues(CSQueue parent) { - CSQueue parentQueue = parent; CapacitySchedulerQueueInfoList queuesInfo = new CapacitySchedulerQueueInfoList(); - for (CSQueue queue : parentQueue.getChildQueues()) { + // JAXB marashalling leads to situation where the "type" field injected + // for JSON changes from string to array depending on order of printing + // Issue gets fixed if all the leaf queues are marshalled before the + // non-leaf queues. See YARN-4785 for more details. + List childQueues = new ArrayList<>(); + List childLeafQueues = new ArrayList<>(); + List childNonLeafQueues = new ArrayList<>(); + for (CSQueue queue : parent.getChildQueues()) { + if (queue instanceof LeafQueue) { + childLeafQueues.add(queue); + } else { + childNonLeafQueues.add(queue); + } + } + childQueues.addAll(childLeafQueues); + childQueues.addAll(childNonLeafQueues); + + for (CSQueue queue : childQueues) { CapacitySchedulerQueueInfo info; if (queue instanceof LeafQueue) { - info = - new CapacitySchedulerLeafQueueInfo((LeafQueue) queue); + info = new CapacitySchedulerLeafQueueInfo((LeafQueue) queue); } else { info = new CapacitySchedulerQueueInfo(queue); info.queues = getQueues(queue); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesCapacitySched.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesCapacitySched.java index 28b1c4fd115..12f0c8b2a55 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesCapacitySched.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesCapacitySched.java @@ -43,6 +43,7 @@ import org.apache.hadoop.yarn.webapp.WebServicesTestUtils; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.w3c.dom.Document; @@ -379,6 +380,8 @@ public class TestRMWebServicesCapacitySched extends JerseyTestBase { verifySubQueue(obj, q2, qi.absoluteCapacity, qi.absoluteMaxCapacity); } } else { + Assert.assertEquals("\"type\" field is incorrect", + "capacitySchedulerLeafQueueInfo", info.getString("type")); LeafQueueInfo lqi = (LeafQueueInfo) qi; lqi.numActiveApplications = info.getInt("numActiveApplications"); lqi.numPendingApplications = info.getInt("numPendingApplications");