Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
adds summery node type
Browse files Browse the repository at this point in the history
  • Loading branch information
jghibiki committed Oct 31, 2018
1 parent e09ccc2 commit eaede8b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
4 changes: 1 addition & 3 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def reset():


time.sleep(5)
set_state("dev", "pipeline_1", "step_1", "ok")

set_state("prod", "pipeline_1", "step_1", "running")
set_state("prod", "pipeline_1", "step_2", "running")
set_state("prod", "pipeline_1", "step_3a", "running")
set_state("prod", "pipeline_1", "step_3b", "running")
Expand Down Expand Up @@ -74,7 +72,7 @@ def reset():
time.sleep(1)
set_state("dev", "pipeline_2", "eating", "running")
time.sleep(3)
set_state("dev", "pipeline_2", "eating", "yes", "__FINISHED__")
set_state("dev", "pipeline_2", "eating", "failed", "__QUIT__")

time.sleep(2)
set_state("dev", "pipeline_1", "step_4", "failed", "__QUIT__")
Expand Down
3 changes: 2 additions & 1 deletion pipelines/demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"links": [
[ "documentation", "https:\/\/github.com/jghibiki/Sydney" ]
],
"child_pipeline": "#pipeline_2"
"child_pipeline": "#pipeline_2",
"summary": true
}
},

Expand Down
3 changes: 3 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
}
],

"failure_state": "failed",

"notifications": [
{
"step": ".*",
"state": "failed"
}
],


"environments": [
"dev",
"prod"
Expand Down
62 changes: 62 additions & 0 deletions server/sydney.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,31 @@ def notify_state_change(environment, pipeline, step, state):

mongo.db.history.insert_one(state_change)

# check to see if parent is a summary node, if so update parent state
if "parent" in pipeline:
parent_pipeline, parent = get_parent(env, pipeline["parent"], pipeline["name"])
if(parent is not None and
"info" in parent and
"summary" in parent["info"] and
parent["info"]["summary"]):

# get state of all chidren of parent node
child_states = get_child_states(env, parent["info"]["child_pipeline"])

if child_states:
if pipelines["failure_state"] in child_states:
# set parent to new state
if pipelines["failure_state"] != parent["state"]:
notify_state_change(env["name"], parent_pipeline, parent["name"], pipelines["failure_state"])


else:
#pick most common state
new_state = max(child_states, key=child_states.count)
if new_state != parent["state"]:
notify_state_change(env["name"], parent_pipeline, parent["name"], new_state)


return "Updated {0} to state {1}".format(step["name"], state["name"])

@app.route('/reset/<environment>/<pipeline>/<state>')
Expand Down Expand Up @@ -156,6 +181,43 @@ def get_environment(env_name):
return environment
return None

def get_parent(env, parent_name, child_name):

raw_parent = parent_name[1:len(parent_name)]
child_name = "#"+child_name

parent_pipeline = None

for pipeline in env["pipelines"]:
if pipeline["name"] == raw_parent:
parent_pipeline = pipeline
break

parents = []
for step in parent_pipeline["steps"]:
if ("info" in step and "child_pipeline" in step["info"]):
if step["info"]["child_pipeline"] == child_name:
return parent_pipeline["name"], step

return None, None

def get_child_states(env, pipeline_name):

pipeline_name = pipeline_name[1:len(pipeline_name)]

child_pipeline = None

for pipeline in env["pipelines"]:
if pipeline["name"] == pipeline_name:
child_pipeline = pipeline
break

if not child_pipeline: return None

states = [ step["state"] for step in pipeline["steps"] ]
return states



if __name__ == '__main__':

Expand Down
12 changes: 7 additions & 5 deletions server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def load():
schema = json.load(f)

pipeline_defs["states"] = schema["states"]
pipeline_defs["failure_state"] = schema["failure_state"]
pipeline_defs["root_hash"] = schema["root_hash"]
pipeline_defs["notifications"] = schema["notifications"]

Expand Down Expand Up @@ -41,11 +42,12 @@ def load():
for env in pipeline_defs["environments"]:
for pipeline in env["pipelines"]:
for step in pipeline["steps"]:
if "info" in step and "child_pipeline" in step["info"]:
for potential_child in env["pipelines"]:
if "#" + potential_child["name"] == step["info"]["child_pipeline"]:
potential_child["parent"] = "#" + pipeline["name"]
break
if "info" in step :
if "child_pipeline" in step["info"]:
for potential_child in env["pipelines"]:
if "#" + potential_child["name"] == step["info"]["child_pipeline"]:
potential_child["parent"] = "#" + pipeline["name"]
break

print("Loaded data", pipeline_defs)
return pipeline_defs
Expand Down

0 comments on commit eaede8b

Please sign in to comment.