Search in sources :

Example 1 with BackupMetaData

use of com.netflix.exhibitor.core.backup.BackupMetaData in project exhibitor by soabase.

the class TestS3BackupProviderBase method testGetAvailableBackupKeys.

@Test
public void testGetAvailableBackupKeys() throws Exception {
    ObjectListing listing = new ObjectListing() {

        @Override
        public List<S3ObjectSummary> getObjectSummaries() {
            List<S3ObjectSummary> list = Lists.newArrayList();
            S3ObjectSummary summary = new S3ObjectSummary();
            summary.setKey("exhibitor-backup" + S3BackupProvider.SEPARATOR + "one" + S3BackupProvider.SEPARATOR + "1234");
            list.add(summary);
            summary = new S3ObjectSummary();
            summary.setKey("exhibitor-backup" + S3BackupProvider.SEPARATOR + "two" + S3BackupProvider.SEPARATOR + "1234");
            list.add(summary);
            summary = new S3ObjectSummary();
            summary.setKey("exhibitor-backup" + S3BackupProvider.SEPARATOR + "three" + S3BackupProvider.SEPARATOR + "1234");
            list.add(summary);
            return list;
        }
    };
    MockS3Client s3Client = new MockS3Client(null, listing);
    S3BackupProvider provider = new S3BackupProvider(new MockS3ClientFactory(s3Client), new PropertyBasedS3Credential(new Properties()), new PropertyBasedS3ClientConfig(new Properties()), null);
    List<BackupMetaData> backups = provider.getAvailableBackups(null, Maps.<String, String>newHashMap());
    List<String> backupNames = Lists.transform(backups, new Function<BackupMetaData, String>() {

        @Override
        public String apply(BackupMetaData metaData) {
            return metaData.getName();
        }
    });
    Assert.assertEquals(backupNames, Arrays.asList("one", "two", "three"));
}
Also used : BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) PropertyBasedS3ClientConfig(com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig) Properties(java.util.Properties) PropertyBasedS3Credential(com.netflix.exhibitor.core.s3.PropertyBasedS3Credential) Test(org.testng.annotations.Test)

Example 2 with BackupMetaData

use of com.netflix.exhibitor.core.backup.BackupMetaData in project exhibitor by soabase.

the class TestS3BackupProviderBase method getUploadedBytes.

private byte[] getUploadedBytes(File sourceFile) throws Exception {
    MockS3Client s3Client = new MockS3Client();
    S3BackupProvider provider = new S3BackupProvider(new MockS3ClientFactory(s3Client), new PropertyBasedS3Credential(new Properties()), new PropertyBasedS3ClientConfig(new Properties()), null);
    provider.uploadBackup(null, new BackupMetaData("test", 10), sourceFile, Maps.<String, String>newHashMap());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    for (byte[] bytes : s3Client.getUploadedBytes()) {
        out.write(bytes);
    }
    return out.toByteArray();
}
Also used : BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) PropertyBasedS3Credential(com.netflix.exhibitor.core.s3.PropertyBasedS3Credential) PropertyBasedS3ClientConfig(com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties)

Example 3 with BackupMetaData

use of com.netflix.exhibitor.core.backup.BackupMetaData in project exhibitor by soabase.

the class TestS3BackupProviderBase method testDownload.

@Test
public void testDownload() throws Exception {
    InputStream in = null;
    OutputStream out = null;
    File tempFile = File.createTempFile("test", ".test");
    try {
        in = new FileInputStream(sourceFile);
        PutObjectRequest dummyRequest = new PutObjectRequest("bucket", "exhibitor-backup" + S3BackupProvider.SEPARATOR + "test" + S3BackupProvider.SEPARATOR + 1, in, null);
        MockS3Client s3Client = new MockS3Client(null, null);
        s3Client.putObject(dummyRequest);
        S3BackupProvider provider = new S3BackupProvider(new MockS3ClientFactory(s3Client), new PropertyBasedS3Credential(new Properties()), new PropertyBasedS3ClientConfig(new Properties()), null);
        out = new FileOutputStream(tempFile);
        provider.downloadBackup(null, new BackupMetaData("test", 1), out, Maps.<String, String>newHashMap());
        Assert.assertEquals(Files.toByteArray(sourceFile), Files.toByteArray(tempFile));
    } finally {
        CloseableUtils.closeQuietly(in);
        CloseableUtils.closeQuietly(out);
        //noinspection ResultOfMethodCallIgnored
        tempFile.delete();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) PropertyBasedS3ClientConfig(com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) PropertyBasedS3Credential(com.netflix.exhibitor.core.s3.PropertyBasedS3Credential) File(java.io.File) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.testng.annotations.Test)

Example 4 with BackupMetaData

use of com.netflix.exhibitor.core.backup.BackupMetaData in project exhibitor by soabase.

the class IndexProcessor method addBackups.

private void addBackups(IndexBuilder builder) throws Exception {
    exhibitor.getLog().add(ActivityLog.Type.ERROR, "Index Build: Getting available backups");
    List<BackupMetaData> availableBackups = Lists.newArrayList(exhibitor.getBackupManager().getAvailableBackups());
    Collections.sort(availableBackups, new Comparator<BackupMetaData>() {

        @Override
        public int compare(BackupMetaData o1, BackupMetaData o2) {
            long diff = o1.getModifiedDate() - o2.getModifiedDate();
            return (diff < 0) ? -1 : ((diff > 0) ? 1 : 0);
        }
    });
    exhibitor.getLog().add(ActivityLog.Type.ERROR, "Index Build: there are " + availableBackups.size() + " available backups");
    int index = 0;
    for (BackupMetaData metaData : availableBackups) {
        exhibitor.getLog().add(ActivityLog.Type.INFO, String.format("Index Build: indexing backup log %d of %d", ++index, availableBackups.size()));
        BackupStream backupStream = exhibitor.getBackupManager().getBackupStream(metaData);
        if (backupStream != null) {
            try {
                builder.add(backupStream.getStream());
            } finally {
                CloseableUtils.closeQuietly(backupStream);
            }
        }
    }
}
Also used : BackupStream(com.netflix.exhibitor.core.backup.BackupStream) BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData)

Example 5 with BackupMetaData

use of com.netflix.exhibitor.core.backup.BackupMetaData in project exhibitor by soabase.

the class IndexResource method getAvailableBackups.

@Path("get-backups")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAvailableBackups() throws Exception {
    Collection<BackupMetaData> backups = context.getExhibitor().getBackupManager().getAvailableBackups();
    Collection<NameAndModifiedDate> transformed = Collections2.transform(backups, new Function<BackupMetaData, NameAndModifiedDate>() {

        @Override
        public NameAndModifiedDate apply(BackupMetaData backup) {
            return new NameAndModifiedDate(backup.getName(), backup.getModifiedDate());
        }
    });
    // move out of Google's TransformingRandomAccessList
    ArrayList<NameAndModifiedDate> cleaned = Lists.newArrayList(transformed);
    GenericEntity<Collection<NameAndModifiedDate>> entity = new GenericEntity<Collection<NameAndModifiedDate>>(cleaned) {
    };
    return Response.ok(entity).build();
}
Also used : BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) GenericEntity(javax.ws.rs.core.GenericEntity) Collection(java.util.Collection) NameAndModifiedDate(com.netflix.exhibitor.core.entities.NameAndModifiedDate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

BackupMetaData (com.netflix.exhibitor.core.backup.BackupMetaData)8 PropertyBasedS3ClientConfig (com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig)3 PropertyBasedS3Credential (com.netflix.exhibitor.core.s3.PropertyBasedS3Credential)3 File (java.io.File)3 Properties (java.util.Properties)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.testng.annotations.Test)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 ImmutableList (com.google.common.collect.ImmutableList)1 BackupStream (com.netflix.exhibitor.core.backup.BackupStream)1 NameAndModifiedDate (com.netflix.exhibitor.core.entities.NameAndModifiedDate)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Collection (java.util.Collection)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1