dk.netarkivet.archive.arcrepository.bitpreservation
Class ActiveBitPreservation

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

public class ActiveBitPreservation
extends java.lang.Object
implements CleanupIF

Class handling integrity check of a given bit archive.

This class must run on the same machine as the arcrepository, as it uses the same admin data file (read-only). However, it still talks JMS with the arcrepository.


Constructor Summary
protected ActiveBitPreservation()
          Initalises an ActiveBitPreservation instance.
 
Method Summary
 void cleanup()
          Used to clean up a class from within a shutdown hook.
 void close()
          Shut down cleanly.
 void findMissingFiles(Location location)
          This method takes as input the name of a bitarchive location for which we have previously run a runFileListJob.
 void findWrongFiles(Location location)
          This method finds out which files in a given bitarchive are misrepresented in the admin data: Either having the wrong checksum or not being marked as uploaded when it actually is.
 void generateActionListForMissingFiles(Location location, Location referenceLocation)
          This methods figures out what actions to take for missing files by comparing checksums for missing files with the reference bitarchive.
 FilePreservationStatus getFilePreservationStatus(java.lang.String filename)
          Retrieve the preservation status for the file with a given filename.
static ActiveBitPreservation getInstance()
          Get singleton ActiveBitPreservation instance.
 boolean reestablishMissingFile(java.lang.String fileName, Location damagedBitarchive, java.lang.StringBuilder result, java.util.Locale l)
          Reestablish a file missing in a bitarchive.
 void removeAndGetFile(java.lang.String filename, Location bitarchive, java.lang.String checksum, java.lang.String credentials)
          Call upon the arc repository to remove a file, returning it to this machine.
 void runChecksumJob(Location location)
          Runs a checksum job on the bit archive at the given location.
 void runChecksumJob(Location location, java.util.List<java.lang.String> specifiedFiles)
          Runs a checksum job on the bit archive at the given location.
 void runFileListJob(Location location)
          Method to get a list of all files in a given bitarchive.
 void runFileListJob(Location location, Location referencedBy, java.util.List<java.lang.String> specifiedFiles)
          Method to get a list of all files in a given bitarchive and store list in the given directory.
 void setAdminChecksum(java.lang.String filename, java.lang.String checksum)
          Calls upon the arc repository to change the known checksum for the given file in one bitarchive.
 void setAdminData(java.lang.String filename, Location ba, BitArchiveStoreState state)
          Calls upon the arc repository to change the known state for the given file in one bitarchive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActiveBitPreservation

protected ActiveBitPreservation()
Initalises an ActiveBitPreservation instance.

Method Detail

getInstance

public static ActiveBitPreservation getInstance()
Get singleton ActiveBitPreservation instance.

Returns:
a singleton ActiveBitPreservation instance

findWrongFiles

public void findWrongFiles(Location location)
This method finds out which files in a given bitarchive are misrepresented in the admin data: Either having the wrong checksum or not being marked as uploaded when it actually is.

It uses the admindata file from the DIRS_ARCREPOSITORY_ADMIN directory, as well as the files output by a runChecksumJob. The erroneous files are stored in files.

Parameters:
location - the bitarchive location the checksumjob came from
Throws:
IOFailure - if the given directory does not contain a file checksumjobOutput/unsorted.txt, or it cannot be read
PermissionDenied - if the output directory cannot be created
ArgumentNotValid - if arguments location is null

findMissingFiles

public void findMissingFiles(Location location)
This method takes as input the name of a bitarchive location for which we have previously run a runFileListJob. It reads in the known files in the arcrepository from the AdminData directory specified in the Setting DIRS_ARCREPOSITORY_ADMIN. The two file lists are compared and a subdirectory missingFiles is created with two files: missingba.txt containing missing files, ie those in the arcrepository but not in the bitarchive. This file is unsorted. missingadmindata.txt containing extra files, ie. those found in the bitarchive but not in the arcrepository admin data. This file is unsorted.

Parameters:
location - the location to search for missing files
Throws:
ArgumentNotValid - if the given directory does not contain a file filelistOutput/sorted.txt, or the argument location is null
PermissionDenied - if the output directory cannot be created

generateActionListForMissingFiles

public void generateActionListForMissingFiles(Location location,
                                              Location referenceLocation)
This methods figures out what actions to take for missing files by comparing checksums for missing files with the reference bitarchive.

It assumes that findMissingFiles has been run first, so its output is available. It outputs to the following areas defined by WorkFiles:

Parameters:
location - The bitarchive we're doing bitpreservation for.
referenceLocation - A different bitarchive used for reference.
Throws:
IOFailure - if the necessary output from findMissingFiles cannot be found.
PermissionDenied - if the output directory cannot be created
ArgumentNotValid - if arguments are null

getFilePreservationStatus

public FilePreservationStatus getFilePreservationStatus(java.lang.String filename)
Retrieve the preservation status for the file with a given filename.

Parameters:
filename - a given filename
Returns:
the preservation status for the file with a given filename, or null if the file named does not exist.
Throws:
ArgumentNotValid - if argument is null or the empty string

setAdminData

public void setAdminData(java.lang.String filename,
                         Location ba,
                         BitArchiveStoreState state)
Calls upon the arc repository to change the known state for the given file in one bitarchive. This method uses JMS and blocks until a reply is sent.

Parameters:
filename - The file to change state for
ba - The bitarchive to change state for the file for.
state - The state to change to.
Throws:
ArgumentNotValid - if arguments are null or empty strings

setAdminChecksum

public void setAdminChecksum(java.lang.String filename,
                             java.lang.String checksum)
Calls upon the arc repository to change the known checksum for the given file in one bitarchive. This method uses JMS and blocks until a reply is sent.

Parameters:
filename - The file to change state for
checksum - The checksum to change to.
Throws:
ArgumentNotValid - if arguments are null or empty strings

runChecksumJob

public void runChecksumJob(Location location)
Runs a checksum job on the bit archive at the given location. Output is written to file returned by WorkFiles.getChecksumOutputFile(location).

Parameters:
location - One of the bitarchive locations.
Throws:
IOFailure - If unable to create output dirs or if unable to write/read output to files.

runChecksumJob

public void runChecksumJob(Location location,
                           java.util.List<java.lang.String> specifiedFiles)
Runs a checksum job on the bit archive at the given location. Output is written to file returned by WorkFiles.getChecksumOutputFile(location).

Parameters:
location - One of the bitarchive locations.
specifiedFiles - Only process specfied files. May be null, meaning all files.
Throws:
IOFailure - If unable to create output dirs or if unable to write/read output to files.

runFileListJob

public void runFileListJob(Location location)
                    throws ArgumentNotValid,
                           IOFailure
Method to get a list of all files in a given bitarchive. The result is stored in the file list output area (WorkFiles.FILES_ON_BA).

Parameters:
location - the location where the given bitarchive lies
Throws:
PermissionDenied - if the output directories cannot be created
IOFailure - if there is a problem writing the output file, or if the job fails for some reason
ArgumentNotValid

runFileListJob

public void runFileListJob(Location location,
                           Location referencedBy,
                           java.util.List<java.lang.String> specifiedFiles)
                    throws ArgumentNotValid,
                           IOFailure
Method to get a list of all files in a given bitarchive and store list in the given directory. The result is stored (unsorted) in the area specified by WorkFiles.FILES_ON_BA or WorkFiles.FILES_ON_REFERENCE_BA.

Parameters:
location - the location where the given bitarchive lies
referencedBy - The location that we are in the process of doing bit preservation for. This determines where output is placed.
specifiedFiles - only run the job on the specified files. May be null, meaning all files
Throws:
PermissionDenied - if the output directories cannot be created
IOFailure - if there is a problem writing the output file, or if the job fails for some reason
ArgumentNotValid

reestablishMissingFile

public boolean reestablishMissingFile(java.lang.String fileName,
                                      Location damagedBitarchive,
                                      java.lang.StringBuilder result,
                                      java.util.Locale l)
Reestablish a file missing in a bitarchive. The following pre-conditions for reestablishing the file are checked before changing anything: 1) the file is registered correctly in AdminData 2) the file is missing in the given bitarchive 3) the file is present in another bitarchive (the reference archive) 4) admin data and the reference archive agree on the checksum of the file. If these conditions are not satisfied, an error is appended to result and we return false without changing the bitarchives.

Parameters:
fileName - name of the file to reestablish
damagedBitarchive - Name of the bitarchive missing the file
l - the locale
result - Output buffer for writing a textual description of the result of the operation
Returns:
True if reestablishing succeeded

removeAndGetFile

public void removeAndGetFile(java.lang.String filename,
                             Location bitarchive,
                             java.lang.String checksum,
                             java.lang.String credentials)
Call upon the arc repository to remove a file, returning it to this machine. The file is left around in case problems are later discovered, and its location can be found in the log.

Parameters:
filename - The file to remove.
bitarchive - The bitarchive to remove the file from.
checksum - The checksum of the file.
credentials - Credentials required to run this operation.

close

public void close()
Shut down cleanly.


cleanup

public void cleanup()
Description copied from interface: CleanupIF
Used to clean up a class from within a shutdown hook. Must not do any logging. Program defensively, please.

Specified by:
cleanup in interface CleanupIF
See Also:
CleanupIF.cleanup()