Search in sources :

Example 6 with BackupMetaData

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) File(java.io.File)

Example 7 with BackupMetaData

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;
}
Also used : BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) File(java.io.File)

Example 8 with BackupMetaData

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;
}
Also used : BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) RetryPolicy(org.apache.curator.RetryPolicy)

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