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;
}
}
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());
}
}
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());
}
}
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();
}
}
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();
}
}
Aggregations