Autopsy  4.14.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  }
133  if (this.job.isCancelled()) {
134  break;
135  }
136  }
137 
138  if (!this.job.isCancelled()) {
139  // Save any properties that have not already been saved to the database
140  try{
141  file.save();
142  } catch (TskCoreException ex){
143  Logger.getLogger(FileIngestPipeline.class.getName()).log(Level.SEVERE, "Failed to save data for file " + file.getId(), ex); //NON-NLS
144  }
145  IngestManager.getInstance().fireFileIngestDone(file);
146  }
147  file.close();
148  }
149  FileIngestPipeline.ingestManager.setIngestTaskProgressCompleted(task);
150  return errors;
151  }
152 
158  synchronized List<IngestModuleError> shutDown() {
159  List<IngestModuleError> errors = new ArrayList<>();
160  if (this.running == true) { // Don't shut down pipelines that never started
161  for (PipelineModule module : this.modules) {
162  try {
163  module.shutDown();
164  } catch (Throwable ex) { // Catch-all exception firewall
165  errors.add(new IngestModuleError(module.getDisplayName(), ex));
166  String msg = ex.getMessage();
167  // Jython run-time errors don't seem to have a message, but have details in toString.
168  if (msg == null) {
169  msg = ex.toString();
170  }
171  MessageNotifyUtil.Notify.error(NbBundle.getMessage(this.getClass(), "FileIngestPipeline.moduleError.title.text", module.getDisplayName()), msg);
172  }
173  }
174  }
175  this.running = false;
176  return errors;
177  }
178 
182  private static final class PipelineModule implements FileIngestModule {
183 
184  private final FileIngestModule module;
185  private final String displayName;
186 
194  PipelineModule(FileIngestModule module, String displayName) {
195  this.module = module;
196  this.displayName = displayName;
197  }
198 
204  String getClassName() {
205  return module.getClass().getCanonicalName();
206  }
207 
213  String getDisplayName() {
214  return displayName;
215  }
216 
217  @Override
218  public void startUp(IngestJobContext context) throws IngestModuleException {
219  module.startUp(context);
220  }
221 
222  @Override
223  public IngestModule.ProcessResult process(AbstractFile file) {
224  return module.process(file);
225  }
226 
227  @Override
228  public void shutDown() {
229  module.shutDown();
230  }
231 
232  }
233 
234 }
ProcessResult process(AbstractFile file)
IngestModule.ProcessResult process(AbstractFile file)
void startUp(IngestJobContext context)

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.