From: krishnaa96 Date: Fri, 12 Apr 2019 14:26:25 +0000 (+0530) Subject: Implement DMaaP message handling from policy X-Git-Tag: 1.0.1~2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=282711996763df7e081f3e41f42f8d475f14625c;hp=2896a24832902865313cd16081bba8b2d079748f;p=dcaegen2%2Fservices%2Fson-handler.git Implement DMaaP message handling from policy Handling of dmaap response from policy implemented Blueprint updated for config policy fetch Fix sonar issues Change-Id: I7a8a54b5d62e5db94ea2bc2d28805d8f5680d579 Issue-ID: DCAEGEN2-1427 Signed-off-by: krishnaa96 --- diff --git a/README.md b/README.md index 65e28af..721274c 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,8 @@ Variables coming from deployment system: - CBS_PROTOCOL - Config Binding Service protocol by default set to **http**, if it is need to change it then that can be set to different value - CONFIG_BINDING_SERVICE - used with conjunction with CBSPOLLTIMER, should be a name of CBS as it is registered in Consul - HOSTNAME - used with conjunction with CBSPOLLTIMER, should be a name of sonhms application as it is registered in CBS catalog - ### Release images -For R1 - image/version pushed to nexus3 +For R4 - image/version pushed to nexus3 ``` nexus3.onap.org:10001/snapshots/onap/org.onap.dcaegen2.services.son-handler 1.0.0 ``` @@ -33,6 +32,10 @@ son handler can be manually deployed in dcae environment using cloudify blueprin login to bootstrap container in dcae deployment +Copy the blueprints to the bootstrap container. + +The blueprint can be found under dpo/blueprints in the son-handler project. + To install : cfy install -b sonhms -d sonhms -i diff --git a/dpo/blueprints/k8s-sonhms-inputs.yaml b/dpo/blueprints/k8s-sonhms-inputs.yaml index 052f0b9..e417c01 100644 --- a/dpo/blueprints/k8s-sonhms-inputs.yaml +++ b/dpo/blueprints/k8s-sonhms-inputs.yaml @@ -36,9 +36,10 @@ buffer_time: 60 cg: sonhms-cg cid: sonhms-cid config_db: http://sdnc.onap:8181 -oof: http://oof-osdf.onap:8080 +oof: http://oof-osdf.onap:8699 pci_optimizer: pci log_path: /dockerdata-nfs/son-handler +policy_id: com.Config_PCIMS_CONFIG_POLICY.1.xml topic00_location: onap topic00_client_role: son-subscriber topic00_client_id: sdnr-son-1 @@ -55,3 +56,7 @@ topic03_location: onap topic03_client_role: son-subscriber topic03_client_id: sdnr-son-1 topic03_url: https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_OUTPUT +topic04_location: onap +topic04_client_role: son-subscriber +topic04_client_id: sdnr-son-1 +topic04_url: https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_RSP diff --git a/dpo/blueprints/k8s-sonhms.yaml b/dpo/blueprints/k8s-sonhms.yaml index 9d4e0db..d77f0fc 100644 --- a/dpo/blueprints/k8s-sonhms.yaml +++ b/dpo/blueprints/k8s-sonhms.yaml @@ -21,6 +21,7 @@ imports: - "http://www.getcloudify.org/spec/cloudify/3.4/types.yaml" - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/k8splugin/1.4.5/k8splugin_types.yaml - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.ccsdk.platform.plugins/type_files/pgaas/1.1.0/pgaas_types.yaml + - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/dcaepolicyplugin/2.3.0/dcaepolicyplugin_types.yaml inputs: replicas: type: integer @@ -77,7 +78,7 @@ inputs: description: threshold for poor neighbors default: 70 namespace: - type: String + type: string description: namespace default: onap dmaap: @@ -110,22 +111,30 @@ inputs: type: string description: log location in host default: /dockerdata-nfs/son-handler + policy_id: + type: string + description: policy id for config policy topic00_location: topic01_location: topic02_location: topic03_location: + topic04_location: topic00_client_role: topic01_client_role: topic02_client_role: topic03_client_role: + topic04_client_role: topic00_client_id: topic01_client_id: topic02_client_id: topic03_client_id: + topic04_client_id: topic00_url: topic01_url: topic02_url: topic03_url: + topic04_url: + node_templates: pgaasvm: @@ -191,6 +200,15 @@ node_templates: client_id: { get_input: topic02_client_id } topic_url: { get_input: topic02_url } type: message-router + dcae_cl_response_topic: + aaf_username: { get_input: aaf_username } + aaf_password: { get_input: aaf_password } + dmaap_info: + location: { get_input: topic04_location } + client_role: { get_input: topic04_client_role } + client_id: { get_input: topic04_client_id } + topic_url: { get_input: topic04_url } + type: message-router streams_publishes: CL_topic: aaf_username: { get_input: aaf_username } @@ -234,7 +252,15 @@ node_templates: relationships: - type: cloudify.relationships.depends_on target: pgaasvm - + - type: cloudify.relationships.depends_on + target: son_policy + + son_policy: + type: dcae.nodes.policy + properties: + policy_id: + get_input: policy_id + diff --git a/dpo/data-formats/dmaap_son.json b/dpo/data-formats/dmaap_son.json index 7e4a950..af5fc83 100644 --- a/dpo/data-formats/dmaap_son.json +++ b/dpo/data-formats/dmaap_son.json @@ -42,5 +42,16 @@ "location": "onap", "topic_url": "https://HOSTNAME:3905/events/DCAE_CL_OUTPUT" } - } + }, + "CL_RSP_topic": { + "type": "message_router", + "aaf_username": "", + "aaf_password": "", + "dmaap_info": { + "client_role": "son-subscriber", + "client_id": "policy-son-1", + "location": "onap", + "topic_url": "https://HOSTNAME:3905/events/DCAE_CL_RSP" + } + } } diff --git a/dpo/data-formats/oofToSonAsyncResp-dataformat.json b/dpo/data-formats/oofToSonAsyncResp-dataformat.json index bf99528..4eb8f5a 100644 --- a/dpo/data-formats/oofToSonAsyncResp-dataformat.json +++ b/dpo/data-formats/oofToSonAsyncResp-dataformat.json @@ -1,91 +1,105 @@ { - "dataformatversion": "1.0.0", - "jsonschema": { - "$schema": "http://json-schema.org/draft-04/schema#", - "additionalproperties": true, - "description": "", - "properties": { - "requestId": { - "description": "", - "type": "string" - }, - "requestStatus": { - "description": "", - "type": "string" - }, - "solutions": { - "description": "", - "items": { - "additionalproperties": true, - "description": "", - "properties": { - "finishTime": { - "description": "", - "type": "string" - }, - "networkId": { - "description": "", - "type": "string" - }, - "pciSolutions": { - "description": "", - "items": { - "additionalproperties": true, - "description": "", - "properties": { - "cellId": { - "description": "", - "type": "string" - }, - "pci": { - "description": "", - "type": "string" - } - }, - "required": [ - "cellId", - "pci" - ], - "type": "object" - }, - "type": "array" - }, - "startTime": { - "description": "", - "type": "string" - } - }, - "required": [ - "finishTime", - "networkId", - "pciSolutions", - "startTime" - ], - "type": "object" - }, - "type": "array" - }, - "statusMessage": { - "description": "", - "type": "string" - }, - "transactionId": { - "description": "", - "type": "string" - } - }, - "required": [ - "requestId", - "requestStatus", - "solutions", - "statusMessage", - "transactionId" - ], - "type": "object" - }, - "self": { - "description": "", - "name": "SON_OOF_ASYNC_RESP", - "version": "1.0.0" - } + "dataformatversion": "1.0.0", + "jsonschema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "additionalproperties": true, + "description": "", + "properties": { + "requestId": { + "description": "", + "type": "string" + }, + "requestStatus": { + "description": "", + "type": "string" + }, + "solutions": { + "additionalproperties": true, + "description": "", + "properties": { + "anrSolutions": { + "description": "", + "items": { + "additionalproperties": true, + "description": "", + "properties": { + "cellId": { + "description": "", + "type": "string" + }, + "removeableNeighbors": { + "description": "", + "items": { + "description": "", + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "cellId", + "removeableNeighbors" + ], + "type": "object" + }, + "type": "array" + }, + "networkId": { + "description": "", + "type": "string" + }, + "pciSolutions": { + "description": "", + "items": { + "additionalproperties": true, + "description": "", + "properties": { + "cellId": { + "description": "", + "type": "string" + }, + "pci": { + "description": "", + "type": "string" + } + }, + "required": [ + "cellId", + "pci" + ], + "type": "object" + }, + "type": "array" + } + }, + "required": [ + "anrSolutions", + "networkId", + "pciSolutions" + ], + "type": "object" + }, + "statusMessage": { + "description": "", + "type": "string" + }, + "transactionId": { + "description": "", + "type": "string" + } + }, + "required": [ + "requestId", + "requestStatus", + "solutions", + "statusMessage", + "transactionId" + ], + "type": "object" + }, + "self": { + "description": "", + "name": "SON_OOF_ASYNC_RESP", + "version": "1.0.0" + } } diff --git a/dpo/data-formats/policyToSonDmaap-dataformat.json b/dpo/data-formats/policyToSonDmaap-dataformat.json new file mode 100644 index 0000000..28588a1 --- /dev/null +++ b/dpo/data-formats/policyToSonDmaap-dataformat.json @@ -0,0 +1,58 @@ +{ + "dataformatversion": "1.0.0", + "jsonschema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "additionalproperties": true, + "description": "", + "properties": { + "closedLoopControlName": { + "description": "", + "type": "string" + }, + "from": { + "description": "", + "type": "string" + }, + "payload": { + "description": "", + "type": "string" + }, + "policyName": { + "description": "", + "type": "string" + }, + "policyVersion": { + "description": "", + "type": "string" + }, + "requestID": { + "description": "", + "type": "string" + }, + "target": { + "description": "", + "type": "string" + }, + "version": { + "description": "", + "type": "string" + } + }, + "required": [ + "closedLoopControlName", + "from", + "payload", + "policyName", + "policyVersion", + "requestID", + "target", + "version" + ], + "type": "object" + }, + "self": { + "description": "", + "name": "POLICY_TO_SON_DMAAP", + "version": "1.0.0" + } +} diff --git a/dpo/data-formats/sonToOofReq-dataformat.json b/dpo/data-formats/sonToOofReq-dataformat.json index e686dd1..d91edae 100644 --- a/dpo/data-formats/sonToOofReq-dataformat.json +++ b/dpo/data-formats/sonToOofReq-dataformat.json @@ -1,97 +1,144 @@ { - "dataformatversion": "1.0.0", - "jsonschema": { - "$schema": "http://json-schema.org/draft-04/schema#", - "additionalproperties": true, - "description": "", - "properties": { - "cellInfo": { - "additionalproperties": true, - "description": "", - "properties": { - "cellIdList": { - "description": "", - "items": { - "description": "", - "type": "string" - }, - "type": "array" - }, - "networkId": { - "description": "", - "type": "string" - } - }, - "required": [ - "cellIdList", - "networkId" - ], - "type": "object" - }, - "requestInfo": { - "additionalproperties": true, - "description": "", - "properties": { - "callbackUrl": { - "description": "", - "type": "string" - }, - "numSolutions": { - "description": "", - "type": "integer" - }, - "optimizers": { - "description": "", - "items": { - "description": "", - "type": "string" - }, - "type": "array" - }, - "requestId": { - "description": "", - "type": "string" - }, - "requestType": { - "description": "", - "type": "string" - }, - "sourceId": { - "description": "", - "type": "string" - }, - "timeout": { - "description": "", - "type": "integer" - }, - "transactionId": { - "description": "", - "type": "string" - } - }, - "required": [ - "callbackUrl", - "numSolutions", - "optimizers", - "requestId", - "requestType", - "sourceId", - "timeout", - "transactionId" - ], - "type": "object" - } - }, - "required": [ - "cellInfo", - "requestInfo" - ], - "type": "object" - }, - "self": { - "description": "", - "name": "SON_TO_OOF_REST_REQ", - "version": "1.0.0" - } + "dataformatversion": "1.0.0", + "jsonschema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "additionalproperties": true, + "description": "", + "properties": { + "cellInfo": { + "additionalproperties": true, + "description": "", + "properties": { + "anrInputList": { + "description": "", + "items": { + "additionalproperties": true, + "description": "", + "properties": { + "cellId": { + "description": "", + "type": "string" + }, + "removeableNeighbors": { + "description": "", + "items": { + "description": "", + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "cellId", + "removeableNeighbors" + ], + "type": "object" + }, + "type": "array" + }, + "cellIdList": { + "description": "", + "items": { + "description": "", + "type": "string" + }, + "type": "array" + }, + "networkId": { + "description": "", + "type": "integer" + }, + "trigger": { + "description": "", + "type": "string" + } + }, + "required": [ + "anrInputList", + "cellIdList", + "networkId", + "trigger" + ], + "type": "object" + }, + "requestInfo": { + "additionalproperties": true, + "description": "", + "properties": { + "callbackHeader": { + "additionalproperties": true, + "description": "", + "properties": { + "blob": { + "description": "", + "type": "string" + } + }, + "required": [ + "blob" + ], + "type": "object" + }, + "callbackUrl": { + "description": "", + "type": "string" + }, + "numSolutions": { + "description": "", + "type": "integer" + }, + "optimizers": { + "description": "", + "items": { + "description": "", + "type": "string" + }, + "type": "array" + }, + "requestId": { + "description": "", + "type": "string" + }, + "requestType": { + "description": "", + "type": "string" + }, + "sourceId": { + "description": "", + "type": "string" + }, + "timeout": { + "description": "", + "type": "integer" + }, + "transactionId": { + "description": "", + "type": "string" + } + }, + "required": [ + "callbackHeader", + "callbackUrl", + "numSolutions", + "optimizers", + "requestId", + "requestType", + "sourceId", + "timeout", + "transactionId" + ], + "type": "object" + } + }, + "required": [ + "cellInfo", + "requestInfo" + ], + "type": "object" + }, + "self": { + "description": "", + "name": "SON_TO_OOF_REST_REQ", + "version": "1.0.0" + } } - diff --git a/dpo/spec/sonhandler-componentspec.json b/dpo/spec/sonhandler-componentspec.json index 6fc51be..2d23fb8 100644 --- a/dpo/spec/sonhandler-componentspec.json +++ b/dpo/spec/sonhandler-componentspec.json @@ -30,7 +30,13 @@ "version": "1.0.0", "route": "/callbackUrl", "type": "http" - } + }, + { + "format": "POLICY_TO_SON_DMAAP", + "version": "1.0.0", + "config_key": "CL_RSP_topic", + "type": "message router" + } ], "publishes": [ { @@ -267,9 +273,9 @@ "designer_editable": false }, { - "name": "sonhandler.callbackUrl", - "value": "http://sonhms.onap:8080/callbackUrl", - "description": "sonhms callback url", + "name": "sonhandler.namespace", + "value": "onap", + "description": "namespace where MS will be deployed", "sourced_at_deployment": false, "policy_editable": false, "designer_editable": false diff --git a/pom.xml b/pom.xml index f87e777..e12462e 100644 --- a/pom.xml +++ b/pom.xml @@ -122,14 +122,6 @@ 1.4.0.RELEASE - - - - - org.codehaus.jackson - jackson-mapper-asl - 1.9.13 - org.hibernate.javax.persistence hibernate-jpa-2.0-api 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 39cfbd1..a5d8ba7 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java @@ -29,7 +29,7 @@ import java.io.IOException; import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; import org.onap.dcaegen2.services.sonhms.dao.PerformanceNotificationsRepository; import org.onap.dcaegen2.services.sonhms.model.Notification; -import org.onap.dcaegen2.services.sonhms.model.PMNotification; +import org.onap.dcaegen2.services.sonhms.model.PmNotification; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +39,7 @@ public class DmaapNotificationsComponent { private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); /** - * Get sdnr notifications + * Get sdnr notifications. */ public Either getSdnrNotifications() { DmaapNotificationsRepository dmaapNotificationsRepository = BeanUtil @@ -61,21 +61,22 @@ public class DmaapNotificationsComponent { } /** - * Get pm notifications + * Get pm notifications. */ - public Either getPmNotifications(){ - PerformanceNotificationsRepository pmNotificationRepository = BeanUtil.getBean(PerformanceNotificationsRepository.class); + public Either 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(); + PmNotification pmNotification = new PmNotification(); try { - pmNotification = mapper.readValue(pmNotificationString, PMNotification.class); + pmNotification = mapper.readValue(pmNotificationString, PmNotification.class); return Either.left(pmNotification); - } catch(IOException e) { + } catch (IOException 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/Event.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Event.java index 84b8eee..3a71f2b 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/Event.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Event.java @@ -18,27 +18,32 @@ * ============LICENSE_END========================================================= * *******************************************************************************/ + package org.onap.dcaegen2.services.sonhms; public class Event { - private CommonEventHeader commonEventHeader; - private FaultFields faultFields; - public CommonEventHeader getCommonEventHeader() { - return commonEventHeader; - } - public void setCommonEventHeader(CommonEventHeader commonEventHeader) { - this.commonEventHeader = commonEventHeader; - } - public FaultFields getFaultFields() { - return faultFields; - } - public void setFaultFields(FaultFields faultFields) { - this.faultFields = faultFields; - } + private CommonEventHeader commonEventHeader; + private FaultFields faultFields; + + public CommonEventHeader getCommonEventHeader() { + return commonEventHeader; + } + + public void setCommonEventHeader(CommonEventHeader commonEventHeader) { + this.commonEventHeader = commonEventHeader; + } + + public FaultFields getFaultFields() { + return faultFields; + } + + public void setFaultFields(FaultFields faultFields) { + this.faultFields = faultFields; + } + @Override public String toString() { return "Event [commonEventHeader=" + commonEventHeader + ", faultFields=" + faultFields + "]"; } - - + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java index bcd9e92..c96cbc8 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java @@ -106,7 +106,8 @@ public class EventHandler { faultNotificationtoClusterMapping.setCollisionConfusionMap(collisionConfusionMap); // matching cells - if (faultNotificationtoClusterMapping.getCellsinCluster() != null && !faultNotificationtoClusterMapping.getCellsinCluster().isEmpty()) { + if (faultNotificationtoClusterMapping.getCellsinCluster() != null + && !faultNotificationtoClusterMapping.getCellsinCluster().isEmpty()) { try { handleMatchedFmCells(faultNotificationtoClusterMapping, clusterDetails); } catch (ConfigDbNotFoundException e) { @@ -115,7 +116,8 @@ public class EventHandler { } // unmatched new cells - if (faultNotificationtoClusterMapping.getNewCells() != null && !faultNotificationtoClusterMapping.getNewCells().isEmpty()) { + if (faultNotificationtoClusterMapping.getNewCells() != null + && !faultNotificationtoClusterMapping.getNewCells().isEmpty()) { handleUnmatchedFmCells(faultNotificationtoClusterMapping, networkId); } @@ -161,8 +163,6 @@ public class EventHandler { /** * handle unmatched fm cells. * - * @param networkId2 - * @param faultNotificationtoClusterMapping */ private void handleUnmatchedFmCells(FaultNotificationtoClusterMapping faultNotificationtoClusterMapping, String networkId) { @@ -175,7 +175,7 @@ public class EventHandler { .get(cellId); log.info("Handle Unmatching cells for FM notificatins,collisionConfusionCount{}", collisionConfusionCount); - Either existingCluster = clusterUtils.getClusterForFMCell(cellId, newClusters); + Either existingCluster = clusterUtils.getClusterForFmCell(cellId, newClusters); if (existingCluster.isRight()) { try { Map> clusterMap = clusterUtils.findClusterMap(cellId); diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultFields.java b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultFields.java index c1649b2..a2c877d 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultFields.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultFields.java @@ -23,7 +23,7 @@ package org.onap.dcaegen2.services.sonhms; public class FaultFields { - @Override + @Override public String toString() { return "FaultFields [faultFieldsVersion=" + faultFieldsVersion + ", alarmCondition=" + alarmCondition + ", eventSourceType=" + eventSourceType + ", specificProblem=" + specificProblem + ", eventSeverity=" @@ -32,13 +32,12 @@ public class FaultFields { } private double faultFieldsVersion; - private String alarmCondition; - private String eventSourceType; - private String specificProblem; - private String eventSeverity; - private String vfStatus; - private AlarmAdditionalInformation alarmAdditionalInformation; - + private String alarmCondition; + private String eventSourceType; + private String specificProblem; + private String eventSeverity; + private String vfStatus; + private AlarmAdditionalInformation alarmAdditionalInformation; public AlarmAdditionalInformation getAlarmAdditionalInformation() { return alarmAdditionalInformation; @@ -49,51 +48,51 @@ public class FaultFields { } public double getFaultFieldsVersion() { - return faultFieldsVersion; - } + return faultFieldsVersion; + } - public void setFaultFieldsVersion(double faultFieldsVersion) { - this.faultFieldsVersion = faultFieldsVersion; - } + public void setFaultFieldsVersion(double faultFieldsVersion) { + this.faultFieldsVersion = faultFieldsVersion; + } - public String getAlarmCondition() { - return alarmCondition; - } + public String getAlarmCondition() { + return alarmCondition; + } - public void setAlarmCondition(String alarmCondition) { - this.alarmCondition = alarmCondition; - } + public void setAlarmCondition(String alarmCondition) { + this.alarmCondition = alarmCondition; + } - public String getEventSourceType() { - return eventSourceType; - } + public String getEventSourceType() { + return eventSourceType; + } - public void setEventSourceType(String eventSourceType) { - this.eventSourceType = eventSourceType; - } + public void setEventSourceType(String eventSourceType) { + this.eventSourceType = eventSourceType; + } - public String getSpecificProblem() { - return specificProblem; - } + public String getSpecificProblem() { + return specificProblem; + } - public void setSpecificProblem(String specificProblem) { - this.specificProblem = specificProblem; - } + public void setSpecificProblem(String specificProblem) { + this.specificProblem = specificProblem; + } - public String getEventSeverity() { - return eventSeverity; - } + public String getEventSeverity() { + return eventSeverity; + } - public void setEventSeverity(String eventSeverity) { - this.eventSeverity = eventSeverity; - } + public void setEventSeverity(String eventSeverity) { + this.eventSeverity = eventSeverity; + } - public String getVfStatus() { - return vfStatus; - } + public String getVfStatus() { + return vfStatus; + } - public void setVfStatus(String vfStatus) { - this.vfStatus = vfStatus; - } + public void setVfStatus(String vfStatus) { + this.vfStatus = vfStatus; + } } 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 99695ab..d1bf351 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponent.java @@ -36,35 +36,35 @@ 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,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 faultEvents = new ArrayList<>(); - try { - faultEvent = mapper.readValue(notificationString,FaultEvent.class); + /** + * Get fault notifications. + */ + public Either, 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 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); - } + faultEvents.add(faultEvent); + + return Either.left(faultEvents); + + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationtoClusterMapping.java b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationtoClusterMapping.java index 5e59467..1ac6715 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationtoClusterMapping.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationtoClusterMapping.java @@ -27,26 +27,26 @@ import java.util.Map; public class FaultNotificationtoClusterMapping { public Map getCellsinCluster() { - return cellsinCluster; - } + return cellsinCluster; + } + + public void setCellsinCluster(Map cellsinCluster) { + this.cellsinCluster = cellsinCluster; + } - public void setCellsinCluster(Map cellsinCluster) { - this.cellsinCluster = cellsinCluster; - } + public List getNewCells() { + return newCells; + } - public List getNewCells() { - return newCells; - } + public void setNewCells(List newCells) { + this.newCells = newCells; + } - public void setNewCells(List newCells) { - this.newCells = newCells; - } - - private Map> collisionConfusionMap; + private Map> collisionConfusionMap; - //map that returns cellid and its matching cluster id + // map that returns cellid and its matching cluster id - public Map> getCollisionConfusionMap() { + public Map> getCollisionConfusionMap() { return collisionConfusionMap; } @@ -55,7 +55,7 @@ public class FaultNotificationtoClusterMapping { } private Map cellsinCluster; - - //cells that dont match + + // cells that dont match private List newCells; } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponent.java index d27227f..cf1cf45 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponent.java @@ -57,7 +57,8 @@ public class HoMetricsComponent { log.error("Exception in parsing HO metrics", hoDetailsString, e); return Either.right(400); } - } else + } else { return Either.right(404); + } } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java index 6cbb711..43c8e3d 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java @@ -55,7 +55,7 @@ public class MainThread implements Runnable { private EventHandler eventHandler; - private Map bufferedFMNotificationCells; + private Map bufferedFmNotificationCells; private List sdnrNotificationCells; @@ -77,7 +77,7 @@ public class MainThread implements Runnable { faultNotificationComponent = new FaultNotificationComponent(); sdnrNotificationCells = new ArrayList<>(); fmNotificationToBuffer = new ArrayList<>(); - bufferedFMNotificationCells = new HashMap<>(); + bufferedFmNotificationCells = new HashMap<>(); eventHandler = new EventHandler(childStatusQueue, Executors.newFixedThreadPool(Configuration.getInstance().getMaximumClusters()), new HashMap<>(), new ClusterUtils(), new ThreadUtils()); @@ -101,15 +101,14 @@ public class MainThread implements Runnable { if (difference > 5000) { log.info("FM handling difference > 5000"); - for (String sdnrCell: sdnrNotificationCells) { - bufferedFMNotificationCells.remove(sdnrCell); + for (String sdnrCell : sdnrNotificationCells) { + bufferedFmNotificationCells.remove(sdnrCell); } - - log.info("FM bufferedFMNotificationCells {}", bufferedFMNotificationCells.values()); - List fmNotificationsToHandle = new ArrayList<>( - bufferedFMNotificationCells.values()); + + log.info("FM bufferedFMNotificationCells {}", bufferedFmNotificationCells.values()); + List fmNotificationsToHandle = new ArrayList<>(bufferedFmNotificationCells.values()); Boolean result = eventHandler.handleFaultNotification(fmNotificationsToHandle); - bufferedFMNotificationCells = new HashMap<>(); + bufferedFmNotificationCells = new HashMap<>(); isTimer = false; log.info("FM notification handling {}", result); } @@ -160,21 +159,21 @@ public class MainThread implements Runnable { } else { for (FaultEvent fmNotification : fmNotifications.left().value()) { faultCellId = fmNotification.getEvent().getCommonEventHeader().getSourceName(); - bufferedFMNotificationCells.put(faultCellId, fmNotification); + bufferedFmNotificationCells.put(faultCellId, fmNotification); log.info("Buffered FM cell {}", faultCellId); log.info("fmNotification{}", fmNotification); } log.info("bufferedFMNotificationCells before staring timer {}", - bufferedFMNotificationCells.keySet()); + bufferedFmNotificationCells.keySet()); - for (String sdnrCell: sdnrNotificationCells) { - bufferedFMNotificationCells.remove(sdnrCell); + for (String sdnrCell : sdnrNotificationCells) { + bufferedFmNotificationCells.remove(sdnrCell); } - + startTimer = new Timestamp(System.currentTimeMillis()); isTimer = true; - log.info("Buffered FM cell {}", bufferedFMNotificationCells.keySet()); + log.info("Buffered FM cell {}", bufferedFmNotificationCells.keySet()); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/NewPmNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/NewPmNotification.java index ce583dd..374e615 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/NewPmNotification.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/NewPmNotification.java @@ -27,29 +27,29 @@ import org.springframework.stereotype.Component; @Component public class NewPmNotification { - + private Boolean newNotif; - + @PostConstruct public void init() { - newNotif=false; + newNotif = false; } public Boolean getNewNotif() { - return newNotif; - } + return newNotif; + } public void setNewNotif(Boolean newNotif) { - this.newNotif = newNotif; + this.newNotif = newNotif; } - public NewPmNotification(Boolean newNotif) { + public NewPmNotification(Boolean newNotif) { super(); this.newNotif = newNotif; } - + public NewPmNotification() { - + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java b/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java index 0df0bdb..e2223d7 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java @@ -43,16 +43,17 @@ import org.onap.dcaegen2.services.sonhms.model.HoDetails; import org.onap.dcaegen2.services.sonhms.model.Lte; import org.onap.dcaegen2.services.sonhms.model.LteCell; import org.onap.dcaegen2.services.sonhms.model.NeighborListInUse; -import org.onap.dcaegen2.services.sonhms.model.PMNotification; import org.onap.dcaegen2.services.sonhms.model.Payload; +import org.onap.dcaegen2.services.sonhms.model.PmNotification; import org.onap.dcaegen2.services.sonhms.model.Ran; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class PmNotificationHandler { - private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); + private static Logger log = LoggerFactory.getLogger(PmNotificationHandler.class); PolicyDmaapClient policyDmaapClient; public PmNotificationHandler() { @@ -66,7 +67,7 @@ public class PmNotificationHandler { /** * handle PM notifications. */ - public Boolean handlePmNotifications(PMNotification pmNotification, int badThreshold) { + public Boolean handlePmNotifications(PmNotification pmNotification, int badThreshold) { HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); Boolean result; try { @@ -75,10 +76,8 @@ public class PmNotificationHandler { String srcCellId = pmNotification.getEvent().getCommonEventHeader().getSourceName(); for (AdditionalMeasurements additionalMeasurements : pmNotification.getEvent().getMeasurementFields() .getAdditionalMeasurements()) { - int attemptsCount = Integer - .parseInt(additionalMeasurements.getHashMap().get("InterEnbOutAtt_X2HO")); - int successCount = Integer - .parseInt(additionalMeasurements.getHashMap().get("InterEnbOutSucc_X2HO")); + int attemptsCount = Integer.parseInt(additionalMeasurements.getHashMap().get("InterEnbOutAtt_X2HO")); + int successCount = Integer.parseInt(additionalMeasurements.getHashMap().get("InterEnbOutSucc_X2HO")); float successRate = ((float) successCount / attemptsCount) * 100; if (successRate >= badThreshold) { HoDetails hoDetails = new HoDetails(); @@ -101,7 +100,7 @@ public class PmNotificationHandler { if (!lteCellList.isEmpty()) { log.info("triggering policy to remove bad neighbors"); Flag policyTriggerFlag = BeanUtil.getBean(Flag.class); - + while (policyTriggerFlag.getHolder().equals("CHILD")) { Thread.sleep(100); } @@ -138,27 +137,34 @@ public class PmNotificationHandler { } - private Boolean sendAnrUpdateToPolicy(PMNotification pmNotification, List lteCellList) { + private Boolean sendAnrUpdateToPolicy(PmNotification pmNotification, List lteCellList) { ObjectMapper mapper = new ObjectMapper(); try { mapper.setSerializationInclusion(Include.NON_NULL); ArrayList configurations = new ArrayList<>(); String cellId = pmNotification.getEvent().getCommonEventHeader().getSourceName(); Configurations configuration = new Configurations( - new Data(new FapService(cellId, null, new CellConfig(new Lte(new Ran(new Common(cellId), - new NeighborListInUse(null, lteCellList, String.valueOf(lteCellList.size())))))))); + new Data(new FapService(cellId, null, + new CellConfig(new Lte(new Ran(new Common(cellId), + new NeighborListInUse(null, lteCellList, String.valueOf(lteCellList.size()))))))), + null); configurations.add(configuration); Payload payload = new Payload(configurations); log.info("payload : {}", payload); String anrUpdateString = mapper.writeValueAsString(payload); ChildThreadUtils childUtils = new ChildThreadUtils(ConfigPolicy.getInstance(), new PnfUtils(), - new PolicyDmaapClient()); - String notification = childUtils.getNotificationString(pmNotification.getEvent().getCommonEventHeader().getReportingEntityName(), UUID.randomUUID().toString(), anrUpdateString, - System.currentTimeMillis(), "ModifyConfigANR"); + new PolicyDmaapClient(new DmaapUtils(), Configuration.getInstance())); + String requestId = UUID.randomUUID().toString(); + String notification = childUtils.getNotificationString( + pmNotification.getEvent().getCommonEventHeader().getReportingEntityName(), requestId, + anrUpdateString, System.currentTimeMillis(), "ModifyConfigANR"); log.info("Policy Notification: {}", notification); Boolean result = policyDmaapClient.sendNotificationToPolicy(notification); log.info("send notification to policy result {} ", result); - + // getting policy response + policyDmaapClient.handlePolicyResponse(requestId); + log.info("handled policy response"); + } catch (Exception e) { log.error("Exception in sending Anr update to policy ", e); return false; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/PmThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/PmThread.java index d2d509f..49f0c56 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/PmThread.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/PmThread.java @@ -24,7 +24,8 @@ package org.onap.dcaegen2.services.sonhms; import fj.data.Either; import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; -import org.onap.dcaegen2.services.sonhms.model.PMNotification; +import org.onap.dcaegen2.services.sonhms.model.PmNotification; +import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +47,8 @@ public class PmThread implements Runnable { super(); this.newPmNotification = newPmNotification; dmaapNotificationsComponent = new DmaapNotificationsComponent(); - pmNotificationHandler = new PmNotificationHandler(new PolicyDmaapClient()); + pmNotificationHandler = new PmNotificationHandler(new PolicyDmaapClient(new DmaapUtils(), + Configuration.getInstance())); } @Override @@ -59,7 +61,7 @@ public class PmThread implements Runnable { Thread.sleep(1000); if (newPmNotification.getNewNotif()) { log.info("New PM notification from Dmaap"); - Either pmNotification = dmaapNotificationsComponent.getPmNotifications(); + Either pmNotification = dmaapNotificationsComponent.getPmNotifications(); if (pmNotification.isRight()) { if (pmNotification.right().value() == 400) { log.error("error parsing pm notifications"); diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java index 15a2881..b053467 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java @@ -55,6 +55,7 @@ import org.onap.dcaegen2.services.sonhms.model.ThreadId; import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; +import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils; import org.slf4j.Logger; import org.slf4j.MDC; @@ -149,7 +150,7 @@ public class ChildThread implements Runnable { ClusterUtils clusterUtils = new ClusterUtils(); Detection detect = new Detection(); ChildThreadUtils childUtils = new ChildThreadUtils(ConfigPolicy.getInstance(), new PnfUtils(), - new PolicyDmaapClient()); + new PolicyDmaapClient(new DmaapUtils(), Configuration.getInstance())); try { String networkId = cluster.getNetworkId(); @@ -167,9 +168,9 @@ public class ChildThread implements Runnable { Boolean trigger = childUtils.triggerOrWait(collisionConfusionResult); ConfigPolicy configPolicy = ConfigPolicy.getInstance(); - int timer = 60; + double timer = 60; try { - timer = (int) configPolicy.getConfig().get("PCI_NEIGHBOR_CHANGE_CLUSTER_TIMEOUT_IN_SECS"); + timer = (double) configPolicy.getConfig().get("PCI_NEIGHBOR_CHANGE_CLUSTER_TIMEOUT_IN_SECS"); } catch (NullPointerException e) { log.info("Policy config not available. Using default timeout - 60 seconds"); } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java index 1acfde6..183de84 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java @@ -111,9 +111,9 @@ public class ChildThreadUtils { * get policy notification string from oof result. * */ - public String getNotificationString(String pnfName, String requestId, String payloadString, - Long alarmStartTime, String action) { - + public String getNotificationString(String pnfName, String requestId, String payloadString, Long alarmStartTime, + String action) { + String closedLoopControlName = "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459"; try { closedLoopControlName = (String) configPolicy.getConfig().get("PCI_MODCONFIG_POLICY_NAME"); @@ -127,6 +127,7 @@ public class ChildThreadUtils { policyNotification.setClosedLoopControlName(closedLoopControlName); policyNotification.setPayload(payloadString); ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); String notification = ""; try { @@ -161,7 +162,8 @@ public class ChildThreadUtils { String cellId = cellPciPair.getCellId(); int pci = cellPciPair.getPhysicalCellId(); Configurations configuration = new Configurations(new Data(new FapService(cellId, - new X0005b9Lte(pci, pnfName), new CellConfig(new Lte(new Ran(new Common(cellId), null)))))); + new X0005b9Lte(pci, pnfName), new CellConfig(new Lte(new Ran(new Common(cellId), null))))), + null); configurations.add(configuration); } @@ -175,7 +177,9 @@ public class ChildThreadUtils { log.debug("JSON processing exception: {}", e); } - String notification = getNotificationString(pnfName, UUID.randomUUID().toString(), payloadString, + String requestId = UUID.randomUUID().toString(); + + String notification = getNotificationString(pnfName, requestId, payloadString, System.currentTimeMillis(), "ModifyConfig"); log.info("Policy Notification: {}", notification); boolean status = policyDmaapClient.sendNotificationToPolicy(notification); @@ -185,34 +189,37 @@ public class ChildThreadUtils { } else { log.debug("Sending notification to policy failed"); } + policyDmaapClient.handlePolicyResponse(requestId); + log.info("handled policy response in ModifyConfig"); } } if (!solutions.getAnrSolutions().isEmpty()) { - Map>>> anrPnfs; + Map>>> anrPnfs; List configurations = new ArrayList<>(); anrPnfs = pnfUtils.getPnfsForAnrSolutions(solutions.getAnrSolutions()); - for(Map.Entry>>> entry : anrPnfs.entrySet()) { + for (Map.Entry>>> entry : anrPnfs.entrySet()) { String pnfName = entry.getKey(); - for(Map> cellRemNeighborsPair : anrPnfs.get(pnfName)) { - for(Map.Entry> entry1 : cellRemNeighborsPair.entrySet()) { - String cellId = entry1.getKey(); - List lteCellList = new ArrayList<>(); - for(String removeableNeighbor : entry1.getValue()) { - LteCell lteCell = new LteCell(); - lteCell.setBlacklisted("true"); - lteCell.setPlmnId(solutions.getNetworkId()); - lteCell.setCid(removeableNeighbor); - int pci = SdnrRestClient.getPci(cellId); - lteCell.setPhyCellId(pci); - lteCell.setPnfName(pnfName); - lteCellList.add(lteCell); - } - Configurations configuration = new Configurations( - new Data(new FapService(cellId, null, new CellConfig(new Lte(new Ran(new Common(cellId), - new NeighborListInUse(null, lteCellList, String.valueOf(lteCellList.size())))))))); - configurations.add(configuration); - } + for (Map> cellRemNeighborsPair : anrPnfs.get(pnfName)) { + for (Map.Entry> entry1 : cellRemNeighborsPair.entrySet()) { + String cellId = entry1.getKey(); + List lteCellList = new ArrayList<>(); + for (String removeableNeighbor : entry1.getValue()) { + LteCell lteCell = new LteCell(); + lteCell.setBlacklisted("true"); + lteCell.setPlmnId(solutions.getNetworkId()); + lteCell.setCid(removeableNeighbor); + int pci = SdnrRestClient.getPci(cellId); + lteCell.setPhyCellId(pci); + lteCell.setPnfName(pnfName); + lteCellList.add(lteCell); + } + Configurations configuration = new Configurations(new Data(new FapService(cellId, null, + new CellConfig(new Lte(new Ran(new Common(cellId), new NeighborListInUse(null, + lteCellList, String.valueOf(lteCellList.size()))))))), + null); + configurations.add(configuration); + } } Payload payload = new Payload(configurations); ObjectMapper mapper = new ObjectMapper(); @@ -223,13 +230,17 @@ public class ChildThreadUtils { } catch (JsonProcessingException e) { log.error("Exception in writing anrupdate string", e); } - String notification = getNotificationString(pnfName, UUID.randomUUID().toString(), payloadString, + String requestId = UUID.randomUUID().toString(); + String notification = getNotificationString(pnfName, requestId, payloadString, System.currentTimeMillis(), "ModifyConfigANR"); log.info("Policy Notification: {}", notification); Boolean result = policyDmaapClient.sendNotificationToPolicy(notification); log.info("send notification to policy result {} ", result); + policyDmaapClient.handlePolicyResponse(requestId); + log.info("handled policy response in ModifyConfigANR"); + } - + } return true; } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java index 43c6c53..66f8221 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java @@ -38,8 +38,6 @@ import org.onap.dcaegen2.services.sonhms.restclient.Solutions; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.slf4j.Logger; - - public class PnfUtils { private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThreadUtils.class); @@ -50,58 +48,59 @@ public class PnfUtils { */ public Map> getPnfs(Solutions solutions) throws ConfigDbNotFoundException { - Map> pnfs = new HashMap<>(); + Map> pnfs = new HashMap<>(); List pciSolutions = solutions.getPciSolutions(); for (PciSolutions pciSolution : pciSolutions) { - String cellId = pciSolution.getCellId(); - int pci = pciSolution.getPci(); + String cellId = pciSolution.getCellId(); + int pci = pciSolution.getPci(); - String pnfName = ""; - CellInfoRepository cellInfoRepository = BeanUtil.getBean(CellInfoRepository.class); - Optional cellInfo = cellInfoRepository.findById(cellId); - if (cellInfo.isPresent()) { - pnfName = cellInfo.get().getPnfName(); - } else { - pnfName = SdnrRestClient.getPnfName(cellId); - cellInfoRepository.save(new CellInfo(cellId, pnfName)); - } - if (pnfs.containsKey(pnfName)) { - pnfs.get(pnfName).add(new CellPciPair(cellId, pci)); - } else { - List cellPciPairs = new ArrayList<>(); - cellPciPairs.add(new CellPciPair(cellId, pci)); - pnfs.put(pnfName, cellPciPairs); - } + String pnfName = ""; + CellInfoRepository cellInfoRepository = BeanUtil.getBean(CellInfoRepository.class); + Optional cellInfo = cellInfoRepository.findById(cellId); + if (cellInfo.isPresent()) { + pnfName = cellInfo.get().getPnfName(); + } else { + pnfName = SdnrRestClient.getPnfName(cellId); + cellInfoRepository.save(new CellInfo(cellId, pnfName)); + } + if (pnfs.containsKey(pnfName)) { + pnfs.get(pnfName).add(new CellPciPair(cellId, pci)); + } else { + List cellPciPairs = new ArrayList<>(); + cellPciPairs.add(new CellPciPair(cellId, pci)); + pnfs.put(pnfName, cellPciPairs); + } } return pnfs; } - + /** - * get pnfs for ANR solutions + * get pnfs for ANR solutions. * */ - public Map>>> getPnfsForAnrSolutions(List anrSolutions) throws ConfigDbNotFoundException { - - Map>>> anrPnfs = new HashMap<>(); - + public Map>>> getPnfsForAnrSolutions(List anrSolutions) + throws ConfigDbNotFoundException { + + Map>>> anrPnfs = new HashMap<>(); + List removeableNeighbors; - for(AnrSolutions anrSolution : anrSolutions) { + for (AnrSolutions anrSolution : anrSolutions) { String cellId = anrSolution.getCellId(); String pnfName = SdnrRestClient.getPnfName(cellId); removeableNeighbors = anrSolution.getRemoveableNeighbors(); - Map> cellRemNeighborsPair = new HashMap<>(); + Map> cellRemNeighborsPair = new HashMap<>(); cellRemNeighborsPair.put(cellId, removeableNeighbors); - if(anrPnfs.containsKey(pnfName)) { + if (anrPnfs.containsKey(pnfName)) { anrPnfs.get(pnfName).add(cellRemNeighborsPair); - }else { - List>> anrCells = new ArrayList<>(); + } else { + List>> anrCells = new ArrayList<>(); anrCells.add(cellRemNeighborsPair); anrPnfs.put(pnfName, anrCells); } } - log.info("anr Pnfs {}",anrPnfs.toString()); + log.info("anr Pnfs {}", anrPnfs); return anrPnfs; - + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java index a92617c..acfa1a4 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java @@ -35,6 +35,7 @@ import org.slf4j.Logger; public class StateOof { private static final Logger log = org.slf4j.LoggerFactory.getLogger(StateOof.class); private BlockingQueue> childStatusUpdate; + public StateOof() { } @@ -50,13 +51,15 @@ public class StateOof { /** * Triggers OOF for pci. - * @throws OofNotFoundException when trigger oof fails + * + * @throws OofNotFoundException + * when trigger oof fails */ - public UUID triggerOof(List cellidList, - String networkId, List anrInputList) throws OofNotFoundException, InterruptedException { - + public UUID triggerOof(List cellidList, String networkId, List anrInputList) + throws OofNotFoundException, InterruptedException { + log.info("Triggering oof"); - + log.debug("the cells triggering the oof are {}", cellidList); UUID transactionId = UUID.randomUUID(); @@ -79,9 +82,8 @@ public class StateOof { Thread.currentThread().interrupt(); } - + return transactionId; } - } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java b/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java index 767dae2..548cb4d 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java @@ -40,7 +40,6 @@ import org.onap.dcaegen2.services.sonhms.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class ConfigFetchFromCbs { private static Logger log = LoggerFactory.getLogger(ConfigFetchFromCbs.class); @@ -56,40 +55,42 @@ public class ConfigFetchFromCbs { RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); // Read necessary properties from the environment final EnvProperties env = EnvProperties.fromEnvironment(); - log.debug("environments {}",env); + log.debug("environments {}", env); ConfigPolicy configPolicy = ConfigPolicy.getInstance(); - + // Create the client and use it to get the configuration final CbsRequest request = CbsRequests.getAll(diagnosticContext); - CbsClientFactory.createCbsClient(env).flatMap(cbsClient -> cbsClient.get(request)) - .subscribe(jsonObject -> { - log.debug("configuration from CBS {}", jsonObject); - JsonObject config = jsonObject.getAsJsonObject("config"); - - updateConfigurationFromJsonObject(config); - - Type mapType = new TypeToken>() {}.getType(); - JsonObject policyJson = jsonObject.getAsJsonObject("policy"); - Map policy = new Gson().fromJson(policyJson, mapType); - configPolicy.setConfig(policy); - }, throwable -> log.warn("Ooops", throwable)) ; + CbsClientFactory.createCbsClient(env).flatMap(cbsClient -> cbsClient.get(request)).subscribe(jsonObject -> { + log.info("configuration and policy from CBS {}", jsonObject); + JsonObject config = jsonObject.getAsJsonObject("config"); + + updateConfigurationFromJsonObject(config); + + Type mapType = new TypeToken>() { + }.getType(); + JsonObject policyJson = jsonObject.getAsJsonObject("policies").getAsJsonArray("items").get(0) + .getAsJsonObject().getAsJsonObject("config"); + Map policy = new Gson().fromJson(policyJson, mapType); + configPolicy.setConfig(policy); + log.info("Config policy {}", configPolicy); + }, throwable -> log.warn("Ooops", throwable)); } private void updateConfigurationFromJsonObject(JsonObject jsonObject) { - + log.info("Updating configuration from CBS"); Configuration configuration = Configuration.getInstance(); - log.info("configuration from CBS {}", jsonObject); - - Type mapType = new TypeToken>() {}.getType(); - + + Type mapType = new TypeToken>() { + }.getType(); + JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); Map streamsSubscribes = new Gson().fromJson(subscribes, mapType); - + JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes"); Map streamsPublishes = new Gson().fromJson(publishes, mapType); - + int pgPort = jsonObject.get("postgres.port").getAsInt(); int pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt(); String pgPassword = jsonObject.get("postgres.password").getAsString(); @@ -102,19 +103,20 @@ public class ConfigFetchFromCbs { String pgHost = jsonObject.get("postgres.host").getAsString(); JsonArray servers = jsonObject.getAsJsonArray("sonhandler.dmaap.server"); - Type listType = new TypeToken>() {}.getType(); + Type listType = new TypeToken>() { + }.getType(); List dmaapServers = new Gson().fromJson(servers, listType); - + String cg = jsonObject.get("sonhandler.cg").getAsString(); int bufferTime = jsonObject.get("sonhandler.bufferTime").getAsInt(); String cid = jsonObject.get("sonhandler.cid").getAsString(); String configDbService = jsonObject.get("sonhandler.configDb.service").getAsString(); String namespace = jsonObject.get("sonhandler.namespace").getAsString(); String callbackUrl = "http://" + System.getenv("HOSTNAME") + "." + namespace + ":8080/callbackUrl"; - + JsonArray optimizersJson = jsonObject.getAsJsonArray("sonhandler.optimizers"); - List optimizers = new Gson().fromJson(optimizersJson, listType); - + List optimizers = new Gson().fromJson(optimizersJson, listType); + String oofService = jsonObject.get("sonhandler.oof.service").getAsString(); int pollingTimeout = jsonObject.get("sonhandler.pollingTimeout").getAsInt(); diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/HandOverMetricsRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/HandOverMetricsRepository.java index efc1e19..40ba19a 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/HandOverMetricsRepository.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/HandOverMetricsRepository.java @@ -22,18 +22,20 @@ package org.onap.dcaegen2.services.sonhms.dao; import org.onap.dcaegen2.services.sonhms.entity.HandOverMetrics; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; @Repository +@Transactional public interface HandOverMetricsRepository extends CrudRepository { - @Query(nativeQuery=true, - value="SELECT ho_details FROM handover_metrics WHERE src_cell_id=?1") + @Query(nativeQuery = true, value = "SELECT ho_details FROM handover_metrics WHERE src_cell_id=?1") public String getHandOverMetrics(String srcCellId); - @Query(nativeQuery=true, - value="UPDATE handover_metrics SET ho_details=?1 where src_cell_id=?2") + @Modifying + @Query(nativeQuery = true, value = "UPDATE handover_metrics SET ho_details=?1 where src_cell_id=?2") public void updateHoMetrics(String hoDetails, String srcCellId); } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/PerformanceNotificationsRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/PerformanceNotificationsRepository.java index c83956f..d45d7de 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/PerformanceNotificationsRepository.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/PerformanceNotificationsRepository.java @@ -28,11 +28,10 @@ import org.springframework.stereotype.Repository; @Repository public interface PerformanceNotificationsRepository extends CrudRepository { - - @Query(nativeQuery = true, - value = "DELETE FROM performance_notifications " - + "WHERE notification = ( SELECT notification FROM performance_notifications ORDER BY " - + "created_at FOR UPDATE SKIP LOCKED LIMIT 1 ) RETURNING notification;") + + @Query(nativeQuery = true, value = "DELETE FROM performance_notifications " + + "WHERE notification = ( SELECT notification FROM performance_notifications ORDER BY " + + "created_at FOR UPDATE SKIP LOCKED LIMIT 1 ) RETURNING notification;") public String getPerformanceNotificationFromQueue(); diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java index d3ca349..664dbf8 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java @@ -100,7 +100,7 @@ public class DmaapClient { // create notification consumers for FM NotificationConsumer fmNotificationConsumer = new NotificationConsumer(fmNotifCambriaConsumer, - new FMNotificationCallback()); + new FmNotificationCallback()); // start fm notification consumer threads executorPool = Executors.newScheduledThreadPool(10); executorPool.scheduleAtFixedRate(fmNotificationConsumer, 0, configuration.getPollingInterval(), @@ -108,7 +108,7 @@ public class DmaapClient { // create notification consumers for PM NotificationConsumer pmNotificationConsumer = new NotificationConsumer(pmNotifCambriaConsumer, - new PMNotificationCallback()); + new PmNotificationCallback()); // start pm notification consumer threads executorPool = Executors.newScheduledThreadPool(10); executorPool.scheduleAtFixedRate(pmNotificationConsumer, 0, configuration.getPollingInterval(), diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/FMNotificationCallback.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/FmNotificationCallback.java similarity index 63% rename from src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/FMNotificationCallback.java rename to src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/FmNotificationCallback.java index aede74b..c2231a0 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/FMNotificationCallback.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/FmNotificationCallback.java @@ -28,28 +28,29 @@ import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class FMNotificationCallback extends NotificationCallback{ - - private static Logger log = LoggerFactory.getLogger(FMNotificationCallback.class); - - @Override - public void activateCallBack(String msg){ - handleNotification(msg); - } - - private void handleNotification(String msg) { - - FaultNotificationsRepository faultNotificationsRepository=BeanUtil - .getBean(FaultNotificationsRepository.class); - - NewFmNotification newNotification=BeanUtil.getBean(NewFmNotification.class); - FaultNotifications faultNotification = new FaultNotifications(); - faultNotification.setNotification(msg); - if (log.isDebugEnabled()) { - log.debug(faultNotification.toString()); - } - faultNotificationsRepository.save(faultNotification); - newNotification.setNewNotif(true); - } +public class FmNotificationCallback extends NotificationCallback { + + private static Logger log = LoggerFactory.getLogger(FmNotificationCallback.class); + + @Override + public void activateCallBack(String msg) { + handleNotification(msg); + } + + private void handleNotification(String msg) { + + FaultNotificationsRepository faultNotificationsRepository = BeanUtil + .getBean(FaultNotificationsRepository.class); + + + FaultNotifications faultNotification = new FaultNotifications(); + faultNotification.setNotification(msg); + if (log.isDebugEnabled()) { + log.debug(faultNotification.toString()); + } + NewFmNotification newNotification = BeanUtil.getBean(NewFmNotification.class); + faultNotificationsRepository.save(faultNotification); + newNotification.setNewNotif(true); + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationCallback.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationCallback.java index f488f03..860789a 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationCallback.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationCallback.java @@ -23,6 +23,6 @@ package org.onap.dcaegen2.services.sonhms.dmaap; public abstract class NotificationCallback { - public abstract void activateCallBack(String msg); - + public abstract void activateCallBack(String msg); + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PMNotificationCallback.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PmNotificationCallback.java similarity index 63% rename from src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PMNotificationCallback.java rename to src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PmNotificationCallback.java index 47e285a..ea6a39f 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PMNotificationCallback.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PmNotificationCallback.java @@ -28,25 +28,25 @@ import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class PMNotificationCallback extends NotificationCallback { - - private static Logger log = LoggerFactory.getLogger(PMNotificationCallback.class); - - @Override - public void activateCallBack(String msg){ - handleNotification(msg); - } - - private void handleNotification(String msg) { - - PerformanceNotificationsRepository performanceNotificationsRepository=BeanUtil.getBean(PerformanceNotificationsRepository.class); - NewPmNotification newNotification=BeanUtil.getBean(NewPmNotification.class); - PerformanceNotifications performanceNotification = new PerformanceNotifications(); - performanceNotification.setNotification(msg); - log.info("Performance notification {}", performanceNotification); - performanceNotificationsRepository.save(performanceNotification); - newNotification.setNewNotif(true); - } +public class PmNotificationCallback extends NotificationCallback { + private static Logger log = LoggerFactory.getLogger(PmNotificationCallback.class); + + @Override + public void activateCallBack(String msg) { + handleNotification(msg); + } + + private void handleNotification(String msg) { + + PerformanceNotificationsRepository performanceNotificationsRepository = BeanUtil + .getBean(PerformanceNotificationsRepository.class); + PerformanceNotifications performanceNotification = new PerformanceNotifications(); + performanceNotification.setNotification(msg); + log.info("Performance notification {}", performanceNotification); + NewPmNotification newNotification = BeanUtil.getBean(NewPmNotification.class); + performanceNotificationsRepository.save(performanceNotification); + newNotification.setNewNotif(true); + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java index dbd9b58..d5371eb 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java @@ -22,29 +22,43 @@ package org.onap.dcaegen2.services.sonhms.dmaap; import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaConsumer; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; +import java.sql.Timestamp; import java.util.Map; import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.model.Payload; +import org.onap.dcaegen2.services.sonhms.model.PolicyNotification; import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils; +import org.slf4j.Logger; public class PolicyDmaapClient { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(PolicyDmaapClient.class); + private DmaapUtils dmaapUtils; + + private Configuration configuration; + + + public PolicyDmaapClient(DmaapUtils dmaapUtils, Configuration configuration) { + this.dmaapUtils = dmaapUtils; + this.configuration = configuration; + } /** * Method stub for sending notification to policy. */ @SuppressWarnings("unchecked") public boolean sendNotificationToPolicy(String msg) { - dmaapUtils = new DmaapUtils(); - Map streamsPublishes = Configuration.getInstance().getStreamsPublishes(); + Map streamsPublishes = configuration.getStreamsPublishes(); String policyTopicUrl = ((Map) ((Map) streamsPublishes.get("CL_topic")) .get("dmaap_info")).get("topic_url"); String[] policyTopicSplit = policyTopicUrl.split("\\/"); String policyTopic = policyTopicSplit[policyTopicSplit.length - 1]; - Configuration configuration = Configuration.getInstance(); CambriaBatchingPublisher cambriaBatchingPublisher; try { @@ -57,4 +71,51 @@ public class PolicyDmaapClient { } return true; } + + /** + * Handles policy response. + */ + @SuppressWarnings("unchecked") + public Boolean handlePolicyResponse(String requestId) { + + Map streamSubscribes = configuration.getStreamsSubscribes(); + String policyResponseTopicUrl = ((Map) ((Map) streamSubscribes + .get("dcae_cl_response_topic")).get("dmaap_info")).get("topic_url"); + String[] policyResponseTopicUrlSplit = policyResponseTopicUrl.split("\\/"); + String policyResponseTopic = policyResponseTopicUrlSplit[policyResponseTopicUrlSplit.length - 1]; + log.debug("policyResponse Topic : {}", policyResponseTopic); + CambriaConsumer policyResponseCambriaConsumer = null; + policyResponseCambriaConsumer = dmaapUtils.buildConsumer(configuration, policyResponseTopic); + Timestamp startTimer = new Timestamp(System.currentTimeMillis()); + + Timestamp currentTime = new Timestamp(System.currentTimeMillis()); + Long difference = currentTime.getTime() - startTimer.getTime(); + + while (difference < 10000) { + Iterable policyResponseMessages; + try { + policyResponseMessages = policyResponseCambriaConsumer.fetch(); + for (String msg : policyResponseMessages) { + ObjectMapper mapper = new ObjectMapper(); + PolicyNotification policyResponse = mapper.readValue(msg, PolicyNotification.class); + if (requestId.equals(policyResponse.getRequestId())) { + String payload = policyResponse.getPayload(); + Payload payloadObject = mapper.readValue(payload, Payload.class); + int status = payloadObject.getConfiguration().get(0).getStatus().getCode(); + String statusToString = Integer.toString(status); + log.info("response from policy, status code {}", statusToString); + + } + return true; + } + } catch (IOException e) { + log.info("caught io exception while fetching policy response"); + } + currentTime = new Timestamp(System.currentTimeMillis()); + difference = currentTime.getTime() - startTimer.getTime(); + } + log.info("no response from policy, timer expired"); + return true; + + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PerformanceNotifications.java b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PerformanceNotifications.java index 30a6c0e..67981d7 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PerformanceNotifications.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PerformanceNotifications.java @@ -33,8 +33,8 @@ import org.hibernate.annotations.CreationTimestamp; @Entity @Table(name = "PERFORMANCE_NOTIFICATIONS") public class PerformanceNotifications { - - @Id + + @Id @Column(name = "notification", columnDefinition = "text") private String notification; @@ -67,5 +67,4 @@ public class PerformanceNotifications { this.createdAt = createdAt; } - } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/AdditionalMeasurements.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/AdditionalMeasurements.java index 15a93e9..c55c6d6 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/AdditionalMeasurements.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/AdditionalMeasurements.java @@ -24,30 +24,33 @@ package org.onap.dcaegen2.services.sonhms.model; import java.util.Map; public class AdditionalMeasurements { - + String name; - Map hashMap ; - + Map hashMap; + public AdditionalMeasurements() { - + } + public String getName() { return name; } + public void setName(String name) { this.name = name; } + public Map getHashMap() { return hashMap; } + public void setHashMap(Map hashMap) { this.hashMap = hashMap; } + @Override public String toString() { return "AdditionalMeasurements [name=" + name + ", hashMap=" + hashMap + "]"; } - - - + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/AnrInput.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/AnrInput.java index faff91e..07a2923 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/AnrInput.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/AnrInput.java @@ -27,10 +27,11 @@ public class AnrInput { String cellId; List removeableNeighbors; - + public AnrInput() { - + } + /** * Parameterized Constructor. */ @@ -40,18 +41,21 @@ public class AnrInput { this.cellId = cellId; this.removeableNeighbors = removeableNeighbors; } + public String getCellId() { return cellId; } + public void setCellId(String cellId) { this.cellId = cellId; } + public List getRemoveableNeighbors() { return removeableNeighbors; } + public void setRemoveableNeighbors(List removeableNeighbors) { this.removeableNeighbors = removeableNeighbors; } - - + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java index 415b7d9..686666c 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java @@ -27,6 +27,9 @@ public class Configurations { @JsonProperty("data") private Data data; + @JsonProperty("Status") + private Status status; + /** * constructor. * @@ -34,22 +37,31 @@ public class Configurations { public Configurations() { } + /** * Parameterized constructor. * */ - public Configurations(Data data) { + public Configurations(Data data, Status status) { super(); this.data = data; + this.status = status; } + public Data getData() { return data; } + public void setData(Data data) { this.data = data; } - - + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/HoDetails.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/HoDetails.java index ecc2048..1d43f09 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/HoDetails.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/HoDetails.java @@ -22,43 +22,49 @@ package org.onap.dcaegen2.services.sonhms.model; public class HoDetails { - + private String dstCellId; private int attemptsCount; private int successCount; private float successRate; - + /** - * default constructor + * default constructor. */ public HoDetails() { - + } - + public String getDstCellId() { return dstCellId; } + public void setDstCellId(String dstCellId) { this.dstCellId = dstCellId; } + public int getAttemptsCount() { return attemptsCount; } + public void setAttemptsCount(int attemptsCount) { this.attemptsCount = attemptsCount; } + public int getSuccessCount() { return successCount; } + public void setSuccessCount(int successCount) { this.successCount = successCount; } + public float getSuccessRate() { return successRate; } + public void setSuccessRate(float successRate) { this.successRate = successRate; } - } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java index f1cae93..ce9099b 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java @@ -24,6 +24,7 @@ package org.onap.dcaegen2.services.sonhms.model; import com.fasterxml.jackson.annotation.JsonProperty; public class LteNeighborListInUseLteCell { + @JsonProperty("pnfName") private String pnfName; @@ -52,6 +53,9 @@ public class LteNeighborListInUseLteCell { } + /** + * constructor. + */ public LteNeighborListInUseLteCell(String pnfName, String enable, String alias, String mustInclude, String plmnId, String cid, int phyCellId, String blacklisted) { super(); diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/MeasurementFields.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/MeasurementFields.java index bdd8641..477a2d3 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/MeasurementFields.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/MeasurementFields.java @@ -27,15 +27,16 @@ public class MeasurementFields { String measurementInterval; String measurementFieldsVersion; - + List additionalMeasurements; - + /** - * default constructor + * default constructor. */ public MeasurementFields() { - + } + public String getMeasurementInterval() { return measurementInterval; } @@ -51,13 +52,13 @@ public class MeasurementFields { public void setAdditionalMeasurements(List additionalMeasurements) { this.additionalMeasurements = additionalMeasurements; } - + public String getMeasurementFieldsVersion() { return measurementFieldsVersion; } + public void setMeasurementFieldsVersion(String measurementFieldsVersion) { this.measurementFieldsVersion = measurementFieldsVersion; } - } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/PMNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/PmNotification.java similarity index 92% rename from src/main/java/org/onap/dcaegen2/services/sonhms/model/PMNotification.java rename to src/main/java/org/onap/dcaegen2/services/sonhms/model/PmNotification.java index 076be31..17b794e 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/PMNotification.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/PmNotification.java @@ -21,24 +21,23 @@ package org.onap.dcaegen2.services.sonhms.model; -public class PMNotification { +public class PmNotification { Event event; - + /** - * default constructor + * default constructor. */ - public PMNotification() { - + public PmNotification() { + } - + public Event getEvent() { return event; } + public void setEvent(Event event) { this.event = event; } - - - + } 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 e432b0c..16f7518 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 @@ -32,7 +32,7 @@ public class PolicyNotification { private long closedLoopAlarmStart; private String closedLoopEventClient; private String closedLoopEventStatus; - + @JsonProperty("target_type") private String targetType; @@ -46,6 +46,9 @@ public class PolicyNotification { private String from; private String version; + + private String policyName; + private String policyVersion; @JsonProperty("Action") private String action; @@ -60,9 +63,9 @@ public class PolicyNotification { /** * Constructor. - * */ - public PolicyNotification(String closedLoopControlName, String requestId, Long alarmStartTime, String pnfName, String action) { + public PolicyNotification(String closedLoopControlName, String requestId, Long alarmStartTime, String pnfName, + String action) { this.closedLoopControlName = closedLoopControlName; this.requestId = requestId; this.closedLoopEventClient = "microservice.PCI"; @@ -210,6 +213,22 @@ public class PolicyNotification { } return (this.hashCode() == obj.hashCode()); } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Status.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Status.java new file mode 100644 index 0000000..8f35b50 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Status.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + + +public class Status { + @JsonProperty("Code") + private int code; + + @JsonProperty("Value") + private String value; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AnrSolutions.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AnrSolutions.java index 117f202..042603a 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AnrSolutions.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AnrSolutions.java @@ -25,14 +25,17 @@ import java.util.ArrayList; import java.util.List; public class AnrSolutions { - + String cellId; List removeableNeighbors = new ArrayList<>(); - + public AnrSolutions() { - + } - + + /** + * constructor. + */ public AnrSolutions(String cellId, List removeableNeighbors) { super(); this.cellId = cellId; @@ -42,19 +45,22 @@ public class AnrSolutions { public String getCellId() { return cellId; } + public void setCellId(String cellId) { this.cellId = cellId; } + public List getRemoveableNeighbors() { return removeableNeighbors; } + public void setRemoveableNeighbors(List removeableNeighbors) { this.removeableNeighbors = removeableNeighbors; } + @Override public String toString() { return "AnrSolutions [cellId=" + cellId + ", removeableNeighbors=" + removeableNeighbors + "]"; } - } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java index 0f6dd98..97668ed 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java @@ -29,7 +29,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import org.onap.dcaegen2.services.sonhms.ConfigPolicy; import org.onap.dcaegen2.services.sonhms.Configuration; import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException; import org.onap.dcaegen2.services.sonhms.model.AnrInput; @@ -73,13 +72,7 @@ public class OofRestClient { Map callbackHeader = new HashMap<>(); callbackHeader.put("Content-Type", "application/json"); requestInfo.setCallbackHeader(callbackHeader); - ConfigPolicy config = ConfigPolicy.getInstance(); int timeout = 60; - try { - timeout = (int) config.getConfig().get("PCI_NEIGHBOR_CHANGE_CLUSTER_TIMEOUT_IN_SECS"); - } catch (NullPointerException e) { - log.debug("No config policy available. Using default timeout 60 sec"); - } requestInfo.setTimeout(timeout); CellInfo cellInfo = new CellInfo(); diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutions.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutions.java index eec3fd8..039285c 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutions.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutions.java @@ -27,8 +27,9 @@ public class PciSolutions { int pci; public PciSolutions() { - + } + public String getCellId() { return cellId; } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solutions.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solutions.java index 8e694a3..c39a20d 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solutions.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solutions.java @@ -25,14 +25,15 @@ import java.util.ArrayList; import java.util.List; public class Solutions { - + String networkId = null; List pciSolutions = new ArrayList<>(); List anrSolutions = new ArrayList<>(); - + public Solutions() { - + } + public String getNetworkId() { return networkId; } @@ -53,6 +54,7 @@ public class Solutions { this.pciSolutions = pciSolutions; } + public List getAnrSolutions() { return anrSolutions; } @@ -67,7 +69,4 @@ public class Solutions { + "]"; } - - - } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java index a25fd54..7228f78 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java @@ -177,7 +177,7 @@ public class ClusterUtils { /** * Get clusters for FM Cell. */ - public Either getClusterForFMCell(String cellId, List newClusters) { + public Either getClusterForFmCell(String cellId, List newClusters) { if (newClusters.isEmpty()) { log.info("getClusterForFMCell 404"); return Either.right(404); @@ -222,8 +222,10 @@ public class ClusterUtils { return clusterCells; } - // generic create cluster for both fm and sdnr - + + /** + * Create cluster. + */ public Graph createCluster(Map> clusterMap) throws ConfigDbNotFoundException { Graph cluster = new Graph(); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java index 6fb72c3..68b94fb 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java @@ -28,7 +28,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.hibernate.sql.ConditionFragment; import org.junit.Test; 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 5bf76b3..4b36b32 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java @@ -40,7 +40,7 @@ import org.mockito.Mock; import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; import org.onap.dcaegen2.services.sonhms.dao.PerformanceNotificationsRepository; import org.onap.dcaegen2.services.sonhms.model.Notification; -import org.onap.dcaegen2.services.sonhms.model.PMNotification; +import org.onap.dcaegen2.services.sonhms.model.PmNotification; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -104,7 +104,7 @@ public class DmaapNotificationsComponentTest { .thenReturn(performanceNotificationsRepositoryMock); when(performanceNotificationsRepositoryMock.getPerformanceNotificationFromQueue()).thenReturn(pmNotificationString); - Either result = component.getPmNotifications(); + Either result = component.getPmNotifications(); assertTrue(result.isLeft()); assertNotNull(result.left().value()); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java index 9cae5b6..cbd0265 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java @@ -40,7 +40,7 @@ import org.onap.dcaegen2.services.sonhms.dao.HandOverMetricsRepository; import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; import org.onap.dcaegen2.services.sonhms.entity.HandOverMetrics; import org.onap.dcaegen2.services.sonhms.model.Flag; -import org.onap.dcaegen2.services.sonhms.model.PMNotification; +import org.onap.dcaegen2.services.sonhms.model.PmNotification; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -69,20 +69,20 @@ public class PMNotificationHandlerTest { private static String pmNotificationsString ; private static String pmNotificationsString1 ; - private static PMNotification pmNotification; - private static PMNotification pmNotification1; + private static PmNotification pmNotification; + private static PmNotification pmNotification1; @BeforeClass public static void setup() { pmNotificationsString=readFromFile("/pmNotification.json"); pmNotificationsString1=readFromFile("/pmNotification1.json"); ObjectMapper mapper = new ObjectMapper(); - pmNotification = new PMNotification(); - pmNotification1 = new PMNotification(); + pmNotification = new PmNotification(); + pmNotification1 = new PmNotification(); try { - pmNotification = mapper.readValue(pmNotificationsString, PMNotification.class); - pmNotification1 = mapper.readValue(pmNotificationsString1, PMNotification.class); + pmNotification = mapper.readValue(pmNotificationsString, PmNotification.class); + pmNotification1 = mapper.readValue(pmNotificationsString1, PmNotification.class); } catch(Exception e) { e.printStackTrace(); } @@ -98,6 +98,7 @@ public class PMNotificationHandlerTest { when(handOverMetricsRepositoryMock.save(new HandOverMetrics())).thenReturn(null); when(flagMock.getHolder()).thenReturn("NONE"); when(policyDmaapClient.sendNotificationToPolicy(Mockito.anyString())).thenReturn(true); + when(policyDmaapClient.handlePolicyResponse(Mockito.anyString())).thenReturn(true); assertTrue(pmNotificationHandler.handlePmNotifications(pmNotification, 50)); assertFalse(pmNotificationHandler.handlePmNotifications(null, 0)); assertTrue(pmNotificationHandler.handlePmNotifications(pmNotification1, 50)); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java index 536f327..28940b3 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java @@ -187,6 +187,7 @@ public class TestChildThreadUtils { pciPairList.add(cell2); pciPairList.add(cell3); pnfsMap.put("pnf1", pciPairList); + when(policyDmaapClient.handlePolicyResponse(Mockito.anyString())).thenReturn(true); when(pnfUtils.getPnfs(async.getSolutions())).thenReturn(pnfsMap); List remNeighbors = new ArrayList<>(); remNeighbors.add("EXP006"); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClientTest.java new file mode 100644 index 0000000..16f205f --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClientTest.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.dmaap; + +import static org.junit.Assert.*; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaConsumer; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest; +import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils; +import org.springframework.boot.test.context.SpringBootTest; + +@RunWith(MockitoJUnitRunner.class) +@SpringBootTest(classes = PolicyDmaapClient.class) +public class PolicyDmaapClientTest { + + @Mock + Configuration configurationMock; + + @Mock + DmaapUtils dmaapUtilsMock; + + @InjectMocks + PolicyDmaapClient policyDmaapClient; + + @Mock + CambriaConsumer policyResponseCambriaConsumerMock; + + @Mock + CambriaBatchingPublisher cambriaBatchingPublisherMock; + + @Mock + NotificationProducer notificationProducerMock; + + @Before + public void setup() { + policyDmaapClient = new PolicyDmaapClient(dmaapUtilsMock, configurationMock); + } + + @Test + public void handlePolicyResponseTest() { + + Map streamsSubscribes = new HashMap<>(); + Map topics = new HashMap<>(); + Map dmaapInfo = new HashMap<>(); + topics.put("topic_url", "https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_RSP"); + dmaapInfo.put("dmaap_info", topics); + streamsSubscribes.put("dcae_cl_response_topic", dmaapInfo); + System.out.println(streamsSubscribes); + String policyResponseString = readFromFile("/policy_response.json"); + List responseMsgs = new ArrayList<>(); + responseMsgs.add(policyResponseString); + Iterable msgs = () -> new Iterator() { + private int index = 0; + + @Override + public boolean hasNext() { + return responseMsgs.size() > index; + } + + @Override + public String next() { + return responseMsgs.get(index++); + } + }; + Mockito.when(configurationMock.getStreamsSubscribes()).thenReturn(streamsSubscribes); + Mockito.when(dmaapUtilsMock.buildConsumer(configurationMock, "DCAE_CL_RSP")).thenReturn(policyResponseCambriaConsumerMock); + try { + Mockito.when(policyResponseCambriaConsumerMock.fetch()).thenReturn(msgs); + } catch (IOException e) { + e.printStackTrace(); + } + assertTrue(policyDmaapClient.handlePolicyResponse("9d2d790e-a5f0-11e8-98d0-529269fb1459")); + } + + @Test + public void sendNotificationToPolicyTest() { + Map streamsPublishes = new HashMap<>(); + Map topics = new HashMap<>(); + Map dmaapInfo = new HashMap<>(); + topics.put("topic_url", "https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_OUTPUT"); + dmaapInfo.put("dmaap_info", topics); + streamsPublishes.put("CL_topic", dmaapInfo); + Mockito.when(configurationMock.getStreamsPublishes()).thenReturn(streamsPublishes); + Mockito.when(dmaapUtilsMock.buildPublisher(configurationMock, "DCAE_CL_OUTPUT")).thenReturn(cambriaBatchingPublisherMock); + try { + Mockito.when(cambriaBatchingPublisherMock.send("", "hello")).thenReturn(0); + } catch (IOException e) { + e.printStackTrace(); + } + assertTrue(policyDmaapClient.sendNotificationToPolicy("hello")); + + } + + private static String readFromFile(String file) { + String content = new String(); + try { + + InputStream is = ClusterUtilsTest.class.getResourceAsStream(file); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); + content = bufferedReader.readLine(); + String temp; + while ((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + bufferedReader.close(); + } catch (Exception e) { + e.printStackTrace(); + content = null; + } + return content; + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java index 12c4912..d4c7828 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java @@ -108,8 +108,10 @@ public class NotificationTest { } catch (IOException e) { e.printStackTrace(); } - - assertNotEquals(notif, notif1); + + Notification notif2 = new Notification("9d2d790e-a5f0-11e8-98d0-529269fb1459", "{}", "SDNR", "1.0.2", "NeighborListModified", payload) ; + assertEquals(notif2.getPayload(), notif.getPayload()); + assertNotEquals(notif, notif1); assertEquals(notif.getAction(), notif1.getAction()); assertEquals(notif.getAai().toString(), notif1.getAai().toString()); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java index e89c8c3..537630c 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java @@ -47,7 +47,7 @@ public class PayloadTest { Data data = new Data(fapService); - Configurations config = new Configurations(data); + Configurations config = new Configurations(data, null); ArrayList al = new ArrayList<>(); al.add(config); diff --git a/src/test/resources/policy_response.json b/src/test/resources/policy_response.json new file mode 100644 index 0000000..37d263a --- /dev/null +++ b/src/test/resources/policy_response.json @@ -0,0 +1,10 @@ +{ + "closedLoopControlName": "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459", + "requestID": "9d2d790e-a5f0-11e8-98d0-529269fb1459", + "target": "SONHandler", + "from": "SDNR", + "version": "1.0.2", + "policyName": "PCI", + "policyVersion": "1.0.2", + "payload": " { \"Configurations\":[ { \"Status\": { \"Code\": 200, \"Value\": \"SUCCESS\" }, \"data\":{\"FAPService\":{\"alias\":\"Chn0330\",\"X0005b9Lte\":{\"phyCellIdInUse\":6,\"pnfName\":\"ncserver23\"},\"CellConfig\":{\"LTE\":{\"RAN\":{\"Common\":{\"CellIdentity\":\"Chn0330\"}}}}}} } ] }" +}