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 """ # Retrieve the stored credentials & create context # Require admin=True to the stack_get to defeat tenant # scoping otherwise we fail to retrieve the stack logger.debug("Periodic watcher task for stack %s" % sid) admin_context = context.get_admin_context() stack = db_api.stack_get(admin_context, sid, admin=True) if not stack: logger.error("Unable to retrieve stack %s for periodic task" % sid) return user_creds = db_api.user_creds_get(stack.user_creds_id) stack_context = context.RequestContext.from_dict(user_creds) # Get all watchrules for this stack and evaluate them try: wrs = db_api.watch_rule_get_all_by_stack(stack_context, sid) except Exception as ex: logger.warn('periodic_task db error (%s) %s' % ('watch rule removed?', str(ex))) return for wr in wrs: rule = watchrule.WatchRule.load(stack_context, watch=wr) actions = rule.evaluate() for action in actions: self._start_in_thread(sid, action)
def _start_watch_task(self, stack_id, cnxt): wrs = db_api.watch_rule_get_all_by_stack(cnxt, stack_id) # reset the last_evaluated so we don't fire off alarms when # the engine has not been running. now = timeutils.utcnow() for wr in wrs: db_api.watch_rule_update(cnxt, wr.id, {'last_evaluated': now}) if len(wrs) > 0: self._timer_in_thread( stack_id, self._periodic_watcher_task, sid=stack_id)
def _start_watch_task(self, stack_id, cnxt): wrs = db_api.watch_rule_get_all_by_stack(cnxt, stack_id) 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 if start_watch_thread: self._timer_in_thread(stack_id, self._periodic_watcher_task, sid=stack_id)
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
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 logger.debug("Periodic watcher task for stack %s" % sid) admin_context = context.get_admin_context() stack = db_api.stack_get(admin_context, sid, tenant_safe=False, eager_load=True) if not stack: logger.error( _("Unable to retrieve stack %s for periodic task") % sid) return stack_context = EngineService.load_user_creds(stack.user_creds_id) # 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(stack_context, sid) except Exception as ex: logger.warn( _('periodic_task db error watch rule removed? %(ex)s') % ex) return def run_alarm_action(actions, details): for action in actions: action(details=details) stk = parser.Stack.load(stack_context, stack=stack) for res in stk.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, actions, rule.get_details())
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
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 logger.debug(_("Periodic watcher task for stack %s") % sid) admin_context = context.get_admin_context() stack = db_api.stack_get(admin_context, sid, tenant_safe=False, eager_load=True) if not stack: logger.error(_("Unable to retrieve stack %s for periodic task") % sid) return stack_context = EngineService.load_user_creds(stack.user_creds_id) # 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(stack_context, sid) except Exception as ex: logger.warn(_('periodic_task db error watch rule removed? %(ex)s') % ex) return def run_alarm_action(actions, details): for action in actions: action(details=details) stk = parser.Stack.load(stack_context, stack=stack) for res in stk.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, 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 """ # Retrieve the stored credentials & create context # Require admin=True to the stack_get to defeat tenant # scoping otherwise we fail to retrieve the stack logger.debug("Periodic watcher task for stack %s" % sid) admin_context = context.get_admin_context() stack = db_api.stack_get(admin_context, sid, admin=True) if not stack: logger.error("Unable to retrieve stack %s for periodic task" % sid) return user_creds = db_api.user_creds_get(stack.user_creds_id) stack_context = context.RequestContext.from_dict(user_creds) # Get all watchrules for this stack and evaluate them try: wrs = db_api.watch_rule_get_all_by_stack(stack_context, sid) except Exception as ex: logger.warn('periodic_task db error (%s) %s' % ('watch rule removed?', str(ex))) return def run_alarm_action(actions, details): for action in actions: action(details=details) stk = parser.Stack.load(stack_context, stack=stack) for res in stk: res.metadata_update() for wr in wrs: rule = watchrule.WatchRule.load(stack_context, watch=wr) actions = rule.evaluate() if actions: self._start_in_thread(sid, run_alarm_action, actions, rule.get_details())
def get_all_by_stack(cls, context, stack_id): return [ cls._from_db_object(context, cls(), db_rule) for db_rule in db_api.watch_rule_get_all_by_stack( context, stack_id) ]
def get_all_by_stack(cls, context, stack_id): return [cls._from_db_object(context, cls(), db_rule) for db_rule in db_api.watch_rule_get_all_by_stack(context, stack_id)]