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
This commit is contained in:
Ivan A. Melnikov
2013-10-14 13:06:04 +04:00
parent ec620ef8a2
commit 568843f8ad
6 changed files with 20 additions and 35 deletions

View File

@@ -17,19 +17,20 @@
# under the License. # under the License.
import abc import abc
import six import six
from taskflow.openstack.common import uuidutils
from taskflow.utils import reflection from taskflow.utils import reflection
class Flow(six.with_metaclass(abc.ABCMeta)): class Flow(six.with_metaclass(abc.ABCMeta)):
"""The base abstract class of all flow implementations. """The base abstract class of all flow implementations.
It provides a name and an identifier (uuid) to the flow so that it can be A flow is a structure that defines relationships between tasks. You can
uniquely identifed among many flows while executing or while referencing add tasks and other flows (as subflows) to the flow, and the flow provides
the results (or other metadata) of this flow in storage. 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 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 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. worth mentioning here.
Flows are expected to provide the following methods/properties: Flows are expected to provide the following methods/properties:
- add - add
- __len__ - __len__
- requires - requires
- provides - provides
""" """
def __init__(self, name, uuid=None): def __init__(self, name):
self._name = str(name) self._name = str(name)
if uuid:
self._id = str(uuid)
else:
self._id = uuidutils.generate_uuid()
@property @property
def name(self): def name(self):
"""A non-unique name for this flow (human readable)""" """A non-unique name for this flow (human readable)"""
return self._name return self._name
@property
def uuid(self):
"""A unique identifier for this flow"""
return self._id
@abc.abstractmethod @abc.abstractmethod
def __len__(self): def __len__(self):
"""Returns how many items are in this flow.""" """Returns how many items are in this flow."""
raise NotImplementedError()
def __str__(self): def __str__(self):
lines = ["%s: %s" % (reflection.get_class_name(self), self.name)] lines = ["%s: %s" % (reflection.get_class_name(self), self.name)]
lines.append("%s" % (self.uuid))
lines.append("%s" % (len(self))) lines.append("%s" % (len(self)))
return "; ".join(lines) return "; ".join(lines)
@abc.abstractmethod @abc.abstractmethod
def add(self, *items): def add(self, *items):
"""Adds a given item/items to this flow.""" """Adds a given item/items to this flow."""
raise NotImplementedError()
@abc.abstractproperty @abc.abstractproperty
def requires(self): def requires(self):

View File

@@ -35,8 +35,8 @@ class Flow(flow.Flow):
Note: Cyclic dependencies are not allowed. Note: Cyclic dependencies are not allowed.
""" """
def __init__(self, name, uuid=None): def __init__(self, name):
super(Flow, self).__init__(name, uuid) super(Flow, self).__init__(name)
self._graph = nx.freeze(nx.DiGraph()) self._graph = nx.freeze(nx.DiGraph())
def _validate(self, graph=None): def _validate(self, graph=None):

View File

@@ -31,8 +31,8 @@ class Flow(flow.Flow):
depend on outputs (provided names/values) of tasks/flows that follow it. depend on outputs (provided names/values) of tasks/flows that follow it.
""" """
def __init__(self, name, uuid=None): def __init__(self, name):
super(Flow, self).__init__(name, uuid) super(Flow, self).__init__(name)
self._children = [] self._children = []
def add(self, *items): def add(self, *items):

View File

@@ -31,8 +31,8 @@ class Flow(flow.Flow):
task/flow outputs (provided names/values). task/flow outputs (provided names/values).
""" """
def __init__(self, name, uuid=None): def __init__(self, name):
super(Flow, self).__init__(name, uuid) super(Flow, self).__init__(name)
# NOTE(imelnikov): A unordered flow is unordered, so we use # NOTE(imelnikov): A unordered flow is unordered, so we use
# set instead of list to save children, children so that # set instead of list to save children, children so that
# people using it don't depend on the ordering # people using it don't depend on the ordering

View File

@@ -38,7 +38,7 @@ FLATTEN_EDGE_DATA = {
def _graph_name(flow): def _graph_name(flow):
return "F:%s:%s" % (flow.name, flow.uuid) return "F:%s" % flow.name
def _flatten_linear(flow, flattened): def _flatten_linear(flow, flattened):

View File

@@ -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 logbook (if provided) and then uses the given backend (if provided) to
save the logbook then returns the created flow detail. save the logbook then returns the created flow detail.
""" """
try: flow_id = uuidutils.generate_uuid()
flow_name = getattr(flow, 'name') flow_name = getattr(flow, 'name', None)
except AttributeError: if flow_name is None:
LOG.warn("Flow %s does not have a name attribute, creating one.", flow) LOG.warn("No name provided for flow %s (id %s)" % (flow, flow_id))
flow_name = uuidutils.generate_uuid() flow_name = flow_id
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_detail = logbook.FlowDetail(name=flow_name, uuid=flow_id) flow_detail = logbook.FlowDetail(name=flow_name, uuid=flow_id)
if meta is not None: if meta is not None: