Browse Source

Cleanup the amount of conditionals and temp variables in patch

Michael James Hoppal 3 years ago
parent
commit
6f3492343c

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

@@ -32,3 +32,6 @@ class StreamDefinitionsV2API(object):
32 32
 
33 33
     def on_delete(self, req, res, stream_id):
34 34
         res.status = '501 Not Implemented'
35
+
36
+    def on_patch(self, req, res, stream_id):
37
+        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,
242 242
                 where tenant_id = %s and id = %s"""
243 243
 
244 244
             if name is None:
245
-                new_name = original_definition['name']
246
-            else:
247
-                new_name = name.encode('utf8')
245
+                name = original_definition['name']
248 246
 
249 247
             if description is None:
250
-                new_description = original_definition['description']
251
-            else:
252
-                new_description = description.encode('utf8')
248
+                description = original_definition['description']
253 249
 
254 250
             if select is None:
255
-                new_select = original_definition['select_by']
256
-            else:
257
-                new_select = json.dumps(select).encode('utf8')
251
+                select = original_definition['select_by']
258 252
 
259
-            if new_select != original_definition['select_by']:
253
+            if select != original_definition['select_by']:
260 254
                 msg = "select_by must not change".encode('utf8')
261 255
                 raise exceptions.InvalidUpdateException(msg)
262 256
 
263 257
             if group_by is None:
264
-                new_group_by = original_definition['group_by']
265
-            else:
266
-                new_group_by = json.dumps(group_by).encode('utf8')
258
+                group_by = original_definition['group_by']
267 259
 
268
-            if new_group_by != original_definition['group_by']:
260
+            if group_by != original_definition['group_by']:
269 261
                 msg = "group_by must not change".encode('utf8')
270 262
                 raise exceptions.InvalidUpdateException(msg)
271 263
 
272 264
             if fire_criteria is None:
273
-                new_fire_criteria = original_definition['fire_criteria']
274
-            else:
275
-                new_fire_criteria = json.dumps(fire_criteria).encode('utf8')
265
+                fire_criteria = original_definition['fire_criteria']
276 266
 
277 267
             if expiration is None:
278
-                new_expiration = original_definition['expiration']
279
-            else:
280
-                new_expiration = expiration
268
+                expiration = original_definition['expiration']
281 269
 
282 270
             now = timeutils.utcnow()
283 271
 
284 272
             update_parms = [
285
-                new_name,
286
-                new_description,
287
-                new_select,
288
-                new_group_by,
289
-                new_fire_criteria,
290
-                new_expiration,
273
+                name,
274
+                description,
275
+                select,
276
+                group_by,
277
+                fire_criteria,
278
+                expiration,
291 279
                 now,
292 280
                 tenant_id,
293 281
                 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):
248 248
                                                                   stream_definition_id,
249 249
                                                                   name,
250 250
                                                                   description,
251
-                                                                  select,
252
-                                                                  group_by,
253
-                                                                  fire_criteria,
251
+                                                                  None if select is None else json.dumps(select),
252
+                                                                  None if group_by is None else json.dumps(group_by),
253
+                                                                  None if fire_criteria is None else json.dumps(
254
+                                                                      fire_criteria),
254 255
                                                                   expiration,
255 256
                                                                   fire_actions,
256 257
                                                                   expire_actions))

Loading…
Cancel
Save