Search in sources :

Example 1 with DatabaseServerImpl

use of cbit.vcell.modeldb.DatabaseServerImpl in project vcell by virtualcell.

the class SimulationDispatcher method main.

/**
 * Starts the application.
 * @param args an array of command-line arguments
 */
public static void main(java.lang.String[] args) {
    OperatingSystemInfo.getInstance();
    if (args.length != 3 && args.length != 0) {
        System.out.println("Missing arguments: " + VCellServices.class.getName() + " [sshHost sshUser sshKeyFile] ");
        System.exit(1);
    }
    try {
        PropertyLoader.loadProperties(REQUIRED_SERVICE_PROPERTIES);
        HtcProxy htcProxy = SlurmProxy.creatCommandService(args);
        int serviceOrdinal = 99;
        VCMongoMessage.serviceStartup(ServiceName.dispatch, new Integer(serviceOrdinal), args);
        // //
        // // JMX registration
        // //
        // MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        // mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        ServiceInstanceStatus serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.DISPATCH, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
        ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
        SimulationDatabase simulationDatabase = new SimulationDatabaseDirect(adminDbTopLevel, databaseServerImpl, true);
        VCMessagingService vcMessagingService_int = new VCMessagingServiceActiveMQ();
        String jmshost_int = PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntHostInternal);
        int jmsport_int = Integer.parseInt(PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntPortInternal));
        vcMessagingService_int.setConfiguration(new ServerMessagingDelegate(), jmshost_int, jmsport_int);
        VCMessagingService vcMessagingService_sim = new VCMessagingServiceActiveMQ();
        String jmshost_sim = PropertyLoader.getRequiredProperty(PropertyLoader.jmsSimHostInternal);
        int jmsport_sim = Integer.parseInt(PropertyLoader.getRequiredProperty(PropertyLoader.jmsSimPortInternal));
        vcMessagingService_sim.setConfiguration(new ServerMessagingDelegate(), jmshost_sim, jmsport_sim);
        SimulationDispatcher simulationDispatcher = new SimulationDispatcher(htcProxy, vcMessagingService_int, vcMessagingService_sim, serviceInstanceStatus, simulationDatabase, false);
        simulationDispatcher.init();
    } catch (Throwable e) {
        lg.error("uncaught exception initializing SimulationDispatcher: " + e.getLocalizedMessage(), e);
        System.exit(1);
    }
}
Also used : ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) VCMessagingService(cbit.vcell.message.VCMessagingService) Date(java.util.Date) VCellServices(cbit.vcell.message.server.combined.VCellServices) ConnectionFactory(org.vcell.db.ConnectionFactory) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) VCMessagingServiceActiveMQ(cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ) KeyFactory(org.vcell.db.KeyFactory)

Example 2 with DatabaseServerImpl

use of cbit.vcell.modeldb.DatabaseServerImpl in project vcell by virtualcell.

the class VCellServices method main.

/**
 * Starts the application.
 * @param args an array of command-line arguments
 */
public static void main(java.lang.String[] args) {
    OperatingSystemInfo.getInstance();
    if (args.length != 3 && args.length != 0) {
        System.out.println("Missing arguments: " + VCellServices.class.getName() + " [sshHost sshUser sshKeyFile] ");
        System.exit(1);
    }
    try {
        PropertyLoader.loadProperties(REQUIRED_SERVICE_PROPERTIES);
        ResourceUtil.setNativeLibraryDirectory();
        new LibraryLoaderThread(false).start();
        PythonSupport.verifyInstallation(new PythonPackage[] { PythonPackage.VTK, PythonPackage.THRIFT });
        HtcProxy htcProxy = SlurmProxy.creatCommandService(args);
        int serviceOrdinal = 0;
        VCMongoMessage.serviceStartup(ServiceName.dispatch, new Integer(serviceOrdinal), args);
        // //
        // // JMX registration
        // //
        // MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        // mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        ServiceInstanceStatus serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.MASTER, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
        ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
        SimulationDatabase simulationDatabase = new SimulationDatabaseDirect(adminDbTopLevel, databaseServerImpl, true);
        String cacheSize = PropertyLoader.getRequiredProperty(PropertyLoader.simdataCacheSizeProperty);
        long maxMemSize = Long.parseLong(cacheSize);
        Cachetable cacheTable = new Cachetable(MessageConstants.MINUTE_IN_MS * 20, maxMemSize);
        DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(cacheTable, new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty)), new File(PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty))));
        ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
        // add dataJobListener
        DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, exportServiceImpl);
        VCMessagingService vcMessagingService_int = new VCMessagingServiceActiveMQ();
        String jmshost_int = PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntHostInternal);
        int jmsport_int = Integer.parseInt(PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntPortInternal));
        vcMessagingService_int.setConfiguration(new ServerMessagingDelegate(), jmshost_int, jmsport_int);
        VCMessagingService vcMessagingService_sim = new VCMessagingServiceActiveMQ();
        String jmshost_sim = PropertyLoader.getRequiredProperty(PropertyLoader.jmsSimHostInternal);
        int jmsport_sim = Integer.parseInt(PropertyLoader.getRequiredProperty(PropertyLoader.jmsSimPortInternal));
        vcMessagingService_sim.setConfiguration(new ServerMessagingDelegate(), jmshost_sim, jmsport_sim);
        VCellServices vcellServices = new VCellServices(htcProxy, vcMessagingService_int, vcMessagingService_sim, serviceInstanceStatus, databaseServerImpl, dataServerImpl, simulationDatabase);
        dataSetControllerImpl.addDataJobListener(vcellServices);
        exportServiceImpl.addExportListener(vcellServices);
        vcellServices.init();
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
}
Also used : Cachetable(cbit.vcell.simdata.Cachetable) DataServerImpl(cbit.vcell.simdata.DataServerImpl) ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) SimulationDatabase(cbit.vcell.message.server.dispatcher.SimulationDatabase) VCMessagingService(cbit.vcell.message.VCMessagingService) LibraryLoaderThread(cbit.vcell.resource.LibraryLoaderThread) Date(java.util.Date) ConnectionFactory(org.vcell.db.ConnectionFactory) SimulationDatabaseDirect(cbit.vcell.message.server.dispatcher.SimulationDatabaseDirect) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) VCMessagingServiceActiveMQ(cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ) File(java.io.File) KeyFactory(org.vcell.db.KeyFactory)

Example 3 with DatabaseServerImpl

use of cbit.vcell.modeldb.DatabaseServerImpl in project vcell by virtualcell.

the class DatabaseServer method main.

/**
 * Starts the application.
 * @param args an array of command-line arguments
 */
public static void main(java.lang.String[] args) {
    OperatingSystemInfo.getInstance();
    if (args.length != 0) {
        System.out.println("Unexpected arguments: " + DatabaseServer.class.getName());
        System.exit(1);
    }
    try {
        PropertyLoader.loadProperties(REQUIRED_SERVICE_PROPERTIES);
        int serviceOrdinal = 99;
        VCMongoMessage.serviceStartup(ServiceName.database, new Integer(serviceOrdinal), args);
        // 
        // JMX registration
        // 
        // MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        // mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        ServiceInstanceStatus serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.DB, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
        ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        String jmshost = PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntHostInternal);
        int jmsport = Integer.parseInt(PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntPortInternal));
        vcMessagingService.setConfiguration(new ServerMessagingDelegate(), jmshost, jmsport);
        DatabaseServer databaseServer = new DatabaseServer(serviceInstanceStatus, databaseServerImpl, vcMessagingService, false);
        databaseServer.init();
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
}
Also used : ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) ConnectionFactory(org.vcell.db.ConnectionFactory) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) VCMessagingService(cbit.vcell.message.VCMessagingService) Date(java.util.Date) KeyFactory(org.vcell.db.KeyFactory)

Example 4 with DatabaseServerImpl

use of cbit.vcell.modeldb.DatabaseServerImpl in project vcell by virtualcell.

the class IonItems method saveVCMLTestSuite.

private static void saveVCMLTestSuite(File dirToSaveVCML, long startSimKey, long endSimKey) throws Exception {
    // select distinct vc_biomodelsimcontext.biomodelref modelkey
    // from vc_tftestsuite,vc_tftestcase,vc_biomodelsimcontext
    // where vc_tftestsuite.tsversion='88_alpha_from_87_alpha'
    // and vc_tftestcase.testsuiteref=vc_tftestsuite.id
    // and vc_tftestcase.bmappref is not null
    // and vc_tftestcase.bmappref=vc_biomodelsimcontext.id
    // union
    // select distinct vc_mathmodel.id modelkey
    // from vc_tftestsuite,vc_tftestcase,vc_mathmodel
    // where vc_tftestsuite.tsversion='88_alpha_from_87_alpha'
    // and vc_tftestcase.testsuiteref=vc_tftestsuite.id
    // and vc_tftestcase.mathmodelref is not null
    // and vc_tftestcase.mathmodelref=vc_mathmodel.id;
    String modelKeyStr = "modelkey";
    String userKeyStr = "userkey";
    String useridStr = "userid";
    String modelUserKeyStr = modelKeyStr + "," + UserTable.table.id.getQualifiedColName() + " " + userKeyStr + "," + UserTable.table.userid.getQualifiedColName() + " " + useridStr;
    String testSuitTestCaseLink = TFTestSuiteTable.table.tsVersion.getQualifiedColName() + "=" + "'88_alpha_from_87_alpha'" + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName();
    String testSuitAndUserStr = TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + UserTable.table.getTableName();
    String bioModelTypeStr = "biomodel";
    String mathModelTypeStr = "mathmodel";
    String modelTypeKeyStr = "modeltype";
    String sql = "SELECT distinct " + "'" + bioModelTypeStr + "' " + modelTypeKeyStr + "," + BioModelTable.table.id.getQualifiedColName() + " " + modelUserKeyStr + " FROM " + testSuitAndUserStr + "," + BioModelSimContextLinkTable.table.getTableName() + "," + BioModelTable.table.getTableName() + " WHERE " + testSuitTestCaseLink + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + " IS NOT NULL" + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + "=" + BioModelSimContextLinkTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + "=" + BioModelTable.table.id.getQualifiedColName() + " AND " + BioModelTable.table.ownerRef.getQualifiedColName() + "=" + UserTable.table.id.getQualifiedColName() + " UNION " + "SELECT distinct " + "'" + mathModelTypeStr + "' " + modelTypeKeyStr + "," + MathModelTable.table.id.getQualifiedColName() + " " + modelUserKeyStr + " FROM " + testSuitAndUserStr + "," + MathModelTable.table.getTableName() + " WHERE " + testSuitTestCaseLink + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + " IS NOT NULL" + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + "=" + MathModelTable.table.id.getQualifiedColName() + " AND " + MathModelTable.table.ownerRef.getQualifiedColName() + "=" + UserTable.table.id.getQualifiedColName();
    Statement stmt = null;
    try {
        stmt = con.createStatement();
        // ArrayList<VCDocument> successDocs = new ArrayList<VCDocument>();
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(connFac, null);
        ArrayList<Object[]> modeKeyAndUser = new ArrayList<Object[]>();
        ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            BigDecimal modelKeyBigDecimal = rset.getBigDecimal(modelKeyStr);
            KeyValue modelKey = new KeyValue(modelKeyBigDecimal);
            String modelType = rset.getString(modelTypeKeyStr);
            if (startSimKey == 0 || (modelKeyBigDecimal.longValue() >= startSimKey && modelKeyBigDecimal.longValue() <= endSimKey)) {
                User user = new User(rset.getString(useridStr), new KeyValue(rset.getBigDecimal(userKeyStr)));
                modeKeyAndUser.add(new Object[] { (modelType.equals(bioModelTypeStr) ? VCDocumentType.BIOMODEL_DOC : VCDocumentType.MATHMODEL_DOC), modelKey, user });
            }
        }
        rset.close();
        stmt.close();
        VCDocument vcDoc = null;
        for (int ii = 0; ii < modeKeyAndUser.size(); ii++) {
            try {
                VCDocumentType vcDocType = (VCDocumentType) modeKeyAndUser.get(ii)[0];
                KeyValue modelKey = (KeyValue) modeKeyAndUser.get(ii)[1];
                User user = (User) modeKeyAndUser.get(ii)[2];
                // -----NOTE: (privacy, versionflag) may not match between xml and database (because privacy and versionflag can be set without saving model)
                // some models regenerated from xml will not have same privacy and versionflag matched in query from database (the database values are correct, ignore the xml values)
                BigString modelXML = (vcDocType == VCDocumentType.BIOMODEL_DOC ? databaseServerImpl.getBioModelXML(user, modelKey) : databaseServerImpl.getMathModelXML(user, modelKey));
                vcDoc = null;
                if (vcDocType == VCDocumentType.BIOMODEL_DOC) {
                    BioModel bm = cbit.vcell.xml.XmlHelper.XMLToBioModel(new XMLSource(modelXML.toString()));
                    bm.refreshDependencies();
                    vcDoc = bm;
                } else {
                    MathModel mm = cbit.vcell.xml.XmlHelper.XMLToMathModel(new XMLSource(modelXML.toString()));
                    mm.refreshDependencies();
                    vcDoc = mm;
                }
                // if(true) {
                // System.out.println(modelKey+" "+user+" "+vcDoc);
                // continue;
                // }
                String docXml = null;
                if (vcDoc.getDocumentType() == VCDocument.VCDocumentType.BIOMODEL_DOC) {
                    docXml = XmlHelper.bioModelToXML(((BioModel) vcDoc));
                } else {
                    docXml = XmlHelper.mathModelToXML(((MathModel) vcDoc));
                }
                PrintWriter pw = new PrintWriter(new File(dirToSaveVCML, vcDoc.getVersion().getVersionKey().toString() + ".xml"));
                pw.write(docXml);
                pw.close();
            // }
            } catch (Exception e) {
                System.out.println("----------GENERALERROR " + vcDoc.getVersion().getVersionKey());
                e.printStackTrace();
                if (vcDoc != null) {
                    PrintWriter pw = new PrintWriter(new File(dirToSaveVCML, vcDoc.getVersion().getVersionKey().toString() + "_exception.xml"));
                    pw.write("");
                    pw.close();
                }
            }
        }
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) VCDocument(org.vcell.util.document.VCDocument) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) VCDocumentType(org.vcell.util.document.VCDocument.VCDocumentType) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) BigDecimal(java.math.BigDecimal) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) BioModel(cbit.vcell.biomodel.BioModel) ResultSet(java.sql.ResultSet) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) XMLSource(cbit.vcell.xml.XMLSource) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 5 with DatabaseServerImpl

use of cbit.vcell.modeldb.DatabaseServerImpl in project vcell by virtualcell.

the class IonItems method saveVCMLRemoveSimsWithNoData.

private static void saveVCMLRemoveSimsWithNoData(Connection con, File dirToSaveVCML, File usersDir, long startSimKey, long endSimKey) {
    // select id from vc_biomodel where versionflag=3 and privacy=0;
    String bmsql = "SELECT " + BioModelTable.table.id.getQualifiedColName() + " modelkey" + "," + UserTable.table.id.getQualifiedColName() + " userkey" + "," + UserTable.table.userid.getQualifiedColName() + " userid" + " FROM " + BioModelTable.table.getTableName() + "," + UserTable.table.getTableName() + " WHERE " + BioModelTable.table.versionFlag.getQualifiedColName() + "=" + VersionFlag.Published.getIntValue() + " AND " + BioModelTable.table.privacy.getQualifiedColName() + "=" + GroupAccess.GROUPACCESS_ALL.intValue() + " AND " + BioModelTable.table.ownerRef.getQualifiedColName() + "=" + UserTable.table.id.getQualifiedColName() + " AND " + BioModelTable.table.id.getQualifiedColName() + " IN " + "(SELECT " + PublicationModelLinkTable.table.bioModelRef.getQualifiedColName() + " FROM " + PublicationModelLinkTable.table.getTableName() + " WHERE " + PublicationModelLinkTable.table.bioModelRef.getQualifiedColName() + " IS NOT NULL)" + " ORDER BY modelKey";
    String mmsql = "SELECT " + MathModelTable.table.id.getQualifiedColName() + " modelkey" + "," + UserTable.table.id.getQualifiedColName() + " userkey" + "," + UserTable.table.userid.getQualifiedColName() + " userid" + " FROM " + MathModelTable.table.getTableName() + "," + UserTable.table.getTableName() + " WHERE " + MathModelTable.table.versionFlag.getQualifiedColName() + "=" + VersionFlag.Published.getIntValue() + " AND " + MathModelTable.table.privacy.getQualifiedColName() + "=" + GroupAccess.GROUPACCESS_ALL.intValue() + " AND " + MathModelTable.table.ownerRef.getQualifiedColName() + "=" + UserTable.table.id.getQualifiedColName() + " AND " + MathModelTable.table.id.getQualifiedColName() + " IN " + // vc_publicationmodellink.biomodelref
    "(SELECT " + PublicationModelLinkTable.table.mathModelRef.getQualifiedColName() + " FROM " + PublicationModelLinkTable.table.getTableName() + " WHERE " + PublicationModelLinkTable.table.mathModelRef.getQualifiedColName() + " IS NOT NULL)" + " ORDER BY modelKey";
    Statement stmt = null;
    try {
        stmt = con.createStatement();
        // ArrayList<VCDocument> successDocs = new ArrayList<VCDocument>();
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(connFac, null);
        // ServerDocumentManager serverDocManager = new ServerDocumentManager(databaseServerImpl);
        // QueryHashtable qht = new QueryHashtable();
        DataSetControllerImpl dsci = new DataSetControllerImpl(new Cachetable(Cachetable.minute * 3, 30000000L), usersDir, null);
        ArrayList<Object[]> modeKeyAndUser = new ArrayList<Object[]>();
        for (int i = 0; i < 2; i++) {
            String sql = (i == 0 ? bmsql : mmsql);
            ResultSet rset = stmt.executeQuery(sql);
            while (rset.next()) {
                BigDecimal modelKeyBigDecimal = rset.getBigDecimal("modelkey");
                KeyValue modelKey = new KeyValue(modelKeyBigDecimal);
                if (startSimKey == 0 || (modelKeyBigDecimal.longValue() >= startSimKey && modelKeyBigDecimal.longValue() <= endSimKey)) {
                    User user = new User(rset.getString("userid"), new KeyValue(rset.getBigDecimal("userkey")));
                    modeKeyAndUser.add(new Object[] { (i == 0 ? VCDocumentType.BIOMODEL_DOC : VCDocumentType.MATHMODEL_DOC), modelKey, user });
                }
            }
            rset.close();
        }
        stmt.close();
        VCDocument vcDoc = null;
        for (int ii = 0; ii < modeKeyAndUser.size(); ii++) {
            try {
                VCDocumentType vcDocType = (VCDocumentType) modeKeyAndUser.get(ii)[0];
                KeyValue modelKey = (KeyValue) modeKeyAndUser.get(ii)[1];
                User user = (User) modeKeyAndUser.get(ii)[2];
                // -----NOTE: (privacy, versionflag) may not match between xml and database (because privacy and versionflag can be set without saving model)
                // some models regenerated from xml will not have same privacy and versionflag matched in query from database (the database values are correct, ignore the xml values)
                BigString modelXML = (vcDocType == VCDocumentType.BIOMODEL_DOC ? databaseServerImpl.getBioModelXML(user, modelKey) : databaseServerImpl.getMathModelXML(user, modelKey));
                Simulation[] sims = null;
                vcDoc = null;
                if (vcDocType == VCDocumentType.BIOMODEL_DOC) {
                    BioModel bm = cbit.vcell.xml.XmlHelper.XMLToBioModel(new XMLSource(modelXML.toString()));
                    bm.refreshDependencies();
                    sims = bm.getSimulations().clone();
                    vcDoc = bm;
                } else {
                    MathModel mm = cbit.vcell.xml.XmlHelper.XMLToMathModel(new XMLSource(modelXML.toString()));
                    mm.refreshDependencies();
                    sims = mm.getSimulations().clone();
                    vcDoc = mm;
                }
                // if(true) {
                // System.out.println(modelKey+" "+user+" "+vcDoc);
                // continue;
                // }
                boolean bRemovedSims = false;
                for (int j = 0; sims != null && j < sims.length; j++) {
                    try {
                        // public FoundSimDataInfo(long simID, int lastTaskID, int jobIndex, String userid) {
                        File foundLog = findSimLogFile(usersDir, new FoundSimDataInfo(Long.parseLong(sims[j].getKey().toString()), -1, 0, user.getName()), true, vcDocType);
                        if (foundLog == null) {
                            throw new Exception("Logfile not found for sim " + sims[j].getKey().toString());
                        } else {
                            VCSimulationIdentifier vcsi = new VCSimulationIdentifier(sims[j].getKey(), user);
                            VCSimulationDataIdentifier vcdID = new VCSimulationDataIdentifier(vcsi, 0);
                            OutputFunctionContext outputFunctionContext = sims[j].getSimulationOwner().getOutputFunctionContext();
                            OutputContext outputContext = new OutputContext(outputFunctionContext.getOutputFunctionsList().toArray(new AnnotatedFunction[0]));
                            DataIdentifier[] dataIdentifiers = dsci.getDataIdentifiers(outputContext, vcdID);
                            double[] dataSetTimes = dsci.getDataSetTimes(vcdID);
                            if (sims[j].getMathDescription().getGeometry().getDimension() == 0) {
                                ODEDataBlock odeDataBlock = dsci.getODEDataBlock(vcdID);
                            } else {
                                // for(int k=0;k<dataIdentifiers.length;k++){
                                SimDataBlock simDataBlock = dsci.getSimDataBlock(outputContext, vcdID, dataIdentifiers[0].getName(), dataSetTimes[dataSetTimes.length - 1]);
                            // }
                            }
                        }
                    } catch (Exception e) {
                        System.out.println("-----SIMERROR " + vcDoc.getVersion().getVersionKey() + "\n-----Sim=" + sims[j].getVersion());
                        e.printStackTrace();
                        if (e.getMessage().contains("HDF5")) {
                            return;
                        }
                        bRemovedSims = true;
                        if (vcDoc.getDocumentType() == VCDocument.VCDocumentType.BIOMODEL_DOC) {
                            ((BioModel) vcDoc).removeSimulation(sims[j]);
                        } else {
                            ((MathModel) vcDoc).removeSimulation(sims[j]);
                        }
                    }
                }
                String docXml = null;
                if (vcDoc.getDocumentType() == VCDocument.VCDocumentType.BIOMODEL_DOC) {
                    docXml = XmlHelper.bioModelToXML(((BioModel) vcDoc));
                } else {
                    docXml = XmlHelper.mathModelToXML(((MathModel) vcDoc));
                }
                PrintWriter pw = new PrintWriter(new File(dirToSaveVCML, vcDoc.getVersion().getVersionKey().toString() + "_" + (bRemovedSims) + ".xml"));
                pw.write(docXml);
                pw.close();
            // }
            } catch (Exception e) {
                System.out.println("----------GENERALERROR " + vcDoc.getVersion().getVersionKey());
                e.printStackTrace();
                if (vcDoc != null) {
                    PrintWriter pw = new PrintWriter(new File(dirToSaveVCML, vcDoc.getVersion().getVersionKey().toString() + "_exception.xml"));
                    pw.write("");
                    pw.close();
                }
            }
        }
    // for(VCDocument successDoc:successDocs) {
    // if(successDoc.getDocumentType() == VCDocument.VCDocumentType.BIOMODEL_DOC) {
    // ((BioModel)vcDoc).removeSimulation(sims[i]);
    // }else {
    // ((MathModel)vcDoc).removeSimulation(sims[i]);
    // }
    // 
    // }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Cachetable(cbit.vcell.simdata.Cachetable) MathModel(cbit.vcell.mathmodel.MathModel) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ArrayList(java.util.ArrayList) VCDocumentType(org.vcell.util.document.VCDocument.VCDocumentType) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) SimDataBlock(cbit.vcell.simdata.SimDataBlock) ResultSet(java.sql.ResultSet) ODEDataBlock(cbit.vcell.simdata.ODEDataBlock) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) PrintWriter(java.io.PrintWriter) VCDocument(org.vcell.util.document.VCDocument) Statement(java.sql.Statement) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) BigDecimal(java.math.BigDecimal) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) OutputContext(cbit.vcell.simdata.OutputContext) OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) XMLSource(cbit.vcell.xml.XMLSource) File(java.io.File)

Aggregations

DatabaseServerImpl (cbit.vcell.modeldb.DatabaseServerImpl)11 File (java.io.File)7 ConnectionFactory (org.vcell.db.ConnectionFactory)7 KeyFactory (org.vcell.db.KeyFactory)7 AdminDBTopLevel (cbit.vcell.modeldb.AdminDBTopLevel)6 User (org.vcell.util.document.User)5 VCMessagingService (cbit.vcell.message.VCMessagingService)4 IOException (java.io.IOException)4 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)3 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)3 Cachetable (cbit.vcell.simdata.Cachetable)3 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)3 SQLException (java.sql.SQLException)3 Date (java.util.Date)3 BigString (org.vcell.util.BigString)3 DataAccessException (org.vcell.util.DataAccessException)3 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)3 VCDocument (org.vcell.util.document.VCDocument)3 VCDocumentType (org.vcell.util.document.VCDocument.VCDocumentType)3 BioModel (cbit.vcell.biomodel.BioModel)2