Repository: cloudstack Updated Branches: refs/heads/master 73b622c82 -> d51e8f44a
CLOUDSTACK-7079: Fixed the issue where rollback was called after commit. As well, added few null checks Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d51e8f44 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d51e8f44 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d51e8f44 Branch: refs/heads/master Commit: d51e8f44aecd192acb3bb6f2195819e1b4c43dd0 Parents: 73b622c Author: Santhosh Edukulla <santhosh.eduku...@gmail.com> Authored: Wed Jul 9 15:58:43 2014 +0530 Committer: Santhosh Edukulla <santhosh.eduku...@gmail.com> Committed: Wed Jul 9 15:58:43 2014 +0530 ---------------------------------------------------------------------- .../dao/ManagementServerHostDaoImpl.java | 45 +++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d51e8f44/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 89d7d27..9136a64 100644 --- a/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java +++ b/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java @@ -85,15 +85,17 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer 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=?");) { - 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(); + 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); @@ -136,19 +138,20 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer try { txn.start(); try( PreparedStatement pstmt = txn.prepareStatement("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(); - - if (count < 1) { - throw new CloudRuntimeException("Invalid cluster session detected", new ClusterInvalidSessionException("runid " + runid + " is no longer valid")); + 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); } + txn.commit(); } catch (RuntimeException e) { txn.rollback(); s_logger.warn("update:Exception:"+e.getMessage(), e); @@ -183,8 +186,10 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer try { txn.start(); try(PreparedStatement pstmt = txn.prepareStatement("update mshost set alert_count=alert_count+1 where id=? and alert_count=0");) { - pstmt.setLong(1, id); - changedRows = pstmt.executeUpdate(); + if (pstmt != null) { + pstmt.setLong(1, id); + changedRows = pstmt.executeUpdate(); + } }catch (SQLException e) { throw new CloudRuntimeException("increaseAlertCount:Exception:"+e.getMessage(),e);