heat engine allow WatchRule load() from DB object
Allow WatchRule.load to initialize an object based on an existing sqlalchemy DB object, similar to parser.Stack, avoids doing two DB lookups when running the periodic watch tasks Change-Id: I280942b81e5fdee17acf5582e3d319045afa7914 Signed-off-by: Steven Hardy <shardy@redhat.com>
This commit is contained in:
parent
d89f6c0ba1
commit
34c1b9cc33
|
@ -397,14 +397,13 @@ class EngineService(service.Service):
|
|||
|
||||
def _periodic_watcher_task(self, context, sid):
|
||||
try:
|
||||
wrn = [w.name for w in
|
||||
db_api.watch_rule_get_all_by_stack(context, sid)]
|
||||
wrs = db_api.watch_rule_get_all_by_stack(context, sid)
|
||||
except Exception as ex:
|
||||
logger.warn('periodic_task db error (%s) %s' %
|
||||
('watch rule removed?', str(ex)))
|
||||
return
|
||||
for wr in wrn:
|
||||
rule = watchrule.WatchRule.load(context, wr)
|
||||
for wr in wrs:
|
||||
rule = watchrule.WatchRule.load(context, watch=wr)
|
||||
rule.evaluate()
|
||||
|
||||
def create_watch_data(self, context, watch_name, stats_data):
|
||||
|
|
|
@ -53,27 +53,27 @@ class WatchRule(object):
|
|||
self.last_evaluated = last_evaluated
|
||||
|
||||
@classmethod
|
||||
def load(cls, context, watch_name):
|
||||
def load(cls, context, watch_name=None, watch=None):
|
||||
'''
|
||||
Load the watchrule from the DB by name
|
||||
Load the watchrule object, either by name or via an existing DB object
|
||||
'''
|
||||
dbwr = None
|
||||
try:
|
||||
dbwr = db_api.watch_rule_get_by_name(context, watch_name)
|
||||
except Exception as ex:
|
||||
logger.warn('show_watch (%s) db error %s' %
|
||||
(watch_name, str(ex)))
|
||||
if not dbwr:
|
||||
if watch == None:
|
||||
try:
|
||||
watch = db_api.watch_rule_get_by_name(context, watch_name)
|
||||
except Exception as ex:
|
||||
logger.warn('WatchRule.load (%s) db error %s' %
|
||||
(watch_name, str(ex)))
|
||||
if watch == None:
|
||||
raise AttributeError('Unknown watch name %s' % watch_name)
|
||||
else:
|
||||
return cls(context=context,
|
||||
watch_name=dbwr.name,
|
||||
rule=dbwr.rule,
|
||||
stack_id=dbwr.stack_id,
|
||||
state=dbwr.state,
|
||||
wid=dbwr.id,
|
||||
watch_data=dbwr.watch_data,
|
||||
last_evaluated=dbwr.last_evaluated)
|
||||
watch_name=watch.name,
|
||||
rule=watch.rule,
|
||||
stack_id=watch.stack_id,
|
||||
state=watch.state,
|
||||
wid=watch.id,
|
||||
watch_data=watch.watch_data,
|
||||
last_evaluated=watch.last_evaluated)
|
||||
|
||||
def store(self):
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue