Autopsy  4.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 2011-2016 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 
55  DataSourceIngestPipeline(DataSourceIngestJob job, List<IngestModuleTemplate> moduleTemplates) {
56  this.job = job;
57  for (IngestModuleTemplate template : moduleTemplates) {
58  if (template.isDataSourceIngestModuleTemplate()) {
59  PipelineModule module = new PipelineModule(template.createDataSourceIngestModule(), template.getModuleName());
60  modules.add(module);
61  }
62  }
63  }
64 
70  boolean isEmpty() {
71  return modules.isEmpty();
72  }
73 
79  synchronized List<IngestModuleError> startUp() {
80  List<IngestModuleError> errors = new ArrayList<>();
81  for (PipelineModule module : modules) {
82  try {
83  module.startUp(new IngestJobContext(this.job));
84  } catch (Throwable ex) { // Catch-all exception firewall
85  errors.add(new IngestModuleError(module.getDisplayName(), ex));
86  }
87  }
88  return errors;
89  }
90 
99  synchronized List<IngestModuleError> process(DataSourceIngestTask task) {
100  List<IngestModuleError> errors = new ArrayList<>();
101  if (!this.job.isCancelled()) {
102  Content dataSource = task.getDataSource();
103  for (PipelineModule module : modules) {
104  try {
105  this.currentModule = module;
106  String displayName = NbBundle.getMessage(this.getClass(),
107  "IngestJob.progress.dataSourceIngest.displayName",
108  module.getDisplayName(), dataSource.getName());
109  this.job.updateDataSourceIngestProgressBarDisplayName(displayName);
110  this.job.switchDataSourceIngestProgressBarToIndeterminate();
111  DataSourceIngestPipeline.ingestManager.setIngestTaskProgress(task, module.getDisplayName());
112  logger.log(Level.INFO, "{0} analysis of {1} (jobId={2}) starting", new Object[]{module.getDisplayName(), this.job.getDataSource().getName(), this.job.getDataSource().getId()}); //NON-NLS
113  module.process(dataSource, new DataSourceIngestModuleProgress(this.job));
114  logger.log(Level.INFO, "{0} analysis of {1} (jobId={2}) finished", new Object[]{module.getDisplayName(), this.job.getDataSource().getName(), this.job.getDataSource().getId()}); //NON-NLS
115  } catch (Throwable ex) { // Catch-all exception firewall
116  errors.add(new IngestModuleError(module.getDisplayName(), ex));
117  String msg = ex.getMessage();
118  // Jython run-time errors don't seem to have a message, but have details in toString.
119  if (msg == null) {
120  msg = ex.toString();
121  }
122  MessageNotifyUtil.Notify.error(NbBundle.getMessage(this.getClass(), "DataSourceIngestPipeline.moduleError.title.text", module.getDisplayName()), msg);
123  }
124  if (this.job.isCancelled()) {
125  break;
126  } else if (this.job.currentDataSourceIngestModuleIsCancelled()) {
127  this.job.currentDataSourceIngestModuleCancellationCompleted(currentModule.getDisplayName());
128  }
129  }
130  }
131  this.currentModule = null;
132  ingestManager.setIngestTaskProgressCompleted(task);
133  return errors;
134  }
135 
141  PipelineModule getCurrentlyRunningModule() {
142  return this.currentModule;
143  }
144 
149  static class PipelineModule implements DataSourceIngestModule {
150 
151  private final DataSourceIngestModule module;
152  private final String displayName;
153  private volatile Date processingStartTime;
154 
163  PipelineModule(DataSourceIngestModule module, String displayName) {
164  this.module = module;
165  this.displayName = displayName;
166  this.processingStartTime = new Date();
167  }
168 
174  String getClassName() {
175  return this.module.getClass().getCanonicalName();
176  }
177 
183  String getDisplayName() {
184  return this.displayName;
185  }
186 
194  Date getProcessingStartTime() {
195  return this.processingStartTime;
196  }
197 
198  @Override
199  public void startUp(IngestJobContext context) throws IngestModuleException {
200  this.module.startUp(context);
201  }
202 
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-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.