Add deep copying of auto ingest monitor snapshots

This commit is contained in:
Richard Cordovano 2017-09-21 15:23:30 -04:00
parent 5973fc39ee
commit 2abb755703
2 changed files with 73 additions and 7 deletions

View File

@ -148,6 +148,37 @@ public final class AutoIngestJob implements Comparable<AutoIngestJob>, Serializa
this.stageDetails = this.getProcessingStageDetails(); this.stageDetails = this.getProcessingStageDetails();
} }
/**
* Copy constructs an automated ingest job.
*
* @param job The job to be copied.
*/
AutoIngestJob(AutoIngestJob job) {
/*
* Version 0 fields.
*/
this.manifest = job.getManifest(); // Manifest is immutable.
this.nodeName = job.getProcessingHostName();
this.caseDirectoryPath = job.getCaseDirectoryPath().toString();
this.priority = job.getPriority();
this.stage = job.getProcessingStage();
this.stageStartDate = job.getProcessingStageStartDate();
this.dataSourceProcessor = job.getDataSourceProcessor();
this.ingestJob = job.getIngestJob();
this.cancelled = job.isCanceled();
this.completed = job.isCompleted();
this.completedDate = new Date(job.getCompletedDate().getTime());
this.errorsOccurred = job.getErrorsOccurred();
/*
* Version 1 fields.
*/
this.version = job.getVersion();
this.processingStatus = job.getProcessingStatus();
this.numberOfCrashes = job.getNumberOfCrashes();
this.stageDetails = job.getProcessingStageDetails(); // StageDetails is immutable.
}
/** /**
* Gets the job manifest. * Gets the job manifest.
* *
@ -292,6 +323,13 @@ public final class AutoIngestJob implements Comparable<AutoIngestJob>, Serializa
this.dataSourceProcessor = dataSourceProcessor; this.dataSourceProcessor = dataSourceProcessor;
} }
/**
* Gets the data source processor for the job.
*/
private DataSourceProcessor getDataSourceProcessor() {
return this.dataSourceProcessor;
}
/** /**
* Sets the ingest job for the auto ingest job. Used for obtaining * Sets the ingest job for the auto ingest job. Used for obtaining
* processing stage details, cancelling the currently running data source * processing stage details, cancelling the currently running data source
@ -498,6 +536,15 @@ public final class AutoIngestJob implements Comparable<AutoIngestJob>, Serializa
return -this.getManifest().getDateFileCreated().compareTo(otherJob.getManifest().getDateFileCreated()); return -this.getManifest().getDateFileCreated().compareTo(otherJob.getManifest().getDateFileCreated());
} }
/**
* gest the version number of the job data.
*
* @return The version number.
*/
private int getVersion() {
return this.version;
}
/** /**
* Comparator that supports doing a descending sort of jobs based on job * Comparator that supports doing a descending sort of jobs based on job
* completion date. * completion date.

View File

@ -142,7 +142,7 @@ public final class AutoIngestMonitor extends Observable implements PropertyChang
jobsSnapshot.removePendingJob(event.getJob()); jobsSnapshot.removePendingJob(event.getJob());
jobsSnapshot.addOrReplaceRunningJob(event.getJob()); jobsSnapshot.addOrReplaceRunningJob(event.getJob());
setChanged(); setChanged();
notifyObservers(jobsSnapshot); notifyObservers(jobsSnapshot.deepCopy());
} }
} }
@ -160,7 +160,7 @@ public final class AutoIngestMonitor extends Observable implements PropertyChang
jobsSnapshot.removePendingJob(job); jobsSnapshot.removePendingJob(job);
jobsSnapshot.addOrReplaceRunningJob(job); jobsSnapshot.addOrReplaceRunningJob(job);
setChanged(); setChanged();
notifyObservers(jobsSnapshot); notifyObservers(jobsSnapshot.deepCopy());
} }
} }
@ -176,7 +176,7 @@ public final class AutoIngestMonitor extends Observable implements PropertyChang
jobsSnapshot.removeRunningJob(job); jobsSnapshot.removeRunningJob(job);
jobsSnapshot.addOrReplaceCompletedJob(job); jobsSnapshot.addOrReplaceCompletedJob(job);
setChanged(); setChanged();
notifyObservers(jobsSnapshot); notifyObservers(jobsSnapshot.deepCopy());
} }
} }
@ -207,7 +207,7 @@ public final class AutoIngestMonitor extends Observable implements PropertyChang
*/ */
JobsSnapshot getJobsSnapshot() { JobsSnapshot getJobsSnapshot() {
synchronized (jobsLock) { synchronized (jobsLock) {
return jobsSnapshot; return jobsSnapshot.deepCopy();
} }
} }
@ -323,7 +323,7 @@ public final class AutoIngestMonitor extends Observable implements PropertyChang
}).start(); }).start();
} }
return jobsSnapshot; return jobsSnapshot.deepCopy();
} }
} }
@ -345,7 +345,7 @@ public final class AutoIngestMonitor extends Observable implements PropertyChang
synchronized (jobsLock) { synchronized (jobsLock) {
jobsSnapshot = queryCoordinationService(); jobsSnapshot = queryCoordinationService();
setChanged(); setChanged();
notifyObservers(jobsSnapshot); notifyObservers(jobsSnapshot.deepCopy());
} }
} }
} }
@ -468,8 +468,27 @@ public final class AutoIngestMonitor extends Observable implements PropertyChang
jobSet.add(job); jobSet.add(job);
} }
/**
* Creates a deep copy of a jobs snapshot.
*
* @return The deep copy.
*/
private JobsSnapshot deepCopy() {
JobsSnapshot copy = new JobsSnapshot();
this.pendingJobs.forEach((job) -> {
this.addOrReplacePendingJob(new AutoIngestJob(job));
});
this.runningJobs.forEach((job) -> {
this.addOrReplacePendingJob(new AutoIngestJob(job));
});
this.completedJobs.forEach((job) -> {
this.addOrReplacePendingJob(new AutoIngestJob(job));
});
return copy;
}
} }
/** /**
* Exception type thrown when there is an error completing an auto ingest * Exception type thrown when there is an error completing an auto ingest
* monitor operation. * monitor operation.