CLOUDSTACK-7079: Fixed the issue where rollback was called after commit. As well, added few null checks

This commit is contained in:
Santhosh Edukulla 2014-07-09 15:58:43 +05:30
parent 73b622c823
commit d51e8f44ae

View File

@ -85,6 +85,7 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
txn.start(); txn.start();
try(PreparedStatement pstmt = 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=?");) { 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(1, name);
pstmt.setString(2, version); pstmt.setString(2, version);
pstmt.setString(3, serviceIP); pstmt.setString(3, serviceIP);
@ -94,6 +95,7 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
pstmt.setString(7, ManagementServerHost.State.Up.toString()); pstmt.setString(7, ManagementServerHost.State.Up.toString());
pstmt.setLong(8, id); pstmt.setLong(8, id);
pstmt.executeUpdate(); pstmt.executeUpdate();
}
}catch(SQLException e) }catch(SQLException e)
{ {
throw new CloudRuntimeException("update:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("update:Exception:"+e.getMessage(),e);
@ -136,19 +138,20 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
try { try {
txn.start(); txn.start();
try( PreparedStatement pstmt = txn.prepareStatement("update mshost set last_update=?, removed=null, alert_count=0 where id=? and runid=?");) { 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.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
pstmt.setLong(2, id); pstmt.setLong(2, id);
pstmt.setLong(3, runid); pstmt.setLong(3, runid);
int count = pstmt.executeUpdate(); int count = pstmt.executeUpdate();
txn.commit();
if (count < 1) { if (count < 1) {
throw new CloudRuntimeException("Invalid cluster session detected", new ClusterInvalidSessionException("runid " + runid + " is no longer valid")); throw new CloudRuntimeException("Invalid cluster session detected", new ClusterInvalidSessionException("runid " + runid + " is no longer valid"));
} }
}
}catch (SQLException e) { }catch (SQLException e) {
throw new CloudRuntimeException("update:Exception:"+e.getMessage(), e); throw new CloudRuntimeException("update:Exception:"+e.getMessage(), e);
} }
txn.commit();
} catch (RuntimeException e) { } catch (RuntimeException e) {
txn.rollback(); txn.rollback();
s_logger.warn("update:Exception:"+e.getMessage(), e); s_logger.warn("update:Exception:"+e.getMessage(), e);
@ -183,8 +186,10 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
try { try {
txn.start(); txn.start();
try(PreparedStatement pstmt = txn.prepareStatement("update mshost set alert_count=alert_count+1 where id=? and alert_count=0");) { 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); pstmt.setLong(1, id);
changedRows = pstmt.executeUpdate(); changedRows = pstmt.executeUpdate();
}
}catch (SQLException e) }catch (SQLException e)
{ {
throw new CloudRuntimeException("increaseAlertCount:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("increaseAlertCount:Exception:"+e.getMessage(),e);