Bug 824102

Summary: [as5] server discovery sometimes discovers a JNP URL containing an IPv6 address surrounded by square brackets (e.g. "jnp://[0:0:0:0:0:0:0:1]:1099"), and the plugin fails to connect to the URL
Product: [Other] RHQ Project Reporter: Ian Springer <ian.springer>
Component: PluginsAssignee: Nobody <nobody>
Status: NEW --- QA Contact:
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.4CC: hrupp, staffan.horke
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 919199    

Description Ian Springer 2012-05-22 18:04:43 UTC
The discovery code reads the JNP URL from $JBOSS_EAP_HOME/server/<ACTIVE_CONFIGURATION>/data/jnp-service.url. Note that this is not a configuration file but a file JBoss EAP creates while starting up. This was done to ease the problem of finding the correct values in the AS configuration files for management software like RHQ. 

For whatever reason (perhaps when IPv6 is set as preferred), AS5 sometimes sets the URL in this file to "jnp://[0:0:0:0:0:0:0:1]:1099", yet the AS5 JNP client does not support connecting to such URL's that contain square brackets (see 
https://community.jboss.org/thread/152432).

I think we may be able to workaround the JBAS bug in cases where the IPv6 address can be converted to an IPv4 address, e.g.:

---

String jnpHost = jnpUri.getHost();
String normalizedJnpHost = jnpHost;
InetAddress ipAddress = IntetAddress.getByName(jnpHost);
if (ipAddress instanceof Inet6Address) {
   Inet6Address ipv6Address = (Inet6Address)ipAddress;
   if (ipv6Address.isIPv4CompatibleAddress()) {
       if (ipv6Address.isLoopbackAddress()) {
           normalizedJnpHost = "127.0.0.1";
       } else {
           byte[] ipv6Bytes = ipv6Address.getAddress();
           byte[] ipv4Bytes = Arrays.copyOfRange(ipv6Bytes, 12, 16);       
           InetAddress ipv4Address = InetAddress.getByAddress(ipv4Bytes);
           normalizedJnpHost = ipv4Address.toString();
       }
    }
}
String normalizedJnpUri = "jnp://" + normalizedJnpHost + ":" + jnpUri.getPort();

Comment 1 Ian Springer 2012-05-22 18:12:44 UTC
This was reported in this user forum thread:

https://community.jboss.org/thread/196085

Comment 2 Staffan Hörke 2012-05-24 11:55:34 UTC
In my case I run JBAS 6.1.0.Final bound to 192.168.115.155 and the jnp-service.url contains a IPv4 address jnp://192.168.115.155:1199. From the agent log it looks like the file is read correctly:

2012-05-22 17:24:35,078 DEBUG [ResourceDiscoveryComponent.invoker.daemon-1] (org.rhq.plugins.jbossas5.ApplicationServerDiscoveryComponent)- Read JNP URL from jnp-service.url file: jnp://192.168.115.155:1199

However, to connect it later uses an IPv6 address, which fails:

2012-05-22 17:24:44,894 DEBUG [InventoryManager.discovery-1] (rhq.plugins.jbossas5.connection.RemoteProfileServiceConnectionProvider)- Connecting to Profile Service via remote JNDI using env [{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.provider.url=jnp://[0:0:0:0:0:0:0:1]:1199, jnp.disableDiscovery=true, jnp.timeout=60000, jnp.sotimeout=60000}]...
...
2012-05-22 17:24:44,894 DEBUG [InventoryManager.discovery-1] (org.rhq.plugins.jbossas5.ApplicationServerComponent)- Failed to connect to Profile Service.
...
Caused by: javax.naming.CommunicationException: Could not obtain connection to any of these urls: [0:0:0:0:0:0:0:1]:1199 [Root exception is javax.naming.CommunicationException: Failed to connect to server /0:0:0:0:0:0:0:1:1199 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server /0:0:0:0:0:0:0:1:1199 [Root exception is java.net.SocketException: Protocol family unavailable]]]

JDK 6
WIN 7
JBAS 6.1.0.Final
RHQ 4.4.0

JBAS + agent on one machine. RHQ server on another. I disabled IPv6 on Windows with the same result.

Running the same setup with RHQ 4.2.0 works

Comment 3 Ian Springer 2012-05-24 20:22:19 UTC
Thanks, this info will be very helpful in getting to the bottom of this. 

One question for you: does your Agent JVM command line contain either of the following options?

-Djava.net.preferIPv4Stack=true
-Djava.net.preferIPv6Addresses=true

Comment 4 Ian Springer 2012-05-24 20:24:56 UTC
Actually can you also check if your AS 6.1 JVM command line has either of those options?

Comment 5 Mike Foley 2012-05-29 14:41:21 UTC
per BZ Triage 5/29/2012 (ccrouch, loleary, asantos, mfoley, myarborough) moving these to JON 3.1.1 or later

Comment 6 Staffan Hörke 2012-05-31 09:42:46 UTC
Agent JVM contains (inst default)
-Djava.net.preferIPv4Stack=true

AS 6.1 did not contain any of the above.

When 4.4.0 failed I tried RHQ 4.2.0 which worked (inst default). After your feedback added -Djava.net.preferIPv4Stack=true to AS 6.1 JAVA_OPTS and tried RHQ 4.4.0. Now my agent connects to the IPv4 url.

However, after discovery success I fail to reproduce the error, even by removing -Djava.net.preferIPv4Stack=true from AS 6.1. So I cannot confirm what actually made it work.