From 568843f8ade414211423512b36d49747045c47a1 Mon Sep 17 00:00:00 2001 From: "Ivan A. Melnikov" Date: Mon, 14 Oct 2013 13:06:04 +0400 Subject: [PATCH] Remove uuid from taskflow.flow.Flow In a way our resumption works it may not correspond uuid from flow details, and so it is hardly useful. Change-Id: I090d017e2f0f8475594af94a2430a34e6ed1ce70 --- taskflow/flow.py | 26 ++++++++------------------ taskflow/patterns/graph_flow.py | 4 ++-- taskflow/patterns/linear_flow.py | 4 ++-- taskflow/patterns/unordered_flow.py | 4 ++-- taskflow/utils/flow_utils.py | 2 +- taskflow/utils/persistence_utils.py | 15 +++++---------- 6 files changed, 20 insertions(+), 35 deletions(-) diff --git a/taskflow/flow.py b/taskflow/flow.py index 7e674581..a4d8bc16 100644 --- a/taskflow/flow.py +++ b/taskflow/flow.py @@ -17,19 +17,20 @@ # under the License. import abc - import six -from taskflow.openstack.common import uuidutils from taskflow.utils import reflection class Flow(six.with_metaclass(abc.ABCMeta)): """The base abstract class of all flow implementations. - It provides a name and an identifier (uuid) to the flow so that it can be - uniquely identifed among many flows while executing or while referencing - the results (or other metadata) of this flow in storage. + A flow is a structure that defines relationships between tasks. You can + add tasks and other flows (as subflows) to the flow, and the flow provides + a way to implicitly or explicitly define how they are interdependent. + Exact structure of the relationships is defined by concrete + implementation, while this class defines common interface and adds + human-readable (not necessary unique) name. NOTE(harlowja): if a flow is placed in another flow as a subflow, a desired way to compose flows together, then it is valid and permissible that during @@ -39,44 +40,33 @@ class Flow(six.with_metaclass(abc.ABCMeta)): worth mentioning here. Flows are expected to provide the following methods/properties: + - add - __len__ - requires - provides """ - def __init__(self, name, uuid=None): + def __init__(self, name): self._name = str(name) - if uuid: - self._id = str(uuid) - else: - self._id = uuidutils.generate_uuid() @property def name(self): """A non-unique name for this flow (human readable)""" return self._name - @property - def uuid(self): - """A unique identifier for this flow""" - return self._id - @abc.abstractmethod def __len__(self): """Returns how many items are in this flow.""" - raise NotImplementedError() def __str__(self): lines = ["%s: %s" % (reflection.get_class_name(self), self.name)] - lines.append("%s" % (self.uuid)) lines.append("%s" % (len(self))) return "; ".join(lines) @abc.abstractmethod def add(self, *items): """Adds a given item/items to this flow.""" - raise NotImplementedError() @abc.abstractproperty def requires(self): diff --git a/taskflow/patterns/graph_flow.py b/taskflow/patterns/graph_flow.py index 01d59d8a..a9f76ab2 100644 --- a/taskflow/patterns/graph_flow.py +++ b/taskflow/patterns/graph_flow.py @@ -35,8 +35,8 @@ class Flow(flow.Flow): Note: Cyclic dependencies are not allowed. """ - def __init__(self, name, uuid=None): - super(Flow, self).__init__(name, uuid) + def __init__(self, name): + super(Flow, self).__init__(name) self._graph = nx.freeze(nx.DiGraph()) def _validate(self, graph=None): diff --git a/taskflow/patterns/linear_flow.py b/taskflow/patterns/linear_flow.py index a3a38241..650d93fd 100644 --- a/taskflow/patterns/linear_flow.py +++ b/taskflow/patterns/linear_flow.py @@ -31,8 +31,8 @@ class Flow(flow.Flow): depend on outputs (provided names/values) of tasks/flows that follow it. """ - def __init__(self, name, uuid=None): - super(Flow, self).__init__(name, uuid) + def __init__(self, name): + super(Flow, self).__init__(name) self._children = [] def add(self, *items): diff --git a/taskflow/patterns/unordered_flow.py b/taskflow/patterns/unordered_flow.py index 3f517be5..294176e6 100644 --- a/taskflow/patterns/unordered_flow.py +++ b/taskflow/patterns/unordered_flow.py @@ -31,8 +31,8 @@ class Flow(flow.Flow): task/flow outputs (provided names/values). """ - def __init__(self, name, uuid=None): - super(Flow, self).__init__(name, uuid) + def __init__(self, name): + super(Flow, self).__init__(name) # NOTE(imelnikov): A unordered flow is unordered, so we use # set instead of list to save children, children so that # people using it don't depend on the ordering diff --git a/taskflow/utils/flow_utils.py b/taskflow/utils/flow_utils.py index 688a790b..29227887 100644 --- a/taskflow/utils/flow_utils.py +++ b/taskflow/utils/flow_utils.py @@ -38,7 +38,7 @@ FLATTEN_EDGE_DATA = { def _graph_name(flow): - return "F:%s:%s" % (flow.name, flow.uuid) + return "F:%s" % flow.name def _flatten_linear(flow, flattened): diff --git a/taskflow/utils/persistence_utils.py b/taskflow/utils/persistence_utils.py index 681f3caf..e5dbd34e 100644 --- a/taskflow/utils/persistence_utils.py +++ b/taskflow/utils/persistence_utils.py @@ -64,16 +64,11 @@ def create_flow_detail(flow, book=None, backend=None, meta=None): logbook (if provided) and then uses the given backend (if provided) to save the logbook then returns the created flow detail. """ - try: - flow_name = getattr(flow, 'name') - except AttributeError: - LOG.warn("Flow %s does not have a name attribute, creating one.", flow) - flow_name = uuidutils.generate_uuid() - try: - flow_id = getattr(flow, 'uuid') - except AttributeError: - LOG.warn("Flow %s does not have a uuid attribute, creating one.", flow) - flow_id = uuidutils.generate_uuid() + flow_id = uuidutils.generate_uuid() + flow_name = getattr(flow, 'name', None) + if flow_name is None: + LOG.warn("No name provided for flow %s (id %s)" % (flow, flow_id)) + flow_name = flow_id flow_detail = logbook.FlowDetail(name=flow_name, uuid=flow_id) if meta is not None: