Search in sources :

Example 1 with S3TransferManagerFactory

use of com.instaclustr.esop.s3.aws.S3Module.S3TransferManagerFactory in project esop by instaclustr.

the class AWSS3BackupRestoreTest method testDownload.

@Test
public void testDownload() throws Exception {
    S3TransferManagerFactory factory = getTransferManagerFactory();
    S3BucketService s3BucketService = new S3BucketService(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("s3://" + BUCKET_NAME + "/cluster/dc/node");
        final BackupOperationRequest backupOperationRequest = new BackupOperationRequest();
        backupOperationRequest.storageLocation = new StorageLocation("s3://" + BUCKET_NAME + "/cluster/dc/node");
        final S3Restorer s3Restorer = new S3Restorer(factory, restoreOperationRequest);
        final S3Backuper s3Backuper = new S3Backuper(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"));
    }
}
Also used : Path(java.nio.file.Path) AmazonS3(com.amazonaws.services.s3.AmazonS3) BackupOperationRequest(com.instaclustr.esop.impl.backup.BackupOperationRequest) S3TransferManagerFactory(com.instaclustr.esop.s3.aws.S3Module.S3TransferManagerFactory) S3BucketService(com.instaclustr.esop.s3.aws.S3BucketService) S3Backuper(com.instaclustr.esop.s3.aws.S3Backuper) RestoreOperationRequest(com.instaclustr.esop.impl.restore.RestoreOperationRequest) StorageLocation(com.instaclustr.esop.impl.StorageLocation) S3Restorer(com.instaclustr.esop.s3.aws.S3Restorer) Test(org.testng.annotations.Test)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 StorageLocation (com.instaclustr.esop.impl.StorageLocation)1 BackupOperationRequest (com.instaclustr.esop.impl.backup.BackupOperationRequest)1 RestoreOperationRequest (com.instaclustr.esop.impl.restore.RestoreOperationRequest)1 S3Backuper (com.instaclustr.esop.s3.aws.S3Backuper)1 S3BucketService (com.instaclustr.esop.s3.aws.S3BucketService)1 S3TransferManagerFactory (com.instaclustr.esop.s3.aws.S3Module.S3TransferManagerFactory)1 S3Restorer (com.instaclustr.esop.s3.aws.S3Restorer)1 Path (java.nio.file.Path)1 Test (org.testng.annotations.Test)1