Require all fields in an alarm update request

Require all fields (state, lifecyclestate, and link)

Change-Id: I7b548fd87143d2733464e0fc33195da5c4e93534
This commit is contained in:
Ryan Brandt 2015-07-21 11:42:04 -06:00
parent 5f6227ce77
commit 8bc6de7e89
2 changed files with 9 additions and 8 deletions

View File

@ -13,7 +13,6 @@
*/
package monasca.api.app.command;
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
import monasca.common.model.alarm.AlarmState;
@ -22,12 +21,14 @@ public class UpdateAlarmCommand {
@NotNull
public AlarmState state;
@NotNull
public String lifecycleState;
@NotNull
public String link;
public UpdateAlarmCommand() {}
public UpdateAlarmCommand(AlarmState state, @Nullable String lifecycleState, @Nullable String link) {
public UpdateAlarmCommand(AlarmState state, String lifecycleState, String link) {
this.state = state;
this.lifecycleState = lifecycleState;
this.link = link;

View File

@ -57,12 +57,12 @@ class Alarms(alarms_api_v2.AlarmsV2API,
if 'state' not in alarm or not alarm['state']:
raise falcon.HTTPBadRequest('Bad request',
"Field 'state' is required")
# Assume these fields are null if not provided
if 'lifecycle_state' not in alarm:
alarm['lifecycle_state'] = None
if 'link' not in alarm:
alarm['link'] = None
if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']:
raise falcon.HTTPBadRequest('Bad Request',
"Field 'lifecycle_state' is required")
if 'link' not in alarm or not alarm['link']:
raise falcon.HTTPBadRequest('Bad Request',
"Field 'link' is required")
self._alarm_update(tenant_id, alarm_id, alarm['state'],
alarm['lifecycle_state'], alarm['link'])