diff options
| author | Joshua Harlow <harlowja@gmail.com> | 2013-07-06 20:55:46 -0700 |
|---|---|---|
| committer | Joshua Harlow <harlowja@gmail.com> | 2013-07-06 22:17:25 -0700 |
| commit | b0beb0728154b76eaf132756876d5942e49fb1bd (patch) | |
| tree | 1c03a50f2bd91f480f4a84d76ce167091889ebd3 /taskflow/patterns | |
| parent | b89eefea1804ede071747f558bb11571090445b3 (diff) | |
| download | taskflow-b0beb0728154b76eaf132756876d5942e49fb1bd.tar.gz | |
Unify creation/usage of uuids.
Instead of using the name it is likely better to
give the flows a uuid and use that for tracking
purposes rather than using the flow name (which
maybe duplicated). Also unify the usage of the
job tracking id -> uuid as well as adjust the
visibility of said uuids (to be read-only).
Change-Id: I592800bd9e08e3a7bde33ff250a454588324f052
Diffstat (limited to 'taskflow/patterns')
| -rw-r--r-- | taskflow/patterns/base.py | 26 | ||||
| -rw-r--r-- | taskflow/patterns/graph_flow.py | 6 | ||||
| -rw-r--r-- | taskflow/patterns/linear_flow.py | 13 | ||||
| -rw-r--r-- | taskflow/patterns/resumption/logbook.py | 13 |
4 files changed, 38 insertions, 20 deletions
diff --git a/taskflow/patterns/base.py b/taskflow/patterns/base.py index a20a709..4060cf7 100644 --- a/taskflow/patterns/base.py +++ b/taskflow/patterns/base.py @@ -19,6 +19,8 @@ import abc import threading +from taskflow.openstack.common import uuidutils + from taskflow import decorators from taskflow import exceptions as exc from taskflow import states @@ -47,14 +49,17 @@ class Flow(object): states.PENDING, ]) - def __init__(self, name, parents=None): - self.name = name + def __init__(self, name, parents=None, uuid=None): + self._name = str(name) # The state of this flow. self._state = states.PENDING # If this flow has a parent flow/s which need to be reverted if # this flow fails then please include them here to allow this child # to call the parents... - self.parents = parents + if parents: + self.parents = list(parents) + else: + self.parents = [] # Any objects that want to listen when a wf/task starts/stops/completes # or errors should be registered here. This can be used to monitor # progress and record tasks finishing (so that it becomes possible to @@ -65,6 +70,19 @@ class Flow(object): # Ensure that modifications and/or multiple runs aren't happening # at the same time in the same flow at the same time. self._lock = threading.RLock() + # Assign this flow a unique identifer. + if uuid: + self._id = str(uuid) + else: + self._id = uuidutils.generate_uuid() + + @property + def name(self): + return self._name + + @property + def uuid(self): + return "f-%s" % (self._id) @property def state(self): @@ -89,6 +107,8 @@ class Flow(object): def __str__(self): lines = ["Flow: %s" % (self.name)] + lines.append("%s" % (self.uuid)) + lines.append("%s" % (len(self.parents))) lines.append("%s" % (self.state)) return "; ".join(lines) diff --git a/taskflow/patterns/graph_flow.py b/taskflow/patterns/graph_flow.py index 2883c48..0527c75 100644 --- a/taskflow/patterns/graph_flow.py +++ b/taskflow/patterns/graph_flow.py @@ -36,8 +36,8 @@ class Flow(linear_flow.Flow): a linear topological ordering (and reverse using the same linear topological order)""" - def __init__(self, name, parents=None): - super(Flow, self).__init__(name, parents) + def __init__(self, name, parents=None, uuid=None): + super(Flow, self).__init__(name, parents, uuid) self._graph = digraph.DiGraph() @decorators.locked @@ -59,8 +59,10 @@ class Flow(linear_flow.Flow): def __str__(self): lines = ["GraphFlow: %s" % (self.name)] + lines.append("%s" % (self.uuid)) lines.append("%s" % (self._graph.number_of_nodes())) lines.append("%s" % (self._graph.number_of_edges())) + lines.append("%s" % (len(self.parents))) lines.append("%s" % (self.state)) return "; ".join(lines) diff --git a/taskflow/patterns/linear_flow.py b/taskflow/patterns/linear_flow.py index 9a9df15..cb81ae7 100644 --- a/taskflow/patterns/linear_flow.py +++ b/taskflow/patterns/linear_flow.py @@ -40,8 +40,8 @@ class Flow(base.Flow): Note(harlowja): Each task in the chain must have requirements which are satisfied by the previous task/s in the chain.""" - def __init__(self, name, parents=None): - super(Flow, self).__init__(name, parents) + def __init__(self, name, parents=None, uuid=None): + super(Flow, self).__init__(name, parents, uuid) # The tasks which have been applied will be collected here so that they # can be reverted in the correct order on failure. self._accumulator = utils.RollbackAccumulator() @@ -98,7 +98,9 @@ class Flow(base.Flow): def __str__(self): lines = ["LinearFlow: %s" % (self.name)] + lines.append("%s" % (self.uuid)) lines.append("%s" % (len(self._runners))) + lines.append("%s" % (len(self.parents))) lines.append("%s" % (self.state)) return "; ".join(lines) @@ -279,7 +281,6 @@ class Flow(base.Flow): self._accumulator.rollback(cause) finally: self._change_state(context, states.FAILURE) - if self.parents: - # Rollback any parents flows if they exist... - for p in self.parents: - p.rollback(context, cause) + # Rollback any parents flows if they exist... + for p in self.parents: + p.rollback(context, cause) diff --git a/taskflow/patterns/resumption/logbook.py b/taskflow/patterns/resumption/logbook.py index 604522d..7d1c597 100644 --- a/taskflow/patterns/resumption/logbook.py +++ b/taskflow/patterns/resumption/logbook.py @@ -40,10 +40,8 @@ class Resumption(object): flow = details['flow'] LOG.debug("Recording %s of %s has finished state %s", runner, flow, state) - # TODO(harlowja): switch to using uuids - flow_id = flow.name metadata = {} - flow_details = self._logbook[flow_id] + flow_details = self._logbook[flow.uuid] if state in (states.SUCCESS, states.FAILURE): metadata['result'] = runner.result if runner.uuid not in flow_details: @@ -74,11 +72,9 @@ class Resumption(object): old_state = details['old_state'] LOG.debug("%s has transitioned from %s to %s", flow, old_state, state) - # TODO(harlowja): switch to using uuids - flow_id = flow.name - if flow_id in self._logbook: + if flow.uuid in self._logbook: return - self._logbook.add_flow(flow_id) + self._logbook.add_flow(flow.uuid) flow.task_notifier.register('*', _task_listener) flow.notifier.register('*', _workflow_listener) @@ -119,8 +115,7 @@ class Resumption(object): has already completed (or errored) and the second which has not completed or errored.""" - # TODO(harlowja): switch to using uuids - flow_id = flow.name + flow_id = flow.uuid if flow_id not in self._logbook: LOG.debug("No record of %s", flow) return ([], ordering) |
