Class JobDAO
- java.lang.Object
-
- dk.netarkivet.harvester.datamodel.JobDAO
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JobDAO()
constructor used when creating singleton.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
create(Job job)
Creates an instance in persistent storage of the given job.abstract boolean
exists(Long jobID)
Check whether a particular job exists.abstract Iterator<Job>
getAll()
Return a list of all jobs .abstract Iterator<Job>
getAll(JobStatus status)
Return a list of all jobs with the given status.abstract Iterator<Long>
getAllJobIds()
Return a list of all job_ids .abstract Iterator<Long>
getAllJobIds(JobStatus status)
Return a list of all job_id's representing jobs with the given status.abstract Iterator<Long>
getAllJobIds(JobStatus status, HarvestChannel channel)
Return a list of all job_id's representing jobs with the given status and channel.abstract int
getCountJobs()
Returns the number of jobs existing.static JobDAO
getInstance()
Gets the JobDAO singleton.abstract List<AliasInfo>
getJobAliasInfo(Job job)
Get a list of AliasInfo objects for all the domains included in the job.abstract List<Long>
getJobIDsForDuplicateReduction(long jobID)
Calculate all jobIDs to use for duplication reduction.abstract JobStatus
getJobStatus(Long jobID)
Get Jobstatus for the job with the given id.abstract List<JobStatusInfo>
getStatusInfo(JobStatus status)
Return status information for all jobs with given job status.abstract HarvestStatus
getStatusInfo(HarvestStatusQuery query)
Return status information for all jobs defined by the supplied query.Iterator<Job>
iterator()
Gets an iterator of all jobs.abstract Job
read(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
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
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 jobIOFailure
- If some IOException occurs while writing the job
-
exists
public abstract boolean exists(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 directory
-
read
public abstract Job read(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 nullUnknownID
- If the Job doesn't exist in the DAOIOFailure
- If writing the job to persistent storage failsPermissionDenied
- 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 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 Iterator<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 Iterator<Long> getAllJobIds(JobStatus status, HarvestChannel channel)
Return a list of all job_id's representing jobs with the given status and channel.- Parameters:
status
- A given statuschannel
- A givenHarvestChannel
- Returns:
- A list of all job_id's representing jobs with given status and channel.
-
getAll
public abstract Iterator<Job> getAll()
Return a list of all jobs .- Returns:
- A list of all jobs
-
iterator
public Iterator<Job> iterator()
Gets an iterator of all jobs. Implements the Iterable interface.
-
getAllJobIds
public abstract Iterator<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 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 List<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 unknownIOFailure
- on trouble getting jobIDs for deduplication from the metadata archive file.
-
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 jobIDIllegalState
- if the job with id jobID is not SUBMITTED or FAILED.
-
getJobStatus
public abstract JobStatus getJobStatus(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
-
-