Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the instance hostname while running a Liberty App pushed via a Packaged Server

I have a bluemix app pushed via packaged liberty server. The app looks for the instance IP/hostname internally. When the app is upscaled with more than one instance, using localhost as the hostname becomes obsolete. Host entry is set in our server.xml.

When i tried to use Referenceable variables such as ${host} or ${vcap_console_ip}, it is not getting the host name or ip address respectively.

  1. ${host} returns 0.0.0.0 in our server.xml
  2. ${vcap_console_ip} - it is not getting any value. I see the runtime-vars.xml doesn't show the ${vcap_console_ip} even if use it in the server.xml.

Looking for suggestion on how to get the host name or ip of the instance the app is running into my server.xml.

like image 817
krckumar Avatar asked Dec 14 '25 20:12

krckumar


1 Answers

You could use the VCAP_APPLICATION env variable and get the "uris" attribute.

    String VCAP_APPLICATION = System.getenv("VCAP_APPLICATION");
    if (VCAP_APPLICATION != null) {
            JsonNode node = Json.mapper().readValue(VCAP_APPLICATION, JsonNode.class);
            ArrayNode uris = (ArrayNode) node.get("uris");
            if (uris != null && uris.size() > 0 && uris.get(0) != null) {
                host = uris.get(0).textValue();
            }
like image 78
ArthurDM Avatar answered Dec 19 '25 05:12

ArthurDM