From: <isp...@rh...> - 2009-09-28 23:04:08
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [5220] Change apache resource key from baseDir of apache install to full path to httpd.conf (http://jira.rhq-project.org/browse/RHQ-690)</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>5220</dd> <dt>Author</dt> <dd>ispringer</dd> <dt>Date</dt> <dd>2009-09-28 18:03:54 -0500 (Mon, 28 Sep 2009)</dd> </dl> <h3>Log Message</h3> <pre>Change apache resource key from baseDir of apache install to full path to httpd.conf (http://jira.rhq-project.org/browse/RHQ-690)</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqbranchesRHQ_1_1_0_GA_CPmodulespluginsapachesrcmainjavaorgrhqpluginsapacheApacheServerComponentjava">rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java</a></li> <li><a href="#rhqbranchesRHQ_1_1_0_GA_CPmodulespluginsapachesrcmainjavaorgrhqpluginsapacheApacheServerDiscoveryComponentjava">rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerDiscoveryComponent.java</a></li> <li><a href="#rhqbranchesRHQ_1_1_0_GA_CPmodulespluginsapachesrcmainresourcesMETAINFrhqpluginxml">rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/resources/META-INF/rhq-plugin.xml</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqbranchesRHQ_1_1_0_GA_CPmodulespluginsapachesrcmainjavaorgrhqpluginsapacheApacheServerComponentjava"></a> <div class="modfile"><h4>Modified: rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java (5219 => 5220)</h4> <pre class="diff"> <span class="info">--- rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java 2009-09-28 17:14:13 UTC (rev 5219) +++ rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java 2009-09-28 23:03:54 UTC (rev 5220) </span><span class="lines">@@ -70,6 +70,7 @@ </span><span class="cx"> public static final String PLUGIN_CONFIG_PROP_EXECUTABLE_PATH = "executablePath"; public static final String PLUGIN_CONFIG_PROP_CONTROL_SCRIPT_PATH = "controlScriptPath"; public static final String PLUGIN_CONFIG_PROP_URL = "url"; </span><span class="add">+ public static final String PLUGIN_CONFIG_PROP_HTTPD_CONF = "configFile"; </span><span class="cx"> public static final String PLUGIN_CONFIG_PROP_SNMP_AGENT_HOST = "snmpAgentHost"; public static final String PLUGIN_CONFIG_PROP_SNMP_AGENT_PORT = "snmpAgentPort"; </span></pre></div> <a id="rhqbranchesRHQ_1_1_0_GA_CPmodulespluginsapachesrcmainjavaorgrhqpluginsapacheApacheServerDiscoveryComponentjava"></a> <div class="modfile"><h4>Modified: rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerDiscoveryComponent.java (5219 => 5220)</h4> <pre class="diff"> <span class="info">--- rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerDiscoveryComponent.java 2009-09-28 17:14:13 UTC (rev 5219) +++ rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerDiscoveryComponent.java 2009-09-28 23:03:54 UTC (rev 5220) </span><span class="lines">@@ -19,6 +19,7 @@ </span><span class="cx"> package org.rhq.plugins.apache; import java.io.File; </span><span class="add">+import java.io.IOException; </span><span class="cx"> import java.util.HashSet; import java.util.List; import java.util.Set; </span><span class="lines">@@ -88,7 +89,13 @@ </span><span class="cx"> log.error("Unable to determine server root for Apache process: " + process.getProcessInfo()); continue; } </span><span class="rem">- </span><span class="add">+ + File serverConfigFile = getServerConfigFile(binaryInfo, process.getProcessInfo(), serverRoot); + if (serverConfigFile == null) { + log.error("Unable to determine server config file for Apache process: " + process.getProcessInfo()); + continue; + } + </span><span class="cx"> Configuration pluginConfig = discoveryContext.getDefaultPluginConfiguration(); PropertySimple executablePathProp = new PropertySimple( </span><span class="lines">@@ -110,15 +117,9 @@ </span><span class="cx"> // Process any manually added resources (NOTE: the PC will never actually pass in more than one)... List<Configuration> pluginConfigs = discoveryContext.getPluginConfigurations(); </span><span class="rem">- for (Configuration pluginConfig : pluginConfigs) { - String serverRoot = ApacheServerComponent.getRequiredPropertyValue(pluginConfig, - ApacheServerComponent.PLUGIN_CONFIG_PROP_SERVER_ROOT); - if (!new File(serverRoot).isDirectory()) { - throw new InvalidPluginConfigurationException("'" + serverRoot - + "' is not a directory. Please make sure the '" - + ApacheServerComponent.PLUGIN_CONFIG_PROP_SERVER_ROOT + "' connection property is set correctly."); - } - </span><span class="add">+ for (Configuration pluginConfig : pluginConfigs) { + validateServerRootAndServerConfigFile(pluginConfig); + </span><span class="cx"> String executablePath = pluginConfig .getSimpleValue(ApacheServerComponent.PLUGIN_CONFIG_PROP_EXECUTABLE_PATH, ApacheServerComponent.DEFAULT_EXECUTABLE_PATH); </span><span class="lines">@@ -155,18 +156,14 @@ </span><span class="cx"> private DiscoveredResourceDetails createResourceDetails(ResourceDiscoveryContext discoveryContext, Configuration pluginConfig, ProcessInfo processInfo, ApacheBinaryInfo binaryInfo) throws Exception { </span><span class="rem">- String serverRoot = pluginConfig.getSimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_SERVER_ROOT) - .getStringValue(); - String key = FileUtils.getCanonicalPath(serverRoot); </span><span class="add">+ String httpdConf = pluginConfig.getSimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_HTTPD_CONF).getStringValue(); </span><span class="cx"> String version = binaryInfo.getVersion(); String hostname = discoveryContext.getSystemInformation().getHostname(); </span><span class="rem">- String name = hostname + " Apache " + version + " (" + serverRoot + File.separator + ")"; </span><span class="add">+ String name = hostname + " Apache " + version + " (" + httpdConf + ")"; </span><span class="cx"> DiscoveredResourceDetails resourceDetails = new DiscoveredResourceDetails(discoveryContext.getResourceType(), </span><span class="rem">- key, name, version, PRODUCT_DESCRIPTION, pluginConfig, processInfo); - </span><span class="add">+ httpdConf, name, version, PRODUCT_DESCRIPTION, pluginConfig, processInfo); </span><span class="cx"> log.debug("Apache Server resource details created: " + resourceDetails); </span><span class="rem">- </span><span class="cx"> return resourceDetails; } </span><span class="lines">@@ -216,23 +213,10 @@ </span><span class="cx"> } @Nullable </span><span class="rem">- private String getServerRoot(@NotNull - ApacheBinaryInfo binaryInfo, @NotNull - ProcessInfo processInfo) { - String root = null; </span><span class="add">+ private String getServerRoot(@NotNull ApacheBinaryInfo binaryInfo, @NotNull ProcessInfo processInfo) { </span><span class="cx"> String[] cmdLine = processInfo.getCommandLine(); </span><span class="rem">- for (int i = 1; i < cmdLine.length; i++) { - String arg = cmdLine[i]; - if (arg.startsWith("-d")) { - root = arg.substring(2, arg.length()); - if (root.length() == 0) { - root = cmdLine[i + 1]; - } </span><span class="add">+ String root = getCommandLineOption(cmdLine, "-d"); </span><span class="cx"> </span><span class="rem">- break; - } - } - </span><span class="cx"> if (root == null) { root = binaryInfo.getRoot(); } </span><span class="lines">@@ -244,6 +228,50 @@ </span><span class="cx"> return root; } </span><span class="add">+ @Nullable + private File getServerConfigFile(ApacheBinaryInfo binaryInfo, ProcessInfo processInfo, String serverRoot) { + String[] cmdLine = processInfo.getCommandLine(); + // First see if -f was specified on the httpd command line. + String serverConfigFile = getCommandLineOption(cmdLine, "-f"); + + // If not, extract the path from the httpd binary. + if (serverConfigFile == null) { + serverConfigFile = binaryInfo.getCtl(); + } + + if (serverConfigFile == null) { + // We have failed to determine the config file path :( + return null; + } + + // If the path is relative, convert it to an absolute path, resolving it relative to the server root dir. + File file = new File(serverConfigFile); + if (!file.isAbsolute()) { + file = new File(serverRoot, serverConfigFile); + serverConfigFile = file.getPath(); + } + + // And now canonicalize the path, but using our own getCanonicalPath() method, which preserves symlinks. + serverConfigFile = FileUtils.getCanonicalPath(serverConfigFile); + + return new File(serverConfigFile); + } + + private String getCommandLineOption(String[] cmdLine, String option) { + String root = null; + for (int i = 1; i < cmdLine.length; i++) { + String arg = cmdLine[i]; + if (arg.startsWith(option)) { + root = arg.substring(2, arg.length()); + if (root.length() == 0) { + root = cmdLine[i + 1]; + } + break; + } + } + return root; + } + </span><span class="cx"> private static String getExecutableName(ProcessScanResult processScanResult) { String query = processScanResult.getProcessScan().getQuery().toLowerCase(); String executableName; </span><span class="lines">@@ -260,4 +288,33 @@ </span><span class="cx"> } return executableName; } </span><span class="add">+ + private static void validateServerRootAndServerConfigFile(Configuration pluginConfig) { + String serverRoot = pluginConfig.getSimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_SERVER_ROOT).getStringValue(); + File serverRootFile; + try { + serverRootFile = new File(serverRoot).getCanonicalFile(); // this will resolve symlinks + } + catch (IOException e) { + serverRootFile = null; + } + if (serverRootFile == null || !serverRootFile.isDirectory()) { + throw new InvalidPluginConfigurationException("'" + serverRoot + + "' does not exist or is not a directory. Please make sure the '" + + ApacheServerComponent.PLUGIN_CONFIG_PROP_SERVER_ROOT + "' connection property is set correctly."); + } + String httpdConf = pluginConfig.getSimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_HTTPD_CONF).getStringValue(); + File httpdConfFile; + try { + httpdConfFile = new File(httpdConf).getCanonicalFile(); // this will resolve symlinks + } + catch (IOException e) { + httpdConfFile = null; + } + if (httpdConfFile == null || !httpdConfFile.isFile()) { + throw new InvalidPluginConfigurationException("'" + httpdConf + + "' does not exist or is not a regular file. Please make sure the '" + + ApacheServerComponent.PLUGIN_CONFIG_PROP_HTTPD_CONF + "' connection property is set correctly."); + } + } </span><span class="cx"> } \ No newline at end of file </span></pre></div> <a id="rhqbranchesRHQ_1_1_0_GA_CPmodulespluginsapachesrcmainresourcesMETAINFrhqpluginxml"></a> <div class="modfile"><h4>Modified: rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/resources/META-INF/rhq-plugin.xml (5219 => 5220)</h4> <pre class="diff"> <span class="info">--- rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/resources/META-INF/rhq-plugin.xml 2009-09-28 17:14:13 UTC (rev 5219) +++ rhq/branches/RHQ_1_1_0_GA_CP/modules/plugins/apache/src/main/resources/META-INF/rhq-plugin.xml 2009-09-28 23:03:54 UTC (rev 5220) </span><span class="lines">@@ -17,15 +17,18 @@ </span><span class="cx"> <!-- Defaults: type: string required: true </span><span class="rem">- readOnly: true </span><span class="add">+ readOnly: false </span><span class="cx"> activationPolicy: immediate --> </span><span class="rem">- <c:simple-property name="serverRoot" </span><span class="add">+ <c:simple-property name="serverRoot" required="true" </span><span class="cx"> description="the absolute path of the Apache server root directory"/> <c:simple-property name="executablePath" required="false" description="the path to the Apache executable - if the path is not absolute, it will be resolved relative to the server root directory; if unset, default value is 'bin/httpd' on UNIX or 'bin\Apache.exe' on Windows"/> <c:simple-property name="controlScriptPath" required="false" </span><span class="rem">- description="the path to the Apache control script - if the path is not absolute, it will be resolved relative to the server root directory; if unset, default will be 'bin/apachectl' on UNIX or the Apache executable on Windows"/> </span><span class="add">+ description="the path to the Apache control script - if the path is not absolute, it will be resolved relative to the server root directory; if unset, default will be 'bin/apachectl' on UNIX or the Apache executable on Windows"/> + <!-- TODO need to add a comment about the file location on Win* --> + <c:simple-property name="configFile" required="true" readOnly="true" + description="the path to the httpd.conf file - if the path is not absolute, it will be resolved relative to the server root directory; if unset, default will be 'conf/httpd.conf' on UNIX"/> </span><span class="cx"> <c:simple-property name="url" displayName="URL" required="false" description="the http or https URL that will be used to check availability for this Apache server; if not set, availablity will be determined based on whether plugin can connect to the Apache server's SNMP agent"/> <c:simple-property name="snmpAgentHost" displayName="SNMP Agent Host" default="127.0.0.1" </span> </pre> </div> </div> </body> </html> |