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/07/29 16:54:36 UTC

svn commit: r1614370 - in /qpid/trunk/qpid/java: broker-core/src/main/java/org/apache/qpid/server/model/ broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ broker-plugins/management-http/src/main/java/org/apache/qpid...

Author: rgodfrey
Date: Tue Jul 29 14:54:36 2014
New Revision: 1614370

URL: http://svn.apache.org/r1614370
Log:
QPID-5940 : [Java Broker] Add meta-data servlet

Added:
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java
Modified:
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java

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=1614370&r1=1614369&r2=1614370&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 Tue Jul 29 14:54:36 2014
@@ -99,6 +99,10 @@ public class ConfiguredObjectTypeRegistr
                     {
                         categories.add(configuredObjectClass);
                     }
+                    else
+                    {
+                        categories.add(getCategory(configuredObjectClass));
+                    }
                     if (!"".equals(annotation.type()))
                     {
                         types.add(configuredObjectClass);
@@ -188,13 +192,16 @@ public class ConfiguredObjectTypeRegistr
         {
             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 ConfiguredObjectTypeRegistr
         {
             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 ConfiguredObjectTypeRegistr
         {
             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 ConfiguredObjectTypeRegistr
     }
 
 
-    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))
         {

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java?rev=1614370&r1=1614369&r2=1614370&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java Tue Jul 29 14:54:36 2014
@@ -60,6 +60,7 @@ import org.apache.qpid.server.management
 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 Abst
 
         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);

Added: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.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/MetaDataServlet.java?rev=1614370&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java Tue Jul 29 14:54:36 2014
@@ -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;
+    }
+}



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