use of cbit.rmi.event.SimulationJobStatusEvent 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();
}
}
}
use of cbit.rmi.event.SimulationJobStatusEvent in project vcell by virtualcell.
the class VCMongoMessage method sendClientMessageEventsDelivered.
public static void sendClientMessageEventsDelivered(MessageEvent[] messageEvents, UserLoginInfo userLoginInfo) {
if (!enabled || messageEvents == null) {
return;
}
for (MessageEvent messageEvent : messageEvents) {
if (messageEvent instanceof SimulationJobStatusEvent) {
try {
Document dbObject = new Document();
addHeader(dbObject, MongoMessage_msgtype_clientSimStatusDelivered);
addObject(dbObject, (SimulationJobStatusEvent) messageEvent);
addObject(dbObject, userLoginInfo);
VCMongoDbDriver.getInstance().addMessage(new VCMongoMessage(dbObject));
} catch (Exception e) {
lg.error(e.getMessage(), e);
}
}
}
}
use of cbit.rmi.event.SimulationJobStatusEvent in project vcell by virtualcell.
the class SimulationControllerImpl method onServiceControlTopic_StopSimulation.
private void onServiceControlTopic_StopSimulation(VCMessage message) {
KeyValue simKey = new KeyValue(String.valueOf(message.getLongProperty(MessageConstants.SIMKEY_PROPERTY)));
int jobIndex = message.getIntProperty(MessageConstants.JOBINDEX_PROPERTY);
int taskID = message.getIntProperty(MessageConstants.TASKID_PROPERTY);
try {
SimulationTaskID simTaskInfo = new SimulationTaskID(simKey, jobIndex, taskID);
LocalSolverController solverController = solverControllerHash.get(simTaskInfo);
if (solverController != null) {
// can only start after updating the database is done
solverController.stopSimulationJob();
}
} catch (Exception e) {
lg.error(e.getMessage(), e);
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, localVCellConnection.getUserLoginInfo().getUser());
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);
}
}
Aggregations