Search in sources :

Example 1 with RpcSimServerProxy

use of org.vcell.rest.rpc.RpcSimServerProxy in project vcell by virtualcell.

the class RestDatabaseService method query.

public SimpleJobStatus[] query(SimulationTasksServerResource resource, User vcellUser) throws SQLException, DataAccessException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    String userID = vcellUser.getName();
    SimpleJobStatusQuerySpec simQuerySpec = new SimpleJobStatusQuerySpec();
    simQuerySpec.userid = userID;
    simQuerySpec.simId = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_SIM_ID);
    simQuerySpec.jobId = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_JOB_ID);
    simQuerySpec.taskId = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_TASK_ID);
    simQuerySpec.computeHost = resource.getQueryValue(SimulationTasksServerResource.PARAM_COMPUTE_HOST);
    simQuerySpec.serverId = resource.getQueryValue(SimulationTasksServerResource.PARAM_SERVER_ID);
    String hasData = resource.getQueryValue(SimulationTasksServerResource.PARAM_HAS_DATA);
    if (hasData != null && hasData.equals("yes")) {
        simQuerySpec.hasData = true;
    } else if (hasData != null && hasData.equals("no")) {
        simQuerySpec.hasData = false;
    } else {
        simQuerySpec.hasData = null;
    }
    simQuerySpec.waiting = resource.getBooleanQueryValue(SimulationTasksServerResource.PARAM_STATUS_WAITING, false);
    simQuerySpec.queued = resource.getBooleanQueryValue(SimulationTasksServerResource.PARAM_STATUS_QUEUED, false);
    simQuerySpec.dispatched = resource.getBooleanQueryValue(SimulationTasksServerResource.PARAM_STATUS_DISPATCHED, false);
    simQuerySpec.running = resource.getBooleanQueryValue(SimulationTasksServerResource.PARAM_STATUS_RUNNING, false);
    simQuerySpec.completed = resource.getBooleanQueryValue(SimulationTasksServerResource.PARAM_STATUS_COMPLETED, false);
    simQuerySpec.failed = resource.getBooleanQueryValue(SimulationTasksServerResource.PARAM_STATUS_FAILED, false);
    simQuerySpec.stopped = resource.getBooleanQueryValue(SimulationTasksServerResource.PARAM_STATUS_STOPPED, false);
    simQuerySpec.submitLowMS = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_SUBMIT_LOW);
    simQuerySpec.submitHighMS = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_SUBMIT_HIGH);
    simQuerySpec.startLowMS = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_START_LOW);
    simQuerySpec.startHighMS = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_START_HIGH);
    simQuerySpec.endLowMS = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_END_LOW);
    simQuerySpec.endHighMS = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_END_HIGH);
    Long startRowParam = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_START_ROW);
    // default
    simQuerySpec.startRow = 1;
    if (startRowParam != null) {
        simQuerySpec.startRow = startRowParam.intValue();
    }
    Long maxRowsParam = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_MAX_ROWS);
    // default
    simQuerySpec.maxRows = 10;
    if (maxRowsParam != null) {
        simQuerySpec.maxRows = maxRowsParam.intValue();
    }
    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);
        SimpleJobStatus[] simpleJobStatusArray = rpcSimServerProxy.getSimpleJobStatus(vcellUser, simQuerySpec);
        return simpleJobStatusArray;
    } finally {
        rpcSession.close();
    }
}
Also used : SimpleJobStatusQuerySpec(cbit.vcell.server.SimpleJobStatusQuerySpec) RpcSimServerProxy(org.vcell.rest.rpc.RpcSimServerProxy) VCMessageSession(cbit.vcell.message.VCMessageSession) BigString(org.vcell.util.BigString) UserLoginInfo(org.vcell.util.document.UserLoginInfo) 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) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus)

Example 2 with RpcSimServerProxy

use of org.vcell.rest.rpc.RpcSimServerProxy in project vcell by virtualcell.

the class RestDatabaseService method query.

public SimulationStatusRepresentation[] query(SimulationStatusServerResource resource, User vcellUser) throws SQLException, DataAccessException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    String userID = vcellUser.getName();
    SimpleJobStatusQuerySpec simQuerySpec = new SimpleJobStatusQuerySpec();
    simQuerySpec.userid = userID;
    simQuerySpec.simId = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_SIM_ID);
    String hasData = resource.getQueryValue(SimulationStatusServerResource.PARAM_HAS_DATA);
    if (hasData != null && hasData.equals("yes")) {
        simQuerySpec.hasData = true;
    } else if (hasData != null && hasData.equals("no")) {
        simQuerySpec.hasData = false;
    } else {
        simQuerySpec.hasData = null;
    }
    simQuerySpec.waiting = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
    simQuerySpec.queued = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
    simQuerySpec.dispatched = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
    simQuerySpec.running = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
    simQuerySpec.completed = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_COMPLETED, false);
    simQuerySpec.failed = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_FAILED, false);
    simQuerySpec.stopped = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_STOPPED, false);
    simQuerySpec.submitLowMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_SUBMIT_LOW);
    simQuerySpec.submitHighMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_SUBMIT_HIGH);
    simQuerySpec.startLowMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_START_LOW);
    simQuerySpec.startHighMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_START_HIGH);
    simQuerySpec.endLowMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_END_LOW);
    simQuerySpec.endHighMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_END_HIGH);
    Long startRowParam = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_START_ROW);
    // default
    simQuerySpec.startRow = 1;
    if (startRowParam != null) {
        simQuerySpec.startRow = startRowParam.intValue();
    }
    Long maxRowsParam = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_MAX_ROWS);
    // default
    simQuerySpec.maxRows = 10;
    if (maxRowsParam != null) {
        simQuerySpec.maxRows = maxRowsParam.intValue();
    }
    SimulationStatus[] simStatuses = null;
    HashMap<KeyValue, SimulationDocumentLink> simDocLinks = new HashMap<KeyValue, SimulationDocumentLink>();
    // 
    // ask server for simJobStatuses with above query spec.
    // find set of simulation IDs from the result set of simJobStatus
    // ask server for simulationStatuses from list of sim IDs.
    // 
    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);
        SimpleJobStatus[] simpleJobStatusArray = rpcSimServerProxy.getSimpleJobStatus(vcellUser, simQuerySpec);
        // gather unique simIDs and go back and ask server for SimulationStatuses
        for (SimpleJobStatus simpleJobStatus : simpleJobStatusArray) {
            KeyValue simulationKey = simpleJobStatus.jobStatus.getVCSimulationIdentifier().getSimulationKey();
            SimulationDocumentLink simulationDocumentLink = simpleJobStatus.simulationDocumentLink;
            simDocLinks.put(simulationKey, simulationDocumentLink);
        }
        KeyValue[] simKeys = simDocLinks.keySet().toArray(new KeyValue[0]);
        if (simKeys.length > 0) {
            simStatuses = rpcSimServerProxy.getSimulationStatus(vcellUser, simKeys);
        }
    } finally {
        rpcSession.close();
    }
    ArrayList<SimulationStatusRepresentation> simStatusReps = new ArrayList<SimulationStatusRepresentation>();
    for (int i = 0; simStatuses != null && i < simStatuses.length; i++) {
        KeyValue simulationKey = simStatuses[i].getVCSimulationIdentifier().getSimulationKey();
        SimulationRep simRep = getSimulationRep(simulationKey);
        try {
            SimulationRepresentation simRepresentation = new SimulationRepresentation(simRep, simDocLinks.get(simulationKey));
            simStatusReps.add(new SimulationStatusRepresentation(simRepresentation, simStatuses[i]));
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
        }
    }
    return simStatusReps.toArray(new SimulationStatusRepresentation[0]);
}
Also used : SimpleJobStatusQuerySpec(cbit.vcell.server.SimpleJobStatusQuerySpec) KeyValue(org.vcell.util.document.KeyValue) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RpcSimServerProxy(org.vcell.rest.rpc.RpcSimServerProxy) VCMessageSession(cbit.vcell.message.VCMessageSession) ArrayList(java.util.ArrayList) BigString(org.vcell.util.BigString) 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) ExpressionException(cbit.vcell.parser.ExpressionException) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) SimulationDocumentLink(cbit.vcell.server.SimulationDocumentLink) SimulationStatus(cbit.vcell.server.SimulationStatus) UserLoginInfo(org.vcell.util.document.UserLoginInfo) DataAccessException(org.vcell.util.DataAccessException) SimulationRep(cbit.vcell.modeldb.SimulationRep) SimulationStatusRepresentation(org.vcell.rest.common.SimulationStatusRepresentation)

Example 3 with RpcSimServerProxy

use of org.vcell.rest.rpc.RpcSimServerProxy 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)

Example 4 with RpcSimServerProxy

use of org.vcell.rest.rpc.RpcSimServerProxy in project vcell by virtualcell.

the class RestDatabaseService method stopSimulation.

public SimulationRep stopSimulation(BiomodelSimulationStopServerResource 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 stop 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.stopSimulation(vcellUser, vcSimID);
        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

MappingException (cbit.vcell.mapping.MappingException)4 MathException (cbit.vcell.math.MathException)4 MatrixException (cbit.vcell.matrix.MatrixException)4 VCMessageSession (cbit.vcell.message.VCMessageSession)4 ModelException (cbit.vcell.model.ModelException)4 ExpressionException (cbit.vcell.parser.ExpressionException)4 XmlParseException (cbit.vcell.xml.XmlParseException)4 PropertyVetoException (java.beans.PropertyVetoException)4 SQLException (java.sql.SQLException)4 RpcSimServerProxy (org.vcell.rest.rpc.RpcSimServerProxy)4 BigString (org.vcell.util.BigString)4 DataAccessException (org.vcell.util.DataAccessException)4 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)4 PermissionException (org.vcell.util.PermissionException)4 UseridIDExistsException (org.vcell.util.UseridIDExistsException)4 UserLoginInfo (org.vcell.util.document.UserLoginInfo)4 SimulationRep (cbit.vcell.modeldb.SimulationRep)3 KeyValue (org.vcell.util.document.KeyValue)3 SimpleJobStatus (cbit.vcell.server.SimpleJobStatus)2 SimpleJobStatusQuerySpec (cbit.vcell.server.SimpleJobStatusQuerySpec)2