def ProduceExtractionError(self, message, path_spec=None): """Produces an extraction error. Args: message (str): message of the error. path_spec (Optional[dfvfs.PathSpec]): path specification, where None will use the path specification of current file entry set in the mediator. Raises: RuntimeError: when storage writer is not set. """ if not self._storage_writer: raise RuntimeError('Storage writer not set.') if not path_spec and self._file_entry: path_spec = self._file_entry.path_spec parser_chain = self.GetParserChain() extraction_error = errors.ExtractionError(message=message, parser_chain=parser_chain, path_spec=path_spec) self._storage_writer.AddError(extraction_error) self._number_of_errors += 1 self.last_activity_timestamp = time.time()
def testGetAttributeNames(self): """Tests the GetAttributeNames function.""" attribute_container = errors.ExtractionError() expected_attribute_names = [u'message', u'parser_chain', u'path_spec'] attribute_names = sorted(attribute_container.GetAttributeNames()) self.assertEqual(attribute_names, expected_attribute_names)
def testAddError(self): """Tests the AddError function.""" extraction_error = errors.ExtractionError( message=u'Test extraction error') with shared_test_lib.TempDirectory() as temp_directory: temp_file = os.path.join(temp_directory, u'storage.plaso') storage_file = gzip_file.GZIPStorageFile() storage_file.Open(path=temp_file, read_only=False) storage_file.AddError(extraction_error) storage_file.Close()
def testAddError(self): """Tests the AddError function.""" session = sessions.Session() extraction_error = errors.ExtractionError( message='Test extraction error') storage_writer = fake_storage.FakeStorageWriter(session) storage_writer.Open() storage_writer.AddError(extraction_error) storage_writer.Close() with self.assertRaises(IOError): storage_writer.AddError(extraction_error)
def testGetErrors(self): """Tests the GetErrors function.""" extraction_error = errors.ExtractionError( message=u'Test extraction error') with shared_test_lib.TempDirectory() as temp_directory: temp_file = os.path.join(temp_directory, u'storage.plaso') storage_file = gzip_file.GZIPStorageFile() storage_file.Open(path=temp_file, read_only=False) storage_file.AddError(extraction_error) storage_file.Close() storage_file = gzip_file.GZIPStorageFile() storage_file.Open(path=temp_file) test_errors = list(storage_file.GetErrors()) self.assertEqual(len(test_errors), 1) storage_file.Close()
def ProduceExtractionError(self, message, path_spec=None): """Produces an extraction error. Args: message (str): message of the error. path_spec (Optional[dfvfs.PathSpec]): path specification. Raises: RuntimeError: when storage writer is not set. """ if not self._storage_writer: raise RuntimeError(u'Storage writer not set.') if not path_spec and self._file_entry: path_spec = self._file_entry.path_spec parser_chain = self.GetParserChain() extraction_error = errors.ExtractionError(message=message, parser_chain=parser_chain, path_spec=path_spec) self._storage_writer.AddError(extraction_error) self._number_of_errors += 1
def _ScheduleTasks(self, storage_writer): """Schedules tasks. Args: storage_writer (StorageWriter): storage writer for a session storage. """ logger.debug('Task scheduler started') self._status = definitions.PROCESSING_STATUS_RUNNING # TODO: make tasks persistent. # TODO: protect task scheduler loop by catch all and # handle abort path. event_source_heap = _EventSourceHeap() self._FillEventSourceHeap(storage_writer, event_source_heap, start_with_first=True) event_source = event_source_heap.PopEventSource() task = None while event_source or self._task_manager.HasPendingTasks(): if self._abort: break try: if not task: task = self._task_manager.CreateRetryTask() if not task and event_source: task = self._task_manager.CreateTask( self._session_identifier) task.file_entry_type = event_source.file_entry_type task.path_spec = event_source.path_spec event_source = None self._number_of_consumed_sources += 1 if self._guppy_memory_profiler: self._guppy_memory_profiler.Sample() if task: if self._ScheduleTask(task): logger.debug( 'Scheduled task {0:s} for path specification {1:s}' .format(task.identifier, task.path_spec.comparable)) self._task_manager.SampleTaskStatus(task, 'scheduled') task = None else: self._task_manager.SampleTaskStatus( task, 'schedule_attempted') self._MergeTaskStorage(storage_writer) self._FillEventSourceHeap(storage_writer, event_source_heap) if not task and not event_source: event_source = event_source_heap.PopEventSource() except KeyboardInterrupt: self._abort = True self._processing_status.aborted = True if self._status_update_callback: self._status_update_callback(self._processing_status) for task in self._task_manager.GetFailedTasks(): error = error_containers.ExtractionError( message='Worker failed to process path specification', path_spec=task.path_spec) self._storage_writer.AddError(error) self._processing_status.error_path_specs.append(task.path_spec) self._status = definitions.PROCESSING_STATUS_IDLE if self._abort: logger.debug('Task scheduler aborted') else: logger.debug('Task scheduler stopped')