19 package org.sleuthkit.autopsy.ingest;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24 import java.util.logging.Level;
25 import org.openide.util.NbBundle;
37 final class DataSourceIngestPipeline {
39 private static final IngestManager ingestManager = IngestManager.getInstance();
40 private static final Logger logger = Logger.getLogger(DataSourceIngestPipeline.class.getName());
41 private final DataSourceIngestJob job;
42 private final List<PipelineModule> modules =
new ArrayList<>();
43 private volatile PipelineModule currentModule;
55 DataSourceIngestPipeline(DataSourceIngestJob job, List<IngestModuleTemplate> moduleTemplates) {
57 for (IngestModuleTemplate
template : moduleTemplates) {
58 if (
template.isDataSourceIngestModuleTemplate()) {
59 PipelineModule module =
new PipelineModule(
template.createDataSourceIngestModule(),
template.getModuleName());
71 return modules.isEmpty();
79 synchronized List<IngestModuleError> startUp() {
80 List<IngestModuleError> errors =
new ArrayList<>();
81 for (PipelineModule module : modules) {
83 module.startUp(
new IngestJobContext(this.job));
84 }
catch (Throwable ex) {
85 errors.add(
new IngestModuleError(module.getDisplayName(), ex));
99 synchronized List<IngestModuleError> process(DataSourceIngestTask task) {
100 List<IngestModuleError> errors =
new ArrayList<>();
101 if (!this.job.isCancelled()) {
102 Content dataSource = task.getDataSource();
103 for (PipelineModule module : modules) {
105 this.currentModule = module;
106 String displayName = NbBundle.getMessage(this.getClass(),
107 "IngestJob.progress.dataSourceIngest.displayName",
108 module.getDisplayName(), dataSource.getName());
109 this.job.updateDataSourceIngestProgressBarDisplayName(displayName);
110 this.job.switchDataSourceIngestProgressBarToIndeterminate();
111 DataSourceIngestPipeline.ingestManager.setIngestTaskProgress(task, module.getDisplayName());
112 logger.log(Level.INFO,
"{0} analysis of {1} (jobId={2}) starting",
new Object[]{module.getDisplayName(), this.job.getDataSource().getName(), this.job.getId()});
113 module.process(dataSource,
new DataSourceIngestModuleProgress(this.job));
114 logger.log(Level.INFO,
"{0} analysis of {1} (jobId={2}) finished",
new Object[]{module.getDisplayName(), this.job.getDataSource().getName(), this.job.getId()});
115 }
catch (Throwable ex) {
116 errors.add(
new IngestModuleError(module.getDisplayName(), ex));
118 if (this.job.isCancelled()) {
120 }
else if (this.job.currentDataSourceIngestModuleIsCancelled()) {
121 this.job.currentDataSourceIngestModuleCancellationCompleted(currentModule.getDisplayName());
125 this.currentModule = null;
126 ingestManager.setIngestTaskProgressCompleted(task);
135 PipelineModule getCurrentlyRunningModule() {
136 return this.currentModule;
143 static class PipelineModule
implements DataSourceIngestModule {
145 private final DataSourceIngestModule module;
146 private final String displayName;
147 private volatile Date processingStartTime;
157 PipelineModule(DataSourceIngestModule module, String displayName) {
158 this.module = module;
159 this.displayName = displayName;
160 this.processingStartTime =
new Date();
168 String getClassName() {
169 return this.module.getClass().getCanonicalName();
177 String getDisplayName() {
178 return this.displayName;
188 Date getProcessingStartTime() {
189 return this.processingStartTime;
193 public void startUp(IngestJobContext context)
throws IngestModuleException {
194 this.module.startUp(context);
198 public IngestModule.ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper) {
199 this.processingStartTime =
new Date();
200 return this.module.process(dataSource, statusHelper);