Search in sources :

Example 16 with OServerAdmin

use of com.orientechnologies.orient.client.remote.OServerAdmin in project YCSB by brianfrankcooper.

the class OrientDBClient method init.

/**
   * Initialize any state for this DB. Called once per DB instance; there is one DB instance per client thread.
   */
public void init() throws DBException {
    // initialize OrientDB driver
    final Properties props = getProperties();
    String url = props.getProperty(URL_PROPERTY, URL_PROPERTY_DEFAULT);
    String user = props.getProperty(USER_PROPERTY, USER_PROPERTY_DEFAULT);
    String password = props.getProperty(PASSWORD_PROPERTY, PASSWORD_PROPERTY_DEFAULT);
    Boolean newdb = Boolean.parseBoolean(props.getProperty(NEWDB_PROPERTY, NEWDB_PROPERTY_DEFAULT));
    String remoteStorageType = props.getProperty(STORAGE_TYPE_PROPERTY);
    INIT_LOCK.lock();
    try {
        clientCounter++;
        if (!initialized) {
            OGlobalConfiguration.dumpConfiguration(System.out);
            LOG.info("OrientDB loading database url = " + url);
            ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
            if (db.getStorage().isRemote()) {
                isRemote = true;
            }
            if (!dbChecked) {
                if (!isRemote) {
                    if (newdb) {
                        if (db.exists()) {
                            db.open(user, password);
                            LOG.info("OrientDB drop and recreate fresh db");
                            db.drop();
                        }
                        db.create();
                    } else {
                        if (!db.exists()) {
                            LOG.info("OrientDB database not found, creating fresh db");
                            db.create();
                        }
                    }
                } else {
                    OServerAdmin server = new OServerAdmin(url).connect(user, password);
                    if (remoteStorageType == null) {
                        throw new DBException("When connecting to a remote OrientDB instance, " + "specify a database storage type (plocal or memory) with " + STORAGE_TYPE_PROPERTY);
                    }
                    if (newdb) {
                        if (server.existsDatabase()) {
                            LOG.info("OrientDB drop and recreate fresh db");
                            server.dropDatabase(remoteStorageType);
                        }
                        server.createDatabase(db.getName(), ORIENTDB_DOCUMENT_TYPE, remoteStorageType);
                    } else {
                        if (!server.existsDatabase()) {
                            LOG.info("OrientDB database not found, creating fresh db");
                            server.createDatabase(server.getURL(), ORIENTDB_DOCUMENT_TYPE, remoteStorageType);
                        }
                    }
                    server.close();
                }
                dbChecked = true;
            }
            if (db.isClosed()) {
                db.open(user, password);
            }
            if (!db.getMetadata().getSchema().existsClass(CLASS)) {
                db.getMetadata().getSchema().createClass(CLASS);
            }
            db.close();
            if (databasePool == null) {
                databasePool = new OPartitionedDatabasePool(url, user, password);
            }
            initialized = true;
        }
    } catch (Exception e) {
        LOG.error("Could not initialize OrientDB connection pool for Loader: " + e.toString());
        e.printStackTrace();
    } finally {
        INIT_LOCK.unlock();
    }
}
Also used : OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException)

Example 17 with OServerAdmin

use of com.orientechnologies.orient.client.remote.OServerAdmin in project orientdb by orientechnologies.

the class ODatabaseHelper method releaseDatabase.

public static void releaseDatabase(final ODatabase database) throws IOException {
    database.activateOnCurrentThread();
    if (database.getURL().startsWith("remote")) {
        final OServerAdmin serverAdmin = new OServerAdmin(database.getURL());
        serverAdmin.connect("root", getServerRootPassword()).releaseDatabase("plocal");
        serverAdmin.close();
    } else {
        database.release();
    }
}
Also used : OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin)

Example 18 with OServerAdmin

use of com.orientechnologies.orient.client.remote.OServerAdmin in project orientdb by orientechnologies.

the class ODatabaseHelper method createDatabase.

public static void createDatabase(ODatabase database, final String url, String directory, String type) throws IOException {
    if (url.startsWith(OEngineRemote.NAME)) {
        new OServerAdmin(url).connect("root", getServerRootPassword(directory)).createDatabase("document", type).close();
    } else {
        database.create();
        database.close();
    }
}
Also used : OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin)

Example 19 with OServerAdmin

use of com.orientechnologies.orient.client.remote.OServerAdmin in project orientdb by orientechnologies.

the class ODatabaseHelper method dropDatabase.

public static void dropDatabase(final ODatabase database, final String directory, String storageType) throws IOException {
    if (existsDatabase(database, storageType)) {
        if (database.getURL().startsWith("remote:")) {
            database.activateOnCurrentThread();
            database.close();
            OServerAdmin admin = new OServerAdmin(database.getURL()).connect("root", getServerRootPassword(directory));
            admin.dropDatabase(storageType);
            admin.close();
        } else {
            if (database.isClosed())
                openDatabase(database);
            else
                database.activateOnCurrentThread();
            database.drop();
        }
    }
}
Also used : OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin)

Example 20 with OServerAdmin

use of com.orientechnologies.orient.client.remote.OServerAdmin in project orientdb by orientechnologies.

the class ODatabaseHelper method existsDatabase.

public static boolean existsDatabase(final String url) throws IOException {
    if (url.startsWith("remote")) {
        OServerAdmin admin = new OServerAdmin(url).connect("root", getServerRootPassword());
        boolean exist = admin.existsDatabase();
        admin.close();
        return exist;
    }
    return new ODatabaseDocumentTx(url).exists();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin)

Aggregations

OServerAdmin (com.orientechnologies.orient.client.remote.OServerAdmin)46 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)9 Before (org.junit.Before)9 OServer (com.orientechnologies.orient.server.OServer)8 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)6 IOException (java.io.IOException)5 Test (org.testng.annotations.Test)5 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)3 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)3 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)3 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)2 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)2 AfterMethod (org.testng.annotations.AfterMethod)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 ORemoteConnectionManager (com.orientechnologies.orient.client.remote.ORemoteConnectionManager)1 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)1 OPartitionedDatabasePool (com.orientechnologies.orient.core.db.OPartitionedDatabasePool)1