Autopsy  4.4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileIngestPipeline.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-2015 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 
25 import org.openide.util.NbBundle;
27 import org.sleuthkit.datamodel.AbstractFile;
28 
36 final class FileIngestPipeline {
37 
38  private static final IngestManager ingestManager = IngestManager.getInstance();
39  private final DataSourceIngestJob job;
40  private final List<PipelineModule> modules = new ArrayList<>();
41  private Date startTime;
42  private volatile boolean running;
43 
53  FileIngestPipeline(DataSourceIngestJob job, List<IngestModuleTemplate> moduleTemplates) {
54  this.job = job;
55  for (IngestModuleTemplate template : moduleTemplates) {
56  if (template.isFileIngestModuleTemplate()) {
57  PipelineModule module = new PipelineModule(template.createFileIngestModule(), template.getModuleName());
58  modules.add(module);
59  }
60  }
61  }
62 
68  boolean isEmpty() {
69  return this.modules.isEmpty();
70  }
71 
77  boolean isRunning() {
78  return this.running;
79  }
80 
87  Date getStartTime() {
88  return this.startTime;
89  }
90 
96  synchronized List<IngestModuleError> startUp() {
97  this.startTime = new Date();
98  this.running = true;
99  List<IngestModuleError> errors = new ArrayList<>();
100  for (PipelineModule module : this.modules) {
101  try {
102  module.startUp(new IngestJobContext(this.job));
103  } catch (Throwable ex) { // Catch-all exception firewall
104  errors.add(new IngestModuleError(module.getDisplayName(), ex));
105  }
106  }
107  return errors;
108  }
109 
117  synchronized List<IngestModuleError> process(FileIngestTask task) {
118  List<IngestModuleError> errors = new ArrayList<>();
119  if (!this.job.isCancelled()) {
120  AbstractFile file = task.getFile();
121  for (PipelineModule module : this.modules) {
122  try {
123  FileIngestPipeline.ingestManager.setIngestTaskProgress(task, module.getDisplayName());
124  this.job.setCurrentFileIngestModule(module.getDisplayName(), task.getFile().getName());
125  module.process(file);
126  } catch (Throwable ex) { // Catch-all exception firewall
127  errors.add(new IngestModuleError(module.getDisplayName(), ex));
128  String msg = ex.getMessage();
129  // Jython run-time errors don't seem to have a message, but have details in toString.
130  if (msg == null) {
131  msg = ex.toString();
132  }
133  MessageNotifyUtil.Notify.error(NbBundle.getMessage(this.getClass(), "FileIngestPipeline.moduleError.title.text", module.getDisplayName()), msg);
134  }
135  if (this.job.isCancelled()) {
136  break;
137  }
138  }
139  file.close();
140  if (!this.job.isCancelled()) {
141  IngestManager.getInstance().fireFileIngestDone(file);
142  }
143  }
144  FileIngestPipeline.ingestManager.setIngestTaskProgressCompleted(task);
145  return errors;
146  }
147 
153  synchronized List<IngestModuleError> shutDown() {
154  List<IngestModuleError> errors = new ArrayList<>();
155  if (this.running == true) { // Don't shut down pipelines that never started
156  for (PipelineModule module : this.modules) {
157  try {
158  module.shutDown();
159  } catch (Throwable ex) { // Catch-all exception firewall
160  errors.add(new IngestModuleError(module.getDisplayName(), ex));
161  String msg = ex.getMessage();
162  // Jython run-time errors don't seem to have a message, but have details in toString.
163  if (msg == null) {
164  msg = ex.toString();
165  }
166  MessageNotifyUtil.Notify.error(NbBundle.getMessage(this.getClass(), "FileIngestPipeline.moduleError.title.text", module.getDisplayName()), msg);
167  }
168  }
169  }
170  this.running = false;
171  return errors;
172  }
173 
177  private static final class PipelineModule implements FileIngestModule {
178 
179  private final FileIngestModule module;
180  private final String displayName;
181 
189  PipelineModule(FileIngestModule module, String displayName) {
190  this.module = module;
191  this.displayName = displayName;
192  }
193 
199  String getClassName() {
200  return module.getClass().getCanonicalName();
201  }
202 
208  String getDisplayName() {
209  return displayName;
210  }
211 
212  @Override
213  public void startUp(IngestJobContext context) throws IngestModuleException {
214  module.startUp(context);
215  }
216 
217  @Override
218  public IngestModule.ProcessResult process(AbstractFile file) {
219  return module.process(file);
220  }
221 
222  @Override
223  public void shutDown() {
224  module.shutDown();
225  }
226 
227  }
228 
229 }
ProcessResult process(AbstractFile file)
IngestModule.ProcessResult process(AbstractFile file)
void startUp(IngestJobContext context)

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.