From: <gla...@hy...> - 2010-05-03 21:08:41
|
Author: glaullon Date: 2010-05-03 14:08:31 -0700 (Mon, 03 May 2010) New Revision: 14563 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14563 Added: trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DB2JDBCProductPlugin.java Modified: trunk/plugins/db2jdbc/ trunk/plugins/db2jdbc/etc/hq-plugin.xml trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DataBaseServerDetector.java trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DefaultServerDetector.java trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/Measurement.java Log: [HHQ-3947] Cannot configure DB2 configuration properties: No suitable driver Property changes on: trunk/plugins/db2jdbc ___________________________________________________________________ Name: svn:ignore - build-lib manifest.mf build db2-jdbc-plugin.jar bin nbproject build.xml hq.properties test + db2jdbc-plugin.jar build-lib manifest.mf test db2-jdbc-plugin.jar build.xml nbproject bin hq.properties build Modified: trunk/plugins/db2jdbc/etc/hq-plugin.xml =================================================================== --- trunk/plugins/db2jdbc/etc/hq-plugin.xml 2010-05-03 07:53:47 UTC (rev 14562) +++ trunk/plugins/db2jdbc/etc/hq-plugin.xml 2010-05-03 21:08:31 UTC (rev 14563) @@ -23,7 +23,7 @@ USA. --> -<plugin name="db2jdbc" > +<plugin name="db2jdbc" class="DB2JDBCProductPlugin"> <property name="template-config" value="database=%db2.jdbc.database%,jdbcUser=%db2.jdbc.user%,jdbcPassword=%db2.jdbc.password%,jdbcUrl=jdbc:db2://%db2.jdbc.hostname%:%db2.jdbc.port%/%db2.jdbc.database%"/> Added: trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DB2JDBCProductPlugin.java =================================================================== --- trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DB2JDBCProductPlugin.java (rev 0) +++ trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DB2JDBCProductPlugin.java 2010-05-03 21:08:31 UTC (rev 14563) @@ -0,0 +1,69 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.hyperic.hq.plugin.db2jdbc; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hyperic.hq.product.ProductPlugin; +import org.hyperic.hq.product.ProductPluginManager; + +public class DB2JDBCProductPlugin extends ProductPlugin { + + public static String DB2LS; + public static List ENTRY_TYPES; + public static String LIST_DATABASE; + public static String INSTALL_PATH; + public static String CLASSPATH; + private static final String PROP_DB2LS = "db2.jdbc.db2ls"; + private static final String PROP_ENTRY_TYPES = "db2.jdbc.entry_types"; + private static final String PROP_LIST_DATABASE = "db2.jdbc.list_database"; + private static final String PROP_INSTALL_PATH = "db2.jdbc.installpath"; + private static final String PROP_CLASSPATH = "db2.jdbc.classpath"; + private final static Log log = LogFactory.getLog(DB2JDBCProductPlugin.class); + + public String[] getClassPath(ProductPluginManager manager) { + String[] res = super.getClassPath(manager); + + DB2LS = manager.getProperties().getProperty(PROP_DB2LS, "db2ls"); + + String et = manager.getProperties().getProperty(PROP_ENTRY_TYPES, "*"); + ENTRY_TYPES = Arrays.asList(et.toLowerCase().split(",")); + + LIST_DATABASE = manager.getProperties().getProperty(PROP_LIST_DATABASE); + INSTALL_PATH = manager.getProperties().getProperty(PROP_INSTALL_PATH); + CLASSPATH = manager.getProperties().getProperty(PROP_CLASSPATH); + + if (log.isDebugEnabled()) { + log.debug("[getServerResources] " + PROP_DB2LS + "=" + DB2LS + ", " + + PROP_ENTRY_TYPES + "=" + ENTRY_TYPES + ", " + + PROP_LIST_DATABASE + "=" + LIST_DATABASE + ", " + + PROP_INSTALL_PATH + "=" + INSTALL_PATH + ", " + + PROP_CLASSPATH + "=" + CLASSPATH); + } + + if (CLASSPATH != null) { + res = CLASSPATH.split(","); + } else { + List paths = new ArrayList(); + if (INSTALL_PATH != null) { + paths.add(INSTALL_PATH); + } else { + paths.addAll(DefaultServerDetector.getInstallPaths(manager.getProperties(), ".*")); + } + + if (paths.size() > 0) { + File jar = new File((String) paths.get(0), "java/db2jcc.jar"); + if (jar.exists()) { + res = new String[]{jar.getAbsolutePath()}; + } + } + } + return res; + } +} Modified: trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DataBaseServerDetector.java =================================================================== --- trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DataBaseServerDetector.java 2010-05-03 07:53:47 UTC (rev 14562) +++ trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DataBaseServerDetector.java 2010-05-03 21:08:31 UTC (rev 14563) @@ -226,7 +226,7 @@ PreparedStatement ps = null; try { getLog().debug("getList props=" + props); - conn = getConnection(props); + conn = getConnection(props.toProperties()); ps = conn.prepareStatement(query); ResultSet rs = ps.executeQuery(); while (rs.next()) { @@ -234,7 +234,7 @@ } getLog().debug("getList '" + query + "' => res= " + res); } catch (Exception ex) { - getLog().debug("getList '" + query + "' => " + ex.getMessage()); + getLog().debug("getList '" + query + "' => " + ex.getMessage(),ex); } finally { try { if (ps != null) { Modified: trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DefaultServerDetector.java =================================================================== --- trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DefaultServerDetector.java 2010-05-03 07:53:47 UTC (rev 14562) +++ trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/DefaultServerDetector.java 2010-05-03 21:08:31 UTC (rev 14563) @@ -22,7 +22,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */ - package org.hyperic.hq.plugin.db2jdbc; import java.io.BufferedReader; @@ -33,12 +32,13 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Iterator; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.hyperic.hq.product.AutoServerDetector; import org.hyperic.hq.product.PluginException; import org.hyperic.hq.product.PluginManager; @@ -53,111 +53,107 @@ */ public abstract class DefaultServerDetector extends ServerDetector implements AutoServerDetector { - private Pattern regExpInstall = Pattern.compile("([^ ]*) *(\\d*\\.\\d*\\.\\d*\\.\\d*) *([^ ]*)"); - private boolean ISWin = false; - private String db2ls; - private List entry_types; - private String list_database; + private final static Pattern regExpInstall = Pattern.compile("([^ ]*) *(\\d*\\.\\d*\\.\\d*\\.\\d*) *([^ ]*)"); + private static boolean ISWin = false; + private final static Log log = LogFactory.getLog(DefaultServerDetector.class); + public void init(PluginManager manager) throws PluginException { + super.init(manager); + ISWin = "win32".equalsIgnoreCase(manager.getProperties().getProperty("platform.type")); + } + public List getServerResources(ConfigResponse conf) throws PluginException { - boolean debug = getLog().isDebugEnabled(); - + boolean debug = log.isDebugEnabled(); + if (debug) { - getLog().debug("[getServerResources] conf=" + conf); + log.debug("[getServerResources] conf=" + conf); } - Pattern regExpVersion = Pattern.compile(getTypeInfo().getVersion().replaceAll("[X|x]", "\\d*")); + + Iterator paths = getInstallPaths(conf.toProperties(), getTypeInfo().getVersion()).iterator(); List res = new ArrayList(); + while (paths.hasNext()) { + String path = (String) paths.next(); + res.addAll(createServers(path)); + } + return res; + } - ISWin = "win32".equalsIgnoreCase(conf.getValue("platform.type")); + public static List getInstallPaths(Properties conf, String versionExp) { + List res = new ArrayList(); + Pattern regExpVersion = Pattern.compile(versionExp.replaceAll("[X|x]", "\\d*")); + boolean debug = log.isDebugEnabled(); + ISWin = "win32".equalsIgnoreCase(conf.getProperty("platform.type")); if (ISWin) { try { - ISWin = true; RegistryKey key = RegistryKey.LocalMachine.openSubKey("SOFTWARE\\IBM\\DB2\\InstalledCopies"); String instances[] = key.getSubKeyNames(); key.close(); - for (int n=0;n<instances.length;n++) { + for (int n = 0; n < instances.length; n++) { key = RegistryKey.LocalMachine.openSubKey("SOFTWARE\\IBM\\DB2\\InstalledCopies\\" + instances[n] + "\\CurrentVersion"); String version = key.getStringValue("Version") + "." + key.getStringValue("Release") + "." + key.getStringValue("Modification") + "." + key.getStringValue("Fix Level"); key.close(); if (debug) { - getLog().debug(instances[n] + "-->" + version); + log.debug(instances[n] + "-->" + version); } if (regExpVersion.matcher(version).find()) { key = RegistryKey.LocalMachine.openSubKey("SOFTWARE\\IBM\\DB2\\InstalledCopies\\" + instances[n]); String path = key.getStringValue("DB2 Path Name"); key.close(); - res.addAll(createServers(path.trim())); + res.add(path.trim()); } else { if (debug) { - getLog().debug("[getServerResources] bad version: '" + instances[n] + " " + version + "'"); + log.debug("[getServerResources] bad version: '" + instances[n] + " " + version + "'"); } } } } catch (Win32Exception ex) { if (debug) { - getLog().debug("[getServerResources] error: " + ex.getMessage(), ex); + log.debug("[getServerResources] error: " + ex.getMessage(), ex); } } } else { try { - Process cmd = Runtime.getRuntime().exec(db2ls); + Process cmd = Runtime.getRuntime().exec(DB2JDBCProductPlugin.DB2LS); cmd.waitFor(); String sal = inputStreamAsString(cmd.getInputStream()); if (debug) { - getLog().debug("[getServerResources] sal=" + sal); + log.debug("[getServerResources] sal=" + sal); } String[] installs = sal.split("\n"); - for (int n=0;n<installs.length;n++) { + for (int n = 0; n < installs.length; n++) { Matcher m = regExpInstall.matcher(installs[n]); if (m.find()) { if (regExpVersion.matcher(m.group(2)).find()) { if (debug) { - getLog().debug("[getServerResources] found: '" + m.group() + "'"); + log.debug("[getServerResources] found: '" + m.group() + "'"); } - res.addAll(createServers(m.group(1))); + res.add(m.group(1)); } else { if (debug) { - getLog().debug("[getServerResources] bad version: '" + m.group() + "'"); + log.debug("[getServerResources] bad version: '" + m.group() + "'"); } } } } } catch (Exception ex) { if (debug) { - getLog().debug("[getServerResources] error: " + ex.getMessage(), ex); + log.debug("[getServerResources] error: " + ex.getMessage(), ex); } } } return res; } - public void init(PluginManager manager) throws PluginException { - db2ls = manager.getProperties().getProperty("db2.jdbc.db2ls", "db2ls"); - - String et = manager.getProperties().getProperty("db2.jdbc.entry_types", "*"); - entry_types = Arrays.asList(et.toLowerCase().split(",")); - - list_database = manager.getProperties().getProperty("db2.jdbc.list_database"); - - if (getLog().isDebugEnabled()) { - getLog().debug("[getServerResources] db2.jdbc.db2ls=" + db2ls); - getLog().debug("[getServerResources] db2.jdbc.entry_types=" + entry_types); - getLog().debug("[getServerResources] db2.jdbc.list_database=" + list_database); - } - - super.init(manager); - } - protected boolean checkEntryTypes(String type) { - boolean res = entry_types.contains("*") || entry_types.contains(type.toLowerCase()); - if (getLog().isDebugEnabled()) { - getLog().debug("[checkEntryTypes] type='" + type + "' res='" + res + "'"); + boolean res = DB2JDBCProductPlugin.ENTRY_TYPES.contains("*") || DB2JDBCProductPlugin.ENTRY_TYPES.contains(type.toLowerCase()); + if (log.isDebugEnabled()) { + log.debug("[checkEntryTypes] type='" + type + "' res='" + res + "'"); } return res; } - protected String getListDatabaseCommand(){ - return list_database; + protected String getListDatabaseCommand() { + return DB2JDBCProductPlugin.LIST_DATABASE; } protected abstract List createServers(String installPath); @@ -180,13 +176,13 @@ return sb.toString(); } - static final Connection getConnection(ConfigResponse props) throws SQLException, ClassNotFoundException { + static final Connection getConnection(Properties props) throws SQLException, ClassNotFoundException { Class.forName("com.ibm.db2.jcc.DB2Driver"); - String url = "jdbc:db2://" + props.getValue("db2.jdbc.hostname") + ":" - + props.getValue("db2.jdbc.port") + "/" - + props.getValue("db2.jdbc.database"); - String user = props.getValue("db2.jdbc.user"); - String pass = props.getValue("db2.jdbc.password"); + String url = "jdbc:db2://" + props.getProperty("db2.jdbc.hostname") + ":" + + props.getProperty("db2.jdbc.port") + "/" + + props.getProperty("db2.jdbc.database"); + String user = props.getProperty("db2.jdbc.user"); + String pass = props.getProperty("db2.jdbc.password"); return DriverManager.getConnection(url, user, pass); } } Modified: trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/Measurement.java =================================================================== --- trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/Measurement.java 2010-05-03 07:53:47 UTC (rev 14562) +++ trunk/plugins/db2jdbc/src/org/hyperic/hq/plugin/db2jdbc/Measurement.java 2010-05-03 21:08:31 UTC (rev 14563) @@ -22,7 +22,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */ - package org.hyperic.hq.plugin.db2jdbc; import java.sql.Connection; @@ -33,7 +32,6 @@ import java.sql.Timestamp; import java.sql.Types; import java.util.HashMap; -import java.util.Hashtable; import java.util.Map; import org.hyperic.hq.product.Metric; import org.hyperic.hq.product.MetricNotFoundException; @@ -47,19 +45,10 @@ private static final String JDBC_DRIVER = "com.ibm.db2.jcc.DB2Driver"; private static final String KEY = "key"; - private static final String EXEC_TIME_ATTR = "QueryExecTime"; - private static final Hashtable cache = new Hashtable(); protected String getQuery(Metric metric) { if (getLog().isDebugEnabled()) { - getLog().debug("*******************"); - getLog().debug("** MT " + metric); - getLog().debug("** DN " + metric.getDomainName()); - getLog().debug("** OP " + metric.getObjectProperties()); - getLog().debug("** ON " + metric.getObjectName()); - getLog().debug("** AT " + metric.getAttributeName()); - getLog().debug("** PR " + metric.getProperties()); - getLog().debug("*******************"); + getLog().debug("[getQuery] metric=" + metric); } String sql = metric.getObjectProperties().getProperty("sql"); if (sql == null) { |