Fixed alarm test
Change-Id: I18fb6f7553dbb1e46d151b83cf43d1d0fa8d7bfd Updated DAOs to recognize deleted alarms MAAS-1184 Change-Id: I7645f48f060a8c2141d770d4e74c4cd75f033433 Ignore failed publishes Change-Id: I5b3e5742fa1e2c9e9c95f4c9bf1c1c4b071809f2 Added support for Swift Change-Id: I167303c98448721d6acd6d3a5b476917ab1750b7
This commit is contained in:
parent
4a0358cae2
commit
6dc5b952c3
4
pom.xml
4
pom.xml
|
@ -15,8 +15,8 @@
|
|||
<properties>
|
||||
<versionNumber>1.0.0</versionNumber>
|
||||
<computedVersion>${versionNumber}-SNAPSHOT</computedVersion>
|
||||
<ps.common.version>1.0.0.292</ps.common.version>
|
||||
<maas.commons.version>1.0.0.140</maas.commons.version>
|
||||
<ps.common.version>1.0.0.295</ps.common.version>
|
||||
<maas.commons.version>1.0.0.145</maas.commons.version>
|
||||
<dropwizard.version>0.6.1</dropwizard.version>
|
||||
|
||||
<skipITs>true</skipITs>
|
||||
|
|
|
@ -68,7 +68,7 @@ public class AlarmDAOImpl implements AlarmDAO {
|
|||
Handle h = db.open();
|
||||
|
||||
try {
|
||||
Alarm alarm = h.createQuery("select * from alarm where id = :id")
|
||||
Alarm alarm = h.createQuery("select * from alarm where id = :id and deleted_at is null")
|
||||
.bind("id", id)
|
||||
.map(new BeanMapper<Alarm>(Alarm.class))
|
||||
.first();
|
||||
|
|
|
@ -20,8 +20,9 @@ import com.hpcloud.maas.domain.service.MetricDefinitionDAO;
|
|||
* @author Jonathan Halterman
|
||||
*/
|
||||
public class MetricDefinitionDAOImpl implements MetricDefinitionDAO {
|
||||
private static final String METRIC_DEF_SQL = "select sa.namespace, sad.dimensions from sub_alarm as sa "
|
||||
+ "left join (select sub_alarm_id, group_concat(dimension_name, '=', value) as dimensions from sub_alarm_dimension group by sub_alarm_id) as sad on sa.id = sad.sub_alarm_id";
|
||||
private static final String METRIC_DEF_SQL = "select sa.namespace, sad.dimensions from alarm as a, sub_alarm as sa "
|
||||
+ "left join (select sub_alarm_id, group_concat(dimension_name, '=', value) as dimensions from sub_alarm_dimension group by sub_alarm_id) as sad on sa.id = sad.sub_alarm_id "
|
||||
+ "where a.id = sa.alarm_id and a.deleted_at is null";
|
||||
|
||||
private final DBI db;
|
||||
|
||||
|
|
|
@ -118,7 +118,10 @@ public class AlarmThresholdingBolt extends BaseRichBolt {
|
|||
AlarmStateTransitionEvent event = new AlarmStateTransitionEvent(alarm.getTenantId(),
|
||||
alarm.getId(), alarm.getName(), initialState, alarm.getState(),
|
||||
alarm.getStateChangeReason(), System.currentTimeMillis() / 1000);
|
||||
rabbitService.send(alertExchange, alertRoutingKey, Serialization.toJson(event));
|
||||
try {
|
||||
rabbitService.send(alertExchange, alertRoutingKey, Serialization.toJson(event));
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
} else
|
||||
LOG.debug("State changed for {}", alarm);
|
||||
}
|
||||
|
|
|
@ -111,10 +111,10 @@ public class AlarmTest {
|
|||
|
||||
assertEquals(
|
||||
Alarm.buildStateChangeReason(AlarmState.UNDETERMINED, expressions),
|
||||
"No data was present for the sub-alarms: [avg(hpcs.compute:{device=1, metric_name=cpu, instance_id=5}, 1) > 5.0 times 3, avg(hpcs.compute:{flavor_id=3, metric_name=mem}, 2) < 4.0 times 3]");
|
||||
"No data was present for the sub-alarms: [avg(hpcs.compute{device=1, metric_name=cpu, instance_id=5}, 1) > 5.0 times 3, avg(hpcs.compute{flavor_id=3, metric_name=mem}, 2) < 4.0 times 3]");
|
||||
|
||||
assertEquals(
|
||||
Alarm.buildStateChangeReason(AlarmState.ALARM, expressions),
|
||||
"Thresholds were exceeded for the sub-alarms: [avg(hpcs.compute:{device=1, metric_name=cpu, instance_id=5}, 1) > 5.0 times 3, avg(hpcs.compute:{flavor_id=3, metric_name=mem}, 2) < 4.0 times 3]");
|
||||
"Thresholds were exceeded for the sub-alarms: [avg(hpcs.compute{device=1, metric_name=cpu, instance_id=5}, 1) > 5.0 times 3, avg(hpcs.compute{flavor_id=3, metric_name=mem}, 2) < 4.0 times 3]");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,21 +44,21 @@ public class MetricDefinitionDAOImplTest {
|
|||
handle.execute("delete from sub_alarm where id in (111, 222, 333)");
|
||||
handle.execute("delete from sub_alarm_dimension where sub_alarm_id in (111, 222, 333)");
|
||||
|
||||
handle.execute("insert into sub_alarm (id, alarm_id, function, namespace, metric_type, metric_subject, operator, threshold, period, periods, state, created_at, updated_at) "
|
||||
+ "values ('111', '123', 'AVG', 'hpcs.compute', 'cpu', '1', 'GT', 10, 60, 1, 'OK', NOW(), NOW())");
|
||||
handle.execute("insert into sub_alarm (id, alarm_id, function, namespace, operator, threshold, period, periods, state, created_at, updated_at) "
|
||||
+ "values ('111', '123', 'AVG', 'hpcs.compute', 'GT', 10, 60, 1, 'OK', NOW(), NOW())");
|
||||
handle.execute("insert into sub_alarm_dimension values ('111', 'metric_name', 'cpu')");
|
||||
handle.execute("insert into sub_alarm_dimension values ('111', 'device', '1')");
|
||||
handle.execute("insert into sub_alarm_dimension values ('111', 'instance_id', '777')");
|
||||
handle.execute("insert into sub_alarm_dimension values ('111', 'image_id', '888')");
|
||||
|
||||
handle.execute("insert into sub_alarm (id, alarm_id, function, namespace, metric_type, metric_subject, operator, threshold, period, periods, state, created_at, updated_at) "
|
||||
+ "values ('222', '123', 'AVG', 'hpcs.compute', 'mem', null, 'GT', 10, 60, 1, 'OK', NOW(), NOW())");
|
||||
handle.execute("insert into sub_alarm (id, alarm_id, function, namespace, operator, threshold, period, periods, state, created_at, updated_at) "
|
||||
+ "values ('222', '123', 'AVG', 'hpcs.compute', 'GT', 10, 60, 1, 'OK', NOW(), NOW())");
|
||||
handle.execute("insert into sub_alarm_dimension values ('222', 'metric_name', 'mem')");
|
||||
handle.execute("insert into sub_alarm_dimension values ('222', 'instance_id', '123')");
|
||||
handle.execute("insert into sub_alarm_dimension values ('222', 'az', '2')");
|
||||
|
||||
handle.execute("insert into sub_alarm (id, alarm_id, function, namespace, metric_type, metric_subject, operator, threshold, period, periods, state, created_at, updated_at) "
|
||||
+ "values ('333', '123', 'AVG', 'foo', 'bar', null, 'GT', 10, 60, 1, 'OK', NOW(), NOW())");
|
||||
handle.execute("insert into sub_alarm (id, alarm_id, function, namespace, operator, threshold, period, periods, state, created_at, updated_at) "
|
||||
+ "values ('333', '123', 'AVG', 'foo', 'GT', 10, 60, 1, 'OK', NOW(), NOW())");
|
||||
handle.execute("insert into sub_alarm_dimension values ('333', 'metric_name', 'bar')");
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ CREATE TABLE `alarm` (
|
|||
`state` varchar(20) NOT NULL check state in ('UNDETERMINED','OK','ALARM'),
|
||||
`created_at` datetime NOT NULL,
|
||||
`updated_at` datetime NOT NULL,
|
||||
`deleted_at` datetime,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue