Search in sources :

Example 6 with ConnectionFactory

use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.

the class EmailList method getConnection.

/**
 * opens the database connection
 * @return database connection
 * @throws SQLException
 */
private Connection getConnection() throws SQLException {
    String dbDriverName = PropertyLoader.getRequiredProperty(PropertyLoader.dbDriverName);
    ConnectionFactory connectionFactory = DatabaseService.getInstance().createConnectionFactory(dbDriverName, EmailList.JDBC_URL, USER_ID, password);
    Connection conn = connectionFactory.getConnection(new Object());
    return conn;
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory) Connection(java.sql.Connection)

Example 7 with ConnectionFactory

use of org.vcell.db.ConnectionFactory 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 });
        CommandService commandService = null;
        if (args.length == 3) {
            String sshHost = args[0];
            String sshUser = args[1];
            File sshKeyFile = new File(args[2]);
            try {
                commandService = new CommandServiceSshNative(sshHost, sshUser, sshKeyFile);
                commandService.command(new String[] { "/usr/bin/env bash -c ls | head -5" });
                lg.trace("SSH Connection test passed with installed keyfile, running ls as user " + sshUser + " on " + sshHost);
            } catch (Exception e) {
                e.printStackTrace();
                try {
                    commandService = new CommandServiceSshNative(sshHost, sshUser, sshKeyFile, new File("/root"));
                    commandService.command(new String[] { "/usr/bin/env bash -c ls | head -5" });
                    lg.trace("SSH Connection test passed after installing keyfile, running ls as user " + sshUser + " on " + sshHost);
                } catch (Exception e2) {
                    e.printStackTrace();
                    throw new RuntimeException("failed to establish an ssh command connection to " + sshHost + " as user '" + sshUser + "' using key '" + sshKeyFile + "'", e);
                }
            }
            // can't make user directories, they are remote.
            AbstractSolver.bMakeUserDirs = false;
        } else {
            commandService = new CommandServiceLocal();
        }
        BatchSystemType batchSystemType = BatchSystemType.SLURM;
        HtcProxy htcProxy = null;
        switch(batchSystemType) {
            case SLURM:
                {
                    htcProxy = new SlurmProxy(commandService, PropertyLoader.getRequiredProperty(PropertyLoader.htcUser));
                    break;
                }
            default:
                {
                    throw new RuntimeException("unrecognized batch scheduling option :" + batchSystemType);
                }
        }
        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);
        Cachetable cacheTable = new Cachetable(MessageConstants.MINUTE_IN_MS * 20);
        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 = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        vcMessagingService.setDelegate(new ServerMessagingDelegate());
        VCellServices vcellServices = new VCellServices(htcProxy, vcMessagingService, 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) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) CommandService(cbit.vcell.message.server.cmd.CommandService) VCMessagingService(cbit.vcell.message.VCMessagingService) ConnectionFactory(org.vcell.db.ConnectionFactory) SimulationDatabaseDirect(cbit.vcell.message.server.dispatcher.SimulationDatabaseDirect) CommandServiceLocal(cbit.vcell.message.server.cmd.CommandServiceLocal) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) KeyFactory(org.vcell.db.KeyFactory) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) SimulationDatabase(cbit.vcell.message.server.dispatcher.SimulationDatabase) LibraryLoaderThread(cbit.vcell.resource.LibraryLoaderThread) SlurmProxy(cbit.vcell.message.server.htc.slurm.SlurmProxy) VCMessagingException(cbit.vcell.message.VCMessagingException) Date(java.util.Date) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) BatchSystemType(cbit.vcell.server.HtcJobID.BatchSystemType) File(java.io.File) CommandServiceSshNative(cbit.vcell.message.server.cmd.CommandServiceSshNative)

Example 8 with ConnectionFactory

use of org.vcell.db.ConnectionFactory 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) {
    if (args.length < 1) {
        System.out.println("Missing arguments: " + DatabaseServer.class.getName() + " serviceOrdinal [logdir]");
        System.exit(1);
    }
    try {
        PropertyLoader.loadProperties();
        DatabasePolicySQL.lg.setLevel(Level.ALL);
        int serviceOrdinal = Integer.parseInt(args[0]);
        String logdir = null;
        if (args.length > 1) {
            logdir = args[1];
        }
        ServiceInstanceStatus serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.DB, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
        VCMongoMessage.serviceStartup(ServiceName.database, new Integer(serviceOrdinal), args);
        // 
        // JMX registration
        // 
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        vcMessagingService.setDelegate(new ServerMessagingDelegate());
        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) VCMessagingService(cbit.vcell.message.VCMessagingService) Date(java.util.Date) ObjectName(javax.management.ObjectName) ConnectionFactory(org.vcell.db.ConnectionFactory) VCellServiceMXBeanImpl(cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) KeyFactory(org.vcell.db.KeyFactory) MBeanServer(javax.management.MBeanServer)

Example 9 with ConnectionFactory

use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.

the class MathVerifier method createMathVerifier.

public static MathVerifier createMathVerifier(String dbHostName, String dbName, String dbSchemaUser, String dbPassword) throws Exception {
    ConnectionFactory conFactory = null;
    KeyFactory keyFactory = null;
    new cbit.vcell.resource.PropertyLoader();
    String driverName = "oracle.jdbc.driver.OracleDriver";
    String connectURL = "jdbc:oracle:thin:@" + dbHostName + ":1521:" + dbName;
    // 
    // get appropriate database factory objects
    // 
    conFactory = DatabaseService.getInstance().createConnectionFactory(driverName, connectURL, dbSchemaUser, dbPassword);
    keyFactory = conFactory.getKeyFactory();
    AdminDatabaseServer adminDbServer = new LocalAdminDbServer(conFactory, keyFactory);
    return new MathVerifier(conFactory, keyFactory, adminDbServer);
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory) BigString(org.vcell.util.BigString) PropertyLoader(cbit.vcell.resource.PropertyLoader) KeyFactory(org.vcell.db.KeyFactory) AdminDatabaseServer(cbit.vcell.server.AdminDatabaseServer)

Example 10 with ConnectionFactory

use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.

the class SQLCreateAllTables method main.

/**
 * Starts the application.
 * @param args an array of command-line arguments
 */
public static void main(java.lang.String[] args) {
    // 
    try {
        final String oracle = "oracle";
        final String postgres = "postgres";
        final String usage = "\nUsage: (" + oracle + "|" + postgres + ") connectUrl schemaUser schemaUserPassword\n";
        if (args.length != 4) {
            System.out.println(usage);
            System.exit(1);
        }
        String connectURL = args[1];
        String dbSchemaUser = args[2];
        String dbPassword = args[3];
        // 
        int ok = javax.swing.JOptionPane.showConfirmDialog(new JFrame(), "EXTREME DANGER!!!!\nAll Tables in Schema below will be DESTROYED and re-created" + "connectURL=" + connectURL + "\nUser=" + dbSchemaUser + "\npassword=" + dbPassword, "Confirm", javax.swing.JOptionPane.OK_CANCEL_OPTION, javax.swing.JOptionPane.WARNING_MESSAGE);
        if (ok != javax.swing.JOptionPane.OK_OPTION) {
            throw new RuntimeException("Aborted by user");
        }
        ConnectionFactory conFactory = null;
        KeyFactory keyFactory = null;
        new cbit.vcell.resource.PropertyLoader();
        if (args[0].equalsIgnoreCase(oracle)) {
            String driverName = "oracle.jdbc.driver.OracleDriver";
            conFactory = DatabaseService.getInstance().createConnectionFactory(driverName, connectURL, dbSchemaUser, dbPassword);
        } else if (args[0].equalsIgnoreCase(postgres)) {
            String driverName = "org.postgresql.Driver";
            conFactory = DatabaseService.getInstance().createConnectionFactory(driverName, connectURL, dbSchemaUser, dbPassword);
        } else {
            System.out.println(usage);
            System.exit(1);
        }
        destroyAndRecreateTables(conFactory, conFactory.getKeyFactory(), conFactory.getDatabaseSyntax());
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
    System.exit(0);
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory) JFrame(javax.swing.JFrame) KeyFactory(org.vcell.db.KeyFactory)

Aggregations

ConnectionFactory (org.vcell.db.ConnectionFactory)21 KeyFactory (org.vcell.db.KeyFactory)13 File (java.io.File)8 SQLException (java.sql.SQLException)7 DatabaseServerImpl (cbit.vcell.modeldb.DatabaseServerImpl)4 IOException (java.io.IOException)4 Connection (java.sql.Connection)4 VCMessagingService (cbit.vcell.message.VCMessagingService)3 AdminDBTopLevel (cbit.vcell.modeldb.AdminDBTopLevel)3 ZipFile (java.util.zip.ZipFile)3 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)2 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)2 RemoteProxyVCellConnectionFactory (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory)2 LocalAdminDbServer (cbit.vcell.modeldb.LocalAdminDbServer)2 PropertyLoader (cbit.vcell.resource.PropertyLoader)2 AdminDatabaseServer (cbit.vcell.server.AdminDatabaseServer)2 FileFilter (java.io.FileFilter)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 JFrame (javax.swing.JFrame)2