diff options
author | Niranjana <niranjana.y60@wipro.com> | 2020-04-21 17:13:17 +0530 |
---|---|---|
committer | Niranjana <niranjana.y60@wipro.com> | 2020-04-22 13:27:30 +0530 |
commit | eeb52b53a4b8a209553698ac0df3155cf731a005 (patch) | |
tree | 0f25176775e4cea8905ac2d0cbecc496cc598349 /src | |
parent | ebd1318096be6b03d633844b2dfa6c65544685d5 (diff) |
Filter FM and PM events & change targetType to PNF
Issue-ID: DCAEGEN2-2200
Signed-off-by: Niranjana <niranjana.y60@wipro.com>
Change-Id: Ib6479b5be8dfc0ce7f42395b5d048ada5d674ff3
Diffstat (limited to 'src')
8 files changed, 206 insertions, 110 deletions
diff --git a/src/main/docker/config/sonhms/config_all.json b/src/main/docker/config/sonhms/config_all.json index 29bb357..b6cb345 100644 --- a/src/main/docker/config/sonhms/config_all.json +++ b/src/main/docker/config/sonhms/config_all.json @@ -92,6 +92,7 @@ "sonhandler.policyNegativeAckThreshold": 3, "sonhandler.policyFixedPciTimeInterval": 300000, "sonhandler.pollingTimeout": 60, + "sonhandler.nfNamingCode": "RansimAgent", "service_calls": { "sdnr-getpnfname": [], "sdnr-getpci": [], @@ -130,4 +131,4 @@ } ] } -}
\ No newline at end of file +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java index 13c86b6..563491c 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java @@ -73,6 +73,7 @@ public class Configuration { private int policyRespTimer; private int policyNegativeAckThreshold; private long policyFixedPciTimeInterval; + private String nfNamingCode; public int getPoorCountThreshold() { return poorCountThreshold; @@ -367,6 +368,14 @@ public class Configuration { public void setPolicyFixedPciTimeInterval(long policyFixedPciTimeInterval) { this.policyFixedPciTimeInterval = policyFixedPciTimeInterval; } + + public String getNfNamingCode() { + return nfNamingCode; + } + + public void setNfNamingCode(String nfNamingCode) { + this.nfNamingCode = nfNamingCode; + } @Override public String toString() { @@ -382,7 +391,7 @@ public class Configuration { + ", badThreshold=" + badThreshold + ", poorThreshold=" + poorThreshold + ", poorCountThreshold=" + poorCountThreshold + ", badCountThreshold=" + badCountThreshold + ", oofTriggerCountTimer=" + oofTriggerCountTimer + ", oofTriggerCountThreshold=" + oofTriggerCountThreshold + ", policyRespTimer=" - + policyRespTimer + ", policyNegativeAckThreshold=" + policyNegativeAckThreshold + ", policyFixedPciTimeInterval="+ policyFixedPciTimeInterval + "]"; + + policyRespTimer + ", policyNegativeAckThreshold=" + policyNegativeAckThreshold + ", policyFixedPciTimeInterval="+ policyFixedPciTimeInterval + ", nfNamingCode="+nfNamingCode+"]"; } /** @@ -441,6 +450,7 @@ public class Configuration { policyRespTimer = jsonObject.get("sonhandler.policyRespTimer").getAsInt(); policyNegativeAckThreshold = jsonObject.get("sonhandler.policyNegativeAckThreshold").getAsInt(); policyFixedPciTimeInterval = jsonObject.get("sonhandler.policyFixedPciTimeInterval").getAsLong(); + nfNamingCode = jsonObject.get("sonhandler.nfNamingCode").getAsString(); log.info("configuration from CBS {}", this); @@ -448,4 +458,4 @@ public class Configuration { -}
\ No newline at end of file +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java index a5d8ba7..5fbb4dc 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019 Wipro Limited. + * Copyright (C) 2019-2020 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import fj.data.Either; import java.io.IOException; + +import org.json.JSONObject; import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; import org.onap.dcaegen2.services.sonhms.dao.PerformanceNotificationsRepository; import org.onap.dcaegen2.services.sonhms.model.Notification; @@ -35,51 +37,59 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class DmaapNotificationsComponent { - - private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); - - /** - * Get sdnr notifications. - */ - public Either<Notification, Integer> getSdnrNotifications() { - DmaapNotificationsRepository dmaapNotificationsRepository = BeanUtil - .getBean(DmaapNotificationsRepository.class); - String notificationString = dmaapNotificationsRepository.getNotificationFromQueue(); - if (notificationString == null) { - return Either.right(404); - } - ObjectMapper mapper = new ObjectMapper(); - Notification notification = new Notification(); - try { - notification = mapper.readValue(notificationString, Notification.class); - return Either.left(notification); - } catch (IOException e) { - log.error("Exception in parsing notification", notificationString, e); - return Either.right(400); - } - } - - /** - * Get pm notifications. - */ - public Either<PmNotification,Integer> getPmNotifications() { - PerformanceNotificationsRepository pmNotificationRepository = - BeanUtil.getBean(PerformanceNotificationsRepository.class); - String pmNotificationString = pmNotificationRepository.getPerformanceNotificationFromQueue(); - if (pmNotificationString == null) { - return Either.right(404); - } - ObjectMapper mapper = new ObjectMapper(); - PmNotification pmNotification = new PmNotification(); - - try { - pmNotification = mapper.readValue(pmNotificationString, PmNotification.class); - return Either.left(pmNotification); - } catch (IOException e) { - log.error("Exception in parsing pm notification ",pmNotificationString,e); - return Either.right(400); - } - } + private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); + + /** + * Get sdnr notifications. + */ + public Either<Notification, Integer> getSdnrNotifications() { + DmaapNotificationsRepository dmaapNotificationsRepository = BeanUtil + .getBean(DmaapNotificationsRepository.class); + String notificationString = dmaapNotificationsRepository.getNotificationFromQueue(); + if (notificationString == null) { + return Either.right(404); + } + ObjectMapper mapper = new ObjectMapper(); + + Notification notification = new Notification(); + try { + notification = mapper.readValue(notificationString, Notification.class); + return Either.left(notification); + } catch (IOException e) { + log.error("Exception in parsing notification", notificationString, e); + return Either.right(400); + } + } + + /** + * Get pm notifications. + */ + public Either<PmNotification, Integer> getPmNotifications() { + PerformanceNotificationsRepository pmNotificationRepository = BeanUtil + .getBean(PerformanceNotificationsRepository.class); + String pmNotificationString = pmNotificationRepository.getPerformanceNotificationFromQueue(); + if (pmNotificationString == null) { + return Either.right(404); + } + try { + JSONObject obj = new JSONObject(pmNotificationString); + Configuration configuration = Configuration.getInstance(); + String configNfNamingCode = configuration.getNfNamingCode(); + String nfNamingCode = obj.getJSONObject("event").getJSONObject("commonEventHeader") + .getString("nfNamingCode"); + if (!nfNamingCode.equalsIgnoreCase(configNfNamingCode)) { + return Either.right(404); + } + ObjectMapper mapper = new ObjectMapper(); + PmNotification pmNotification = new PmNotification(); + pmNotification = mapper.readValue(pmNotificationString, PmNotification.class); + return Either.left(pmNotification); + } catch (Exception e) { + log.error("Exception in parsing pm notification ", pmNotificationString, e); + return Either.right(400); + } + } } + diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponent.java index d1bf351..9f889da 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponent.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019 Wipro Limited. + * Copyright (C) 2019-2020 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.json.JSONObject; import org.onap.dcaegen2.services.sonhms.dao.FaultNotificationsRepository; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.slf4j.Logger; @@ -36,35 +37,40 @@ import org.slf4j.LoggerFactory; public class FaultNotificationComponent { - private static Logger log = LoggerFactory.getLogger(FaultNotificationComponent.class); + private static Logger log = LoggerFactory.getLogger(FaultNotificationComponent.class); - /** - * Get fault notifications. - */ - public Either<List<FaultEvent>, Integer> getFaultNotifications() { - FaultNotificationsRepository faultNotificationsRepository = BeanUtil - .getBean(FaultNotificationsRepository.class); - String notificationString = faultNotificationsRepository.getFaultNotificationFromQueue(); - log.info("get fault notifications method"); - if (notificationString == null) { - return Either.right(404); - } - ObjectMapper mapper = new ObjectMapper(); - FaultEvent faultEvent = new FaultEvent(); - List<FaultEvent> faultEvents = new ArrayList<>(); - try { - faultEvent = mapper.readValue(notificationString, FaultEvent.class); - log.info("Parsing FM notification"); - - } catch (IOException e) { - log.error("Exception in parsing Notification {}", e); - return Either.right(400); - } - - faultEvents.add(faultEvent); - - return Either.left(faultEvents); - - } + /** + * Get fault notifications. + */ + public Either<List<FaultEvent>, Integer> getFaultNotifications() { + FaultNotificationsRepository faultNotificationsRepository = BeanUtil + .getBean(FaultNotificationsRepository.class); + String notificationString = faultNotificationsRepository.getFaultNotificationFromQueue(); + log.info("get fault notifications method"); + if (notificationString == null) { + return Either.right(404); + } + try { + JSONObject obj = new JSONObject(notificationString); + Configuration configuration = Configuration.getInstance(); + String configNfNamingCode = configuration.getNfNamingCode(); + String nfNamingCode = obj.getJSONObject("event").getJSONObject("commonEventHeader") + .getString("nfNamingCode"); + if (!nfNamingCode.equalsIgnoreCase(configNfNamingCode)) { + return Either.right(404); + } + ObjectMapper mapper = new ObjectMapper(); + FaultEvent faultEvent = new FaultEvent(); + List<FaultEvent> faultEvents = new ArrayList<>(); + faultEvent = mapper.readValue(notificationString, FaultEvent.class); + log.info("Parsing FM notification"); + faultEvents.add(faultEvent); + return Either.left(faultEvents); + } catch (Exception e) { + log.error("Exception in parsing Notification {}", e); + return Either.right(400); + } + } } + diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotification.java index 16f7518..972b1f4 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotification.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotification.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019 Wipro Limited. + * Copyright (C) 2019-2020 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,7 +75,7 @@ public class PolicyNotification { this.version = "1.0.2"; this.action = action; this.target = "generic-vnf.vnf-id"; - this.targetType = "VNF"; + this.targetType = "PNF"; this.aai = new HashMap<>(); aai.put("generic-vnf.is-closed-loop-disabled", "false"); aai.put("generic-vnf.prov-status", "ACTIVE"); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java index 4b36b32..4a3fb42 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019 Wipro Limited. + * Copyright (C) 2019-2020 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; import org.onap.dcaegen2.services.sonhms.dao.PerformanceNotificationsRepository; import org.onap.dcaegen2.services.sonhms.model.Notification; @@ -51,29 +52,33 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({ BeanUtil.class }) +@PrepareForTest({ BeanUtil.class, Configuration.class }) @SpringBootTest(classes = DmaapNotificationsComponentTest.class) public class DmaapNotificationsComponentTest { @Mock DmaapNotificationsRepository dmaapNotificationsRepositoryMock; - + @Mock PerformanceNotificationsRepository performanceNotificationsRepositoryMock; + @Mock + Configuration configurationMock; + @InjectMocks DmaapNotificationsComponent component; static String notificationString; static String pmNotificationString; - + static String pmNotificationString2; @BeforeClass public static void setupTest() { notificationString = readFromFile("/notification1.json"); - pmNotificationString=readFromFile("/pmNotification.json"); + pmNotificationString = readFromFile("/pmNotification.json"); + pmNotificationString2 = readFromFile("/pmNotification2.json"); } @@ -84,38 +89,56 @@ public class DmaapNotificationsComponentTest { .thenReturn(dmaapNotificationsRepositoryMock); when(dmaapNotificationsRepositoryMock.getNotificationFromQueue()).thenReturn(notificationString); - Either<Notification, Integer> result = component.getSdnrNotifications(); - //assertTrue(result.isLeft()); + // assertTrue(result.isLeft()); assertNotNull(result.left().value()); - + when(dmaapNotificationsRepositoryMock.getNotificationFromQueue()).thenReturn("notification"); - result = component.getSdnrNotifications(); - int resultRight = result.right().value(); - assertEquals(400, resultRight); - + result = component.getSdnrNotifications(); + int resultRight = result.right().value(); + assertEquals(400, resultRight); + } - + @Test public void getPmNotificationsTest() { - PowerMockito.mockStatic(BeanUtil.class); - PowerMockito.when(BeanUtil.getBean(PerformanceNotificationsRepository.class)) - .thenReturn(performanceNotificationsRepositoryMock); - when(performanceNotificationsRepositoryMock.getPerformanceNotificationFromQueue()).thenReturn(pmNotificationString); - - Either<PmNotification,Integer> result = component.getPmNotifications(); - assertTrue(result.isLeft()); - assertNotNull(result.left().value()); - - when(performanceNotificationsRepositoryMock.getPerformanceNotificationFromQueue()).thenReturn("pmNotification"); - result = component.getPmNotifications(); - int res= result.right().value(); - assertEquals(400,res); - + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(PerformanceNotificationsRepository.class)) + .thenReturn(performanceNotificationsRepositoryMock); + when(performanceNotificationsRepositoryMock.getPerformanceNotificationFromQueue()) + .thenReturn(pmNotificationString); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configurationMock); + when(configurationMock.getNfNamingCode()).thenReturn("RansimAgent"); + Either<PmNotification, Integer> result = component.getPmNotifications(); + assertTrue(result.isLeft()); + assertNotNull(result.left().value()); + when(performanceNotificationsRepositoryMock.getPerformanceNotificationFromQueue()).thenReturn("pmNotification"); + result = component.getPmNotifications(); + int res = result.right().value(); + assertEquals(400, res); + + } + + @Test + public void getPmNotificationsORanNotifTest() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(PerformanceNotificationsRepository.class)) + .thenReturn(performanceNotificationsRepositoryMock); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configurationMock); + when(configurationMock.getNfNamingCode()).thenReturn("RansimAgent"); + when(performanceNotificationsRepositoryMock.getPerformanceNotificationFromQueue()) + .thenReturn(pmNotificationString2); + Either<PmNotification, Integer> result = component.getPmNotifications(); + result = component.getPmNotifications(); + int res = result.right().value(); + assertEquals(404, res); + } - private static String readFromFile(String file) { + private static String readFromFile(String file) { String content = new String(); try { @@ -135,3 +158,4 @@ public class DmaapNotificationsComponentTest { } } + diff --git a/src/test/resources/pmNotification2.json b/src/test/resources/pmNotification2.json new file mode 100644 index 0000000..b55f489 --- /dev/null +++ b/src/test/resources/pmNotification2.json @@ -0,0 +1,45 @@ + + { + "event":{ + "commonEventHeader":{ + "version":"4.0.1", + "domain":"measurement", + "eventName":"Measurement_RansimAgent-Wipro_HandoffMetric", + "eventId":"measurement000001", + "sequence":0, + "priority":"Normal", + "reportingEntityId":"cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName":"ncserver1", + "sourceId":"de305d54-75b4-431b-adb2-eb6b9e546456", + "sourceName":"Chn0002", + "startEpochMicrosec":1551772223000000, + "lastEpochMicrosec":1551790542000000, + "nfNamingCode":"SDN", + "nfVendorName":"Wipro", + "vesEventListenerVersion":"7.0.1", + "timeZoneOffset":"UTC-05:30" + }, + "measurementFields":{ + "measurementInterval":180, + "measurementFieldsVersion":"4.0", + "additionalMeasurements":[ + { + "hashMap":{ + "networkId":"plmnid1", + "InterEnbOutAtt_X2HO":"300", + "InterEnbOutSucc_X2HO":"100" + }, + "name":"Chn0004" + }, + { + "hashMap":{ + "networkId":"plmnid1", + "InterEnbOutAtt_X2HO":"250", + "InterEnbOutSucc_X2HO":"100" + }, + "name":"Chn0001" + } + ] + } + } +} diff --git a/src/test/resources/policy_notification.json b/src/test/resources/policy_notification.json index 35fe06c..767c024 100644 --- a/src/test/resources/policy_notification.json +++ b/src/test/resources/policy_notification.json @@ -3,7 +3,7 @@ "closedLoopAlarmStart": 1542445563201, "closedLoopEventClient": "microservice.PCI", "closedLoopEventStatus": "ONSET", - "target_type": "VNF", + "target_type": "PNF", "target": "generic-vnf.vnf-id", "requestID": "a4130fd5-2291-4a83-8992-04e4c9f32731", "from": "PCIMS", |