mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-7079: Fixed the issue where rollback was called after commit. As well, added few null checks
This commit is contained in:
parent
73b622c823
commit
d51e8f44ae
@ -85,15 +85,17 @@ 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=?");) {
|
||||||
pstmt.setString(1, name);
|
if (pstmt != null) {
|
||||||
pstmt.setString(2, version);
|
pstmt.setString(1, name);
|
||||||
pstmt.setString(3, serviceIP);
|
pstmt.setString(2, version);
|
||||||
pstmt.setInt(4, servicePort);
|
pstmt.setString(3, serviceIP);
|
||||||
pstmt.setString(5, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
|
pstmt.setInt(4, servicePort);
|
||||||
pstmt.setLong(6, runid);
|
pstmt.setString(5, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
|
||||||
pstmt.setString(7, ManagementServerHost.State.Up.toString());
|
pstmt.setLong(6, runid);
|
||||||
pstmt.setLong(8, id);
|
pstmt.setString(7, ManagementServerHost.State.Up.toString());
|
||||||
pstmt.executeUpdate();
|
pstmt.setLong(8, id);
|
||||||
|
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=?");) {
|
||||||
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
|
if (pstmt != null) {
|
||||||
pstmt.setLong(2, id);
|
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
|
||||||
pstmt.setLong(3, runid);
|
pstmt.setLong(2, id);
|
||||||
|
pstmt.setLong(3, runid);
|
||||||
|
|
||||||
int count = pstmt.executeUpdate();
|
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 (count < 1) {
|
}
|
||||||
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");) {
|
||||||
pstmt.setLong(1, id);
|
if (pstmt != null) {
|
||||||
changedRows = pstmt.executeUpdate();
|
pstmt.setLong(1, id);
|
||||||
|
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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user