Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced graph view #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ celery*.log

*.dot
*.png
*.svg
resources_compiled.py

# bootstrap
Expand Down
13 changes: 13 additions & 0 deletions solar/solar/cli/orch.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ def dg(uid, start, end):
utils.write_graph(plan)
click.echo('Created {name}.svg'.format(name=plan.graph['name']))

@orchestration.command()
@click.argument('uid', type=SOLARUID)
def rdg(uid):
import networkx as nx
plan = graph.get_graph(uid)
reduced = nx.DiGraph()
reduced.graph['name'] = 'reduced_' + plan.graph['name']
for u, v in plan.edges():
u = '{}.{}'.format(plan.node[u]['resource_type'], plan.node[u]['action'])
v = '{}.{}'.format(plan.node[v]['resource_type'], plan.node[v]['action'])
reduced.add_edge(u, v)
utils.write_graph(reduced)
click.echo('Created {name}.svg'.format(name=reduced.graph['name']))

@orchestration.command()
@click.argument('uid', type=SOLARUID)
Expand Down
7 changes: 6 additions & 1 deletion solar/solar/core/resource/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def __init__(self, name, base_path, args=None, tags=None, virtual_resource=None)
'puppet_module': metadata.get('puppet_module', ''),
'version': metadata.get('version', ''),
'meta_inputs': inputs,
'tags': tags
'tags': tags,
'type': metadata.get('id', ''),

})
self.db_obj.state = RESOURCE_STATE.created.name
Expand All @@ -102,6 +103,10 @@ def __init__(self, resource_db):
self.base_path = resource_db.base_path
self.virtual_resource = None

@property
def type(self):
return self.db_obj.type

def auto_extend_inputs(self, inputs):
# XXX: we didn't agree on `location_id` and `transports_id`
# that are added automaticaly to all resources
Expand Down
19 changes: 11 additions & 8 deletions solar/solar/events/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ def insert(self, changed_resources, changes_graph):
loaded_resource = resource.load(self.child)
except KeyError:
# orm throws this error when we're NOT using resource there
location_id = None
kwargs = {}
else:
location_id = loaded_resource.args['location_id']
kwargs = {'target': loaded_resource.args['location_id'],
'resource_type': loaded_resource.type}
changes_graph.add_node(
self.child_node, status='PENDING',
target=location_id,
errmsg=None, type='solar_resource',
args=[self.child, self.child_action])
action=self.child_action,
args=[self.child, self.child_action], **kwargs)

changes_graph.add_edge(
self.parent_node, self.child_node, state=self.state)
Expand All @@ -128,11 +129,13 @@ def insert(self, changed_resources, changes_graph):
loaded_resource = resource.load(self.parent)
except KeyError:
# orm throws this error when we're NOT using resource there
location_id = None
kwargs = {}
else:
location_id = loaded_resource.args['location_id']

kwargs = {'target': loaded_resource.args['location_id'],
'resource_type': loaded_resource.type}
changes_graph.add_node(
self.parent_node, status='PENDING',
target=location_id,
errmsg=None, type='solar_resource',
args=[self.parent, self.parent_action])
action=self.parent_action,
args=[self.parent, self.parent_action], **kwargs)
1 change: 1 addition & 0 deletions solar/solar/interfaces/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ class DBResource(DBObject):
tags = db_field(schema=[], default_value=[])
meta_inputs = db_field(schema={}, default_value={})
state = db_field(schema='str')
type = db_field(schema='str')

inputs = db_related_field(base.BaseGraphDB.RELATION_TYPES.resource_input,
DBResourceInput)
Expand Down
6 changes: 4 additions & 2 deletions solar/solar/orchestration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ def write_graph(plan):
'SKIPPED': 'blue'}

for n in plan:
color = colors[plan.node[n]['status']]
plan.node[n]['color'] = color
status = plan.node[n].get('status')
if status:
color = colors[status]
plan.node[n]['color'] = color

nx.write_dot(plan, '{name}.dot'.format(name=plan.graph['name']))
subprocess.call(
Expand Down