diff --git a/docs/monasca-api-spec.md b/docs/monasca-api-spec.md index ecb4f11af..c4166d0ec 100644 --- a/docs/monasca-api-spec.md +++ b/docs/monasca-api-spec.md @@ -1954,17 +1954,16 @@ None. Consists of an alarm definition. An alarm has the following properties: * name (string(255), required) - A name of the alarm definition. -* description (string(255), optional) - A description of an alarm definition. +* description (string(255), required) - A description of an alarm definition. * expression (string, required) - An alarm expression. -* match_by ([string], optional) - The metric dimensions to use to create unique alarms. If specified, this MUST be the same as the existing value for match_by -* severity (string, optional) - Severity of an alarm definition. Must be either `LOW`, `MEDIUM`, `HIGH` or `CRITICAL`. -* alarm_actions ([string(50)], optional) -* ok_actions ([string(50)], optional) -* undetermined_actions ([string(50)], optional) +* match_by ([string], required) - The metric dimensions to use to create unique alarms. This MUST be the same as the existing value for match_by +* severity (string, required) - Severity of an alarm definition. Must be either `LOW`, `MEDIUM`, `HIGH` or `CRITICAL`. +* alarm_actions ([string(50)], required) +* ok_actions ([string(50)], required) +* undetermined_actions ([string(50)], required) +* actions_enabled (boolean, required) If actions should be enabled (set to true) or ignored (set to false) -If optional parameters are not specified they will be reset to their default state. - -Only the parameters that are specified will be updated. See Changing Alarm Definitions for restrictions on changing expression and match_by. +See Changing Alarm Definitions for restrictions on changing expression and match_by. #### Request Examples ``` @@ -1981,6 +1980,7 @@ Cache-Control: no-cache "match_by":[ "hostname" ], + "severity": "LOW", "alarm_actions":[ "c60ec47e-5038-4bf1-9f95-4046c6e9a759" ], @@ -1989,7 +1989,8 @@ Cache-Control: no-cache ], "undetermined_actions":[ "c60ec47e-5038-4bf1-9f95-4046c6e9a759" - ] + ], + "actions_enabled": true } ``` diff --git a/java/src/main/java/monasca/api/app/command/UpdateAlarmDefinitionCommand.java b/java/src/main/java/monasca/api/app/command/UpdateAlarmDefinitionCommand.java index 14c1c4050..a288239d3 100644 --- a/java/src/main/java/monasca/api/app/command/UpdateAlarmDefinitionCommand.java +++ b/java/src/main/java/monasca/api/app/command/UpdateAlarmDefinitionCommand.java @@ -13,34 +13,102 @@ */ package monasca.api.app.command; +import org.hibernate.validator.constraints.NotEmpty; + import java.util.List; -import javax.annotation.Nullable; import javax.validation.constraints.NotNull; -public class UpdateAlarmDefinitionCommand extends CreateAlarmDefinitionCommand { +import monasca.api.app.validation.AlarmValidation; + +public class UpdateAlarmDefinitionCommand { + @NotNull public Boolean actionsEnabled; + @NotEmpty + public String name; + @NotNull + public String description; + @NotEmpty + public String expression; + @NotNull + public List matchBy; + @NotNull + public String severity; + @NotNull + public List alarmActions; + @NotNull + public List okActions; + @NotNull + public List undeterminedActions; - public UpdateAlarmDefinitionCommand() {} + public UpdateAlarmDefinitionCommand() { + } - public UpdateAlarmDefinitionCommand(String name, @Nullable String description, String expression, - List matchBy, String severity, boolean enabled, List alarmActions, - List okActions, List undeterminedActions) { - super(name, description, expression, matchBy, severity, alarmActions, okActions, - undeterminedActions); + public UpdateAlarmDefinitionCommand(String name, String description, String expression, + List matchBy, String severity, boolean enabled, + List alarmActions, + List okActions, List undeterminedActions) { + this.name = name; + this.description = description; + this.expression = expression; + this.matchBy = matchBy; + this.alarmActions = alarmActions; + this.okActions = okActions; + this.undeterminedActions = undeterminedActions; this.actionsEnabled = enabled; + this.severity = severity; } @Override public boolean equals(Object obj) { if (this == obj) return true; - if (!super.equals(obj)) + if (obj == null) return false; if (!(obj instanceof UpdateAlarmDefinitionCommand)) return false; UpdateAlarmDefinitionCommand other = (UpdateAlarmDefinitionCommand) obj; + if (alarmActions == null) { + if (other.alarmActions != null) + return false; + } else if (!alarmActions.equals(other.alarmActions)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (expression == null) { + if (other.expression != null) + return false; + } else if (!expression.equals(other.expression)) + return false; + if (matchBy == null) { + if (other.matchBy != null) + return false; + } else if (!matchBy.equals(other.matchBy)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (okActions == null) { + if (other.okActions != null) + return false; + } else if (!okActions.equals(other.okActions)) + return false; + if (severity == null) { + if (other.severity != null) + return false; + } else if (!severity.equals(other.severity)) + return false; + if (undeterminedActions == null) { + if (other.undeterminedActions != null) + return false; + } else if (!undeterminedActions.equals(other.undeterminedActions)) + return false; if (actionsEnabled == null) { if (other.actionsEnabled != null) return false; @@ -52,8 +120,21 @@ public class UpdateAlarmDefinitionCommand extends CreateAlarmDefinitionCommand { @Override public int hashCode() { final int prime = 31; - int result = super.hashCode(); + int result = 1; + result = prime * result + ((alarmActions == null) ? 0 : alarmActions.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((expression == null) ? 0 : expression.hashCode()); + result = prime * result + ((matchBy == null) ? 0 : matchBy.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((okActions == null) ? 0 : okActions.hashCode()); + result = prime * result + ((severity == null) ? 0 : severity.hashCode()); + result = prime * result + ((undeterminedActions == null) ? 0 : undeterminedActions.hashCode()); result = prime * result + ((actionsEnabled == null) ? 0 : actionsEnabled.hashCode()); return result; } + + public void validate() { + AlarmValidation.validate(name, description, severity, alarmActions, okActions, + undeterminedActions); + } } diff --git a/java/src/test/java/monasca/api/resource/AlarmDefinitionResourceTest.java b/java/src/test/java/monasca/api/resource/AlarmDefinitionResourceTest.java index b24fe249d..f2b4e268d 100644 --- a/java/src/test/java/monasca/api/resource/AlarmDefinitionResourceTest.java +++ b/java/src/test/java/monasca/api/resource/AlarmDefinitionResourceTest.java @@ -118,9 +118,10 @@ public class AlarmDefinitionResourceTest extends AbstractMonApiResourceTest { .header("X-Tenant-Id", "abc") .header("Content-Type", MediaType.APPLICATION_JSON) .put(ClientResponse.class, - new UpdateAlarmDefinitionCommand("Disk Exceeds 1k Operations", null, expression, + new UpdateAlarmDefinitionCommand("Disk Exceeds 1k Operations", "", expression, Arrays.asList("service", "instance_id"), "LOW", - true, alarmActions, null, null)); + true, alarmActions, new ArrayList(), + new ArrayList())); assertEquals(response.getStatus(), 200); verify(service).update(eq("abc"), eq("123"), any(AlarmExpression.class),