Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceIngestPipeline.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.ingest;
20 
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;
27 import org.sleuthkit.datamodel.Content;
28 
36 final class DataSourceIngestPipeline {
37 
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;
43 
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());
58  modules.add(module);
59  }
60  }
61  }
62 
68  boolean isEmpty() {
69  return modules.isEmpty();
70  }
71 
77  synchronized List<IngestModuleError> startUp() {
78  List<IngestModuleError> errors = new ArrayList<>();
79  for (PipelineModule module : modules) {
80  try {
81  module.startUp(new IngestJobContext(this.ingestJobPipeline));
82  } catch (Throwable ex) { // Catch-all exception firewall
83  errors.add(new IngestModuleError(module.getDisplayName(), ex));
84  }
85  }
86  return errors;
87  }
88 
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) {
102  try {
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()}); //NON-NLS
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()}); //NON-NLS
113  } catch (Throwable ex) { // Catch-all exception firewall
114  errors.add(new IngestModuleError(module.getDisplayName(), ex));
115  }
116  if (this.ingestJobPipeline.isCancelled()) {
117  break;
118  } else if (this.ingestJobPipeline.currentDataSourceIngestModuleIsCancelled()) {
119  this.ingestJobPipeline.currentDataSourceIngestModuleCancellationCompleted(currentModule.getDisplayName());
120  }
121  }
122  }
123  this.currentModule = null;
124  ingestManager.setIngestTaskProgressCompleted(task);
125  return errors;
126  }
127 
133  PipelineModule getCurrentlyRunningModule() {
134  return this.currentModule;
135  }
136 
141  static class PipelineModule implements DataSourceIngestModule {
142 
143  private final DataSourceIngestModule module;
144  private final String displayName;
145  private volatile Date processingStartTime;
146 
155  PipelineModule(DataSourceIngestModule module, String displayName) {
156  this.module = module;
157  this.displayName = displayName;
158  this.processingStartTime = new Date();
159  }
160 
166  String getClassName() {
167  return this.module.getClass().getCanonicalName();
168  }
169 
175  String getDisplayName() {
176  return this.displayName;
177  }
178 
186  Date getProcessingStartTime() {
187  return this.processingStartTime;
188  }
189 
190  @Override
191  public void startUp(IngestJobContext context) throws IngestModuleException {
192  this.module.startUp(context);
193  }
194 
195  @Override
196  public IngestModule.ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper) {
197  this.processingStartTime = new Date();
198  return this.module.process(dataSource, statusHelper);
199  }
200 
201  }
202 
203 }

Copyright © 2012-2021 Basis Technology. Generated on: Tue Jan 19 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.