use of cbit.vcell.server.SimulationStatusPersistent in project vcell by virtualcell.
the class SimulationDatabaseDirect method getSimulationStatus.
@Override
public SimulationStatus[] getSimulationStatus(KeyValue[] simKeys) throws ObjectNotFoundException, DataAccessException {
SimulationStatusPersistent[] simStatusDbArray = databaseServerImpl.getSimulationStatus(simKeys);
ArrayList<SimulationStatus> simStatusList = new ArrayList<SimulationStatus>();
for (SimulationStatusPersistent simStatusDb : simStatusDbArray) {
if (simStatusDb != null) {
simStatusList.add(buildSimulationStatus(simStatusDb));
} else {
simStatusList.add(null);
}
}
return simStatusList.toArray(new SimulationStatus[0]);
}
use of cbit.vcell.server.SimulationStatusPersistent 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.vcell.server.SimulationStatusPersistent in project vcell by virtualcell.
the class MathVerifier method scanBioModels.
/**
* Insert the method's description here.
* Creation date: (2/2/01 3:40:29 PM)
*/
public void scanBioModels(boolean bUpdateDatabase, KeyValue[] bioModelKeys) throws MathException, MappingException, SQLException, DataAccessException, ModelException, ExpressionException {
java.util.Calendar calendar = java.util.GregorianCalendar.getInstance();
// calendar.set(2002,java.util.Calendar.MAY,7+1);
calendar.set(2002, java.util.Calendar.JULY, 1);
final java.util.Date fluxCorrectionOrDisablingBugFixDate = calendar.getTime();
// calendar.set(2001,java.util.Calendar.JUNE,13+1);
calendar.set(2002, java.util.Calendar.JANUARY, 1);
final java.util.Date totalVolumeCorrectionFixDate = calendar.getTime();
User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
for (int i = 0; i < bioModelKeys.length; i++) {
BioModelInfo bioModelInfo = dbServerImpl.getBioModelInfo(user, bioModelKeys[i]);
if (lg.isTraceEnabled())
lg.trace("Testing bioModel with key '" + bioModelKeys[i] + "'");
java.sql.Connection con = null;
java.sql.Statement stmt = null;
try {
//
// read in the BioModel from the database
//
BigString bioModelXML = dbServerImpl.getBioModelXML(user, bioModelInfo.getVersion().getVersionKey());
BioModel bioModelFromDB = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
BioModel bioModelNewMath = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
bioModelFromDB.refreshDependencies();
bioModelNewMath.refreshDependencies();
//
// get all Simulations for this model
//
Simulation[] modelSimsFromDB = bioModelFromDB.getSimulations();
//
// for each application, recompute mathDescription, and verify it is equivalent
// then check each associated simulation to ensure math overrides are applied in an equivalent manner also.
//
SimulationContext[] simContextsFromDB = bioModelFromDB.getSimulationContexts();
SimulationContext[] simContextsNewMath = bioModelNewMath.getSimulationContexts();
for (int k = 0; k < simContextsFromDB.length; k++) {
SimulationContext simContextFromDB = simContextsFromDB[k];
Simulation[] appSimsFromDB = simContextFromDB.getSimulations();
SimulationContext simContextNewMath = simContextsNewMath[k];
Simulation[] appSimsNewMath = simContextNewMath.getSimulations();
MathCompareResults mathCompareResults = null;
try {
MathDescription origMathDesc = simContextFromDB.getMathDescription();
//
// find out if any simulation belonging to this Application has data
//
boolean bApplicationHasData = false;
for (int l = 0; l < modelSimsFromDB.length; l++) {
SimulationStatusPersistent simulationStatus = dbServerImpl.getSimulationStatus(modelSimsFromDB[l].getKey());
if (simulationStatus != null && simulationStatus.getHasData()) {
bApplicationHasData = true;
}
}
//
try {
if (simContextNewMath.getGeometry().getDimension() > 0 && simContextNewMath.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
simContextNewMath.getGeometry().getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
//
// updated mathdescription loaded into copy of biomodel, then test for equivalence.
//
cbit.vcell.mapping.MathMapping mathMapping = simContextNewMath.createNewMathMapping();
MathDescription newMathDesc = mathMapping.getMathDescription();
String issueString = null;
org.vcell.util.Issue[] issues = mathMapping.getIssues();
if (issues != null && issues.length > 0) {
StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):");
for (int l = 0; l < issues.length; l++) {
buffer.append(" <<" + issues[l].toString() + ">>");
}
issueString = buffer.toString();
}
simContextNewMath.setMathDescription(newMathDesc);
MathCompareResults testIfSameResults = cbit.vcell.math.MathUtilities.testIfSame(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
StringBuffer buffer = new StringBuffer();
buffer.append(">>>BioModel(" + bioModelFromDB.getVersion().getVersionKey() + ") '" + bioModelFromDB.getName() + "':" + bioModelFromDB.getVersion().getDate() + ", Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "' <<EQUIV=" + mathCompareResults.isEquivalent() + ">>: " + mathCompareResults.toDatabaseStatus());
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.hasData.getUnqualifiedColName() + " = " + ((bApplicationHasData) ? (1) : (0)) + ", " + SimContextStat2Table.table.equiv.getUnqualifiedColName() + " = " + (mathCompareResults.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.toDatabaseStatus()) + "'" + ((issueString != null) ? (", " + SimContextStat2Table.table.comments.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(issueString, 255) + "'") : ("")) + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'newMath' for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE MATH for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
//
for (int l = 0; l < appSimsFromDB.length; l++) {
try {
boolean bSimEquivalent = Simulation.testEquivalency(appSimsNewMath[l], appSimsFromDB[l], mathCompareResults);
if (lg.isTraceEnabled())
lg.trace("Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "', " + "Simulation(" + modelSimsFromDB[l].getKey() + ") '" + modelSimsFromDB[l].getName() + "':" + modelSimsFromDB[l].getVersion().getDate() + "mathEquivalency=" + mathCompareResults.isEquivalent() + ", simEquivalency=" + bSimEquivalent);
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.equiv.getUnqualifiedColName() + " = " + ((bSimEquivalent) ? (1) : (0)) + ", " + SimStatTable.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.decision.description) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'simulation status for simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
}
}
} catch (Throwable e) {
// exception in whole BioModel
lg.error(e.getMessage(), e);
// can't update anything in database, since we don't know what simcontexts are involved
}
}
}
use of cbit.vcell.server.SimulationStatusPersistent in project vcell by virtualcell.
the class MathVerifier method scanSimContexts.
/**
* Insert the method's description here.
* Creation date: (2/2/01 3:40:29 PM)
*/
public void scanSimContexts(boolean bUpdateDatabase, KeyValue[] simContextKeys) throws MathException, MappingException, SQLException, DataAccessException, ModelException, ExpressionException {
java.util.Calendar calendar = java.util.GregorianCalendar.getInstance();
// calendar.set(2002,java.util.Calendar.MAY,7+1);
calendar.set(2002, java.util.Calendar.JULY, 1);
final java.util.Date fluxCorrectionOrDisablingBugFixDate = calendar.getTime();
// calendar.set(2001,java.util.Calendar.JUNE,13+1);
calendar.set(2002, java.util.Calendar.JANUARY, 1);
final java.util.Date totalVolumeCorrectionFixDate = calendar.getTime();
User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
for (int i = 0; i < simContextKeys.length; i++) {
if (lg.isTraceEnabled())
lg.trace("Testing SimContext with key '" + simContextKeys[i] + "'");
// get biomodel refs
java.sql.Connection con = null;
java.sql.Statement stmt = null;
con = conFactory.getConnection(new Object());
cbit.vcell.modeldb.BioModelSimContextLinkTable bmscTable = cbit.vcell.modeldb.BioModelSimContextLinkTable.table;
String sql = "SELECT " + bmscTable.bioModelRef.getQualifiedColName() + " FROM " + bmscTable.getTableName() + " WHERE " + bmscTable.simContextRef.getQualifiedColName() + " = " + simContextKeys[i];
java.util.Vector keys = new java.util.Vector();
stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
KeyValue key = new KeyValue(rset.getBigDecimal(bmscTable.bioModelRef.getUnqualifiedColName()));
keys.addElement(key);
}
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
KeyValue[] bmKeys = (org.vcell.util.document.KeyValue[]) org.vcell.util.BeanUtils.getArray(keys, org.vcell.util.document.KeyValue.class);
try {
// use the first biomodel...
BioModelInfo bioModelInfo = dbServerImpl.getBioModelInfo(user, bmKeys[0]);
//
// read in the BioModel from the database
//
BigString bioModelXML = dbServerImpl.getBioModelXML(user, bioModelInfo.getVersion().getVersionKey());
BioModel bioModelFromDB = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
BioModel bioModelNewMath = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
bioModelFromDB.refreshDependencies();
bioModelNewMath.refreshDependencies();
//
// get all Simulations for this model
//
Simulation[] modelSimsFromDB = bioModelFromDB.getSimulations();
//
// ---> only for the SimContext we started with...
// recompute mathDescription, and verify it is equivalent
// then check each associated simulation to ensure math overrides are applied in an equivalent manner also.
//
SimulationContext[] simContextsFromDB = bioModelFromDB.getSimulationContexts();
SimulationContext[] simContextsNewMath = bioModelNewMath.getSimulationContexts();
SimulationContext simContextFromDB = null;
SimulationContext simContextNewMath = null;
for (int k = 0; k < simContextsFromDB.length; k++) {
// find it...
if (simContextsFromDB[k].getKey().equals(simContextKeys[i])) {
simContextFromDB = simContextsFromDB[k];
simContextNewMath = simContextsNewMath[k];
break;
}
}
if (simContextFromDB == null) {
throw new RuntimeException("BioModel referred to by this SimContext does not contain this SimContext");
} else {
Simulation[] appSimsFromDB = simContextFromDB.getSimulations();
Simulation[] appSimsNewMath = simContextNewMath.getSimulations();
MathCompareResults mathCompareResults = null;
try {
MathDescription origMathDesc = simContextFromDB.getMathDescription();
//
// find out if any simulation belonging to this Application has data
//
boolean bApplicationHasData = false;
for (int l = 0; l < modelSimsFromDB.length; l++) {
SimulationStatusPersistent simulationStatus = dbServerImpl.getSimulationStatus(modelSimsFromDB[l].getKey());
if (simulationStatus != null && simulationStatus.getHasData()) {
bApplicationHasData = true;
}
}
//
try {
if (simContextNewMath.getGeometry().getDimension() > 0 && simContextNewMath.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
simContextNewMath.getGeometry().getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
//
// updated mathdescription loaded into copy of biomodel, then test for equivalence.
//
cbit.vcell.mapping.MathMapping mathMapping = simContextNewMath.createNewMathMapping();
MathDescription newMathDesc = mathMapping.getMathDescription();
String issueString = null;
org.vcell.util.Issue[] issues = mathMapping.getIssues();
if (issues != null && issues.length > 0) {
StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):");
for (int l = 0; l < issues.length; l++) {
buffer.append(" <<" + issues[l].toString() + ">>");
}
issueString = buffer.toString();
}
simContextNewMath.setMathDescription(newMathDesc);
MathCompareResults testIfSameResults = cbit.vcell.math.MathUtilities.testIfSame(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
StringBuffer buffer = new StringBuffer();
buffer.append(">>>BioModel(" + bioModelFromDB.getVersion().getVersionKey() + ") '" + bioModelFromDB.getName() + "':" + bioModelFromDB.getVersion().getDate() + ", Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "' <<EQUIV=" + mathCompareResults.isEquivalent() + ">>: " + mathCompareResults.toDatabaseStatus());
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.hasData.getUnqualifiedColName() + " = " + ((bApplicationHasData) ? (1) : (0)) + ", " + SimContextStat2Table.table.equiv.getUnqualifiedColName() + " = " + (mathCompareResults.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.toDatabaseStatus()) + "'" + ((issueString != null) ? (", " + SimContextStat2Table.table.comments.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(issueString, 255) + "'") : ("")) + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'newMath' for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE MATH for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
//
for (int l = 0; l < appSimsFromDB.length; l++) {
try {
boolean bSimEquivalent = Simulation.testEquivalency(appSimsNewMath[l], appSimsFromDB[l], mathCompareResults);
if (lg.isTraceEnabled())
lg.trace("Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "', " + "Simulation(" + modelSimsFromDB[l].getKey() + ") '" + modelSimsFromDB[l].getName() + "':" + modelSimsFromDB[l].getVersion().getDate() + "mathEquivalency=" + mathCompareResults.isEquivalent() + ", simEquivalency=" + bSimEquivalent);
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.equiv.getUnqualifiedColName() + " = " + ((bSimEquivalent) ? (1) : (0)) + ", " + SimStatTable.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.toDatabaseStatus()) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'simulation status for simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
}
}
} catch (Throwable e) {
// exception in whole BioModel
lg.error(e.getMessage(), e);
// update database, since we know the simcontext...
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = 'BIOMODEL EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'" + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextKeys[i];
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Application with key '" + simContextKeys[i] + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application with key '" + simContextKeys[i] + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
}
}
use of cbit.vcell.server.SimulationStatusPersistent in project vcell by virtualcell.
the class MathVerifier method checkMathForBioModel.
private void checkMathForBioModel(BigString bioModelXMLFromDB, BioModel bioModelFromDB, User user, boolean bUpdateDatabase) throws Exception {
BioModel bioModelNewMath = XmlHelper.XMLToBioModel(new XMLSource(bioModelXMLFromDB.toString()));
bioModelFromDB.refreshDependencies();
bioModelNewMath.refreshDependencies();
//
// get all Simulations for this model
//
Simulation[] modelSimsFromDB = bioModelFromDB.getSimulations();
//
// for each application, recompute mathDescription, and verify it is equivalent
// then check each associated simulation to ensure math overrides are applied in an equivalent manner also.
//
SimulationContext[] simContextsFromDB = bioModelFromDB.getSimulationContexts();
SimulationContext[] simContextsNewMath = bioModelNewMath.getSimulationContexts();
for (int k = 0; k < simContextsFromDB.length; k++) {
SimulationContext simContextFromDB = simContextsFromDB[k];
Simulation[] appSimsFromDB = simContextFromDB.getSimulations();
SimulationContext simContextNewMath = simContextsNewMath[k];
Simulation[] appSimsNewMath = simContextNewMath.getSimulations();
MathCompareResults mathCompareResults_latest = null;
MathCompareResults mathCompareResults_4_8 = null;
try {
MathDescription origMathDesc = simContextFromDB.getMathDescription();
//
// find out if any simulation belonging to this Application has data
//
boolean bApplicationHasData = false;
for (int l = 0; l < modelSimsFromDB.length; l++) {
SimulationStatusPersistent simulationStatus = dbServerImpl.getSimulationStatus(modelSimsFromDB[l].getKey());
if (simulationStatus != null && simulationStatus.getHasData()) {
bApplicationHasData = true;
}
}
//
try {
if (simContextNewMath.getGeometry().getDimension() > 0 && simContextNewMath.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
simContextNewMath.getGeometry().getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
//
// updated mathdescription loaded into copy of biomodel, then test for equivalence.
//
cbit.vcell.mapping.MathMapping mathMapping = simContextNewMath.createNewMathMapping();
MathDescription newMathDesc = mathMapping.getMathDescription();
String issueString = null;
org.vcell.util.Issue[] issues = mathMapping.getIssues();
if (issues != null && issues.length > 0) {
StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):");
for (int l = 0; l < issues.length; l++) {
buffer.append(" <<" + issues[l].toString() + ">>");
}
issueString = buffer.toString();
}
MathCompareResults testIfSameResult = cbit.vcell.math.MathUtilities.testIfSame(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
mathCompareResults_latest = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
System.out.println(">>>BioModel(" + bioModelFromDB.getVersion().getVersionKey() + ") '" + bioModelFromDB.getName() + "':" + bioModelFromDB.getVersion().getDate() + ", Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "' <<EQUIV=" + mathCompareResults_latest.isEquivalent() + ">>: " + mathCompareResults_latest.toDatabaseStatus());
MathDescription mathDesc_4_8 = null;
try {
mathDesc_4_8 = new MathMapping_4_8(simContextNewMath).getMathDescription();
mathCompareResults_4_8 = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, mathDesc_4_8);
} catch (Exception e) {
e.printStackTrace(System.out);
mathCompareResults_4_8 = new MathCompareResults(Decision.MathDifferent_FAILURE_UNKNOWN, e.getMessage());
}
simContextNewMath.setMathDescription(newMathDesc);
//
if (bUpdateDatabase) {
java.sql.Connection con = null;
java.sql.Statement stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.hasData.getUnqualifiedColName() + " = " + ((bApplicationHasData) ? (1) : (0)) + ", " + SimContextStat2Table.table.equiv.getUnqualifiedColName() + " = " + (mathCompareResults_latest.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults_latest.toDatabaseStatus(), 255) + "', " + SimContextStat2Table.table.equiv_4_8.getUnqualifiedColName() + " = " + (mathCompareResults_4_8.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status_4_8.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults_4_8.toDatabaseStatus(), 255) + "'" + // ((issueString!=null)?(", "+SimContextStat2Table.table.comments.getUnqualifiedColName()+" = '"+org.vcell.util.TokenMangler.getSQLEscapedString(issueString,255)+"'"):(""))+
" WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'newMath' for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE MATH for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
java.sql.Connection con = null;
java.sql.Statement stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = 'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'" + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
//
for (int l = 0; l < appSimsFromDB.length; l++) {
try {
boolean bSimEquivalent = Simulation.testEquivalency(appSimsNewMath[l], appSimsFromDB[l], mathCompareResults_latest);
if (lg.isTraceEnabled())
lg.trace("Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "', " + "Simulation(" + modelSimsFromDB[l].getKey() + ") '" + modelSimsFromDB[l].getName() + "':" + modelSimsFromDB[l].getVersion().getDate() + "mathEquivalency=" + mathCompareResults_latest.isEquivalent() + ", simEquivalency=" + bSimEquivalent);
//
if (bUpdateDatabase) {
java.sql.Connection con = null;
java.sql.Statement stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.equiv.getUnqualifiedColName() + " = " + ((bSimEquivalent) ? (1) : (0)) + ", " + SimStatTable.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults_latest.decision.description) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'simulation status for simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
java.sql.Connection con = null;
java.sql.Statement stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.status.getUnqualifiedColName() + " = 'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
}
}
}
Aggregations