Skip to content

Commit

Permalink
Added support for restart basing on service dependencies. (Fixes sign…
Browse files Browse the repository at this point in the history
  • Loading branch information
zsuzhengdu committed Apr 13, 2017
1 parent 10b2f41 commit a1e7fe4
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions maestro/plays/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def __init__(self, containers=[], forward=True, ignore_dependencies=False,
self._dependencies = dict(
(c.name, self._gather_dependencies(c)) for c in containers)

self._start_dependencies = dict(
(c.name, self._gather_restart_dependencies(c)) for c in containers)

self._om = termoutput.OutputManager(len(containers))
self._threads = set([])
self._done = set([])
Expand Down Expand Up @@ -85,8 +88,13 @@ def act(task):
# Wait until we can be released (or if an error occurred for
# another container).
self._cv.acquire()
while not self._satisfied(task.container) and not self._error:
self._cv.wait(1)
if self._play != 'restart':
while not self._satisfied(task.container) and not self._error:
self._cv.wait(1)
else:
while not self._restart_satisfied(task.container) and not self._error:
self._cv.wait(1)

self._cv.release()

# Abort if needed
Expand Down Expand Up @@ -178,6 +186,19 @@ def _gather_dependencies(self, container):
result.remove(container)
return result

def _gather_restart_dependencies(self, container):
containers = set(self._containers)
result = set([container])

for container in result:
deps = container.service.needed_for if self._forward else container.service.requires
deps = functools.reduce(lambda x, y: x.union(y), [s.containers for s in deps], set([]))

result = result.union(deps.intersection(containers))

result.remove(container)
return result

def _satisfied(self, container):
"""Returns True if all the dependencies of a given container have been
satisfied by what's been executed so far (or if it was explicitely
Expand All @@ -187,6 +208,12 @@ def _satisfied(self, container):
missing = self._dependencies[container.name].difference(self._done)
return len(missing) == 0

def _restart_satisfied(self, container):
if self._ignore_dependencies:
return True
missing = self._start_dependencies[container.name].difference(self._done)
return len(missing) == 0


class FullStatus(BaseOrchestrationPlay):
"""A Maestro orchestration play that displays the status of the given
Expand Down

0 comments on commit a1e7fe4

Please sign in to comment.