19 package org.sleuthkit.autopsy.ingest;
21 import com.google.common.util.concurrent.ThreadFactoryBuilder;
22 import java.awt.EventQueue;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.io.Serializable;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.Date;
30 import java.util.EnumSet;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.List;
36 import java.util.concurrent.Callable;
37 import java.util.concurrent.ConcurrentHashMap;
38 import java.util.concurrent.ExecutorService;
39 import java.util.concurrent.Executors;
40 import java.util.concurrent.Future;
41 import java.util.concurrent.atomic.AtomicLong;
42 import java.util.logging.Level;
43 import java.util.stream.Collectors;
44 import java.util.stream.Stream;
45 import javax.annotation.concurrent.GuardedBy;
46 import javax.annotation.concurrent.Immutable;
47 import javax.annotation.concurrent.ThreadSafe;
48 import javax.swing.JOptionPane;
49 import org.netbeans.api.progress.ProgressHandle;
50 import org.openide.util.Cancellable;
51 import org.openide.util.NbBundle;
52 import org.openide.windows.WindowManager;
121 @GuardedBy(
"IngestManager.class")
125 private final ExecutorService
startIngestJobsExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("IM-start-ingest-jobs-%d").build());
130 private final ExecutorService
eventPublishingExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("IM-ingest-events-%d").build());
149 if (null == instance) {
151 instance.subscribeToServiceMonitorEvents();
152 instance.subscribeToCaseEvents();
190 PropertyChangeListener propChangeListener = (PropertyChangeEvent evt) -> {
205 logger.log(Level.SEVERE,
"Service {0} is down, cancelling all running ingest jobs", serviceDisplayName);
207 EventQueue.invokeLater(
new Runnable() {
210 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
211 NbBundle.getMessage(this.getClass(),
"IngestManager.cancellingIngest.msgDlg.text"),
212 NbBundle.getMessage(this.getClass(),
"IngestManager.serviceIsDown.msgDlg.text", serviceDisplayName),
213 JOptionPane.ERROR_MESSAGE);
227 Set<String> servicesList =
new HashSet<>();
239 if (event.getNewValue() != null) {
254 void handleCaseOpened() {
259 String channelPrefix = openedCase.
getName();
264 }
catch (NoCurrentCaseException | AutopsyEventException ex) {
265 logger.log(Level.SEVERE,
"Failed to open remote events channel", ex);
266 MessageNotifyUtil.Notify.error(NbBundle.getMessage(
IngestManager.class,
"IngestManager.OpenEventChannel.Fail.Title"),
267 NbBundle.getMessage(
IngestManager.class,
"IngestManager.OpenEventChannel.Fail.ErrMsg"));
279 void handleCaseClosed() {
303 IngestJobInputStream stream =
new IngestJobInputStream(job);
304 if (stream.getIngestJobStartResult().getJob() != null) {
306 }
else if (stream.getIngestJobStartResult().getModuleErrors().isEmpty()) {
307 for (
IngestModuleError error : stream.getIngestJobStartResult().getModuleErrors()) {
308 logger.log(Level.SEVERE, String.format(
"%s ingest module startup error for %s", error.getModuleDisplayName(), dataSource.getName()), error.getThrowable());
310 throw new TskCoreException(
"Error starting ingest modules");
312 throw new TskCoreException(
"Error starting ingest modules", stream.getIngestJobStartResult().getStartupException());
336 if (job.hasIngestPipeline()) {
355 if (job.hasIngestPipeline()) {
375 if (job.hasIngestPipeline()) {
376 return startIngestJob(job);
392 "IngestManager.startupErr.dlgTitle=Ingest Module Startup Failure",
393 "IngestManager.startupErr.dlgMsg=Unable to start up one or more ingest modules, ingest cancelled.",
394 "IngestManager.startupErr.dlgSolution=Please disable the failed modules or fix the errors before restarting ingest.",
395 "IngestManager.startupErr.dlgErrorList=Errors:"
397 IngestJobStartResult startIngestJob(IngestJob job) {
398 List<IngestModuleError> errors = null;
401 openCase = Case.getCurrentCaseThrows();
402 }
catch (NoCurrentCaseException ex) {
403 return new IngestJobStartResult(null,
new IngestManagerException(
"Exception while getting open case.", ex), Collections.<IngestModuleError>emptyList());
405 if (openCase.getCaseType() == Case.CaseType.MULTI_USER_CASE) {
408 if (RuntimeProperties.runningWithGUI()) {
409 EventQueue.invokeLater(
new Runnable() {
412 String serviceDisplayName = ServicesMonitor.Service.REMOTE_CASE_DATABASE.getDisplayName();
413 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
414 NbBundle.getMessage(this.getClass(),
"IngestManager.cancellingIngest.msgDlg.text"),
415 NbBundle.getMessage(this.getClass(),
"IngestManager.serviceIsDown.msgDlg.text", serviceDisplayName),
416 JOptionPane.ERROR_MESSAGE);
420 return new IngestJobStartResult(null,
new IngestManagerException(
"Ingest aborted. Remote database is down"), Collections.<IngestModuleError>emptyList());
422 }
catch (ServicesMonitor.ServicesMonitorException ex) {
423 return new IngestJobStartResult(null,
new IngestManagerException(
"Database server is down", ex), Collections.<IngestModuleError>emptyList());
434 IngestManager.logger.log(Level.INFO,
"Starting ingest job {0}", job.getId());
435 errors = job.start();
436 if (errors.isEmpty()) {
437 this.fireIngestJobStarted(job.getId());
442 for (IngestModuleError error : errors) {
443 logger.log(Level.SEVERE, String.format(
"Error starting %s ingest module for job %d", error.getModuleDisplayName(), job.getId()), error.getThrowable());
445 IngestManager.logger.log(Level.SEVERE,
"Ingest job {0} could not be started", job.getId());
446 if (RuntimeProperties.runningWithGUI()) {
447 final StringBuilder message =
new StringBuilder(1024);
448 message.append(Bundle.IngestManager_startupErr_dlgMsg()).append(
"\n");
449 message.append(Bundle.IngestManager_startupErr_dlgSolution()).append(
"\n\n");
450 message.append(Bundle.IngestManager_startupErr_dlgErrorList()).append(
"\n");
451 for (IngestModuleError error : errors) {
452 String moduleName = error.getModuleDisplayName();
453 String errorMessage = error.getThrowable().getLocalizedMessage();
454 message.append(moduleName).append(
": ").append(errorMessage).append(
"\n");
456 message.append(
"\n\n");
457 EventQueue.invokeLater(() -> {
458 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), message, Bundle.IngestManager_startupErr_dlgTitle(), JOptionPane.ERROR_MESSAGE);
461 return new IngestJobStartResult(null,
new IngestManagerException(
"Errors occurred while starting ingest"), errors);
464 return new IngestJobStartResult(job, null, errors);
472 void finishIngestJob(IngestJob job) {
473 long jobId = job.getId();
477 if (!job.isCancelled()) {
478 IngestManager.logger.log(Level.INFO,
"Ingest job {0} completed", jobId);
479 fireIngestJobCompleted(jobId);
481 IngestManager.logger.log(Level.INFO,
"Ingest job {0} cancelled", jobId);
482 fireIngestJobCancelled(jobId);
601 void fireIngestJobStarted(
long ingestJobId) {
611 void fireIngestJobCompleted(
long ingestJobId) {
612 AutopsyEvent
event =
new AutopsyEvent(IngestJobEvent.COMPLETED.toString(), ingestJobId, null);
621 void fireIngestJobCancelled(
long ingestJobId) {
622 AutopsyEvent
event =
new AutopsyEvent(IngestJobEvent.CANCELLED.toString(), ingestJobId, null);
634 void fireDataSourceAnalysisStarted(
long ingestJobId,
long dataSourceIngestJobId, Content dataSource) {
635 AutopsyEvent
event =
new DataSourceAnalysisStartedEvent(ingestJobId, dataSourceIngestJobId, dataSource);
647 void fireDataSourceAnalysisCompleted(
long ingestJobId,
long dataSourceIngestJobId, Content dataSource) {
648 AutopsyEvent
event =
new DataSourceAnalysisCompletedEvent(ingestJobId, dataSourceIngestJobId, dataSource, DataSourceAnalysisCompletedEvent.Reason.ANALYSIS_COMPLETED);
660 void fireDataSourceAnalysisCancelled(
long ingestJobId,
long dataSourceIngestJobId, Content dataSource) {
661 AutopsyEvent
event =
new DataSourceAnalysisCompletedEvent(ingestJobId, dataSourceIngestJobId, dataSource, DataSourceAnalysisCompletedEvent.Reason.ANALYSIS_CANCELLED);
671 void fireFileIngestDone(AbstractFile file) {
672 AutopsyEvent
event =
new FileAnalyzedEvent(file);
683 void fireIngestModuleDataEvent(ModuleDataEvent moduleDataEvent) {
684 AutopsyEvent
event =
new BlackboardPostEvent(moduleDataEvent);
695 void fireIngestModuleContentEvent(ModuleContentEvent moduleContentEvent) {
696 AutopsyEvent
event =
new ContentChangedEvent(moduleContentEvent);
705 void initIngestMessageInbox() {
716 void postIngestMessage(IngestMessage message) {
719 if (message.getMessageType() != IngestMessage.MessageType.ERROR && message.getMessageType() != IngestMessage.MessageType.WARNING) {
723 if (errorPosts <= MAX_ERROR_MESSAGE_POSTS) {
725 }
else if (errorPosts == MAX_ERROR_MESSAGE_POSTS + 1) {
726 IngestMessage errorMessageLimitReachedMessage = IngestMessage.createErrorMessage(
727 NbBundle.getMessage(
this.getClass(),
"IngestManager.IngestMessage.ErrorMessageLimitReached.title"),
728 NbBundle.getMessage(
this.getClass(),
"IngestManager.IngestMessage.ErrorMessageLimitReached.subject"),
729 NbBundle.getMessage(
this.getClass(),
"IngestManager.IngestMessage.ErrorMessageLimitReached.msg",
MAX_ERROR_MESSAGE_POSTS));
760 void setIngestTaskProgress(DataSourceIngestTask task, String ingestModuleDisplayName) {
761 ingestThreadActivitySnapshots.put(task.getThreadId(),
new IngestThreadActivitySnapshot(task.getThreadId(), task.getIngestJobPipeline().getId(), ingestModuleDisplayName, task.getDataSource()));
775 void setIngestTaskProgress(FileIngestTask task, String ingestModuleDisplayName) {
777 IngestThreadActivitySnapshot newSnap;
779 newSnap =
new IngestThreadActivitySnapshot(task.getThreadId(), task.getIngestJobPipeline().getId(), ingestModuleDisplayName, task.getDataSource(), task.getFile());
780 }
catch (TskCoreException ex) {
783 newSnap =
new IngestThreadActivitySnapshot(task.getThreadId(), task.getIngestJobPipeline().getId(), ingestModuleDisplayName, task.getDataSource());
786 incrementModuleRunTime(prevSnap.getActivity(), newSnap.getStartTime().getTime() - prevSnap.getStartTime().getTime());
796 void setIngestTaskProgressCompleted(DataSourceIngestTask task) {
807 void setIngestTaskProgressCompleted(FileIngestTask task) {
809 IngestThreadActivitySnapshot newSnap =
new IngestThreadActivitySnapshot(task.getThreadId());
811 incrementModuleRunTime(prevSnap.getActivity(), newSnap.getStartTime().getTime() - prevSnap.getStartTime().getTime());
821 if (moduleDisplayName.equals(
"IDLE")) {
828 if (prevTimeL != null) {
829 prevTime = prevTimeL;
831 prevTime += duration;
867 List<Snapshot> snapShots =
new ArrayList<>();
870 snapShots.addAll(job.getDataSourceIngestJobSnapshots());
882 long getFreeDiskSpace() {
907 if (Thread.currentThread().isInterrupted()) {
915 final String displayName = NbBundle.getMessage(this.getClass(),
"IngestManager.StartIngestJobsTask.run.displayName");
916 this.progress = ProgressHandle.createHandle(displayName,
new Cancellable() {
918 public boolean cancel() {
919 if (progress != null) {
920 progress.setDisplayName(NbBundle.getMessage(
this.getClass(),
"IngestManager.StartIngestJobsTask.run.cancelling", displayName));
934 if (null != progress) {
949 private final BlockingIngestTaskQueue
tasks;
960 IngestTask task = tasks.getNextTask();
961 task.execute(threadId);
962 }
catch (InterruptedException ex) {
965 if (Thread.currentThread().isInterrupted()) {
1024 startTime =
new Date();
1025 this.activity = NbBundle.getMessage(this.getClass(),
"IngestManager.IngestThreadActivitySnapshot.idleThread");
1026 this.dataSourceName =
"";
1044 startTime =
new Date();
1046 this.dataSourceName = dataSource.getName();
1062 IngestThreadActivitySnapshot(
long threadId,
long jobId, String activity, Content dataSource, AbstractFile file) {
1065 startTime =
new Date();
1067 this.dataSourceName = dataSource.getName();
1068 this.fileName = file.getName();
1076 long getIngestJobId() {
1085 long getThreadId() {
1094 Date getStartTime() {
1103 String getActivity() {
1114 String getDataSourceName() {
1123 String getFileName() {
1205 private static final long serialVersionUID = 1L;
1223 super(message, cause);
final ConcurrentHashMap< String, Long > ingestModuleRunTimes
void addIngestModuleEventListener(Set< IngestModuleEvent > eventTypes, final PropertyChangeListener listener)
final Map< Long, Future< Void > > startIngestJobFutures
String getServiceStatus(String service)
void removeIngestModuleEventListener(final PropertyChangeListener listener)
IngestStream openIngestStream(DataSource dataSource, IngestJobSettings settings)
static final String INGEST_MODULE_EVENT_CHANNEL_NAME
List< IngestThreadActivitySnapshot > getIngestThreadActivitySnapshots()
void queueIngestJob(Content dataSource, List< AbstractFile > files, IngestJobSettings settings)
IngestManagerException(String message, Throwable cause)
static synchronized IngestManager getInstance()
static IngestManager instance
final String dataSourceName
void removeIngestModuleEventListener(Set< IngestModuleEvent > eventTypes, final PropertyChangeListener listener)
final ExecutorService dataSourceLevelIngestJobTasksExecutor
static boolean runningWithGUI
void cancelAllIngestJobs()
void publish(AutopsyEvent event)
static void addPropertyChangeListener(final PropertyChangeListener listener)
IngestJobStartResult beginIngestJob(Collection< Content > dataSources, IngestJobSettings settings)
static final Logger logger
final ExecutorService eventPublishingExecutor
void clearIngestMessageBox()
void addSubscriber(Set< String > eventNames, PropertyChangeListener subscriber)
void subscribeToServiceMonitorEvents()
boolean isIngestRunning()
DATA_SOURCE_ANALYSIS_COMPLETED
static void removePropertyChangeListener(final PropertyChangeListener listener)
static final Set< String > INGEST_MODULE_EVENT_NAMES
volatile IngestMessageTopComponent ingestMessageBox
void addSubscriber(PropertyChangeListener subscriber)
List< Snapshot > getIngestJobSnapshots()
final AutopsyEventPublisher publisher
synchronized void closeRemoteEventChannel()
Map< String, Long > getModuleRunTimes()
final ServicesMonitor servicesMonitor
void removeIngestJobEventListener(final PropertyChangeListener listener)
void addIngestJobEventListener(Set< IngestJobEvent > eventTypes, final PropertyChangeListener listener)
final BlockingIngestTaskQueue tasks
static final String INGEST_JOB_EVENT_CHANNEL_NAME
static final Set< String > INGEST_JOB_EVENT_NAMES
final AutopsyEventPublisher moduleEventPublisher
static int numberOfFileIngestThreads()
synchronized void openRemoteEventChannel(String channelName)
void addIngestJobEventListener(final PropertyChangeListener listener)
final Object ingestMessageBoxLock
IngestManagerException(String message)
void queueIngestJob(Collection< Content > dataSources, IngestJobSettings settings)
void removeSubscriber(Set< String > eventNames, PropertyChangeListener subscriber)
static final int MAX_ERROR_MESSAGE_POSTS
final AtomicLong ingestErrorMessagePosts
volatile boolean caseIsOpen
final AtomicLong nextIngestManagerTaskId
int getNumberOfFileIngestThreads()
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
DATA_SOURCE_ANALYSIS_STARTED
static Case getCurrentCaseThrows()
void incrementModuleRunTime(String moduleDisplayName, Long duration)
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
synchronized IngestJob startIngestJob(Collection< Content > dataSources, IngestJobSettings settings)
final ConcurrentHashMap< Long, IngestThreadActivitySnapshot > ingestThreadActivitySnapshots
void cancelAllIngestJobs(IngestJob.CancellationReason reason)
final IngestMonitor ingestMonitor
final ExecutorService fileLevelIngestJobTasksExecutor
final Map< Long, IngestJob > ingestJobsById
void subscribeToCaseEvents()
final ExecutorService startIngestJobsExecutor
void removeIngestJobEventListener(Set< IngestJobEvent > eventTypes, final PropertyChangeListener listener)
final int numberOfFileIngestThreads
static final long serialVersionUID
final AutopsyEventPublisher jobEventPublisher