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

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