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