LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """Task related attribute container definitions.""" | 2 """Task related attribute container definitions.""" |
3 | 3 |
4 from __future__ import unicode_literals | 4 from __future__ import unicode_literals |
5 | 5 |
6 import time | 6 import time |
7 import uuid | 7 import uuid |
8 | 8 |
9 from plaso.containers import interface | 9 from plaso.containers import interface |
10 from plaso.containers import manager | 10 from plaso.containers import manager |
11 from plaso.lib import definitions | 11 from plaso.lib import definitions |
12 | 12 |
13 | 13 |
14 class Task(interface.AttributeContainer): | 14 class Task(interface.AttributeContainer): |
15 """Task attribute container. | 15 """Task attribute container. |
16 | 16 |
17 A task describes a piece of work for a multi processing worker process | 17 A task describes a piece of work for a multi processing worker process |
18 e.g. to process a path specification or to analyze an event. | 18 e.g. to process a path specification or to analyze an event. |
19 | 19 |
20 Attributes: | 20 Attributes: |
21 aborted (bool): True if the session was aborted. | 21 aborted (bool): True if the session was aborted. |
22 completion_time (int): time that the task was completed. Contains the | 22 completion_time (int): time that the task was completed. Contains the |
23 number of micro seconds since January 1, 1970, 00:00:00 UTC. | 23 number of micro seconds since January 1, 1970, 00:00:00 UTC. |
24 file_entry_type (str): dfVFS type of the file entry the path specification | 24 file_entry_type (str): dfVFS type of the file entry the path specification |
25 is referencing. | 25 is referencing. |
| 26 has_retry (bool): True if the task was previously abandoned and a retry |
| 27 task was created, False otherwise. |
26 identifier (str): unique identifier of the task. | 28 identifier (str): unique identifier of the task. |
27 last_processing_time (int): the last time the task was marked as being | 29 last_processing_time (int): the last time the task was marked as being |
28 processed as number of milliseconds since January 1, 1970, 00:00:00 UTC. | 30 processed as number of milliseconds since January 1, 1970, 00:00:00 UTC. |
29 merge_priority (int): priority used for the task storage file merge, where | 31 merge_priority (int): priority used for the task storage file merge, where |
30 a lower value indicates a higher priority to merge. | 32 a lower value indicates a higher priority to merge. |
31 original_task_identifier (str): the identifier of the task of which this | |
32 task is a retry or None if not set. | |
33 path_spec (dfvfs.PathSpec): path specification. | 33 path_spec (dfvfs.PathSpec): path specification. |
34 retry_count (int): number of times the task has been retried. | |
35 retry_task_identifier (str): identifier of the retry task, when the task | |
36 is being retried or None if not set. | |
37 session_identifier (str): the identifier of the session the task is part of. | 34 session_identifier (str): the identifier of the session the task is part of. |
38 start_time (int): time that the task was started. Contains the number | 35 start_time (int): time that the task was started. Contains the number |
39 of micro seconds since January 1, 1970, 00:00:00 UTC. | 36 of micro seconds since January 1, 1970, 00:00:00 UTC. |
40 storage_file_size (int): size of the storage file in bytes. | 37 storage_file_size (int): size of the storage file in bytes. |
41 """ | 38 """ |
42 CONTAINER_TYPE = 'task' | 39 CONTAINER_TYPE = 'task' |
43 | 40 |
44 def __init__(self, session_identifier=None): | 41 def __init__(self, session_identifier=None): |
45 """Initializes a task attribute container. | 42 """Initializes a task attribute container. |
46 | 43 |
47 Args: | 44 Args: |
48 session_identifier (Optional[str]): identifier of the session the task | 45 session_identifier (Optional[str]): identifier of the session the task |
49 is part of. | 46 is part of. |
50 """ | 47 """ |
51 super(Task, self).__init__() | 48 super(Task, self).__init__() |
52 self.aborted = False | 49 self.aborted = False |
53 self.completion_time = None | 50 self.completion_time = None |
54 self.file_entry_type = None | 51 self.file_entry_type = None |
| 52 self.has_retry = False |
55 self.identifier = '{0:s}'.format(uuid.uuid4().hex) | 53 self.identifier = '{0:s}'.format(uuid.uuid4().hex) |
56 self.last_processing_time = None | 54 self.last_processing_time = None |
57 self.merge_priority = None | 55 self.merge_priority = None |
58 self.original_task_identifier = None | |
59 self.path_spec = None | 56 self.path_spec = None |
60 self.retry_count = 0 | |
61 self.retry_task_identifier = None | |
62 self.session_identifier = session_identifier | 57 self.session_identifier = session_identifier |
63 self.start_time = int(time.time() * definitions.MICROSECONDS_PER_SECOND) | 58 self.start_time = int(time.time() * definitions.MICROSECONDS_PER_SECOND) |
64 self.storage_file_size = None | 59 self.storage_file_size = None |
65 | 60 |
66 # This method is necessary for heap sort. | 61 # This method is necessary for heap sort. |
67 def __lt__(self, other): | 62 def __lt__(self, other): |
68 """Compares if the task attribute container is less than the other. | 63 """Compares if the task attribute container is less than the other. |
69 | 64 |
70 Args: | 65 Args: |
71 other (Task): task attribute container to compare to. | 66 other (Task): task attribute container to compare to. |
72 | 67 |
73 Returns: | 68 Returns: |
74 bool: True if the task attribute container is less than the other. | 69 bool: True if the task attribute container is less than the other. |
75 """ | 70 """ |
76 return self.identifier < other.identifier | 71 return self.identifier < other.identifier |
77 | 72 |
78 def CreateRetryTask(self): | 73 def CreateRetryTask(self): |
79 """Creates a new task to retry the existing task. | 74 """Creates a new task to retry a previously abandoned task. |
| 75 |
| 76 The retry task will have a new identifier but most of the attributes |
| 77 will be a copy of the previously abandoned task. |
80 | 78 |
81 Returns: | 79 Returns: |
82 task (Task): a task to retry of the existing task. | 80 Task: a task to retry a previously abandoned task. |
83 """ | 81 """ |
84 retry_task = Task(session_identifier=self.session_identifier) | 82 retry_task = Task(session_identifier=self.session_identifier) |
85 retry_task.file_entry_type = self.file_entry_type | 83 retry_task.file_entry_type = self.file_entry_type |
86 retry_task.merge_priority = self.merge_priority | 84 retry_task.merge_priority = self.merge_priority |
87 retry_task.original_task_identifier = self.identifier | |
88 retry_task.path_spec = self.path_spec | 85 retry_task.path_spec = self.path_spec |
89 retry_task.retry_count = self.retry_count + 1 | |
90 retry_task.storage_file_size = self.storage_file_size | 86 retry_task.storage_file_size = self.storage_file_size |
91 | 87 |
92 self.retry_task_identifier = retry_task.identifier | 88 self.has_retry = True |
93 | 89 |
94 return retry_task | 90 return retry_task |
95 | 91 |
96 def CreateTaskCompletion(self): | 92 def CreateTaskCompletion(self): |
97 """Creates a task completion. | 93 """Creates a task completion. |
98 | 94 |
99 Returns: | 95 Returns: |
100 TaskCompletion: task completion attribute container. | 96 TaskCompletion: task completion attribute container. |
101 """ | 97 """ |
102 self.completion_time = int( | 98 self.completion_time = int( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 is part of. | 176 is part of. |
181 """ | 177 """ |
182 super(TaskStart, self).__init__() | 178 super(TaskStart, self).__init__() |
183 self.identifier = identifier | 179 self.identifier = identifier |
184 self.session_identifier = session_identifier | 180 self.session_identifier = session_identifier |
185 self.timestamp = None | 181 self.timestamp = None |
186 | 182 |
187 | 183 |
188 manager.AttributeContainersManager.RegisterAttributeContainers([ | 184 manager.AttributeContainersManager.RegisterAttributeContainers([ |
189 Task, TaskCompletion, TaskStart]) | 185 Task, TaskCompletion, TaskStart]) |
LEFT | RIGHT |