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 institution)
          This method takes as input the name of a bitarchive institution for which we have previously run a runFileListJob.
 void findWrongFiles(Location institution)
          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 institution, 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 institution)
          Runs a checksum job on the bit archive at the given institution.
 void runChecksumJob(Location institution, java.util.List<java.lang.String> specifiedFiles)
          Runs a checksum job on the bit archive at the given institution.
 void runFileListJob(Location institution)
          Method to get a list of all files in a given bitarchive.
 void runFileListJob(Location institution, 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 institution)
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 errenous files are stored in files.

Parameters:
institution - the institution 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

findMissingFiles

public void findMissingFiles(Location institution)
This method takes as input the name of a bitarchive institution 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 in the bitarchive but not in the arcrepository. This file is unsorted.

Parameters:
institution -
Throws:
ArgumentNotValid - if the given directory does not contain a file filelistOutput/sorted.txt.
PermissionDenied - if the output directory cannot be created

generateActionListForMissingFiles

public void generateActionListForMissingFiles(Location institution,
                                              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:
institution - 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

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.

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.

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.

runChecksumJob

public void runChecksumJob(Location institution)
Runs a checksum job on the bit archive at the given institution. Output is writting to WorkFiles.getChecksumOutputFile(institution).

Parameters:
institution - 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 institution,
                           java.util.List<java.lang.String> specifiedFiles)
Runs a checksum job on the bit archive at the given institution. Output is writting to WorkFiles.getChecksumOutputFile(institution).

Parameters:
institution - 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 institution)
                    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:
institution - the institution 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 institution,
                           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:
institution - the institution where the given bitarchive lies
referencedBy - The institution 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()