Search in sources :

Example 6 with SimulationRep

use of cbit.vcell.modeldb.SimulationRep in project vcell by virtualcell.

the class RestDatabaseService method getSimulationRep.

public SimulationRep getSimulationRep(KeyValue key) throws DataAccessException, SQLException {
    SimulationRep simulationRep = simMap.get(key);
    if (simulationRep != null) {
        return simulationRep;
    } else {
        System.out.println("getting simulation rep for simKey = " + key);
        simulationRep = databaseServerImpl.getSimulationRep(key);
        if (simulationRep != null) {
            System.out.println("found simulation key = " + key + " number of cached simulations is " + simMap.size());
            simMap.put(key, simulationRep);
        } else {
            System.out.println("couldn't find simulation key = " + key);
        }
        return simulationRep;
    }
}
Also used : SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 7 with SimulationRep

use of cbit.vcell.modeldb.SimulationRep in project vcell by virtualcell.

the class BiomodelSimulationStartServerResource method start.

@Override
public Representation start() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    RestDatabaseService restDatabaseService = application.getRestDatabaseService();
    try {
        SimulationRep simRep = restDatabaseService.startSimulation(this, vcellUser);
        Representation representation = new StringRepresentation("simulation started", MediaType.TEXT_PLAIN);
        redirectSeeOther("/" + VCellApiApplication.SIMTASK + "?" + SimulationTasksServerResource.PARAM_SIM_ID + "=" + simRep.getKey().toString() + "&" + SimulationTasksServerResource.PARAM_STATUS_COMPLETED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_DISPATCHED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_FAILED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_QUEUED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_RUNNING + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_STOPPED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_WAITING + "=on" + "&" + SimulationTasksServerResource.PARAM_START_ROW + "=1" + "&" + SimulationTasksServerResource.PARAM_MAX_ROWS + "=" + Integer.toString(simRep.getScanCount() * 4));
        return representation;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized to start simulation");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "simulation not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) User(org.vcell.util.document.User) StringRepresentation(org.restlet.representation.StringRepresentation) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) StringRepresentation(org.restlet.representation.StringRepresentation) Representation(org.restlet.representation.Representation) ResourceException(org.restlet.resource.ResourceException) SimulationRep(cbit.vcell.modeldb.SimulationRep) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 8 with SimulationRep

use of cbit.vcell.modeldb.SimulationRep in project vcell by virtualcell.

the class BiomodelSimulationStopServerResource method stop.

@Override
public Representation stop() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    RestDatabaseService restDatabaseService = application.getRestDatabaseService();
    try {
        SimulationRep simRep = restDatabaseService.stopSimulation(this, vcellUser);
        Representation representation = new StringRepresentation("simulation stopped", MediaType.TEXT_PLAIN);
        redirectSeeOther("/" + VCellApiApplication.SIMTASK + "?" + SimulationTasksServerResource.PARAM_SIM_ID + "=" + simRep.getKey().toString() + "&" + SimulationTasksServerResource.PARAM_STATUS_COMPLETED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_DISPATCHED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_FAILED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_QUEUED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_RUNNING + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_STOPPED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_WAITING + "=on" + "&" + SimulationTasksServerResource.PARAM_START_ROW + "=1" + "&" + SimulationTasksServerResource.PARAM_MAX_ROWS + "=" + Integer.toString(simRep.getScanCount() * 4));
        return representation;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized to stop simulation");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "simulation not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) User(org.vcell.util.document.User) StringRepresentation(org.restlet.representation.StringRepresentation) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) StringRepresentation(org.restlet.representation.StringRepresentation) Representation(org.restlet.representation.Representation) ResourceException(org.restlet.resource.ResourceException) SimulationRep(cbit.vcell.modeldb.SimulationRep) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 9 with SimulationRep

use of cbit.vcell.modeldb.SimulationRep in project vcell by virtualcell.

the class RestDatabaseService method getDataSetTimeSeries.

public DataSetTimeSeries getDataSetTimeSeries(SimDataValuesServerResource resource, User vcellUser) throws DataAccessException, ObjectNotFoundException, SQLException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String simId = resource.getAttribute(VCellApiApplication.SIMDATAID);
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String jobIndexString = resource.getAttribute(VCellApiApplication.JOBINDEX);
    KeyValue simKey = new KeyValue(simId);
    SimulationRep simRep = getSimulationRep(simKey);
    if (simRep == null) {
        throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
    }
    int jobIndex = Integer.parseInt(jobIndexString);
    // TODO: pass in variables names from the query parameters.
    String[] variableNames = null;
    User owner = simRep.getOwner();
    VCMessageSession rpcSession = vcMessagingService.createProducerSession();
    try {
        RpcDataServerProxy rpcDataServerProxy = new RpcDataServerProxy(userLoginInfo, rpcSession);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
        VCDataIdentifier vcdID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
        DataSetTimeSeries dataSetTimeSeries = rpcDataServerProxy.getDataSetTimeSeries(vcdID, variableNames);
        return dataSetTimeSeries;
    } finally {
        rpcSession.close();
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) VCMessageSession(cbit.vcell.message.VCMessageSession) BigString(org.vcell.util.BigString) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) RpcDataServerProxy(org.vcell.rest.rpc.RpcDataServerProxy) DataSetTimeSeries(cbit.vcell.simdata.DataSetTimeSeries) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) UserLoginInfo(org.vcell.util.document.UserLoginInfo) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 10 with SimulationRep

use of cbit.vcell.modeldb.SimulationRep in project vcell by virtualcell.

the class RestDatabaseService method startSimulation.

public SimulationRep startSimulation(BiomodelSimulationStartServerResource resource, User vcellUser) throws PermissionException, ObjectNotFoundException, DataAccessException, SQLException {
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String simId = resource.getAttribute(VCellApiApplication.SIMULATIONID);
    KeyValue simKey = new KeyValue(simId);
    SimulationRep simRep = getSimulationRep(simKey);
    if (simRep == null) {
        throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
    }
    User owner = simRep.getOwner();
    if (!owner.compareEqual(vcellUser)) {
        throw new PermissionException("not authorized to start simulation");
    }
    VCMessageSession rpcSession = vcMessagingService.createProducerSession();
    try {
        UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
        try {
            userLoginInfo.setUser(vcellUser);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAccessException(e.getMessage());
        }
        RpcSimServerProxy rpcSimServerProxy = new RpcSimServerProxy(userLoginInfo, rpcSession);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
        rpcSimServerProxy.startSimulation(vcellUser, vcSimID, simRep.getScanCount());
        return simRep;
    } finally {
        rpcSession.close();
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) RpcSimServerProxy(org.vcell.rest.rpc.RpcSimServerProxy) VCMessageSession(cbit.vcell.message.VCMessageSession) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) BigString(org.vcell.util.BigString) UserLoginInfo(org.vcell.util.document.UserLoginInfo) SimulationRep(cbit.vcell.modeldb.SimulationRep) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) UseridIDExistsException(org.vcell.util.UseridIDExistsException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

SimulationRep (cbit.vcell.modeldb.SimulationRep)13 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)10 BigString (org.vcell.util.BigString)9 KeyValue (org.vcell.util.document.KeyValue)9 PermissionException (org.vcell.util.PermissionException)7 User (org.vcell.util.document.User)7 VCMessageSession (cbit.vcell.message.VCMessageSession)5 UserLoginInfo (org.vcell.util.document.UserLoginInfo)5 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)4 ArrayList (java.util.ArrayList)4 MappingException (cbit.vcell.mapping.MappingException)3 MathException (cbit.vcell.math.MathException)3 MatrixException (cbit.vcell.matrix.MatrixException)3 ModelException (cbit.vcell.model.ModelException)3 BioModelRep (cbit.vcell.modeldb.BioModelRep)3 SimContextRep (cbit.vcell.modeldb.SimContextRep)3 ExpressionException (cbit.vcell.parser.ExpressionException)3 XmlParseException (cbit.vcell.xml.XmlParseException)3 PropertyVetoException (java.beans.PropertyVetoException)3 SQLException (java.sql.SQLException)3