Repository: cloudstack
Updated Branches:
  refs/heads/master 394be902e -> 1f3d02b38


Reverting the changes done to this file for coverity fixes


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

Branch: refs/heads/master
Commit: 1f3d02b38acbd269a65e2a9b0a1d0233b69a7598
Parents: 394be90
Author: Santhosh Edukulla <santhosh.eduku...@gmail.com>
Authored: Thu Jul 10 23:35:27 2014 +0530
Committer: Santhosh Edukulla <santhosh.eduku...@gmail.com>
Committed: Thu Jul 10 23:35:27 2014 +0530

----------------------------------------------------------------------
 .../dao/ManagementServerHostDaoImpl.java        | 169 +++++++++----------
 1 file changed, 77 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1f3d02b3/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java
----------------------------------------------------------------------
diff --git 
a/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java 
b/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java
index 9136a64..3d0c3f5 100644
--- 
a/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java
+++ 
b/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java
@@ -53,14 +53,15 @@ public class ManagementServerHostDaoImpl extends 
GenericDaoBase<ManagementServer
     @Override
     public void invalidateRunSession(long id, long runid) {
         TransactionLegacy txn = TransactionLegacy.currentTxn();
-        try (PreparedStatement pstmt = txn.prepareStatement("update mshost set 
runid=0, state='Down' where id=? and runid=?");){
-            if(pstmt != null) {
-                pstmt.setLong(1, id);
-                pstmt.setLong(2, runid);
-                pstmt.executeUpdate();
-            }
+        PreparedStatement pstmt = null;
+        try {
+            pstmt = txn.prepareAutoCloseStatement("update mshost set runid=0, 
state='Down' where id=? and runid=?");
+            pstmt.setLong(1, id);
+            pstmt.setLong(2, runid);
+
+            pstmt.executeUpdate();
         } catch (SQLException e) {
-            throw new CloudRuntimeException("invalidateRunSession:Exception:"+ 
e.getMessage(), e);
+            throw new CloudRuntimeException("DB exception on " + 
pstmt.toString(), e);
         }
     }
 
@@ -81,32 +82,26 @@ public class ManagementServerHostDaoImpl extends 
GenericDaoBase<ManagementServer
     @DB
     public void update(long id, long runid, String name, String version, 
String serviceIP, int servicePort, Date lastUpdate) {
         TransactionLegacy txn = TransactionLegacy.currentTxn();
+        PreparedStatement pstmt = null;
         try {
             txn.start();
-            try(PreparedStatement pstmt =
-                txn.prepareStatement("update mshost set name=?, version=?, 
service_ip=?, service_port=?, last_update=?, removed=null, alert_count=0, 
runid=?, state=? where id=?");) {
-                if (pstmt != null) {
-                    pstmt.setString(1, name);
-                    pstmt.setString(2, version);
-                    pstmt.setString(3, serviceIP);
-                    pstmt.setInt(4, servicePort);
-                    pstmt.setString(5, 
DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
-                    pstmt.setLong(6, runid);
-                    pstmt.setString(7, 
ManagementServerHost.State.Up.toString());
-                    pstmt.setLong(8, id);
-                    pstmt.executeUpdate();
-                }
-            }catch(SQLException e)
-            {
-                throw new 
CloudRuntimeException("update:Exception:"+e.getMessage(),e);
-            }
+
+            pstmt =
+                txn.prepareAutoCloseStatement("update mshost set name=?, 
version=?, service_ip=?, service_port=?, last_update=?, removed=null, 
alert_count=0, runid=?, state=? where id=?");
+            pstmt.setString(1, name);
+            pstmt.setString(2, version);
+            pstmt.setString(3, serviceIP);
+            pstmt.setInt(4, servicePort);
+            pstmt.setString(5, 
DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
+            pstmt.setLong(6, runid);
+            pstmt.setString(7, ManagementServerHost.State.Up.toString());
+            pstmt.setLong(8, id);
+
+            pstmt.executeUpdate();
             txn.commit();
-        } catch (RuntimeException e) {
-            txn.rollback();
+        } catch (Exception e) {
             s_logger.warn("Unexpected exception, ", e);
             throw new RuntimeException(e.getMessage(), e);
-        }finally {
-            txn.close();
         }
     }
 
@@ -114,20 +109,19 @@ public class ManagementServerHostDaoImpl extends 
GenericDaoBase<ManagementServer
     @DB
     public boolean remove(Long id) {
         TransactionLegacy txn = TransactionLegacy.currentTxn();
+
         try {
             txn.start();
+
             ManagementServerHostVO msHost = findById(id);
             msHost.setState(ManagementServerHost.State.Down);
             super.remove(id);
+
             txn.commit();
             return true;
         } catch (Exception e) {
-            txn.rollback();
             s_logger.warn("Unexpected exception, ", e);
-            throw new 
CloudRuntimeException("remove:Exception:"+e.getMessage(), e);
-        }finally
-        {
-            txn.close();
+            throw new RuntimeException(e.getMessage(), e);
         }
     }
 
@@ -135,30 +129,24 @@ public class ManagementServerHostDaoImpl extends 
GenericDaoBase<ManagementServer
     @DB
     public void update(long id, long runid, Date lastUpdate) {
         TransactionLegacy txn = TransactionLegacy.currentTxn();
+        PreparedStatement pstmt = null;
         try {
             txn.start();
-            try( PreparedStatement pstmt = txn.prepareStatement("update mshost 
set last_update=?, removed=null, alert_count=0 where id=? and runid=?");) {
-                if (pstmt != null) {
-                    pstmt.setString(1, 
DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
-                    pstmt.setLong(2, id);
-                    pstmt.setLong(3, runid);
-
-                    int count = pstmt.executeUpdate();
-                    if (count < 1) {
-                        throw new CloudRuntimeException("Invalid cluster 
session detected", new ClusterInvalidSessionException("runid " + runid + " is 
no longer valid"));
-                    }
-                }
-            }catch (SQLException e) {
-                throw new 
CloudRuntimeException("update:Exception:"+e.getMessage(), e);
-            }
+
+            pstmt = txn.prepareAutoCloseStatement("update mshost set 
last_update=?, removed=null, alert_count=0 where id=? and runid=?");
+            pstmt.setString(1, 
DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
+            pstmt.setLong(2, id);
+            pstmt.setLong(3, runid);
+
+            int count = pstmt.executeUpdate();
             txn.commit();
-        } catch (RuntimeException e) {
-            txn.rollback();
-            s_logger.warn("update:Exception:"+e.getMessage(), e);
-            throw new RuntimeException("update:Exception:"+e.getMessage(), e);
-        }
-        finally {
-            txn.close();
+
+            if (count < 1) {
+                throw new CloudRuntimeException("Invalid cluster session 
detected", new ClusterInvalidSessionException("runid " + runid + " is no longer 
valid"));
+            }
+        } catch (Exception e) {
+            s_logger.warn("Unexpected exception, ", e);
+            throw new RuntimeException(e.getMessage(), e);
         }
     }
 
@@ -182,27 +170,21 @@ public class ManagementServerHostDaoImpl extends 
GenericDaoBase<ManagementServer
     @DB
     public int increaseAlertCount(long id) {
         TransactionLegacy txn = TransactionLegacy.currentTxn();
+        PreparedStatement pstmt = null;
         int changedRows = 0;
         try {
             txn.start();
-            try(PreparedStatement pstmt = txn.prepareStatement("update mshost 
set alert_count=alert_count+1 where id=? and alert_count=0");) {
-                if (pstmt != null) {
-                    pstmt.setLong(1, id);
-                    changedRows = pstmt.executeUpdate();
-                }
-            }catch (SQLException e)
-            {
-                throw new 
CloudRuntimeException("increaseAlertCount:Exception:"+e.getMessage(),e);
-            }
+
+            pstmt = txn.prepareAutoCloseStatement("update mshost set 
alert_count=alert_count+1 where id=? and alert_count=0");
+            pstmt.setLong(1, id);
+
+            changedRows = pstmt.executeUpdate();
             txn.commit();
-        } catch (RuntimeException e) {
-            txn.rollback();
-            s_logger.warn("increaseAlertCount:Exception:" + e.getMessage(), e);
-            throw new CloudRuntimeException("increaseAlertCount:Exception:" + 
e.getMessage(), e);
-        }finally
-        {
-            txn.close();
+        } catch (Exception e) {
+            s_logger.warn("Unexpected exception, ", e);
+            throw new RuntimeException(e.getMessage(), e);
         }
+
         return changedRows;
     }
 
@@ -229,19 +211,21 @@ public class ManagementServerHostDaoImpl extends 
GenericDaoBase<ManagementServer
     @Override
     public void update(long id, long runId, State state, Date lastUpdate) {
         TransactionLegacy txn = TransactionLegacy.currentTxn();
-        try (PreparedStatement pstmt = txn.prepareStatement("update mshost set 
state=?, last_update=? where id=? and runid=?");){
-            if (pstmt != null) {
-                pstmt.setString(1, state.toString());
-                pstmt.setString(2, 
DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
-                pstmt.setLong(3, id);
-                pstmt.setLong(4, runId);
-                int count = pstmt.executeUpdate();
-                if (count < 1) {
-                    throw new CloudRuntimeException("Invalid cluster session 
detected", new ClusterInvalidSessionException("runid " + runId + " is no longer 
valid"));
-                }
+        PreparedStatement pstmt = null;
+        try {
+            pstmt = txn.prepareAutoCloseStatement("update mshost set state=?, 
last_update=? where id=? and runid=?");
+            pstmt.setString(1, state.toString());
+            pstmt.setString(2, 
DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
+            pstmt.setLong(3, id);
+            pstmt.setLong(4, runId);
+
+            int count = pstmt.executeUpdate();
+
+            if (count < 1) {
+                throw new CloudRuntimeException("Invalid cluster session 
detected", new ClusterInvalidSessionException("runid " + runId + " is no longer 
valid"));
             }
         } catch (SQLException e) {
-            throw new CloudRuntimeException("update:Exception:" + 
e.getMessage(), e);
+            throw new CloudRuntimeException("DB exception on " + 
pstmt.toString(), e);
         }
     }
 
@@ -257,21 +241,22 @@ public class ManagementServerHostDaoImpl extends 
GenericDaoBase<ManagementServer
     @Override
     public List<Long> listOrphanMsids() {
         List<Long> orphanList = new ArrayList<Long>();
+
         TransactionLegacy txn = TransactionLegacy.currentTxn();
-        try (PreparedStatement pstmt =
-                     txn.prepareStatement("select t.mgmt_server_id from 
(select mgmt_server_id, count(*) as count from host group by mgmt_server_id) as 
t WHERE t.count > 0 AND t.mgmt_server_id NOT IN (select msid from mshost)");)
-        {
-            try(ResultSet rs = pstmt.executeQuery();) {
-                while (rs.next()) {
-                    orphanList.add(rs.getLong(1));
-                }
-            }catch (SQLException e) {
-                throw new CloudRuntimeException("listOrphanMsids:Exception:" + 
e.getMessage(), e);
+        PreparedStatement pstmt = null;
+        try {
+            pstmt =
+                txn.prepareAutoCloseStatement("select t.mgmt_server_id from 
(select mgmt_server_id, count(*) as count from host group by mgmt_server_id) as 
t WHERE t.count > 0 AND t.mgmt_server_id NOT IN (select msid from mshost)");
+
+            ResultSet rs = pstmt.executeQuery();
+            while (rs.next()) {
+                orphanList.add(rs.getLong(1));
             }
-            return orphanList;
         } catch (SQLException e) {
-            throw new CloudRuntimeException("listOrphanMsids:Exception:" + 
e.getMessage(), e);
+            throw new CloudRuntimeException("DB exception on " + 
pstmt.toString(), e);
         }
+
+        return orphanList;
     }
 
     @Override

Reply via email to