Alarm enabled -> actionsEnabled
This commit is contained in:
parent
836cc38c5d
commit
1d05a23f73
|
@ -132,10 +132,10 @@ public class AlarmService {
|
|||
assertAlarmExists(tenantId, alarmId, command.alarmActions, command.okActions,
|
||||
command.undeterminedActions);
|
||||
updateInternal(tenantId, alarmId, false, command.name, command.description, command.expression,
|
||||
alarmExpression, command.state, command.enabled, command.alarmActions, command.okActions,
|
||||
alarmExpression, command.state, command.actionsEnabled, command.alarmActions, command.okActions,
|
||||
command.undeterminedActions);
|
||||
return new Alarm(alarmId, command.name, command.description, command.expression, command.state,
|
||||
command.enabled, command.alarmActions, command.okActions, command.undeterminedActions);
|
||||
command.actionsEnabled, command.alarmActions, command.okActions, command.undeterminedActions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,7 +146,7 @@ public class AlarmService {
|
|||
* @throws InvalidEntityException if one of the actions cannot be found
|
||||
*/
|
||||
public Alarm patch(String tenantId, String alarmId, String name, String description,
|
||||
String expression, AlarmExpression alarmExpression, AlarmState state, Boolean enabled,
|
||||
String expression, AlarmExpression alarmExpression, AlarmState state, Boolean actionsEnabled,
|
||||
List<String> alarmActions, List<String> okActions, List<String> undeterminedActions) {
|
||||
Alarm alarm = assertAlarmExists(tenantId, alarmId, alarmActions, okActions, undeterminedActions);
|
||||
name = name == null ? alarm.getName() : name;
|
||||
|
@ -154,12 +154,12 @@ public class AlarmService {
|
|||
expression = expression == null ? alarm.getExpression() : expression;
|
||||
alarmExpression = alarmExpression == null ? AlarmExpression.of(expression) : alarmExpression;
|
||||
state = state == null ? alarm.getState() : state;
|
||||
enabled = enabled == null ? alarm.isEnabled() : enabled;
|
||||
actionsEnabled = actionsEnabled == null ? alarm.isActionsEnabled() : actionsEnabled;
|
||||
|
||||
updateInternal(tenantId, alarmId, true, name, description, expression, alarmExpression, state,
|
||||
enabled, alarmActions, okActions, undeterminedActions);
|
||||
actionsEnabled, alarmActions, okActions, undeterminedActions);
|
||||
|
||||
return new Alarm(alarmId, name, description, expression, state, enabled,
|
||||
return new Alarm(alarmId, name, description, expression, state, actionsEnabled,
|
||||
alarmActions == null ? alarm.getAlarmActions() : alarmActions,
|
||||
okActions == null ? alarm.getOkActions() : okActions,
|
||||
undeterminedActions == null ? alarm.getUndeterminedActions() : undeterminedActions);
|
||||
|
@ -167,21 +167,21 @@ public class AlarmService {
|
|||
|
||||
private void updateInternal(String tenantId, String alarmId, boolean patch, String name,
|
||||
String description, String expression, AlarmExpression alarmExpression, AlarmState state,
|
||||
Boolean enabled, List<String> alarmActions, List<String> okActions,
|
||||
Boolean actionsEnabled, List<String> alarmActions, List<String> okActions,
|
||||
List<String> undeterminedActions) {
|
||||
Entry<Map<String, AlarmSubExpression>, Map<String, AlarmSubExpression>> subAlarms = oldAndNewSubExpressionsFor(
|
||||
alarmId, alarmExpression);
|
||||
|
||||
try {
|
||||
LOG.debug("Updating alarm {} for tenant {}", name, tenantId);
|
||||
repo.update(tenantId, alarmId, patch, name, description, expression, state, enabled,
|
||||
repo.update(tenantId, alarmId, patch, name, description, expression, state, actionsEnabled,
|
||||
subAlarms.getKey().keySet(), subAlarms.getValue(), alarmActions, okActions,
|
||||
undeterminedActions);
|
||||
|
||||
// Notify interested parties of new alarm
|
||||
// TODO pass changed sub alarms
|
||||
String event = Serialization.toJson(new AlarmUpdatedEvent(tenantId, alarmId, name,
|
||||
expression, state, enabled, subAlarms.getKey(), null, subAlarms.getValue()));
|
||||
expression, state, actionsEnabled, subAlarms.getKey(), null, subAlarms.getValue()));
|
||||
producer.send(new KeyedMessage<>(config.eventsTopic, tenantId, event));
|
||||
} catch (Exception e) {
|
||||
throw Exceptions.uncheck(e, "Error updating alarm for project / tenant %s", tenantId);
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.hpcloud.mon.common.model.alarm.AlarmState;
|
|||
*/
|
||||
public class UpdateAlarmCommand extends CreateAlarmCommand {
|
||||
@NotNull public AlarmState state;
|
||||
@NotNull public Boolean enabled;
|
||||
@NotNull public Boolean actionsEnabled;
|
||||
|
||||
public UpdateAlarmCommand() {
|
||||
}
|
||||
|
@ -22,6 +22,6 @@ public class UpdateAlarmCommand extends CreateAlarmCommand {
|
|||
List<String> undeterminedActions) {
|
||||
super(name, description, expression, alarmActions, okActions, undeterminedActions);
|
||||
this.state = state;
|
||||
this.enabled = enabled;
|
||||
this.actionsEnabled = enabled;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class Alarm extends AbstractEntity implements Linked {
|
|||
private String description = "";
|
||||
private String expression;
|
||||
private AlarmState state;
|
||||
private boolean enabled;
|
||||
private boolean actionsEnabled;
|
||||
private List<String> alarmActions;
|
||||
private List<String> okActions;
|
||||
private List<String> undeterminedActions;
|
||||
|
@ -28,14 +28,14 @@ public class Alarm extends AbstractEntity implements Linked {
|
|||
}
|
||||
|
||||
public Alarm(String id, String name, String description, String expression, AlarmState state,
|
||||
boolean enabled, List<String> alarmActions, List<String> okActions,
|
||||
boolean actionsEnabled, List<String> alarmActions, List<String> okActions,
|
||||
List<String> undeterminedActions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
setDescription(description);
|
||||
setExpression(expression);
|
||||
setState(state);
|
||||
setEnabled(enabled);
|
||||
setActionsEnabled(actionsEnabled);
|
||||
setAlarmActions(alarmActions);
|
||||
setOkActions(okActions);
|
||||
setUndeterminedActions(undeterminedActions);
|
||||
|
@ -60,7 +60,7 @@ public class Alarm extends AbstractEntity implements Linked {
|
|||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (enabled != other.enabled)
|
||||
if (actionsEnabled != other.actionsEnabled)
|
||||
return false;
|
||||
if (expression == null) {
|
||||
if (other.expression != null)
|
||||
|
@ -134,7 +134,7 @@ public class Alarm extends AbstractEntity implements Linked {
|
|||
int result = super.hashCode();
|
||||
result = prime * result + ((alarmActions == null) ? 0 : alarmActions.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + (enabled ? 1231 : 1237);
|
||||
result = prime * result + (actionsEnabled ? 1231 : 1237);
|
||||
result = prime * result + ((expression == null) ? 0 : expression.hashCode());
|
||||
result = prime * result + ((links == null) ? 0 : links.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
|
@ -144,8 +144,12 @@ public class Alarm extends AbstractEntity implements Linked {
|
|||
return result;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
public boolean isActionsEnabled() {
|
||||
return actionsEnabled;
|
||||
}
|
||||
|
||||
public void setActionsEnabled(boolean actionsEnabled) {
|
||||
this.actionsEnabled = actionsEnabled;
|
||||
}
|
||||
|
||||
public void setAlarmActions(List<String> alarmActions) {
|
||||
|
@ -156,10 +160,6 @@ public class Alarm extends AbstractEntity implements Linked {
|
|||
this.description = description == null ? "" : description;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void setExpression(String expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class AlarmRepositoryImpl implements AlarmRepository {
|
|||
try {
|
||||
h.begin();
|
||||
h.insert(
|
||||
"insert into alarm (id, tenant_id, name, description, expression, state, enabled, created_at, updated_at, deleted_at) values (?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), NULL)",
|
||||
"insert into alarm (id, tenant_id, name, description, expression, state, actions_enabled, created_at, updated_at, deleted_at) values (?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), NULL)",
|
||||
id, tenantId, name, description, expression, AlarmState.UNDETERMINED.toString(), true);
|
||||
|
||||
// Persist sub-alarms
|
||||
|
@ -191,16 +191,16 @@ public class AlarmRepositoryImpl implements AlarmRepository {
|
|||
|
||||
@Override
|
||||
public void update(String tenantId, String id, boolean patch, String name, String description,
|
||||
String expression, AlarmState state, boolean enabled, Collection<String> oldSubAlarmIds,
|
||||
Map<String, AlarmSubExpression> newSubAlarms, List<String> alarmActions,
|
||||
List<String> okActions, List<String> undeterminedActions) {
|
||||
String expression, AlarmState state, boolean actionsEnabled,
|
||||
Collection<String> oldSubAlarmIds, Map<String, AlarmSubExpression> newSubAlarms,
|
||||
List<String> alarmActions, List<String> okActions, List<String> undeterminedActions) {
|
||||
Handle h = db.open();
|
||||
|
||||
try {
|
||||
h.begin();
|
||||
h.insert(
|
||||
"update alarm set name = ?, description = ?, expression = ?, state = ?, enabled = ?, updated_at = NOW() where tenant_id = ? and id = ?",
|
||||
name, description, expression, state.name(), enabled, tenantId, id);
|
||||
"update alarm set name = ?, description = ?, expression = ?, state = ?, actions_enabled = ?, updated_at = NOW() where tenant_id = ? and id = ?",
|
||||
name, description, expression, state.name(), actionsEnabled, tenantId, id);
|
||||
|
||||
// Delete old sub-alarms
|
||||
if (oldSubAlarmIds != null)
|
||||
|
|
|
@ -67,7 +67,7 @@ public class AlarmRepositoryImplTest {
|
|||
handle.execute("truncate table sub_alarm_dimension");
|
||||
handle.execute("truncate table alarm");
|
||||
|
||||
handle.execute("insert into alarm (id, tenant_id, name, expression, state, enabled, created_at, updated_at, deleted_at) "
|
||||
handle.execute("insert into alarm (id, tenant_id, name, expression, state, actions_enabled, created_at, updated_at, deleted_at) "
|
||||
+ "values ('123', 'bob', '90% CPU', 'avg(hpcs.compute{flavor_id=777, image_id=888, metric_name=cpu, device=1}) > 10', 'UNDETERMINED', 1, NOW(), NOW(), NULL)");
|
||||
handle.execute("insert into sub_alarm (id, alarm_id, function, metric_name, operator, threshold, period, periods, state, created_at, updated_at) "
|
||||
+ "values ('111', '123', 'avg', 'hpcs.compute', 'GT', 10, 60, 1, 'UNDETERMINED', NOW(), NOW())");
|
||||
|
@ -78,7 +78,7 @@ public class AlarmRepositoryImplTest {
|
|||
handle.execute("insert into alarm_action values ('123', 'ALARM', '29387234')");
|
||||
handle.execute("insert into alarm_action values ('123', 'ALARM', '77778687')");
|
||||
|
||||
handle.execute("insert into alarm (id, tenant_id, name, expression, state, enabled, created_at, updated_at, deleted_at) "
|
||||
handle.execute("insert into alarm (id, tenant_id, name, expression, state, actions_enabled, created_at, updated_at, deleted_at) "
|
||||
+ "values ('234', 'bob', '50% CPU', 'avg(hpcs.compute{flavor_id=777, image_id=888, metric_name=mem}) > 20', 'UNDETERMINED', 1, NOW(), NOW(), NULL)");
|
||||
handle.execute("insert into sub_alarm (id, alarm_id, function, metric_name, operator, threshold, period, periods, state, created_at, updated_at) "
|
||||
+ "values ('222', '234', 'avg', 'hpcs.compute', 'GT', 20, 60, 1, 'UNDETERMINED', NOW(), NOW())");
|
||||
|
@ -148,7 +148,7 @@ public class AlarmRepositoryImplTest {
|
|||
assertEquals(alarm.getExpression(),
|
||||
"avg(hpcs.compute{flavor_id=777, image_id=888, metric_name=cpu, device=1}) > 10");
|
||||
assertEquals(alarm.getState(), AlarmState.UNDETERMINED);
|
||||
assertEquals(alarm.isEnabled(), true);
|
||||
assertEquals(alarm.isActionsEnabled(), true);
|
||||
assertEquals(alarm.getAlarmActions(), alarmActions);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ CREATE TABLE `alarm` (
|
|||
`description` varchar(250) DEFAULT NULL,
|
||||
`expression` mediumtext,
|
||||
`state` varchar(20) NOT NULL check state in ('UNDETERMINED','OK','ALARM'),
|
||||
`enabled` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`actions_enabled` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`created_at` datetime NOT NULL,
|
||||
`updated_at` datetime NOT NULL,
|
||||
`deleted_at` datetime DEFAULT NULL,
|
||||
|
|
Loading…
Reference in New Issue