use of org.vcell.util.document.BioModelInfo in project vcell by virtualcell.
the class VCDatabaseScanner method scanBioModels.
/**
* Insert the method's description here.
* Creation date: (2/2/01 3:40:29 PM)
* @throws DataAccessException
* @throws XmlParseException
*/
public void scanBioModels(VCDatabaseVisitor databaseVisitor, PrintStream logFilePrintStream, User[] users, KeyValue singleModelKey, HashSet<KeyValue> includeHash, HashSet<KeyValue> excludeHash, boolean bAbortOnDataAccessException) throws DataAccessException, XmlParseException {
if (users == null) {
users = getAllUsers();
}
try {
// start visiting models and writing log
logFilePrintStream.println("Start scanning bio-models......");
logFilePrintStream.println("\n");
// adapter for verifyMathDescriptionsUnchanged
PrintWriter logFilePrintWriter = new PrintWriter(logFilePrintStream);
for (int i = 0; i < users.length; i++) {
User user = users[i];
BioModelInfo[] bioModelInfos = dbServerImpl.getBioModelInfos(user, false);
for (int j = 0; j < bioModelInfos.length; j++) {
if (singleModelKey != null && !bioModelInfos[j].getVersion().getVersionKey().compareEqual(singleModelKey)) {
System.out.println("skipping biomodel, not the single one that we wanted");
continue;
}
if (excludeHash != null && excludeHash.contains(bioModelInfos[j].getVersion().getVersionKey())) {
System.out.println("skipping bioModel with key '" + bioModelInfos[j].getVersion().getVersionKey() + "'");
continue;
}
if (includeHash != null && !includeHash.contains(bioModelInfos[j].getVersion().getVersionKey())) {
System.out.println("not including bioModel with key '" + bioModelInfos[j].getVersion().getVersionKey() + "'");
continue;
}
if (!databaseVisitor.filterBioModel(bioModelInfos[j])) {
continue;
}
try {
BigString bioModelXML = dbServerImpl.getBioModelXML(user, bioModelInfos[j].getVersion().getVersionKey());
BioModel bioModel = cbit.vcell.xml.XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
bioModel.refreshDependencies();
// + bioModelInfos[j].getVersion().getName() + " -----> ");
logFilePrintStream.println("---- " + (j + 1) + " ----> " + bioModel.getName());
databaseVisitor.visitBioModel(bioModel, logFilePrintStream);
// verifyMathDescriptionsUnchanged(bioModel, logFilePrintWriter);
} catch (Exception e2) {
lg.error(e2.getMessage(), e2);
logFilePrintStream.println("======= " + e2.getMessage());
if (bAbortOnDataAccessException) {
throw e2;
}
}
}
}
logFilePrintStream.close();
} catch (Exception e) {
e.printStackTrace();
System.err.println("error writing to log file.");
}
}
use of org.vcell.util.document.BioModelInfo in project vcell by virtualcell.
the class VCDatabaseScanner method multiScanBioModels.
/**
* Insert the method's description here.
* Creation date: (2/2/01 3:40:29 PM)
* @throws DataAccessException
* @throws XmlParseException
*/
public void multiScanBioModels(VCMultiBioVisitor databaseVisitor, Writer writer, User[] users, boolean bAbortOnDataAccessException) throws DataAccessException, XmlParseException {
assert users != null;
try {
PrintWriter printWriter = new PrintWriter(writer);
// start visiting models and writing log
printWriter.println("Start scanning bio-models......");
printWriter.println("\n");
for (int i = 0; i < users.length; i++) {
User user = users[i];
BioModelInfo[] bioModelInfos = dbServerImpl.getBioModelInfos(user, false);
for (int j = 0; j < bioModelInfos.length; j++) {
BioModelInfo bmi = bioModelInfos[j];
if (!databaseVisitor.filterBioModel(bmi)) {
continue;
}
try {
BigString bioModelXML = dbServerImpl.getBioModelXML(user, bmi.getVersion().getVersionKey());
BioModel storedModel = cbit.vcell.xml.XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
System.out.println(storedModel.getName());
if (databaseVisitor.filterBioModel(storedModel)) {
storedModel.refreshDependencies();
verifyMathDescriptionsUnchanged(storedModel, printWriter);
databaseVisitor.setBioModel(storedModel, printWriter);
// + bioModelInfos[j].getVersion().getName() + " -----> ");
printWriter.println("---- " + (j + 1) + " ----> " + storedModel.getName());
for (BioModel bioModel : databaseVisitor) {
SimulationContext[] simContexts = bioModel.getSimulationContexts();
for (SimulationContext sc : simContexts) {
try {
sc.createNewMathMapping().getMathDescription();
} catch (Exception e) {
printWriter.println("\t " + bioModel.getName() + " :: " + sc.getName() + " ----> math regeneration failed.s");
// e.printStackTrace();
}
}
}
}
} catch (Exception e2) {
lg.error(e2.getMessage(), e2);
printWriter.println("======= " + e2.getMessage());
if (bAbortOnDataAccessException) {
throw e2;
}
}
}
}
printWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.vcell.util.document.BioModelInfo in project vcell by virtualcell.
the class NagiosVCellCheck method checkVCell.
private static String checkVCell(VCELL_CHECK_LEVEL checkLevel, String rmiHostName, int rmiPort, String rmiBootstrapStubName, String vcellNagiosPassword, int warningTimeout, int criticalTimeout) throws Exception {
long startTime = System.currentTimeMillis();
SimulationStatusPersistent lastSimStatus = null;
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());
}
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");
}
VCellConnection vcellConnection = vcellBootstrap.getVCellConnection(new UserLoginInfo("vcellNagios", new DigestedPassword(vcellNagiosPassword)));
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.INFOS_2.ordinal()) {
VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
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 (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();
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);
// SimDataBlock simDataBlock = vcellConnection.getDataSetController().getSimDataBlock(outputContext, vcSimulationDataIdentifier, "RanC_cyt",times[times.length-1]);
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.RUN_5.ordinal()) {
KeyValue copy1Key = null;
KeyValue copy2Key = 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 + "_" + rmiPort;
for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
if (bioModelInfo.getVersion().getName().equals(copyModelName)) {
throw new UnexpectedTestStateException("Messy test environment, not expecting " + copyModelName + " to exist at this point");
}
}
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());
}
VCSimulationIdentifier newSimID = new VCSimulationIdentifier(newSimulation.getVersion().getVersionKey(), copyBioModel.getVersion().getOwner());
vcellConnection.getSimulationController().startSimulation(newSimID, 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(newSimID);
vcellConnection.getMessageEvents();
break;
}
simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
if (simulationStatus != null && !simulationStatus.toString().equals((lastSimStatus == null ? null : lastSimStatus.toString()))) {
lastSimStatus = simulationStatus;
}
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();
}
}
}
}
}
}
}
long endTime = System.currentTimeMillis();
if (criticalTimeout != -1 && ((endTime - startTime) / 1000) > criticalTimeout) {
throw new Exception(checkLevel.toString() + " test exceeded criticalTimeout=" + criticalTimeout + " seconds lastSimStatus=" + lastSimStatus);
}
if (warningTimeout != -1 && ((endTime - startTime) / 1000) > warningTimeout) {
throw new WarningTestConditionException(checkLevel.toString() + " test exceeded warningTimeout=" + warningTimeout + " seconds lastSimStatus=" + lastSimStatus);
}
return vcellBootstrap.getVCellSoftwareVersion();
}
use of org.vcell.util.document.BioModelInfo in project vcell by virtualcell.
the class BatchTester method keyScanBioModels.
/**
* scan biomodels for further processing, put into database table if criteria met
* @throws DataAccessException
* @throws XmlParseException
*/
public void keyScanBioModels(VCMultiBioVisitor databaseVisitor, Writer writer, User[] users, boolean bAbortOnDataAccessException, String statusTableName) throws DataAccessException, XmlParseException {
assert users != null;
try {
PrintWriter printWriter = new PrintWriter(writer);
// start visiting models and writing log
printWriter.println("Start scanning bio-models......");
printWriter.println("\n");
Object lock = new Object();
Connection conn = connFactory.getConnection(lock);
PreparedStatement ps = conn.prepareStatement("insert into " + statusTableName + "(user_id,model_id) values(?,?)");
for (int i = 0; i < users.length; i++) {
User user = users[i];
BioModelInfo[] bioModelInfos = dbServerImpl.getBioModelInfos(user, false);
for (int j = 0; j < bioModelInfos.length; j++) {
BioModelInfo bmi = bioModelInfos[j];
if (!databaseVisitor.filterBioModel(bmi)) {
continue;
}
try {
KeyValue vk = bmi.getVersion().getVersionKey();
ps.setLong(1, convert(user.getID()));
ps.setLong(2, convert(vk));
ps.execute();
} catch (Exception e2) {
lg.error(e2.getMessage(), e2);
printWriter.println("======= " + e2.getMessage());
if (bAbortOnDataAccessException) {
throw e2;
}
}
}
}
printWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations