use of com.instaclustr.esop.azure.AzureBucketService in project esop by instaclustr.
the class AzureListingAndBackupRemovalTest method destroy.
@Override
public void destroy() throws Exception {
try {
FileUtils.deleteDirectory(cassandraDir);
} catch (final Exception ex) {
logger.error("Unable to remove Cassandra dir " + cassandraDir);
}
try {
ListOperationRequest request = new ListOperationRequest();
request.storageLocation = new StorageLocation(getStorageLocation());
new AzureBucketService(cloudStorageAccountFactory, request).delete(BUCKET_NAME);
} catch (final Exception ex) {
logger.error("Unable to remove bucket " + BUCKET_NAME);
}
}
use of com.instaclustr.esop.azure.AzureBucketService in project esop by instaclustr.
the class AzureBackupRestoreTest method testDownload.
@Test
public void testDownload() throws Exception {
AzureBucketService azureBucketService = new AzureBucketService(cloudStorageAccountFactory, getBackupOperationRequest());
Path tmp = Files.createTempDirectory("tmp");
tmp.toFile().deleteOnExit();
try {
azureBucketService.create(BUCKET_NAME);
CloudBlobClient cloudBlobClient = cloudStorageAccountFactory.build(getBackupOperationRequest()).createCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.getContainerReference(BUCKET_NAME);
CloudBlockBlob blob1 = container.getBlockBlobReference("cluster/dc/node/manifests/snapshot-name-" + BUCKET_NAME);
blob1.uploadText("hello");
CloudBlockBlob blob2 = container.getBlockBlobReference("snapshot/in/dir/name-" + BUCKET_NAME);
blob2.uploadText("hello world");
final RestoreOperationRequest restoreOperationRequest = new RestoreOperationRequest();
restoreOperationRequest.storageLocation = new StorageLocation("azure://" + BUCKET_NAME + "/cluster/dc/node");
final BackupOperationRequest backupOperationRequest = new BackupOperationRequest();
backupOperationRequest.storageLocation = new StorageLocation("azure://" + BUCKET_NAME + "/cluster/dc/node");
final AzureRestorer azureRestorer = new AzureRestorer(cloudStorageAccountFactory, restoreOperationRequest);
final AzureBackuper azureBackuper = new AzureBackuper(cloudStorageAccountFactory, backupOperationRequest);
// 1
final Path downloadedFile = azureRestorer.downloadNodeFileToDir(tmp, Paths.get("manifests"), s -> s.contains("manifests/snapshot-name"));
assertTrue(Files.exists(downloadedFile));
// 2
final String content = azureRestorer.downloadNodeFileToString(Paths.get("manifests"), s -> s.contains("manifests/snapshot-name"));
Assert.assertEquals("hello", content);
// 3
final String content2 = azureRestorer.downloadFileToString(Paths.get("snapshot/in/dir"), s -> s.endsWith("name-" + BUCKET_NAME));
Assert.assertEquals("hello world", content2);
// 4
azureRestorer.downloadFile(tmp.resolve("some-file"), azureRestorer.objectKeyToRemoteReference(Paths.get("snapshot/in/dir/name-" + BUCKET_NAME)));
Assert.assertTrue(Files.exists(tmp.resolve("some-file")));
Assert.assertEquals("hello world", new String(Files.readAllBytes(tmp.resolve("some-file"))));
// backup
azureBackuper.uploadText("hello world", azureBackuper.objectKeyToRemoteReference(Paths.get("topology/some-file-in-here.txt")));
String text = azureRestorer.downloadFileToString(azureBackuper.objectKeyToRemoteReference(Paths.get("topology/some-file-in-here.txt")));
Assert.assertEquals("hello world", text);
String topology = azureRestorer.downloadFileToString(Paths.get("topology/some-file-in"), fileName -> fileName.contains("topology/some-file-in"));
Assert.assertEquals("hello world", topology);
} finally {
azureBucketService.delete(BUCKET_NAME);
deleteDirectory(Paths.get(target("commitlog_download_dir")));
Files.deleteIfExists(tmp.resolve("some-file"));
}
}
Aggregations