5 Replies Latest reply on Aug 31, 2012 2:34 AM by wdfink

    Identifying if a node is started in standalone or cluster mode and is master/slave if cluster mode

    jbosss

      Is there a way to programatically know whether the node is running in a standalone mode or a domain cluster mode? Does JBoss make this information available?


      Also in case of cluster mode, is there an API available, which can tell me if the current node (on which this piece of code is running) is a master or a slave? Probably, in most cases, you dont care, but say if you dont implement a ha singleton service, but want to execute some code only on the master (or only on the salve) node(s), how do you do it? How do the various UIs for JBoss monitoring get this information from JBoss AS?

       

      I looked at JBoss AS clustering code and I couldnt find and API that can give this information. I looked at the GroupCommunicationService class and the MBeanServer class and they dont have this information. Is there any way I could query and get this information from JBOSS?

        • 1. Re: Identifying if a node is started in standalone or cluster mode and is master/slave if cluster mode
          rhusar
          Is there a way to programatically know whether the node is running in a standalone mode or a domain cluster mode? Does JBoss make this information available?

           

          The terms are confused here a little. Clustering and domain mode are orthogonal/independent to each other.

          Also in case of cluster mode, is there an API available, which can tell me if the current node (on which this piece of code is running) is a master or a slave?

          There isnt really a master/slave concept.

          but want to execute some code only on the master (or only on the salve) node(s), how do you do it? How do the various UIs for JBoss monitoring get this information from JBoss AS?

          You can create your own artificial master which will be running your own service wrapped in SIngletonService. Then you can differenciate if its a master or slave.

          • 2. Re: Identifying if a node is started in standalone or cluster mode and is master/slave if cluster mode
            wdfink

            From the server perspective it is not relevant whether it run in a domain mode or not. Both run similar from the application perspective. There is no API to check from the app whether the server is controlled by a domain.

             

            AS Radoslav said, be careful and do not mix the concepts.

             

            Cluster is a bunch of server that handle the same application load and might loadbalance and/or replicate states.

            A domain is only an administrative wrapper where server are controlled by special instances called host-controller and all configurations are done by a special host-controller instance called domain-dontroller.

             

            Why do you need to know whether a server is a master or controlled by a domain? Could you explain your usecase?

            • 3. Re: Identifying if a node is started in standalone or cluster mode and is master/slave if cluster mode
              jbosss

              Yes. I got the concepts messed up, I realize now. Thanks!

               

              There are 2 configurations that we support for the product. One is configuration for a bunch of servers as a cluster (configured via the domain.xml). The other is just a standalone single sever of JBoss with no other nodes (so it is not a part of any cluster). In either case, we need to have some code wrapped in a service run on only one node at a time. The ha-singleton service that I wrote using your quickstart example helps achieve in the cluster mode (configured via the domain.xml). But incase of the standalone server with no clustering, the ha-singleton service doesnt start. It waits on transition to UP for sometime and then it throws an exception saying 'Singleton Service {servicename} not started, are you sure to start in a cluster (HA) environment'

               

              So based on that error message, I think that the ha-singleton works only for cluster enabled server (standalone or domain mode). Can you confirm if that is that true? Or is there a way to we make the ha-singleton service work for the standalone server (without clustering as well)?

               

              Am I still mixing things up? :-).

              Please do let me know as you guys have been very helpful. Appreciate it!

               

              Thanks!

              • 4. Re: Identifying if a node is started in standalone or cluster mode and is master/slave if cluster mode
                jbosss

                The way I am thinknig of doing is having the application configuration tell us if it is a standalone or cluster. So then from that information, we either spawn the service directly if it is a standalone or use the ha-singleton service incase of the cluster so we have the failover capability

                • 5. Re: Identifying if a node is started in standalone or cluster mode and is master/slave if cluster mode
                  wdfink

                  So based on that error message, I think that the ha-singleton works only for cluster enabled server (standalone or domain mode). Can you confirm if that is that true? Or is there a way to we make the ha-singleton service work for the standalone server (without clustering as well)?

                  Yes, the SingletonService need part of the cluster subsystem to sync the state, that's why I'm add this message.

                   

                  For me it looks ok to start the -ha profile, you might add only the part of -ha.xml which is needed (I think it is the cache-container stuff).

                  This will have the benefit that you don't need a extra code and everything works if you add more nodes.

                   

                  You solution looks also possible, but I'm not sure how to check. Maybe use the management API to check whether the jgroups subsystem is configured.