Autopsy  3.1
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 2014 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;
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 
54  DataSourceIngestPipeline(DataSourceIngestJob job, List<IngestModuleTemplate> moduleTemplates) {
55  this.job = job;
56  for (IngestModuleTemplate template : moduleTemplates) {
57  if (template.isDataSourceIngestModuleTemplate()) {
58  PipelineModule module = new PipelineModule(template.createDataSourceIngestModule(), template.getModuleName());
59  modules.add(module);
60  }
61  }
62  }
63 
69  boolean isEmpty() {
70  return modules.isEmpty();
71  }
72 
78  synchronized List<IngestModuleError> startUp() {
79  List<IngestModuleError> errors = new ArrayList<>();
80  for (PipelineModule module : modules) {
81  try {
82  module.startUp(new IngestJobContext(this.job));
83  } catch (Throwable ex) { // Catch-all exception firewall
84  errors.add(new IngestModuleError(module.getDisplayName(), ex));
85  }
86  }
87  return errors;
88  }
89 
97  synchronized List<IngestModuleError> process(DataSourceIngestTask task) {
98  List<IngestModuleError> errors = new ArrayList<>();
99  Content dataSource = task.getDataSource();
100  for (PipelineModule module : modules) {
101  try {
102  this.currentModule = module;
103  String displayName = NbBundle.getMessage(this.getClass(),
104  "IngestJob.progress.dataSourceIngest.displayName",
105  module.getDisplayName(), dataSource.getName());
106  this.job.updateDataSourceIngestProgressBarDisplayName(displayName);
107  this.job.switchDataSourceIngestProgressBarToIndeterminate();
108  DataSourceIngestPipeline.ingestManager.setIngestTaskProgress(task, module.getDisplayName());
109  logger.log(Level.INFO, "{0} analysis of {1} (jobId={2}) starting", new Object[]{module.getDisplayName(), this.job.getDataSource().getName(), this.job.getDataSource().getId()});
110  module.process(dataSource, new DataSourceIngestModuleProgress(this.job));
111  logger.log(Level.INFO, "{0} analysis of {1} (jobId={2}) finished", new Object[]{module.getDisplayName(), this.job.getDataSource().getName(), this.job.getDataSource().getId()});
112  } catch (Throwable ex) { // Catch-all exception firewall
113  errors.add(new IngestModuleError(module.getDisplayName(), ex));
114  String msg = ex.getMessage();
115  // Jython run-time errors don't seem to have a message, but have details in toString.
116  if (msg == null)
117  msg = ex.toString();
118  MessageNotifyUtil.Notify.error(module.getDisplayName() + " Error", msg);
119  }
120  if (this.job.isCancelled()) {
121  break;
122  } else if (this.job.currentDataSourceIngestModuleIsCancelled()) {
123  this.job.currentDataSourceIngestModuleCancellationCompleted(currentModule.getDisplayName());
124  }
125  }
126  this.currentModule = null;
127  ingestManager.setIngestTaskProgressCompleted(task);
128  return errors;
129  }
130 
136  PipelineModule getCurrentlyRunningModule() {
137  return this.currentModule;
138  }
139 
144  static class PipelineModule implements DataSourceIngestModule {
145 
146  private final DataSourceIngestModule module;
147  private final String displayName;
148  private volatile Date processingStartTime;
149 
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 
195  @Override
196  public void startUp(IngestJobContext context) throws IngestModuleException {
197  this.module.startUp(context);
198  }
199 
203  @Override
204  public IngestModule.ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper) {
205  this.processingStartTime = new Date();
206  return this.module.process(dataSource, statusHelper);
207  }
208 
209  }
210 
211 }

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