Browse Source

Cleanup the amount of conditionals and temp variables in patch

tags/0.1.0
Michael James Hoppal 4 years ago
parent
commit
6f3492343c
3 changed files with 21 additions and 29 deletions
  1. +3
    -0
      monasca_events_api/api/stream_definitions_api_v2.py
  2. +14
    -26
      monasca_events_api/common/repositories/mysql/streams_repository.py
  3. +4
    -3
      monasca_events_api/v2/stream_definitions.py

+ 3
- 0
monasca_events_api/api/stream_definitions_api_v2.py View File

@@ -32,3 +32,6 @@ class StreamDefinitionsV2API(object):

def on_delete(self, req, res, stream_id):
res.status = '501 Not Implemented'

def on_patch(self, req, res, stream_id):
res.status = '501 Not Implemented'

+ 14
- 26
monasca_events_api/common/repositories/mysql/streams_repository.py View File

@@ -242,52 +242,40 @@ class StreamsRepository(mysql_repository.MySQLRepository,
where tenant_id = %s and id = %s"""

if name is None:
new_name = original_definition['name']
else:
new_name = name.encode('utf8')
name = original_definition['name']

if description is None:
new_description = original_definition['description']
else:
new_description = description.encode('utf8')
description = original_definition['description']

if select is None:
new_select = original_definition['select_by']
else:
new_select = json.dumps(select).encode('utf8')
select = original_definition['select_by']

if new_select != original_definition['select_by']:
if select != original_definition['select_by']:
msg = "select_by must not change".encode('utf8')
raise exceptions.InvalidUpdateException(msg)

if group_by is None:
new_group_by = original_definition['group_by']
else:
new_group_by = json.dumps(group_by).encode('utf8')
group_by = original_definition['group_by']

if new_group_by != original_definition['group_by']:
if group_by != original_definition['group_by']:
msg = "group_by must not change".encode('utf8')
raise exceptions.InvalidUpdateException(msg)

if fire_criteria is None:
new_fire_criteria = original_definition['fire_criteria']
else:
new_fire_criteria = json.dumps(fire_criteria).encode('utf8')
fire_criteria = original_definition['fire_criteria']

if expiration is None:
new_expiration = original_definition['expiration']
else:
new_expiration = expiration
expiration = original_definition['expiration']

now = timeutils.utcnow()

update_parms = [
new_name,
new_description,
new_select,
new_group_by,
new_fire_criteria,
new_expiration,
name,
description,
select,
group_by,
fire_criteria,
expiration,
now,
tenant_id,
stream_definition_id]

+ 4
- 3
monasca_events_api/v2/stream_definitions.py View File

@@ -248,9 +248,10 @@ class StreamDefinitions(stream_definitions_api_v2.StreamDefinitionsV2API):
stream_definition_id,
name,
description,
select,
group_by,
fire_criteria,
None if select is None else json.dumps(select),
None if group_by is None else json.dumps(group_by),
None if fire_criteria is None else json.dumps(
fire_criteria),
expiration,
fire_actions,
expire_actions))

Loading…
Cancel
Save