6 Replies Latest reply on Mar 16, 2004 1:43 PM by michael.daleiden

    How to listen to cluster topology changes ?

    vatsanc

      I want to be able to get notifications (ip address) when nodes in a jboss cluster go down. I need to be able to register as a listener to changes to the cluster topology as nodes join and leave for the monitoring application that I am developing. What is the best way to do this ? I noticed that there is a TopologyMonitorService mbean jarred with jbossha.jar but the mbean is not loaded( atleast I cant see it from the JMX Console). How can I make use of this mbean ?
      Thanks,
      Sri

        • 1. Re: How to listen to cluster topology changes ?
          vatsanc

          Let me add some comments to my above posting for clarfication.
          I am trying to write an mbean that will be deployed on all nodes of a cluster. This mbean is to make use of the HASingleton mbean for cluster health monitoring. One of the JBoss nodes will take over as the master and keep track of the other nodes. Whenever a Jboss node crashes, then the master is to get notification of this topological change. For this I realized that the TopologyMonitor MBean can be used. I would like to how to configure this TopologyMonitor mbean. I am using JBOSS 3.2.1/3.2.2.
          If some one knows of a better technique, please enlighten!

          Thanks.

          • 2. Re: How to listen to cluster topology changes ?
            belaban

            Use the HAMembershipListener in your MBean
            Bela

            • 3. Re: How to listen to cluster topology changes ?
              vatsanc

              Thanks for your response. Could you please carify this further ?
              My understanding is that HAMembershipListener is an interface that is to be implemented to recieve notifications of cluster topology changes. But where should I register this listener object ? Which MBean ?
              Thanks much for you help.

              • 4. Re: How to listen to cluster topology changes ?
                vatsanc

                For the benefit for others who may come across a similar problem I post my solution here:
                I retrieved the HAPartition attribute from the JBoss object jboss:service=DefaultPartition and registered a listener that implements the MembershipListener interface.

                • 5. Re: How to listen to cluster topology changes ?
                  andrew.saunders

                  The problem (for me at least) with HAMembershipListener is that the notification information it receives is of type ClusterNode which is basically at the JGroups level and not at the partition/node level. So it's a bunch of addresses/ports.

                  Does anyone know a way of obtaining higher level information about topology changes? Or a reliable way of mapping the ClusterNode JGroups info to partition/node level info?

                  The best I have been able to come up with so far is based on the fact that "normally" the default value of ClusterNode.getName() will be the address:port of the JNDI provider of the node that was added/removed. From here it's possible to obtain the remote MBeanServer and therefore any information about the node. BUT, this link is tenuous as it's dependent on an undocumented feature - not even in the javadoc - just buried in the source code.

                  Any ideas for a reliable/supported alternative?

                  • 6. Re: How to listen to cluster topology changes ?
                    michael.daleiden

                     

                    "andrew.saunders" wrote:
                    The problem (for me at least) with HAMembershipListener is that the notification information it receives is of type ClusterNode which is basically at the JGroups level and not at the partition/node level. So it's a bunch of addresses/ports.

                    Does anyone know a way of obtaining higher level information about topology changes? Or a reliable way of mapping the ClusterNode JGroups info to partition/node level info?

                    The best I have been able to come up with so far is based on the fact that "normally" the default value of ClusterNode.getName() will be the address:port of the JNDI provider of the node that was added/removed. From here it's possible to obtain the remote MBeanServer and therefore any information about the node. BUT, this link is tenuous as it's dependent on an undocumented feature - not even in the javadoc - just buried in the source code.

                    Any ideas for a reliable/supported alternative?

                    You can use the following code snippet in your membershipChanged() implementation (gleaned from TopologyMonitorService) to get the InetAddress object that corresponds to the ClusterNode:
                    org.jboss.ha.framework.interfaces.ClusterNode node =
                     (org.jboss.ha.framework.interfaces.ClusterNode)deadMembers.get(0);
                    InetAddress deadAddress = node.getOriginalJGAddress().getIpAddress();

                    Then, you can simply use the InetAddress methods to determine the hostname, IP address, etc. of the node that died (or use the other Vectors to determine the nodes that were added or the complete current membership roster for the cluster).

                    I actually just used the TopologyMonitorService to notify a custom MBean when the topology changes:
                    <?xml version="1.0" encoding="UTF-8"?>
                    <!-- ===================================================================== -->
                    <!-- -->
                    <!-- Topology Monitor Service Configuration -->
                    <!-- -->
                    <!-- ===================================================================== -->
                    
                    <server>
                    
                     <classpath codebase="lib" archives="jbossha.jar"/>
                    
                     <mbean code="org.jboss.ha.framework.server.util.TopologyMonitorService"
                     name="Telematics:service=TopologyService">
                     <attribute name="PartitionName">DefaultPartition</attribute>
                     <attribute name="TriggerServiceName">MyServer:service=MyTopologyManager</attribute>
                     <depends>MyServer:service=MyTopologyManager</depends>
                     </mbean>
                    
                    </server>

                    My MBean (MyTopologyManager) simply implements the trigger method:
                    /**
                     * Updates the distributed MBean registry based on cluster membership changes (dead servers are removed).
                     *
                     * @param deadMembers list of cluster members that have died
                     *
                     * @param newMembers list of cluster members that have joined
                     *
                     * @param allMembers list of all active cluster members
                     *
                     * @param logCategoryName log4j category name for logging messages
                     *
                     * @jmx.managed-operation
                     */
                     public void membershipChanged(ArrayList deadMembers, ArrayList newMembers,
                     ArrayList allMembers, String logCategoryName)

                    The ArrayLists contain org.jboss.ha.framework.server.util.TopologyMonitorService.AddressPort objects, which encapsulate the InetAddress and port of the affected node.