Search in sources :

Example 16 with OCommandOutputListener

use of com.orientechnologies.orient.core.command.OCommandOutputListener in project orientdb by orientechnologies.

the class StorageBackupMTStateTest method testRun.

public void testRun() throws Exception {
    String buildDirectory = System.getProperty("buildDirectory", ".");
    String dbDirectory = buildDirectory + File.separator + StorageBackupMTStateTest.class.getSimpleName();
    System.out.println("Clean up old data");
    OFileUtils.deleteRecursively(new File(dbDirectory));
    final String backedUpDbDirectory = buildDirectory + File.separator + StorageBackupMTStateTest.class.getSimpleName() + "BackUp";
    OFileUtils.deleteRecursively(new File(backedUpDbDirectory));
    backupDir = new File(buildDirectory, StorageBackupMTStateTest.class.getSimpleName() + "BackupDir");
    OFileUtils.deleteRecursively(backupDir);
    if (!backupDir.exists())
        Assert.assertTrue(backupDir.mkdirs());
    dbURL = "plocal:" + dbDirectory;
    System.out.println("Create database");
    ODatabaseDocumentTx databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
    databaseDocumentTx.create();
    System.out.println("Create schema");
    final OSchema schema = databaseDocumentTx.getMetadata().getSchema();
    for (int i = 0; i < 3; i++) {
        createClass(schema);
    }
    databaseDocumentTx.close();
    pool = new OPartitionedDatabasePool(dbURL, "admin", "admin");
    System.out.println("Start data modification");
    final ExecutorService executor = Executors.newFixedThreadPool(5);
    final ScheduledExecutorService backupExecutor = Executors.newSingleThreadScheduledExecutor();
    final ScheduledExecutorService classCreatorExecutor = Executors.newSingleThreadScheduledExecutor();
    final ScheduledExecutorService classDeleterExecutor = Executors.newSingleThreadScheduledExecutor();
    classDeleterExecutor.scheduleWithFixedDelay(new ClassDeleter(), 10, 10, TimeUnit.MINUTES);
    backupExecutor.scheduleWithFixedDelay(new IncrementalBackupThread(), 5, 5, TimeUnit.MINUTES);
    classCreatorExecutor.scheduleWithFixedDelay(new ClassAdder(), 7, 5, TimeUnit.MINUTES);
    List<Future<Void>> futures = new ArrayList<Future<Void>>();
    futures.add(executor.submit(new NonTxInserter()));
    futures.add(executor.submit(new NonTxInserter()));
    futures.add(executor.submit(new TxInserter()));
    futures.add(executor.submit(new TxInserter()));
    futures.add(executor.submit(new RecordsDeleter()));
    int k = 0;
    while (k < 180) {
        Thread.sleep(30 * 1000);
        k++;
        System.out.println(k * 0.5 + " minutes...");
    }
    stop = true;
    System.out.println("Stop backup");
    backupExecutor.shutdown();
    System.out.println("Stop class creation/deletion");
    classCreatorExecutor.shutdown();
    classDeleterExecutor.shutdown();
    backupExecutor.awaitTermination(15, TimeUnit.MINUTES);
    classCreatorExecutor.awaitTermination(15, TimeUnit.MINUTES);
    classDeleterExecutor.awaitTermination(15, TimeUnit.MINUTES);
    System.out.println("Stop data threads");
    for (Future<Void> future : futures) future.get();
    System.out.println("All threads are stopped");
    pool.close();
    System.out.println("Final incremental  backup");
    databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
    databaseDocumentTx.open("admin", "admin");
    databaseDocumentTx.incrementalBackup(backupDir.getAbsolutePath());
    OStorage storage = databaseDocumentTx.getStorage();
    databaseDocumentTx.close();
    storage.close(true, false);
    System.out.println("Create backup database");
    final ODatabaseDocumentTx backedUpDb = new ODatabaseDocumentTx("plocal:" + backedUpDbDirectory);
    backedUpDb.create(backupDir.getAbsolutePath());
    final OStorage backupStorage = backedUpDb.getStorage();
    backedUpDb.close();
    backupStorage.close(true, false);
    System.out.println("Compare databases");
    final ODatabaseCompare compare = new ODatabaseCompare("plocal:" + dbDirectory, "plocal:" + backedUpDbDirectory, "admin", "admin", new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
            System.out.println(iText);
        }
    });
    Assert.assertTrue(compare.compare());
    System.out.println("Drop databases and backup directory");
    databaseDocumentTx.open("admin", "admin");
    databaseDocumentTx.drop();
    backedUpDb.open("admin", "admin");
    backedUpDb.drop();
    OFileUtils.deleteRecursively(backupDir);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODatabaseCompare(com.orientechnologies.orient.core.db.tool.ODatabaseCompare) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) File(java.io.File) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener)

Example 17 with OCommandOutputListener

use of com.orientechnologies.orient.core.command.OCommandOutputListener in project orientdb by orientechnologies.

the class ObjectExportImportTest method testExportImport.

@Test
public void testExportImport() throws IOException {
    OObjectDatabaseTx db = new OObjectDatabaseTx("memory:test");
    db.create();
    db.setAutomaticSchemaGeneration(true);
    db.getMetadata().getSchema().synchronizeSchema();
    assertNotNull(db.getMetadata().getSchema().getClass("ODocumentWrapper"));
    byte[] bytes;
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    new ODatabaseExport(db.getUnderlying(), byteOutputStream, new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
        }
    }).exportDatabase().close();
    bytes = byteOutputStream.toByteArray();
    OObjectDatabaseTx db1 = new OObjectDatabaseTx("memory:test1");
    db1.create();
    db1.setAutomaticSchemaGeneration(true);
    db1.getMetadata().getSchema().synchronizeSchema();
    InputStream input = new ByteArrayInputStream(bytes);
    new ODatabaseImport(db1.getUnderlying(), input, new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
        }
    }).importDatabase().close();
    assertNotNull(db1.getMetadata().getSchema().getClass("ODocumentWrapper"));
}
Also used : ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport) Test(org.testng.annotations.Test)

Example 18 with OCommandOutputListener

use of com.orientechnologies.orient.core.command.OCommandOutputListener 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 19 with OCommandOutputListener

use of com.orientechnologies.orient.core.command.OCommandOutputListener in project orientdb by orientechnologies.

the class OAutomaticBackup method fullBackupDatabase.

protected void fullBackupDatabase(final String dbURL, final String iPath, final ODatabaseDocumentInternal db) throws IOException {
    OLogManager.instance().info(this, "AutomaticBackup: executing full backup of database '%s' to %s", dbURL, iPath);
    final FileOutputStream fileOutputStream = new FileOutputStream(iPath);
    try {
        db.backup(fileOutputStream, null, null, new OCommandOutputListener() {

            @Override
            public void onMessage(String iText) {
                OLogManager.instance().info(this, iText);
            }
        }, compressionLevel, bufferSize);
    } finally {
        fileOutputStream.close();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener)

Aggregations

OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)19 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)8 OStorage (com.orientechnologies.orient.core.storage.OStorage)5 File (java.io.File)5 ODatabaseCompare (com.orientechnologies.orient.core.db.tool.ODatabaseCompare)4 ODatabaseExport (com.orientechnologies.orient.core.db.tool.ODatabaseExport)4 ODatabaseImport (com.orientechnologies.orient.core.db.tool.ODatabaseImport)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 OIntentMassiveInsert (com.orientechnologies.orient.core.intent.OIntentMassiveInsert)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileInputStream (java.io.FileInputStream)3 Future (java.util.concurrent.Future)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 ODistributedDatabaseChunk (com.orientechnologies.orient.server.distributed.impl.ODistributedDatabaseChunk)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2