3 Replies Latest reply on Jun 19, 2012 11:22 PM by fred.vogt

    AS 7.1 - Programatic discovery of cluster node addresses

    will.tatam

      What is the recommended way of getting the ip addreses for the node currently in the cluster ?

       

      Previously we were using the jboss.partition=${name},service=HAPartition CurrentView but given all the changes with the mbean stuff in AS7 and new ip role stuff (public, management etc), is there something better to get this ip list ?

        • 1. Re: AS 7.1 - Programatic discovery of cluster node addresses
          pferraro

          There are a number of ways you could do this.  Of the top of my head:

           

          1. From Infinispan:

          @Resource(lookup = "java:jboss/infinispan/container/web")

          private EmbeddedCacheContainer container;

           

          public Collection<InetAddress> getClusterAddresses() {

             List<Address> members = this.container.getMembers();

            List<InetAddress> addresses = new ArrayList<InetAddress>(addresses.size());

             for (Address member: members) {

               addresses.add(((IpAddress) ((JGroupsAddress) member).getJGroupsAddress()).getIpAddress());

             }

             return addresses;

          }

           

          2. From JGroups via MSC:

          Channel channel = (Channel) CurrentServiceContainer.getServiceContainer().getService(ServiceName.JBOSS.append("jgroups", "channel", "web")).getValue();

          List<Address> members = channel.getView().getMembers();

          List<InetAddress> addresses = new ArrayList<InetAddress>(addresses.size());

          for (Address member: members) {

            addresses.add(((IpAddress) member).getIpAddress());

          }

          return addresses;

           

          3. From JGroups via JMX:

          ManagementFactory.getPlatformMBeanServer().getAttribute(ObjectName.getInstance("jgroups:type=channel,cluster=\"web\""), "View");

          This returns the logical names of the cluster members, which defaults to "<host-name>/<cluster-name>"

          1 of 1 people found this helpful
          • 2. Re: AS 7.1 - Programatic discovery of cluster node addresses
            will.tatam

            These all sound like helpful suggestions, but I'm guessing they alll return the ip being used by jgroups. This is basically what we has before, which was fine in AS 5.1 as you only really had the jboss.bind.address where as with AS7 we now have the whole management/public etc stuff so my question was more about an offical way to discover the list of public addresses for all nodes.

             

            The reason I want this is that we need clients to be able to goto a http url where they download their jnlp file. In there it contains the connection properties for the java SE app to connect back to JBossAS. Now it could just contain the connection details of the server which served that HTTP request and then use the funky smart proxy stuff to then discover all other server nodes. The problem with this is that if we happen to take that server out of the cluster for some reason, the client can't discover any of the other node and the user if forced to goto the web page and re-launch the appplication with a fresh jnlp file. If i know the public ips of all the node currently in the cluster, we only require one of those nodes to be active when the user launches the app, with only a minor delay while the client working it's way though the list till it hits one that is live in order to get a fresh list for it's smart proxy.

             

            Given the grown of on-demand stuff that cloud offers I can see our clusters being much more dynamic than they have been in the past, so this becomes a larger issue as does the need for the public ips, given how in the case of EC2 the nodes will be using private address space to communicate but may be accessed by public ips

            • 3. Re: AS 7.1 - Programatic discovery of cluster node addresses
              fred.vogt

              #2 Needs to be changed with JGroups 2.8+:

               

              Channel channel = (Channel) CurrentServiceContainer.getServiceContainer().getService(ServiceName.JBOSS.append("jgroups", "channel", "web")).getValue();

              List<Address> members = channel.getView().getMembers();

              List<IpAddress> addresses = new ArrayList<IpAddress>(addresses.size());

              for (Address member: members) {

                PhysicalAddress physicalAddr = (PhysicalAddress)channel.down(new Event(Event.GET_PHYSICAL_ADDRESS, member));

                IpAddress ipAddr = (IpAddress)physicalAddr;

               

                addresses.add(ipAddr);

              }

              return addresses

               

              IpAddress has  {ip:port}.