Search in sources :

Example 56 with XMLSource

use of cbit.vcell.xml.XMLSource 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();
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) MessageEvent(cbit.rmi.event.MessageEvent) VCellBootstrap(cbit.vcell.server.VCellBootstrap) BigString(org.vcell.util.BigString) ODESimData(cbit.vcell.solver.ode.ODESimData) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) BigString(org.vcell.util.BigString) VCInfoContainer(org.vcell.util.document.VCInfoContainer) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) VCellConnection(cbit.vcell.server.VCellConnection) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) SimulationContext(cbit.vcell.mapping.SimulationContext) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) UserLoginInfo(org.vcell.util.document.UserLoginInfo) XMLSource(cbit.vcell.xml.XMLSource)

Example 57 with XMLSource

use of cbit.vcell.xml.XMLSource 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.");
    }
}
Also used : User(org.vcell.util.document.User) BioModel(cbit.vcell.biomodel.BioModel) BioModelInfo(org.vcell.util.document.BioModelInfo) BigString(org.vcell.util.BigString) XMLSource(cbit.vcell.xml.XMLSource) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) RemoteException(java.rmi.RemoteException) PrintWriter(java.io.PrintWriter)

Example 58 with XMLSource

use of cbit.vcell.xml.XMLSource 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();
    }
}
Also used : User(org.vcell.util.document.User) BioModel(cbit.vcell.biomodel.BioModel) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationContext(cbit.vcell.mapping.SimulationContext) BigString(org.vcell.util.BigString) XMLSource(cbit.vcell.xml.XMLSource) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) RemoteException(java.rmi.RemoteException) PrintWriter(java.io.PrintWriter)

Example 59 with XMLSource

use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.

the class VCDatabaseScanner method scanGeometries.

/**
 * Insert the method's description here.
 * Creation date: (2/2/01 3:40:29 PM)
 * @throws DataAccessException
 * @throws XmlParseException
 */
public void scanGeometries(VCDatabaseVisitor databaseVisitor, PrintStream logFilePrintStream, User[] users, KeyValue singleGeometryKey, 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 geometries......");
        logFilePrintStream.println("\n");
        for (int i = 0; i < users.length; i++) {
            User user = users[i];
            GeometryInfo[] geoInfos = dbServerImpl.getGeometryInfos(user, false);
            for (int j = 0; j < geoInfos.length; j++) {
                if (singleGeometryKey != null && !geoInfos[j].getVersion().getVersionKey().compareEqual(singleGeometryKey)) {
                    System.out.println("skipping geometry, not the single one that we wanted");
                    continue;
                }
                if (excludeHash != null && excludeHash.contains(geoInfos[j].getVersion().getVersionKey())) {
                    System.out.println("skipping geometry with key '" + geoInfos[j].getVersion().getVersionKey() + "'");
                    continue;
                }
                if (includeHash != null && !includeHash.contains(geoInfos[j].getVersion().getVersionKey())) {
                    System.out.println("not including geometry with key '" + geoInfos[j].getVersion().getVersionKey() + "'");
                    continue;
                }
                if (!databaseVisitor.filterGeometry(geoInfos[j])) {
                    continue;
                }
                try {
                    BigString geometryXML = dbServerImpl.getGeometryXML(user, geoInfos[j].getVersion().getVersionKey());
                    Geometry geometry = cbit.vcell.xml.XmlHelper.XMLToGeometry(new XMLSource(geometryXML.toString()));
                    geometry.refreshDependencies();
                    databaseVisitor.visitGeometry(geometry, logFilePrintStream);
                } catch (Exception e2) {
                    lg.error(e2.getMessage(), e2);
                    if (bAbortOnDataAccessException) {
                        throw e2;
                    }
                }
            }
        }
        logFilePrintStream.close();
    } catch (Exception e) {
        System.err.println("error writing to log file.");
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) User(org.vcell.util.document.User) GeometryInfo(cbit.vcell.geometry.GeometryInfo) BigString(org.vcell.util.BigString) XMLSource(cbit.vcell.xml.XMLSource) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) RemoteException(java.rmi.RemoteException)

Example 60 with XMLSource

use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.

the class ServerDocumentManager method getMathModelXML.

/**
 * Insert the method's description here.
 * Creation date: (3/29/2004 4:04:16 PM)
 * @return java.lang.String
 * @param vType cbit.sql.VersionableType
 * @param vKey cbit.sql.KeyValue
 */
public String getMathModelXML(QueryHashtable dbc, User user, KeyValue mathModelKey, boolean bRegenerateXML) throws DataAccessException {
    String mathModelXML = null;
    try {
        mathModelXML = dbServer.getDBTopLevel().getMathModelXML(user, mathModelKey, true);
        if (mathModelXML != null) {
            if (bRegenerateXML) {
                try {
                    MathModel mathModel = XmlHelper.XMLToMathModel(new XMLSource(mathModelXML));
                    return cbit.vcell.xml.XmlHelper.mathModelToXML(mathModel);
                } catch (XmlParseException e) {
                    e.printStackTrace();
                    throw new DataAccessException(e.getMessage(), e);
                }
            } else {
                return mathModelXML;
            }
        }
    } catch (java.sql.SQLException e) {
        lg.error(e.getLocalizedMessage(), e);
        throw new DataAccessException(e.getMessage());
    } catch (ObjectNotFoundException e) {
    // 
    // not stored as XML currently, retrieve traditional way.
    // 
    }
    try {
        MathModel mathModel = getMathModelUnresolved(dbc, user, mathModelKey);
        mathModelXML = cbit.vcell.xml.XmlHelper.mathModelToXML(mathModel);
        dbServer.insertVersionableXML(user, VersionableType.MathModelMetaData, mathModelKey, mathModelXML);
        return mathModelXML;
    } catch (java.sql.SQLException e) {
        lg.error(e.getLocalizedMessage(), e);
        throw new DataAccessException(e.getMessage());
    } catch (cbit.vcell.xml.XmlParseException e) {
        lg.error(e.getLocalizedMessage(), e);
        throw new DataAccessException(e.getMessage());
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) XmlParseException(cbit.vcell.xml.XmlParseException) XMLSource(cbit.vcell.xml.XMLSource) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

XMLSource (cbit.vcell.xml.XMLSource)62 BioModel (cbit.vcell.biomodel.BioModel)48 XmlParseException (cbit.vcell.xml.XmlParseException)33 DataAccessException (org.vcell.util.DataAccessException)33 SimulationContext (cbit.vcell.mapping.SimulationContext)28 BigString (org.vcell.util.BigString)26 KeyValue (org.vcell.util.document.KeyValue)25 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)24 Simulation (cbit.vcell.solver.Simulation)22 SQLException (java.sql.SQLException)20 IOException (java.io.IOException)17 User (org.vcell.util.document.User)17 File (java.io.File)15 MathModel (cbit.vcell.mathmodel.MathModel)14 PropertyVetoException (java.beans.PropertyVetoException)14 MathException (cbit.vcell.math.MathException)13 ExpressionException (cbit.vcell.parser.ExpressionException)13 MappingException (cbit.vcell.mapping.MappingException)12 MathDescription (cbit.vcell.math.MathDescription)11 PrintWriter (java.io.PrintWriter)11