diff options
Diffstat (limited to 'qpid/java')
11 files changed, 311 insertions, 74 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java index 8eb0b4feb0..a910eea657 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java @@ -36,6 +36,7 @@ import org.apache.qpid.server.logging.EventLogger; 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; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java index 67bbc26f74..a5c74cb286 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java @@ -123,7 +123,6 @@ public class HeadersExchange extends AbstractExchange<HeadersExchange> { 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 AbstractExchange<HeadersExchange> 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)); diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java index 18930d8817..436842017a 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java @@ -1100,7 +1100,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im @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()) { diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java index 3201ff16f1..b7b5197753 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java @@ -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 ConfiguredObjectTypeRegistry { 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 ConfiguredObjectTypeRegistry 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 ConfiguredObjectTypeRegistry 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>(); diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java index 50f98c7f03..cc1f557df1 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java @@ -52,6 +52,7 @@ public class VirtualHostAliasAdapter extends AbstractConfiguredObject<VirtualHos 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; } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java index 78d2b6507a..4671539b66 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java @@ -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 implements DurableConfigurationStore { 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 implements DurableConfigurationStore } } - 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 implements DurableConfigurationStore 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); diff --git a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java index cee1a04b17..8dddac9809 100644 --- a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java +++ b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java @@ -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; diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java index bc563c141e..a444f9e2e4 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java @@ -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 ConfiguredObjectToMapConverter /** 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 ConfiguredObjectToMapConverter 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 ConfiguredObjectToMapConverter 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); + } } } } diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java index dc1f5bba46..861b0c15a6 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java @@ -59,8 +59,14 @@ public class RestServlet extends AbstractServlet 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 AbstractServlet 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); diff --git a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java index 011b7b995d..15102c8ce4 100644 --- a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java +++ b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java @@ -58,7 +58,7 @@ public class ConfiguredObjectToMapConverterTest extends TestCase 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 ConfiguredObjectToMapConverterTest extends TestCase 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 ConfiguredObjectToMapConverterTest extends TestCase 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 ConfiguredObjectToMapConverterTest extends TestCase 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 ConfiguredObjectToMapConverterTest extends TestCase 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 ConfiguredObjectToMapConverterTest extends TestCase 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)); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java index 7b337580d3..2c3ad1f8e5 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java @@ -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, |
