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;
36 final class DataSourceIngestPipeline {
38 private static final IngestManager ingestManager = IngestManager.getInstance();
39 private static final Logger logger = Logger.getLogger(DataSourceIngestPipeline.class.getName());
40 private final IngestJobPipeline ingestJobPipeline;
41 private final List<PipelineModule> modules =
new ArrayList<>();
42 private volatile PipelineModule currentModule;
53 DataSourceIngestPipeline(IngestJobPipeline ingestJobPipeline, List<IngestModuleTemplate> moduleTemplates) {
54 this.ingestJobPipeline = ingestJobPipeline;
55 for (IngestModuleTemplate
template : moduleTemplates) {
56 if (
template.isDataSourceIngestModuleTemplate()) {
57 PipelineModule module =
new PipelineModule(
template.createDataSourceIngestModule(),
template.getModuleName());
69 return modules.isEmpty();
77 synchronized List<IngestModuleError> startUp() {
78 List<IngestModuleError> errors =
new ArrayList<>();
79 for (PipelineModule module : modules) {
81 module.startUp(
new IngestJobContext(this.ingestJobPipeline));
82 }
catch (Throwable ex) {
83 errors.add(
new IngestModuleError(module.getDisplayName(), ex));
97 synchronized List<IngestModuleError> process(DataSourceIngestTask task) {
98 List<IngestModuleError> errors =
new ArrayList<>();
99 if (!this.ingestJobPipeline.isCancelled()) {
100 Content dataSource = task.getDataSource();
101 for (PipelineModule module : modules) {
103 this.currentModule = module;
104 String displayName = NbBundle.getMessage(this.getClass(),
105 "IngestJob.progress.dataSourceIngest.displayName",
106 module.getDisplayName(), dataSource.getName());
107 this.ingestJobPipeline.updateDataSourceIngestProgressBarDisplayName(displayName);
108 this.ingestJobPipeline.switchDataSourceIngestProgressBarToIndeterminate();
109 DataSourceIngestPipeline.ingestManager.setIngestTaskProgress(task, module.getDisplayName());
110 logger.log(Level.INFO,
"{0} analysis of {1} (pipeline={2}) starting",
new Object[]{module.getDisplayName(), ingestJobPipeline.getDataSource().getName(), ingestJobPipeline.getId()});
111 module.process(dataSource,
new DataSourceIngestModuleProgress(this.ingestJobPipeline));
112 logger.log(Level.INFO,
"{0} analysis of {1} (pipeline={2}) finished",
new Object[]{module.getDisplayName(), ingestJobPipeline.getDataSource().getName(), ingestJobPipeline.getId()});
113 }
catch (Throwable ex) {
114 errors.add(
new IngestModuleError(module.getDisplayName(), ex));
116 if (this.ingestJobPipeline.isCancelled()) {
118 }
else if (this.ingestJobPipeline.currentDataSourceIngestModuleIsCancelled()) {
119 this.ingestJobPipeline.currentDataSourceIngestModuleCancellationCompleted(currentModule.getDisplayName());
123 this.currentModule = null;
124 ingestManager.setIngestTaskProgressCompleted(task);
133 PipelineModule getCurrentlyRunningModule() {
134 return this.currentModule;
141 static class PipelineModule
implements DataSourceIngestModule {
143 private final DataSourceIngestModule module;
144 private final String displayName;
145 private volatile Date processingStartTime;
155 PipelineModule(DataSourceIngestModule module, String displayName) {
156 this.module = module;
157 this.displayName = displayName;
158 this.processingStartTime =
new Date();
166 String getClassName() {
167 return this.module.getClass().getCanonicalName();
175 String getDisplayName() {
176 return this.displayName;
186 Date getProcessingStartTime() {
187 return this.processingStartTime;
191 public void startUp(IngestJobContext context)
throws IngestModuleException {
192 this.module.startUp(context);
196 public IngestModule.ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper) {
197 this.processingStartTime =
new Date();
198 return this.module.process(dataSource, statusHelper);