modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
| 52 +++++-----
modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASDiscoveryComponent.java
| 50 ++++++---
2 files changed, 64 insertions(+), 38 deletions(-)
New commits:
commit bb5e7a9d039d10ce308c5bcd811c4c1423330a7f
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Thu Apr 29 15:27:19 2010 +0200
BZ 580928, BZ 587250 - RHQ server is identified as such in the resource name, jboss as
(4 and 5) are called hostname:jnpPort instead of bindingAddress:jnpPort
diff --git
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
index b02bd01..3b51ec7 100644
---
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
+++
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
@@ -27,7 +27,9 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.URL;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -288,43 +290,51 @@ public class ApplicationServerDiscoveryComponent implements
ResourceDiscoveryCom
namingPort = port;
}
- String configName = absoluteConfigPath.getName();
- String baseName = discoveryContext.getSystemInformation().getHostname();
String description = installInfo.getProductType().DESCRIPTION;
File deployDir = new File(absoluteConfigPath, "deploy");
File rhqInstallerWar = new File(deployDir, "rhq-installer.war");
File rhqInstallerWarUndeployed = new File(deployDir,
"rhq-installer.war.rej");
boolean isRhqServer = rhqInstallerWar.exists() ||
rhqInstallerWarUndeployed.exists();
if (isRhqServer) {
- baseName += " RHQ Server, ";
description += " hosting the RHQ Server";
// We know this is an RHQ Server. Let's add an event source for its
server log file, but disable it by default.
configureEventSourceForServerLogFile(pluginConfig);
}
- String name = bindAddress+ (namingPort
==null?"":":"+namingPort);
+ String name = formatServerName(bindAddress, namingPort,
discoveryContext.getSystemInformation().getHostname(), isRhqServer);
return new DiscoveredResourceDetails(discoveryContext.getResourceType(), key,
name, installInfo.getVersion(),
description, pluginConfig, processInfo);
}
- /*
- private String formatServerName(String baseName, String bindingAddress, String
jnpPort, String configName,
- JBossInstallationInfo installInfo) {
- baseName = baseName + " " + installInfo.getProductType().NAME + "
" + installInfo.getVersion() + " "
- + configName;
-
- String details = null;
- if ((bindingAddress != null) && (jnpPort != null &&
!jnpPort.equals(CHANGE_ME))) {
- details = bindingAddress + ":" + jnpPort;
- } else if ((bindingAddress == null) && (jnpPort != null &&
!jnpPort.equals(CHANGE_ME))) {
- details = jnpPort;
- } else if (bindingAddress != null) {
- details = bindingAddress;
- }
- return baseName + ((details != null) ? (" (" + details + ")")
: "");
-
+ public String formatServerName(String bindingAddress, String jnpPort, String
hostname, boolean isRhq) {
+
+ if (isRhq) {
+ return hostname + " RHQ Server";
+ } else {
+ String hostnameToUse = hostname;
+
+ if (bindingAddress != null) {
+ try {
+ InetAddress bindAddr = InetAddress.getByName(bindingAddress);
+ if (!bindAddr.isAnyLocalAddress()) {
+ //if the binding address != 0.0.0.0
+ hostnameToUse = bindAddr.getHostName();
+ }
+ } catch (UnknownHostException e) {
+ //this should not happen?
+ log.warn("Unknown hostname passed in as the binding address for
JBoss AS server discovery: "
+ + bindingAddress);
+ }
+ }
+
+ if (jnpPort != null && !jnpPort.equals(CHANGE_ME)) {
+ hostnameToUse += ":" + jnpPort;
+ }
+
+ return hostnameToUse;
+ }
}
-*/
+
private void configureEventSourceForServerLogFile(Configuration pluginConfig) {
File rhqLogFile = resolvePathRelativeToHomeDir(pluginConfig,
"../logs/rhq-server-log4j.log");
if (rhqLogFile.exists() && !rhqLogFile.isDirectory()) {
diff --git
a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASDiscoveryComponent.java
b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASDiscoveryComponent.java
index b14027e..05483e4 100644
---
a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASDiscoveryComponent.java
+++
b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASDiscoveryComponent.java
@@ -24,6 +24,8 @@ package org.rhq.plugins.jbossas;
import java.io.File;
import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -294,11 +296,9 @@ public class JBossASDiscoveryComponent implements
ResourceDiscoveryComponent, Ma
}
String configName = absoluteConfigPath.getName();
- String baseName = discoveryContext.getSystemInformation().getHostname();
String description = installInfo.getProductType().DESCRIPTION;
- boolean isInServer = isEmbeddedInServer(absoluteConfigPath);
+ boolean isInServer = isRhqServer(absoluteConfigPath);
if (isInServer) {
- baseName += " RHQ Server, ";
description += " hosting the RHQ Server";
// RHQ-633 : We know this is an RHQ Server. Let's auto-configure for
tracking its log file, which is not in
@@ -325,7 +325,7 @@ public class JBossASDiscoveryComponent implements
ResourceDiscoveryComponent, Ma
}
}
}
- String name = formatServerName(baseName, bindingAddress, namingPort, configName,
installInfo);
+ String name = formatServerName(bindingAddress, namingPort,
discoveryContext.getSystemInformation().getHostname(), isInServer);
return new DiscoveredResourceDetails(discoveryContext.getResourceType(), key,
name, installInfo.getVersion(),
description, pluginConfiguration, processInfo);
@@ -335,7 +335,7 @@ public class JBossASDiscoveryComponent implements
ResourceDiscoveryComponent, Ma
* @param absoluteConfigPath
* @return true if this plugin is in an Agent that is embedded in the Server
*/
- private boolean isEmbeddedInServer(File absoluteConfigPath) {
+ private boolean isRhqServer(File absoluteConfigPath) {
File deployDir = new File(absoluteConfigPath, "deploy");
File rhqInstallerWar = new File(deployDir, "rhq-installer.war");
File rhqInstallerWarUndeployed = new File(deployDir,
"rhq-installer.war.rej");
@@ -403,8 +403,8 @@ public class JBossASDiscoveryComponent implements
ResourceDiscoveryComponent, Ma
// Now set default values on any props that are still not set.
setPluginConfigurationDefaults(pluginConfiguration);
- String resourceName =
formatServerName(context.getSystemInformation().getHostname(), bindAddress,
- jnpPort, configName, installInfo);
+ String resourceName = formatServerName(bindAddress, jnpPort,
+ context.getSystemInformation().getHostname(),
isRhqServer(configDir));
DiscoveredResourceDetails resource = new
DiscoveredResourceDetails(context.getResourceType(), configDir
.getAbsolutePath(), resourceName, version,
"JBoss AS server that the RHQ Plugin Container is running
within", pluginConfiguration, null);
@@ -420,16 +420,32 @@ public class JBossASDiscoveryComponent implements
ResourceDiscoveryComponent, Ma
return null;
}
- public String formatServerName(String baseName, String bindingAddress, String
jnpPort, String configName,
- JBossInstallationInfo installInfo) {
-
- String details = null;
- if ((bindingAddress != null) && (jnpPort != null &&
!jnpPort.equals(CHANGE_ME))) {
- details = bindingAddress + ":" + jnpPort;
- } else
- details = bindingAddress;
-
- return details;
+ public String formatServerName(String bindingAddress, String jnpPort, String
hostname, boolean isRhq) {
+
+ if (isRhq) {
+ return hostname + " RHQ Server";
+ } else {
+ String hostnameToUse = hostname;
+
+ if (bindingAddress != null) {
+ try {
+ InetAddress bindAddr = InetAddress.getByName(bindingAddress);
+ if (!bindAddr.isAnyLocalAddress()) {
+ //if the binding address != 0.0.0.0
+ hostnameToUse = bindAddr.getHostName();
+ }
+ } catch (UnknownHostException e) {
+ //this should not happen?
+ log.warn("Unknown hostname passed in as the binding address
for JBoss AS server discovery: " + bindingAddress);
+ }
+ }
+
+ if (jnpPort != null && !jnpPort.equals(CHANGE_ME)) {
+ hostnameToUse += ":" + jnpPort;
+ }
+
+ return hostnameToUse;
+ }
}
private static String getJnpURL(JBossInstanceInfo cmdLine, File installHome, File
configDir) {