diff --git a/thresh/src/main/java/monasca/thresh/domain/model/Alarm.java b/thresh/src/main/java/monasca/thresh/domain/model/Alarm.java index 22949fe..3406861 100644 --- a/thresh/src/main/java/monasca/thresh/domain/model/Alarm.java +++ b/thresh/src/main/java/monasca/thresh/domain/model/Alarm.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. + * Copyright (c) 2014,2016 Hewlett Packard Enterprise Development Company, L.P. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +42,8 @@ public class Alarm extends AbstractEntity { private Map subAlarms; private Set alarmedMetrics = new HashSet<>(); private AlarmState state; + private String link; + private String lifecycleState; private String stateChangeReason; private String alarmDefinitionId; private List transitionSubAlarms = new ArrayList<>(); @@ -97,6 +99,12 @@ public class Alarm extends AbstractEntity { if (state != other.state) { return false; } + if (!compareObjects(link, other.link)) { + return false; + } + if (!compareObjects(lifecycleState, other.lifecycleState)) { + return false; + } if (!compareObjects(alarmDefinitionId, other.alarmDefinitionId)) { return false; } @@ -179,6 +187,10 @@ public class Alarm extends AbstractEntity { return state; } + public String getLink() { return link; } + + public String getLifecycleState() { return lifecycleState; } + public String getStateChangeReason() { return stateChangeReason; } @@ -192,6 +204,8 @@ public class Alarm extends AbstractEntity { final int prime = 31; int result = super.hashCode(); result = prime * result + ((state == null) ? 0 : state.hashCode()); + result = prime * result + ((link == null) ? 0 : link.hashCode()); + result = prime * result + ((lifecycleState == null) ? 0 : lifecycleState.hashCode()); result = prime * result + ((subAlarms == null) ? 0 : subAlarms.hashCode()); result = prime * result + ((alarmDefinitionId == null) ? 0 : alarmDefinitionId.hashCode()); result = prime * result + ((stateChangeReason == null) ? 0 : stateChangeReason.hashCode()); @@ -207,6 +221,14 @@ public class Alarm extends AbstractEntity { this.state = state; } + public void setLink(String newLink) { + this.link = newLink; + } + + public void setLifecycleState(String newLifecycleState) { + this.lifecycleState = newLifecycleState; + } + public void setSubAlarms(List subAlarms) { this.subAlarms = new HashMap(); for (SubAlarm subAlarm : subAlarms) { diff --git a/thresh/src/main/java/monasca/thresh/infrastructure/thresholding/AlarmThresholdingBolt.java b/thresh/src/main/java/monasca/thresh/infrastructure/thresholding/AlarmThresholdingBolt.java index 8730fe8..18a5b34 100644 --- a/thresh/src/main/java/monasca/thresh/infrastructure/thresholding/AlarmThresholdingBolt.java +++ b/thresh/src/main/java/monasca/thresh/infrastructure/thresholding/AlarmThresholdingBolt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. + * Copyright (c) 2014,2016 Hewlett Packard Enterprise Development Company, L.P. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -236,7 +236,8 @@ public class AlarmThresholdingBolt extends BaseRichBolt { new AlarmStateTransitionedEvent(alarmDefinition.getTenantId(), alarm.getId(), alarmDefinition.getId(), alarmedMetrics, alarmDefinition.getName(), alarmDefinition.getDescription(), initialState, alarm.getState(), - alarmDefinition.getSeverity(), alarmDefinition.isActionsEnabled(), stateChangeReason, + alarmDefinition.getSeverity(), alarm.getLink(), alarm.getLifecycleState(), + alarmDefinition.isActionsEnabled(), stateChangeReason, alarm.getTransitionSubAlarms(), getTimestamp()); try { alarmEventForwarder.send(Serialization.toJson(event)); @@ -262,6 +263,8 @@ public class AlarmThresholdingBolt extends BaseRichBolt { } oldAlarm.setState(alarmUpdatedEvent.alarmState); + oldAlarm.setLink(alarmUpdatedEvent.link); + oldAlarm.setLifecycleState(alarmUpdatedEvent.lifecycleState); } diff --git a/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/AlarmThresholdingBoltTest.java b/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/AlarmThresholdingBoltTest.java index 1ad31a2..00f26a5 100644 --- a/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/AlarmThresholdingBoltTest.java +++ b/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/AlarmThresholdingBoltTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. + * Copyright (c) 2014,2016 Hewlett Packard Enterprise Development Company, L.P. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -124,6 +124,7 @@ public class AlarmThresholdingBoltTest { + "\"actionsEnabled\":true," + "\"stateChangeReason\":\"Thresholds were exceeded for the sub-alarms: " + subAlarm.getExpression().getExpression() + " with the values: []\"," + "\"severity\":\"LOW\"," + + "\"link\":null," + "\"lifecycleState\":null," + "\"subAlarms\":[" + buildSubAlarmJson(alarm.getSubAlarms()) + "]," + "\"timestamp\":1395587091003}}"; @@ -149,6 +150,7 @@ public class AlarmThresholdingBoltTest { + subAlarms.get(1).getExpression().getExpression() + " with the values: [], " + subAlarms.get(2).getExpression().getExpression() + " with the values: []" + "\",\"severity\":\"LOW\"," + + "\"link\":null," + "\"lifecycleState\":null," + "\"subAlarms\":[" + buildSubAlarmJson(alarm.getSubAlarms()) + "]," + "\"timestamp\":1395587091003}}"; verify(alarmEventForwarder, times(1)).send(okJson); diff --git a/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/EventProcessingBoltTest.java b/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/EventProcessingBoltTest.java index 8c5c31c..2357366 100644 --- a/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/EventProcessingBoltTest.java +++ b/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/EventProcessingBoltTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. + * Copyright (c) 2014,2016 Hewlett Packard Enterprise Development Company, L.P. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -216,7 +216,8 @@ public class EventProcessingBoltTest { } final AlarmUpdatedEvent event = new AlarmUpdatedEvent(alarm.getId(), alarmDefinition.getId(), - alarmDefinition.getTenantId(), alarmedMetrics, subAlarmMap, newState, alarm.getState()); + alarmDefinition.getTenantId(), alarmedMetrics, subAlarmMap, newState, alarm.getState(), + alarm.getLink(), alarm.getLifecycleState()); return event; } diff --git a/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/deserializer/EventDeserializerTest.java b/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/deserializer/EventDeserializerTest.java index 3b43b7c..91cbed6 100644 --- a/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/deserializer/EventDeserializerTest.java +++ b/thresh/src/test/java/monasca/thresh/infrastructure/thresholding/deserializer/EventDeserializerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. + * Copyright (c) 2014,2016 Hewlett Packard Enterprise Development Company, L.P. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,7 +86,7 @@ public class EventDeserializerTest { final MetricDefinition md = new MetricDefinition("load", dimensions); alarmMetrics.add(md); roundTrip(new AlarmUpdatedEvent(ALARM_ID, ALARM_DEFINITION_ID, TENANT_ID, alarmMetrics, - subAlarms, AlarmState.OK, AlarmState.UNDETERMINED)); + subAlarms, AlarmState.OK, AlarmState.UNDETERMINED, null, null)); } private void roundTrip(Object event) {