public abstract class AbstractFileSystem extends java.lang.Object implements IBackupFileSystem, EventGenerator<BackupEvent>
Created by aagrawal on 8/30/18.
Modifier and Type | Field and Description |
---|---|
protected BackupMetrics |
backupMetrics |
protected com.google.inject.Provider<AbstractBackupPath> |
pathProvider |
Constructor and Description |
---|
AbstractFileSystem(IConfiguration configuration,
BackupMetrics backupMetrics,
BackupNotificationMgr backupNotificationMgr,
com.google.inject.Provider<AbstractBackupPath> pathProvider) |
Modifier and Type | Method and Description |
---|---|
void |
addObserver(EventObserver<BackupEvent> observer)
Subscribes
observer to receive generated events. |
java.util.concurrent.Future<java.nio.file.Path> |
asyncDownloadFile(AbstractBackupPath path,
int retry)
Download the file denoted by remotePath in an async fashion to the local file system denoted
by local path.
|
com.google.common.util.concurrent.ListenableFuture<AbstractBackupPath> |
asyncUploadAndDelete(AbstractBackupPath path,
int retry)
Upload the local file denoted by localPath in async fashion to the remote file system at
location denoted by remotePath.
|
boolean |
checkObjectExists(java.nio.file.Path remotePath)
Checks if the file denoted by remotePath exists on the remote file system.
|
void |
clearCache()
Clear the cache for the backup file system, if any.
|
protected abstract void |
deleteFiles(java.util.List<java.nio.file.Path> remotePaths) |
void |
deleteRemoteFiles(java.util.List<java.nio.file.Path> remotePaths)
Delete list of remote files from the remote file system.
|
protected abstract boolean |
doesRemoteFileExist(java.nio.file.Path remotePath) |
void |
downloadFile(AbstractBackupPath path,
java.lang.String suffix,
int retry)
Download the file denoted by remotePath to the local file system denoted by local path.
|
protected abstract void |
downloadFileImpl(AbstractBackupPath path,
java.lang.String suffix) |
int |
getDownloadTasksQueued()
Get the number of tasks en-queue in the filesystem for download.
|
java.nio.file.Path |
getPrefix()
Get the prefix path for the backup file system.
|
java.lang.String |
getShard()
Get the shard where this object should be stored.
|
int |
getUploadTasksQueued()
Get the number of tasks en-queue in the filesystem for upload.
|
java.util.Iterator<AbstractBackupPath> |
list(java.lang.String path,
java.util.Date start,
java.util.Date till)
List all files in the backup location for the specified time range.
|
java.util.Iterator<AbstractBackupPath> |
listPrefixes(java.util.Date date)
Get a list of prefixes for the cluster available in backup for the specified date
|
void |
notifyEventFailure(BackupEvent event)
Notify all the observers of an event failure who subscribed to receive events.
|
void |
notifyEventStart(BackupEvent event)
Notify all the observers of an event start who subscribed to receive events.
|
void |
notifyEventStop(BackupEvent event)
Notify all the observers of an event stop who subscribed to receive events.
|
void |
notifyEventSuccess(BackupEvent event)
Notify all the observers of an event success who subscribed to receive events.
|
void |
removeObserver(EventObserver<BackupEvent> observer)
Removes
observer from receiving any further events from this generator. |
void |
uploadAndDelete(AbstractBackupPath path,
int retry)
Upload the local file to its remote counterpart.
|
protected abstract long |
uploadFileImpl(AbstractBackupPath path) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
cleanup, getFileSize, listFileSystem, shutdown
protected final com.google.inject.Provider<AbstractBackupPath> pathProvider
protected final BackupMetrics backupMetrics
@Inject public AbstractFileSystem(IConfiguration configuration, BackupMetrics backupMetrics, BackupNotificationMgr backupNotificationMgr, com.google.inject.Provider<AbstractBackupPath> pathProvider)
public java.util.concurrent.Future<java.nio.file.Path> asyncDownloadFile(AbstractBackupPath path, int retry) throws java.util.concurrent.RejectedExecutionException
IBackupFileSystem
asyncDownloadFile
in interface IBackupFileSystem
path
- Backup path representing a local and remote file pairretry
- No. of times to retry to download a file from remote file system. If <1, it
will try to download file exactly once.java.util.concurrent.RejectedExecutionException
- if the queue is full and TIMEOUT is reached while trying
to add the work to the queue.public void downloadFile(AbstractBackupPath path, java.lang.String suffix, int retry) throws BackupRestoreException
IBackupFileSystem
downloadFile
in interface IBackupFileSystem
path
- Backup path representing a local and remote file pairretry
- No. of times to retry to download a file from remote file system. If <1, it
will try to download file exactly once.BackupRestoreException
- if file is not available, downloadable or any other error from
remote file system.protected abstract void downloadFileImpl(AbstractBackupPath path, java.lang.String suffix) throws BackupRestoreException
BackupRestoreException
public com.google.common.util.concurrent.ListenableFuture<AbstractBackupPath> asyncUploadAndDelete(AbstractBackupPath path, int retry) throws java.util.concurrent.RejectedExecutionException
IBackupFileSystem
asyncUploadAndDelete
in interface IBackupFileSystem
path
- AbstractBackupPath to be used to send backup notifications only.retry
- No of times to retry to upload a file. If <1, it will try to upload file
exactly once.java.util.concurrent.RejectedExecutionException
- if the queue is full and TIMEOUT is reached while trying
to add the work to the queue.public void uploadAndDelete(AbstractBackupPath path, int retry) throws BackupRestoreException
IBackupFileSystem
uploadAndDelete
in interface IBackupFileSystem
path
- Backup path representing a local and remote file pairretry
- No of times to retry to upload a file. If <1, it will try to upload file
exactly once.BackupRestoreException
- in case of failure to upload for any reason including file not
readable or remote file system errors.public boolean checkObjectExists(java.nio.file.Path remotePath)
IBackupFileSystem
checkObjectExists
in interface IBackupFileSystem
remotePath
- location on the remote file system.public void deleteRemoteFiles(java.util.List<java.nio.file.Path> remotePaths) throws BackupRestoreException
IBackupFileSystem
deleteRemoteFiles
in interface IBackupFileSystem
remotePaths
- list of files on remote file system to be deleted. This path may or may
not exist.BackupRestoreException
- in case of remote file system not able to process the request
or unable to reach.protected abstract void deleteFiles(java.util.List<java.nio.file.Path> remotePaths) throws BackupRestoreException
BackupRestoreException
protected abstract boolean doesRemoteFileExist(java.nio.file.Path remotePath)
protected abstract long uploadFileImpl(AbstractBackupPath path) throws BackupRestoreException
BackupRestoreException
public java.lang.String getShard()
IBackupFileSystem
getShard
in interface IBackupFileSystem
public java.nio.file.Path getPrefix()
IBackupFileSystem
getPrefix
in interface IBackupFileSystem
public java.util.Iterator<AbstractBackupPath> listPrefixes(java.util.Date date)
IBackupFileSystem
listPrefixes
in interface IBackupFileSystem
public java.util.Iterator<AbstractBackupPath> list(java.lang.String path, java.util.Date start, java.util.Date till)
IBackupFileSystem
list
in interface IBackupFileSystem
path
- This is used as the `prefix` for listing files in the filesystem. All the files
that start with this prefix will be returned.start
- Start date of the file upload.till
- End date of the file upload.public final void addObserver(EventObserver<BackupEvent> observer)
EventGenerator
observer
to receive generated events.addObserver
in interface EventGenerator<BackupEvent>
observer
- EventObserver
interested in receiving updates from this event
generator. May not be null
.public void removeObserver(EventObserver<BackupEvent> observer)
EventGenerator
observer
from receiving any further events from this generator.removeObserver
in interface EventGenerator<BackupEvent>
observer
- EventObserver
that is to stop receiving updates from this event
generator. May not be null
.public void notifyEventStart(BackupEvent event)
EventGenerator
notifyEventStart
in interface EventGenerator<BackupEvent>
event
- Generated event from the generatorpublic void notifyEventSuccess(BackupEvent event)
EventGenerator
notifyEventSuccess
in interface EventGenerator<BackupEvent>
event
- Event which was successful from the generator.public void notifyEventFailure(BackupEvent event)
EventGenerator
notifyEventFailure
in interface EventGenerator<BackupEvent>
event
- Event which was failure from the generator.public void notifyEventStop(BackupEvent event)
EventGenerator
notifyEventStop
in interface EventGenerator<BackupEvent>
event
- Event which was stopped from the generator.public int getUploadTasksQueued()
IBackupFileSystem
getUploadTasksQueued
in interface IBackupFileSystem
public int getDownloadTasksQueued()
IBackupFileSystem
getDownloadTasksQueued
in interface IBackupFileSystem
public void clearCache()
IBackupFileSystem
clearCache
in interface IBackupFileSystem