use of org.vcell.util.BigString in project vcell by virtualcell.
the class ClientDocumentManager method save.
/**
* Insert the method's description here.
* Creation date: (10/28/00 12:08:30 AM)
*/
public Geometry save(Geometry geometry) throws DataAccessException {
try {
String geometryXML = null;
try {
geometryXML = XmlHelper.geometryToXML(geometry);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
String savedGeometryXML = sessionManager.getUserMetaDbServer().saveGeometry(new BigString(geometryXML)).toString();
Geometry savedGeometry = getGeometryFromDatabaseXML(savedGeometryXML);
KeyValue savedKey = savedGeometry.getVersion().getVersionKey();
if (xmlHash.get(savedKey) == null) {
xmlHash.put(savedKey, savedGeometryXML);
}
updateGeometryRelatedHashes(savedGeometry);
return savedGeometry;
} catch (RemoteProxyException e) {
e.printStackTrace(System.out);
throw new DataAccessException(VCellErrorMessages.FAIL_SAVE_MESSAGE + "\n\n" + e.getMessage());
}
}
use of org.vcell.util.BigString 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 org.vcell.util.BigString 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 org.vcell.util.BigString in project vcell by virtualcell.
the class BatchTester method batchScanBioModels.
@SuppressWarnings("static-access")
public void batchScanBioModels(VCMultiBioVisitor databaseVisitor, String statusTable, int chunkSize) throws DataAccessException, XmlParseException, SQLException, IOException {
PrintStream current = System.out;
// System.setOut(new PrintStream(new NullStream()));
try {
String processHostId = ManagementFactory.getRuntimeMXBean().getName();
String filename = processHostId + ".txt";
FileOutputStream fos = new FileOutputStream(filename);
System.setOut(new PrintStream(fos));
OutputStreamWriter writer = new OutputStreamWriter(fos);
// autoflush
PrintWriter printWriter = new PrintWriter(writer, true);
Connection conn = connFactory.getConnection(null);
conn.setAutoCommit(true);
printWriter.println("reserving slots");
try (Statement statement = conn.createStatement()) {
String query = "Update " + statusTable + " set scan_process = '" + processHostId + "', log_file = '" + filename + "' where scanned = 0 and scan_process is null and rownum <= " + chunkSize;
int uCount = statement.executeUpdate(query);
if (uCount > chunkSize) {
throw new Error("logic / SQL bad");
}
if (uCount == 0) {
printWriter.println("No models to scan, exiting");
System.exit(100);
}
}
printWriter.println("finding ours");
ArrayList<BioModelIdent> models = new ArrayList<BatchTester.BioModelIdent>();
try (Statement statement = conn.createStatement()) {
String query = "Select id, user_id, model_id from " + statusTable + " where scan_process ='" + processHostId + "' and scanned = 0";
ResultSet rs = statement.executeQuery(query);
while (rs.next()) {
BioModelIdent mi = new BioModelIdent(rs);
models.add(mi);
printWriter.println("claiming " + mi.statusId);
}
}
try {
// start visiting models and writing log
printWriter.println("Start scanning bio-models......");
printWriter.println("\n");
PreparedStatement ps = conn.prepareStatement("Update " + statusTable + " set scanned = 1, good = ? , exception_type = ?, exception = ?, scan_process = null where id = ?");
for (BioModelIdent modelIdent : models) {
ScanStatus scanStatus = ScanStatus.PASS;
String exceptionMessage = null;
String exceptionClass = null;
try {
User user = new User("", convert(modelIdent.userId));
KeyValue modelKey = convert(modelIdent.modelId);
BigString bioModelXML = null;
// seconds
long dbSleepTime = 10;
while (bioModelXML == null) {
try {
bioModelXML = dbServerImpl.getBioModelXML(user, modelKey);
} catch (DataAccessException dae) {
Throwable cause = dae.getCause();
if (cause.getClass().getSimpleName().equals("UniversalConnectionPoolException")) {
printWriter.println("No db connection for " + modelIdent.statusId + ", sleeping " + dbSleepTime + " seconds");
Thread.currentThread().sleep(dbSleepTime * 1000);
// wait a little longer next time
dbSleepTime *= 1.5;
} else {
// other exception, just rethrow
throw dae;
}
}
}
BioModel storedModel = cbit.vcell.xml.XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
if (databaseVisitor.filterBioModel(storedModel)) {
storedModel.refreshDependencies();
boolean goodModel = verifyMathDescriptionsUnchanged(storedModel, printWriter);
if (goodModel) {
printWriter.println("Model for " + modelIdent.statusId + " good");
databaseVisitor.setBioModel(storedModel, printWriter);
for (BioModel bioModel : databaseVisitor) {
SimulationContext[] simContexts = bioModel.getSimulationContexts();
for (SimulationContext sc : simContexts) {
// try {
// long start = System.currentTimeMillis();
sc.createNewMathMapping().getMathDescription();
// long end = System.currentTimeMillis();
// printWriter.println("mapping took " + (end - start)/1000.0 + " sec ");
/*
} catch (Exception e) {
//printWriter.println("\t " + bioModel.getName() + " :: " + sc.getName() + " ----> math regeneration failed.s");
// e.printStackTrace();
}
*/
}
}
} else {
throw new MathRegenFail();
}
} else {
scanStatus = ScanStatus.FILTERED;
}
} catch (Exception e) {
lg.error(e.getMessage(), e);
scanStatus = ScanStatus.FAIL;
exceptionClass = e.getClass().getName();
exceptionMessage = e.getMessage();
printWriter.println("failed " + modelIdent.statusId);
e.printStackTrace(printWriter);
}
ps.setInt(1, scanStatus.code);
ps.setString(2, exceptionClass);
ps.setString(3, exceptionMessage);
ps.setLong(4, modelIdent.statusId);
boolean estat = ps.execute();
if (estat) {
throw new Error("logic");
}
int uc = ps.getUpdateCount();
if (uc != 1) {
throw new Error("logic / sql ");
}
}
} catch (Exception e) {
e.printStackTrace(printWriter);
}
printWriter.close();
} finally {
System.setOut(current);
}
}
use of org.vcell.util.BigString in project vcell by virtualcell.
the class BatchTester method batchScanMathModels.
@SuppressWarnings("static-access")
public void batchScanMathModels(BadMathVisitor databaseVisitor, String statusTable, int chunkSize) throws DataAccessException, XmlParseException, SQLException, IOException {
PrintStream current = System.out;
// System.setOut(new PrintStream(new NullStream()));
try {
String processHostId = ManagementFactory.getRuntimeMXBean().getName();
String filename = processHostId + ".txt";
FileOutputStream fos = new FileOutputStream(filename);
System.setOut(new PrintStream(fos));
OutputStreamWriter writer = new OutputStreamWriter(fos);
// autoflush
PrintWriter printWriter = new PrintWriter(writer, true);
Connection conn = connFactory.getConnection(null);
conn.setAutoCommit(true);
printWriter.println("reserving slots");
try (Statement statement = conn.createStatement()) {
String query = "Update " + statusTable + " set scan_process = '" + processHostId + "', log_file = '" + filename + "' where scanned = 0 and scan_process is null and rownum <= " + chunkSize;
int uCount = statement.executeUpdate(query);
if (uCount > chunkSize) {
throw new Error("logic / SQL bad");
}
if (uCount == 0) {
printWriter.println("No models to scan, exiting");
System.exit(100);
}
}
printWriter.println("finding ours");
ArrayList<MathModelIdent> models = new ArrayList<BatchTester.MathModelIdent>();
try (Statement statement = conn.createStatement()) {
String query = "Select model_id from " + statusTable + " where scan_process ='" + processHostId + "' and scanned = 0";
ResultSet rs = statement.executeQuery(query);
while (rs.next()) {
MathModelIdent mmi = new MathModelIdent(rs);
models.add(mmi);
printWriter.println("claiming " + mmi.id);
}
}
try {
// start visiting models and writing log
printWriter.println("Start scanning math-models......");
printWriter.println("\n");
PreparedStatement ps = conn.prepareStatement("Update " + statusTable + " set scanned = 1, good = ? , exception_type = ?, exception = ?, scan_process = null where model_id = ?");
for (MathModelIdent modelIdent : models) {
ScanStatus scanStatus = ScanStatus.PASS;
String exceptionMessage = null;
String exceptionClass = null;
try {
KeyValue modelKey = convert(modelIdent.id);
BigString mathModelXML = null;
// seconds
long dbSleepTime = 10;
while (mathModelXML == null) {
try {
mathModelXML = dbServerImpl.getMathModelXML(BatchTester.ADMINISTRATOR, modelKey);
} catch (DataAccessException dae) {
Throwable cause = dae.getCause();
if (cause.getClass().getSimpleName().equals("UniversalConnectionPoolException")) {
printWriter.println("No db connection for " + modelIdent.id + ", sleeping " + dbSleepTime + " seconds");
Thread.currentThread().sleep(dbSleepTime * 1000);
// wait a little longer next time
dbSleepTime *= 1.5;
} else {
// other exception, just rethrow
throw dae;
}
}
}
MathModel storedModel = cbit.vcell.xml.XmlHelper.XMLToMathModel(new XMLSource(mathModelXML.toString()));
databaseVisitor.visitMathModel(storedModel, System.out);
} catch (Exception e) {
lg.error(e.getMessage(), e);
scanStatus = ScanStatus.FAIL;
exceptionClass = e.getClass().getName();
exceptionMessage = e.getMessage();
printWriter.println("failed " + modelIdent.id);
e.printStackTrace(printWriter);
}
ps.setInt(1, scanStatus.code);
ps.setString(2, exceptionClass);
ps.setString(3, exceptionMessage);
ps.setLong(4, modelIdent.id);
boolean estat = ps.execute();
if (estat) {
throw new Error("logic");
}
int uc = ps.getUpdateCount();
if (uc != 1) {
throw new Error("logic / sql ");
}
printWriter.println("model " + modelIdent.id + " " + scanStatus);
}
printWriter.close();
} finally {
System.setOut(current);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations