karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf-cellar git commit: [KARAF-4619] Add CellarHttpMBean
Date Sun, 10 Jul 2016 19:51:54 GMT
Repository: karaf-cellar
Updated Branches:
  refs/heads/master f8a15e208 -> 439381b6c


[KARAF-4619] Add CellarHttpMBean


Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/439381b6
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/439381b6
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/439381b6

Branch: refs/heads/master
Commit: 439381b6c869b8624b01a3a8467b7f40bd85e567
Parents: f8a15e2
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Sun Jul 10 21:51:30 2016 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Sun Jul 10 21:51:30 2016 +0200

----------------------------------------------------------------------
 http/balancer/pom.xml                           |  2 +
 .../http/balancer/internal/osgi/Activator.java  | 17 +++++
 .../balancer/management/CellarHttpMBean.java    | 29 ++++++++
 .../internal/CellarHttpMBeanImpl.java           | 77 ++++++++++++++++++++
 4 files changed, 125 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/439381b6/http/balancer/pom.xml
----------------------------------------------------------------------
diff --git a/http/balancer/pom.xml b/http/balancer/pom.xml
index a14b254..6663f9f 100644
--- a/http/balancer/pom.xml
+++ b/http/balancer/pom.xml
@@ -99,6 +99,7 @@
                     <instructions>
                         <Export-Package>
                             !org.apache.karaf.cellar.http.balancer.internal.osgi,
+                            !org.apache.karaf.cellar.http.balancer.management.internal,
                             org.apache.karaf.cellar.http.balancer*
                         </Export-Package>
                         <Import-Package>
@@ -110,6 +111,7 @@
                         </Import-Package>
                         <Private-Package>
                             org.apache.karaf.cellar.http.balancer.internal.osgi,
+                            org.apache.karaf.cellar.http.balancer.management.internal,
                             org.apache.http*,
                             org.apache.commons.codec*
                         </Private-Package>

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/439381b6/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/internal/osgi/Activator.java
b/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/internal/osgi/Activator.java
index 219e284..ee3c8f2 100644
--- a/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/internal/osgi/Activator.java
+++ b/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/internal/osgi/Activator.java
@@ -22,11 +22,13 @@ import org.apache.karaf.cellar.http.balancer.BalancerEventHandler;
 import org.apache.karaf.cellar.http.balancer.LocalServletListener;
 import org.apache.karaf.cellar.http.balancer.ProxyServletRegistry;
 import org.apache.karaf.cellar.http.balancer.ServletSynchronizer;
+import org.apache.karaf.cellar.http.balancer.management.internal.CellarHttpMBeanImpl;
 import org.apache.karaf.util.tracker.BaseActivator;
 import org.apache.karaf.util.tracker.annotation.ProvideService;
 import org.apache.karaf.util.tracker.annotation.RequireService;
 import org.apache.karaf.util.tracker.annotation.Services;
 import org.ops4j.pax.web.service.spi.ServletListener;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,6 +54,8 @@ public class Activator extends BaseActivator {
 
     private ProxyServletRegistry proxyRegistry;
 
+    private ServiceRegistration mbeanRegistration;
+
     @Override
     public void doStart() throws Exception {
         ClusterManager clusterManager = getTrackedService(ClusterManager.class);
@@ -106,6 +110,14 @@ public class Activator extends BaseActivator {
         servletListener.setConfigurationAdmin(configurationAdmin);
         servletListener.setEventProducer(eventProducer);
         register(ServletListener.class, servletListener);
+
+        LOGGER.debug("CELLAR HTTP BALANCER: register MBean");
+        CellarHttpMBeanImpl mbean = new CellarHttpMBeanImpl();
+        mbean.setClusterManager(clusterManager);
+        mbean.setGroupManager(groupManager);
+        props = new Hashtable();
+        props.put("jmx.objectname", "org.apache.karaf.cellar:type=http,name=" + System.getProperty("karaf.name"));
+        mbeanRegistration = bundleContext.registerService(getInterfaceNames(mbean), mbean,
props);
     }
 
     @Override
@@ -116,6 +128,11 @@ public class Activator extends BaseActivator {
             proxyRegistry.destroy();
             proxyRegistry = null;
         }
+
+        if (mbeanRegistration != null) {
+            mbeanRegistration.unregister();
+            mbeanRegistration = null;
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/439381b6/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/management/CellarHttpMBean.java
----------------------------------------------------------------------
diff --git a/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/management/CellarHttpMBean.java
b/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/management/CellarHttpMBean.java
new file mode 100644
index 0000000..b8d6274
--- /dev/null
+++ b/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/management/CellarHttpMBean.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed 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.karaf.cellar.http.balancer.management;
+
+import java.util.Map;
+
+public interface CellarHttpMBean {
+
+    /**
+     * List the HTTP servlets on a cluster group.
+     *
+     * @param group The cluster group name.
+     * @return A map with HTTP servlet aliases and locations.
+     * @throws Exception
+     */
+    Map<String, String> listHttp(String group) throws Exception;
+
+}

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/439381b6/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/management/internal/CellarHttpMBeanImpl.java
----------------------------------------------------------------------
diff --git a/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/management/internal/CellarHttpMBeanImpl.java
b/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/management/internal/CellarHttpMBeanImpl.java
new file mode 100644
index 0000000..f32df69
--- /dev/null
+++ b/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/management/internal/CellarHttpMBeanImpl.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed 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.karaf.cellar.http.balancer.management.internal;
+
+import org.apache.karaf.cellar.core.ClusterManager;
+import org.apache.karaf.cellar.core.Configurations;
+import org.apache.karaf.cellar.core.Group;
+import org.apache.karaf.cellar.core.GroupManager;
+import org.apache.karaf.cellar.http.balancer.Constants;
+import org.apache.karaf.cellar.http.balancer.management.CellarHttpMBean;
+import org.apache.karaf.shell.support.table.ShellTable;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class CellarHttpMBeanImpl extends StandardMBean implements CellarHttpMBean {
+
+    private GroupManager groupManager;
+    private ClusterManager clusterManager;
+
+    public CellarHttpMBeanImpl() throws NotCompliantMBeanException {
+        super(CellarHttpMBean.class);
+    }
+
+    public GroupManager getGroupManager() {
+        return groupManager;
+    }
+
+    public void setGroupManager(GroupManager groupManager) {
+        this.groupManager = groupManager;
+    }
+
+    public ClusterManager getClusterManager() {
+        return clusterManager;
+    }
+
+    public void setClusterManager(ClusterManager clusterManager) {
+        this.clusterManager = clusterManager;
+    }
+
+    @Override
+    public Map<String, String> listHttp(String groupName) throws Exception {
+        Map<String, String> result = new HashMap<String, String>();
+        Group group = groupManager.findGroupByName(groupName);
+        if (group == null) {
+            throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist");
+        }
+
+        Map<String, List<String>> clusterServlets = clusterManager.getMap(Constants.BALANCER_MAP
+ Configurations.SEPARATOR + groupName);
+
+
+        for (String alias : clusterServlets.keySet()) {
+            List<String> locations = clusterServlets.get(alias);
+            StringBuilder builder = new StringBuilder();
+            for (String location : locations) {
+                builder.append(location).append(" ");
+            }
+            result.put(alias, builder.toString());
+        }
+
+        return result;
+    }
+}


Mime
View raw message