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 teh 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.
 FilePreservationState getFilePreservationState(java.lang.String filename)
          Method for retrieving the FilePreservationState for a specific file.
 java.util.Map<java.lang.String,FilePreservationState> getFilePreservationStateMap(java.lang.String... filenames)
          Method for retrieving the FilePreservationState for a list of files.
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.
 void rebuildDatabase()
          This is a method to recreate the database, if it somehow has been lost.
 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.

rebuildDatabase

public void rebuildDatabase()
This is a method to recreate the database, if it somehow has been lost. It just calls all the replicas and retrieves the checksum for each replica in the ChecksumEntry form, which contain both the checksum and the filenames. Thus the names of all the files within any replica should be retrieved, along with at least one checksum. These checksum results should then be put into the database.


getNumberOfChangedFiles

public long getNumberOfChangedFiles(Replica replica)
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.

getChangedFiles

public 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. 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.

getNumberOfMissingFiles

public long getNumberOfMissingFiles(Replica replica)
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.

getMissingFiles

public 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. 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.

getDateForChangedFiles

public java.sql.Date getDateForChangedFiles(Replica replica)
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.

getDateForMissingFiles

public java.sql.Date getDateForMissingFiles(Replica replica)
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.

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 either through a ChecksumJob (for a bitarchive) or through a GetAllChecksumMessage (for a checksumarchive). 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.

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.

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

getFilePreservationState

public FilePreservationState getFilePreservationState(java.lang.String filename)
                                               throws NotImplementedException,
                                                      ArgumentNotValid
Method for retrieving the FilePreservationState for a specific file.

Specified by:
getFilePreservationState in interface ActiveBitPreservation
Parameters:
filename - The name of the file for whom the FilePreservationState should be retrieved.
Returns:
The FilePreservationState for the file.
Throws:
NotImplementedException - This method has not yet been implemented.
ArgumentNotValid - If the filename does not have a valid name.

getFilePreservationStateMap

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

Specified by:
getFilePreservationStateMap in interface ActiveBitPreservation
Parameters:
filenames - The list of filenames whos FilePreservationState should be retrieved.
Returns:
A mapping between the filenames and their FilePreservationState.
Throws:
NotImplementedException - Since it has not yet been implemented.
ArgumentNotValid - If the filenames are invalid.

getNumberOfFiles

public long getNumberOfFiles(Replica replica)
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.

replaceChangedFile

public void replaceChangedFile(Replica replica,
                               java.lang.String filename,
                               java.lang.String credentials,
                               java.lang.String checksum)
                        throws UnknownID,
                               IOFailure,
                               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:
IOFailure - if the file cannot be reestablished.
UnknownID - if the file is not in correct state.
ArgumentNotValid - if any of the arguments are not valid.

uploadMissingFiles

public void uploadMissingFiles(Replica replica,
                               java.lang.String... filenames)
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.

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 - Since it has not yet been 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 teh 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