use of cbit.rmi.event.MessageEvent in project vcell by virtualcell.
the class HybridSolverTester method runSim.
private static void runSim(UserLoginInfo userLoginInfo, VCSimulationIdentifier vcSimulationIdentifier, VCellConnectionHelper vcellConnectionHelper) throws Exception {
SimulationStatusPersistent simulationStatus = vcellConnectionHelper.getSimulationStatus(vcSimulationIdentifier.getSimulationKey());
System.out.println("initial status=" + simulationStatus);
if (simulationStatus != null && simulationStatus.isRunning()) /*!simulationStatus.isNeverRan() && !simulationStatus.isCompleted()*/
{
throw new Exception("Sim in unexpected state " + simulationStatus);
}
int intialMaxTaskID = vcellConnectionHelper.getMaxTaskID(simulationStatus);
BigString simXML = vcellConnectionHelper.getSimulationXML(vcSimulationIdentifier.getSimulationKey());
Simulation sim = XmlHelper.XMLToSim(simXML.toString());
int scanCount = sim.getScanCount();
vcellConnectionHelper.startSimulation(vcSimulationIdentifier, scanCount);
long startTime = System.currentTimeMillis();
// wait until sim has stopped running
while ((simulationStatus = vcellConnectionHelper.getSimulationStatus(vcSimulationIdentifier.getSimulationKey())) == null || (simulationStatus.isStopped() || simulationStatus.isCompleted() || simulationStatus.isFailed())) {
MessageEvent[] messageEvents = vcellConnectionHelper.getMessageEvents();
if (vcellConnectionHelper.getMaxTaskID(simulationStatus) > intialMaxTaskID) {
// new sim must have started
break;
}
Thread.sleep(250);
// }
if ((System.currentTimeMillis() - startTime) > 120000) {
throw new Exception("Sim finished too fast or took too long to start");
}
}
SimulationStatusPersistent lastSimStatus = simulationStatus;
while (!simulationStatus.isStopped() && !simulationStatus.isCompleted() && !simulationStatus.isFailed()) {
Thread.sleep(3000);
simulationStatus = vcellConnectionHelper.getSimulationStatus(vcSimulationIdentifier.getSimulationKey());
if (simulationStatus != null && !simulationStatus.toString().equals(lastSimStatus.toString())) {
lastSimStatus = simulationStatus;
System.out.println("running status=" + simulationStatus);
}
MessageEvent[] messageEvents = vcellConnectionHelper.getMessageEvents();
// for(int i = 0;i<(messageEvents==null?0:messageEvents.length);i++){
// System.out.println(messageEvents[i].toString());
// }
}
System.out.println("last run simStatus=" + simulationStatus);
}
use of cbit.rmi.event.MessageEvent in project vcell by virtualcell.
the class NagiosVCellMonitor method checkVCell.
private CheckResults checkVCell(VCELL_CHECK_LEVEL checkLevel, String rmiHostName, int rmiPort, String rmiBootstrapStubName, String vcellNagiosPassword, int criticalTimeout, int monitorPort) throws Exception {
SimulationStatusPersistent lastSimStatus = null;
String vcellVersion = null;
TreeMap<VCELL_CHECK_LEVEL, Long> levelTimesMillisec = new TreeMap<NagiosVCellMonitor.VCELL_CHECK_LEVEL, Long>();
long startTime = System.currentTimeMillis();
VCellConnection vcellConnection = null;
try {
if (rmiHostName == null || rmiPort == -1) {
throw new UnexpectedTestStateException("Host name/ip and rmiPort required for testing, rmihostname=" + rmiHostName + " rmiport=" + rmiPort);
}
String rmiUrl = "//" + rmiHostName + ":" + rmiPort + "/" + rmiBootstrapStubName;
VCellBootstrap vcellBootstrap = null;
try {
vcellBootstrap = (VCellBootstrap) Naming.lookup(rmiUrl);
} catch (Exception e) {
throw new UnexpectedTestStateException("Error during bootstrap lookup, " + e.getClass().getSimpleName() + " " + e.getMessage());
}
vcellVersion = vcellBootstrap.getVCellSoftwareVersion();
levelTimesMillisec.put(VCELL_CHECK_LEVEL.RMI_ONLY_0, System.currentTimeMillis() - startTime);
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.CONNECT_1.ordinal()) {
if (vcellNagiosPassword == null) {
throw new UnexpectedTestStateException("vcellNagios Password required for " + VCELL_CHECK_LEVEL.CONNECT_1.toString() + " and above");
}
UserLoginInfo userLoginInfo = new UserLoginInfo(VCELL_NAGIOS_USER, new DigestedPassword(vcellNagiosPassword));
vcellConnection = vcellBootstrap.getVCellConnection(userLoginInfo);
levelTimesMillisec.put(VCELL_CHECK_LEVEL.CONNECT_1, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.RMI_ONLY_0));
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.INFOS_2.ordinal()) {
VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
levelTimesMillisec.put(VCELL_CHECK_LEVEL.INFOS_2, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.CONNECT_1));
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.LOAD_3.ordinal()) {
KeyValue bioModelKey = null;
final String testModelName = "Solver Suite 5.1 (BETA only ode)";
for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
if (userLoginInfo.getUserName().equals(bioModelInfo.getVersion().getOwner().getName()) && bioModelInfo.getVersion().getName().equals(testModelName)) {
bioModelKey = bioModelInfo.getVersion().getVersionKey();
break;
}
}
BigString bioModelXML = vcellConnection.getUserMetaDbServer().getBioModelXML(bioModelKey);
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
bioModel.refreshDependencies();
levelTimesMillisec.put(VCELL_CHECK_LEVEL.LOAD_3, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.INFOS_2));
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.DATA_4.ordinal()) {
final String testSimContextName = "non-spatial ODE";
SimulationContext simulationContext = bioModel.getSimulationContext(testSimContextName);
final String testSimName = "Copy of combined ida/cvode";
Simulation simulation = simulationContext.getSimulation(testSimName);
if (simulation == null) {
throw new UnexpectedTestStateException("Couldn't find sim '" + testSimName + "' for " + checkLevel.toString());
}
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), 0);
ArrayList<AnnotatedFunction> outputFunctionsList = simulationContext.getOutputFunctionContext().getOutputFunctionsList();
OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
double[] times = vcellConnection.getDataSetController().getDataSetTimes(vcSimulationDataIdentifier);
ODESimData odeSimData = vcellConnection.getDataSetController().getODEData(vcSimulationDataIdentifier);
levelTimesMillisec.put(VCELL_CHECK_LEVEL.DATA_4, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.LOAD_3));
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.RUN_5.ordinal()) {
KeyValue copy1Key = null;
KeyValue copy2Key = null;
VCSimulationIdentifier testRunSimID = null;
try {
if (simulationContext.getSimulations().length != 1) {
throw new UnexpectedTestStateException("Expecting only 1 sim to be copied for " + checkLevel.toString());
}
SimulationStatusPersistent simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(simulation.getVersion().getVersionKey());
if (!simulationStatus.isCompleted()) {
throw new UnexpectedTestStateException("Expecting completed sim to copy for " + checkLevel.toString());
}
String copyModelName = testModelName + "_" + rmiHostName + "_rmi" + rmiPort + "_siteprt" + monitorPort;
boolean bForceCleanup = true;
while (true) {
boolean bMessy = false;
for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
if (userLoginInfo.getUserName().equals(bioModelInfo.getVersion().getOwner().getName()) && bioModelInfo.getVersion().getName().equals(copyModelName)) {
bMessy = true;
if (bForceCleanup) {
try {
vcellConnection.getUserMetaDbServer().deleteBioModel(bioModelInfo.getVersion().getVersionKey());
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new MessyTestEnvironmentException("Messy test environment, not expecting " + copyModelName + " and couldn't cleanup");
}
}
}
if (!bMessy) {
break;
}
// get new vcInfoContainer without cleaned-up model
vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
bForceCleanup = false;
}
BigString copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModelAs(bioModelXML, copyModelName, null);
BioModel copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
copy1Key = copyBioModel.getVersion().getVersionKey();
copyBioModel.refreshDependencies();
Simulation copySim = copyBioModel.getSimulationContext(testSimContextName).copySimulation(copyBioModel.getSimulationContext(testSimContextName).getSimulation(testSimName));
final String copyTestSimName = "test";
copySim.setName(copyTestSimName);
copyBioModel.refreshDependencies();
copyBioModelXMLStr = new BigString(XmlHelper.bioModelToXML(copyBioModel));
copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModel(copyBioModelXMLStr, null);
copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
copy2Key = copyBioModel.getVersion().getVersionKey();
copyBioModel.refreshDependencies();
Simulation newSimulation = copyBioModel.getSimulationContext(testSimContextName).getSimulation(copyTestSimName);
simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
if (simulationStatus != null && !simulationStatus.isNeverRan()) {
throw new UnexpectedTestStateException("Expecting new sim to have 'never ran' status for " + checkLevel.toString());
}
testRunSimID = new VCSimulationIdentifier(newSimulation.getVersion().getVersionKey(), copyBioModel.getVersion().getOwner());
vcellConnection.getSimulationController().startSimulation(testRunSimID, 1);
lastSimStatus = simulationStatus;
MessageEvent[] messageEvents = null;
while (simulationStatus == null || (!simulationStatus.isStopped() && !simulationStatus.isCompleted() && !simulationStatus.isFailed())) {
Thread.sleep(200);
if (((System.currentTimeMillis() - startTime) / 1000) > criticalTimeout) {
vcellConnection.getSimulationController().stopSimulation(testRunSimID);
vcellConnection.getMessageEvents();
break;
}
simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
if (simulationStatus != null && !simulationStatus.toString().equals((lastSimStatus == null ? null : lastSimStatus.toString()))) {
lastSimStatus = simulationStatus;
}
if (simulationStatus != null && simulationStatus.isFailed()) {
throw new Exception("time " + ((System.currentTimeMillis() - startTime) / 1000) + ", Sim execution failed key:" + testRunSimID.getSimulationKey() + " sim " + newSimulation.getName() + " model " + copyBioModel.getVersion().getName() + " messg " + simulationStatus.getFailedMessage());
}
messageEvents = vcellConnection.getMessageEvents();
}
} finally {
try {
if (copy1Key != null) {
vcellConnection.getUserMetaDbServer().deleteBioModel(copy1Key);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if (copy2Key != null) {
vcellConnection.getUserMetaDbServer().deleteBioModel(copy2Key);
}
} catch (Exception e) {
e.printStackTrace();
}
if (testRunSimID != null) {
deleteSimData(testRunSimID);
}
}
levelTimesMillisec.put(VCELL_CHECK_LEVEL.RUN_5, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.DATA_4));
}
}
}
}
}
return new CheckResults(vcellVersion, levelTimesMillisec, lastSimStatus, System.currentTimeMillis() - startTime, null);
} catch (Exception e) {
return new CheckResults(vcellVersion, levelTimesMillisec, lastSimStatus, System.currentTimeMillis() - startTime, e);
} finally {
vcellConnection = null;
}
}
use of cbit.rmi.event.MessageEvent in project vcell by virtualcell.
the class AsynchMessageManager method poll.
private void poll() {
if (!bPoll.get()) {
if (lg.isDebugEnabled()) {
lg.debug("polling stopped");
}
return;
}
if (lg.isDebugEnabled()) {
lg.debug("polling");
}
boolean report = counter % 50 == 0;
long begin = 0;
long end = 0;
//
try {
MessageEvent[] queuedEvents = null;
if (report) {
// time the call
begin = System.currentTimeMillis();
}
synchronized (this) {
if (!clientServerManager.isStatusConnected()) {
clientServerManager.attemptReconnect();
return;
}
pollTime = BASE_POLL_SECONDS;
queuedEvents = clientServerManager.getMessageEvents();
}
if (report) {
end = System.currentTimeMillis();
}
// this is skipped if the connection has failed:w
failureCount = 0;
// deal with events, if any
if (queuedEvents != null) {
for (MessageEvent messageEvent : queuedEvents) {
onMessageEvent(messageEvent);
}
}
// report polling call performance
if (report) {
double duration = ((double) (end - begin)) / 1000;
PerformanceMonitorEvent performanceMonitorEvent = new PerformanceMonitorEvent(this, null, new PerformanceData("AsynchMessageManager.poll()", MessageEvent.POLLING_STAT, new PerformanceDataEntry[] { new PerformanceDataEntry("remote call duration", Double.toString(duration)) }));
}
} catch (Exception exc) {
System.out.println(">> polling failure << " + exc.getMessage());
pollTime = ATTEMPT_POLL_SECONDS;
failureCount++;
if (failureCount % 3 == 0) {
bPoll.set(false);
clientServerManager.setDisconnected();
}
} finally {
if (lg.isDebugEnabled()) {
lg.debug(ExecutionTrace.justClassName(this) + " poll time " + pollTime + " seconds");
}
if (bPoll.get()) {
schedule(pollTime);
}
}
}
use of cbit.rmi.event.MessageEvent in project vcell by virtualcell.
the class TestMissingSimData method runSim.
private static void runSim(SimIDAndJobID simIDAndJobID) throws Exception {
if (notCompletedSimIDs.contains(simIDAndJobID.simID.toString())) {
// System.out.println("--skipping notCompleted");
return;
} else if (completedSimIDs.contains(simIDAndJobID.simID.toString())) {
System.out.println("-----unexpected sim rerun already completed once");
return;
}
VCSimulationIdentifier vcSimulationIdentifier = new VCSimulationIdentifier(simIDAndJobID.simID, simIDAndJobID.user);
UserLoginInfo userLoginInfo = new UserLoginInfo(simIDAndJobID.user.getName(), new DigestedPassword("xoxoxox"));
// getVcellClient().getClientServerManager().getConnectionStatus()
VCellConnection vcellConnection = userConnections.get(simIDAndJobID.user);
try {
if (vcellConnection != null) {
vcellConnection.getMessageEvents();
}
} catch (Exception e) {
e.printStackTrace();
// assume disconnected
vcellConnection = null;
}
if (vcellConnection == null) {
VCellBootstrap vCellBootstrap = getVCellBootstrap("rmi-alpha.cam.uchc.edu", 40106, "VCellBootstrapServer", 12, false);
vcellConnection = vCellBootstrap.getVCellConnection(userLoginInfo);
userConnections.put(simIDAndJobID.user, vcellConnection);
}
SimulationStatusPersistent finalSimStatus = null;
try {
SimulationStatusPersistent simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(vcSimulationIdentifier.getSimulationKey());
System.out.println("initial status=" + simulationStatus);
BigString simXML = vcellConnection.getUserMetaDbServer().getSimulationXML(vcSimulationIdentifier.getSimulationKey());
Simulation sim = XmlHelper.XMLToSim(simXML.toString());
SolverDescription solverDescription = sim.getSolverTaskDescription().getSolverDescription();
if (solverDescription.equals(SolverDescription.StochGibson) || solverDescription.equals(SolverDescription.FiniteVolume)) {
// These 2 solvers give too much trouble so skip
System.out.println("--skipping solver");
// notCompletedSimIDs.add(simIDAndJobID.simID.toString());
return;
}
int scanCount = sim.getScanCount();
vcellConnection.getSimulationController().startSimulation(vcSimulationIdentifier, scanCount);
long startTime = System.currentTimeMillis();
while (simulationStatus.isStopped() || simulationStatus.isCompleted() || simulationStatus.isFailed()) {
Thread.sleep(250);
simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(vcSimulationIdentifier.getSimulationKey());
MessageEvent[] messageEvents = vcellConnection.getMessageEvents();
if ((System.currentTimeMillis() - startTime) > 60000) {
System.out.println("-----Sim finished too fast or took too long to start");
return;
}
// System.out.println(simulationStatus);
}
SimulationStatusPersistent lastSimStatus = simulationStatus;
while (!simulationStatus.isStopped() && !simulationStatus.isCompleted() && !simulationStatus.isFailed()) {
Thread.sleep(3000);
simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(vcSimulationIdentifier.getSimulationKey());
if (!simulationStatus.toString().equals(lastSimStatus.toString())) {
lastSimStatus = simulationStatus;
System.out.println("running status=" + simulationStatus);
}
// System.out.println(simulationStatus);
MessageEvent[] messageEvents = vcellConnection.getMessageEvents();
// for (int i = 0; messageEvents != null && i < messageEvents.length; i++) {
// System.out.println(messageEvents[i]);
// }
}
finalSimStatus = simulationStatus;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
} finally {
System.out.println("final status=" + finalSimStatus + "\n");
if (finalSimStatus == null || !finalSimStatus.isCompleted()) {
notCompletedSimIDs.add(simIDAndJobID.simID.toString());
} else {
completedSimIDs.add(simIDAndJobID.simID.toString());
}
}
}
use of cbit.rmi.event.MessageEvent 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