mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Reverting the changes done to this file for coverity fixes
This commit is contained in:
parent
394be902eb
commit
1f3d02b38a
@ -53,14 +53,15 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
|||||||
@Override
|
@Override
|
||||||
public void invalidateRunSession(long id, long runid) {
|
public void invalidateRunSession(long id, long runid) {
|
||||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
try (PreparedStatement pstmt = txn.prepareStatement("update mshost set runid=0, state='Down' where id=? and runid=?");){
|
PreparedStatement pstmt = null;
|
||||||
if(pstmt != null) {
|
try {
|
||||||
|
pstmt = txn.prepareAutoCloseStatement("update mshost set runid=0, state='Down' where id=? and runid=?");
|
||||||
pstmt.setLong(1, id);
|
pstmt.setLong(1, id);
|
||||||
pstmt.setLong(2, runid);
|
pstmt.setLong(2, runid);
|
||||||
|
|
||||||
pstmt.executeUpdate();
|
pstmt.executeUpdate();
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new CloudRuntimeException("invalidateRunSession:Exception:"+ e.getMessage(), e);
|
throw new CloudRuntimeException("DB exception on " + pstmt.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +82,12 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
|||||||
@DB
|
@DB
|
||||||
public void update(long id, long runid, String name, String version, String serviceIP, int servicePort, Date lastUpdate) {
|
public void update(long id, long runid, String name, String version, String serviceIP, int servicePort, Date lastUpdate) {
|
||||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
try {
|
try {
|
||||||
txn.start();
|
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 =
|
||||||
if (pstmt != null) {
|
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(1, name);
|
||||||
pstmt.setString(2, version);
|
pstmt.setString(2, version);
|
||||||
pstmt.setString(3, serviceIP);
|
pstmt.setString(3, serviceIP);
|
||||||
@ -94,19 +96,12 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
|||||||
pstmt.setLong(6, runid);
|
pstmt.setLong(6, runid);
|
||||||
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)
|
|
||||||
{
|
|
||||||
throw new CloudRuntimeException("update:Exception:"+e.getMessage(),e);
|
|
||||||
}
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
} catch (RuntimeException e) {
|
} catch (Exception e) {
|
||||||
txn.rollback();
|
|
||||||
s_logger.warn("Unexpected exception, ", e);
|
s_logger.warn("Unexpected exception, ", e);
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}finally {
|
|
||||||
txn.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,20 +109,19 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
|||||||
@DB
|
@DB
|
||||||
public boolean remove(Long id) {
|
public boolean remove(Long id) {
|
||||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
txn.start();
|
txn.start();
|
||||||
|
|
||||||
ManagementServerHostVO msHost = findById(id);
|
ManagementServerHostVO msHost = findById(id);
|
||||||
msHost.setState(ManagementServerHost.State.Down);
|
msHost.setState(ManagementServerHost.State.Down);
|
||||||
super.remove(id);
|
super.remove(id);
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
txn.rollback();
|
|
||||||
s_logger.warn("Unexpected exception, ", e);
|
s_logger.warn("Unexpected exception, ", e);
|
||||||
throw new CloudRuntimeException("remove:Exception:"+e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}finally
|
|
||||||
{
|
|
||||||
txn.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,30 +129,24 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
|||||||
@DB
|
@DB
|
||||||
public void update(long id, long runid, Date lastUpdate) {
|
public void update(long id, long runid, Date lastUpdate) {
|
||||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
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=?");) {
|
|
||||||
if (pstmt != null) {
|
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.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 (Exception e) {
|
||||||
}catch (SQLException e) {
|
s_logger.warn("Unexpected exception, ", e);
|
||||||
throw new CloudRuntimeException("update:Exception:"+e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,27 +170,21 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
|||||||
@DB
|
@DB
|
||||||
public int increaseAlertCount(long id) {
|
public int increaseAlertCount(long id) {
|
||||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
int changedRows = 0;
|
int changedRows = 0;
|
||||||
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");) {
|
|
||||||
if (pstmt != null) {
|
pstmt = txn.prepareAutoCloseStatement("update mshost set alert_count=alert_count+1 where id=? and alert_count=0");
|
||||||
pstmt.setLong(1, id);
|
pstmt.setLong(1, id);
|
||||||
|
|
||||||
changedRows = pstmt.executeUpdate();
|
changedRows = pstmt.executeUpdate();
|
||||||
}
|
|
||||||
}catch (SQLException e)
|
|
||||||
{
|
|
||||||
throw new CloudRuntimeException("increaseAlertCount:Exception:"+e.getMessage(),e);
|
|
||||||
}
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
} catch (RuntimeException e) {
|
} catch (Exception e) {
|
||||||
txn.rollback();
|
s_logger.warn("Unexpected exception, ", e);
|
||||||
s_logger.warn("increaseAlertCount:Exception:" + e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
throw new CloudRuntimeException("increaseAlertCount:Exception:" + e.getMessage(), e);
|
|
||||||
}finally
|
|
||||||
{
|
|
||||||
txn.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return changedRows;
|
return changedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,19 +211,21 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
|||||||
@Override
|
@Override
|
||||||
public void update(long id, long runId, State state, Date lastUpdate) {
|
public void update(long id, long runId, State state, Date lastUpdate) {
|
||||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
try (PreparedStatement pstmt = txn.prepareStatement("update mshost set state=?, last_update=? where id=? and runid=?");){
|
PreparedStatement pstmt = null;
|
||||||
if (pstmt != null) {
|
try {
|
||||||
|
pstmt = txn.prepareAutoCloseStatement("update mshost set state=?, last_update=? where id=? and runid=?");
|
||||||
pstmt.setString(1, state.toString());
|
pstmt.setString(1, state.toString());
|
||||||
pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
|
pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate));
|
||||||
pstmt.setLong(3, id);
|
pstmt.setLong(3, id);
|
||||||
pstmt.setLong(4, runId);
|
pstmt.setLong(4, runId);
|
||||||
|
|
||||||
int count = pstmt.executeUpdate();
|
int count = pstmt.executeUpdate();
|
||||||
|
|
||||||
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("DB exception on " + pstmt.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,21 +241,22 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
|
|||||||
@Override
|
@Override
|
||||||
public List<Long> listOrphanMsids() {
|
public List<Long> listOrphanMsids() {
|
||||||
List<Long> orphanList = new ArrayList<Long>();
|
List<Long> orphanList = new ArrayList<Long>();
|
||||||
|
|
||||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
try (PreparedStatement pstmt =
|
PreparedStatement pstmt = null;
|
||||||
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 {
|
||||||
{
|
pstmt =
|
||||||
try(ResultSet rs = pstmt.executeQuery();) {
|
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()) {
|
while (rs.next()) {
|
||||||
orphanList.add(rs.getLong(1));
|
orphanList.add(rs.getLong(1));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new CloudRuntimeException("listOrphanMsids:Exception:" + e.getMessage(), e);
|
throw new CloudRuntimeException("DB exception on " + pstmt.toString(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return orphanList;
|
return orphanList;
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new CloudRuntimeException("listOrphanMsids:Exception:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user