Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestJob.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.Collection;
23 import java.util.Collections;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.concurrent.ConcurrentHashMap;
28 import java.util.concurrent.atomic.AtomicInteger;
29 import java.util.concurrent.atomic.AtomicLong;
31 
38 public final class IngestJob {
39 
40  private static final AtomicLong nextId = new AtomicLong(0L);
41  private final long id;
42  private final Map<Long, DataSourceIngestJob> dataSourceJobs;
43  private final AtomicInteger incompleteJobsCount;
44  private boolean started; // Guarded by this
45  private volatile boolean cancelled;
46 
56  IngestJob(Collection<Content> dataSources, IngestJobSettings settings, boolean runInteractively) {
57  this.id = IngestJob.nextId.getAndIncrement();
58  this.dataSourceJobs = new ConcurrentHashMap<>();
59  for (Content dataSource : dataSources) {
60  DataSourceIngestJob dataSourceIngestJob = new DataSourceIngestJob(this, dataSource, settings, runInteractively);
61  this.dataSourceJobs.put(dataSourceIngestJob.getId(), dataSourceIngestJob);
62  }
63  incompleteJobsCount = new AtomicInteger(dataSourceJobs.size());
64  }
65 
71  public long getId() {
72  return this.id;
73  }
74 
81  boolean hasIngestPipeline() {
82  for (DataSourceIngestJob dataSourceJob : this.dataSourceJobs.values()) {
83  if (dataSourceJob.hasIngestPipeline()) {
84  return true;
85  }
86  }
87  return false;
88  }
89 
96  synchronized List<IngestModuleError> start() {
97  List<IngestModuleError> errors = new ArrayList<>();
98  if (started) {
99  errors.add(new IngestModuleError("IngestJob", new IllegalStateException("Job already started")));
100  return errors;
101  }
102  started = true;
103 
104  for (DataSourceIngestJob dataSourceJob : this.dataSourceJobs.values()) {
105  errors.addAll(dataSourceJob.start());
106  if (!errors.isEmpty()) {
107  break;
108  }
109  }
110 
119  if (!errors.isEmpty()) {
120  for (DataSourceIngestJob dataSourceJob : this.dataSourceJobs.values()) {
121  dataSourceJob.cancel();
122  }
123  }
124 
125  return errors;
126  }
127 
134  return new ProgressSnapshot(true);
135  }
136 
142  public ProgressSnapshot getSnapshot(boolean getIngestTasksSnapshot) {
143  return new ProgressSnapshot(getIngestTasksSnapshot);
144  }
145 
152  List<DataSourceIngestJob.Snapshot> getDataSourceIngestJobSnapshots() {
153  List<DataSourceIngestJob.Snapshot> snapshots = new ArrayList<>();
154  for (DataSourceIngestJob dataSourceJob : this.dataSourceJobs.values()) {
155  snapshots.add(dataSourceJob.getSnapshot(true));
156  }
157  return snapshots;
158  }
159 
166  public void cancel() {
167  for (DataSourceIngestJob job : this.dataSourceJobs.values()) {
168  job.cancel();
169  }
170  this.cancelled = true;
171  }
172 
179  public boolean isCancelled() {
180  return this.cancelled;
181  }
182 
189  void dataSourceJobFinished(DataSourceIngestJob dataSourceIngestJob) {
190  if (incompleteJobsCount.decrementAndGet() == 0) {
191  IngestManager.getInstance().finishIngestJob(this);
192  }
193  }
194 
198  public final class ProgressSnapshot {
199 
200  private final List<DataSourceProcessingSnapshot> dataSourceProcessingSnapshots;
202  private boolean fileIngestRunning;
203  private Date fileIngestStartTime;
204  private final boolean jobCancelled;
205 
210  public final class DataSourceProcessingSnapshot {
211 
212  private final DataSourceIngestJob.Snapshot snapshot;
213 
214  private DataSourceProcessingSnapshot(DataSourceIngestJob.Snapshot snapshot) {
215  this.snapshot = snapshot;
216  }
217 
224  public String getDataSource() {
225  return snapshot.getDataSource();
226  }
227 
234  public boolean isCancelled() {
235  return snapshot.isCancelled();
236  }
237 
245  public List<String> getCancelledDataSourceIngestModules() {
246  return snapshot.getCancelledDataSourceIngestModules();
247  }
248 
249  }
250 
254  private ProgressSnapshot(boolean getIngestTasksSnapshot) {
255  dataSourceModule = null;
256  fileIngestRunning = false;
257  fileIngestStartTime = null;
258  dataSourceProcessingSnapshots = new ArrayList<>();
259  for (DataSourceIngestJob dataSourceJob : dataSourceJobs.values()) {
260  DataSourceIngestJob.Snapshot snapshot = dataSourceJob.getSnapshot(getIngestTasksSnapshot);
261  dataSourceProcessingSnapshots.add(new DataSourceProcessingSnapshot(snapshot));
262  if (null == dataSourceModule) {
263  DataSourceIngestPipeline.PipelineModule module = snapshot.getDataSourceLevelIngestModule();
264  if (null != module) {
265  dataSourceModule = new DataSourceIngestModuleHandle(dataSourceJobs.get(snapshot.getJobId()), module);
266  }
267  }
268  if (snapshot.fileIngestIsRunning()) {
269  fileIngestRunning = true;
270  }
271  Date childFileIngestStartTime = snapshot.fileIngestStartTime();
272  if (null != childFileIngestStartTime && (null == fileIngestStartTime || childFileIngestStartTime.before(fileIngestStartTime))) {
273  fileIngestStartTime = childFileIngestStartTime;
274  }
275  }
276  this.jobCancelled = cancelled;
277  }
278 
286  return this.dataSourceModule;
287  }
288 
295  public boolean fileIngestIsRunning() {
296  return this.fileIngestRunning;
297  }
298 
304  public Date fileIngestStartTime() {
305  return new Date(this.fileIngestStartTime.getTime());
306  }
307 
314  public boolean isCancelled() {
315  return this.jobCancelled;
316  }
317 
323  public List<DataSourceProcessingSnapshot> getDataSourceSnapshots() {
324  return Collections.unmodifiableList(this.dataSourceProcessingSnapshots);
325  }
326 
327  }
328 
334  public static class DataSourceIngestModuleHandle {
335 
336  private final DataSourceIngestJob job;
337  private final DataSourceIngestPipeline.PipelineModule module;
338  private final boolean cancelled;
339 
349  private DataSourceIngestModuleHandle(DataSourceIngestJob job, DataSourceIngestPipeline.PipelineModule module) {
350  this.job = job;
351  this.module = module;
352  this.cancelled = job.currentDataSourceIngestModuleIsCancelled();
353  }
354 
361  public String displayName() {
362  return this.module.getDisplayName();
363  }
364 
371  public Date startTime() {
372  return this.module.getProcessingStartTime();
373  }
374 
381  public boolean isCancelled() {
382  return this.cancelled;
383  }
384 
390  public void cancel() {
402  if (this.job.getCurrentDataSourceIngestModule() == this.module) {
403  this.job.cancelCurrentDataSourceIngestModule();
404  }
405  }
406 
407  }
408 
409 }
DataSourceIngestModuleHandle(DataSourceIngestJob job, DataSourceIngestPipeline.PipelineModule module)
Definition: IngestJob.java:349
static synchronized IngestManager getInstance()
final DataSourceIngestPipeline.PipelineModule module
Definition: IngestJob.java:337
final AtomicInteger incompleteJobsCount
Definition: IngestJob.java:43
final Map< Long, DataSourceIngestJob > dataSourceJobs
Definition: IngestJob.java:42
DataSourceIngestModuleHandle runningDataSourceIngestModule()
Definition: IngestJob.java:285
List< DataSourceProcessingSnapshot > getDataSourceSnapshots()
Definition: IngestJob.java:323
static final AtomicLong nextId
Definition: IngestJob.java:40
ProgressSnapshot getSnapshot(boolean getIngestTasksSnapshot)
Definition: IngestJob.java:142
final List< DataSourceProcessingSnapshot > dataSourceProcessingSnapshots
Definition: IngestJob.java:200

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.