From 9a83dbf2d1fc932703707e1cf1e5763035e8f169 Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Tue, 14 Jul 2015 17:00:10 +0300 Subject: [PATCH] Add several helpers for cleanup and fixes --- solar/solar/cli/system_log.py | 8 +++++++- solar/solar/system_log/change.py | 4 +++- solar/solar/system_log/data.py | 5 +++++ solar/solar/system_log/operations.py | 7 +++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/solar/solar/cli/system_log.py b/solar/solar/cli/system_log.py index 46a5e9b5..db171265 100644 --- a/solar/solar/cli/system_log.py +++ b/solar/solar/cli/system_log.py @@ -31,7 +31,7 @@ def stage(): @changes.command() -def send(): +def process(): click.echo(change.send_to_orchestration()) @@ -50,3 +50,9 @@ def history(n): @changes.command() def test(): testing.test_all() + + +@changes.command(name='clean-history') +def clean_history(): + data.CL().clean() + data.CD().clean() diff --git a/solar/solar/system_log/change.py b/solar/solar/system_log/change.py index f80f664f..b0a814e5 100644 --- a/solar/solar/system_log/change.py +++ b/solar/solar/system_log/change.py @@ -55,7 +55,9 @@ def create_diff(staged, commited): if 'tags' in commited: commited['tags'].sort() staged['tags'].sort() - + if 'tags' in commited.get('metadata', {}): + commited['metadata']['tags'].sort() + staged['metadata']['tags'].sort() return list(diff(commited, staged)) diff --git a/solar/solar/system_log/data.py b/solar/solar/system_log/data.py index 2565af2c..2e5e654e 100644 --- a/solar/solar/system_log/data.py +++ b/solar/solar/system_log/data.py @@ -70,6 +70,8 @@ class Log(object): def pop(self, uid): item = self.get(uid) + if not item: + return None self.ordered_log.rem([uid]) return item @@ -118,3 +120,6 @@ class Data(collections.MutableMapping): def __len__(self): return len(self.store) + + def clean(self): + db.save(self.path, {}, collection=db.COLLECTIONS.state_data) diff --git a/solar/solar/system_log/operations.py b/solar/solar/system_log/operations.py index 45f700c3..07f32053 100644 --- a/solar/solar/system_log/operations.py +++ b/solar/solar/system_log/operations.py @@ -1,6 +1,7 @@ from solar.system_log import data +from dictdiffer import patch def set_error(task_uuid, *args, **kwargs): @@ -13,9 +14,11 @@ def set_error(task_uuid, *args, **kwargs): def move_to_commited(task_uuid, *args, **kwargs): sl = data.SL() - item = sl.get(task_uuid) + item = sl.pop(task_uuid) if item: - sl.rem(task_uuid) + commited = data.CD() + staged_data = patch(item.diff, commited.get(item.res, {})) cl = data.CL() item.state = data.STATES.success cl.append(item) + commited[item.res] = staged_data