4 Replies Latest reply on Aug 24, 2015 8:51 AM by kalzzz

    How to retrieve programmatically the management host and port

    kalzzz

      Greetings,

       

      I'd like to connect to Jboss-cli from a servlet running in JBOSS.EAP 6.3

       

      Example

      ModelControllerClient _client = ModelControllerClient.Factory.create(InetAddress.getByName(_management_host), _management_port);

       

      My problem is how to pickup the good _management_host and _management_port informations

      Default is 127.0.0.1:9999  of course, but depending of the JBOSS configuration, it can be something different..

       

       

      In standalone mode, i found the solution with JMX :

       

      MBeanServerConnection mbs = ManagementFactory.getPlatformMBeanServer();

      ObjectName socketBindingObjectName = new ObjectName("jboss.as:socket-binding-group=standard-sockets,socket-binding=management-native"); 

      _management_host = (String) mbs.getAttribute(socketBindingObjectName, "boundAddress");

      _management_port  = (Integer) mbs.getAttribute(socketBindingObjectName, "boundPort");

       

       

      Unfortunately in domain mode cluster, the standard-socket in the JMX view is replaced by a full-ha-socket (or other..)  not containing management-native host and port information,

       

      So my question is.. what is the best way to obtain them in domain mode ?

       

      Even better : is there a way to obtain the host and port to connect to the JBOSS-cli of the Domain controller (remote) instead of the local node jboss-cli ?

       

      Thanks for any help.

        • 1. Re: How to retrieve programmatically the management host and port
          mayerw01

          This should provide you the management host address via JMX:

           

          MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);

          ObjectName objectName = new ObjectName("jboss.as:interface=management");

          String attrib = "";

             try {

                    attrib = (String) server.getAttribute(objectName, "inetAddress");

          ...

           

          I understand that the native management port uses the abyss service in domain mode.

          So in linux the command  'nmap -v  localhost | grep abyss' should show an output like

          9999/tcp open  abyss

          • 2. Re: How to retrieve programmatically the management host and port
            kalzzz

            Thank you for the quick anwser,  Wolfgang Mayer.

             

            Indeed with the jboss.as:interface=management object i can get the host controller IP
            But the object don't contain other util stuff.
            Actually, i also need the port because it can be something else than 9999 (for exemple , because of a JBoss offset port setting)
            It seems that the port information is missing in the jmx tree in domain mode.


            More than that when my running application is not on the domain controller computer, i d'like to connect to the remote domain controller (for the full cluster view)
            And in this case again, no possible help by the JMX view...


            I'm currently thinking about a solution using the JBoss host.xml file.
            For example, reading the <domain-controller><remote> tag.
            I have the location of the file with the JMX key  jboss.as:path=jboss.domain.config.dir
            But The difficulty is that the name can be something different of host.xml (if launch command --host-config=my-custom-host.xml is used )

             

            So i'm still looking for a more reliable solution

             

            (the linux command  nmap is not possible because the jboss  can run on a windows plateform).

            • 3. Re: How to retrieve programmatically the management host and port
              mayerw01

              I doubt that you will be able to get the "real" port from the configuration. This issue apparently exists also in standalone mode Obtain http port programatically fails on Wildfly 8.1.0

              I still think that the only reliable information will come from the operating system using some port scanner as described above

              • 4. Re: How to retrieve programmatically the management host and port
                kalzzz

                Finally, I implemented this solution :
                1) connection to the host controller with jboss-cli to retrieve the "domain-controler" informations  (better than reading the host.xml because its name can be changed)
                2) connection to the domain controller with jboss-cli to retrieve the whole cluster informations (all hosts and server...)

                 

                However things are still fishy in the point 1)
                -no clean solution to retrieve the management host and port , so i pick  properties jboss.bind.address.management and jboss.management.native.port when available or default 127.0.0.1:9999 (but offset settings are still a problem)
                -the readed domain-controler object can contains JBoss expression like ${jboss.domain.master.address}"  and in this case, no idea how to resolve them