dk.netarkivet.archive.arcrepository.bitpreservation
Class DatabaseBasedActiveBitPreservation

java.lang.Object
  extended by dk.netarkivet.archive.arcrepository.bitpreservation.DatabaseBasedActiveBitPreservation
All Implemented Interfaces:
ActiveBitPreservation, CleanupIF

public final class DatabaseBasedActiveBitPreservation
extends java.lang.Object
implements ActiveBitPreservation, CleanupIF

The database based active bit preservation. This is the alternative to the FileBasedActiveBitPreservation. A database is used to handle the bitpreservation.


Method Summary
 void addMissingFilesToAdminData(java.lang.String... filenames)
          Old method, which refers to the checksum replica part of admin data.
 void changeStateForAdminData(java.lang.String filename)
          This should reestablish the state for the file.
 void cleanup()
          Method for cleaning up this instance.
 void close()
          Method for closing the running instance of this class.
 void findChangedFiles(Replica replica)
          The method is used to update the checksum for all the files in a replica.
 void findMissingFiles(Replica replica)
          This method retrieves the filelist for the replica, and then it updates the database with this list of filenames.
 java.lang.Iterable<java.lang.String> getChangedFiles(Replica replica)
          This method retrieves the name of all the files which has a wrong checksum for the replica.
 java.lang.Iterable<java.lang.String> getChangedFilesForAdminData()
          Old method, which refers to the checksum replica part of admin data.
 java.sql.Date getDateForChangedFiles(Replica replica)
          This method retrieves the date for the latest checksum update was performed for the replica.
 java.sql.Date getDateForMissingFiles(Replica replica)
          This method retrieves the date for the latest filelist update was performed for the replica.
static DatabaseBasedActiveBitPreservation getInstance()
          Method for retrieving the current instance of this class.
 java.lang.Iterable<java.lang.String> getMissingFiles(Replica replica)
          This method retrieves the name of all the files which are missing for the given replica.
 java.lang.Iterable<java.lang.String> getMissingFilesForAdminData()
          Old method, which refers to the checksum replica part of admin data.
 long getNumberOfChangedFiles(Replica replica)
          The method calculates the number of files which has a wrong checksum for the replica.
 long getNumberOfFiles(Replica replica)
          This method finds the number of files which are known to be in the archive of a specific replica.
 long getNumberOfMissingFiles(Replica replica)
          This method calculates the number of files which are not found in the given replica.
 PreservationState getPreservationState(java.lang.String filename)
          Method for retrieving the FilePreservationState for a specific file.
 java.util.Map<java.lang.String,PreservationState> getPreservationStateMap(java.lang.String... filenames)
          Method for retrieving the FilePreservationState for a list of files.
 void replaceChangedFile(Replica replica, java.lang.String filename, java.lang.String credentials, java.lang.String checksum)
          Check that the checksum of the file is indeed different to the value in admin data and reference replica.
 void uploadMissingFiles(Replica replica, java.lang.String... filenames)
          This method is used to upload missing files to a replica.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static DatabaseBasedActiveBitPreservation getInstance()
Method for retrieving the current instance of this class.

Returns:
The instance.

getNumberOfChangedFiles

public long getNumberOfChangedFiles(Replica replica)
                             throws ArgumentNotValid
The method calculates the number of files which has a wrong checksum for the replica. This simple counts all the entries in the replicafileinfo table for the replica where the filelist_status is set to CORRUPT.

Specified by:
getNumberOfChangedFiles in interface ActiveBitPreservation
Parameters:
replica - The replica for which to count the number of changed files.
Returns:
The number of files for the replica where the checksum does not correspond to the checksum of the same file in the other replicas.
Throws:
ArgumentNotValid - If the replica is null.

getChangedFiles

public java.lang.Iterable<java.lang.String> getChangedFiles(Replica replica)
                                                     throws ArgumentNotValid
This method retrieves the name of all the files which has a wrong checksum for the replica. It simple returns the filename of all the entries in the replicafileinfo table for the replica where the filelist_status is set to CORRUPT.

Specified by:
getChangedFiles in interface ActiveBitPreservation
Parameters:
replica - The replica for which the changed files should be found.
Returns:
The names of files in the replica where the checksum does not correspond to the checksum of the same file in the other replicas.
Throws:
ArgumentNotValid - If the replica is null.

getNumberOfMissingFiles

public long getNumberOfMissingFiles(Replica replica)
                             throws ArgumentNotValid
This method calculates the number of files which are not found in the given replica. This simple counts all the entries in the replicafileinfo table for the replica where the filelist_status is set to MISSING.

Specified by:
getNumberOfMissingFiles in interface ActiveBitPreservation
Parameters:
replica - The replica for which to count the number of missing files.
Returns:
The number of files which is missing in the replica.
Throws:
ArgumentNotValid - If the replica is null.

getMissingFiles

public java.lang.Iterable<java.lang.String> getMissingFiles(Replica replica)
                                                     throws ArgumentNotValid
This method retrieves the name of all the files which are missing for the given replica. It simple returns the filename of all the entries in the replicafileinfo table for the replica where the filelist_status is set to MISSING.

Specified by:
getMissingFiles in interface ActiveBitPreservation
Parameters:
replica - The replica for which the missing files should be found.
Returns:
The names of files in the replica which are missing.
Throws:
ArgumentNotValid - If the replica is null.

getDateForChangedFiles

public java.sql.Date getDateForChangedFiles(Replica replica)
                                     throws ArgumentNotValid
This method retrieves the date for the latest checksum update was performed for the replica. This means the date for the latest the replica has calculated the checksum of all the files within its archive. This method does not call out to the replicas. It only contacts the local database.

Specified by:
getDateForChangedFiles in interface ActiveBitPreservation
Parameters:
replica - The replica for which the date for last checksum update should be retrieved.
Returns:
The date for the last time the checksums has been update. If the checksum update has never occurred, then a null is returned.
Throws:
ArgumentNotValid - If the replica is null.

getDateForMissingFiles

public java.sql.Date getDateForMissingFiles(Replica replica)
                                     throws ArgumentNotValid
This method retrieves the date for the latest filelist update was performed for the replica. This means the date for the latest the replica has retrieved the list of all the files within the archive. This method does not call out to the replicas. It only contacts the local database.

Specified by:
getDateForMissingFiles in interface ActiveBitPreservation
Parameters:
replica - The replica for which the date for last filelist update should be retrieved.
Returns:
The date for the last time the filelist has been update. If the filelist update has never occurred, then a null is returned.
Throws:
ArgumentNotValid - If the replica is null.

findChangedFiles

public void findChangedFiles(Replica replica)
                      throws ArgumentNotValid
The method is used to update the checksum for all the files in a replica. The checksum for the replica is retrieved through GetAllChecksumMessages. This will take a very large amount of time for the bitarchive, but a more limited amount of time for the checksumarchive. The corresponding replicafileinfo entries in the database for the retrieved checksum results will be updated. Then a checksum update will be performed to check for corrupted replicafileinfo. Each replica can only be updated once at the time.

Specified by:
findChangedFiles in interface ActiveBitPreservation
Parameters:
replica - The replica to find the changed files for.
Throws:
ArgumentNotValid - If the replica is null.

findMissingFiles

public void findMissingFiles(Replica replica)
                      throws ArgumentNotValid
This method retrieves the filelist for the replica, and then it updates the database with this list of filenames. Each replica can only be updated once at the time.

Specified by:
findMissingFiles in interface ActiveBitPreservation
Parameters:
replica - The replica to find the missing files for.
Throws:
ArgumentNotValid - If the replica is null.

getPreservationState

public PreservationState getPreservationState(java.lang.String filename)
                                       throws ArgumentNotValid
Method for retrieving the FilePreservationState for a specific file.

Specified by:
getPreservationState in interface ActiveBitPreservation
Parameters:
filename - The name of the file for whom the FilePreservationState should be retrieved.
Returns:
The FilePreservationState for the file.
Throws:
ArgumentNotValid - If the filename is null or the empty string.

getPreservationStateMap

public java.util.Map<java.lang.String,PreservationState> getPreservationStateMap(java.lang.String... filenames)
                                                                          throws ArgumentNotValid
Method for retrieving the FilePreservationState for a list of files.

Specified by:
getPreservationStateMap in interface ActiveBitPreservation
Parameters:
filenames - The list of filenames whose FilePreservationState should be retrieved.
Returns:
A mapping between the filenames and their FilePreservationState.
Throws:
ArgumentNotValid - If the list of filenames are null.

getNumberOfFiles

public long getNumberOfFiles(Replica replica)
                      throws ArgumentNotValid
This method finds the number of files which are known to be in the archive of a specific replica. This method will not go out to the replica, but only contact the local database. The number of files in the replica is retrieved from the database by counting the amount of files in the replicafileinfo table which belong to the replica and which has the filelist_status set to OK.

Specified by:
getNumberOfFiles in interface ActiveBitPreservation
Parameters:
replica - The replica for which the number of files should be counted.
Returns:
The number of files for a specific replica.
Throws:
ArgumentNotValid - If the replica is null.

replaceChangedFile

public void replaceChangedFile(Replica replica,
                               java.lang.String filename,
                               java.lang.String credentials,
                               java.lang.String checksum)
                        throws ArgumentNotValid
Check that the checksum of the file is indeed different to the value in admin data and reference replica. If so, remove missing file and upload it from reference replica to this replica.

Specified by:
replaceChangedFile in interface ActiveBitPreservation
Parameters:
replica - The replica to restore file to
filename - The name of the file
credentials - The credentials used to perform this replace operation
checksum - The known bad checksum. Only a file with this bad checksum is attempted repaired.
Throws:
ArgumentNotValid - If any of the arguments are not valid.

uploadMissingFiles

public void uploadMissingFiles(Replica replica,
                               java.lang.String... filenames)
                        throws ArgumentNotValid,
                               IOFailure
This method is used to upload missing files to a replica. For each file a good version of this file is found, and it is reestablished on the replicas where it is missing.

Specified by:
uploadMissingFiles in interface ActiveBitPreservation
Parameters:
replica - The replica where the files are missing.
filenames - The names of the files which are missing in the given replica.
Throws:
ArgumentNotValid - If the replica or list of filenames is null, or if the list of filenames is empty.
IOFailure - If some files could not be established.

changeStateForAdminData

public void changeStateForAdminData(java.lang.String filename)
                             throws ArgumentNotValid,
                                    NotImplementedException
This should reestablish the state for the file.

Specified by:
changeStateForAdminData in interface ActiveBitPreservation
Parameters:
filename - The name of the file to change the state for.
Throws:
ArgumentNotValid - If the filename is invalid.
NotImplementedException - This will not be implemented.

getMissingFilesForAdminData

public java.lang.Iterable<java.lang.String> getMissingFilesForAdminData()
                                                                 throws NotImplementedException
Old method, which refers to the checksum replica part of admin data.

Specified by:
getMissingFilesForAdminData in interface ActiveBitPreservation
Returns:
Nothing, since it always throws an exception.
Throws:
NotImplementedException - This method will not be implemented.

getChangedFilesForAdminData

public java.lang.Iterable<java.lang.String> getChangedFilesForAdminData()
                                                                 throws NotImplementedException
Old method, which refers to the checksum replica part of admin data.

Specified by:
getChangedFilesForAdminData in interface ActiveBitPreservation
Returns:
Nothing, since it always throws an exception.
Throws:
NotImplementedException - This method will not be implemented.

addMissingFilesToAdminData

public void addMissingFilesToAdminData(java.lang.String... filenames)
                                throws ArgumentNotValid,
                                       NotImplementedException
Old method, which refers to the checksum replica part of admin data.

Specified by:
addMissingFilesToAdminData in interface ActiveBitPreservation
Parameters:
filenames - The list of filenames which should be added to admin data.
Throws:
NotImplementedException - This method will not be implemented.
ArgumentNotValid - If filenames invalid.

close

public void close()
Method for closing the running instance of this class.


cleanup

public void cleanup()
Method for cleaning up this instance.

Specified by:
cleanup in interface CleanupIF