Search in sources :

Example 21 with OServerAdmin

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

the class StandAloneDatabaseJavaThreadPoolTest method checkAndCreateDatabase.

/**
   *
   */
public void checkAndCreateDatabase(String dbName) {
    try {
        OServerAdmin serverAdmin = new OServerAdmin(getDBURL()).connect("root", "root");
        if (!serverAdmin.existsDatabase("plocal")) {
            log("Database does not exists. New database is created");
            serverAdmin.createDatabase(dbName, "graph", "plocal");
        } else {
            log(dbName + " database already exists");
        }
        serverAdmin.close();
    } catch (Exception ex) {
        log("Failed to create database", ex);
    }
}
Also used : OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException)

Example 22 with OServerAdmin

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

the class OOrientDBLoader method manageRemoteDatabase.

private void manageRemoteDatabase() {
    if (!dbAutoCreate && !dbAutoDropIfExists) {
        log(INFO, "nothing setup  on remote database " + dbURL);
        return;
    }
    if (NOT_DEF.equals(serverPassword) || NOT_DEF.equals(serverUser)) {
        log(ERROR, "please provide server administrator credentials");
        throw new OLoaderException("unable to manage remote db without server admin credentials");
    }
    ODatabaseDocument documentDatabase = new ODatabaseDocumentTx(dbURL);
    try {
        OServerAdmin admin = new OServerAdmin(documentDatabase.getURL()).connect(serverUser, serverPassword);
        boolean exists = admin.existsDatabase();
        if (!exists && dbAutoCreate) {
            admin.createDatabase(documentDatabase.getName(), dbType.name(), "plocal");
        } else if (exists && dbAutoDropIfExists) {
            admin.dropDatabase(documentDatabase.getName(), documentDatabase.getType());
        }
        admin.close();
    } catch (IOException e) {
        throw new OLoaderException(e);
    }
    documentDatabase.close();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) IOException(java.io.IOException)

Example 23 with OServerAdmin

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

the class GraphNonBlockingQueryRemote method before.

@Before
public void before() throws ClassNotFoundException, MalformedObjectNameException, InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException, InvocationTargetException, NoSuchMethodException, InstantiationException, IOException, IllegalAccessException {
    server = new OServer(false);
    server.startup(OrientGraphRemoteTest.class.getResourceAsStream("/embedded-server-config-single-run.xml"));
    server.activate();
    OServerAdmin admin = new OServerAdmin("remote:localhost:3064");
    admin.connect("root", "root");
    admin.createDatabase(GraphNonBlockingQueryRemote.class.getSimpleName(), "graph", "memory");
    admin.close();
}
Also used : OServer(com.orientechnologies.orient.server.OServer) OrientGraphRemoteTest(com.tinkerpop.blueprints.impls.orient.OrientGraphRemoteTest) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) Before(org.junit.Before)

Example 24 with OServerAdmin

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

the class OrientGraphNoTxRemoteTest method generateGraph.

public Graph generateGraph(final String graphDirectoryName) {
    final String url = "remote:localhost:" + serverPort + "/" + graphDirectoryName;
    OrientGraphNoTx graph = currentGraphs.get(url);
    if (graph != null) {
        if (graph.isClosed())
            currentGraphs.remove(url);
        else {
            ODatabaseRecordThreadLocal.INSTANCE.set(graph.getRawGraph());
            return graph;
        }
    }
    try {
        final OServerAdmin serverAdmin = new OServerAdmin(url);
        serverAdmin.connect("root", "root");
        if (!serverAdmin.existsDatabase(OrientGraphTest.getStorageType()))
            serverAdmin.createDatabase("graph", OrientGraphTest.getStorageType());
        serverAdmin.close();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    OrientGraphFactory factory = graphFactories.get(url);
    if (factory == null) {
        factory = new OrientGraphFactory(url);
        factory.setupPool(5, 256);
        graphFactories.put(url, factory);
    }
    graph = factory.getNoTx();
    graph.setWarnOnForceClosingTx(false);
    graph.setStandardExceptions(true);
    currentGraphs.put(url, graph);
    return graph;
}
Also used : OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) IOException(java.io.IOException)

Example 25 with OServerAdmin

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

the class OrientGraphNoTxRemoteTest method dropGraph.

@Override
public void dropGraph(final String graphDirectoryName) {
    // while to unlock files
    try {
        final String url = "remote:localhost:" + serverPort + "/" + graphDirectoryName;
        final OrientGraphNoTx graph = currentGraphs.get(url);
        if (graph != null)
            graph.shutdown();
        final OrientGraphFactory factory = graphFactories.remove(url);
        if (factory != null)
            factory.close();
        final OServerAdmin serverAdmin = new OServerAdmin(url);
        serverAdmin.connect("root", "root");
        if (serverAdmin.existsDatabase(OrientGraphTest.getStorageType()))
            serverAdmin.dropDatabase(OrientGraphTest.getStorageType());
        serverAdmin.close();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) IOException(java.io.IOException)

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