Repository: cloudstack
Updated Branches:
  refs/heads/master 4d952d0a0 -> e26855e28


CLOUDSTACK-6594: Improve the logging in the util functions utilized by db 
upgrades currently. If the exception is to be ignored, dont log the stack trace 
and also dont log it in warn. Making them debug just to be little verbose 
during upgrade scenario.
Correcting all the unit tests accordingly.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e26855e2
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e26855e2
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e26855e2

Branch: refs/heads/master
Commit: e26855e2849960951fd27fcb394c19a5b4bb2755
Parents: 4d952d0
Author: Nitin Mehta <[email protected]>
Authored: Thu Jul 31 16:36:33 2014 -0700
Committer: Nitin Mehta <[email protected]>
Committed: Thu Jul 31 16:36:33 2014 -0700

----------------------------------------------------------------------
 .../cloud/upgrade/dao/DatabaseAccessObject.java |  6 ++--
 .../upgrade/dao/DatabaseAccessObjectTest.java   | 36 +++++++-------------
 2 files changed, 16 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e26855e2/engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java 
b/engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java
index 1e620a5..5d0eddd 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java
@@ -39,7 +39,7 @@ public class DatabaseAccessObject {
             pstmt.executeUpdate();
             s_logger.debug("Key " + key + " is dropped successfully from the 
table " + tableName);
         } catch (SQLException e) {
-            s_logger.warn("Ignored SQL Exception when trying to drop " + 
(isForeignKey ? "foreign " : "") + "key " + key + " on table "  + tableName, e);
+            s_logger.debug("Ignored SQL Exception when trying to drop " + 
(isForeignKey ? "foreign " : "") + "key " + key + " on table "  + tableName + " 
exception: " + e.getMessage());
 
         }
     }
@@ -49,7 +49,7 @@ public class DatabaseAccessObject {
             pstmt.executeUpdate();
             s_logger.debug("Primary key is dropped successfully from the table 
" + tableName);
         } catch (SQLException e) {
-            s_logger.warn("Ignored SQL Exception when trying to drop primary 
key on table " + tableName, e);
+            s_logger.debug("Ignored SQL Exception when trying to drop primary 
key on table " + tableName + " exception: " + e.getMessage());
         }
     }
 
@@ -68,7 +68,7 @@ public class DatabaseAccessObject {
             pstmt.executeQuery();
             columnExists = true;
         } catch (SQLException e) {
-            s_logger.warn("Field " + columnName + " doesn't exist in " + 
tableName, e);
+            s_logger.debug("Field " + columnName + " doesn't exist in " + 
tableName + " ignoring exception: " + e.getMessage());
         }
         return columnExists;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e26855e2/engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java
----------------------------------------------------------------------
diff --git 
a/engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java 
b/engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java
index 5d37fbf..9a2115e 100644
--- a/engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java
+++ b/engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java
@@ -70,8 +70,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeUpdate();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(1)).debug(anyString());
-        verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class));
+        verify(loggerMock, times(1)).debug(contains("successfully"));
     }
 
     @Test(expected = NullPointerException.class)
@@ -100,8 +99,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeUpdate();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(0)).debug(anyString());
-        verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
+        verify(loggerMock, times(1)).debug(contains("Exception"));
     }
 
     @Test
@@ -120,8 +118,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeUpdate();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(0)).debug(anyString());
-        verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
+        verify(loggerMock, times(1)).debug(contains("Exception"));
     }
 
     @Test
@@ -138,8 +135,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeUpdate();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(1)).debug(anyString());
-        verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class));
+        verify(loggerMock, times(1)).debug(contains("successfully"));
     }
 
     @Test
@@ -157,8 +153,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(0)).executeUpdate();
         verify(preparedStatementMock, times(0)).close();
-        verify(loggerMock, times(0)).debug(anyString());
-        verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
+        verify(loggerMock, times(1)).debug(contains("Exception"));
     }
 
     @Test
@@ -177,8 +172,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeUpdate();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(0)).debug(anyString());
-        verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
+        verify(loggerMock, times(1)).debug(contains("Exception"));
     }
 
     @SuppressWarnings("static-access")
@@ -231,8 +225,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeUpdate();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(1)).debug(anyString());
-        verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class));
+        verify(loggerMock, times(1)).debug(contains("successfully"));
     }
 
     @Test(expected = NullPointerException.class)
@@ -257,8 +250,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeUpdate();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(0)).debug(anyString());
-        verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
+        verify(loggerMock, times(1)).debug(contains("Exception"));
     }
 
     @Test
@@ -274,8 +266,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(0)).executeUpdate();
         verify(preparedStatementMock, times(0)).close();
-        verify(loggerMock, times(0)).debug(anyString());
-        verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
+        verify(loggerMock, times(1)).debug(contains("Exception"));
     }
 
     @Test
@@ -292,8 +283,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeUpdate();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(0)).debug(anyString());
-        verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
+        verify(loggerMock, times(1)).debug(contains("Exception"));
     }
 
     @Test
@@ -309,7 +299,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeQuery();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class));
+        verify(loggerMock, times(0)).debug(anyString(), any(Throwable.class));
     }
 
     @Test(expected = NullPointerException.class)
@@ -336,7 +326,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeQuery();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
+        verify(loggerMock, times(1)).debug(anyString());
     }
 
     @Test
@@ -354,7 +344,7 @@ public class DatabaseAccessObjectTest {
         verify(connectionMock, times(1)).prepareStatement(anyString());
         verify(preparedStatementMock, times(1)).executeQuery();
         verify(preparedStatementMock, times(1)).close();
-        verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
+        verify(loggerMock, times(1)).debug(anyString());
     }
 
     @Test

Reply via email to