Search in sources :

Example 1 with UpdateSynchronizationException

use of cbit.vcell.server.UpdateSynchronizationException in project vcell by virtualcell.

the class SimulationDispatcherEngine method onStopRequest.

public void onStopRequest(VCSimulationIdentifier vcSimID, User user, SimulationDatabase simulationDatabase, VCMessageSession session) throws DataAccessException, VCMessagingException, SQLException {
    KeyValue simKey = vcSimID.getSimulationKey();
    SimulationJobStatus[] allActiveSimJobStatusArray = simulationDatabase.getActiveJobs();
    ArrayList<SimulationJobStatus> simJobStatusArray = new ArrayList<SimulationJobStatus>();
    for (SimulationJobStatus activeSimJobStatus : allActiveSimJobStatusArray) {
        if (activeSimJobStatus.getVCSimulationIdentifier().getSimulationKey().equals(vcSimID.getSimulationKey())) {
            simJobStatusArray.add(activeSimJobStatus);
        }
    }
    for (SimulationJobStatus simJobStatus : simJobStatusArray) {
        SimulationStateMachine simStateMachine = getSimulationStateMachine(simKey, simJobStatus.getJobIndex());
        try {
            simStateMachine.onStopRequest(user, simJobStatus, simulationDatabase, session);
        } catch (UpdateSynchronizationException e) {
            simStateMachine.onStopRequest(user, simJobStatus, simulationDatabase, session);
        }
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) ArrayList(java.util.ArrayList) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException)

Example 2 with UpdateSynchronizationException

use of cbit.vcell.server.UpdateSynchronizationException in project vcell by virtualcell.

the class SimulationDispatcherEngine method onStartRequest.

/**
 * @param vcMessage
 * @param session
 * @throws VCMessagingException
 * @throws SQLException
 * @throws DataAccessException
 */
public void onStartRequest(VCSimulationIdentifier vcSimID, User user, int simulationScanCount, SimulationDatabase simulationDatabase, VCMessageSession session, VCMessageSession dispatcherQueueSession) throws VCMessagingException, DataAccessException, SQLException {
    KeyValue simKey = vcSimID.getSimulationKey();
    SimulationInfo simulationInfo = null;
    try {
        simulationInfo = simulationDatabase.getSimulationInfo(user, simKey);
    } catch (DataAccessException ex) {
        if (lg.isWarnEnabled())
            lg.warn("Bad simulation " + vcSimID);
        StatusMessage message = new StatusMessage(new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, -1, null, SchedulerStatus.FAILED, 0, SimulationMessage.workerFailure("Failed to dispatch simulation: " + ex.getMessage()), null, null), user.getName(), null, null);
        message.sendToClient(session);
        return;
    }
    if (simulationInfo == null) {
        if (lg.isWarnEnabled())
            lg.warn("Can't start, simulation [" + vcSimID + "] doesn't exist in database");
        StatusMessage message = new StatusMessage(new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, -1, null, SchedulerStatus.FAILED, 0, SimulationMessage.workerFailure("Can't start, simulation [" + vcSimID + "] doesn't exist"), null, null), user.getName(), null, null);
        message.sendToClient(session);
        return;
    }
    if (simulationScanCount > Integer.parseInt(cbit.vcell.resource.PropertyLoader.getRequiredProperty(cbit.vcell.resource.PropertyLoader.maxJobsPerScan))) {
        if (lg.isWarnEnabled())
            lg.warn("Too many simulations (" + simulationScanCount + ") for parameter scan." + vcSimID);
        StatusMessage message = new StatusMessage(new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, -1, null, SchedulerStatus.FAILED, 0, SimulationMessage.workerFailure("Too many simulations (" + simulationScanCount + ") for parameter scan."), null, null), user.getName(), null, null);
        message.sendToClient(session);
        return;
    }
    for (int jobIndex = 0; jobIndex < simulationScanCount; jobIndex++) {
        SimulationStateMachine simStateMachine = getSimulationStateMachine(simKey, jobIndex);
        try {
            simStateMachine.onStartRequest(user, vcSimID, simulationDatabase, session);
        } catch (UpdateSynchronizationException e) {
            simStateMachine.onStartRequest(user, vcSimID, simulationDatabase, session);
        }
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException) DataAccessException(org.vcell.util.DataAccessException) SimulationInfo(cbit.vcell.solver.SimulationInfo) StatusMessage(cbit.vcell.message.messages.StatusMessage)

Example 3 with UpdateSynchronizationException

use of cbit.vcell.server.UpdateSynchronizationException in project vcell by virtualcell.

the class AdminDBTopLevel method modifyServiceStatus.

public ServiceStatus modifyServiceStatus(ServiceStatus oldServiceStatus, ServiceStatus newServiceStatus, 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(), false);
        if (!currentServiceStatus.compareEqual(oldServiceStatus)) {
            throw new UpdateSynchronizationException("service doesn't exist:" + currentServiceStatus);
        }
        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 modifyServiceStatus()", e);
        try {
            con.rollback();
        } catch (Throwable rbe) {
            lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
        }
        if (bEnableRetry && isBadConnection(con)) {
            conFactory.failed(con, lock);
            return modifyServiceStatus(oldServiceStatus, newServiceStatus, false);
        } else {
            handle_SQLException(e);
            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 4 with UpdateSynchronizationException

use of cbit.vcell.server.UpdateSynchronizationException 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 5 with UpdateSynchronizationException

use of cbit.vcell.server.UpdateSynchronizationException 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)

Aggregations

UpdateSynchronizationException (cbit.vcell.server.UpdateSynchronizationException)6 ServiceStatus (cbit.vcell.message.server.ServiceStatus)4 Connection (java.sql.Connection)4 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)2 DataAccessException (org.vcell.util.DataAccessException)2 KeyValue (org.vcell.util.document.KeyValue)2 StatusMessage (cbit.vcell.message.messages.StatusMessage)1 SimulationInfo (cbit.vcell.solver.SimulationInfo)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)1 UseridIDExistsException (org.vcell.util.UseridIDExistsException)1