Search in sources :

Example 6 with ServiceStatus

use of cbit.vcell.message.server.ServiceStatus in project vcell by virtualcell.

the class AdminDBTopLevel method updateServiceStatus.

public ServiceStatus updateServiceStatus(ServiceStatus oldServiceStatus, TransactionalServiceOperation serviceOP, boolean bEnableRetry) throws SQLException, UpdateSynchronizationException {
    Object lock = new Object();
    Connection con = conFactory.getConnection(lock);
    try {
        ServiceStatus currentServiceStatus = serviceStatusDB.getServiceStatus(con, oldServiceStatus.getServiceSpec().getServerID(), oldServiceStatus.getServiceSpec().getType(), oldServiceStatus.getServiceSpec().getOrdinal(), true);
        if (!currentServiceStatus.compareEqual(oldServiceStatus)) {
            throw new UpdateSynchronizationException("current service status " + currentServiceStatus + " doesn't match argument for " + oldServiceStatus);
        }
        ServiceStatus newServiceStatus = null;
        try {
            newServiceStatus = serviceOP.doOperation(oldServiceStatus);
        } catch (Exception ex) {
            lg.error("failure in updateServiceStatus()", ex);
            throw new RuntimeException("transactional operation failed for " + newServiceStatus + " : " + ex.getMessage());
        }
        serviceStatusDB.updateServiceStatus(con, newServiceStatus);
        con.commit();
        ServiceStatus updatedServiceStatus = serviceStatusDB.getServiceStatus(con, oldServiceStatus.getServiceSpec().getServerID(), oldServiceStatus.getServiceSpec().getType(), oldServiceStatus.getServiceSpec().getOrdinal(), false);
        return updatedServiceStatus;
    } catch (Throwable e) {
        lg.error("failure in updateServiceStatus()", e);
        try {
            con.rollback();
        } catch (Throwable rbe) {
            lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
        }
        if (bEnableRetry && isBadConnection(con)) {
            conFactory.failed(con, lock);
            return updateServiceStatus(oldServiceStatus, serviceOP, false);
        } else {
            handle_SQLException(e);
            // never gets here;
            return null;
        }
    } finally {
        conFactory.release(con, lock);
    }
}
Also used : ServiceStatus(cbit.vcell.message.server.ServiceStatus) Connection(java.sql.Connection) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) UseridIDExistsException(org.vcell.util.UseridIDExistsException) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException)

Example 7 with ServiceStatus

use of cbit.vcell.message.server.ServiceStatus in project vcell by virtualcell.

the class AdminDBTopLevel method insertServiceStatus.

public ServiceStatus insertServiceStatus(ServiceStatus serviceStatus, boolean bEnableRetry) throws SQLException, UpdateSynchronizationException {
    Object lock = new Object();
    Connection con = conFactory.getConnection(lock);
    try {
        ServiceStatus currentServiceStatus = serviceStatusDB.getServiceStatus(con, serviceStatus.getServiceSpec().getServerID(), serviceStatus.getServiceSpec().getType(), serviceStatus.getServiceSpec().getOrdinal(), false);
        if (currentServiceStatus != null) {
            throw new UpdateSynchronizationException("service already exists:" + currentServiceStatus);
        }
        serviceStatusDB.insertServiceStatus(con, serviceStatus, conFactory.getKeyFactory().getNewKey(con));
        con.commit();
        ServiceStatus newServiceStatus = serviceStatusDB.getServiceStatus(con, serviceStatus.getServiceSpec().getServerID(), serviceStatus.getServiceSpec().getType(), serviceStatus.getServiceSpec().getOrdinal(), false);
        return newServiceStatus;
    } catch (Throwable e) {
        lg.error("failure in insertServiceStatus()", e);
        try {
            con.rollback();
        } catch (Throwable rbe) {
            lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
        }
        if (bEnableRetry && isBadConnection(con)) {
            conFactory.failed(con, lock);
            return insertServiceStatus(serviceStatus, false);
        } else {
            handle_SQLException(e);
            // never gets here;
            return null;
        }
    } finally {
        conFactory.release(con, lock);
    }
}
Also used : ServiceStatus(cbit.vcell.message.server.ServiceStatus) Connection(java.sql.Connection) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException)

Example 8 with ServiceStatus

use of cbit.vcell.message.server.ServiceStatus in project vcell by virtualcell.

the class AdminDBTopLevel method deleteServiceStatus.

public void deleteServiceStatus(ServiceStatus serviceStatus, boolean bEnableRetry) throws SQLException, UpdateSynchronizationException {
    Object lock = new Object();
    Connection con = conFactory.getConnection(lock);
    try {
        ServiceStatus currentServiceStatus = serviceStatusDB.getServiceStatus(con, serviceStatus.getServiceSpec().getServerID(), serviceStatus.getServiceSpec().getType(), serviceStatus.getServiceSpec().getOrdinal(), false);
        if (currentServiceStatus == null) {
            throw new UpdateSynchronizationException("service doesn't exist:" + currentServiceStatus);
        }
        serviceStatusDB.deleteServiceStatus(con, serviceStatus, conFactory.getKeyFactory().getNewKey(con));
        con.commit();
    } catch (Throwable e) {
        lg.error("failure in deleteServiceStatus()", e);
        try {
            con.rollback();
        } catch (Throwable rbe) {
            lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
        }
        if (bEnableRetry && isBadConnection(con)) {
            conFactory.failed(con, lock);
            deleteServiceStatus(serviceStatus, false);
        } else {
            handle_SQLException(e);
        }
    } finally {
        conFactory.release(con, lock);
    }
}
Also used : ServiceStatus(cbit.vcell.message.server.ServiceStatus) Connection(java.sql.Connection) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException)

Aggregations

ServiceStatus (cbit.vcell.message.server.ServiceStatus)8 UpdateSynchronizationException (cbit.vcell.server.UpdateSynchronizationException)4 Connection (java.sql.Connection)4 ServiceSpec (cbit.vcell.message.server.ServiceSpec)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 HtcJobID (cbit.vcell.server.HtcJobID)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DataAccessException (org.vcell.util.DataAccessException)1 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)1 UserCancelException (org.vcell.util.UserCancelException)1 UseridIDExistsException (org.vcell.util.UseridIDExistsException)1 VCellServerID (org.vcell.util.document.VCellServerID)1