use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationControllerImpl method stopSimulation.
/**
* This method was created by a SmartGuide.
* @throws JMSException
* @throws AuthenticationException
* @throws DataAccessException
* @throws SQLException
* @throws FileNotFoundException
* @exception java.rmi.RemoteException The exception description.
* @throws VCMessagingException
*/
public void stopSimulation(Simulation simulation) throws FileNotFoundException, SQLException, DataAccessException, AuthenticationException, JMSException, VCMessagingException {
LocalVCMessageListener localVCMessageListener = new LocalVCMessageListener() {
public void onLocalVCMessage(VCDestination destination, VCMessage objectMessage) {
String messageTypeProperty = VCMessagingConstants.MESSAGE_TYPE_PROPERTY;
String stopSimulationValue = MessageConstants.MESSAGE_TYPE_STOPSIMULATION_VALUE;
if (destination == VCellTopic.ClientStatusTopic && objectMessage.getObjectContent() instanceof SimulationJobStatus) {
onClientStatusTopic_SimulationJobStatus(objectMessage);
} else if (destination == VCellTopic.ServiceControlTopic && objectMessage.getStringProperty(messageTypeProperty).equals(stopSimulationValue)) {
lg.error("SimulationControllerImpl.stopSimulation() exercising serviceControl topic ... should be removed");
onServiceControlTopic_StopSimulation(objectMessage);
} else {
throw new RuntimeException("SimulationControllerImpl.startSimulation().objectMessageListener:: expecting message with SimulationJobStatus to topic " + VCellTopic.ClientStatusTopic.getName() + ": received \"" + objectMessage.show() + "\" on destination \"" + destination + "\"");
}
}
};
LocalVCMessageAdapter vcMessageSession = new LocalVCMessageAdapter(localVCMessageListener);
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simulation.getKey(), simulation.getVersion().getOwner());
simulationDispatcherEngine.onStopRequest(vcSimID, localVCellConnection.getUserLoginInfo().getUser(), simulationDatabase, vcMessageSession);
vcMessageSession.deliverAll();
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationControllerImpl method onSimJobQueue_SimulationTask.
private void onSimJobQueue_SimulationTask(VCMessage vcMessage) {
SimulationTask simTask = null;
try {
SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(vcMessage);
simTask = simTaskMessage.getSimulationTask();
LocalSolverController solverController = getOrCreateSolverController(simTask);
// can only start after updating the database is done
solverController.startSimulationJob();
} catch (Exception e) {
lg.error(e.getMessage(), e);
KeyValue simKey = simTask.getSimKey();
VCSimulationIdentifier vcSimID = simTask.getSimulationJob().getVCDataIdentifier().getVcSimID();
int jobIndex = simTask.getSimulationJob().getJobIndex();
int taskID = simTask.getTaskID();
SimulationJobStatus newJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, null, SchedulerStatus.FAILED, taskID, SimulationMessage.jobFailed(e.getMessage()), null, null);
SimulationJobStatusEvent event = new SimulationJobStatusEvent(this, Simulation.createSimulationID(simKey), newJobStatus, null, null, vcSimID.getOwner().getName());
fireSimulationJobStatusEvent(event);
}
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class AdminService method query.
public SimulationJobStatus[] query(SimpleJobStatusQuerySpec querySpec) throws ObjectNotFoundException, DataAccessException {
SimulationDatabase simDatabase = new SimulationDatabaseDirect(adminDbTop, dbServerImpl, false);
SimulationJobStatus[] resultList = simDatabase.queryJobs(querySpec);
return resultList;
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationDatabaseDirectTest method test.
@Test
public void test() {
try (ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory()) {
DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, conFactory.getKeyFactory());
AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
boolean bCache = false;
SimulationDatabaseDirect simulationDatabaseDirect = new SimulationDatabaseDirect(adminDbTopLevel, databaseServerImpl, bCache);
SimpleJobStatusQuerySpec querySpec = new SimpleJobStatusQuerySpec();
querySpec.submitLowMS = null;
querySpec.submitHighMS = null;
querySpec.startLowMS = null;
querySpec.startHighMS = null;
querySpec.endLowMS = null;
querySpec.endHighMS = null;
querySpec.startRow = 0;
querySpec.maxRows = 100;
querySpec.serverId = null;
querySpec.computeHost = null;
querySpec.userid = null;
querySpec.simId = null;
querySpec.jobId = null;
querySpec.taskId = null;
querySpec.hasData = null;
querySpec.waiting = true;
querySpec.queued = true;
querySpec.dispatched = true;
querySpec.running = true;
querySpec.completed = true;
querySpec.failed = true;
querySpec.stopped = true;
SimulationJobStatus[] resultList = simulationDatabaseDirect.queryJobs(querySpec);
Gson gson = new Gson();
for (SimulationJobStatus status : resultList) {
System.out.println(gson.toJson(status.toRep()));
}
// test that there are no repeated jobs
} catch (Exception e) {
e.printStackTrace();
fail("exception: " + e.getMessage());
}
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class HealthService method runsimLoop.
private void runsimLoop() {
try {
Thread.sleep(SIMULATION_LOOP_START_DELAY);
} catch (InterruptedException e1) {
}
UserLoginInfo userLoginInfo = new UserLoginInfo(testUserid, testPassword);
while (true) {
long id = simStartEvent();
KeyValue savedBioModelKey = null;
VCSimulationIdentifier runningSimId = null;
try {
RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, userLoginInfo);
VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection();
String vcmlString = IOUtils.toString(getClass().getResourceAsStream("/TestTemplate.vcml"));
BioModel templateBioModel = XmlHelper.XMLToBioModel(new XMLSource(vcmlString));
templateBioModel.clearVersion();
String newBiomodelName = "test_" + System.currentTimeMillis();
templateBioModel.setName(newBiomodelName);
// remove all existing simulations from stored template model, and add new one
while (templateBioModel.getNumSimulations() > 0) {
templateBioModel.removeSimulation(templateBioModel.getSimulation(0));
}
MathMappingCallback callback = new MathMappingCallback() {
@Override
public void setProgressFraction(float fractionDone) {
}
@Override
public void setMessage(String message) {
}
@Override
public boolean isInterrupted() {
return false;
}
};
templateBioModel.getSimulationContext(0).addNewSimulation("sim", callback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
BigString vcml = new BigString(XmlHelper.bioModelToXML(templateBioModel));
String[] independentSims = new String[0];
BigString savedBioModelVCML = vcellConnection.getUserMetaDbServer().saveBioModelAs(vcml, newBiomodelName, independentSims);
BioModel savedBioModel = XmlHelper.XMLToBioModel(new XMLSource(savedBioModelVCML.toString()));
savedBioModelKey = savedBioModel.getVersion().getVersionKey();
Simulation sim = savedBioModel.getSimulation(0);
VCSimulationIdentifier vcSimId = new VCSimulationIdentifier(sim.getKey(), sim.getVersion().getOwner());
long eventTimestamp = System.currentTimeMillis();
SimulationStatus simStatus = vcellConnection.getSimulationController().startSimulation(vcSimId, 1);
simSubmitEvent(id, vcSimId);
runningSimId = vcSimId;
long startTime_MS = System.currentTimeMillis();
while (simStatus.isActive()) {
if ((System.currentTimeMillis() - startTime_MS) > SIMULATION_TIMEOUT) {
throw new RuntimeException("simulation took longer than " + SIMULATION_TIMEOUT + " to complete");
}
Thread.sleep(1000);
MessageEvent[] messageEvents = vcellConnection.getMessageEvents();
if (messageEvents != null) {
for (MessageEvent event : messageEvents) {
if (event instanceof SimulationJobStatusEvent) {
SimulationJobStatusEvent jobEvent = (SimulationJobStatusEvent) event;
SimulationJobStatus jobStatus = jobEvent.getJobStatus();
VCSimulationIdentifier eventSimId = jobStatus.getVCSimulationIdentifier();
if (eventSimId.getOwner().equals(userLoginInfo.getUser()) && eventSimId.getSimulationKey().equals(sim.getKey())) {
simStatus = SimulationStatus.updateFromJobEvent(simStatus, jobEvent);
}
}
}
}
}
runningSimId = null;
if (!simStatus.isCompleted()) {
throw new RuntimeException("failed: " + simStatus.getDetails());
}
simSuccess(id);
} catch (Throwable e) {
simFailed(id, e.getMessage());
} finally {
// cleanup
try {
RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, userLoginInfo);
VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection();
if (runningSimId != null) {
try {
vcellConnection.getSimulationController().stopSimulation(runningSimId);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
if (savedBioModelKey != null) {
vcellConnection.getUserMetaDbServer().deleteBioModel(savedBioModelKey);
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
try {
Thread.sleep(SIMULATION_LOOP_SLEEP);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Aggregations