Search in sources :

Example 1 with GCPBucketService

use of com.instaclustr.esop.gcp.GCPBucketService in project esop by instaclustr.

the class GoogleListingAndBackupRemovalTest 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 GCPBucketService(storageFactory, request).delete(BUCKET_NAME);
    } catch (final Exception ex) {
        logger.error("Unable to remove bucket " + BUCKET_NAME);
    }
}
Also used : GCPBucketService(com.instaclustr.esop.gcp.GCPBucketService) ListOperationRequest(com.instaclustr.esop.impl.list.ListOperationRequest) StorageLocation(com.instaclustr.esop.impl.StorageLocation)

Example 2 with GCPBucketService

use of com.instaclustr.esop.gcp.GCPBucketService in project esop by instaclustr.

the class GoogleStorageBackupRestoreTest method testDownload.

@Test
public void testDownload() throws Exception {
    GCPBucketService gcpBucketService = new GCPBucketService(googleStorageFactory, getBackupOperationRequest());
    Path tmp = Files.createTempDirectory("tmp");
    tmp.toFile().deleteOnExit();
    try {
        gcpBucketService.create(BUCKET_NAME);
        Storage storage = googleStorageFactory.build(getBackupOperationRequest());
        Bucket bucket = storage.get(BUCKET_NAME);
        bucket.create("cluster/dc/node/manifests/snapshot-name-" + BUCKET_NAME, "hello".getBytes());
        bucket.create("snapshot/in/dir/name-" + BUCKET_NAME, "hello world".getBytes());
        final RestoreOperationRequest restoreOperationRequest = new RestoreOperationRequest();
        restoreOperationRequest.storageLocation = new StorageLocation("gcp://" + BUCKET_NAME + "/cluster/dc/node");
        final BackupOperationRequest backupOperationRequest = new BackupOperationRequest();
        backupOperationRequest.storageLocation = new StorageLocation("gcp://" + BUCKET_NAME + "/cluster/dc/node");
        final GCPRestorer gcpRestorer = new GCPRestorer(googleStorageFactory, restoreOperationRequest);
        final GCPBackuper gcpBackuper = new GCPBackuper(googleStorageFactory, backupOperationRequest);
        // 1
        final Path downloadedFile = gcpRestorer.downloadNodeFileToDir(tmp, Paths.get("manifests"), s -> s.contains("manifests/snapshot-name"));
        assertTrue(Files.exists(downloadedFile));
        // 2
        final String content = gcpRestorer.downloadNodeFileToString(Paths.get("manifests"), s -> s.contains("manifests/snapshot-name"));
        Assert.assertEquals("hello", content);
        // 3
        // final String content2 = gcpRestorer.downloadFileToString(Paths.get("snapshot/in/dir"), s -> s.endsWith("name-" + BUCKET_NAME));
        // Assert.assertEquals("hello world", content2);
        // 4
        gcpRestorer.downloadFile(tmp.resolve("some-file"), gcpRestorer.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
        gcpBackuper.uploadText("hello world", gcpBackuper.objectKeyToRemoteReference(Paths.get("topology/some-file-in-here.txt")));
        String topology = gcpRestorer.downloadFileToString(Paths.get("topology/some-file-in"), fileName -> fileName.contains("topology/some-file-in"));
        Assert.assertEquals("hello world", topology);
    } finally {
        gcpBucketService.delete(BUCKET_NAME);
        deleteDirectory(Paths.get(target("commitlog_download_dir")));
        Files.deleteIfExists(tmp.resolve("some-file"));
    }
}
Also used : Path(java.nio.file.Path) Storage(com.google.cloud.storage.Storage) BackupOperationRequest(com.instaclustr.esop.impl.backup.BackupOperationRequest) Bucket(com.google.cloud.storage.Bucket) GCPBucketService(com.instaclustr.esop.gcp.GCPBucketService) GCPRestorer(com.instaclustr.esop.gcp.GCPRestorer) RestoreOperationRequest(com.instaclustr.esop.impl.restore.RestoreOperationRequest) StorageLocation(com.instaclustr.esop.impl.StorageLocation) GCPBackuper(com.instaclustr.esop.gcp.GCPBackuper) Test(org.testng.annotations.Test)

Aggregations

GCPBucketService (com.instaclustr.esop.gcp.GCPBucketService)2 StorageLocation (com.instaclustr.esop.impl.StorageLocation)2 Bucket (com.google.cloud.storage.Bucket)1 Storage (com.google.cloud.storage.Storage)1 GCPBackuper (com.instaclustr.esop.gcp.GCPBackuper)1 GCPRestorer (com.instaclustr.esop.gcp.GCPRestorer)1 BackupOperationRequest (com.instaclustr.esop.impl.backup.BackupOperationRequest)1 ListOperationRequest (com.instaclustr.esop.impl.list.ListOperationRequest)1 RestoreOperationRequest (com.instaclustr.esop.impl.restore.RestoreOperationRequest)1 Path (java.nio.file.Path)1 Test (org.testng.annotations.Test)1