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"));
}
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();
}
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();
}
}
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);
}
}
}
}
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();
}
Aggregations