Pass link and lifecycle state in state transitions

Requires changes to monasca-thresh to use

Change-Id: I3ef6f7a692c09b7cd2d6cb4098790e90ccd0a5e8
This commit is contained in:
Ryan Brandt 2015-12-16 14:32:02 -07:00
parent 2c48c8de50
commit 986fa566eb
4 changed files with 19 additions and 12 deletions

View File

@ -121,7 +121,7 @@ class AlarmsRepository(mysql_repository.MySQLRepository,
with cnxn:
select_query = """
select a.state
select a.state, a.link, a.lifecycle_state
from alarm as a
inner join alarm_definition as ad
on ad.id = a.alarm_definition_id
@ -160,7 +160,7 @@ class AlarmsRepository(mysql_repository.MySQLRepository,
cursor.execute(update_query, parms)
return prev_alarm['state'], time_ms
return prev_alarm, time_ms
@mysql_repository.mysql_try_catch_block
def delete_alarm(self, tenant_id, id):

View File

@ -294,7 +294,7 @@ class AlarmDefinitions(alarm_definitions_api_v2.AlarmDefinitionsV2API,
sub_alarm_definition_rows)
self._send_alarm_event(u'alarm-deleted', tenant_id, id,
alarm_metric_rows, sub_alarm_rows)
alarm_metric_rows, sub_alarm_rows, None, None)
@resource.resource_try_catch_block
def _alarm_definition_list(self, tenant_id, name, dimensions, req_uri, sort_by,

View File

@ -45,6 +45,7 @@ class Alarming(object):
alarm_definition_row,
alarm_metric_rows,
old_state, new_state,
link, lifecycle_state,
time_ms):
# This is a change via the API, so there is no SubAlarm info to add
@ -59,6 +60,8 @@ class Alarming(object):
u'actionsEnabled': alarm_definition_row['actions_enabled'] == 1,
u'stateChangeReason': 'Alarm state updated via API',
u'severity': alarm_definition_row['severity'],
u'link': link,
u'lifecycleState': lifecycle_state,
u'oldState': old_state,
u'newState': new_state,
u'timestamp': time_ms,
@ -88,7 +91,8 @@ class Alarming(object):
return metric
def _send_alarm_event(self, event_type, tenant_id, alarm_definition_id,
alarm_metric_rows, sub_alarm_rows, extra_info=None):
alarm_metric_rows, sub_alarm_rows, link, lifecycle_state,
extra_info=None):
if not alarm_metric_rows:
return
@ -120,6 +124,8 @@ class Alarming(object):
alarm_definition_id,
u'alarmId': alarm_metric_row[
'alarm_id'],
u'link': link,
u'lifecycleState': lifecycle_state,
u'alarmMetrics':
alarm_metrics_event_msg}}
if extra_info:

View File

@ -88,9 +88,9 @@ class Alarms(alarms_api_v2.AlarmsV2API,
# if a field is not present or is None, replace it with the old value
if 'state' not in alarm or not alarm['state']:
alarm['state'] = old_alarm['state']
if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']:
if 'lifecycle_state' not in alarm or alarm['lifecycle_state'] is None:
alarm['lifecycle_state'] = old_alarm['lifecycle_state']
if 'link' not in alarm or not alarm['link']:
if 'link' not in alarm or alarm['link'] is None:
alarm['link'] = old_alarm['link']
self._alarm_patch(tenant_id, alarm_id, alarm['state'],
@ -210,20 +210,20 @@ class Alarms(alarms_api_v2.AlarmsV2API,
alarm_metric_rows = self._alarms_repo.get_alarm_metrics(alarm_id)
sub_alarm_rows = self._alarms_repo.get_sub_alarms(tenant_id, alarm_id)
old_state, time_ms = self._alarms_repo.update_alarm(tenant_id, alarm_id,
old_alarm, time_ms = self._alarms_repo.update_alarm(tenant_id, alarm_id,
new_state,
lifecycle_state, link)
# alarm_definition_id is the same for all rows.
alarm_definition_id = sub_alarm_rows[0]['alarm_definition_id']
state_info = {u'alarmState': new_state, u'oldAlarmState': old_state}
state_info = {u'alarmState': new_state, u'oldAlarmState': old_alarm['state']}
self._send_alarm_event(u'alarm-updated', tenant_id,
alarm_definition_id, alarm_metric_rows,
sub_alarm_rows, state_info)
sub_alarm_rows, link, lifecycle_state, state_info)
if old_state != new_state:
if old_alarm['state'] != new_state:
try:
alarm_definition_row = self._alarms_repo.get_alarm_definition(
tenant_id, alarm_id)
@ -236,7 +236,8 @@ class Alarms(alarms_api_v2.AlarmsV2API,
self._send_alarm_transitioned_event(tenant_id, alarm_id,
alarm_definition_row,
alarm_metric_rows,
old_state, new_state,
old_alarm['state'], new_state,
link, lifecycle_state,
time_ms)
@resource.resource_try_catch_block
@ -252,7 +253,7 @@ class Alarms(alarms_api_v2.AlarmsV2API,
self._send_alarm_event(u'alarm-deleted', tenant_id,
alarm_definition_id, alarm_metric_rows,
sub_alarm_rows)
sub_alarm_rows, None, None)
@resource.resource_try_catch_block
def _alarm_show(self, req_uri, tenant_id, alarm_id):