use of com.netflix.exhibitor.core.backup.BackupMetaData in project exhibitor by soabase.
the class FileSystemBackupProvider method getAvailableBackups.
@Override
public List<BackupMetaData> getAvailableBackups(Exhibitor exhibitor, Map<String, String> configValues) throws Exception {
ImmutableList.Builder<BackupMetaData> builder = ImmutableList.builder();
String pathname = configValues.get(CONFIG_DIRECTORY.getKey());
if (pathname != null) {
File directory = new File(pathname);
if (directory.isDirectory()) {
File[] files = directory.listFiles();
if (files != null) {
for (File nameDir : files) {
if (nameDir.isDirectory()) {
File[] subFiles = nameDir.listFiles();
if (subFiles != null) {
for (File version : subFiles) {
if (version.isFile()) {
builder.add(new BackupMetaData(nameDir.getName(), Long.parseLong(version.getName())));
}
}
}
}
}
}
}
}
return builder.build();
}
use of com.netflix.exhibitor.core.backup.BackupMetaData in project exhibitor by soabase.
the class FileSystemBackupProvider method uploadBackup.
@Override
public UploadResult uploadBackup(Exhibitor exhibitor, BackupMetaData backup, File source, Map<String, String> configValues) throws Exception {
String path = configValues.get(CONFIG_DIRECTORY.getKey());
if (path == null) {
exhibitor.getLog().add(ActivityLog.Type.ERROR, "No backup directory set in config");
return UploadResult.FAILED;
}
File directory = new File(path);
File destinationDirectory = new File(directory, backup.getName());
File destinationFile = new File(destinationDirectory, Long.toString(backup.getModifiedDate()));
if (destinationFile.exists()) {
return UploadResult.DUPLICATE;
}
if (!destinationDirectory.isDirectory() && !destinationDirectory.mkdirs()) {
exhibitor.getLog().add(ActivityLog.Type.ERROR, "Could not create backup directory: " + destinationDirectory);
return UploadResult.FAILED;
}
List<BackupMetaData> availableBackups = getAvailableBackups(exhibitor, configValues);
Files.copy(source, destinationFile);
UploadResult result = UploadResult.SUCCEEDED;
for (BackupMetaData existing : availableBackups) {
if (existing.getName().equals(backup.getName())) {
deleteBackup(exhibitor, existing, configValues);
result = UploadResult.REPLACED_OLD_VERSION;
}
}
return result;
}
use of com.netflix.exhibitor.core.backup.BackupMetaData in project exhibitor by soabase.
the class S3BackupProvider method uploadBackup.
@Override
public UploadResult uploadBackup(Exhibitor exhibitor, BackupMetaData backup, File source, final Map<String, String> configValues) throws Exception {
List<BackupMetaData> availableBackups = getAvailableBackups(exhibitor, configValues);
if (availableBackups.contains(backup)) {
return UploadResult.DUPLICATE;
}
RetryPolicy retryPolicy = makeRetryPolicy(configValues);
Throttle throttle = makeThrottle(configValues);
String key = toKey(backup, configValues);
if (source.length() < MIN_S3_PART_SIZE) {
byte[] bytes = Files.toByteArray(source);
S3Utils.simpleUploadFile(s3Client, bytes, configValues.get(CONFIG_BUCKET.getKey()), key);
} else {
multiPartUpload(source, configValues, retryPolicy, throttle, key);
}
UploadResult result = UploadResult.SUCCEEDED;
for (BackupMetaData existing : availableBackups) {
if (existing.getName().equals(backup.getName())) {
deleteBackup(exhibitor, existing, configValues);
result = UploadResult.REPLACED_OLD_VERSION;
}
}
return result;
}
Aggregations