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");
}
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);
}
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();
}
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();
}
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());
}
Aggregations