def get_all_by_owner_id(cls, context, owner_id): db_stacks = db_api.stack_get_all_by_owner_id(context, owner_id) for db_stack in db_stacks: try: yield cls._from_db_object(context, cls(context), db_stack) except exception.NotFound: pass
def get_all_by_owner_id(cls, context, owner_id): db_stacks = db_api.stack_get_all_by_owner_id(context, owner_id) stacks = map( lambda db_stack: cls._from_db_object( context, cls(context), db_stack), db_stacks) return stacks
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) 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 (%(msg)s) %(ex)s') % { 'msg': 'watch rule removed?', 'ex': 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.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 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 stk = stack.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(stk, actions, details): for action in actions: action(details=details) for res in stk.itervalues(): res.metadata_update() for wr in wrs: rule = watchrule.WatchRule.load(stk.context, watch=wr) actions = rule.evaluate() if actions: self.thread_group_mgr.start(sid, run_alarm_action, stk, actions, rule.get_details())
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 _check_stack_watches(self, sid): # 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 stack_context = self._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 (%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_owner_id(cls, context, owner_id): db_stacks = db_api.stack_get_all_by_owner_id(context, owner_id) stacks = [cls._from_db_object(context, cls(context), db_stack) for db_stack in db_stacks] return stacks