CHUKWA-258. More detailed logging of SQL errors.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/chukwa/branches/chukwa-0.1@779704 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 4699799..4d95e8a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -38,6 +38,8 @@
 
   IMPROVEMENTS
 
+    CHUKWA-258. Better logging of SQL errors. (asrabkin)
+
     CHUKWA-226. Changed HDFS usage collection frequency from 10 minutes to 60 minutes. (Cheng Zhang via Eric Yang)
 
     CHUKWA-219. Improved usability of host selector, and updated caching for host list. (Eric Yang)
diff --git a/src/java/org/apache/hadoop/chukwa/database/Aggregator.java b/src/java/org/apache/hadoop/chukwa/database/Aggregator.java
index b7ca563..8e34014 100644
--- a/src/java/org/apache/hadoop/chukwa/database/Aggregator.java
+++ b/src/java/org/apache/hadoop/chukwa/database/Aggregator.java
@@ -24,7 +24,6 @@
 import java.io.IOException;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
 import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
diff --git a/src/java/org/apache/hadoop/chukwa/database/Consolidator.java b/src/java/org/apache/hadoop/chukwa/database/Consolidator.java
index 7e71eb8..243640d 100644
--- a/src/java/org/apache/hadoop/chukwa/database/Consolidator.java
+++ b/src/java/org/apache/hadoop/chukwa/database/Consolidator.java
@@ -119,7 +119,7 @@
         log.debug("Query: " + query);
         rs = db.query(query);
         if (rs == null) {
-          throw new SQLException("Table is undefined.");
+          throw new SQLException("Table "+ sumTable + " is undefined.");
         }
         ResultSetMetaData rmeta = rs.getMetaData();
         boolean empty = true;
diff --git a/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java b/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java
index 17aa8fe..2b8319c 100644
--- a/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java
+++ b/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java
@@ -49,6 +49,7 @@
       // broken Java implementations
       org.apache.hadoop.chukwa.util.DriverManagerUtil.loadDriver().newInstance();
     } catch (Exception ex) {
+      log.error("failed to load driver", ex);
       // handle the error
     }
     Connection conn = null;
@@ -160,7 +161,7 @@
       // Now do something with the ResultSet ....
     } catch (SQLException ex) {
       // handle any errors
-      log.error("SQLException: " + ex.getMessage());
+      log.error("SQLException: " + ex.getMessage() + " on query: " + query);
       log.error("SQLState: " + ex.getSQLState());
       log.error("VendorError: " + ex.getErrorCode());
     } catch (Exception ex) {
diff --git a/src/java/org/apache/hadoop/chukwa/util/DatabaseWriter.java b/src/java/org/apache/hadoop/chukwa/util/DatabaseWriter.java
index abd281f..db908c6 100644
--- a/src/java/org/apache/hadoop/chukwa/util/DatabaseWriter.java
+++ b/src/java/org/apache/hadoop/chukwa/util/DatabaseWriter.java
@@ -112,6 +112,8 @@
       rs = stmt.executeQuery(query);
     } catch (SQLException ex) {
       // handle any errors
+      //only log at debug level because caller will still see exception
+      //only log at debug level because caller will still see exception
       log.debug(ex, ex);
       log.debug("SQL Statement:" + query);
       log.debug("SQLException: " + ex.getMessage());
diff --git a/src/web/hicc/jsp/host_selector_dropdown.jsp b/src/web/hicc/jsp/host_selector_dropdown.jsp
index c4d4c20..99111a6 100644
--- a/src/web/hicc/jsp/host_selector_dropdown.jsp
+++ b/src/web/hicc/jsp/host_selector_dropdown.jsp
@@ -63,6 +63,7 @@
     Connection conn = null;
     Statement stmt = null;
     ResultSet rs = null;
+    String query = "";
     try {
         HashMap<String, String> hosts = new HashMap<String, String>();
         try {
@@ -74,7 +75,6 @@
     }
            conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc);
            stmt = conn.createStatement();
-           String query = "";
            String jobId = (String)session.getAttribute("JobID");
            if(jobId!=null && !jobId.equals("null") && !jobId.equals("")) {
                query = "select DISTINCT Machine from HodMachine where HodID='"+jobId+"' order by Machine;";
@@ -124,9 +124,10 @@
            // Now do something with the ResultSet ....
        } catch (SQLException ex) {
            // handle any errors
-           out.println("SQLException: " + ex.getMessage());
-           out.println("SQLState: " + ex.getSQLState());
-           out.println("VendorError: " + ex.getErrorCode());
+           // FIXME: should we use Log4j here?
+           System.out.println("SQLException on query " + query +" " + ex.getMessage());
+           System.out.println("SQLState: " + ex.getSQLState());
+           System.out.println("VendorError: " + ex.getErrorCode());
        } finally {
            // it is a good idea to release
            // resources in a finally{} block
diff --git a/src/web/hicc/jsp/host_selector_role.jsp b/src/web/hicc/jsp/host_selector_role.jsp
index ab5b920..f856719 100644
--- a/src/web/hicc/jsp/host_selector_role.jsp
+++ b/src/web/hicc/jsp/host_selector_role.jsp
@@ -62,6 +62,7 @@
          }
          roles.put(type,"checked");
        } catch(SQLException ex) {
+       	 System.out.println("SQLException "+ ex + " on query " + query);
          // Ignore if there is no data for the cluster.
        } finally {
          db.close();