diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2014-08-20 22:49:44 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2014-08-20 22:49:44 +0000 |
| commit | a53039556aa86f4add5f09be8204ac361b588528 (patch) | |
| tree | 2869fbdabaceaa6f9906ac4523a2acfef44e919c /qpid/java/broker-plugins | |
| parent | 38d687074d863d9a5cd4bc3b4194d434960b999a (diff) | |
| download | qpid-python-a53039556aa86f4add5f09be8204ac361b588528.tar.gz | |
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)
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1619259 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-plugins')
4 files changed, 165 insertions, 61 deletions
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)); |
