diff options
author | Fei Tang <tang.fei4@zte.com.cn> | 2018-03-27 16:26:39 +0800 |
---|---|---|
committer | Fei Tang <tang.fei4@zte.com.cn> | 2018-03-27 16:50:32 +0800 |
commit | 6c4fde1fd6dcf484d2c567d3fabf0496ed8b30e0 (patch) | |
tree | 0c357c36cfda707fa1ec6cd81d5f0f95f53f2bcd /holmes-actions/src | |
parent | 131be6f05c41acd5502d637d2d3326d8b20081ce (diff) |
add alarm synchronization related operation
Issue-ID: HOLMES-106
Change-Id: I9020c29b69eb0e8bd5a0a33901c671fd02b9f0d1
Signed-off-by: FeiTang <tang.fei4@zte.com.cn>
Diffstat (limited to 'holmes-actions/src')
6 files changed, 276 insertions, 0 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java new file mode 100644 index 0000000..fe1f677 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java @@ -0,0 +1,49 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.common.api.entity;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class AlarmInfo {
+
+ @SerializedName(value = "eventid")
+ private String eventId;
+
+ @SerializedName(value = "eventname")
+ private String eventName;
+
+ @SerializedName(value = "startepochmicrosec")
+ private Long startEpochMicroSec;
+
+ @SerializedName(value = "lastepochmicrosec")
+ private Long lastEpochMicroSec;
+
+ @SerializedName(value = "sourceid")
+ private String sourceId;
+
+ @SerializedName(value = "sourcename")
+ private String sourceName;
+
+ @SerializedName(value = "alarmiscleared")
+ private int alarmIsCleared;
+
+ @SerializedName(value = "rootflag")
+ private int rootFlag;
+}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/exception/AlarmInfoException.java b/holmes-actions/src/main/java/org/onap/holmes/common/exception/AlarmInfoException.java new file mode 100644 index 0000000..ab3eba7 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/exception/AlarmInfoException.java @@ -0,0 +1,23 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.common.exception;
+
+public class AlarmInfoException extends Exception {
+
+ public AlarmInfoException(String msg, Exception e) { super(msg, e);}
+
+ public AlarmInfoException(String msg) { super(msg);}
+}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java new file mode 100644 index 0000000..0c7d756 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java @@ -0,0 +1,39 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.common.utils;
+
+import org.onap.holmes.common.api.entity.AlarmInfo;
+import org.skife.jdbi.v2.StatementContext;
+import org.skife.jdbi.v2.tweak.ResultSetMapper;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class AlarmInfoMapper implements ResultSetMapper<AlarmInfo> {
+ @Override
+ public AlarmInfo map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
+ AlarmInfo alarmInfo = new AlarmInfo();
+ alarmInfo.setAlarmIsCleared(resultSet.getInt("alarmiscleared"));
+ alarmInfo.setRootFlag(resultSet.getInt("rootflag"));
+ alarmInfo.setEventId(resultSet.getString("eventid"));
+ alarmInfo.setEventName(resultSet.getString("eventname"));
+ alarmInfo.setSourceId(resultSet.getString("sourceid"));
+ alarmInfo.setSourceName(resultSet.getString("sourcename"));
+ alarmInfo.setStartEpochMicroSec(resultSet.getLong("startepochmicrosec"));
+ alarmInfo.setLastEpochMicroSec(resultSet.getLong("lastepochmicrosec"));
+ return alarmInfo;
+ }
+}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmInfoTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmInfoTest.java new file mode 100644 index 0000000..a2e60ee --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmInfoTest.java @@ -0,0 +1,94 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.common.api.entity;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class AlarmInfoTest {
+
+ private AlarmInfo alarmInfo;
+
+ @Before
+ public void before() throws Exception {
+ alarmInfo = new AlarmInfo();
+ }
+
+ @After
+ public void after() throws Exception {
+
+ }
+
+ @Test
+ public void getterAndSetter4EventID() throws Exception {
+ final String eventID = "eventId";
+ alarmInfo.setEventId(eventID);
+ assertThat(alarmInfo.getEventId(), equalTo(eventID));
+ }
+
+ @Test
+ public void getterAndSetter4EventName() throws Exception {
+ final String eventName = "eventName";
+ alarmInfo.setEventName(eventName);
+ assertThat(alarmInfo.getEventName(), equalTo(eventName));
+ }
+
+ @Test
+ public void getterAndSetter4StartEpochMicroSec() throws Exception {
+ final long startEpochMicroSec = 1L;
+ alarmInfo.setStartEpochMicroSec(startEpochMicroSec);
+ assertThat(alarmInfo.getStartEpochMicroSec(), equalTo(startEpochMicroSec));
+ }
+
+ @Test
+ public void getterAndSetter4LastEpochMicroSec() throws Exception {
+ final long lastEpochMicroSec = 1L;
+ alarmInfo.setLastEpochMicroSec(lastEpochMicroSec);
+ assertThat(alarmInfo.getLastEpochMicroSec(), equalTo(lastEpochMicroSec));
+ }
+
+ @Test
+ public void getterAndSetter4SourceID() throws Exception {
+ final String sourceID = "sourceId";
+ alarmInfo.setSourceId(sourceID);
+ assertThat(alarmInfo.getSourceId(), equalTo(sourceID));
+ }
+
+ @Test
+ public void getterAndSetter4SourceName() throws Exception {
+ final String sourceName = "sourceName";
+ alarmInfo.setSourceName(sourceName);
+ assertThat(alarmInfo.getSourceName(), equalTo(sourceName));
+ }
+
+ @Test
+ public void getterAndSetter4AlarmIsCleared() throws Exception {
+ final int alarmIsCleared = 1;
+ alarmInfo.setAlarmIsCleared(alarmIsCleared);
+ assertThat(alarmInfo.getAlarmIsCleared(), equalTo(alarmIsCleared));
+ }
+
+ @Test
+ public void getterAndSetter4RootFlag() throws Exception {
+ final int rootFlag = 1;
+ alarmInfo.setRootFlag(rootFlag);
+ assertThat(alarmInfo.getRootFlag(), equalTo(rootFlag));
+ }
+}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/exception/AlarmInfoExceptionTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/exception/AlarmInfoExceptionTest.java new file mode 100644 index 0000000..1263b73 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/exception/AlarmInfoExceptionTest.java @@ -0,0 +1,27 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.common.exception;
+
+import org.junit.Test;
+
+public class AlarmInfoExceptionTest {
+ @Test
+ public void testConstructors() throws Exception {
+ AlarmInfoException ae1 = new AlarmInfoException("msg", new Exception());
+ AlarmInfoException ae2 = new AlarmInfoException("msg");
+ }
+}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java new file mode 100644 index 0000000..06bbfa8 --- /dev/null +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java @@ -0,0 +1,44 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.common.utils;
+
+import org.junit.Test;
+import org.powermock.api.easymock.PowerMock;
+
+import java.sql.ResultSet;
+
+import static org.easymock.EasyMock.expect;
+
+public class AlarmInfoMapperTest {
+
+ @Test
+ public void map() throws Exception {
+ AlarmInfoMapper mapper = new AlarmInfoMapper();
+ ResultSet resultSet = PowerMock.createMock(ResultSet.class);
+ expect(resultSet.getString("eventid")).andReturn("");
+ expect(resultSet.getString("eventname")).andReturn("");
+ expect(resultSet.getString("sourceid")).andReturn("");
+ expect(resultSet.getString("sourcename")).andReturn("");
+ expect(resultSet.getLong("startepochmicrosec")).andReturn(0L);
+ expect(resultSet.getLong("lastepochmicrosec")).andReturn(0L);
+ expect(resultSet.getInt("alarmiscleared")).andReturn(0);
+ expect(resultSet.getInt("rootflag")).andReturn(0);
+ PowerMock.replay(resultSet);
+ mapper.map(0, resultSet, null);
+ PowerMock.verify(resultSet);
+ }
+}
|