Search in sources :

Example 1 with ClusterInvalidSessionException

use of com.cloud.cluster.ClusterInvalidSessionException in project cloudstack by apache.

the class ManagementServerHostDaoImpl method update.

@Override
public void update(long id, long runId, State state, Date lastUpdate) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    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) {
            s_logger.info("Invalid cluster session detected, runId " + runId + " is no longer valid");
            throw new CloudRuntimeException("Invalid cluster session detected, runId " + runId + " is no longer valid", new ClusterInvalidSessionException("runId " + runId + " is no longer valid"));
        }
    } catch (SQLException e) {
        throw new CloudRuntimeException("DB exception: ", e);
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ClusterInvalidSessionException(com.cloud.cluster.ClusterInvalidSessionException) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PreparedStatement(java.sql.PreparedStatement)

Example 2 with ClusterInvalidSessionException

use of com.cloud.cluster.ClusterInvalidSessionException in project cloudstack by apache.

the class ManagementServerHostDaoImpl method update.

@Override
@DB
public void update(long id, long runid, Date lastUpdate) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    try {
        txn.start();
        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();
        if (count < 1) {
            s_logger.info("Invalid cluster session detected, runId " + runid + " is no longer valid");
            throw new CloudRuntimeException("Invalid cluster session detected, runId " + runid + " is no longer valid", new ClusterInvalidSessionException("runId " + runid + " is no longer valid"));
        }
    } catch (Exception e) {
        s_logger.warn("Unexpected exception, ", e);
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ClusterInvalidSessionException(com.cloud.cluster.ClusterInvalidSessionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PreparedStatement(java.sql.PreparedStatement) ClusterInvalidSessionException(com.cloud.cluster.ClusterInvalidSessionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) DB(com.cloud.utils.db.DB)

Aggregations

ClusterInvalidSessionException (com.cloud.cluster.ClusterInvalidSessionException)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 DB (com.cloud.utils.db.DB)1