From e86d500205adb39b40475b568ead3655e14133a6 Mon Sep 17 00:00:00 2001 From: fhanik Date: Thu, 9 Aug 2007 01:54:34 +0000 Subject: [PATCH] Setup framework for cluster JMX operations git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@564069 13f79535-47bb-0310-9956-ffa450edef68 --- .../ha/authenticator/mbeans-descriptors.xml | 40 +- .../catalina/ha/deploy/mbeans-descriptors.xml | 5 +- .../apache/catalina/ha/jmx/ClusterJmxHelper.java | 130 ++ java/org/apache/catalina/ha/mbeans-descriptors.xml | 88 +- .../catalina/ha/session/mbeans-descriptors.xml | 672 +++--- .../apache/catalina/ha/tcp/SimpleTcpCluster.java | 6 + .../apache/catalina/ha/tcp/mbeans-descriptors.xml | 2244 +++++++++++--------- 7 files changed, 1752 insertions(+), 1433 deletions(-) create mode 100644 java/org/apache/catalina/ha/jmx/ClusterJmxHelper.java diff --git a/java/org/apache/catalina/ha/authenticator/mbeans-descriptors.xml b/java/org/apache/catalina/ha/authenticator/mbeans-descriptors.xml index 7920f9880..6243060a9 100644 --- a/java/org/apache/catalina/ha/authenticator/mbeans-descriptors.xml +++ b/java/org/apache/catalina/ha/authenticator/mbeans-descriptors.xml @@ -1,25 +1,23 @@ - - - - - - - - - + + + + - diff --git a/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml b/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml index 378b962bf..6ac06e2ad 100644 --- a/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml +++ b/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml @@ -1,11 +1,10 @@ - - + type="org.apache.catalina.ha.deploy.FarmWarDeployer"> diff --git a/java/org/apache/catalina/ha/jmx/ClusterJmxHelper.java b/java/org/apache/catalina/ha/jmx/ClusterJmxHelper.java new file mode 100644 index 000000000..2dd340960 --- /dev/null +++ b/java/org/apache/catalina/ha/jmx/ClusterJmxHelper.java @@ -0,0 +1,130 @@ +/* + * 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.catalina.ha.jmx; + +import org.apache.tomcat.util.modeler.Registry; +import org.apache.catalina.ha.CatalinaCluster; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; +import org.apache.catalina.ha.tcp.SimpleTcpCluster; +import org.apache.catalina.ha.session.DeltaManager; +import org.apache.catalina.ha.deploy.FarmWarDeployer; +import org.apache.catalina.ha.authenticator.ClusterSingleSignOn; +import org.apache.catalina.core.StandardHost; +import javax.management.ObjectName; +import org.apache.catalina.core.StandardEngine; +import javax.management.MBeanServerFactory; +import javax.management.MBeanServer; +import javax.management.modelmbean.ModelMBean; +import org.apache.tomcat.util.modeler.ManagedBean; +import javax.management.DynamicMBean; + +public class ClusterJmxHelper { + + protected static Registry registry = Registry.getRegistry(null,null); + + protected static Log log = LogFactory.getLog(ClusterJmxHelper.class); + + protected static boolean jmxEnabled = true; + + protected static MBeanServer mbeanServer = null; + + public static Registry getRegistry() { + return registry; + } + + public static MBeanServer getMBeanServer() throws Exception { + if (mbeanServer == null) { + if (MBeanServerFactory.findMBeanServer(null).size() > 0) { + mbeanServer = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0); + } else { + mbeanServer = MBeanServerFactory.createMBeanServer(); + } + } + return mbeanServer; + } + + protected static boolean initMetaData(Class clazz) { + try { + if (clazz==null) return false; + getRegistry().loadMetadata(clazz.getResourceAsStream("mbeans-descriptors.xml")); + }catch (Exception x) { + log.warn("Unable to load meta data for class:"+clazz.getName()); + return false; + } + return true; + } + + public static DynamicMBean getManagedBean(Object object) throws Exception { + DynamicMBean mbean = null; + if (getRegistry() != null) { + ManagedBean managedBean = registry.findManagedBean(object.getClass().getName()); + mbean = managedBean.createMBean(object); + } + return mbean; + } + + + protected static void initDefaultCluster() { + initMetaData(SimpleTcpCluster.class); + initMetaData(DeltaManager.class); + initMetaData(FarmWarDeployer.class); //not functional yet + initMetaData(ClusterSingleSignOn.class); //not functional yet + } + + public static boolean registerDefaultCluster(SimpleTcpCluster cluster) { + try { + initDefaultCluster(); + ObjectName clusterName = getDefaultClusterName(cluster); + if (!getMBeanServer().isRegistered(clusterName)) { + getMBeanServer().registerMBean(getManagedBean(cluster), clusterName); + } + return true; + }catch ( Exception x ) { + log.warn("Unable to register default cluster implementation with JMX",x); + return false; + } + } + + public static boolean unregisterDefaultCluster(SimpleTcpCluster cluster) throws Exception { + ObjectName clusterName = getDefaultClusterName(cluster); + if (getMBeanServer().isRegistered(clusterName)) { + getMBeanServer().unregisterMBean(clusterName); + } + return true; + } + + private static ObjectName getDefaultClusterName(SimpleTcpCluster cluster) throws Exception { + String domain = getMBeanServer().getDefaultDomain(); + String type = ":type="; + boolean hostParent = false; + //Step 1. Register the Cluster MBean + String clusterType= type+"Cluster"; + if (cluster.getContainer() instanceof StandardHost) { + domain = ((StandardHost) cluster.getContainer()).getDomain(); + clusterType += ",host=" + cluster.getContainer().getName(); + hostParent = true; + } else { + if (cluster.getContainer() instanceof StandardEngine) { + domain = ((StandardEngine) cluster.getContainer()).getDomain(); + } + } + ObjectName clusterName = new ObjectName(domain + clusterType); + return clusterName; + } + +} \ No newline at end of file diff --git a/java/org/apache/catalina/ha/mbeans-descriptors.xml b/java/org/apache/catalina/ha/mbeans-descriptors.xml index 8a4f610f3..07e95fdb4 100644 --- a/java/org/apache/catalina/ha/mbeans-descriptors.xml +++ b/java/org/apache/catalina/ha/mbeans-descriptors.xml @@ -1,90 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/java/org/apache/catalina/ha/session/mbeans-descriptors.xml b/java/org/apache/catalina/ha/session/mbeans-descriptors.xml index f0621213a..28567f725 100644 --- a/java/org/apache/catalina/ha/session/mbeans-descriptors.xml +++ b/java/org/apache/catalina/ha/session/mbeans-descriptors.xml @@ -3,318 +3,386 @@ "-//Apache Software Foundation//DTD Model MBeans Configuration File" "http://jakarta.apache.org/commons/dtds/mbeans-descriptors.dtd"> - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - + + + - - + - - + - - + - - - - + + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + type="java.lang.String" + writeable="false"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + - - + + - - - - - - - - - + + + + + + + + + + + + + + + - diff --git a/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java b/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java index 68aa27167..613b5552c 100644 --- a/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java +++ b/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java @@ -57,6 +57,7 @@ import org.apache.catalina.tribes.group.interceptors.MessageDispatch15Intercepto import org.apache.catalina.tribes.group.interceptors.TcpFailureDetector; import org.apache.catalina.ha.session.JvmRouteBinderValve; import org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener; +import org.apache.catalina.ha.jmx.ClusterJmxHelper; /** * A Cluster implementation using simple multicast. Responsible for @@ -689,6 +690,8 @@ public class SimpleTcpCluster channel.start(channel.DEFAULT); if (clusterDeployer != null) clusterDeployer.start(); this.started = true; + //register JMX objects + ClusterJmxHelper.registerDefaultCluster(this); // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(AFTER_START_EVENT, this); } catch (Exception x) { @@ -784,6 +787,9 @@ public class SimpleTcpCluster channel.removeChannelListener(this); channel.removeMembershipListener(this); this.unregisterClusterValve(); + //unregister JMX objects + ClusterJmxHelper.unregisterDefaultCluster(this); + } catch (Exception x) { log.error("Unable to stop cluster valve.", x); } diff --git a/java/org/apache/catalina/ha/tcp/mbeans-descriptors.xml b/java/org/apache/catalina/ha/tcp/mbeans-descriptors.xml index e051aee3e..3a4ba7b2d 100644 --- a/java/org/apache/catalina/ha/tcp/mbeans-descriptors.xml +++ b/java/org/apache/catalina/ha/tcp/mbeans-descriptors.xml @@ -3,1036 +3,1240 @@ "-//Apache Software Foundation//DTD Model MBeans Configuration File" "http://jakarta.apache.org/commons/dtds/mbeans-descriptors.dtd"> - - - - - - - - - - - - + + + + + + + + + + + - - - + + - - - + + - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - -- 2.11.0