Search in sources :

Example 26 with ODatabaseException

use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.

the class DistributedDbDropAndReCreateTest method onAfterExecution.

@Override
protected void onAfterExecution() throws Exception {
    int s = 0;
    do {
        ServerRun server = serverInstance.get(0);
        ODatabaseDocumentTx db = new ODatabaseDocumentTx(getDatabaseURL(server));
        db.open("admin", "admin");
        banner("DROPPING DATABASE ON SERVERS");
        waitForDatabaseIsOnline(0, "europe-0", getDatabaseName(), 5000);
        waitForDatabaseIsOnline(0, "europe-1", getDatabaseName(), 5000);
        waitForDatabaseIsOnline(0, "europe-2", getDatabaseName(), 5000);
        db.drop();
        Thread.sleep(2000);
        Assert.assertFalse(server.getServerInstance().getDistributedManager().getConfigurationMap().containsKey(OHazelcastPlugin.CONFIG_DATABASE_PREFIX + getDatabaseName()));
        server = serverInstance.get(s);
        banner("RE-CREATING DATABASE ON SERVER " + server.getServerId());
        db = new ODatabaseDocumentTx(getDatabaseURL(server));
        Assert.assertFalse(server.getServerInstance().getDistributedManager().getConfigurationMap().containsKey(OHazelcastPlugin.CONFIG_DATABASE_PREFIX + getDatabaseName()));
        for (int retry = 0; retry < 10; retry++) {
            try {
                db.create();
                break;
            } catch (ODatabaseException e) {
                System.out.println("DB STILL IN THE CLUSTER, WAIT AND RETRY (retry " + retry + ")...");
                Thread.sleep(1000);
            }
        }
        db.activateOnCurrentThread();
        db.close();
    } while (++s < serverInstance.size());
    // DROP LAST DATABASE
    final ODatabaseDocumentTx db = new ODatabaseDocumentTx(getDatabaseURL(serverInstance.get(serverInstance.size() - 1)));
    db.open("admin", "admin");
    db.drop();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException)

Example 27 with ODatabaseException

use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.

the class OServerCommandPostInstallDatabase method execute.

@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
    checkSyntax(iRequest.url, 1, "Syntax error: installDatabase");
    iRequest.data.commandInfo = "Import database";
    try {
        final String url = iRequest.content;
        final String name = getDbName(url);
        if (name != null) {
            final String folder = server.getDatabaseDirectory() + File.separator + name;
            final File f = new File(folder);
            if (f.exists() && OLocalPaginatedStorage.exists(folder)) {
                throw new ODatabaseException("Database named '" + name + "' already exists: ");
            } else {
                f.mkdirs();
                final URL uri = new URL(url);
                final URLConnection conn = uri.openConnection();
                conn.setRequestProperty("User-Agent", "OrientDB-Studio");
                conn.setDefaultUseCaches(false);
                OZIPCompressionUtil.uncompressDirectory(conn.getInputStream(), folder, new OCommandOutputListener() {

                    @Override
                    public void onMessage(String iText) {
                    }
                });
                iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_TEXT_PLAIN, null, null);
            }
        } else {
            throw new IllegalArgumentException("Could not find database name");
        }
    } catch (Exception e) {
        throw e;
    } finally {
    }
    return false;
}
Also used : ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) File(java.io.File) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) URL(java.net.URL) URLConnection(java.net.URLConnection) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException)

Example 28 with ODatabaseException

use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.

the class DatabaseThreadFactoryTest method init.

@BeforeClass
public void init() {
    try {
        ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
        db.close();
        ODatabaseRecordThreadLocal.INSTANCE.remove();
    } catch (ODatabaseException ode) {
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException)

Aggregations

ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)28 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)7 OException (com.orientechnologies.common.exception.OException)5 ORecordId (com.orientechnologies.orient.core.id.ORecordId)5 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)4 IOException (java.io.IOException)4 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)3 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)3 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)3 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)3 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OLocalClusterWrapperStrategy (com.orientechnologies.orient.server.distributed.impl.OLocalClusterWrapperStrategy)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)1