19 package org.sleuthkit.autopsy.ingest;
21 import com.google.common.eventbus.Subscribe;
22 import com.google.common.util.concurrent.ThreadFactoryBuilder;
23 import java.awt.EventQueue;
24 import java.beans.PropertyChangeEvent;
25 import java.beans.PropertyChangeListener;
26 import java.io.Serializable;
27 import java.lang.reflect.InvocationTargetException;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.Collections;
31 import java.util.Date;
32 import java.util.EnumSet;
33 import java.util.HashMap;
34 import java.util.HashSet;
35 import java.util.List;
38 import java.util.concurrent.Callable;
39 import java.util.concurrent.ConcurrentHashMap;
40 import java.util.concurrent.ExecutorService;
41 import java.util.concurrent.Executors;
42 import java.util.concurrent.Future;
43 import java.util.concurrent.atomic.AtomicLong;
44 import java.util.logging.Level;
45 import java.util.stream.Collectors;
46 import java.util.stream.Stream;
47 import javax.annotation.concurrent.GuardedBy;
48 import javax.annotation.concurrent.Immutable;
49 import javax.annotation.concurrent.ThreadSafe;
50 import javax.swing.JOptionPane;
51 import javax.swing.SwingUtilities;
52 import org.netbeans.api.progress.ProgressHandle;
53 import org.openide.util.Cancellable;
54 import org.openide.util.NbBundle;
55 import org.openide.windows.WindowManager;
127 @GuardedBy(
"IngestManager.class")
131 private final ExecutorService
startIngestJobsExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("IM-start-ingest-jobs-%d").build());
139 private final ExecutorService
eventPublishingExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("IM-ingest-events-%d").build());
158 if (null == instance) {
160 instance.subscribeToServiceMonitorEvents();
161 instance.subscribeToCaseEvents();
194 resultIngestTasksExecutor = Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder().setNameFormat(
"IM-results-ingest-%d").build());
207 PropertyChangeListener propChangeListener = (PropertyChangeEvent evt) -> {
222 logger.log(Level.SEVERE,
"Service {0} is down, cancelling all running ingest jobs", serviceDisplayName);
224 EventQueue.invokeLater(
new Runnable() {
227 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
228 NbBundle.getMessage(this.getClass(),
"IngestManager.cancellingIngest.msgDlg.text"),
229 NbBundle.getMessage(this.getClass(),
"IngestManager.serviceIsDown.msgDlg.text", serviceDisplayName),
230 JOptionPane.ERROR_MESSAGE);
244 Set<String> servicesList =
new HashSet<>();
256 if (event.getNewValue() != null) {
272 void handleCaseOpened() {
277 String channelPrefix = openedCase.
getName();
283 }
catch (NoCurrentCaseException | AutopsyEventException ex) {
284 logger.log(Level.SEVERE,
"Failed to open remote events channel", ex);
285 MessageNotifyUtil.Notify.error(NbBundle.getMessage(
IngestManager.class,
"IngestManager.OpenEventChannel.Fail.Title"),
286 NbBundle.getMessage(
IngestManager.class,
"IngestManager.OpenEventChannel.Fail.ErrMsg"));
298 void handleArtifactsPosted(Blackboard.ArtifactsPostedEvent tskEvent) {
299 for (BlackboardArtifact.Type artifactType : tskEvent.getArtifactTypes()) {
300 ModuleDataEvent legacyEvent =
new ModuleDataEvent(tskEvent.getModuleName(), artifactType, tskEvent.getArtifacts(artifactType));
301 AutopsyEvent autopsyEvent =
new BlackboardPostEvent(legacyEvent);
315 void handleCaseClosed() {
321 Case.getCurrentCase().getSleuthkitCase().unregisterForEvents(
this);
341 IngestJobInputStream stream =
new IngestJobInputStream(job);
342 if (stream.getIngestJobStartResult().getJob() != null) {
344 }
else if (stream.getIngestJobStartResult().getModuleErrors().isEmpty()) {
345 for (
IngestModuleError error : stream.getIngestJobStartResult().getModuleErrors()) {
346 logger.log(Level.SEVERE, String.format(
"%s ingest module startup error for %s", error.getModuleDisplayName(), dataSource.getName()), error.getThrowable());
348 throw new TskCoreException(
"Error starting ingest modules");
350 throw new TskCoreException(
"Error starting ingest modules", stream.getIngestJobStartResult().getStartupException());
373 if (job.hasIngestPipeline()) {
394 if (job.hasIngestPipeline()) {
416 if (job.hasIngestPipeline()) {
417 return startIngestJob(job);
433 "IngestManager.startupErr.dlgTitle=Ingest Module Startup Failure",
434 "IngestManager.startupErr.dlgMsg=Unable to start up one or more ingest modules, ingest cancelled.",
435 "IngestManager.startupErr.dlgSolution=Please disable the failed modules or fix the errors before restarting ingest.",
436 "IngestManager.startupErr.dlgErrorList=Errors:"
438 IngestJobStartResult startIngestJob(IngestJob job) {
442 if (SwingUtilities.isEventDispatchThread()) {
443 initIngestMessageInbox();
446 SwingUtilities.invokeAndWait(() -> initIngestMessageInbox());
447 }
catch (InterruptedException ex) {
449 }
catch (InvocationTargetException ex) {
450 logger.log(Level.WARNING,
"There was an error starting ingest message inbox", ex);
454 List<IngestModuleError> errors = null;
457 openCase = Case.getCurrentCaseThrows();
458 }
catch (NoCurrentCaseException ex) {
459 return new IngestJobStartResult(null,
new IngestManagerException(
"Exception while getting open case.", ex), Collections.<IngestModuleError>emptyList());
461 if (openCase.getCaseType() == Case.CaseType.MULTI_USER_CASE) {
464 if (RuntimeProperties.runningWithGUI()) {
465 EventQueue.invokeLater(
new Runnable() {
468 String serviceDisplayName = ServicesMonitor.Service.REMOTE_CASE_DATABASE.getDisplayName();
469 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
470 NbBundle.getMessage(this.getClass(),
"IngestManager.cancellingIngest.msgDlg.text"),
471 NbBundle.getMessage(this.getClass(),
"IngestManager.serviceIsDown.msgDlg.text", serviceDisplayName),
472 JOptionPane.ERROR_MESSAGE);
476 return new IngestJobStartResult(null,
new IngestManagerException(
"Ingest aborted. Remote database is down"), Collections.<IngestModuleError>emptyList());
478 }
catch (ServicesMonitor.ServicesMonitorException ex) {
479 return new IngestJobStartResult(null,
new IngestManagerException(
"Database server is down", ex), Collections.<IngestModuleError>emptyList());
490 IngestManager.logger.log(Level.INFO,
"Starting ingest job {0}", job.getId());
492 errors = job.start();
493 }
catch (InterruptedException ex) {
494 return new IngestJobStartResult(null,
new IngestManagerException(
"Interrupted while starting ingest", ex), errors);
496 if (errors.isEmpty()) {
497 this.fireIngestJobStarted(job.getId());
502 for (IngestModuleError error : errors) {
503 logger.log(Level.SEVERE, String.format(
"Error starting %s ingest module for job %d", error.getModuleDisplayName(), job.getId()), error.getThrowable());
505 IngestManager.logger.log(Level.SEVERE,
"Ingest job {0} could not be started", job.getId());
506 if (RuntimeProperties.runningWithGUI()) {
507 final StringBuilder message =
new StringBuilder(1024);
508 message.append(Bundle.IngestManager_startupErr_dlgMsg()).append(
"\n");
509 message.append(Bundle.IngestManager_startupErr_dlgSolution()).append(
"\n\n");
510 message.append(Bundle.IngestManager_startupErr_dlgErrorList()).append(
"\n");
511 for (IngestModuleError error : errors) {
512 String moduleName = error.getModuleDisplayName();
513 String errorMessage = error.getThrowable().getLocalizedMessage();
514 message.append(moduleName).append(
": ").append(errorMessage).append(
"\n");
516 message.append(
"\n\n");
517 EventQueue.invokeLater(() -> {
518 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), message, Bundle.IngestManager_startupErr_dlgTitle(), JOptionPane.ERROR_MESSAGE);
521 return new IngestJobStartResult(null,
new IngestManagerException(
"Errors occurred while starting ingest"), errors);
524 return new IngestJobStartResult(job, null, errors);
532 void finishIngestJob(IngestJob job
534 long jobId = job.getId();
538 if (!job.isCancelled()) {
539 IngestManager.logger.log(Level.INFO,
"Ingest job {0} completed", jobId);
540 fireIngestJobCompleted(jobId);
542 IngestManager.logger.log(Level.INFO,
"Ingest job {0} cancelled", jobId);
543 fireIngestJobCancelled(jobId);
666 void fireIngestJobStarted(
long ingestJobId) {
676 void fireIngestJobCompleted(
long ingestJobId) {
677 AutopsyEvent
event =
new AutopsyEvent(IngestJobEvent.COMPLETED.toString(), ingestJobId, null);
686 void fireIngestJobCancelled(
long ingestJobId) {
687 AutopsyEvent
event =
new AutopsyEvent(IngestJobEvent.CANCELLED.toString(), ingestJobId, null);
699 void fireDataSourceAnalysisStarted(
long ingestJobId,
long dataSourceIngestJobId, Content dataSource) {
700 AutopsyEvent
event =
new DataSourceAnalysisStartedEvent(ingestJobId, dataSourceIngestJobId, dataSource);
712 void fireDataSourceAnalysisCompleted(
long ingestJobId,
long dataSourceIngestJobId, Content dataSource) {
713 AutopsyEvent
event =
new DataSourceAnalysisCompletedEvent(ingestJobId, dataSourceIngestJobId, dataSource, DataSourceAnalysisCompletedEvent.Reason.ANALYSIS_COMPLETED);
725 void fireDataSourceAnalysisCancelled(
long ingestJobId,
long dataSourceIngestJobId, Content dataSource) {
726 AutopsyEvent
event =
new DataSourceAnalysisCompletedEvent(ingestJobId, dataSourceIngestJobId, dataSource, DataSourceAnalysisCompletedEvent.Reason.ANALYSIS_CANCELLED);
736 void fireFileIngestDone(AbstractFile file) {
737 AutopsyEvent
event =
new FileAnalyzedEvent(file);
748 void fireIngestModuleContentEvent(ModuleContentEvent moduleContentEvent) {
749 AutopsyEvent
event =
new ContentChangedEvent(moduleContentEvent);
761 void initIngestMessageInbox() {
772 void postIngestMessage(IngestMessage message) {
775 if (message.getMessageType() != IngestMessage.MessageType.ERROR && message.getMessageType() != IngestMessage.MessageType.WARNING) {
779 if (errorPosts <= MAX_ERROR_MESSAGE_POSTS) {
781 }
else if (errorPosts == MAX_ERROR_MESSAGE_POSTS + 1) {
782 IngestMessage errorMessageLimitReachedMessage = IngestMessage.createErrorMessage(
783 NbBundle.getMessage(
this.getClass(),
"IngestManager.IngestMessage.ErrorMessageLimitReached.title"),
784 NbBundle.getMessage(
this.getClass(),
"IngestManager.IngestMessage.ErrorMessageLimitReached.subject"),
785 NbBundle.getMessage(
this.getClass(),
"IngestManager.IngestMessage.ErrorMessageLimitReached.msg",
MAX_ERROR_MESSAGE_POSTS));
813 void setIngestTaskProgress(DataSourceIngestTask task, String currentModuleName) {
815 IngestThreadActivitySnapshot newSnap =
new IngestThreadActivitySnapshot(task.getThreadId(), task.getIngestJobPipeline().getId(), currentModuleName, task.getDataSource());
822 incrementModuleRunTime(prevSnap.getActivity(), newSnap.getStartTime().getTime() - prevSnap.getStartTime().getTime());
833 void setIngestTaskProgress(FileIngestTask task, String currentModuleName) {
835 IngestThreadActivitySnapshot newSnap;
837 newSnap =
new IngestThreadActivitySnapshot(task.getThreadId(), task.getIngestJobPipeline().getId(), currentModuleName, task.getDataSource(), task.getFile());
838 }
catch (TskCoreException ex) {
839 logger.log(Level.SEVERE,
"Error getting file from file ingest task", ex);
840 newSnap =
new IngestThreadActivitySnapshot(task.getThreadId(), task.getIngestJobPipeline().getId(), currentModuleName, task.getDataSource());
848 incrementModuleRunTime(prevSnap.getActivity(), newSnap.getStartTime().getTime() - prevSnap.getStartTime().getTime());
856 void setIngestTaskProgressCompleted(IngestTask task) {
858 IngestThreadActivitySnapshot newSnap =
new IngestThreadActivitySnapshot(task.getThreadId());
865 incrementModuleRunTime(prevSnap.getActivity(), newSnap.getStartTime().getTime() - prevSnap.getStartTime().getTime());
874 void incrementModuleRunTime(String moduleDisplayName, Long duration) {
875 if (moduleDisplayName.equals(
"IDLE")) {
882 if (prevTimeL != null) {
883 prevTime = prevTimeL;
885 prevTime += duration;
921 List<Snapshot> snapShots =
new ArrayList<>();
924 snapShots.addAll(job.getDataSourceIngestJobSnapshots());
936 long getFreeDiskSpace() {
961 if (Thread.currentThread().isInterrupted()) {
969 final String displayName = NbBundle.getMessage(this.getClass(),
"IngestManager.StartIngestJobsTask.run.displayName");
970 this.progress = ProgressHandle.createHandle(displayName,
new Cancellable() {
972 public boolean cancel() {
973 if (progress != null) {
974 progress.setDisplayName(NbBundle.getMessage(
this.getClass(),
"IngestManager.StartIngestJobsTask.run.cancelling", displayName));
990 if (null != progress) {
1007 private final BlockingIngestTaskQueue
tasks;
1018 IngestTask task = tasks.getNextTask();
1019 task.execute(threadId);
1020 }
catch (InterruptedException ex) {
1023 if (Thread.currentThread().isInterrupted()) {
1082 startTime =
new Date();
1083 this.activity = NbBundle.getMessage(this.getClass(),
"IngestManager.IngestThreadActivitySnapshot.idleThread");
1084 this.dataSourceName =
"";
1102 startTime =
new Date();
1104 this.dataSourceName = dataSource.getName();
1120 IngestThreadActivitySnapshot(
long threadId,
long jobId, String activity, Content dataSource, AbstractFile file) {
1123 startTime =
new Date();
1125 this.dataSourceName = dataSource.getName();
1126 this.fileName = file.getName();
1134 long getIngestJobId() {
1143 long getThreadId() {
1152 Date getStartTime() {
1161 String getActivity() {
1172 String getDataSourceName() {
1181 String getFileName() {
1263 private static final long serialVersionUID = 1L;
1281 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()
final ExecutorService resultIngestTasksExecutor
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)
SleuthkitCase getSleuthkitCase()
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()
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