modules/plugins/apache/pom.xml
| 21 +
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceComponent.java
| 46 +---
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceDiscoveryComponent.java
| 20 -
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
| 61 ++---
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasTreeBuilderApache.java
| 10
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheParserImpl.java
| 4
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/HttpdAddressUtility.java
| 114 ++++++++--
modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApacheAugeasTest.java
| 11
modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApachePluginTest.java
| 13 -
modules/plugins/augeas/src/main/java/org/rhq/augeas/util/Glob.java
| 4
10 files changed, 193 insertions(+), 111 deletions(-)
New commits:
commit ae99b5bc0bf42909308a9d1efc09cee77d06ffc1
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Nov 23 22:09:27 2010 +0100
a couple of robustness enhancements to the apache plugin:
BZ 656449 - use the matching algorithm between SNMP values and augeas nodes also
when matching the vhost node by resource key, because resource key
in RHQ 3 is based on the SNMP value.
BZ 652247 - Log the SNMP errors only on DEBUG level during discovery because SNMP
isn't
required for it to work.
BZ 656476 - Do not fail the discovery if a non-existent directory is used in an
Include directive
BZ 652247, BZ 656491 - Do not choke on invalid/unresolvable hostnames in VirtualHost
or ServerName directives
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceComponent.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceComponent.java
index a0f2120..c894fa9 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceComponent.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceComponent.java
@@ -26,6 +26,7 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -384,25 +385,26 @@ public class ApacheVirtualHostServiceComponent implements
ResourceComponent<Apac
//BZ 612189 - remove this once resource upgrade is in place
HttpdAddressUtility.Address resourceKeyAddress =
HttpdAddressUtility.Address.parse(resourceKey);
+
+ AugeasNode bestNode = null;
+ int bestMatch = 0;
for(AugeasNode node : nodes) {
- List<AugeasNode> serverNameNodes = tree.matchRelative(node,
"ServerName/param");
List<AugeasNode> vhostAddressNodes =
node.getChildByLabel("param");
- String vhostServerName = serverNameNodes.isEmpty() ? null :
serverNameNodes.get(0).getValue();
- String vhostAddressDef = vhostAddressNodes.isEmpty() ? null :
vhostAddressNodes.get(0).getValue();
+ List<HttpdAddressUtility.Address> vhostAddresses = new
ArrayList<HttpdAddressUtility.Address>();
+ for (AugeasNode vhostAddressNode : vhostAddressNodes) {
+
vhostAddresses.add(HttpdAddressUtility.Address.parse(vhostAddressNode.getValue()));
+ }
- if (vhostAddressDef != null) {
- HttpdAddressUtility.Address vhostAddress =
HttpdAddressUtility.Address.parse(vhostAddressDef);
- if (vhostServerName != null) {
- HttpdAddressUtility.Address vhostServerAddress =
HttpdAddressUtility.Address.parse(vhostServerName);
- vhostAddress.host = vhostServerAddress.host;
- }
-
- if (resourceKeyAddress.equals(vhostAddress)) {
- virtualHosts.add(node);
- }
+ int matchRate = matchRate(vhostAddresses, resourceKeyAddress);
+ if (bestMatch < matchRate) {
+ bestNode = node;
}
}
+
+ if (bestNode != null) {
+ return bestNode;
+ }
//BZ 612189 - remove this once we have resource upgrade
//ok, one final attempt... the legacy resource key format for the MainServer is
just a host:port as with the rest of the vhosts, let's try that
@@ -411,24 +413,18 @@ public class ApacheVirtualHostServiceComponent implements
ResourceComponent<Apac
URI serverUri = new URI(serverUrl);
String expectedResourceKey = serverUri.getHost() + ":" +
serverUri.getPort();
- if (expectedResourceKey.equals(resourceKey)) {
+ HttpdAddressUtility.Address expectedAddress =
HttpdAddressUtility.Address.parse(expectedResourceKey);
+ HttpdAddressUtility.Address actualAddress =
HttpdAddressUtility.Address.parse(resourceKey);
+
+ if (matchRate(Collections.singletonList(expectedAddress), actualAddress) >
0) {
return tree.getRootNode();
}
} catch (URISyntaxException e) {
log.warn("Failed to parse the server URL when trying to match the vhost
with the main server.", e);
}
- if (virtualHosts.size() == 0) {
- throw new IllegalStateException("Could not find virtual host
configuration in augeas for virtual host: "
- + resourceKey);
- }
-
- if (virtualHosts.size() > 1) {
- throw new IllegalStateException("Found more than 1 virtual host
configuration in augeas for virtual host: "
- + resourceKey);
- }
-
- return virtualHosts.get(0);
+ throw new IllegalStateException("Could not find virtual host configuration
in augeas for virtual host: "
+ + resourceKey);
}
/**
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceDiscoveryComponent.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceDiscoveryComponent.java
index 8251658..95edbcf 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceDiscoveryComponent.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheVirtualHostServiceDiscoveryComponent.java
@@ -96,6 +96,7 @@ public class ApacheVirtualHostServiceDiscoveryComponent implements
ResourceDisco
}
String resourceKey = createResourceKey(serverName, hosts);
+ String resourceName = resourceKey; //this'll get overridden below if we
find a better value using the address variable
Configuration pluginConfiguration = context.getDefaultPluginConfiguration();
@@ -104,7 +105,7 @@ public class ApacheVirtualHostServiceDiscoveryComponent implements
ResourceDisco
String scheme = address.scheme;
String hostToPing = address.host;
int portToPing = address.port;
- if (address.isPortWildcard()) {
+ if (address.isPortWildcard() || !address.isPortDefined()) {
Address serverAddress =
serverComponent.getAddressUtility().getMainServerSampleAddress(tree, hostToPing, 0);
if (serverAddress != null) {
portToPing = serverAddress.port;
@@ -132,21 +133,14 @@ public class ApacheVirtualHostServiceDiscoveryComponent implements
ResourceDisco
PropertySimple urlProp = new
PropertySimple(ApacheVirtualHostServiceComponent.URL_CONFIG_PROP, url);
pluginConfiguration.put(urlProp);
- }
-
- if (address != null) {
File rtLogFile = new File(logsDir, address.host + address.port +
RT_LOG_FILE_NAME_SUFFIX);
-
+
PropertySimple rtLogProp = new PropertySimple(
ApacheVirtualHostServiceComponent.RESPONSE_TIME_LOG_FILE_CONFIG_PROP,
rtLogFile.toString());
pluginConfiguration.put(rtLogProp);
- }
-
- String resourceName;
- if (serverName != null) {
- resourceName = address.host + ":" + address.port;
- } else {
- resourceName = resourceKey;
+
+ //redefine the resourcename using the virtual host sample address
+ resourceName = address.toString(false);
}
//BZ 612189 - remove this once we have resource upgrade
@@ -320,7 +314,7 @@ public class ApacheVirtualHostServiceDiscoveryComponent implements
ResourceDisco
return ret;
} catch (Exception e) {
- log.warn("Error while trying to contact SNMP of the apache server "
+ discoveryContext.getParentResourceContext().getResourceKey(), e);
+ log.debug("Error while trying to contact SNMP of the apache server
" + discoveryContext.getParentResourceContext().getResourceKey(), e);
return null;
}
}
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
index 3e51757..d4f7dd2 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
@@ -31,10 +31,11 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.rhq.augeas.config.AugeasModuleConfig;
import org.rhq.augeas.util.Glob;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.plugins.apache.ApachePluginLifecycleListener;
import org.rhq.plugins.apache.ApacheServerComponent;
import org.rhq.rhqtransform.AugeasRhqException;
import org.rhq.rhqtransform.impl.PluginDescriptorBasedAugeasConfiguration;
@@ -59,6 +60,8 @@ public class AugeasConfigurationApache extends
PluginDescriptorBasedAugeasConfig
private final Pattern includePattern = Pattern.compile(INCLUDE_FILES_PATTERN);
private final Pattern serverRootPattern = Pattern.compile(SERVER_ROOT_PATTERN);
+ private static final Log LOG = LogFactory.getLog(AugeasConfigurationApache.class);
+
private String serverRootPath;
private AugeasModuleConfig module;
private List<File> allConfigFiles;
@@ -109,7 +112,7 @@ public class AugeasConfigurationApache extends
PluginDescriptorBasedAugeasConfig
files.addAll(Glob.match(root, expression));
for (File fl : files){
- if (fl.exists()) {
+ if (fl.exists() && fl.isFile()) {
foundIncludes.add(fl.getAbsolutePath());
FileInputStream fstream = new FileInputStream(fl);
@@ -162,18 +165,23 @@ public class AugeasConfigurationApache extends
PluginDescriptorBasedAugeasConfig
for (File configFile : files) {
if (!configFile.isAbsolute()) {
- throw new IllegalStateException(
- "Configuration files inclusion patterns contain a
non-absolute file.");
+ LOG.warn("Configuration files inclusion patterns contain a
non-absolute file: " + configFile);
+ continue;
}
+
if (!configFile.exists()) {
- throw new IllegalStateException(
- "Configuration files inclusion patterns refer to a
non-existent file.");
+ LOG.warn("Configuration files inclusion patterns refer to a
non-existent file: " + configFile);
+ continue;
}
+
if (configFile.isDirectory()) {
- throw new IllegalStateException("Configuration files inclusion
patterns refer to a directory.");
+ LOG.warn("Configuration files inclusion patterns refer to a
directory: " + configFile);
+ continue;
}
- if (!module.getConfigFiles().contains(configFile.getAbsolutePath()))
+
+ if (!module.getConfigFiles().contains(configFile.getAbsolutePath())) {
module.addConfigFile(configFile.getAbsolutePath());
+ }
}
}
}
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheParserImpl.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheParserImpl.java
index f33f8fd..686625e 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheParserImpl.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheParserImpl.java
@@ -24,7 +24,9 @@ public class ApacheParserImpl implements ApacheParser{
if (directive.getName().equals(INCLUDE_DIRECTIVE)){
List<File> files = getIncludeFiles(directive.getValuesAsString());
for (File fl : files){
- ApacheConfigReader.searchFile(fl.getAbsolutePath(), this);
+ if (fl.exists() && fl.isFile()) {
+ ApacheConfigReader.searchFile(fl.getAbsolutePath(), this);
+ }
}
}
directive.setParentNode(stack.getLastDirective());
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/HttpdAddressUtility.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/HttpdAddressUtility.java
index b5cdedf..0710178 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/HttpdAddressUtility.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/HttpdAddressUtility.java
@@ -82,7 +82,7 @@ public enum HttpdAddressUtility {
address = getLocalhost(address.port);
}
- updateWithServerName(address, ag, false);
+ updateWithServerName(address, ag);
return address;
}
@@ -106,7 +106,7 @@ public enum HttpdAddressUtility {
addr = getLocalhost(addr.port);
}
- updateWithServerName(addr, ag, false);
+ updateWithServerName(addr, ag);
return addr;
}
@@ -217,21 +217,68 @@ public enum HttpdAddressUtility {
Address o = (Address) other;
- if (this.host == null) {
- return o.host == null && this.port == o.port;
- } else {
- return this.host.equals(o.host) && this.port == o.port;
+ return safeEquals(host, o.host) && this.port == o.port;
+ }
+
+ /**
+ * This differs from equals in the way that it considers wildcard values:
+ * <ul>
+ * <li>wildcard host matches any host
+ * <li>default host matches default host
+ * <li>wildcard port matches any port
+ * <li>undefined port matches undefined port
+ * </ul>
+ * The addresses match if both address and port match.
+ *
+ * @param other the address to match
+ * @param whether to match the scheme as well
+ * @return true if the addresses match according to the rules described above,
false otherwise
+ */
+ public boolean matches(Address other, boolean matchSchemes) {
+ if (matchSchemes && !safeEquals(scheme, other.scheme)) {
+ return false;
+ }
+
+ if (!WILDCARD.equals(host) && !WILDCARD.equals(other.host) &&
!safeEquals(host, other.host)) {
+ return false;
}
+
+ if (PORT_WILDCARD_VALUE != port && PORT_WILDCARD_VALUE != other.port
&& port != other.port) {
+ return false;
+ }
+
+ return true;
}
@Override
public String toString() {
- if (port == NO_PORT_SPECIFIED_VALUE) return scheme + "://" + host;
- else {
- String portSpec = port == PORT_WILDCARD_VALUE ? WILDCARD :
String.valueOf(port);
+ return toString(true);
+ }
+
+ public String toString(boolean includeScheme) {
+ StringBuilder bld = new StringBuilder();
+
+ if (includeScheme) {
+ bld.append(scheme).append("://");
+ }
+
+ bld.append(host);
+
+ if (port != NO_PORT_SPECIFIED_VALUE) {
+ bld.append(":");
- return scheme + "://" + host + ":" + portSpec;
+ if (port == PORT_WILDCARD_VALUE) {
+ bld.append(WILDCARD);
+ } else {
+ bld.append(port);
+ }
}
+
+ return bld.toString();
+ }
+
+ private static boolean safeEquals(Object a, Object b) {
+ return a == null ? b == null : a.equals(b);
}
}
@@ -270,9 +317,9 @@ public enum HttpdAddressUtility {
return null;
addr.host = serverAddr.host;
}
-
+
if (serverName != null) {
- updateWithServerName(addr, serverName, true);
+ updateWithServerName(addr, serverName);
}
return addr;
@@ -351,7 +398,7 @@ public enum HttpdAddressUtility {
}
}
- private static void updateWithServerName(Address address, ApacheDirectiveTree config,
boolean updatePort) throws UnknownHostException {
+ private static void updateWithServerName(Address address, ApacheDirectiveTree config)
throws UnknownHostException {
//check if there is a ServerName directive
List<ApacheDirective> serverNameNodes =
config.search("/ServerName");
@@ -360,21 +407,46 @@ public enum HttpdAddressUtility {
//be the case if the server listens on more than one interfaces.
if (serverNameNodes.size() > 0) {
String serverName = serverNameNodes.get(0).getValuesAsString();
- updateWithServerName(address, serverName, updatePort);
+ updateWithServerName(address, serverName);
}
}
- private static void updateWithServerName(Address address, String serverName, boolean
updatePort) throws UnknownHostException {
+ private static void updateWithServerName(Address address, String serverName) throws
UnknownHostException {
+ //the configuration may be invalid and/or the hostname can be unresolvable.
+ //we try to match the address with the servername first by IP address
+ //but if that fails (i.e. the hostname couldn't be resolved to an IP)
+ //we try to simply match the hostnames themselves.
+
Address serverAddr = Address.parse(serverName);
- InetAddress addrFromServerName = InetAddress.getByName(serverAddr.host);
- InetAddress addrFromAddress = InetAddress.getByName(address.host);
+ String ipFromServerName = null;
+ String ipFromAddress = null;
+ String hostFromServerName = null;
+ String hostFromAddress = null;
+ boolean lookupFailed = false;
+
+ try {
+ InetAddress addrFromServerName = InetAddress.getByName(serverAddr.host);
+ ipFromServerName = addrFromServerName.getHostAddress();
+ hostFromServerName = addrFromServerName.getHostName();
+ } catch (UnknownHostException e) {
+ ipFromServerName = serverAddr.host;
+ hostFromServerName = serverAddr.host;
+ lookupFailed = true;
+ }
- if (addrFromAddress.equals(addrFromServerName)) {
+ try {
+ InetAddress addrFromAddress = InetAddress.getByName(address.host);
+ ipFromAddress = addrFromAddress.getHostAddress();
+ hostFromAddress = addrFromAddress.getHostName();
+ } catch (UnknownHostException e) {
+ ipFromAddress = address.host;
+ hostFromAddress = address.host;
+ lookupFailed = true;
+ }
+
+ if (ipFromAddress.equals(ipFromServerName) || (lookupFailed &&
(hostFromAddress.equals(hostFromServerName)))) {
address.scheme = serverAddr.scheme;
address.host = serverAddr.host;
- if (updatePort) {
- address.port = serverAddr.port;
- }
}
}
}
diff --git a/modules/plugins/augeas/src/main/java/org/rhq/augeas/util/Glob.java
b/modules/plugins/augeas/src/main/java/org/rhq/augeas/util/Glob.java
index fddf06e..d41d2a2 100644
--- a/modules/plugins/augeas/src/main/java/org/rhq/augeas/util/Glob.java
+++ b/modules/plugins/augeas/src/main/java/org/rhq/augeas/util/Glob.java
@@ -26,6 +26,7 @@ package org.rhq.augeas.util;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -129,7 +130,8 @@ public class Glob {
globPattern = new File(globPattern).getAbsolutePath();
File[] files = parentPath.listFiles(new GlobFilter(globPattern));
if (files == null) {
- throw new IllegalStateException("Could not list files in " +
parentPath);
+ log.debug("Could list files in " + parentPath);
+ return Collections.emptyList();
}
return Arrays.asList(files);
}
commit 1e6b979b70b403f1ac537e1fd274bf01b2c0c515
Author: Filip Drabek <fdrabek(a)dhcp-lab-136.englab.brq.redhat.com>
Date: Thu Aug 5 13:54:15 2010 +0200
BZ-618314 - fix of apache tests
BZ-618877 - Includes can use absolute path now.
diff --git a/modules/plugins/apache/pom.xml b/modules/plugins/apache/pom.xml
index f8868f6..5781ac5 100644
--- a/modules/plugins/apache/pom.xml
+++ b/modules/plugins/apache/pom.xml
@@ -95,18 +95,27 @@
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration-tests</id>
- <activation>
- <property>
- <name>maven.test.skip</name>
- <value>!true</value>
- </property>
- </activation>
+ <!--
+ <activation>
+ <property>
+ <name>maven.test.skip</name>
+ <value>!true</value>
+ </property>
+ </activation>
+ -->
<build>
<plugins>
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
index cb61c0a..3e51757 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
@@ -101,17 +101,13 @@ public class AugeasConfigurationApache extends
PluginDescriptorBasedAugeasConfig
}
private void loadIncludes(String expression, List<String> foundIncludes) {
- try {
- File file = new File(expression);
-
+ try {
List<File> files = new ArrayList<File>();
- if (!file.isAbsolute()) {
- File serverRootFile = new File(serverRootPath);
- files = Glob.match(serverRootFile, expression);
- }else
- files.add(file);
-
+ File check = new File(expression);
+ File root = new File(check.isAbsolute() ? Glob.rootPortion(expression) :
serverRootPath);
+ files.addAll(Glob.match(root, expression));
+
for (File fl : files){
if (fl.exists()) {
foundIncludes.add(fl.getAbsolutePath());
@@ -142,8 +138,7 @@ public class AugeasConfigurationApache extends
PluginDescriptorBasedAugeasConfig
}
public void loadFiles() {
- File root = new File(serverRootPath);
-
+
for (AugeasModuleConfig module : modules) {
List<String> includeGlobs = module.getIncludedGlobs();
@@ -154,10 +149,10 @@ public class AugeasConfigurationApache extends
PluginDescriptorBasedAugeasConfig
ArrayList<File> files = new ArrayList<File>();
for (String incl : includeGlobs) {
- if (incl.indexOf(File.separatorChar) == 0) {
- files.add(new File(incl));
- } else
- files.addAll(Glob.match(root, incl));
+ File check = new File(incl);
+ File root = new File(check.isAbsolute() ? Glob.rootPortion(incl) :
serverRootPath);
+
+ files.addAll(Glob.match(root, incl));
}
if (module.getExcludedGlobs() != null) {
@@ -185,15 +180,11 @@ public class AugeasConfigurationApache extends
PluginDescriptorBasedAugeasConfig
private static List<File> getIncludeFiles(String serverRoot, List<String>
foundIncludes) {
List<File> ret = new ArrayList<File>();
- File serverRootFile = new File(serverRoot);
for (String path : foundIncludes) {
- File check = new File(path);
- if (check.isAbsolute()) {
- ret.add(check);
- } else {
- for (File f : Glob.match(serverRootFile, path)) {
- ret.add(f);
- }
+ File check = new File(path);
+ File root = new File(check.isAbsolute() ? Glob.rootPortion(path) :
serverRoot);
+ for (File f :Glob.match(root, path)){
+ ret.add(f);
}
}
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasTreeBuilderApache.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasTreeBuilderApache.java
index 24c2e95..e6454b7 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasTreeBuilderApache.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasTreeBuilderApache.java
@@ -70,18 +70,16 @@ public class AugeasTreeBuilderApache implements AugeasTreeBuilder {
AugeasNode rootNode = new ApacheAugeasNode(ApacheAugeasTree.AUGEAS_DATA_PATH +
rootPath, tree);
tree.setRootNode(rootNode);
- File rootFile = new File(apacheConfig.getServerRootPath());
// we need to know which files are related to each glob
for (String inclName : module.getIncludedGlobs()) {
List<File> files = new ArrayList<File>();
- if (inclName.indexOf(File.separatorChar) == 0) {
- files.add(new File(inclName));
- } else
- files.addAll(Glob.match(rootFile, inclName));
-
+ File check = new File(inclName);
+ File root = new File(check.isAbsolute() ? Glob.rootPortion(inclName) :
apacheConfig.getServerRootPath());
+ files.addAll(Glob.match(root, inclName));
+
if (module.getExcludedGlobs() != null)
Glob.excludeAll(files, module.getExcludedGlobs());
diff --git
a/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApacheAugeasTest.java
b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApacheAugeasTest.java
index 344ab1f..88a050b 100644
--- a/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApacheAugeasTest.java
+++ b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApacheAugeasTest.java
@@ -3,6 +3,8 @@ package org.rhq.plugins.apache;
import java.io.File;
import java.util.List;
+import net.augeas.Augeas;
+
import org.rhq.augeas.AugeasProxy;
import org.rhq.augeas.node.AugeasNode;
import org.rhq.augeas.tree.AugeasTree;
@@ -120,4 +122,13 @@ public class ApacheAugeasTest {
//test if the updated augeas tree can be mapped to configuration stored at
files in "loadconfig" temporary directory
testLoadConfig(treeUpdate, container);
}
+
+ public boolean isAugeasInstalled(){
+ try {
+ Augeas ag = new Augeas();
+ }catch(Throwable e){
+ return false;
+ }
+ return true;
+ }
}
diff --git
a/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApachePluginTest.java
b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApachePluginTest.java
index 890aa10..5a6cc7e 100644
--- a/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApachePluginTest.java
+++ b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/ApachePluginTest.java
@@ -18,18 +18,16 @@
*/
package org.rhq.plugins.apache;
-/*
+
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
-
import org.rhq.core.clientapi.server.discovery.InventoryReport;
import org.rhq.core.domain.measurement.DataType;
import org.rhq.core.domain.measurement.MeasurementData;
@@ -43,7 +41,6 @@ import org.rhq.core.pc.plugin.PluginEnvironment;
import org.rhq.core.pc.plugin.PluginManager;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
-*/
/**
* The unit tests for the JON Apache plugin.
@@ -53,7 +50,6 @@ import org.rhq.core.pluginapi.measurement.MeasurementFacet;
public class ApachePluginTest {
private static final String PLUGIN_NAME = "Apache";
- /*
@BeforeSuite
public void start() {
//System.out.println("java.class.path=" +
System.getProperty("java.class.path"));
@@ -71,6 +67,10 @@ public class ApachePluginTest {
container.getInventoryManager().executeServerScanImmediately();
container.getInventoryManager().executeServiceScanImmediately();
ApacheAugeasTest test = new ApacheAugeasTest();
+ if (!test.isAugeasInstalled()){
+ System.out.println("Augeas is not installed.");
+ return;
+ }
test.testMapping(container);
} catch (Exception e) {
e.printStackTrace();
@@ -153,5 +153,4 @@ public class ApachePluginTest {
ApachePluginTest pluginTest = new ApachePluginTest();
pluginTest.start();
}
- */
-}
\ No newline at end of file
+}