Merge "Handle retry last_results/last_failure better"
This commit is contained in:
@@ -21,6 +21,7 @@ import logging
|
|||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from taskflow import exceptions as exc
|
||||||
from taskflow.openstack.common import timeutils
|
from taskflow.openstack.common import timeutils
|
||||||
from taskflow.openstack.common import uuidutils
|
from taskflow.openstack.common import uuidutils
|
||||||
from taskflow import states
|
from taskflow import states
|
||||||
@@ -269,6 +270,13 @@ class AtomDetail(object):
|
|||||||
# information can be associated with.
|
# information can be associated with.
|
||||||
self.version = None
|
self.version = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_results(self):
|
||||||
|
"""Gets the atoms last result (if it has many results it should then
|
||||||
|
return the last one of many).
|
||||||
|
"""
|
||||||
|
return self.results
|
||||||
|
|
||||||
def update(self, ad):
|
def update(self, ad):
|
||||||
"""Updates the objects state to be the same as the given one."""
|
"""Updates the objects state to be the same as the given one."""
|
||||||
if ad is self:
|
if ad is self:
|
||||||
@@ -394,6 +402,20 @@ class RetryDetail(AtomDetail):
|
|||||||
self.state = state
|
self.state = state
|
||||||
self.intention = states.EXECUTE
|
self.intention = states.EXECUTE
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_results(self):
|
||||||
|
try:
|
||||||
|
return self.results[-1][0]
|
||||||
|
except IndexError as e:
|
||||||
|
raise exc.NotFound("Last results not found", e)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_failures(self):
|
||||||
|
try:
|
||||||
|
return self.results[-1][1]
|
||||||
|
except IndexError as e:
|
||||||
|
raise exc.NotFound("Last failures not found", e)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data):
|
def from_dict(cls, data):
|
||||||
"""Translates the given data into an instance of this class."""
|
"""Translates the given data into an instance of this class."""
|
||||||
|
|||||||
@@ -350,7 +350,13 @@ class Storage(object):
|
|||||||
with self._lock.write_lock():
|
with self._lock.write_lock():
|
||||||
ad = self._atomdetail_by_name(retry_name,
|
ad = self._atomdetail_by_name(retry_name,
|
||||||
expected_type=logbook.RetryDetail)
|
expected_type=logbook.RetryDetail)
|
||||||
failures = ad.results[-1][1]
|
try:
|
||||||
|
failures = ad.last_failures
|
||||||
|
except exceptions.NotFound as e:
|
||||||
|
raise exceptions.StorageFailure("Unable to fetch most recent"
|
||||||
|
" retry failures so new retry"
|
||||||
|
" failure can be inserted", e)
|
||||||
|
else:
|
||||||
if failed_atom_name not in failures:
|
if failed_atom_name not in failures:
|
||||||
failures[failed_atom_name] = failure
|
failures[failed_atom_name] = failure
|
||||||
self._with_connection(self._save_atom_detail, ad)
|
self._with_connection(self._save_atom_detail, ad)
|
||||||
@@ -364,8 +370,7 @@ class Storage(object):
|
|||||||
ad.results = []
|
ad.results = []
|
||||||
self._with_connection(self._save_atom_detail, ad)
|
self._with_connection(self._save_atom_detail, ad)
|
||||||
|
|
||||||
def get(self, atom_name):
|
def _get(self, atom_name, only_last=False):
|
||||||
"""Gets the result for an atom with a given name from storage."""
|
|
||||||
with self._lock.read_lock():
|
with self._lock.read_lock():
|
||||||
ad = self._atomdetail_by_name(atom_name)
|
ad = self._atomdetail_by_name(atom_name)
|
||||||
if ad.failure is not None:
|
if ad.failure is not None:
|
||||||
@@ -376,8 +381,15 @@ class Storage(object):
|
|||||||
if ad.state not in STATES_WITH_RESULTS:
|
if ad.state not in STATES_WITH_RESULTS:
|
||||||
raise exceptions.NotFound("Result for atom %s is not currently"
|
raise exceptions.NotFound("Result for atom %s is not currently"
|
||||||
" known" % atom_name)
|
" known" % atom_name)
|
||||||
|
if only_last:
|
||||||
|
return ad.last_results
|
||||||
|
else:
|
||||||
return ad.results
|
return ad.results
|
||||||
|
|
||||||
|
def get(self, atom_name):
|
||||||
|
"""Gets the results for an atom with a given name from storage."""
|
||||||
|
return self._get(atom_name)
|
||||||
|
|
||||||
def get_failures(self):
|
def get_failures(self):
|
||||||
"""Get list of failures that happened with this flow.
|
"""Get list of failures that happened with this flow.
|
||||||
|
|
||||||
@@ -473,17 +485,8 @@ class Storage(object):
|
|||||||
# Return the first one that is found.
|
# Return the first one that is found.
|
||||||
for (atom_name, index) in reversed(indexes):
|
for (atom_name, index) in reversed(indexes):
|
||||||
try:
|
try:
|
||||||
result = self.get(atom_name)
|
results = self._get(atom_name, only_last=True)
|
||||||
ad = self._atomdetail_by_name(atom_name)
|
return misc.item_from(results, index, name)
|
||||||
|
|
||||||
# If it is a retry's result then fetch values from the
|
|
||||||
# latest retry run only.
|
|
||||||
if isinstance(ad, logbook.RetryDetail):
|
|
||||||
if result:
|
|
||||||
result = result[-1][0]
|
|
||||||
else:
|
|
||||||
result = None
|
|
||||||
return misc.item_from(result, index, name)
|
|
||||||
except exceptions.NotFound:
|
except exceptions.NotFound:
|
||||||
pass
|
pass
|
||||||
raise exceptions.NotFound("Unable to find result %r" % name)
|
raise exceptions.NotFound("Unable to find result %r" % name)
|
||||||
|
|||||||
Reference in New Issue
Block a user