chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r761161 - in /hadoop/chukwa/trunk/src: java/org/apache/hadoop/chukwa/database/ java/org/apache/hadoop/chukwa/extraction/database/ java/org/apache/hadoop/chukwa/extraction/engine/datasource/database/ java/org/apache/hadoop/chukwa/hicc/ java/...
Date Thu, 02 Apr 2009 04:18:52 GMT
Author: eyang
Date: Thu Apr  2 04:18:51 2009
New Revision: 761161

URL: http://svn.apache.org/viewvc?rev=761161&view=rev
Log:
CHUKWA-86. Improved compatability layer for JDBC driver. (Cheng Zhang via Eric Yang)

Added:
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DriverManagerUtil.java
    hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/util/DriverManagerUtilTest.java
Modified:
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/database/MetricsAggregation.java
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/database/MetricDataLoader.java
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/database/DatabaseDS.java
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/mdl/TorqueInfoProcessor.java
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DatabaseWriter.java
    hadoop/chukwa/trunk/src/web/hicc/jsp/events-xml.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/get_user_list.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job_list.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/host_selector.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/single-series-chart-javascript.jsp

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/database/MetricsAggregation.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/database/MetricsAggregation.java?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/database/MetricsAggregation.java
(original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/database/MetricsAggregation.java
Thu Apr  2 04:18:51 2009
@@ -40,8 +40,7 @@
     try {
       // The newInstance() call is a work around for some
       // broken Java implementations
-      String jdbcDriver = System.getenv("JDBC_DRIVER");
-      Class.forName(jdbcDriver).newInstance();
+      org.apache.hadoop.chukwa.util.DriverManagerUtil.loadDriver().newInstance();
       log.info("Initialized JDBC URL: " + jdbc_url);
     } catch (Exception ex) {
       // handle the error
@@ -49,7 +48,7 @@
       log.error(ex, ex);
     }
     try {
-      conn = DriverManager.getConnection(jdbc_url);
+      conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc_url);
     } catch (SQLException ex) {
       ex.printStackTrace();
       log.error(ex, ex);

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/database/MetricDataLoader.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/database/MetricDataLoader.java?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/database/MetricDataLoader.java
(original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/database/MetricDataLoader.java
Thu Apr  2 04:18:51 2009
@@ -116,15 +116,14 @@
     try {
       // The newInstance() call is a work around for some
       // broken Java implementations
-      String jdbcDriver = System.getenv("JDBC_DRIVER");
-      Class.forName(jdbcDriver).newInstance();
+      org.apache.hadoop.chukwa.util.DriverManagerUtil.loadDriver().newInstance();
       log.debug("Initialized JDBC URL: " + jdbc_url);
     } catch (Exception ex) {
       // handle the error
       log.error(ex, ex);
     }
     try {
-      conn = DriverManager.getConnection(jdbc_url);
+      conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc_url);
       HashMap<String, String> dbNames = mdlConfig.startWith("report.db.name.");
       Iterator<String> ki = dbNames.keySet().iterator();
       dbSchema = new HashMap<String, HashMap<String, Integer>>();

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/database/DatabaseDS.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/database/DatabaseDS.java?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/database/DatabaseDS.java
(original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/database/DatabaseDS.java
Thu Apr  2 04:18:51 2009
@@ -73,7 +73,7 @@
       // ClusterConfig cc = new ClusterConfig();
       String jdbc = ""; // cc.getURL(cluster);
 
-      Connection conn = DriverManager.getConnection(jdbc);
+      Connection conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc);
 
       stmt = conn.createStatement();
       String query = "";

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java Thu Apr
 2 04:18:51 2009
@@ -47,8 +47,7 @@
     try {
       // The newInstance() call is a work around for some
       // broken Java implementations
-      String jdbcDriver = System.getenv("JDBC_DRIVER");
-      Class.forName(jdbcDriver).newInstance();
+      org.apache.hadoop.chukwa.util.DriverManagerUtil.loadDriver().newInstance();
     } catch (Exception ex) {
       // handle the error
     }
@@ -61,7 +60,7 @@
     double max = 0.0;
     int labelsCount = 0;
     try {
-      conn = DriverManager.getConnection(jdbc);
+      conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc);
       stmt = conn.createStatement();
       // rs = stmt.executeQuery(query);
       if (stmt.execute(query)) {

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/mdl/TorqueInfoProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/mdl/TorqueInfoProcessor.java?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/mdl/TorqueInfoProcessor.java
(original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/mdl/TorqueInfoProcessor.java
Thu Apr  2 04:18:51 2009
@@ -422,7 +422,7 @@
 
     Iterator<String> hodIdsIt = hodIds.iterator();
     while (hodIdsIt.hasNext()) {
-      String hodId = (String) hodIdsIt.next();
+      String hodId = hodIdsIt.next();
       TreeMap<String, String> aJobData = currentHodJobs.get(hodId);
       String status = aJobData.get("status");
       String process = aJobData.get("process");

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DatabaseWriter.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DatabaseWriter.java?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DatabaseWriter.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DatabaseWriter.java Thu Apr
 2 04:18:51 2009
@@ -47,13 +47,13 @@
     try {
       // The newInstance() call is a work around for some
       // broken Java implementations
-      Class.forName("com.mysql.jdbc.Driver").newInstance();
+      DriverManagerUtil.loadDriver().newInstance();
     } catch (Exception ex) {
       // handle the error
       log.error(ex, ex);
     }
     try {
-      conn = DriverManager.getConnection(jdbc_url);
+      conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc_url);
       log.debug("Initialized JDBC URL: " + jdbc_url);
     } catch (SQLException ex) {
       log.error(ex, ex);
@@ -66,13 +66,13 @@
     try {
       // The newInstance() call is a work around for some
       // broken Java implementations
-      Class.forName("com.mysql.jdbc.Driver").newInstance();
+      DriverManagerUtil.loadDriver().newInstance();
     } catch (Exception ex) {
       // handle the error
       log.error(ex, ex);
     }
     try {
-      conn = DriverManager.getConnection(jdbc_url);
+      conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc_url);
       log.debug("Initialized JDBC URL: " + jdbc_url);
     } catch (SQLException ex) {
       log.error(ex, ex);
@@ -92,13 +92,13 @@
     try {
       // The newInstance() call is a work around for some
       // broken Java implementations
-      Class.forName("com.mysql.jdbc.Driver").newInstance();
+      DriverManagerUtil.loadDriver().newInstance();
     } catch (Exception ex) {
       // handle the error
       log.error(ex, ex);
     }
     try {
-      conn = DriverManager.getConnection(jdbc_url);
+      conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc_url);
       log.debug("Initialized JDBC URL: " + jdbc_url);
     } catch (SQLException ex) {
       log.error(ex, ex);

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DriverManagerUtil.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DriverManagerUtil.java?rev=761161&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DriverManagerUtil.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/DriverManagerUtil.java Thu
Apr  2 04:18:51 2009
@@ -0,0 +1,58 @@
+package org.apache.hadoop.chukwa.util;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Properties;
+
+public class DriverManagerUtil {
+  
+  @SuppressWarnings("unchecked")
+  public static Class loadDriver() throws ClassNotFoundException {
+    String jdbcDriver = System.getenv("JDBC_DRIVER");
+    if(jdbcDriver == null) {
+      jdbcDriver = "com.mysql.jdbc.Driver";
+    }
+    return Class.forName(jdbcDriver);
+  }
+  
+  public static Connection getConnection(String url) throws SQLException {
+    ConnectionInfo info = new ConnectionInfo(url);
+    return DriverManager.getConnection(info.getUri(), info.getProperties());
+  }
+  
+  public static class ConnectionInfo {
+    private Properties properties = new Properties();
+    private String uri = null;
+    
+    public ConnectionInfo(String url) {
+      int pos = url.indexOf('?');
+      if(pos == -1) {
+        uri = url;
+      } else {
+        uri = url.substring(0, pos);
+        String[] paras = url.substring(pos + 1).split("&");
+        for(String s : paras) {
+          if(s==null || s.length()==0) {
+            continue;
+          }
+          String[] kv = s.split("=");
+          if(kv.length > 1) {
+            properties.put(kv[0], kv[1]);
+          }
+          else {
+            properties.put(kv[0], "");
+          }
+        }
+      }
+    }
+
+    public Properties getProperties() {
+      return properties;
+    }
+
+    public String getUri() {
+      return uri;
+    }
+  }
+}

Added: hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/util/DriverManagerUtilTest.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/util/DriverManagerUtilTest.java?rev=761161&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/util/DriverManagerUtilTest.java
(added)
+++ hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/util/DriverManagerUtilTest.java
Thu Apr  2 04:18:51 2009
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.chukwa.util;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.apache.hadoop.chukwa.util.DriverManagerUtil.ConnectionInfo;
+
+import junit.framework.TestCase;
+
+public class DriverManagerUtilTest extends TestCase {
+
+  public void testLoadDriver() throws ClassNotFoundException {
+    Class<?> clazz = DriverManagerUtil.loadDriver();
+    System.out.println(clazz);
+  }
+
+  public void testGetConnectionInfo() {
+    {
+      String url = "jdbc:mysql://localhost:3306/demo";
+      ConnectionInfo ci = new ConnectionInfo(url);
+      assertEquals("jdbc:mysql://localhost:3306/demo", ci.getUri());
+      assertEquals(0, ci.getProperties().size());
+    }
+    
+    {
+      String url = "jdbc:mysql://localhost:3306/demo?user=example";
+      ConnectionInfo ci = new ConnectionInfo(url);
+      assertEquals("jdbc:mysql://localhost:3306/demo", ci.getUri());
+      assertEquals(1, ci.getProperties().size());
+      assertEquals("example", ci.getProperties().get("user"));
+    }
+    
+    {
+      String url = "jdbc:mysql://localhost:3306/demo?user=example&";
+      ConnectionInfo ci = new ConnectionInfo(url);
+      assertEquals("jdbc:mysql://localhost:3306/demo", ci.getUri());
+      assertEquals(1, ci.getProperties().size());
+      assertEquals("example", ci.getProperties().get("user"));
+    }
+    
+    {
+      String url = "jdbc:mysql://localhost:3306/demo?user=example&pwd";
+      ConnectionInfo ci = new ConnectionInfo(url);
+      assertEquals("jdbc:mysql://localhost:3306/demo", ci.getUri());
+      assertEquals(2, ci.getProperties().size());
+      assertEquals("example", ci.getProperties().get("user"));
+      assertEquals("", ci.getProperties().get("pwd"));
+    }
+    
+    {
+      String url = "jdbc:mysql://localhost:3306/demo?user=example&pwd=";
+      ConnectionInfo ci = new ConnectionInfo(url);
+      assertEquals("jdbc:mysql://localhost:3306/demo", ci.getUri());
+      assertEquals(2, ci.getProperties().size());
+      assertEquals("example", ci.getProperties().get("user"));
+      assertEquals("", ci.getProperties().get("pwd"));
+    }
+    
+    {
+      String url = "jdbc:mysql://localhost:3306/demo?user=example&pwd=ppppp";
+      ConnectionInfo ci = new ConnectionInfo(url);
+      assertEquals("jdbc:mysql://localhost:3306/demo", ci.getUri());
+      assertEquals(2, ci.getProperties().size());
+      assertEquals("example", ci.getProperties().get("user"));
+      assertEquals("ppppp", ci.getProperties().get("pwd"));
+    }
+  }
+
+  public void testGetConnection() throws ClassNotFoundException, SQLException, InstantiationException,
IllegalAccessException {
+    if(false) {
+      DriverManagerUtil.loadDriver().newInstance();
+      String url = "jdbc:mysql://localhost:3306/test?user=root&pwd=";
+      Connection conn = DriverManagerUtil.getConnection(url);
+    }
+  } 
+}

Modified: hadoop/chukwa/trunk/src/web/hicc/jsp/events-xml.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/events-xml.jsp?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/events-xml.jsp (original)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/events-xml.jsp Thu Apr  2 04:18:51 2009
@@ -41,7 +41,7 @@
                ClusterConfig cc = new ClusterConfig();
                String jdbc = cc.getURL(cluster);
                try {
-                   conn = DriverManager.getConnection(jdbc);
+                   conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc);
                    stmt = conn.createStatement();
                    String query = "";
                    query = "select * from "+database[q]+" where "+dateclause+";";

Modified: hadoop/chukwa/trunk/src/web/hicc/jsp/get_user_list.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/get_user_list.jsp?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/get_user_list.jsp (original)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/get_user_list.jsp Thu Apr  2 04:18:51 2009
@@ -34,7 +34,7 @@
        ClusterConfig cc = new ClusterConfig();
        String jdbc = cc.getURL(cluster);
        try {
-           conn = DriverManager.getConnection(jdbc);
+           conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc);
            stmt = conn.createStatement();
            String query = "select distinct UserID from HodJob order by UserID";
            if (stmt.execute(query)) {

Modified: hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job.jsp?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job.jsp (original)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job.jsp Thu Apr  2 04:18:51 2009
@@ -52,7 +52,7 @@
        ClusterConfig cc = new ClusterConfig();
        String jdbc = cc.getURL(cluster);
        try {
-           conn = DriverManager.getConnection(jdbc);
+           conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc);
            stmt = conn.createStatement();
            String query = "";
            String HodID = (String)session.getAttribute("HodID");

Modified: hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job_list.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job_list.jsp?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job_list.jsp (original)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/hod_job_list.jsp Thu Apr  2 04:18:51 2009
@@ -53,7 +53,7 @@
        SimpleDateFormat format2 = new SimpleDateFormat("kk");
        SimpleDateFormat format3 = new SimpleDateFormat("mm");
        try {
-           conn = DriverManager.getConnection(jdbc);
+           conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc);
            stmt = conn.createStatement();
            DatabaseConfig dbc = new DatabaseConfig();
            String[] tables = dbc.findTableName("HodJob",time.getStartTime(),time.getEndTime());

Modified: hadoop/chukwa/trunk/src/web/hicc/jsp/host_selector.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/host_selector.jsp?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/host_selector.jsp (original)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/host_selector.jsp Thu Apr  2 04:18:51 2009
@@ -59,7 +59,7 @@
             }
         } catch (NullPointerException e) {
     }
-           conn = DriverManager.getConnection(jdbc);
+           conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc);
            stmt = conn.createStatement();
            String query = "";
            String HodID = (String)session.getAttribute("HodID");

Modified: hadoop/chukwa/trunk/src/web/hicc/jsp/single-series-chart-javascript.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/single-series-chart-javascript.jsp?rev=761161&r1=761160&r2=761161&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/single-series-chart-javascript.jsp (original)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/single-series-chart-javascript.jsp Thu Apr  2 04:18:51
2009
@@ -105,8 +105,7 @@
        }
        String mrtimeclause = "";
        try {
-           String jdbcDriver = System.getenv("JDBC_DRIVER");
-           Class.forName(jdbcDriver).newInstance();
+           org.apache.hadoop.chukwa.util.DriverManagerUtil.loadDriver().newInstance();
        } catch (Exception ex) {
        }
        Connection conn = null;



Mime
View raw message