dk.netarkivet.harvester.datamodel
Class JobDAO

java.lang.Object
  extended by dk.netarkivet.harvester.datamodel.JobDAO
All Implemented Interfaces:
java.lang.Iterable<Job>
Direct Known Subclasses:
JobDBDAO

public abstract class JobDAO
extends java.lang.Object
implements java.lang.Iterable<Job>

Interface for creating and accessing jobs in persistent storage.


Constructor Summary
protected JobDAO()
          constructor used when creating singleton.
 
Method Summary
abstract  void create(Job job)
          Creates an instance in persistent storage of the given job.
abstract  boolean exists(java.lang.Long jobID)
          Check whether a particular job exists.
abstract  java.util.Iterator<Job> getAll()
          Return a list of all jobs .
abstract  java.util.Iterator<Job> getAll(JobStatus status)
          Return a list of all jobs with the given status.
abstract  java.util.Iterator<java.lang.Long> getAllJobIds()
          Return a list of all job_ids .
abstract  java.util.Iterator<java.lang.Long> getAllJobIds(JobStatus status)
          Return a list of all job_id's representing jobs with the given status.
abstract  java.util.Iterator<java.lang.Long> getAllJobIds(JobStatus status, JobPriority priority)
          Return a list of all job_id's representing jobs with the given status and priority.
abstract  int getCountJobs()
          Returns the number of jobs existing.
static JobDAO getInstance()
          Gets the JobDAO singleton.
abstract  java.util.List<java.lang.Long> getJobIDsForDuplicateReduction(long jobID)
          Calculate all jobIDs to use for duplication reduction.
abstract  JobStatus getJobStatus(java.lang.Long jobID)
          Get Jobstatus for the job with the given id.
abstract  HarvestStatus getStatusInfo(HarvestStatusQuery query)
          Return status information for all jobs defined by the supplied query.
abstract  java.util.List<JobStatusInfo> getStatusInfo(JobStatus status)
          Return status information for all jobs with given job status.
 java.util.Iterator<Job> iterator()
          Gets an iterator of all jobs.
abstract  Job read(java.lang.Long jobID)
          Reads a job from persistent storage.
abstract  long rescheduleJob(long oldJobID)
          Reschedule a job by creating a new job (in status NEW) and setting the old job to status RESUBMITTED.
static void reset()
          Reset the DAO instance.
abstract  void update(Job job)
          Update a Job in persistent storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JobDAO

protected JobDAO()
constructor used when creating singleton. Do not call directly.

Method Detail

getInstance

public static JobDAO getInstance()
Gets the JobDAO singleton.

Returns:
the JobDAO singleton

create

public abstract void create(Job job)
Creates an instance in persistent storage of the given job. If the job doesn't have an ID, one is generated for it.

Parameters:
job - a job to create in persistent storage.
Throws:
PermissionDenied - If a job already exists in persistent storage with id of the given job
IOFailure - If some IOException occurs while writing the job

exists

public abstract boolean exists(java.lang.Long jobID)
Check whether a particular job exists.

Parameters:
jobID - Id of the job.
Returns:
true if the job exists in any state.

getCountJobs

public abstract int getCountJobs()
Returns the number of jobs existing.

Returns:
Number of jobs in jobs dir

read

public abstract Job read(java.lang.Long jobID)
                  throws ArgumentNotValid,
                         UnknownID,
                         IOFailure
Reads a job from persistent storage.

Parameters:
jobID - The ID of the job to read
Returns:
a Job instance
Throws:
ArgumentNotValid - If failed to create job instance in case the configuration or priority is null, or the harvestID is invalid.
UnknownID - If the job with the given jobID does not exist in persistent storage.
IOFailure - If the loaded ID of job does not match the expected.

update

public abstract void update(Job job)
                     throws IOFailure
Update a Job in persistent storage.

Parameters:
job - The Job to update
Throws:
ArgumentNotValid - If the Job is null
UnknownID - If the Job doesn't exist in the DAO
IOFailure - If writing the job to persistent storage fails
PermissionDenied - If the job has been updated behind our backs

reset

public static void reset()
Reset the DAO instance. Only for use from within tests.


getAll

public abstract java.util.Iterator<Job> getAll(JobStatus status)
Return a list of all jobs with the given status.

Parameters:
status - A given status.
Returns:
A list of all job with given status
Throws:
ArgumentNotValid - If the given status is not one of the six valid states specified in JobStatus.

getAllJobIds

public abstract java.util.Iterator<java.lang.Long> getAllJobIds(JobStatus status)
Return a list of all job_id's representing jobs with the given status.

Parameters:
status - A given status.
Returns:
A list of all job_id's representing jobs with given status
Throws:
ArgumentNotValid - If the given status is not one of the six valid states specified in JobStatus.

getAllJobIds

public abstract java.util.Iterator<java.lang.Long> getAllJobIds(JobStatus status,
                                                                JobPriority priority)
Return a list of all job_id's representing jobs with the given status and priority.

Parameters:
status - A given status
priority - A given priority
Returns:
A list of all job_id's representing jobs with given status and priority.

getAll

public abstract java.util.Iterator<Job> getAll()
Return a list of all jobs .

Returns:
A list of all jobs

iterator

public java.util.Iterator<Job> iterator()
Gets an iterator of all jobs. Implements the Iterable interface.

Specified by:
iterator in interface java.lang.Iterable<Job>
Returns:
Iterator of all jobs, regardless of status.

getAllJobIds

public abstract java.util.Iterator<java.lang.Long> getAllJobIds()
Return a list of all job_ids .

Returns:
A list of all job_ids

getStatusInfo

public abstract HarvestStatus getStatusInfo(HarvestStatusQuery query)
Return status information for all jobs defined by the supplied query.

Parameters:
query - the user query
Returns:
A HarvestStatus object corresponding to the given query.
Throws:
IOFailure - on trouble in database access

getStatusInfo

public abstract java.util.List<JobStatusInfo> getStatusInfo(JobStatus status)
Return status information for all jobs with given job status.

Parameters:
status - The status asked for.
Returns:
A list of status objects with the pertinent information for all jobs with given job status.
Throws:
IOFailure - on trouble in database access

getJobIDsForDuplicateReduction

public abstract java.util.List<java.lang.Long> getJobIDsForDuplicateReduction(long jobID)
                                                                       throws UnknownID
Calculate all jobIDs to use for duplication reduction. More precisely, this method calculates the following: If the job ID corresponds to a partial harvest, all jobIDs from the previous scheduled harvest are returned, or the empty list if this harvest hasn't been scheduled before. If the job ID corresponds to a full harvest, the entire chain of harvests this is based on is returned, and all jobIDs from the previous chain of full harvests is returned.

Parameters:
jobID - The job ID to find duplicate reduction data for.
Returns:
A list of job IDs (possibly empty) of potential previous harvests of this job, to use for duplicate reduction.
Throws:
UnknownID - if job ID is unknown
IOFailure - on trouble getting ids from metadata storage

rescheduleJob

public abstract long rescheduleJob(long oldJobID)
Reschedule a job by creating a new job (in status NEW) and setting the old job to status RESUBMITTED. Notice the slightly confusing naming: The only job is marked RESUBMITTED, but the new job is not really submitted, that happens in a separate stage, the new job is in status NEW.

Parameters:
oldJobID - ID of a job to reschedule
Returns:
ID of the newly created job
Throws:
UnknownID - if no job exists with id jobID
IllegalState - if the job with id jobID is not SUBMITTED or FAILED.

getJobStatus

public abstract JobStatus getJobStatus(java.lang.Long jobID)
Get Jobstatus for the job with the given id.

Parameters:
jobID - A given Jobid
Returns:
the Jobstatus for the job with the given id.
Throws:
UnknownID - if no job exists with id jobID