Search in sources :

Example 1 with BackupStream

use of com.netflix.exhibitor.core.backup.BackupStream 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 2 with BackupStream

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

the class S3BackupProvider method getBackupStream.

@Override
public BackupStream getBackupStream(Exhibitor exhibitor, BackupMetaData backup, Map<String, String> configValues) throws Exception {
    long startMs = System.currentTimeMillis();
    RetryPolicy retryPolicy = makeRetryPolicy(configValues);
    S3Object object = null;
    int retryCount = 0;
    while (object == null) {
        try {
            object = s3Client.getObject(configValues.get(CONFIG_BUCKET.getKey()), toKey(backup, configValues));
        } catch (AmazonS3Exception e) {
            if (e.getErrorType() == AmazonServiceException.ErrorType.Client) {
                exhibitor.getLog().add(ActivityLog.Type.ERROR, "Amazon client error: " + ActivityLog.getExceptionMessage(e));
                return null;
            }
            if (!retryPolicy.allowRetry(retryCount++, System.currentTimeMillis() - startMs, RetryLoop.getDefaultRetrySleeper())) {
                exhibitor.getLog().add(ActivityLog.Type.ERROR, "Retries exhausted: " + ActivityLog.getExceptionMessage(e));
                return null;
            }
        }
    }
    final Throttle throttle = makeThrottle(configValues);
    final InputStream in = object.getObjectContent();
    final InputStream wrappedstream = new InputStream() {

        @Override
        public void close() throws IOException {
            in.close();
        }

        @Override
        public int read() throws IOException {
            throttle.throttle(1);
            return in.read();
        }

        @Override
        public int read(byte[] b) throws IOException {
            int bytesRead = in.read(b);
            if (bytesRead > 0) {
                throttle.throttle(bytesRead);
            }
            return bytesRead;
        }

        @Override
        public int read(byte[] b, int off, int len) throws IOException {
            int bytesRead = in.read(b, off, len);
            if (bytesRead > 0) {
                throttle.throttle(bytesRead);
            }
            return bytesRead;
        }
    };
    return new BackupStream() {

        @Override
        public InputStream getStream() {
            return wrappedstream;
        }

        @Override
        public void close() throws IOException {
            in.close();
        }
    };
}
Also used : BackupStream(com.netflix.exhibitor.core.backup.BackupStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RetryPolicy(org.apache.curator.RetryPolicy)

Example 3 with BackupStream

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

the class FileSystemBackupProvider method getBackupStream.

@Override
public BackupStream getBackupStream(Exhibitor exhibitor, BackupMetaData backup, Map<String, String> configValues) throws Exception {
    File directory = new File(configValues.get(CONFIG_DIRECTORY.getKey()));
    File nameDirectory = new File(directory, backup.getName());
    File source = new File(nameDirectory, Long.toString(backup.getModifiedDate()));
    if (!source.exists()) {
        return null;
    }
    final InputStream in = new BufferedInputStream(new FileInputStream(source));
    return new BackupStream() {

        @Override
        public InputStream getStream() {
            return in;
        }

        @Override
        public void close() throws IOException {
            in.close();
        }
    };
}
Also used : BackupStream(com.netflix.exhibitor.core.backup.BackupStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

BackupStream (com.netflix.exhibitor.core.backup.BackupStream)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 BackupMetaData (com.netflix.exhibitor.core.backup.BackupMetaData)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 RetryPolicy (org.apache.curator.RetryPolicy)1