You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2014/08/21 00:49:45 UTC

svn commit: r1619259 - in /qpid/trunk/qpid/java: broker-core/src/main/java/org/apache/qpid/server/binding/ broker-core/src/main/java/org/apache/qpid/server/exchange/ broker-core/src/main/java/org/apache/qpid/server/model/ broker-core/src/main/java/org/...

Author: rgodfrey
Date: Wed Aug 20 22:49:44 2014
New Revision: 1619259

URL: http://svn.apache.org/r1619259
Log:
QPID-6027 : Give Json extracts a stable ordering, and add option to REST servlet to extract data for an initial configuration (e.g. for a vhost)

Modified:
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java
    qpid/trunk/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java Wed Aug 20 22:49:44 2014
@@ -36,6 +36,7 @@ import org.apache.qpid.server.logging.Ev
 import org.apache.qpid.server.logging.messages.BindingMessages;
 import org.apache.qpid.server.logging.subjects.BindingLogSubject;
 import org.apache.qpid.server.model.AbstractConfiguredObject;
+import org.apache.qpid.server.model.Binding;
 import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.model.ManagedAttributeField;
 import org.apache.qpid.server.model.Queue;
@@ -66,12 +67,31 @@ public class BindingImpl
 
     public BindingImpl(Map<String, Object> attributes, AMQQueue queue, ExchangeImpl exchange)
     {
-        super(parentsMap(queue,exchange),enhanceWithDurable(attributes,queue,exchange));
+        super(parentsMap(queue,exchange),stripEmptyArguments(enhanceWithDurable(attributes, queue, exchange)));
         _bindingKey = getName();
         _queue = queue;
         _exchange = exchange;
     }
 
+    private static Map<String, Object> stripEmptyArguments(final Map<String, Object> attributes)
+    {
+        Map<String,Object> returnVal;
+        if(attributes != null
+           && attributes.containsKey(Binding.ARGUMENTS)
+           && (attributes.get(Binding.ARGUMENTS) instanceof Map)
+           && ((Map)(attributes.get(Binding.ARGUMENTS))).isEmpty())
+        {
+            returnVal = new HashMap<>(attributes);
+            returnVal.remove(Binding.ARGUMENTS);
+        }
+        else
+        {
+            returnVal = attributes;
+        }
+
+        return returnVal;
+    }
+
     @Override
     protected void onOpen()
     {
@@ -113,7 +133,7 @@ public class BindingImpl
     {
         if(!attributes.containsKey(DURABLE))
         {
-            attributes = new HashMap<String, Object>(attributes);
+            attributes = new HashMap(attributes);
             attributes.put(DURABLE, queue.isDurable() && exchange.isDurable());
         }
         return attributes;

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java Wed Aug 20 22:49:44 2014
@@ -123,7 +123,6 @@ public class HeadersExchange extends Abs
     {
         String bindingKey = binding.getBindingKey();
         AMQQueue queue = binding.getAMQQueue();
-        Map<String,Object> args = binding.getArguments();
 
         assert queue != null;
         assert bindingKey != null;
@@ -143,7 +142,7 @@ public class HeadersExchange extends Abs
         if(_logger.isDebugEnabled())
         {
             _logger.debug("Exchange " + getName() + ": Binding " + queue.getName() +
-                          " with binding key '" +bindingKey + "' and args: " + args);
+                          " with binding key '" +bindingKey + "' and args: " + binding.getArguments());
         }
 
         _bindingHeaderMatchers.add(new HeadersBinding(binding));

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java Wed Aug 20 22:49:44 2014
@@ -1100,7 +1100,7 @@ public abstract class AbstractConfigured
                     @Override
                     public Map<String, Object> run()
                     {
-                        Map<String,Object> attributes = new HashMap<String, Object>();
+                        Map<String,Object> attributes = new LinkedHashMap<String, Object>();
                         Map<String,Object> actualAttributes = getActualAttributes();
                         for(ConfiguredObjectAttribute<?,?> attr : _attributeTypes.values())
                         {

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java Wed Aug 20 22:49:44 2014
@@ -24,6 +24,7 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.AbstractCollection;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
@@ -33,6 +34,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
+import java.util.TreeMap;
 import java.util.TreeSet;
 
 import org.apache.log4j.Logger;
@@ -45,16 +47,105 @@ public class ConfiguredObjectTypeRegistr
 {
     private static final Logger LOGGER = Logger.getLogger(ConfiguredObjectTypeRegistry.class);
 
-    private static final Comparator<ConfiguredObjectAttributeOrStatistic<?,?>> NAME_COMPARATOR = new Comparator<ConfiguredObjectAttributeOrStatistic<?, ?>>()
+    private static Map<String,Integer> STANDARD_FIRST_FIELDS_ORDER = new HashMap<>();
+    static
+    {
+        int i = 0;
+        for(String name : Arrays.asList(ConfiguredObject.ID,
+                                        ConfiguredObject.NAME,
+                                        ConfiguredObject.DESCRIPTION,
+                                        ConfiguredObject.TYPE,
+                                        ConfiguredObject.DESIRED_STATE,
+                                        ConfiguredObject.DURABLE,
+                                        ConfiguredObject.LIFETIME_POLICY,
+                                        ConfiguredObject.CONTEXT))
+        {
+            STANDARD_FIRST_FIELDS_ORDER.put(name, i++);
+        }
+
+    }
+
+    private static Map<String,Integer> STANDARD_LAST_FIELDS_ORDER = new HashMap<>();
+    static
+    {
+        int i = 0;
+        for(String name : Arrays.asList(ConfiguredObject.LAST_UPDATED_BY,
+                                        ConfiguredObject.LAST_UPDATED_TIME,
+                                        ConfiguredObject.CREATED_BY,
+                                        ConfiguredObject.CREATED_TIME))
+        {
+            STANDARD_LAST_FIELDS_ORDER.put(name, i++);
+        }
+
+    }
+
+
+    private static final Comparator<ConfiguredObjectAttributeOrStatistic<?,?>> OBJECT_NAME_COMPARATOR = new Comparator<ConfiguredObjectAttributeOrStatistic<?, ?>>()
     {
         @Override
         public int compare(final ConfiguredObjectAttributeOrStatistic<?, ?> left,
                            final ConfiguredObjectAttributeOrStatistic<?, ?> right)
         {
-            return left.getName().compareTo(right.getName());
+            String leftName = left.getName();
+            String rightName = right.getName();
+            return compareAttributeNames(leftName, rightName);
         }
     };
 
+    private static final Comparator<String> NAME_COMPARATOR = new Comparator<String>()
+    {
+        @Override
+        public int compare(final String left, final String right)
+        {
+            return compareAttributeNames(left, right);
+        }
+    };
+
+    private static int compareAttributeNames(final String leftName, final String rightName)
+    {
+        int result;
+        if(leftName.equals(rightName))
+        {
+            result = 0;
+        }
+        else if(STANDARD_FIRST_FIELDS_ORDER.containsKey(leftName))
+        {
+            if(STANDARD_FIRST_FIELDS_ORDER.containsKey(rightName))
+            {
+                result = STANDARD_FIRST_FIELDS_ORDER.get(leftName) - STANDARD_FIRST_FIELDS_ORDER.get(rightName);
+            }
+            else
+            {
+                result = -1;
+            }
+        }
+        else if(STANDARD_FIRST_FIELDS_ORDER.containsKey(rightName))
+        {
+            result = 1;
+        }
+        else if(STANDARD_LAST_FIELDS_ORDER.containsKey(rightName))
+        {
+            if(STANDARD_LAST_FIELDS_ORDER.containsKey(leftName))
+            {
+                result = STANDARD_LAST_FIELDS_ORDER.get(leftName) - STANDARD_LAST_FIELDS_ORDER.get(rightName);
+            }
+            else
+            {
+                result = -1;
+            }
+        }
+        else if(STANDARD_LAST_FIELDS_ORDER.containsKey(leftName))
+        {
+            result = 1;
+        }
+        else
+        {
+            result = leftName.compareTo(rightName);
+        }
+
+        return result;
+    }
+
 
     private final Map<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectAttribute<?,?>>> _allAttributes =
             Collections.synchronizedMap(new HashMap<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectAttribute<?, ?>>>());
@@ -373,8 +464,8 @@ public class ConfiguredObjectTypeRegistr
                 process((Class<? extends ConfiguredObject>) superclass);
             }
 
-            final SortedSet<ConfiguredObjectAttribute<?, ?>> attributeSet = new TreeSet<>(NAME_COMPARATOR);
-            final SortedSet<ConfiguredObjectStatistic<?, ?>> statisticSet = new TreeSet<>(NAME_COMPARATOR);
+            final SortedSet<ConfiguredObjectAttribute<?, ?>> attributeSet = new TreeSet<>(OBJECT_NAME_COMPARATOR);
+            final SortedSet<ConfiguredObjectStatistic<?, ?>> statisticSet = new TreeSet<>(OBJECT_NAME_COMPARATOR);
 
             _allAttributes.put(clazz, attributeSet);
             _allStatistics.put(clazz, statisticSet);
@@ -480,7 +571,7 @@ public class ConfiguredObjectTypeRegistr
 
     private <X extends ConfiguredObject> void processAttributesTypesAndFields(final Class<X> clazz)
     {
-        Map<String,ConfiguredObjectAttribute<?,?>> attrMap = new HashMap<String, ConfiguredObjectAttribute<?, ?>>();
+        Map<String,ConfiguredObjectAttribute<?,?>> attrMap = new TreeMap<>(NAME_COMPARATOR);
         Map<String,AutomatedField> fieldMap = new HashMap<String, AutomatedField>();
 
 

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java Wed Aug 20 22:49:44 2014
@@ -52,6 +52,7 @@ public class VirtualHostAliasAdapter ext
         final Map<String, Object> attributes = new HashMap<String, Object>();
         attributes.put(ID, UUID.randomUUID());
         attributes.put(NAME, virtualHost.getName());
+        attributes.put(DURABLE, false);
         return attributes;
     }
 

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java Wed Aug 20 22:49:44 2014
@@ -31,11 +31,14 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
 import java.util.UUID;
 
 import org.apache.log4j.Logger;
@@ -385,8 +388,6 @@ public class JsonFileConfigStore impleme
     {
         ConfiguredObjectRecord record = _objectsById.get(id);
         Map<String,Object> map = new LinkedHashMap<String, Object>();
-        map.put("id", id);
-        map.putAll(record.getAttributes());
 
         Collection<Class<? extends ConfiguredObject>> parentTypes = _parent.getModel().getParentTypes(type);
         if(parentTypes.size() > 1)
@@ -403,9 +404,21 @@ public class JsonFileConfigStore impleme
             }
         }
 
-        Collection<Class<? extends ConfiguredObject>> childClasses =
+        map.put("id", id);
+        map.putAll(record.getAttributes());
+
+        List<Class<? extends ConfiguredObject>> childClasses =
                 new ArrayList<Class<? extends ConfiguredObject>>(_parent.getModel().getChildTypes(type));
 
+        Collections.sort(childClasses, new Comparator<Class<? extends ConfiguredObject>>()
+        {
+            @Override
+            public int compare(final Class<? extends ConfiguredObject> o1, final Class<? extends ConfiguredObject> o2)
+            {
+                return o1.getSimpleName().compareTo(o2.getSimpleName());
+            }
+        });
+
         for(Class<? extends ConfiguredObject> childClass : childClasses)
         {
             // only add if this is the "first" parent
@@ -416,6 +429,14 @@ public class JsonFileConfigStore impleme
                 if(childIds != null)
                 {
                     List<Map<String,Object>> entities = new ArrayList<Map<String, Object>>();
+                    SortedSet<ConfiguredObjectRecord> sortedChildren = new TreeSet<>(new Comparator<ConfiguredObjectRecord>()
+                    {
+                        @Override
+                        public int compare(final ConfiguredObjectRecord o1, final ConfiguredObjectRecord o2)
+                        {
+                            return ((String)o1.getAttributes().get(ConfiguredObject.NAME)).compareTo(((String)o2.getAttributes().get(ConfiguredObject.NAME)));
+                        }
+                    });
                     for(UUID childId : childIds)
                     {
                         ConfiguredObjectRecord childRecord = _objectsById.get(childId);

Modified: qpid/trunk/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java Wed Aug 20 22:49:44 2014
@@ -21,7 +21,9 @@
 package org.apache.qpid.server.protocol.v0_10;
 
 
-import org.apache.qpid.server.flow.AbstractFlowCreditManager;public class CreditCreditManager extends AbstractFlowCreditManager implements FlowCreditManager_0_10
+import org.apache.qpid.server.flow.AbstractFlowCreditManager;
+
+public class CreditCreditManager extends AbstractFlowCreditManager implements FlowCreditManager_0_10
 {
     private volatile long _bytesCredit;
     private volatile long _messageCredit;

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java Wed Aug 20 22:49:44 2014
@@ -20,11 +20,17 @@
 package org.apache.qpid.server.management.plugin.servlet.rest;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.qpid.server.model.ConfiguredObject;
 
@@ -33,20 +39,32 @@ public class ConfiguredObjectToMapConver
     /** Name of the key used for the statistics map */
     public static final String STATISTICS_MAP_KEY = "statistics";
 
+    private static Set<String> CONFIG_EXCLUDED_ATTRIBUTES =
+            new HashSet<>(Arrays.asList(ConfiguredObject.ID,
+                                        ConfiguredObject.DURABLE,
+                                        ConfiguredObject.CREATED_BY,
+                                        ConfiguredObject.CREATED_TIME,
+                                        ConfiguredObject.LAST_UPDATED_BY,
+                                        ConfiguredObject.LAST_UPDATED_TIME));
+
     public Map<String, Object> convertObjectToMap(final ConfiguredObject<?> confObject,
                                                   Class<? extends ConfiguredObject> clazz,
                                                   int depth,
                                                   final boolean useActualValues,
-                                                  final boolean includeSystemContext)
+                                                  final boolean includeSystemContext,
+                                                  final boolean extractAsConfig)
     {
-        Map<String, Object> object = new LinkedHashMap<String, Object>();
+        Map<String, Object> object = new LinkedHashMap<>();
 
-        incorporateAttributesIntoMap(confObject, object, useActualValues, includeSystemContext);
-        incorporateStatisticsIntoMap(confObject, object);
+        incorporateAttributesIntoMap(confObject, object, useActualValues, includeSystemContext, extractAsConfig);
+        if(!extractAsConfig)
+        {
+            incorporateStatisticsIntoMap(confObject, object);
+        }
 
         if(depth > 0)
         {
-            incorporateChildrenIntoMap(confObject, clazz, depth, object, useActualValues, includeSystemContext);
+            incorporateChildrenIntoMap(confObject, clazz, depth, object, useActualValues, includeSystemContext, extractAsConfig);
         }
         return object;
     }
@@ -56,51 +74,79 @@ public class ConfiguredObjectToMapConver
             final ConfiguredObject<?> confObject,
             Map<String, Object> object,
             final boolean useActualValues,
-            final boolean includeSystemContext)
+            final boolean includeSystemContext,
+            final boolean extractAsConfig)
     {
-
-        for(String name : confObject.getAttributeNames())
+        // if extracting as config add a fake attribute for each secondary parent
+        if(extractAsConfig && confObject.getModel().getParentTypes(confObject.getCategoryClass()).size()>1)
         {
-            Object value = useActualValues ? confObject.getActualAttributes().get(name) : confObject.getAttribute(name);
-            if(value instanceof ConfiguredObject)
+            Iterator<Class<? extends ConfiguredObject>> parentClasses =
+                    confObject.getModel().getParentTypes(confObject.getCategoryClass()).iterator();
+
+            // ignore the first parent which is supplied by structure
+            parentClasses.next();
+
+            while(parentClasses.hasNext())
             {
-                object.put(name, ((ConfiguredObject) value).getName());
+                Class<? extends ConfiguredObject> parentClass = parentClasses.next();
+                ConfiguredObject parent = confObject.getParent(parentClass);
+                if(parent != null)
+                {
+                    String categoryName = parentClass.getSimpleName();
+                    object.put(categoryName.substring(0,1).toLowerCase()+categoryName.substring(1), parent.getName());
+                }
             }
-            else if(ConfiguredObject.CONTEXT.equals(name))
+        }
+
+        for(String name : confObject.getAttributeNames())
+        {
+            if (!(extractAsConfig && CONFIG_EXCLUDED_ATTRIBUTES.contains(name)))
             {
-                Map<String,Object> contextValues = new HashMap<>();
-                if(useActualValues)
+                Object value =
+                        useActualValues ? confObject.getActualAttributes().get(name) : confObject.getAttribute(name);
+                if (value instanceof ConfiguredObject)
                 {
-                    contextValues.putAll(confObject.getContext());
+                    object.put(name, ((ConfiguredObject) value).getName());
                 }
-                else
+                else if (ConfiguredObject.CONTEXT.equals(name))
                 {
-                    for(String contextName : confObject.getContextKeys(!includeSystemContext))
+                    Map<String, Object> contextValues = new HashMap<>();
+                    if (useActualValues)
                     {
-                        contextValues.put(contextName, confObject.getContextValue(String.class, contextName));
+                        contextValues.putAll(confObject.getContext());
                     }
-                }
-                object.put(ConfiguredObject.CONTEXT, contextValues);
-            }
-            else if(value instanceof Collection)
-            {
-                List<Object> converted = new ArrayList();
-                for(Object member : (Collection)value)
-                {
-                    if(member instanceof ConfiguredObject)
+                    else
                     {
-                        converted.add(((ConfiguredObject)member).getName());
+                        for (String contextName : confObject.getContextKeys(!includeSystemContext))
+                        {
+                            contextValues.put(contextName, confObject.getContextValue(String.class, contextName));
+                        }
                     }
-                    else
+                    if (!contextValues.isEmpty())
                     {
-                        converted.add(member);
+                        object.put(ConfiguredObject.CONTEXT, contextValues);
                     }
                 }
-                object.put(name, converted);
-            }
-            else if(value != null)
-            {
-                object.put(name, value);
+                else if (value instanceof Collection)
+                {
+                    List<Object> converted = new ArrayList<>();
+                    for (Object member : (Collection) value)
+                    {
+                        if (member instanceof ConfiguredObject)
+                        {
+                            converted.add(((ConfiguredObject) member).getName());
+                        }
+                        else
+                        {
+                            converted.add(member);
+                        }
+                    }
+                    object.put(name, converted);
+                }
+                else if (value != null)
+                {
+                    object.put(name, value);
+                }
             }
         }
     }
@@ -120,24 +166,60 @@ public class ConfiguredObjectToMapConver
 
     private void incorporateChildrenIntoMap(
             final ConfiguredObject confObject,
-            Class<? extends ConfiguredObject> clazz, int depth,
-            Map<String, Object> object, final boolean useActualValues, final boolean includeSystemContext)
+            Class<? extends ConfiguredObject> clazz,
+            int depth,
+            Map<String, Object> object,
+            final boolean useActualValues,
+            final boolean includeSystemContext,
+            final boolean extractAsConfig)
     {
-        for(Class<? extends ConfiguredObject> childClass : confObject.getModel().getChildTypes(clazz))
+        List<Class<? extends ConfiguredObject>> childTypes = new ArrayList<>(confObject.getModel().getChildTypes(clazz));
+
+        Collections.sort(childTypes, new Comparator<Class<? extends ConfiguredObject>>()
         {
-            Collection<? extends ConfiguredObject> children = confObject.getChildren(childClass);
-            if(children != null)
+            @Override
+            public int compare(final Class<? extends ConfiguredObject> o1, final Class<? extends ConfiguredObject> o2)
+            {
+                return o1.getSimpleName().compareTo(o2.getSimpleName());
+            }
+        });
+        for(Class<? extends ConfiguredObject> childClass : childTypes)
+        {
+            if(!(extractAsConfig && confObject.getModel().getParentTypes(childClass).iterator().next() != confObject.getCategoryClass()))
             {
-                List<Map<String, Object>> childObjects = new ArrayList<Map<String, Object>>();
 
-                for(ConfiguredObject child : children)
+                Collection children = confObject.getChildren(childClass);
+                if(children != null)
                 {
-                    childObjects.add(convertObjectToMap(child, childClass, depth-1, useActualValues, includeSystemContext));
-                }
+                    List<? extends ConfiguredObject> sortedChildren = new ArrayList<ConfiguredObject>(children);
+                    Collections.sort(sortedChildren, new Comparator<ConfiguredObject>()
+                    {
+                        @Override
+                        public int compare(final ConfiguredObject o1, final ConfiguredObject o2)
+                        {
+                            return o1.getName().compareTo(o2.getName());
+                        }
+                    });
 
-                if(!childObjects.isEmpty())
-                {
-                    object.put(childClass.getSimpleName().toLowerCase()+"s",childObjects);
+                    List<Map<String, Object>> childObjects = new ArrayList<>();
+
+                    for (ConfiguredObject child : sortedChildren)
+                    {
+                        if (!(extractAsConfig && !child.isDurable()))
+                        {
+                            childObjects.add(convertObjectToMap(child,
+                                                                childClass,
+                                                                depth - 1,
+                                                                useActualValues,
+                                                                includeSystemContext,
+                                                                extractAsConfig));
+                        }
+                    }
+
+                    if (!childObjects.isEmpty())
+                    {
+                        object.put(childClass.getSimpleName().toLowerCase() + "s", childObjects);
+                    }
                 }
             }
         }

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java Wed Aug 20 22:49:44 2014
@@ -59,8 +59,14 @@ public class RestServlet extends Abstrac
     public static final String ACTUALS_PARAM = "actuals";
     public static final String SORT_PARAM = "sort";
     public static final String INCLUDE_SYS_CONTEXT_PARAM = "includeSysContext";
+    public static final String EXTRACT_INITIAL_CONFIG_PARAM = "extractInitialConfig";
 
-    public static final Set<String> RESERVED_PARAMS = new HashSet<String>(Arrays.asList(DEPTH_PARAM, SORT_PARAM, ACTUALS_PARAM, INCLUDE_SYS_CONTEXT_PARAM));
+    public static final Set<String> RESERVED_PARAMS =
+            new HashSet<>(Arrays.asList(DEPTH_PARAM,
+                                        SORT_PARAM,
+                                        ACTUALS_PARAM,
+                                        INCLUDE_SYS_CONTEXT_PARAM,
+                                        EXTRACT_INITIAL_CONFIG_PARAM));
 
     private Class<? extends ConfiguredObject>[] _hierarchy;
 
@@ -316,15 +322,29 @@ public class RestServlet extends Abstrac
         Collection<ConfiguredObject<?>> allObjects = getObjects(request);
 
         // TODO - sort special params, everything else should act as a filter
-        int depth = getDepthParameterFromRequest(request);
-        boolean actuals = getBooleanParameterFromRequest(request, ACTUALS_PARAM);
-        boolean includeSystemContext = getBooleanParameterFromRequest(request, INCLUDE_SYS_CONTEXT_PARAM);
+        boolean extractInitialConfig = getBooleanParameterFromRequest(request, EXTRACT_INITIAL_CONFIG_PARAM);
+        int depth;
+        boolean actuals;
+        boolean includeSystemContext;
+
+        if(extractInitialConfig)
+        {
+            depth = Integer.MAX_VALUE;
+            actuals = true;
+            includeSystemContext = false;
+        }
+        else
+        {
+            depth = getDepthParameterFromRequest(request);
+            actuals = getBooleanParameterFromRequest(request, ACTUALS_PARAM);
+            includeSystemContext = getBooleanParameterFromRequest(request, INCLUDE_SYS_CONTEXT_PARAM);
+        }
 
         List<Map<String, Object>> output = new ArrayList<Map<String, Object>>();
         for(ConfiguredObject configuredObject : allObjects)
         {
             output.add(_objectConverter.convertObjectToMap(configuredObject, getConfiguredClass(),
-                    depth, actuals, includeSystemContext));
+                    depth, actuals, includeSystemContext, extractInitialConfig));
         }
 
         Writer writer = getOutputWriter(request, response);

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java Wed Aug 20 22:49:44 2014
@@ -58,7 +58,7 @@ public class ConfiguredObjectToMapConver
         when(_configuredObject.getStatistics()).thenReturn(Collections.singletonMap(statisticName, (Number) statisticValue));
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 0,
-                                                                      false, false);
+                                                                      false, false, false);
         Map<String, Object> statsAsMap = (Map<String, Object>) resultMap.get(STATISTICS_MAP_KEY);
         assertNotNull("Statistics should be part of map", statsAsMap);
         assertEquals("Unexpected number of statistics", 1, statsAsMap.size());
@@ -72,7 +72,7 @@ public class ConfiguredObjectToMapConver
         configureMockToReturnOneAttribute(_configuredObject, attributeName, attributeValue);
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 0,
-                                                                      false, false);
+                                                                      false, false, false);
         assertEquals("Unexpected number of attributes", 1, resultMap.size());
         assertEquals("Unexpected attribute value", attributeValue, resultMap.get(attributeName));
     }
@@ -90,7 +90,7 @@ public class ConfiguredObjectToMapConver
         configureMockToReturnOneAttribute(_configuredObject, attributeName, attributeValue);
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 0,
-                                                                      false, false);
+                                                                      false, false, false);
         assertEquals("Unexpected number of attributes", 1, resultMap.size());
         assertEquals("Unexpected attribute value", "attributeConfiguredObjectName", resultMap.get(attributeName));
     }
@@ -109,7 +109,7 @@ public class ConfiguredObjectToMapConver
         when(_configuredObject.getChildren(TestChild.class)).thenReturn(Arrays.asList(mockChild));
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 1,
-                                                                      false, false);
+                                                                      false, false, false);
         assertEquals("Unexpected parent map size", 1, resultMap.size());
 
         final List<Map<String, Object>> childList = (List<Map<String, Object>>) resultMap.get("testchilds");
@@ -146,18 +146,18 @@ public class ConfiguredObjectToMapConver
 
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 1, true,
-                                                                      false);
+                                                                      false, false);
         assertEquals("Unexpected parent map size", 2, resultMap.size());
         assertEquals("Incorrect context", resultMap.get(ConfiguredObject.CONTEXT), actualContext);
         List<Map<String, Object>> childList = (List<Map<String, Object>>) resultMap.get("testchilds");
         assertEquals("Unexpected number of children", 1, childList.size());
         Map<String, Object> childMap = childList.get(0);
-        assertEquals("Unexpected child map size", 2, childMap.size());
         assertNotNull(childMap);
+        assertEquals("Unexpected child map size", 1, childMap.size());
 
         assertEquals("Unexpected child attribute value", childActualAttributeValue, childMap.get(childAttributeName));
 
-        resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 1, false, false);
+        resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 1, false, false, false);
         assertEquals("Unexpected parent map size", 2, resultMap.size());
         Map<String, Object> inheritedContext = new HashMap<>();
         inheritedContext.put("key","value");
@@ -166,7 +166,7 @@ public class ConfiguredObjectToMapConver
         childList = (List<Map<String, Object>>) resultMap.get("testchilds");
         assertEquals("Unexpected number of children", 1, childList.size());
         childMap = childList.get(0);
-        assertEquals("Unexpected child map size", 2, childMap.size());
+        assertEquals("Unexpected child map size", 1, childMap.size());
         assertNotNull(childMap);
 
         assertEquals("Unexpected child attribute value", childAttributeValue, childMap.get(childAttributeName));

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java?rev=1619259&r1=1619258&r2=1619259&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java Wed Aug 20 22:49:44 2014
@@ -378,6 +378,7 @@ public class Asserts
         assertAttributesPresent(binding,
                                 BrokerModel.getInstance().getTypeRegistry().getAttributeNames(Binding.class),
                                 Binding.STATE,
+                                Binding.ARGUMENTS,
                                 ConfiguredObject.TYPE,
                                 ConfiguredObject.CREATED_BY,
                                 ConfiguredObject.CREATED_TIME,



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org