Search in sources :

Example 11 with OCommandOutputListener

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

the class OGremlinConsole method importDatabase.

@Override
@ConsoleCommand(description = "Import a database into the current one", splitInWords = false)
public void importDatabase(@ConsoleParameter(name = "options", description = "Import options") String text) throws IOException {
    checkForDatabase();
    final List<String> items = OStringSerializerHelper.smartSplit(text, ' ');
    final String fileName = items.size() <= 0 || (items.get(1)).charAt(0) == '-' ? null : items.get(1);
    final String optionsAsString = fileName != null ? text.substring((items.get(0)).length() + (items.get(1)).length() + 1).trim() : text;
    final Map<String, List<String>> options = parseOptions(optionsAsString);
    final String format = options.containsKey("-format") ? options.get("-format").get(0) : null;
    if ((format != null && format.equalsIgnoreCase("graphml")) || (fileName != null && (fileName.endsWith(".graphml") || fileName.endsWith(".xml")))) {
        // GRAPHML
        message("\nImporting GRAPHML database from " + fileName + " with options (" + optionsAsString + ")...");
        try {
            final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase);
            g.setUseLog(false);
            g.setWarnOnForceClosingTx(false);
            final long totalEdges = g.countEdges();
            final long totalVertices = g.countVertices();
            final File file = new File(fileName);
            if (!file.exists())
                throw new ODatabaseImportException("Input file '" + fileName + "' not exists");
            InputStream is = new FileInputStream(file);
            if (fileName.endsWith(".zip"))
                is = new ZipInputStream(is);
            else if (fileName.endsWith(".gz"))
                is = new GZIPInputStream(is);
            try {
                new OGraphMLReader(g).setOptions(options).setOutput(new OCommandOutputListener() {

                    @Override
                    public void onMessage(final String iText) {
                        System.out.print("\r" + iText);
                    }
                }).inputGraph(is);
                g.commit();
                currentDatabase.commit();
                message("\nDone: imported %d vertices and %d edges", g.countVertices() - totalVertices, g.countEdges() - totalEdges);
            } finally {
                is.close();
            }
        } catch (ODatabaseImportException e) {
            printError(e);
        }
    } else if ((format != null && format.equalsIgnoreCase("graphson")) || (fileName != null && (fileName.endsWith(".graphson")))) {
        // GRAPHSON
        message("\nImporting GRAPHSON database from " + fileName + " with options (" + optionsAsString + ")...");
        try {
            final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase);
            g.setUseLog(false);
            g.setWarnOnForceClosingTx(false);
            final long totalEdges = g.countEdges();
            final long totalVertices = g.countVertices();
            final File file = new File(fileName);
            if (!file.exists())
                throw new ODatabaseImportException("Input file '" + fileName + "' not exists");
            InputStream is = new FileInputStream(file);
            if (fileName.endsWith(".zip")) {
                is = new ZipInputStream(is);
            } else if (fileName.endsWith(".gz")) {
                is = new GZIPInputStream(is);
            }
            try {
                new OGraphSONReader(g).setOutput(new OCommandOutputListener() {

                    @Override
                    public void onMessage(final String iText) {
                        System.out.print("\r" + iText);
                    }
                }).inputGraph(is, 10000);
                // new OGraphMLReader(g).setOptions(options).inputGraph(g, fileName);
                g.commit();
                currentDatabase.commit();
                message("\nDone: imported %d vertices and %d edges", g.countVertices() - totalVertices, g.countEdges() - totalEdges);
            } finally {
                is.close();
            }
        } catch (ODatabaseImportException e) {
            printError(e);
        }
    } else if (format == null)
        super.importDatabase(text);
    else
        throw new IllegalArgumentException("Format '" + format + "' is not supported");
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ODatabaseImportException(com.orientechnologies.orient.core.db.tool.ODatabaseImportException) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) OGraphSONReader(com.orientechnologies.orient.graph.graphml.OGraphSONReader) OGraphMLReader(com.orientechnologies.orient.graph.graphml.OGraphMLReader) List(java.util.List) File(java.io.File) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 12 with OCommandOutputListener

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

the class OBaseGraphWorkload method check.

@Override
public void check(final ODatabaseIdentifier databaseIdentifier) {
    final OGraphRepair repair = new OGraphRepair();
    repair.repair(getGraphNoTx(databaseIdentifier), new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
            System.out.print("   - " + iText);
        }
    }, null);
}
Also used : OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener)

Example 13 with OCommandOutputListener

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

the class ODatabaseImportTest method exportImportOnlySchemaTest.

@Test
public void exportImportOnlySchemaTest() throws IOException {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODatabaseImportTest.class.getSimpleName());
    db.create();
    db.getMetadata().getSchema().createClass("SimpleClass");
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ODatabaseExport export = new ODatabaseExport((ODatabaseDocumentInternal) db, output, new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
        }
    });
    export.setOptions(" -excludeAll -includeSchema=true");
    export.exportDatabase();
    db.drop();
    ODatabaseDocument dbImp = new ODatabaseDocumentTx("memory:import_" + ODatabaseImportTest.class.getSimpleName());
    dbImp.create();
    ODatabaseImport importer = new ODatabaseImport((ODatabaseDocumentInternal) dbImp, new ByteArrayInputStream(output.toByteArray()), new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
        }
    });
    importer.importDatabase();
    assertTrue(dbImp.getMetadata().getSchema().existsClass("SimpleClass"));
    dbImp.drop();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) Test(org.junit.Test)

Example 14 with OCommandOutputListener

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

the class ODatabaseImportTest method exportImportExcludeClusters.

@Test
public void exportImportExcludeClusters() throws IOException {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODatabaseImportTest.class.getSimpleName() + "_excludeclusters");
    db.create();
    db.getMetadata().getSchema().createClass("SimpleClass");
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ODatabaseExport export = new ODatabaseExport((ODatabaseDocumentInternal) db, output, new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
        }
    });
    export.setOptions(" -includeClusterDefinitions=false");
    export.exportDatabase();
    db.drop();
    ODatabaseDocument dbImp = new ODatabaseDocumentTx("memory:import_" + ODatabaseImportTest.class.getSimpleName());
    dbImp.create();
    ODatabaseImport importer = new ODatabaseImport((ODatabaseDocumentInternal) dbImp, new ByteArrayInputStream(output.toByteArray()), new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
        }
    });
    importer.importDatabase();
    assertTrue(dbImp.getMetadata().getSchema().existsClass("SimpleClass"));
    dbImp.drop();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) Test(org.junit.Test)

Example 15 with OCommandOutputListener

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

the class LocalPaginatedStorageRestoreTx method testSimpleRestore.

public void testSimpleRestore() throws Exception {
    List<Future<Void>> futures = new ArrayList<Future<Void>>();
    baseDocumentTx.declareIntent(new OIntentMassiveInsert());
    for (int i = 0; i < 8; i++) futures.add(executorService.submit(new DataPropagationTask()));
    for (Future<Void> future : futures) future.get();
    Thread.sleep(1500);
    copyDataFromTestWithoutClose();
    OStorage storage = baseDocumentTx.getStorage();
    baseDocumentTx.close();
    storage.close();
    testDocumentTx = new ODatabaseDocumentTx("plocal:" + buildDir.getAbsolutePath() + "/testLocalPaginatedStorageRestoreFromTx");
    testDocumentTx.open("admin", "admin");
    testDocumentTx.close();
    ODatabaseCompare databaseCompare = new ODatabaseCompare(testDocumentTx.getURL(), baseDocumentTx.getURL(), "admin", "admin", new OCommandOutputListener() {

        @Override
        public void onMessage(String text) {
            System.out.println(text);
        }
    });
    databaseCompare.setCompareIndexMetadata(true);
    Assert.assertTrue(databaseCompare.compare());
}
Also used : ODatabaseCompare(com.orientechnologies.orient.core.db.tool.ODatabaseCompare) ArrayList(java.util.ArrayList) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) Future(java.util.concurrent.Future) 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