|
17 | 17 | # |
18 | 18 | # FileSR: local-file storage repository |
19 | 19 | from pathlib import Path |
20 | | -import json |
21 | 20 | import contextlib |
22 | 21 |
|
23 | | -from sm_typing import Dict, Optional, List, override, Tuple, Collection, Union, Any, TypeVar, Type |
| 22 | +from sm_typing import Dict, Optional, List, override, Tuple, Collection, Union, Any |
24 | 23 |
|
25 | | -import abc |
26 | 24 | import SR |
27 | 25 | import VDI |
28 | 26 | import SRCommand |
|
37 | 35 | import time |
38 | 36 | import glob |
39 | 37 | import fjournaler |
| 38 | +from jutils import BaseLogEntry |
40 | 39 | from uuid import uuid4 |
41 | 40 | from cowutil import ( |
42 | 41 | getCowUtil, |
@@ -122,54 +121,6 @@ def from_file_vdi(cls, vdi: "FileVDI") -> "VDILogEntry": |
122 | 121 | def __str__(self) -> str: |
123 | 122 | return str(self.to_dict()) |
124 | 123 |
|
125 | | -LogEntry = TypeVar("LogEntry", bound="BaseLogEntry") |
126 | | - |
127 | | -class BaseLogEntry(abc.ABC): |
128 | | - """Base class for serializing journal based entries inteded to rollback failed operations""" |
129 | | - |
130 | | - @property # type: ignore # Only way to simulate an abstract class variable |
131 | | - @classmethod |
132 | | - @abc.abstractmethod |
133 | | - def CURRENT_VERSION(cls) -> str: |
134 | | - ... |
135 | | - |
136 | | - @property # type: ignore # Only way to simulate an abstract class variable |
137 | | - @classmethod |
138 | | - @abc.abstractmethod |
139 | | - def JRN_KEY(cls) -> str: |
140 | | - ... |
141 | | - |
142 | | - @classmethod |
143 | | - @abc.abstractmethod |
144 | | - def from_dict(cls: Type[LogEntry], data: Dict[str, Any]) -> LogEntry: |
145 | | - ... |
146 | | - |
147 | | - @abc.abstractmethod |
148 | | - def to_dict(self) -> Dict[str, Collection[Any]]: |
149 | | - ... |
150 | | - |
151 | | - @staticmethod |
152 | | - def _get_version_from_journal_id(journal_id: str) -> str: |
153 | | - _, version = journal_id.split("+") |
154 | | - return version.replace("-", ".") |
155 | | - |
156 | | - @classmethod |
157 | | - def from_journal(cls: Type[LogEntry], journal_id: str, value: str) -> LogEntry: |
158 | | - version = cls._get_version_from_journal_id(journal_id) |
159 | | - if version != cls.CURRENT_VERSION: |
160 | | - raise xs_errors.SRException(f"Could not revert operation {journal_id} with mismatched log versions {version} != {cls.CURRENT_VERSION}") |
161 | | - return cls.from_dict(json.loads(value)) |
162 | | - |
163 | | - def to_journal(self) -> Tuple[str, str]: |
164 | | - # We use + as a version delimiter to not clash with journaler file name parsing |
165 | | - journal_id = f"{util.gen_uuid()}+{self.CURRENT_VERSION.replace('.', '-')}" |
166 | | - value = json.dumps(self.to_dict()) |
167 | | - return journal_id, value |
168 | | - |
169 | | - @override |
170 | | - def __str__(self) -> str: |
171 | | - return str(self.to_dict()) |
172 | | - |
173 | 124 | class RevertLogEntry(BaseLogEntry): |
174 | 125 | """Journal entry used to rollback failed revert operations""" |
175 | 126 |
|
|
0 commit comments