modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerDiscoveryComponent.java | 1 modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheParserImpl.java | 2 modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/ApacheBinaryInfo.java | 2 modules/plugins/apache/src/test/java/org/rhq/plugins/apache/RuntimeConfigurationTest.java | 240 ++++++++++ modules/plugins/apache/src/test/java/org/rhq/plugins/apache/util/MockApacheBinaryInfo.java | 126 +++++ modules/plugins/apache/src/test/java/org/rhq/plugins/apache/util/MockProcessInfo.java | 51 ++ modules/plugins/apache/src/test/resources/runtime-config/conditional/httpd.conf | 2 modules/plugins/apache/src/test/resources/runtime-config/conditional/ifdefine-defined.conf | 5 modules/plugins/apache/src/test/resources/runtime-config/conditional/ifdefine-undefined.conf | 5 modules/plugins/apache/src/test/resources/runtime-config/conditional/ifmodule-loaded.conf | 13 modules/plugins/apache/src/test/resources/runtime-config/conditional/ifmodule-not-loaded.conf | 11 modules/plugins/apache/src/test/resources/runtime-config/conditional/nested-mess.conf | 53 ++ modules/plugins/apache/src/test/resources/runtime-config/incl-order/a.conf | 1 modules/plugins/apache/src/test/resources/runtime-config/incl-order/b.conf | 1 modules/plugins/apache/src/test/resources/runtime-config/incl-order/c.conf | 1 modules/plugins/apache/src/test/resources/runtime-config/incl-order/httpd.conf | 1 modules/plugins/apache/src/test/resources/runtime-config/vhost-names/httpd.conf | 5 modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-with-servername-by-ip.conf | 3 modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-with-servername-by-unresolvable-hostname.conf | 3 modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-without-servername-resolvable-ip.conf | 3 modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-without-servername-unresolvable-ip.conf | 3 modules/plugins/augeas/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java | 2 modules/plugins/augeas/src/main/java/org/rhq/augeas/util/Glob.java | 48 +- modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java | 2 modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java | 18 modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/PluginDescriptorBasedAugeasConfiguration.java | 2 26 files changed, 587 insertions(+), 17 deletions(-)
New commits: commit 8c7ba989644f307a4a783a31e83f76639ed92a71 Author: Lukas Krejci lkrejci@redhat.com Date: Mon May 2 17:54:09 2011 +0200
Tests for the inclusion order and IfModule and IfDefine detection.
diff --git a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/ApacheBinaryInfo.java b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/ApacheBinaryInfo.java index aedb144..724fc19 100644 --- a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/ApacheBinaryInfo.java +++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/ApacheBinaryInfo.java @@ -65,7 +65,7 @@ public class ApacheBinaryInfo { private Set<String> compiledInModules = new HashSet<String>(); private Set<String> compiledInDefines = new HashSet<String>();
- private ApacheBinaryInfo(@NotNull + protected ApacheBinaryInfo(@NotNull String binaryPath) { this.binaryPath = binaryPath; } diff --git a/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/RuntimeConfigurationTest.java b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/RuntimeConfigurationTest.java new file mode 100644 index 0000000..260c4c6 --- /dev/null +++ b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/RuntimeConfigurationTest.java @@ -0,0 +1,240 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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. + */ + +package org.rhq.plugins.apache; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static org.testng.Assert.*; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import org.rhq.core.pluginapi.util.FileUtils; +import org.rhq.core.util.file.FileUtil; +import org.rhq.plugins.apache.parser.ApacheConfigReader; +import org.rhq.plugins.apache.parser.ApacheDirective; +import org.rhq.plugins.apache.parser.ApacheDirectiveTree; +import org.rhq.plugins.apache.parser.ApacheParser; +import org.rhq.plugins.apache.parser.ApacheParserImpl; +import org.rhq.plugins.apache.util.MockApacheBinaryInfo; +import org.rhq.plugins.apache.util.MockProcessInfo; +import org.rhq.plugins.apache.util.RuntimeApacheConfiguration; + +/** + * + * + * @author Lukas Krejci + */ +@Test +public class RuntimeConfigurationTest { + + private File tmpDir; + + private static final String[] CONDITIONAL_CONFIGURATION_TEST_FILES = { + "runtime-config/conditional/httpd.conf", + "runtime-config/conditional/ifdefine-defined.conf", + "runtime-config/conditional/ifdefine-undefined.conf", + "runtime-config/conditional/ifmodule-loaded.conf", + "runtime-config/conditional/ifmodule-not-loaded.conf", + "runtime-config/conditional/nested-mess.conf" + }; + + private static final String[] INCLUSION_ORDER_CONFIGURATION_TEST_FILES = { + "runtime-config/incl-order/a.conf", + "runtime-config/incl-order/b.conf", + "runtime-config/incl-order/c.conf", + "runtime-config/incl-order/httpd.conf" + }; + + private static final String[] VHOST_NAMES_CONFIGURATION_TEST_FILES = { + "runtime-config/vhost-names/httpd.conf", + "runtime-config/vhost-names/vhost-with-servername-by-ip.conf", + "runtime-config/vhost-names/vhost-with-servername-by-unresolvable-hostname.conf", + "runtime-config/vhost-names/vhost-without-servername-resolvable-ip.conf", + "runtime-config/vhost-names/vhost-without-servername-unresolvable-ip.conf" + }; + + @BeforeClass + public void copyConfigurationFiles() throws Exception { + tmpDir = FileUtil.createTempDirectory("apache-runtime-config-tests", null, null); + + for(String path : CONDITIONAL_CONFIGURATION_TEST_FILES) { + copyResourceToFile(path, new File(tmpDir, path)); + } + + for(String path : INCLUSION_ORDER_CONFIGURATION_TEST_FILES) { + copyResourceToFile(path, new File(tmpDir, path)); + } + + for(String path : VHOST_NAMES_CONFIGURATION_TEST_FILES) { + copyResourceToFile(path, new File(tmpDir, path)); + } + } + + @AfterClass + public void deleteConfigurationFiles() throws IOException { + FileUtils.purge(tmpDir, true); + } + + public void testConditionalInclusion() { + //TODO add tests for IfVersion!!! + + MockApacheBinaryInfo binfo = new MockApacheBinaryInfo(); + binfo.setVersion("2.2.17"); + MockProcessInfo pinfo = new MockProcessInfo(); + pinfo.setCommandLine(new String[] {"/usr/sbin/httpd", "-D", "DEFINED"}); + + ApacheDirectiveTree tree = new ApacheDirectiveTree(); + ApacheParser parser = new ApacheParserImpl(tree, new File(tmpDir, "runtime-config/conditional").getAbsolutePath()); + ApacheConfigReader.buildTree(new File(tmpDir, "runtime-config/conditional/httpd.conf").getAbsolutePath(), parser); + + tree = RuntimeApacheConfiguration.extract(tree, pinfo, binfo, ApacheServerDiscoveryComponent.MODULE_SOURCE_FILE_TO_MODULE_NAME_20); + + List<VhostSpec> vhosts = VhostSpec.detect(tree); + + List<VhostSpec> expectedVhosts = new ArrayList<VhostSpec>(); + + expectedVhosts.add(new VhostSpec(Collections.singleton("127.0.0.1:80"), "ifdefine.defined")); + expectedVhosts.add(new VhostSpec(Collections.singleton("127.0.0.1:82"), "ifmodule.loaded.source-file")); + expectedVhosts.add(new VhostSpec(Collections.singleton("127.0.0.1:83"), "ifmodule.loaded.module-name")); + expectedVhosts.add(new VhostSpec(Collections.singleton("127.0.0.1:88"), "ifdefine.ifmodule.loaded.source-file")); + expectedVhosts.add(new VhostSpec(Collections.singleton("127.0.0.1:89"), "ifdefine.ifmodule.loaded.module-name")); + + assertEquals(vhosts, expectedVhosts); + } + + public void testInclusionOrder() { + MockApacheBinaryInfo binfo = new MockApacheBinaryInfo(); + binfo.setVersion("2.2.17"); + MockProcessInfo pinfo = new MockProcessInfo(); + pinfo.setCommandLine(new String[] {"/usr/sbin/httpd"}); + + ApacheDirectiveTree tree = new ApacheDirectiveTree(); + ApacheParser parser = new ApacheParserImpl(tree, new File(tmpDir, "runtime-config/incl-order").getAbsolutePath()); + ApacheConfigReader.buildTree(new File(tmpDir, "runtime-config/incl-order/httpd.conf").getAbsolutePath(), parser); + + tree = RuntimeApacheConfiguration.extract(tree, pinfo, binfo, ApacheServerDiscoveryComponent.MODULE_SOURCE_FILE_TO_MODULE_NAME_20); + + List<ApacheDirective> listens = tree.search("/Listen"); + + assertEquals(listens.size(), 3, "There should be 3 listen directives"); + + assertEquals(listens.get(0).getValuesAsString(), "80"); + assertEquals(listens.get(1).getValuesAsString(), "81"); + assertEquals(listens.get(2).getValuesAsString(), "82"); + } + + public void testVhostNames() { + MockApacheBinaryInfo binfo = new MockApacheBinaryInfo(); + binfo.setVersion("2.2.17"); + MockProcessInfo pinfo = new MockProcessInfo(); + pinfo.setCommandLine(new String[] {"/usr/sbin/httpd"}); + + ApacheDirectiveTree tree = new ApacheDirectiveTree(); + ApacheParser parser = new ApacheParserImpl(tree, new File(tmpDir, "runtime-config/vhost-names").getAbsolutePath()); + ApacheConfigReader.buildTree(new File(tmpDir, "runtime-config/vhost-names/httpd.conf").getAbsolutePath(), parser); + + tree = RuntimeApacheConfiguration.extract(tree, pinfo, binfo, ApacheServerDiscoveryComponent.MODULE_SOURCE_FILE_TO_MODULE_NAME_20); + + //TODO implement this + } + + private void copyResourceToFile(String resourcePath, File destination) throws IOException { + InputStream input = getClass().getClassLoader().getResourceAsStream(resourcePath); + + if (input != null) { + destination.getParentFile().mkdirs(); + destination.createNewFile(); + + BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(destination)); + + try { + int data; + while((data = input.read()) != -1) { + output.write(data); + } + } finally { + input.close(); + output.close(); + } + } + } + + private static class VhostSpec { + public List<String> definition; + public String serverName; + + public static List<VhostSpec> detect(ApacheDirectiveTree tree) { + List<VhostSpec> ret = new ArrayList<VhostSpec>(); + + for(ApacheDirective vhost : tree.search("/<VirtualHost")) { + ret.add(new VhostSpec(vhost)); + } + + return ret; + } + + public VhostSpec(ApacheDirective vhost) { + definition = vhost.getValues(); + List<ApacheDirective> serverNames = vhost.getChildByName("ServerName"); + if (serverNames.size() > 0) { + serverName = serverNames.get(0).getValuesAsString(); + } + } + + public VhostSpec(Collection<String> definition, String serverName) { + this.definition = new ArrayList<String>(definition); + this.serverName = serverName; + } + + @Override + public String toString() { + return "VhostSpec[serverName='" + serverName + "', definition=" + definition + "]"; + } + + @Override + public int hashCode() { + return serverName.hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof VhostSpec)) { + return false; + } + + VhostSpec o = (VhostSpec) other; + + return serverName.equals(o.serverName) && definition.equals(o.definition); + } + } +} diff --git a/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/util/MockApacheBinaryInfo.java b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/util/MockApacheBinaryInfo.java new file mode 100644 index 0000000..adb5ac8 --- /dev/null +++ b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/util/MockApacheBinaryInfo.java @@ -0,0 +1,126 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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. + */ + +package org.rhq.plugins.apache.util; + +import java.util.HashSet; +import java.util.Set; + +/** + * Class used to represent the apache binary in the runtime configuration tests. + * + * @author Lukas Krejci + */ +public class MockApacheBinaryInfo extends ApacheBinaryInfo { + + private Set<String> defines = new HashSet<String>(); + private Set<String> modules = new HashSet<String>(); + private String configFile; + private String binaryPath; + private String built; + private long lastModified; + private String mpm; + private String root; + private String version; + + public MockApacheBinaryInfo() { + super(null); + } + + @Override + public String getBinaryPath() { + return binaryPath; + } + + public void setBinaryPath(String path) { + this.binaryPath = path; + } + + @Override + public String getBuilt() { + return built; + } + + public void setBuilt(String built) { + this.built = built; + } + + @Override + public Set<String> getCompiledInDefines() { + return defines; + } + + public void setCompiledInDefines(Set<String> defines) { + this.defines = defines; + } + + @Override + public Set<String> getCompiledInModules() { + return modules; + } + + public void setCompiledInModules(Set<String> modules) { + this.modules = modules; + } + + @Override + public String getCtl() { + return configFile; + } + + public void setCtl(String ctl) { + this.configFile = ctl; + } + + @Override + public long getLastModified() { + return lastModified; + } + + public void setLastModified(long lastModified) { + this.lastModified = lastModified; + } + + @Override + public String getMpm() { + return mpm; + } + + public void setMpm(String mpm) { + this.mpm = mpm; + } + + @Override + public String getRoot() { + return root; + } + + public void setRoot(String root) { + this.root = root; + } + + @Override + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} diff --git a/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/util/MockProcessInfo.java b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/util/MockProcessInfo.java new file mode 100644 index 0000000..2832ce2 --- /dev/null +++ b/modules/plugins/apache/src/test/java/org/rhq/plugins/apache/util/MockProcessInfo.java @@ -0,0 +1,51 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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. + */ + +package org.rhq.plugins.apache.util; + +import org.rhq.core.system.ProcessInfo; + +/** + * Class used to pretend the apache process info in the runtime configuration tests. + * + * @author Lukas Krejci + */ +public class MockProcessInfo extends ProcessInfo { + + private long pid; + private String[] commandLine; + + @Override + public long getPid() { + return pid; + } + + public void setPid(long pid) { + this.pid = pid; + } + + @Override + public String[] getCommandLine() { + return commandLine; + } + + public void setCommandLine(String[] commandLine) { + this.commandLine = commandLine; + } +} diff --git a/modules/plugins/apache/src/test/resources/runtime-config/conditional/httpd.conf b/modules/plugins/apache/src/test/resources/runtime-config/conditional/httpd.conf new file mode 100644 index 0000000..7325704 --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/conditional/httpd.conf @@ -0,0 +1,2 @@ +Include if*.conf +Include nested-mess.conf diff --git a/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifdefine-defined.conf b/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifdefine-defined.conf new file mode 100644 index 0000000..7631a5c --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifdefine-defined.conf @@ -0,0 +1,5 @@ +<IfDefine DEFINED> + <VirtualHost 127.0.0.1:80> + ServerName ifdefine.defined + </VirtualHost> +</IfDefine> diff --git a/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifdefine-undefined.conf b/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifdefine-undefined.conf new file mode 100644 index 0000000..6acd1a5 --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifdefine-undefined.conf @@ -0,0 +1,5 @@ +<IfDefine UNDEFINED> + <VirtualHost 127.0.0.1:81> + ServerName ifdefine.undefined + </VirtualHost> +</IfDefine> diff --git a/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifmodule-loaded.conf b/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifmodule-loaded.conf new file mode 100644 index 0000000..f9aba0a --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifmodule-loaded.conf @@ -0,0 +1,13 @@ +LoadModule alias_module + +<IfModule mod_alias.c> + <VirtualHost 127.0.0.1:82> + ServerName ifmodule.loaded.source-file + </VirtualHost> +</IfModule> + +<IfModule alias_module> + <VirtualHost 127.0.0.1:83> + ServerName ifmodule.loaded.module-name + </VirtualHost> +</IfModule> diff --git a/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifmodule-not-loaded.conf b/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifmodule-not-loaded.conf new file mode 100644 index 0000000..611ba1a --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/conditional/ifmodule-not-loaded.conf @@ -0,0 +1,11 @@ +<IfModule mod_not_loaded.c> + <VirtualHost 127.0.0.1:84> + ServerName ifmodule.not-loaded.source-file + </VirtualHost> +</IfModule> + +<IfModule not_loaded_module> + <VirtualHost 127.0.0.1:85> + ServerName ifmodule.not-loaded.module-name + </VirtualHost> +</IfModule> diff --git a/modules/plugins/apache/src/test/resources/runtime-config/conditional/nested-mess.conf b/modules/plugins/apache/src/test/resources/runtime-config/conditional/nested-mess.conf new file mode 100644 index 0000000..5a2ab62 --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/conditional/nested-mess.conf @@ -0,0 +1,53 @@ +<IfDefine DEFINED> + <IfModule mod_not_loaded.c> + <VirtualHost 127.0.0.1:86> + ServerName ifdefine.ifmodule.not-loaded.source-file + </VirtualHost> + </IfModule> + + <IfModule not_loaded_module> + <VirtualHost 127.0.0.1:87> + ServerName ifdefine.ifmodule.not-loaded.module-name + </VirtualHost> + </IfModule> + + <IfModule mod_alias.c> + <VirtualHost 127.0.0.1:88> + ServerName ifdefine.ifmodule.loaded.source-file + </VirtualHost> + </IfModule> + + <IfModule alias_module> + <VirtualHost 127.0.0.1:89> + ServerName ifdefine.ifmodule.loaded.module-name + </VirtualHost> + </IfModule> +</IfDefine> + +<IfDefine UNDEFINED> + <IfModule mod_not_loaded.c> + <VirtualHost 127.0.0.1:90> + ServerName not-ifdefine.ifmodule.not-loaded.source-file + </VirtualHost> + </IfModule> + + <IfModule not_loaded_module> + <VirtualHost 127.0.0.1:91> + ServerName not-ifdefine.ifmodule.not-loaded.module-name + </VirtualHost> + </IfModule> + + <IfModule mod_alias.c> + <VirtualHost 127.0.0.1:92> + ServerName not-ifdefine.ifmodule.loaded.source-file + </VirtualHost> + </IfModule> + + <IfModule alias_module> + <VirtualHost 127.0.0.1:93> + ServerName not-ifdefine.ifmodule.loaded.module-name + </VirtualHost> + </IfModule> +</IfDefine> + + diff --git a/modules/plugins/apache/src/test/resources/runtime-config/incl-order/a.conf b/modules/plugins/apache/src/test/resources/runtime-config/incl-order/a.conf new file mode 100644 index 0000000..5c1d82b --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/incl-order/a.conf @@ -0,0 +1 @@ +Listen 80 diff --git a/modules/plugins/apache/src/test/resources/runtime-config/incl-order/b.conf b/modules/plugins/apache/src/test/resources/runtime-config/incl-order/b.conf new file mode 100644 index 0000000..15adf3c --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/incl-order/b.conf @@ -0,0 +1 @@ +Listen 81 diff --git a/modules/plugins/apache/src/test/resources/runtime-config/incl-order/c.conf b/modules/plugins/apache/src/test/resources/runtime-config/incl-order/c.conf new file mode 100644 index 0000000..dd36fbd --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/incl-order/c.conf @@ -0,0 +1 @@ +Listen 82 diff --git a/modules/plugins/apache/src/test/resources/runtime-config/incl-order/httpd.conf b/modules/plugins/apache/src/test/resources/runtime-config/incl-order/httpd.conf new file mode 100644 index 0000000..ee1ee60 --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/incl-order/httpd.conf @@ -0,0 +1 @@ +Include ?.conf diff --git a/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/httpd.conf b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/httpd.conf new file mode 100644 index 0000000..29a43eb --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/httpd.conf @@ -0,0 +1,5 @@ +Listen 80 +Listen 127.0.0.1:90 +ServerName the-main-server-name:42 + +Include vhost-*.conf diff --git a/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-with-servername-by-ip.conf b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-with-servername-by-ip.conf new file mode 100644 index 0000000..978892c --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-with-servername-by-ip.conf @@ -0,0 +1,3 @@ +<VirtualHost 127.0.0.1:1000> + ServerName 12.34.56.78 +</VirtualHost> diff --git a/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-with-servername-by-unresolvable-hostname.conf b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-with-servername-by-unresolvable-hostname.conf new file mode 100644 index 0000000..d38cfc3 --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-with-servername-by-unresolvable-hostname.conf @@ -0,0 +1,3 @@ +<VirtualHost 127.0.0.1:1001> + ServerName this-will-never-resolve.weird-server.net:90 +</VirtualHost> diff --git a/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-without-servername-resolvable-ip.conf b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-without-servername-resolvable-ip.conf new file mode 100644 index 0000000..16586d1 --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-without-servername-resolvable-ip.conf @@ -0,0 +1,3 @@ +<VirtualHost 127.0.0.1:1002> + +</VirtualHost> diff --git a/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-without-servername-unresolvable-ip.conf b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-without-servername-unresolvable-ip.conf new file mode 100644 index 0000000..1637446 --- /dev/null +++ b/modules/plugins/apache/src/test/resources/runtime-config/vhost-names/vhost-without-servername-unresolvable-ip.conf @@ -0,0 +1,3 @@ +<VirtualHost 12.34.56.78:1003> + +</VirtualHost>
commit 2632a30b0bc37eaabbac4e82afc8388411cb34dd Author: Lukas Krejci lkrejci@redhat.com Date: Mon May 2 17:51:42 2011 +0200
BZ 700616 - porting over the alphabetic order awareness in glob patterns from master
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 686625e..f0e966f 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 @@ -47,6 +47,6 @@ public class ApacheParserImpl implements ApacheParser{ File check = new File(foundInclude); File root = new File(check.isAbsolute() ? Glob.rootPortion(foundInclude) : serverRootPath);
- return Glob.match(root, foundInclude); + return Glob.match(root, foundInclude, Glob.ALPHABETICAL_COMPARATOR); } } diff --git a/modules/plugins/augeas/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java b/modules/plugins/augeas/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java index 3ab8e26..0fa093c 100644 --- a/modules/plugins/augeas/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java +++ b/modules/plugins/augeas/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java @@ -132,7 +132,7 @@ public class AugeasConfigurationSimple implements AugeasConfiguration { throw new IllegalStateException("Expecting at least once inclusion pattern for configuration files."); }
- List<File> files = Glob.matchAll(root, includeGlobs); + List<File> files = Glob.matchAll(root, includeGlobs, Glob.ALPHABETICAL_COMPARATOR);
if (module.getExcludedGlobs() != null) { List<String> excludeGlobs = module.getExcludedGlobs(); 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 d41d2a2..c61f932 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 @@ -27,6 +27,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.Iterator; import java.util.List; import org.apache.commons.logging.Log; @@ -41,6 +42,16 @@ public class Glob {
private static final Log log = LogFactory.getLog(Glob.class);
+ public static final Comparator<File> ALPHABETICAL_COMPARATOR = new Comparator<File>() { + + public int compare(File o1, File o2) { + String path1 = o1.getAbsolutePath(); + String path2 = o2.getAbsolutePath(); + + return path1.compareTo(path2); + } + }; + private Glob() {
} @@ -79,6 +90,16 @@ public class Glob { }
/** + * This is an overloaded version of the {@link #match(File, String, Comparator)} method + * that passes <code>null</code> as the comparator to use. + * + * @see #match(File, String, Comparator) + */ + public static List<File> match(File parentPath, String globPattern) { + return match(parentPath, globPattern, null); + } + + /** * Returns a fixed size list of matches. * * The parent path specifies the "root" from which the glob pattern applies. @@ -90,9 +111,10 @@ public class Glob { * * @param parentPath the parent path to start the pattern search * @param globPattern the glob pattern to match against + * @param resultComparator the comparator using which to sort the results or null if no sorting is necessary * @return the list of matches */ - public static List<File> match(File parentPath, String globPattern) { + public static List<File> match(File parentPath, String globPattern, Comparator<? super File> resultComparator) { if (!parentPath.exists()) { throw new IllegalArgumentException("Path '" + parentPath + "' does not exist."); } @@ -133,6 +155,11 @@ public class Glob { log.debug("Could list files in " + parentPath); return Collections.emptyList(); } + + if (resultComparator != null) { + Arrays.sort(files, resultComparator); + } + return Arrays.asList(files); }
@@ -141,14 +168,25 @@ public class Glob { parent = parent + File.separatorChar; return parent+pattern; } - public static List<File> matchAll(File parentPath, String... globPattern) { - return matchAll(parentPath, Arrays.asList(globPattern)); - }
+ /** + * This is an overloaded version of the {@link #matchAll(File, List, Comparator)} method + * that passes <code>null</code> as the comparator to use. + * + * @see #matchAll(File, List, Comparator) + */ public static List<File> matchAll(File parentPath, List<String> globPatterns) { + return matchAll(parentPath, globPatterns, null); + } + + public static List<File> matchAll(File parentPath, List<String> globPatterns, Comparator<? super File> resultComparator) { ArrayList<File> matches = new ArrayList<File>(); for(String p : globPatterns) { - matches.addAll(match(parentPath, p)); + matches.addAll(match(parentPath, p, null)); + } + + if (resultComparator != null) { + Collections.sort(matches, resultComparator); }
return matches; diff --git a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java index 2f500b6..1a37613 100644 --- a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java +++ b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java @@ -312,7 +312,7 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement }
public List<File> getConfigurationFiles() { - List<File> files = Glob.matchAll(new File(this.augeasRootPath), includeGlobs); + List<File> files = Glob.matchAll(new File(this.augeasRootPath), includeGlobs, Glob.ALPHABETICAL_COMPARATOR); Glob.excludeAll(files, excludeGlobs); return files; } diff --git a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java index 04d4faf..292e6df 100644 --- a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java +++ b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java @@ -60,12 +60,16 @@ public class AugeasConfigurationDiscoveryComponent<T extends ResourceComponent> pluginConfig.put(includeProps); pluginConfig.put(excludeProps);
- checkFiles(pluginConfig); - - DiscoveredResourceDetails resource = createResourceDetails(discoveryContext, pluginConfig); - discoveredResources.add(resource); - log.debug("Discovered " + discoveryContext.getResourceType().getName() + " Resource with key [" - + resource.getResourceKey() + "]."); + try { + checkFiles(pluginConfig); + + DiscoveredResourceDetails resource = createResourceDetails(discoveryContext, pluginConfig); + discoveredResources.add(resource); + log.debug("Discovered " + discoveryContext.getResourceType().getName() + " Resource with key [" + + resource.getResourceKey() + "]."); + } catch (IllegalStateException e) { // Thrown by augeas if it can not read a file + log.warn("Discovery failed: " + e.getMessage()); + }
return discoveredResources; } @@ -127,7 +131,7 @@ public class AugeasConfigurationDiscoveryComponent<T extends ResourceComponent> throw new IllegalStateException("Expecting at least one inclusion pattern for configuration files."); }
- List<File> files = Glob.matchAll(root, includeGlobs); + List<File> files = Glob.matchAll(root, includeGlobs, Glob.ALPHABETICAL_COMPARATOR);
if (excludeGlobsProp != null) { List<String> excludeGlobs = getGlobList(excludeGlobsProp); diff --git a/modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/PluginDescriptorBasedAugeasConfiguration.java b/modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/PluginDescriptorBasedAugeasConfiguration.java index cd15ef2..dd3f497 100644 --- a/modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/PluginDescriptorBasedAugeasConfiguration.java +++ b/modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/PluginDescriptorBasedAugeasConfiguration.java @@ -183,7 +183,7 @@ public class PluginDescriptorBasedAugeasConfiguration implements AugeasConfigura throw new IllegalStateException("Expecting at least once inclusion pattern for configuration files."); }
- List<File> files = Glob.matchAll(root, includeGlobs); + List<File> files = Glob.matchAll(root, includeGlobs, Glob.ALPHABETICAL_COMPARATOR);
if (module.getExcludedGlobs() != null) { List<String> excludeGlobs = module.getExcludedGlobs();
commit a2c00c6f1da359c6fbd51e391fb4422ada03ac9d Author: Lukas Krejci lkrejci@redhat.com Date: Mon May 2 11:04:43 2011 +0200
BZ 700616 - runtime config extracted even in the case server root was redefined in the config files.
diff --git a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerDiscoveryComponent.java b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerDiscoveryComponent.java index 9d73da0..56ac57a 100644 --- a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerDiscoveryComponent.java +++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerDiscoveryComponent.java @@ -322,6 +322,7 @@ public class ApacheServerDiscoveryComponent implements ResourceDiscoveryComponen serverRootProp.setValue(serverRoot); //reparse the configuration with the new ServerRoot serverConfig = loadParser(serverConfigFile.getAbsolutePath(), serverRoot); + serverConfig = RuntimeApacheConfiguration.extract(serverConfig, process.getProcessInfo(), binaryInfo, getDefaultModuleNames(binaryInfo.getVersion())); }
serverUrl = getUrl(serverConfig, binaryInfo.getVersion());
rhq-commits@lists.fedorahosted.org