Autopsy  4.14.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;
28 import org.sleuthkit.datamodel.Content;
29 
37 final class DataSourceIngestPipeline {
38 
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;
44 
55  DataSourceIngestPipeline(DataSourceIngestJob job, List<IngestModuleTemplate> moduleTemplates) {
56  this.job = job;
57  for (IngestModuleTemplate template : moduleTemplates) {
58  if (template.isDataSourceIngestModuleTemplate()) {
59  PipelineModule module = new PipelineModule(template.createDataSourceIngestModule(), template.getModuleName());
60  modules.add(module);
61  }
62  }
63  }
64 
70  boolean isEmpty() {
71  return modules.isEmpty();
72  }
73 
79  synchronized List<IngestModuleError> startUp() {
80  List<IngestModuleError> errors = new ArrayList<>();
81  for (PipelineModule module : modules) {
82  try {
83  module.startUp(new IngestJobContext(this.job));
84  } catch (Throwable ex) { // Catch-all exception firewall
85  errors.add(new IngestModuleError(module.getDisplayName(), ex));
86  }
87  }
88  return errors;
89  }
90 
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) {
104  try {
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()}); //NON-NLS
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()}); //NON-NLS
115  } catch (Throwable ex) { // Catch-all exception firewall
116  errors.add(new IngestModuleError(module.getDisplayName(), ex));
117  }
118  if (this.job.isCancelled()) {
119  break;
120  } else if (this.job.currentDataSourceIngestModuleIsCancelled()) {
121  this.job.currentDataSourceIngestModuleCancellationCompleted(currentModule.getDisplayName());
122  }
123  }
124  }
125  this.currentModule = null;
126  ingestManager.setIngestTaskProgressCompleted(task);
127  return errors;
128  }
129 
135  PipelineModule getCurrentlyRunningModule() {
136  return this.currentModule;
137  }
138 
143  static class PipelineModule implements DataSourceIngestModule {
144 
145  private final DataSourceIngestModule module;
146  private final String displayName;
147  private volatile Date processingStartTime;
148 
157  PipelineModule(DataSourceIngestModule module, String displayName) {
158  this.module = module;
159  this.displayName = displayName;
160  this.processingStartTime = new Date();
161  }
162 
168  String getClassName() {
169  return this.module.getClass().getCanonicalName();
170  }
171 
177  String getDisplayName() {
178  return this.displayName;
179  }
180 
188  Date getProcessingStartTime() {
189  return this.processingStartTime;
190  }
191 
192  @Override
193  public void startUp(IngestJobContext context) throws IngestModuleException {
194  this.module.startUp(context);
195  }
196 
197  @Override
198  public IngestModule.ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper) {
199  this.processingStartTime = new Date();
200  return this.module.process(dataSource, statusHelper);
201  }
202 
203  }
204 
205 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.