modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java | 55 ++++++++-- modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/helper/HostConfiguration.java | 24 ++-- 2 files changed, 65 insertions(+), 14 deletions(-)
New commits: commit bf8587569567d261791f272a672f5722d7dca8c0 Author: Thomas Segismont tsegismo@redhat.com Date: Thu Jul 18 23:37:57 2013 +0200
[as7] Fix domain api version discovery
Look for the first node of type element instead of simply calling getFirstChild
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/helper/HostConfiguration.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/helper/HostConfiguration.java index 329246e..3c71135 100644 --- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/helper/HostConfiguration.java +++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/helper/HostConfiguration.java @@ -1,6 +1,6 @@ /* * RHQ Management Platform - * Copyright (C) 2012 Red Hat, Inc. + * Copyright (C) 2005-2013 Red Hat, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify @@ -13,11 +13,14 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package org.rhq.modules.plugins.jbossas7.helper;
+import static org.rhq.core.util.StringUtil.EMPTY_STRING; +import static org.w3c.dom.Node.ELEMENT_NODE; + import java.io.File; import java.io.FileInputStream; import java.io.InputStream; @@ -33,6 +36,7 @@ import javax.xml.xpath.XPathFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; +import org.w3c.dom.Node;
import org.rhq.core.pluginapi.util.CommandLineOption; import org.rhq.modules.plugins.jbossas7.AS7CommandLine; @@ -234,11 +238,15 @@ public class HostConfiguration { }
public String getDomainApiVersion() { - - String version = document.getFirstChild().getAttributes().getNamedItem("xmlns").getTextContent(); - - version = version.substring(version.lastIndexOf(':')+1); - return version; + // Look for the first child node of type element (<host> in domain mode or <server> in standalone mode) + // We can't just call getFirstChild because first child could be a node of type comment + for (Node childNode = document.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) { + if (childNode.getNodeType() == ELEMENT_NODE) { + String xmlns = childNode.getAttributes().getNamedItem("xmlns").getTextContent(); + return xmlns.substring(xmlns.lastIndexOf(':') + 1); + } + } + return EMPTY_STRING; }
/**
commit 5283e5356d2ca4bda6e3aeea9d323c186030baa9 Author: Thomas Segismont tsegismo@redhat.com Date: Thu Jul 18 09:41:39 2013 +0200
Bug 969621 - EAP 6 managed plug-in is unable to discover EAP servers when more then one is running on a single host
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java index cc13406..cd9f276 100644 --- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java +++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java @@ -1,6 +1,6 @@ /* * RHQ Management Platform - * Copyright (C) 2005-2012 Red Hat, Inc. + * Copyright (C) 2005-2013 Red Hat, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify @@ -13,8 +13,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package org.rhq.modules.plugins.jbossas7;
@@ -42,6 +42,7 @@ import org.rhq.core.domain.configuration.Configuration; import org.rhq.core.domain.configuration.PropertyList; import org.rhq.core.domain.configuration.PropertyMap; import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.core.domain.resource.ResourceUpgradeReport; import org.rhq.core.pluginapi.event.log.LogFileEventResourceComponentHelper; import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails; import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException; @@ -49,6 +50,8 @@ import org.rhq.core.pluginapi.inventory.ManualAddFacet; import org.rhq.core.pluginapi.inventory.ProcessScanResult; import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent; import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext; +import org.rhq.core.pluginapi.upgrade.ResourceUpgradeContext; +import org.rhq.core.pluginapi.upgrade.ResourceUpgradeFacet; import org.rhq.core.pluginapi.util.CommandLineOption; import org.rhq.core.pluginapi.util.FileUtils; import org.rhq.core.pluginapi.util.JavaCommandLine; @@ -66,12 +69,15 @@ import org.rhq.modules.plugins.jbossas7.json.Result; * Abstract base discovery component for the two server types - "JBossAS7 Host Controller" and * "JBossAS7 Standalone Server". */ -public abstract class BaseProcessDiscovery implements ResourceDiscoveryComponent, ManualAddFacet { +public abstract class BaseProcessDiscovery implements ResourceDiscoveryComponent, ManualAddFacet, ResourceUpgradeFacet {
private static final String JBOSS_AS_PREFIX = "jboss-as-"; private static final String JBOSS_EAP_PREFIX = "jboss-eap-"; private static final String WILDFLY_PREFIX = "wildfly-";
+ private static final String LOCAL_RESOURCE_KEY_PREFIX = "hostConfig: "; + private static final String REMOTE_RESOURCE_KEY_PREFIX = "hostPort: "; + private static final String HOME_DIR_SYSPROP = "jboss.home.dir";
private static final String RHQADMIN = "rhqadmin"; @@ -202,7 +208,7 @@ public abstract class BaseProcessDiscovery implements ResourceDiscoveryComponent setStartScriptPluginConfigProps(process, commandLine, pluginConfig, agentProcess); setUserAndPasswordPluginConfigProps(serverPluginConfig, hostConfig, baseDir);
- String key = baseDir.getPath(); + String key = createKeyForLocalResource(serverPluginConfig); HostPort hostPort = hostConfig.getDomainControllerHostPort(commandLine); String name = buildDefaultResourceName(hostPort, managementHostPort, productType); String description = buildDefaultResourceDescription(hostPort, productType); @@ -455,7 +461,7 @@ public abstract class BaseProcessDiscovery implements ResourceDiscoveryComponent HostPort managementHostPort = new HostPort(false); managementHostPort.host = hostname; managementHostPort.port = port; - String key = hostname + ":" + port; + String key = createKeyForRemoteResource(hostname + ":" + port); String name = buildDefaultResourceName(hostPort, managementHostPort, productType); String version = productInfo.getProductVersion(); String description = buildDefaultResourceDescription(hostPort, productType); @@ -469,6 +475,43 @@ public abstract class BaseProcessDiscovery implements ResourceDiscoveryComponent return detail; }
+ @Override + public ResourceUpgradeReport upgrade(ResourceUpgradeContext inventoriedResource) { + String currentResourceKey = inventoriedResource.getResourceKey(); + Configuration pluginConfiguration = inventoriedResource.getPluginConfiguration(); + ServerPluginConfiguration serverPluginConfiguration = new ServerPluginConfiguration(pluginConfiguration); + + if (currentResourceKey.startsWith(LOCAL_RESOURCE_KEY_PREFIX) + || currentResourceKey.startsWith(REMOTE_RESOURCE_KEY_PREFIX)) { + // Resource key already in right format + return null; + } + + ResourceUpgradeReport report = new ResourceUpgradeReport(); + + if (new File(currentResourceKey).isDirectory()) { + // Old key format for a local resource (key is base dir) + report.setNewResourceKey(createKeyForLocalResource(serverPluginConfiguration)); + } else if (currentResourceKey.contains(":")) { + // Old key format for a remote (manually added) resource (key is base dir) + report.setNewResourceKey(createKeyForRemoteResource(currentResourceKey)); + } else { + log.warn("Unknown format, cannot upgrade resource key [" + currentResourceKey + "]"); + return null; + } + + return report; + } + + private String createKeyForRemoteResource(String hostPort) { + return REMOTE_RESOURCE_KEY_PREFIX + hostPort; + } + + private String createKeyForLocalResource(ServerPluginConfiguration serverPluginConfiguration) { + return LOCAL_RESOURCE_KEY_PREFIX + + serverPluginConfiguration.getHostConfigFile().getAbsolutePath(); + } + private <T>T getServerAttribute(ASConnection connection, String attributeName) { Operation op = new ReadAttribute(null, attributeName); Result res = connection.execute(op);
rhq-commits@lists.fedorahosted.org