for (ProcessScanResult autoDiscoveryResult : autoDiscoveryResults) {
ProcessInfo processInfo = autoDiscoveryResult.getProcessInfo();
if (LOG.isDebugEnabled())
LOG.debug("Discovered JBoss AS process: " + processInfo);
JBossInstanceInfo jbossInstanceInfo;
try {
jbossInstanceInfo = new JBossInstanceInfo(processInfo);
} catch (Exception e) {
LOG.error("Failed to process JBoss AS command line: " + Arrays.asList(processInfo.getCommandLine()), e);
continue;
}
// Skip it if it's an AS/EAP/SOA-P version we don't support.
JBossInstallationInfo installInfo = jbossInstanceInfo.getInstallInfo();
if (!isSupportedProduct(installInfo)) {
continue;
}
File installHome = new File(jbossInstanceInfo.getSystemProperties().getProperty(JBossProperties.HOME_DIR));
File configDir = new File(jbossInstanceInfo.getSystemProperties().getProperty(
JBossProperties.SERVER_HOME_DIR));
// The config dir might be a symlink - call getCanonicalFile() to resolve it if so, before
// calling isDirectory() (isDirectory() returns false for a symlink, even if it points at
// a directory).
try {
if (!configDir.getCanonicalFile().isDirectory()) {
LOG.warn("Skipping discovery for JBoss AS process " + processInfo + ", because configuration dir '"
+ configDir + "' does not exist or is not a directory.");
continue;
}
} catch (IOException e) {
LOG.error("Skipping discovery for JBoss AS process " + processInfo + ", because configuration dir '"
+ configDir + "' could not be canonicalized.", e);
continue;
}
Configuration pluginConfiguration = discoveryContext.getDefaultPluginConfiguration();
// TODO? Set the connection type - local or remote
// Set the required props...
String jnpURL = getJnpURL(jbossInstanceInfo, installHome, configDir);
PropertySimple namingUrlProp = new PropertySimple(
ApplicationServerPluginConfigurationProperties.NAMING_URL, jnpURL);
if (jnpURL == null) {
namingUrlProp.setErrorMessage("RHQ failed to discover the naming provider URL.");
}
pluginConfiguration.put(namingUrlProp);
pluginConfiguration.put(new PropertySimple(ApplicationServerPluginConfigurationProperties.HOME_DIR,
installHome.getAbsolutePath()));
pluginConfiguration.put(new PropertySimple(ApplicationServerPluginConfigurationProperties.SERVER_HOME_DIR,
configDir));
// Set the optional props...
pluginConfiguration.put(new PropertySimple(ApplicationServerPluginConfigurationProperties.SERVER_NAME,
jbossInstanceInfo.getSystemProperties().getProperty(JBossProperties.SERVER_NAME)));
pluginConfiguration.put(new PropertySimple(ApplicationServerPluginConfigurationProperties.BIND_ADDRESS,
jbossInstanceInfo.getSystemProperties().getProperty(JBossProperties.BIND_ADDRESS)));
JBossASDiscoveryUtils.UserInfo userInfo = JBossASDiscoveryUtils.getJmxInvokerUserInfo(configDir);
if (userInfo != null) {
pluginConfiguration.put(new PropertySimple(ApplicationServerPluginConfigurationProperties.PRINCIPAL,
userInfo.getUsername()));