[rhq] Branch 'release/jon3.1.x' - modules/plugins
Heiko W. Rupp
pilhuhn at fedoraproject.org
Wed Aug 8 15:19:27 UTC 2012
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java | 33 +++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
New commits:
commit ca526ee7bbe5e1d6bf38fb1fd5a30cfa6f1f2753
Author: Heiko W. Rupp <hwr at redhat.com>
Date: Wed Aug 8 11:19:13 2012 -0400
BZ 841048 Don't assume a host name of 'master', but get it via api if it is not set. If this does not work, get it via hostname resolution.
(cherry-picked from 2639e50, BZ 841047)
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
index b729983..7c00fb4 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
@@ -19,6 +19,8 @@
package org.rhq.modules.plugins.jbossas7;
import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -64,7 +66,10 @@ public class ManagedASDiscovery implements ResourceDiscoveryComponent<HostContro
parentComponent = discoveryContext.getParentResourceComponent();
Configuration hcConfig = discoveryContext.getParentResourceContext().getPluginConfiguration();
- String hostName = hcConfig.getSimpleValue("domainHost", "master"); // TODO good default?
+ String hostName = hcConfig.getSimpleValue("domainHost", null);
+ if (hostName==null) {
+ hostName = getHostName(discoveryContext.getParentResourceComponent().getASConnection());
+ }
String productTypeString = hcConfig.getSimpleValue("productType", null);
JBossProductType productType = JBossProductType.valueOf(productTypeString);
@@ -129,6 +134,32 @@ public class ManagedASDiscovery implements ResourceDiscoveryComponent<HostContro
return discoveredResources;
}
+ /**
+ * Let us try to determine the hostname of the parent's controller via api access.
+ * If that does not work, use host name resolution.
+ *
+ * @param asConnection ASConnection to the parent
+ * @return Host name
+ */
+ private String getHostName(ASConnection asConnection) {
+
+ Operation op = new ReadAttribute(new Address(),"local-host-name");
+ String hostname;
+ Result res = asConnection.execute(op);
+ if (res.isSuccess()) {
+ hostname = (String) res.getResult();
+ return hostname;
+ }
+ // Above failed. Now try falling back to host name resolution
+ try {
+ hostname = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException e) {
+ hostname = "master"; // Very last resort
+ }
+
+ return hostname;
+ }
+
private String resolveSocketBindingGroup(String serverGroup) {
Address address = new Address("server-group", serverGroup);
Operation operation = new ReadAttribute(address, "socket-binding-group");
More information about the rhq-commits
mailing list