Autopsy  4.6.0
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 import java.util.logging.Level;
25 
26 import org.openide.util.NbBundle;
30 import org.sleuthkit.datamodel.AbstractFile;
31 import org.sleuthkit.datamodel.TskCoreException;
32 
40 final class FileIngestPipeline {
41 
42  private static final IngestManager ingestManager = IngestManager.getInstance();
43  private final DataSourceIngestJob job;
44  private final List<PipelineModule> modules = new ArrayList<>();
45  private Date startTime;
46  private volatile boolean running;
47 
57  FileIngestPipeline(DataSourceIngestJob job, List<IngestModuleTemplate> moduleTemplates) {
58  this.job = job;
59  for (IngestModuleTemplate template : moduleTemplates) {
60  if (template.isFileIngestModuleTemplate()) {
61  PipelineModule module = new PipelineModule(template.createFileIngestModule(), template.getModuleName());
62  modules.add(module);
63  }
64  }
65  }
66 
72  boolean isEmpty() {
73  return this.modules.isEmpty();
74  }
75 
81  boolean isRunning() {
82  return this.running;
83  }
84 
91  Date getStartTime() {
92  return this.startTime;
93  }
94 
100  synchronized List<IngestModuleError> startUp() {
101  this.startTime = new Date();
102  this.running = true;
103  List<IngestModuleError> errors = new ArrayList<>();
104  for (PipelineModule module : this.modules) {
105  try {
106  module.startUp(new IngestJobContext(this.job));
107  } catch (Throwable ex) { // Catch-all exception firewall
108  errors.add(new IngestModuleError(module.getDisplayName(), ex));
109  }
110  }
111  return errors;
112  }
113 
121  synchronized List<IngestModuleError> process(FileIngestTask task) {
122  List<IngestModuleError> errors = new ArrayList<>();
123  if (!this.job.isCancelled()) {
124  AbstractFile file = task.getFile();
125  for (PipelineModule module : this.modules) {
126  try {
127  FileIngestPipeline.ingestManager.setIngestTaskProgress(task, module.getDisplayName());
128  this.job.setCurrentFileIngestModule(module.getDisplayName(), task.getFile().getName());
129  module.process(file);
130  } catch (Throwable ex) { // Catch-all exception firewall
131  errors.add(new IngestModuleError(module.getDisplayName(), ex));
132  String msg = ex.getMessage();
133  // Jython run-time errors don't seem to have a message, but have details in toString.
134  if (msg == null) {
135  msg = ex.toString();
136  }
137  MessageNotifyUtil.Notify.error(NbBundle.getMessage(this.getClass(), "FileIngestPipeline.moduleError.title.text", module.getDisplayName()), msg);
138  }
139  if (this.job.isCancelled()) {
140  break;
141  }
142  }
143 
144  if (!this.job.isCancelled()) {
145  // Save any properties that have not already been saved to the database
146  try{
147  file.save();
148  } catch (TskCoreException ex){
149  Logger.getLogger(FileIngestPipeline.class.getName()).log(Level.SEVERE, "Failed to save data for file " + file.getId(), ex); //NON-NLS
150  }
151  IngestManager.getInstance().fireFileIngestDone(file);
152  }
153  file.close();
154  }
155  FileIngestPipeline.ingestManager.setIngestTaskProgressCompleted(task);
156  return errors;
157  }
158 
164  synchronized List<IngestModuleError> shutDown() {
165  List<IngestModuleError> errors = new ArrayList<>();
166  if (this.running == true) { // Don't shut down pipelines that never started
167  for (PipelineModule module : this.modules) {
168  try {
169  module.shutDown();
170  } catch (Throwable ex) { // Catch-all exception firewall
171  errors.add(new IngestModuleError(module.getDisplayName(), ex));
172  String msg = ex.getMessage();
173  // Jython run-time errors don't seem to have a message, but have details in toString.
174  if (msg == null) {
175  msg = ex.toString();
176  }
177  MessageNotifyUtil.Notify.error(NbBundle.getMessage(this.getClass(), "FileIngestPipeline.moduleError.title.text", module.getDisplayName()), msg);
178  }
179  }
180  }
181  this.running = false;
182  return errors;
183  }
184 
188  private static final class PipelineModule implements FileIngestModule {
189 
190  private final FileIngestModule module;
191  private final String displayName;
192 
200  PipelineModule(FileIngestModule module, String displayName) {
201  this.module = module;
202  this.displayName = displayName;
203  }
204 
210  String getClassName() {
211  return module.getClass().getCanonicalName();
212  }
213 
219  String getDisplayName() {
220  return displayName;
221  }
222 
223  @Override
224  public void startUp(IngestJobContext context) throws IngestModuleException {
225  module.startUp(context);
226  }
227 
228  @Override
229  public IngestModule.ProcessResult process(AbstractFile file) {
230  return module.process(file);
231  }
232 
233  @Override
234  public void shutDown() {
235  module.shutDown();
236  }
237 
238  }
239 
240 }
ProcessResult process(AbstractFile file)
IngestModule.ProcessResult process(AbstractFile file)
void startUp(IngestJobContext context)

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.