use of com.instaclustr.esop.s3.ceph.CephBucketService in project esop by instaclustr.
the class CephS3BackupRestoreTest method testDownload.
@Test
public void testDownload() throws Exception {
CephS3TransferManagerFactory factory = getTransferManagerFactory();
CephBucketService s3BucketService = new CephBucketService(factory, getBackupOperationRequest());
Path tmp = Files.createTempDirectory("tmp");
tmp.toFile().deleteOnExit();
try {
s3BucketService.create(BUCKET_NAME);
AmazonS3 amazonS3Client = factory.build(getBackupOperationRequest()).getAmazonS3Client();
amazonS3Client.putObject(BUCKET_NAME, "cluster/dc/node/manifests/snapshot-name-" + BUCKET_NAME, "hello");
amazonS3Client.putObject(BUCKET_NAME, "snapshot/in/dir/my-name-" + BUCKET_NAME, "hello world");
amazonS3Client.listObjects(BUCKET_NAME).getObjectSummaries().forEach(summary -> logger.info(summary.getKey()));
final RestoreOperationRequest restoreOperationRequest = new RestoreOperationRequest();
restoreOperationRequest.storageLocation = new StorageLocation("ceph://" + BUCKET_NAME + "/cluster/dc/node");
final BackupOperationRequest backupOperationRequest = new BackupOperationRequest();
backupOperationRequest.storageLocation = new StorageLocation("ceph://" + BUCKET_NAME + "/cluster/dc/node");
final CephRestorer s3Restorer = new CephRestorer(factory, restoreOperationRequest);
final CephBackuper s3Backuper = new CephBackuper(factory, backupOperationRequest);
// 1
final Path downloadedFile = s3Restorer.downloadNodeFileToDir(tmp, Paths.get("manifests"), s -> s.contains("manifests/snapshot-name"));
assertTrue(Files.exists(downloadedFile));
// 2
final String content = s3Restorer.downloadNodeFileToString(Paths.get("manifests"), s -> s.contains("manifests/snapshot-name"));
Assert.assertEquals("hello", content);
// 3
final String content2 = s3Restorer.downloadFileToString(Paths.get("snapshot/in/dir"), s -> s.endsWith("my-name-" + BUCKET_NAME));
Assert.assertEquals("hello world", content2);
// 4
s3Restorer.downloadFile(tmp.resolve("some-file"), s3Restorer.objectKeyToRemoteReference(Paths.get("snapshot/in/dir/my-name-" + BUCKET_NAME)));
Assert.assertTrue(Files.exists(tmp.resolve("some-file")));
Assert.assertEquals("hello world", new String(Files.readAllBytes(tmp.resolve("some-file"))));
// backup
s3Backuper.uploadText("hello world", s3Backuper.objectKeyToRemoteReference(Paths.get("topology/some-file-in-here.txt")));
String text = s3Restorer.downloadFileToString(s3Restorer.objectKeyToRemoteReference(Paths.get("topology/some-file-in-here.txt")));
Assert.assertEquals("hello world", text);
} finally {
s3BucketService.delete(BUCKET_NAME);
deleteDirectory(Paths.get(target("commitlog_download_dir")));
Files.deleteIfExists(tmp.resolve("some-file"));
}
}
Aggregations