diff options
author | Robert Godfrey <rgodfrey@apache.org> | 2014-07-29 14:54:36 +0000 |
---|---|---|
committer | Robert Godfrey <rgodfrey@apache.org> | 2014-07-29 14:54:36 +0000 |
commit | 63887e9ffebaa10f33f4afdfe6f88c359d844a8d (patch) | |
tree | 07c2b69b6a026868d985941b327df2afca88b8e3 /qpid | |
parent | 242b0827d0ff650b973775e47786018372ae4fea (diff) | |
download | qpid-python-63887e9ffebaa10f33f4afdfe6f88c359d844a8d.tar.gz |
QPID-5940 : [Java Broker] Add meta-data servlet
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1614370 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid')
3 files changed, 161 insertions, 8 deletions
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 950638cd63..d692e663df 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 @@ -99,6 +99,10 @@ public class ConfiguredObjectTypeRegistry { categories.add(configuredObjectClass); } + else + { + categories.add(getCategory(configuredObjectClass)); + } if (!"".equals(annotation.type())) { types.add(configuredObjectClass); @@ -188,13 +192,16 @@ public class ConfiguredObjectTypeRegistry { Class<? extends ConfiguredObject> category = getCategory(clazz); Set<Class<? extends ConfiguredObject>> types = _knownTypes.get(category); - for(Class<? extends ConfiguredObject> type : types) + if(types != null) { - ManagedObject annotation = type.getAnnotation(ManagedObject.class); - if(typeName.equals(annotation.type())) + for (Class<? extends ConfiguredObject> type : types) { - typeClass = type; - break; + ManagedObject annotation = type.getAnnotation(ManagedObject.class); + if (typeName.equals(annotation.type())) + { + typeClass = type; + break; + } } } if(typeClass == null && typeName.equals(category.getSimpleName())) @@ -214,7 +221,12 @@ public class ConfiguredObjectTypeRegistry { throw new IllegalArgumentException("Cannot locate ManagedObject information for " + clazz.getName()); } - return Collections.unmodifiableCollection(_knownTypes.get(categoryClass)); + Set<Class<? extends ConfiguredObject>> classes = _knownTypes.get(categoryClass); + if(classes == null) + { + classes = (Set<Class<? extends ConfiguredObject>>) ((Set)Collections.singleton(clazz)); + } + return Collections.unmodifiableCollection(classes); } @@ -225,7 +237,8 @@ public class ConfiguredObjectTypeRegistry { throw new IllegalArgumentException("Cannot locate ManagedObject information for " + clazz.getName()); } - return Collections.unmodifiableCollection(_typeSpecificAttributes.get(typeClass)); + Collection<ConfiguredObjectAttribute<?, ?>> typeAttrs = _typeSpecificAttributes.get(typeClass); + return Collections.unmodifiableCollection(typeAttrs == null ? Collections.<ConfiguredObjectAttribute<?, ?>>emptySet() : typeAttrs); } public static String getType(final Class<? extends ConfiguredObject> clazz) @@ -711,7 +724,7 @@ public class ConfiguredObjectTypeRegistry } - static Map<String, ConfiguredObjectAttribute<?, ?>> getAttributeTypes(final Class<? extends ConfiguredObject> clazz) + public static Map<String, ConfiguredObjectAttribute<?, ?>> getAttributeTypes(final Class<? extends ConfiguredObject> clazz) { if(!_allAttributes.containsKey(clazz)) { diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java index fb3aed932d..86a054ef31 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java @@ -60,6 +60,7 @@ import org.apache.qpid.server.management.plugin.servlet.rest.LoggedOnUserPrefere import org.apache.qpid.server.management.plugin.servlet.rest.LogoutServlet; import org.apache.qpid.server.management.plugin.servlet.rest.MessageContentServlet; import org.apache.qpid.server.management.plugin.servlet.rest.MessageServlet; +import org.apache.qpid.server.management.plugin.servlet.rest.MetaDataServlet; import org.apache.qpid.server.management.plugin.servlet.rest.RestServlet; import org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet; import org.apache.qpid.server.management.plugin.servlet.rest.StructureServlet; @@ -267,6 +268,8 @@ public class HttpManagement extends AbstractPluginAdapter<HttpManagement> implem root.addServlet(new ServletHolder(new LogRecordsServlet()), "/service/logrecords"); + root.addServlet(new ServletHolder(new MetaDataServlet()), "/service/metadata"); + root.addServlet(new ServletHolder(new SaslServlet()), "/service/sasl"); root.addServlet(new ServletHolder(new DefinedFileServlet("index.html")), HttpManagementUtil.ENTRY_POINT_PATH); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java new file mode 100644 index 0000000000..0fefa93a81 --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java @@ -0,0 +1,137 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.management.plugin.servlet.rest; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; + +import org.apache.qpid.server.model.BrokerModel; +import org.apache.qpid.server.model.ConfiguredAutomatedAttribute; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ConfiguredObjectAttribute; +import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; +import org.apache.qpid.server.model.Model; + +public class MetaDataServlet extends AbstractServlet +{ + + private Model _instance; + + @Override + public void init() throws ServletException + { + super.init(); + + _instance = BrokerModel.getInstance(); + } + + @Override + protected void doGetWithSubjectAndActor(final HttpServletRequest request, final HttpServletResponse response) + throws ServletException, IOException + { + response.setContentType("application/json"); + response.setStatus(HttpServletResponse.SC_OK); + + Map<String,Map> classToDataMap = new TreeMap<>(); + + for(Class<? extends ConfiguredObject> clazz : _instance.getSupportedCategories()) + { + classToDataMap.put(clazz.getSimpleName(), processCategory(clazz)); + } + + final Writer writer = new BufferedWriter(response.getWriter()); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); + mapper.writeValue(writer, classToDataMap); + + response.setContentType("application/json"); + response.setStatus(HttpServletResponse.SC_OK); + + } + + private Map<String,Map> processCategory(final Class<? extends ConfiguredObject> clazz) + { + Map<String, Map> typeToDataMap = new TreeMap<>(); + for(Class<? extends ConfiguredObject> type : ConfiguredObjectTypeRegistry.getTypeSpecialisations(clazz)) + { + typeToDataMap.put(ConfiguredObjectTypeRegistry.getType(type), processType(type)); + } + return typeToDataMap; + } + + private Map<String,Object> processType(final Class<? extends ConfiguredObject> type) + { + Map<String,Object> typeDetails = new LinkedHashMap<>(); + typeDetails.put("attributes", processAttributes(type)); + return typeDetails; + } + + private Map<String,Map> processAttributes(final Class<? extends ConfiguredObject> type) + { + Collection<ConfiguredObjectAttribute<?, ?>> attributes = + ConfiguredObjectTypeRegistry.getAttributeTypes(type).values(); + + Map<String,Map> attributeDetails = new LinkedHashMap<>(); + for(ConfiguredObjectAttribute<?, ?> attribute : attributes) + { + Map<String,Object> attrDetails = new LinkedHashMap<>(); + attrDetails.put("type",attribute.getType().getSimpleName()); + if(!"".equals(attribute.getDescription())) + { + attrDetails.put("description",attribute.getDescription()); + } + if(attribute.isDerived()) + { + attrDetails.put("derived",attribute.isDerived()); + } + if(attribute.isAutomated()) + { + if(!"".equals(((ConfiguredAutomatedAttribute)attribute).defaultValue())) + { + attrDetails.put("defaultValue",((ConfiguredAutomatedAttribute)attribute).defaultValue()); + } + if(((ConfiguredAutomatedAttribute)attribute).isMandatory()) + { + attrDetails.put("mandatory",((ConfiguredAutomatedAttribute)attribute).isMandatory()); + } + } + if(attribute.isSecure()) + { + attrDetails.put("secure",attribute.isSecure()); + } + + attributeDetails.put(attribute.getName(), attrDetails); + } + return attributeDetails; + } +} |