diff --git a/solar/solar/events/controls.py b/solar/solar/events/controls.py index 3a01083b..64d82cf8 100644 --- a/solar/solar/events/controls.py +++ b/solar/solar/events/controls.py @@ -34,11 +34,11 @@ class Event(object): @property def parent(self): - return '{}:{}'.format(self.parent_node, self.parent_action) + return '{}.{}'.format(self.parent_node, self.parent_action) @property def dependent(self): - return '{}:{}'.format(self.depend_node, self.depend_action) + return '{}.{}'.format(self.depend_node, self.depend_action) def to_dict(self): rst = {'etype': self.etype} @@ -63,7 +63,8 @@ class Dependency(Event): etype = 'depends_on' def add_edge(self, changed_resources, changes_graph): - if self.parent in changes_graph: + if (self.parent in changes_graph and + self.dependent in changes_graph): changes_graph.add_edge( self.parent, self.dependent, state=self.state) @@ -74,6 +75,13 @@ class React(Event): etype = 'react_on' def add_edge(self, changed_resources, changes_graph): + if self.parent in changes_graph: + if self.dependent not in changes_graph: + changes_graph.add_node( + self.dependent, status='PENDING', + errmsg=None, type='solar_resource', + args=[self.depend_node, self.depend_action]) + changes_graph.add_edge(self.parent, self.dependent, state=self.state) changed_resources.append(self.depend_node) diff --git a/solar/solar/orchestration/graph.py b/solar/solar/orchestration/graph.py index adf6fc13..5a34f102 100644 --- a/solar/solar/orchestration/graph.py +++ b/solar/solar/orchestration/graph.py @@ -21,7 +21,7 @@ def save_graph(name, graph): def get_graph(name): - dg = nx.DiGraph() + dg = nx.MultiDiGraph() nodes = json.loads(r.get('{}:nodes'.format(name))) edges = json.loads(r.get('{}:edges'.format(name))) dg.graph = json.loads(r.get('{}:attributes'.format(name))) @@ -37,7 +37,7 @@ def parse_plan(plan_data): """ parses yaml definition and returns graph """ plan = yaml.load(plan_data) - dg = nx.DiGraph() + dg = nx.MultiDiGraph() dg.graph['name'] = plan['name'] for task in plan['tasks']: dg.add_node( diff --git a/solar/solar/system_log/change.py b/solar/solar/system_log/change.py index 4e63df4d..3307f4c2 100644 --- a/solar/solar/system_log/change.py +++ b/solar/solar/system_log/change.py @@ -27,22 +27,6 @@ def guess_action(from_, to): return 'update' -def connections(res, graph): - result = [] - for pred in graph.predecessors(res.name): - for num, edge in graph.get_edge_data(pred, res.name).items(): - if 'label' in edge: - if ':' in edge['label']: - parent, child = edge['label'].split(':') - mapping = [parent, child] - else: - mapping = [edge['label'], edge['label']] - else: - mapping = None - result.append([pred, res.name, mapping]) - return result - - def create_diff(staged, commited): return list(diff(commited, staged)) @@ -84,7 +68,7 @@ def stage_changes(): def send_to_orchestration(): - dg = nx.DiGraph() + dg = nx.MultiDiGraph() staged = {r.name: r.args_show() for r in resource.load_all().values()} commited = data.CD() @@ -103,7 +87,7 @@ def send_to_orchestration(): action = guess_action(commited_data, staged_data) dg.add_node( - '{}:{}'.format(res_uid, action), status='PENDING', + '{}.{}'.format(res_uid, action), status='PENDING', errmsg=None, **parameters(res_uid, action)) diff --git a/solar/solar/test/test_events.py b/solar/solar/test/test_events.py index f8a17216..5f5d8e8c 100644 --- a/solar/solar/test/test_events.py +++ b/solar/solar/test/test_events.py @@ -17,11 +17,11 @@ def nova_deps(): def test_nova_api_run_after_nova(nova_deps): changed = ['nova', 'nova_api'] changes_graph = nx.DiGraph() - changes_graph.add_node('nova:run') - changes_graph.add_node('nova_api:run') + changes_graph.add_node('nova.run') + changes_graph.add_node('nova_api.run') evapi.build_edges(changed, changes_graph, nova_deps) - assert changes_graph.successors('nova:run') == ['nova_api:run'] + assert changes_graph.successors('nova.run') == ['nova_api.run'] def test_nova_api_react_on_update(nova_deps): @@ -30,10 +30,10 @@ def test_nova_api_react_on_update(nova_deps): """ changed = ['nova'] changes_graph = nx.DiGraph() - changes_graph.add_node('nova:update') + changes_graph.add_node('nova.update') evapi.build_edges(changed, changes_graph, nova_deps) - assert changes_graph.successors('nova:update') == ['nova_api:update'] + assert changes_graph.successors('nova.update') == ['nova_api.update'] @fixture @@ -56,13 +56,13 @@ def rmq_deps(): def test_rmq(rmq_deps): changed = ['rmq.1', 'rmq.2', 'rmq.3', 'rmq_cluster.1', 'rmq_cluster.2', 'rmq_cluster.3'] changes_graph = nx.DiGraph() - changes_graph.add_node('rmq.1:run') - changes_graph.add_node('rmq.2:run') - changes_graph.add_node('rmq.3:run') - changes_graph.add_node('rmq_cluster.1:create') - changes_graph.add_node('rmq_cluster.2:join') - changes_graph.add_node('rmq_cluster.3:join') + changes_graph.add_node('rmq.1.run') + changes_graph.add_node('rmq.2.run') + changes_graph.add_node('rmq.3.run') + changes_graph.add_node('rmq_cluster.1.create') + changes_graph.add_node('rmq_cluster.2.join') + changes_graph.add_node('rmq_cluster.3.join') evapi.build_edges(changed, changes_graph, rmq_deps) - assert set(changes_graph.successors('rmq_cluster.1:create')) == { - 'rmq_cluster.2:join', 'rmq_cluster.3:join'} + assert set(changes_graph.successors('rmq_cluster.1.create')) == { + 'rmq_cluster.2.join', 'rmq_cluster.3.join'}