summaryrefslogtreecommitdiff
path: root/heat/engine/service.py
diff options
context:
space:
mode:
Diffstat (limited to 'heat/engine/service.py')
-rw-r--r--heat/engine/service.py87
1 files changed, 3 insertions, 84 deletions
diff --git a/heat/engine/service.py b/heat/engine/service.py
index 5c0781444..33b582558 100644
--- a/heat/engine/service.py
+++ b/heat/engine/service.py
@@ -20,7 +20,6 @@ import eventlet
from oslo.config import cfg
from oslo import messaging
from oslo.serialization import jsonutils
-from oslo.utils import timeutils
from osprofiler import profiler
import requests
import six
@@ -44,6 +43,7 @@ from heat.engine import event as evt
from heat.engine import parameter_groups
from heat.engine import properties
from heat.engine import resources
+from heat.engine import service_stack_watch
from heat.engine import stack as parser
from heat.engine import stack_lock
from heat.engine import template as templatem
@@ -216,88 +216,6 @@ class ThreadGroupManager(object):
event.send(message)
-class StackWatch(object):
- def __init__(self, thread_group_mgr):
- self.thread_group_mgr = thread_group_mgr
-
- def start_watch_task(self, stack_id, cnxt):
-
- def stack_has_a_watchrule(sid):
- wrs = db_api.watch_rule_get_all_by_stack(cnxt, sid)
-
- now = timeutils.utcnow()
- start_watch_thread = False
- for wr in wrs:
- # reset the last_evaluated so we don't fire off alarms when
- # the engine has not been running.
- db_api.watch_rule_update(cnxt, wr.id, {'last_evaluated': now})
-
- if wr.state != rpc_api.WATCH_STATE_CEILOMETER_CONTROLLED:
- start_watch_thread = True
-
- children = db_api.stack_get_all_by_owner_id(cnxt, sid)
- for child in children:
- if stack_has_a_watchrule(child.id):
- start_watch_thread = True
-
- return start_watch_thread
-
- if stack_has_a_watchrule(stack_id):
- self.thread_group_mgr.add_timer(
- stack_id,
- self.periodic_watcher_task,
- sid=stack_id)
-
- def check_stack_watches(self, sid):
- # Retrieve the stored credentials & create context
- # Require tenant_safe=False to the stack_get to defeat tenant
- # scoping otherwise we fail to retrieve the stack
- LOG.debug("Periodic watcher task for stack %s" % sid)
- admin_context = context.get_admin_context()
- db_stack = db_api.stack_get(admin_context, sid, tenant_safe=False,
- eager_load=True)
- if not db_stack:
- LOG.error(_LE("Unable to retrieve stack %s for periodic task"),
- sid)
- return
- stack = parser.Stack.load(admin_context, stack=db_stack,
- use_stored_context=True)
-
- # recurse into any nested stacks.
- children = db_api.stack_get_all_by_owner_id(admin_context, sid)
- for child in children:
- self.check_stack_watches(child.id)
-
- # Get all watchrules for this stack and evaluate them
- try:
- wrs = db_api.watch_rule_get_all_by_stack(admin_context, sid)
- except Exception as ex:
- LOG.warn(_LW('periodic_task db error watch rule removed? %(ex)s'),
- ex)
- return
-
- def run_alarm_action(stack, actions, details):
- for action in actions:
- action(details=details)
- for res in stack.itervalues():
- res.metadata_update()
-
- for wr in wrs:
- rule = watchrule.WatchRule.load(stack.context, watch=wr)
- actions = rule.evaluate()
- if actions:
- self.thread_group_mgr.start(sid, run_alarm_action, stack,
- actions, rule.get_details())
-
- def periodic_watcher_task(self, sid):
- """
- Periodic task, created for each stack, triggers watch-rule
- evaluation for all rules defined for the stack
- sid = stack ID
- """
- self.check_stack_watches(sid)
-
-
@profiler.trace_cls("rpc")
class EngineListener(service.Service):
'''
@@ -384,7 +302,8 @@ class EngineService(service.Service):
# so we need to create a ThreadGroupManager here for the periodic tasks
if self.thread_group_mgr is None:
self.thread_group_mgr = ThreadGroupManager()
- self.stack_watch = StackWatch(self.thread_group_mgr)
+ self.stack_watch = service_stack_watch.StackWatch(
+ self.thread_group_mgr)
# Create a periodic_watcher_task per-stack
admin_context = context.get_admin_context()