]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat engine : add show_watch RPC method
authorSteven Hardy <shardy@redhat.com>
Tue, 21 Aug 2012 16:33:49 +0000 (17:33 +0100)
committerSteven Hardy <shardy@redhat.com>
Fri, 24 Aug 2012 09:54:15 +0000 (10:54 +0100)
Add new show_watch RPC method, to allow retrieval
of information related to watches for cloudwatch

Change-Id: Ib434c80cf6cfab7f2cba972d5316f0ed2bbcbf30
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/engine/api.py
heat/engine/manager.py
heat/engine/rpcapi.py

index 097b0bb646e69eedcb293ac5a8b54cfe8f433597..8fe522108599f319518a4cec2985684bf15d8844 100644 (file)
@@ -177,3 +177,78 @@ def format_event(event):
     }
 
     return result
+
+
+# This is the representation of a watch we expose to the API via RPC
+WATCH_KEYS = (
+    WATCH_ACTIONS_ENABLED, WATCH_ALARM_ACTIONS, WATCH_TOPIC,
+    WATCH_UPDATED_TIME, WATCH_DESCRIPTION, WATCH_NAME,
+    WATCH_COMPARISON, WATCH_DIMENSIONS, WATCH_PERIODS,
+    WATCH_INSUFFICIENT_ACTIONS, WATCH_METRIC_NAME, WATCH_NAMESPACE,
+    WATCH_OK_ACTIONS, WATCH_PERIOD, WATCH_STATE_REASON,
+    WATCH_STATE_REASON_DATA, WATCH_STATE_UPDATED_TIME, WATCH_STATE_VALUE,
+    WATCH_STATISTIC, WATCH_THRESHOLD, WATCH_UNIT, WATCH_STACK_NAME
+    ) = (
+    'actions_enabled', 'actions', 'topic',
+    'updated_time', 'description', 'name',
+    'comparison', 'dimensions', 'periods',
+    'insufficient_actions', 'metric_name', 'namespace',
+    'ok_actions', 'period', 'state_reason',
+    'state_reason_data', 'state_updated_time', 'state_value',
+    'statistic', 'threshold', 'unit', 'stack_name')
+
+
+# Alternate representation of a watch rule to align with DB format
+# FIXME : These align with AWS naming for compatibility with the
+# current cfn-push-stats & metadata server, fix when we've ported
+# cfn-push-stats to use the Cloudwatch server and/or moved metric
+# collection into ceilometer, these should just be WATCH_KEYS
+# or each field should be stored separately in the DB watch_data
+# table if we stick to storing watch data in the heat DB
+WATCH_RULE_KEYS = (
+    RULE_ACTIONS_ENABLED, RULE_ALARM_ACTIONS, RULE_TOPIC,
+    RULE_UPDATED_TIME, RULE_DESCRIPTION, RULE_NAME,
+    RULE_COMPARISON, RULE_DIMENSIONS, RULE_PERIODS,
+    RULE_INSUFFICIENT_ACTIONS, RULE_METRIC_NAME, RULE_NAMESPACE,
+    RULE_OK_ACTIONS, RULE_PERIOD, RULE_STATE_REASON,
+    RULE_STATE_REASON_DATA, RULE_STATE_UPDATED_TIME, RULE_STATE_VALUE,
+    RULE_STATISTIC, RULE_THRESHOLD, RULE_UNIT, RULE_STACK_NAME
+    ) = (
+    'ActionsEnabled', 'AlarmActions', 'AlarmArn',
+    'AlarmConfigurationUpdatedTimestamp', 'AlarmDescription', 'AlarmName',
+    'ComparisonOperator', 'Dimensions', 'EvaluationPeriods',
+    'InsufficientDataActions', 'MetricName', 'Namespace',
+    'OKActions', 'Period', 'StateReason',
+    'StateReasonData', 'StateUpdatedTimestamp', 'StateValue',
+    'Statistic', 'Threshold', 'Unit', 'StackName')
+
+
+def format_watch(watch):
+
+    result = {
+        WATCH_ACTIONS_ENABLED: watch.rule.get(RULE_ACTIONS_ENABLED),
+        WATCH_ALARM_ACTIONS: watch.rule.get(RULE_ALARM_ACTIONS),
+        WATCH_TOPIC: watch.rule.get(RULE_TOPIC),
+        WATCH_UPDATED_TIME: heat_utils.strtime(watch.updated_at),
+        WATCH_DESCRIPTION: watch.rule.get(RULE_DESCRIPTION),
+        WATCH_NAME: watch.name,
+        WATCH_COMPARISON: watch.rule.get(RULE_COMPARISON),
+        WATCH_DIMENSIONS: watch.rule.get(RULE_DIMENSIONS) or [],
+        WATCH_PERIODS: watch.rule.get(RULE_PERIODS),
+        WATCH_INSUFFICIENT_ACTIONS: watch.rule.get(RULE_INSUFFICIENT_ACTIONS),
+        WATCH_METRIC_NAME: watch.rule.get(RULE_METRIC_NAME),
+        WATCH_NAMESPACE: watch.rule.get(RULE_NAMESPACE),
+        WATCH_OK_ACTIONS: watch.rule.get(RULE_OK_ACTIONS),
+        WATCH_PERIOD: watch.rule.get(RULE_PERIOD),
+        WATCH_STATE_REASON: watch.rule.get(RULE_STATE_REASON),
+        WATCH_STATE_REASON_DATA: watch.rule.get(RULE_STATE_REASON_DATA),
+        WATCH_STATE_UPDATED_TIME: heat_utils.strtime(
+                                  watch.rule.get(RULE_STATE_UPDATED_TIME)),
+        WATCH_STATE_VALUE: watch.state,
+        WATCH_STATISTIC: watch.rule.get(RULE_STATISTIC),
+        WATCH_THRESHOLD: watch.rule.get(RULE_THRESHOLD),
+        WATCH_UNIT: watch.rule.get(RULE_UNIT),
+        WATCH_STACK_NAME: watch.stack_name
+    }
+
+    return result
index 2e1c26ce9dc1e969d9aa0aa9b219c297543814ec..1af5f98712ff9f55159b23ac44343e62f7e1ffcb 100644 (file)
@@ -479,3 +479,26 @@ class EngineManager(manager.Manager):
             self.run_rule(None, wr)
 
         return [None, wd.data]
+
+    def show_watch(self, context, watch_name):
+        '''
+        The show_watch method returns the attributes of one watch/alarm
+        arg1 -> RPC context.
+        arg2 -> Name of the watch you want to see, or None to see all
+        '''
+        if watch_name:
+            try:
+                wrs = db_api.watch_rule_get(context, watch_name)
+            except Exception as ex:
+                logger.warn('show_watch (%s) db error %s' %
+                            (watch_name, str(ex)))
+                return
+        else:
+            try:
+                wrs = db_api.watch_rule_get_all(context)
+            except Exception as ex:
+                logger.warn('show_watch (all) db error %s' % str(ex))
+                return
+
+        result = [api.format_watch(w) for w in wrs]
+        return result
index 50829bdbd5e9876f2fee35b49c513d3289f315a3..c786f3234be3a3b6a8830179000fd1d9cb3ce930 100644 (file)
@@ -219,3 +219,16 @@ class EngineAPI(heat.openstack.common.rpc.proxy.RpcProxy):
         return self.call(ctxt, self.make_msg('create_watch_data',
                          watch_name=watch_name, stats_data=stats_data),
                          topic=_engine_topic(self.topic, ctxt, None))
+
+    def show_watch(self, ctxt, watch_name):
+        """
+        The show_watch method returns the attributes of one watch
+        or all watches if no watch_name is passed
+
+        :param ctxt: RPC context.
+        :param watch_name: Name of the watch/alarm you want to see,
+                           or None to see all
+        """
+        return self.call(ctxt, self.make_msg('show_watch',
+                         watch_name=watch_name),
+                         topic=_engine_topic(self.topic, ctxt, None))