From 2896a24832902865313cd16081bba8b2d079748f Mon Sep 17 00:00:00 2001 From: krishnaa96 Date: Wed, 10 Apr 2019 14:28:53 +0530 Subject: Fix bugs and formatting issues Added minor functionality changes License formatting fixed Change-Id: Ieed4aab7562256eaf15627de0cee53cfe1cc8956 Issue-ID: DCAEGEN2-1111 Signed-off-by: krishnaa96 --- README.md | 43 +++++ dpo/blueprints/k8s-sonhms-inputs.yaml | 9 +- dpo/blueprints/k8s-sonhms.yaml | 9 +- dpo/spec/sonhandler-componentspec.json | 8 +- entrypoint.sh | 0 pom.xml | 37 ++-- .../sonhms/AlarmAdditionalInformation.java | 43 +++-- .../dcaegen2/services/sonhms/EventHandler.java | 35 ++-- .../onap/dcaegen2/services/sonhms/FaultFields.java | 6 +- .../services/sonhms/MainThreadComponent.java | 4 +- .../services/sonhms/PMNotificationHandler.java | 171 ------------------- .../onap/dcaegen2/services/sonhms/PMThread.java | 85 --------- .../services/sonhms/PmNotificationHandler.java | 190 +++++++++++++++++++++ .../onap/dcaegen2/services/sonhms/PmThread.java | 86 ++++++++++ .../services/sonhms/child/ChildThread.java | 32 +++- .../services/sonhms/child/ChildThreadUtils.java | 127 +++++++------- .../dcaegen2/services/sonhms/child/PnfUtils.java | 32 ++++ .../sonhms/controller/ConfigFetchFromCbs.java | 8 +- .../sonhms/model/AdditionalMeasurements.java | 16 +- .../onap/dcaegen2/services/sonhms/model/Event.java | 12 +- .../onap/dcaegen2/services/sonhms/model/Flag.java | 56 ++++++ .../services/sonhms/model/Measurement.java | 54 ------ .../services/sonhms/model/MeasurementFields.java | 63 +++++++ .../services/sonhms/model/PolicyNotification.java | 4 +- .../services/sonhms/restclient/OofRestClient.java | 15 +- .../services/sonhms/restclient/SdnrRestClient.java | 41 ++--- .../services/sonhms/utils/ThreadUtils.java | 35 ++-- src/main/resources/logback.xml | 75 ++++---- .../dcaegen2/services/sonhms/EventHandlerTest.java | 35 ++-- .../dcaegen2/services/sonhms/FaultFieldsTest.java | 4 +- .../services/sonhms/PMNotificationHandlerTest.java | 44 +++-- .../sonhms/child/TestChildThreadUtils.java | 17 +- .../services/sonhms/child/TestPnfUtils.java | 33 ++++ .../sonhms/restclient/SdnrRestClientTest.java | 46 ++--- src/test/resources/anrSolutions.json | 15 ++ src/test/resources/pmNotification.json | 94 +++++----- src/test/resources/pmNotification1.json | 96 +++++------ src/test/resources/policy_notification.json | 4 +- 38 files changed, 960 insertions(+), 724 deletions(-) create mode 100644 README.md mode change 100644 => 100755 entrypoint.sh delete mode 100644 src/main/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandler.java delete mode 100644 src/main/java/org/onap/dcaegen2/services/sonhms/PMThread.java create mode 100644 src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java create mode 100644 src/main/java/org/onap/dcaegen2/services/sonhms/PmThread.java create mode 100644 src/main/java/org/onap/dcaegen2/services/sonhms/model/Flag.java delete mode 100644 src/main/java/org/onap/dcaegen2/services/sonhms/model/Measurement.java create mode 100644 src/main/java/org/onap/dcaegen2/services/sonhms/model/MeasurementFields.java create mode 100644 src/test/resources/anrSolutions.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..65e28af --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +SONHMS + +### Build Instructions + +This project is organized as a mvn project and has "org.onap.dcaegen2" as parent project. The build generate a jar and package into docker container. + +``` +git clone https://gerrit.onap.org/r/dcaegen2/services/son-handler +mvn clean install +``` + + +### Environment variables in Docker Container + + +Variables coming from deployment system: + +- APP_NAME - son-handler application name that will be registered with consul +- CONSUL_PROTOCOL - Consul protocol by default set to **http**, if it is need to change it then that can be set to different value +- CONSUL_HOST - used with conjunction with CBSPOLLTIMER, should be a host address (without port! e.g my-ip-or-host) where Consul service lies +- 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 +``` +nexus3.onap.org:10001/snapshots/onap/org.onap.dcaegen2.services.son-handler 1.0.0 +``` + +### Deployment +son handler can be manually deployed in dcae environment using cloudify blueprint. + +login to bootstrap container in dcae deployment + +To install : + cfy install -b sonhms -d sonhms -i + +To uninstall: + cfy uninstall sonhms + cfy blueprints delete sonhms + + diff --git a/dpo/blueprints/k8s-sonhms-inputs.yaml b/dpo/blueprints/k8s-sonhms-inputs.yaml index 42afba4..052f0b9 100644 --- a/dpo/blueprints/k8s-sonhms-inputs.yaml +++ b/dpo/blueprints/k8s-sonhms-inputs.yaml @@ -18,7 +18,7 @@ pgaas_cluster_name: dcae-pg-primary.onap database_name: sonhms -tag_version: nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.son-handler:latest +tag_version: nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.son-handler:1.0.0 replicas: 1 aaf_username: aaf_password: @@ -30,12 +30,13 @@ min_confusion: 5 max_clusters: 5 bad_threshold: 50 poor_threshold: 70 -dmaap: message-router +namespace: onap +dmaap: message-router.onap buffer_time: 60 cg: sonhms-cg cid: sonhms-cid -config_db: http://sdnc.onap.svc.cluster.local:8181 -oof: http://oof.onap.svc.cluster.local:8080 +config_db: http://sdnc.onap:8181 +oof: http://oof-osdf.onap:8080 pci_optimizer: pci log_path: /dockerdata-nfs/son-handler topic00_location: onap diff --git a/dpo/blueprints/k8s-sonhms.yaml b/dpo/blueprints/k8s-sonhms.yaml index 9e43fac..9d4e0db 100644 --- a/dpo/blueprints/k8s-sonhms.yaml +++ b/dpo/blueprints/k8s-sonhms.yaml @@ -29,7 +29,7 @@ inputs: tag_version: type: string description: docker image name and version - default: "nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.son-handler:latest" + default: "nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.son-handler:1.0.0" pgaas_cluster_name: type: string description: pg cluster @@ -76,6 +76,10 @@ inputs: type: integer description: threshold for poor neighbors default: 70 + namespace: + type: String + description: namespace + default: onap dmaap: type: string description: dmaap server @@ -143,7 +147,7 @@ node_templates: - host: path: { get_input: log_path } container: - bind: /var/log/onap + bind: /home/sonhms/logs mode: rw properties: image: @@ -209,6 +213,7 @@ node_templates: sonhandler.maximumClusters: { get_input: max_clusters } sonhandler.badThreshold: { get_input: bad_threshold } sonhandler.poorThreshold: { get_input: poor_threshold } + sonhandler.namespace: { get_input: namespace } sonhandler.sourceId: SONHMS sonhandler.dmaap.server: - { get_input: dmaap } diff --git a/dpo/spec/sonhandler-componentspec.json b/dpo/spec/sonhandler-componentspec.json index 1586dcf..6fc51be 100644 --- a/dpo/spec/sonhandler-componentspec.json +++ b/dpo/spec/sonhandler-componentspec.json @@ -14,14 +14,14 @@ "type": "message router" }, { - "format": "FM_ALARM_FROM_VES", - "version": "1.0.0", + "format": "VES_specification", + "version": "7.30.1", "config_key": "fault_management_topic", "type": "message router" }, { - "format": "PM_ALARM_FROM_VES", - "version": "1.0.0", + "format": "VES_specification", + "version": "7.30.1", "config_key": "performance_management_topic", "type": "message router" }, diff --git a/entrypoint.sh b/entrypoint.sh old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml index e3a48a3..f87e777 100644 --- a/pom.xml +++ b/pom.xml @@ -1,14 +1,26 @@ - + 4.0.0 @@ -29,7 +41,7 @@ - 1.1.4-SNAPSHOT + 1.1.4 UTF-8 1.8 1.8 @@ -263,11 +275,10 @@ + adduser --disabled-password sonhms chmod +x /bin/entrypoint.sh mv /bin/*.jar /bin/application.jar chmod -R 777 /bin - mkdir /var/log/onap - chmod -R 777 /var/log/onap 8080 diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/AlarmAdditionalInformation.java b/src/main/java/org/onap/dcaegen2/services/sonhms/AlarmAdditionalInformation.java index 63cc745..fb45967 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/AlarmAdditionalInformation.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/AlarmAdditionalInformation.java @@ -1,22 +1,23 @@ /******************************************************************************* - * ============LICENSE_START======================================================= - * pcims + * ============LICENSE_START======================================================= + * son-handler * ================================================================================ - * Copyright (C) 2018 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========================================================= - ******************************************************************************/ + * 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; @@ -25,23 +26,29 @@ public class AlarmAdditionalInformation { private String networkId; private int collisions; private int confusions; + public String getNetworkId() { return networkId; } + public void setNetworkId(String networkId) { this.networkId = networkId; } + public int getCollisions() { return collisions; } + public void setCollisions(int collisions) { this.collisions = collisions; } + public int getConfusions() { return confusions; } + public void setConfusions(int confusions) { this.confusions = confusions; } - + } 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 a25fe0e..bcd9e92 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java @@ -1,22 +1,23 @@ /******************************************************************************* - * ============LICENSE_START======================================================= - * pcims + * ============LICENSE_START======================================================= + * son-handler * ================================================================================ - * Copyright (C) 2018 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========================================================= - ******************************************************************************/ + * 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; 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 462f550..c1649b2 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultFields.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultFields.java @@ -31,7 +31,7 @@ public class FaultFields { + alarmAdditionalInformation + "]"; } - private int faultFieldsVersion; + private double faultFieldsVersion; private String alarmCondition; private String eventSourceType; private String specificProblem; @@ -48,11 +48,11 @@ public class FaultFields { this.alarmAdditionalInformation = alarmAdditionalInformation; } - public int getFaultFieldsVersion() { + public double getFaultFieldsVersion() { return faultFieldsVersion; } - public void setFaultFieldsVersion(int faultFieldsVersion) { + public void setFaultFieldsVersion(double faultFieldsVersion) { this.faultFieldsVersion = faultFieldsVersion; } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java index 606f420..a167872 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java @@ -41,6 +41,8 @@ public class MainThreadComponent { @Autowired private NewFmNotification newFmNotification; + + /** * main thread initialization. @@ -50,7 +52,7 @@ public class MainThreadComponent { log.debug("initializing main thread"); Thread thread = new Thread(new MainThread(newNotification, newFmNotification)); thread.start(); - Thread pmThread = new Thread(new PMThread(newPmNotification)); + Thread pmThread = new Thread(new PmThread(newPmNotification)); pmThread.start(); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandler.java b/src/main/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandler.java deleted file mode 100644 index 0482b83..0000000 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandler.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * Copyright (C) 2018 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; - -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.ArrayList; -import java.util.List; -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.AdditionalMeasurements; -import org.onap.dcaegen2.services.sonhms.model.CellConfig; -import org.onap.dcaegen2.services.sonhms.model.Common; -import org.onap.dcaegen2.services.sonhms.model.Configurations; -import org.onap.dcaegen2.services.sonhms.model.Data; -import org.onap.dcaegen2.services.sonhms.model.FapService; -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.Ran; -import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PMNotificationHandler { - - private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); - PolicyDmaapClient policyDmaapClient; - - public PMNotificationHandler() { - - } - - public PMNotificationHandler(PolicyDmaapClient policyDmaapClient) { - this.policyDmaapClient = policyDmaapClient; - } - - /** - * handle pm notifications. - */ - public Boolean handlePmNotifications(PMNotification pmNotification, int badThreshold) { - HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); - Boolean result; - try { - List hoDetailsList = new ArrayList<>(); - List lteCellList = new ArrayList<>(); - String srcCellId = pmNotification.getEvent().getCommonEventHeader().getSourceName(); - for (AdditionalMeasurements additionalMeasurements : pmNotification.getEvent().getMeasurement() - .getAdditionalMeasurements()) { - int attemptsCount = Integer - .parseInt(additionalMeasurements.getArrayOfNamedHashMap().get(1).get("InterEnbOutAtt_X2HO")); - int successCount = Integer - .parseInt(additionalMeasurements.getArrayOfNamedHashMap().get(2).get("InterEnbOutSucc_X2HO")); - float successRate = ((float) successCount / attemptsCount) * 100; - if (successRate >= badThreshold) { - HoDetails hoDetails = new HoDetails(); - hoDetails.setDstCellId(additionalMeasurements.getName()); - hoDetails.setAttemptsCount(attemptsCount); - hoDetails.setSuccessCount(successCount); - hoDetails.setSuccessRate(successRate); - hoDetailsList.add(hoDetails); - log.info("not bad neighbor {}",additionalMeasurements.getName()); - } else { - log.info(" bad neighbor {}",additionalMeasurements.getName()); - LteCell lteCell = new LteCell(); - lteCell.setBlacklisted("true"); - lteCell.setCid(additionalMeasurements.getName()); - lteCell.setPlmnId(additionalMeasurements.getArrayOfNamedHashMap().get(0).get("networkId")); - lteCell.setPnfName(pmNotification.getEvent().getCommonEventHeader().getReportingEntityName()); - lteCellList.add(lteCell); - } - } - if (!lteCellList.isEmpty()) { - log.info("triggering policy to remove bad neighbors"); - result = sendAnrUpdateToPolicy(pmNotification, lteCellList); - log.info("Sent ANR update to policy {}", result); - String hoDetailsString = handOverMetricsRepository.getHandOverMetrics(srcCellId); - if (hoDetailsString != null) { - ObjectMapper mapper = new ObjectMapper(); - String newHoDetailsString = null; - try { - newHoDetailsString = mapper.writeValueAsString(hoDetailsList); - } catch (Exception e) { - log.error("Error in writing handover metrics json ", e); - return false; - } - handOverMetricsRepository.updateHoMetrics(newHoDetailsString, srcCellId); - } - } - if (!hoDetailsList.isEmpty()) { - result = saveToHandOverMetrics(hoDetailsList, srcCellId); - log.debug("save HO metrics result {} ", result); - - } - - } catch (Exception e) { - log.error("Error in handlePmNotifications ", e); - return false; - } - return true; - - } - - 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())))))))); - configurations.add(configuration); - Payload payload = new Payload(configurations); - log.info("payload : {}", payload); - String anrUpdateString = mapper.writeValueAsString(payload); - - Boolean result = policyDmaapClient.sendNotificationToPolicy(anrUpdateString); - log.debug("send notification to policy result {} ", result); - } catch (Exception e) { - log.error("Exception in sending Anr update to policy ", e); - return false; - } - return true; - } - - private Boolean saveToHandOverMetrics(List hoDetailsList, String srcCellId) { - HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); - ObjectMapper mapper = new ObjectMapper(); - String hoDetailsString = null; - try { - hoDetailsString = mapper.writeValueAsString(hoDetailsList); - } catch (Exception e) { - log.error("Error in writing handover metrics json ", e); - return false; - } - - if (handOverMetricsRepository.getHandOverMetrics(srcCellId) == null) { - HandOverMetrics handOverMetrics = new HandOverMetrics(); - handOverMetrics.setHoDetails(hoDetailsString); - handOverMetrics.setSrcCellId(srcCellId); - handOverMetricsRepository.save(handOverMetrics); - } - else { - handOverMetricsRepository.updateHoMetrics(hoDetailsString, srcCellId); - } - return true; - } -} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/PMThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/PMThread.java deleted file mode 100644 index 608e61f..0000000 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/PMThread.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * ============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; - -import fj.data.Either; - -import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; -import org.onap.dcaegen2.services.sonhms.model.PMNotification; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PMThread implements Runnable { - - private static Logger log = LoggerFactory.getLogger(PMThread.class); - - private NewPmNotification newPmNotification; - - private DmaapNotificationsComponent dmaapNotificationsComponent; - - private PMNotificationHandler pmNotificationHandler; - - /** - * parameterized constructor. - */ - public PMThread(NewPmNotification newPmNotification) { - super(); - this.newPmNotification = newPmNotification; - dmaapNotificationsComponent = new DmaapNotificationsComponent(); - pmNotificationHandler = new PMNotificationHandler(new PolicyDmaapClient()); - } - - @Override - public void run() { - log.info("PM thread starting ..."); - // check for PM notifications - Boolean done = false; - while (!done) { - try { - Thread.sleep(1000); - if (newPmNotification.getNewNotif()) { - log.info("New PM notification from Dmaap"); - Either pmNotification = dmaapNotificationsComponent.getPmNotifications(); - if (pmNotification.isRight()) { - if (pmNotification.right().value() == 400) { - log.error("error parsing pm notifications"); - } else if (pmNotification.right().value() == 404) { - log.info("Queue is empty"); - newPmNotification.setNewNotif(false); - } - } else if (pmNotification.isLeft()) { - Configuration configuration = Configuration.getInstance(); - Boolean result = pmNotificationHandler.handlePmNotifications(pmNotification.left().value(), - configuration.getBadThreshold()); - log.info("pm notification handler result {}", result); - } - - } - } catch (Exception e) { - log.error("Exception in PM Thread ", e); - done = true; - } - } - - } - -} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java b/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java new file mode 100644 index 0000000..0df0bdb --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java @@ -0,0 +1,190 @@ +/******************************************************************************* + * ============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; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.onap.dcaegen2.services.sonhms.child.ChildThreadUtils; +import org.onap.dcaegen2.services.sonhms.child.PnfUtils; +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.AdditionalMeasurements; +import org.onap.dcaegen2.services.sonhms.model.CellConfig; +import org.onap.dcaegen2.services.sonhms.model.Common; +import org.onap.dcaegen2.services.sonhms.model.Configurations; +import org.onap.dcaegen2.services.sonhms.model.Data; +import org.onap.dcaegen2.services.sonhms.model.FapService; +import org.onap.dcaegen2.services.sonhms.model.Flag; +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.Ran; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PmNotificationHandler { + + private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); + PolicyDmaapClient policyDmaapClient; + + public PmNotificationHandler() { + + } + + public PmNotificationHandler(PolicyDmaapClient policyDmaapClient) { + this.policyDmaapClient = policyDmaapClient; + } + + /** + * handle PM notifications. + */ + public Boolean handlePmNotifications(PMNotification pmNotification, int badThreshold) { + HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); + Boolean result; + try { + List hoDetailsList = new ArrayList<>(); + List lteCellList = new ArrayList<>(); + 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")); + float successRate = ((float) successCount / attemptsCount) * 100; + if (successRate >= badThreshold) { + HoDetails hoDetails = new HoDetails(); + hoDetails.setDstCellId(additionalMeasurements.getName()); + hoDetails.setAttemptsCount(attemptsCount); + hoDetails.setSuccessCount(successCount); + hoDetails.setSuccessRate(successRate); + hoDetailsList.add(hoDetails); + log.info("not bad neighbor {}", additionalMeasurements.getName()); + } else { + log.info(" bad neighbor {}", additionalMeasurements.getName()); + LteCell lteCell = new LteCell(); + lteCell.setBlacklisted("true"); + lteCell.setCid(additionalMeasurements.getName()); + lteCell.setPlmnId(additionalMeasurements.getHashMap().get("networkId")); + lteCell.setPnfName(pmNotification.getEvent().getCommonEventHeader().getReportingEntityName()); + lteCellList.add(lteCell); + } + } + 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); + } + + policyTriggerFlag.setHolder("PM"); + result = sendAnrUpdateToPolicy(pmNotification, lteCellList); + log.info("Sent ANR update to policy {}", result); + policyTriggerFlag.setHolder("NONE"); + + String hoDetailsString = handOverMetricsRepository.getHandOverMetrics(srcCellId); + if (hoDetailsString != null) { + ObjectMapper mapper = new ObjectMapper(); + String newHoDetailsString = null; + try { + newHoDetailsString = mapper.writeValueAsString(hoDetailsList); + } catch (Exception e) { + log.error("Error in writing handover metrics json ", e); + return false; + } + handOverMetricsRepository.updateHoMetrics(newHoDetailsString, srcCellId); + } + } + if (!hoDetailsList.isEmpty()) { + result = saveToHandOverMetrics(hoDetailsList, srcCellId); + log.debug("save HO metrics result {} ", result); + + } + + } catch (Exception e) { + log.error("Error in handlePmNotifications ", e); + return false; + } + return true; + + } + + 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())))))))); + 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"); + log.info("Policy Notification: {}", notification); + Boolean result = policyDmaapClient.sendNotificationToPolicy(notification); + log.info("send notification to policy result {} ", result); + + } catch (Exception e) { + log.error("Exception in sending Anr update to policy ", e); + return false; + } + return true; + } + + private Boolean saveToHandOverMetrics(List hoDetailsList, String srcCellId) { + HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); + ObjectMapper mapper = new ObjectMapper(); + String hoDetailsString = null; + try { + hoDetailsString = mapper.writeValueAsString(hoDetailsList); + } catch (Exception e) { + log.error("Error in writing handover metrics json ", e); + return false; + } + + if (handOverMetricsRepository.getHandOverMetrics(srcCellId) == null) { + HandOverMetrics handOverMetrics = new HandOverMetrics(); + handOverMetrics.setHoDetails(hoDetailsString); + handOverMetrics.setSrcCellId(srcCellId); + handOverMetricsRepository.save(handOverMetrics); + } else { + handOverMetricsRepository.updateHoMetrics(hoDetailsString, srcCellId); + } + return true; + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/PmThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/PmThread.java new file mode 100644 index 0000000..d2d509f --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/PmThread.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * ============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; + +import fj.data.Either; + +import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; +import org.onap.dcaegen2.services.sonhms.model.PMNotification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PmThread implements Runnable { + + private static Logger log = LoggerFactory.getLogger(PmThread.class); + + private NewPmNotification newPmNotification; + + + private DmaapNotificationsComponent dmaapNotificationsComponent; + + private PmNotificationHandler pmNotificationHandler; + + /** + * parameterized constructor. + */ + public PmThread(NewPmNotification newPmNotification) { + super(); + this.newPmNotification = newPmNotification; + dmaapNotificationsComponent = new DmaapNotificationsComponent(); + pmNotificationHandler = new PmNotificationHandler(new PolicyDmaapClient()); + } + + @Override + public void run() { + log.info("PM thread starting ..."); + // check for PM notifications + Boolean done = false; + while (!done) { + try { + Thread.sleep(1000); + if (newPmNotification.getNewNotif()) { + log.info("New PM notification from Dmaap"); + Either pmNotification = dmaapNotificationsComponent.getPmNotifications(); + if (pmNotification.isRight()) { + if (pmNotification.right().value() == 400) { + log.error("error parsing pm notifications"); + } else if (pmNotification.right().value() == 404) { + log.info("Queue is empty"); + newPmNotification.setNewNotif(false); + } + } else if (pmNotification.isLeft()) { + Configuration configuration = Configuration.getInstance(); + Boolean result = pmNotificationHandler.handlePmNotifications(pmNotification.left().value(), + configuration.getBadThreshold()); + log.info("pm notification handler result {}", result); + } + + } + } catch (Exception e) { + log.error("Exception in PM Thread ", e); + done = true; + } + } + + } + +} 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 5348e7d..15a2881 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 @@ -49,6 +49,7 @@ import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; import org.onap.dcaegen2.services.sonhms.model.AnrInput; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.model.ClusterMap; +import org.onap.dcaegen2.services.sonhms.model.Flag; import org.onap.dcaegen2.services.sonhms.model.HoDetails; import org.onap.dcaegen2.services.sonhms.model.ThreadId; import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; @@ -142,7 +143,7 @@ public class ChildThread implements Runnable { } MDC.put("logFileName", Thread.currentThread().getName()); - log.debug("Starting child thread"); + log.info("Starting child thread"); StateOof oof = new StateOof(childStatusUpdate); ClusterUtils clusterUtils = new ClusterUtils(); @@ -188,9 +189,9 @@ public class ChildThread implements Runnable { // update cluster in DB clusterUtils.updateCluster(cluster); + collisionConfusionResult = detect.detectCollisionConfusion(cluster); } - collisionConfusionResult = detect.detectCollisionConfusion(cluster); } ArrayList cellidList = new ArrayList<>(); @@ -215,15 +216,27 @@ public class ChildThread implements Runnable { cellidList.add(cell); } UUID transactionId; + + Flag policyTriggerFlag = BeanUtil.getBean(Flag.class); + while (policyTriggerFlag.getHolder().equals("PM")) { + Thread.sleep(100); + } + policyTriggerFlag.setHolder("CHILD"); + policyTriggerFlag.setNumChilds(policyTriggerFlag.getNumChilds() + 1); + Either, Integer> anrTriggerResponse = checkAnrTrigger(cellidList); if (anrTriggerResponse.isRight()) { - if (anrTriggerResponse.right().value() == 404) + + if (anrTriggerResponse.right().value() == 404) { log.debug("No poor neighbors found"); - else if (anrTriggerResponse.right().value() == 500) + } else if (anrTriggerResponse.right().value() == 500) { log.debug("Failed to fetch HO details from DB "); + } + transactionId = oof.triggerOof(cellidList, networkId, new ArrayList<>()); } else { List anrInputList = anrTriggerResponse.left().value(); + log.info("Trigger oof for joint optimization"); transactionId = oof.triggerOof(cellidList, networkId, anrInputList); } long childThreadId = Thread.currentThread().getId(); @@ -234,8 +247,16 @@ public class ChildThread implements Runnable { AsyncResponseBody asynResponseBody = ChildThread.getResponseMap().get(childThreadId); + + try { childUtils.sendToPolicy(asynResponseBody); + policyTriggerFlag.setNumChilds(policyTriggerFlag.getNumChilds() - 1); + if (policyTriggerFlag.getNumChilds() == 0) { + policyTriggerFlag.setHolder("NONE"); + } + + } catch (ConfigDbNotFoundException e1) { log.debug("Config DB is unreachable: {}", e1); } @@ -379,6 +400,9 @@ public class ChildThread implements Runnable { return clusterMapList; } + /** + * Check if ANR to be triggered. + */ public Either, Integer> checkAnrTrigger(List cellidList) { List anrInputList = new ArrayList<>(); 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 178d728..1acfde6 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 @@ -49,7 +49,6 @@ import org.onap.dcaegen2.services.sonhms.model.Payload; import org.onap.dcaegen2.services.sonhms.model.PolicyNotification; import org.onap.dcaegen2.services.sonhms.model.Ran; import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte; -import org.onap.dcaegen2.services.sonhms.restclient.AnrSolutions; import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; import org.onap.dcaegen2.services.sonhms.restclient.Solutions; @@ -112,27 +111,9 @@ public class ChildThreadUtils { * get policy notification string from oof result. * */ - public String getNotificationString(String pnfName, List cellPciPairs, String requestId, - Long alarmStartTime) { - ArrayList configurations = new ArrayList<>(); - for (CellPciPair cellPciPair : cellPciPairs) { - 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)))))); - configurations.add(configuration); - } - - Payload payload = new Payload(configurations); - ObjectMapper mapper = new ObjectMapper(); - mapper.setSerializationInclusion(Include.NON_NULL); - String payloadString = ""; - try { - payloadString = mapper.writeValueAsString(payload); - } catch (JsonProcessingException e) { - log.debug("JSON processing exception: {}", e); - } - + 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"); @@ -141,10 +122,11 @@ public class ChildThreadUtils { } PolicyNotification policyNotification = new PolicyNotification(closedLoopControlName, requestId, alarmStartTime, - pnfName); + pnfName, action); policyNotification.setClosedLoopControlName(closedLoopControlName); policyNotification.setPayload(payloadString); + ObjectMapper mapper = new ObjectMapper(); String notification = ""; try { @@ -161,7 +143,7 @@ public class ChildThreadUtils { * @throws ConfigDbNotFoundException * when config db is unreachable */ - public void sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException { + public Boolean sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException { if (log.isDebugEnabled()) { log.debug(async.toString()); @@ -169,19 +151,34 @@ public class ChildThreadUtils { Solutions solutions; solutions = async.getSolutions(); - if (!solutions.getPciSolutions().isEmpty()) { Map> pnfs = pnfUtils.getPnfs(solutions); - for (Map.Entry> entry : pnfs.entrySet()) { String pnfName = entry.getKey(); List cellPciPairs = entry.getValue(); + ArrayList configurations = new ArrayList<>(); + for (CellPciPair cellPciPair : cellPciPairs) { + 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)))))); + configurations.add(configuration); + } + + Payload payload = new Payload(configurations); + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + String payloadString = ""; + try { + payloadString = mapper.writeValueAsString(payload); + } catch (JsonProcessingException e) { + log.debug("JSON processing exception: {}", e); + } - String notification = getNotificationString(pnfName, cellPciPairs, UUID.randomUUID().toString(), - System.currentTimeMillis()); - log.debug("Policy Notification: {}", notification); - PolicyDmaapClient policy = new PolicyDmaapClient(); - boolean status = policy.sendNotificationToPolicy(notification); + String notification = getNotificationString(pnfName, UUID.randomUUID().toString(), payloadString, + System.currentTimeMillis(), "ModifyConfig"); + log.info("Policy Notification: {}", notification); + boolean status = policyDmaapClient.sendNotificationToPolicy(notification); log.debug("sent Message: {}", status); if (status) { log.debug("Message sent to policy"); @@ -192,39 +189,49 @@ public class ChildThreadUtils { } } if (!solutions.getAnrSolutions().isEmpty()) { - + Map>>> anrPnfs; List configurations = new ArrayList<>(); - for (AnrSolutions anrSolution : solutions.getAnrSolutions()) { - String cellId = anrSolution.getCellId(); - List lteCellList = new ArrayList<>(); - for (String removeableNeighbor : anrSolution.getRemoveableNeighbors()) { - LteCell lteCell = new LteCell(); - lteCell.setBlacklisted("true"); - lteCell.setPlmnId(solutions.getNetworkId()); - lteCell.setCid(removeableNeighbor); - int pci = SdnrRestClient.getPci(cellId); - String pnfName = SdnrRestClient.getPnfName(cellId); - lteCell.setPhyCellId(pci); - lteCell.setPnfName(pnfName); - lteCellList.add(lteCell); + anrPnfs = pnfUtils.getPnfsForAnrSolutions(solutions.getAnrSolutions()); + 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); + } } - 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); - } - Payload payload = new Payload(configurations); - ObjectMapper mapper = new ObjectMapper(); - mapper.setSerializationInclusion(Include.NON_NULL); - String anrUpdateString = null; - try { - anrUpdateString = mapper.writeValueAsString(payload); - } catch (JsonProcessingException e) { - log.error("Exception in writing anrupdate string", e); + Payload payload = new Payload(configurations); + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + String payloadString = null; + try { + payloadString = mapper.writeValueAsString(payload); + } catch (JsonProcessingException e) { + log.error("Exception in writing anrupdate string", e); + } + String notification = getNotificationString(pnfName, UUID.randomUUID().toString(), payloadString, + System.currentTimeMillis(), "ModifyConfigANR"); + log.info("Policy Notification: {}", notification); + Boolean result = policyDmaapClient.sendNotificationToPolicy(notification); + log.info("send notification to policy result {} ", result); } - Boolean result = policyDmaapClient.sendNotificationToPolicy(anrUpdateString); - log.debug("send notification to policy result {} ", result); + } + 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 590a938..43c6c53 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 @@ -31,15 +31,19 @@ import org.onap.dcaegen2.services.sonhms.dao.CellInfoRepository; import org.onap.dcaegen2.services.sonhms.entity.CellInfo; import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.restclient.AnrSolutions; import org.onap.dcaegen2.services.sonhms.restclient.PciSolutions; import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; 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); + /** * get pnfs. * @@ -72,4 +76,32 @@ public class PnfUtils { } return pnfs; } + + /** + * get pnfs for ANR solutions + * + */ + public Map>>> getPnfsForAnrSolutions(List anrSolutions) throws ConfigDbNotFoundException { + + Map>>> anrPnfs = new HashMap<>(); + + List removeableNeighbors; + for(AnrSolutions anrSolution : anrSolutions) { + String cellId = anrSolution.getCellId(); + String pnfName = SdnrRestClient.getPnfName(cellId); + removeableNeighbors = anrSolution.getRemoveableNeighbors(); + Map> cellRemNeighborsPair = new HashMap<>(); + cellRemNeighborsPair.put(cellId, removeableNeighbors); + if(anrPnfs.containsKey(pnfName)) { + anrPnfs.get(pnfName).add(cellRemNeighborsPair); + }else { + List>> anrCells = new ArrayList<>(); + anrCells.add(cellRemNeighborsPair); + anrPnfs.put(pnfName, anrCells); + } + } + log.info("anr Pnfs {}",anrPnfs.toString()); + return anrPnfs; + + } } 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 76e7929..767dae2 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 @@ -80,7 +80,7 @@ public class ConfigFetchFromCbs { log.info("Updating configuration from CBS"); Configuration configuration = Configuration.getInstance(); - log.debug("configuration from CBS {}", jsonObject); + log.info("configuration from CBS {}", jsonObject); Type mapType = new TypeToken>() {}.getType(); @@ -109,8 +109,8 @@ public class ConfigFetchFromCbs { int bufferTime = jsonObject.get("sonhandler.bufferTime").getAsInt(); String cid = jsonObject.get("sonhandler.cid").getAsString(); String configDbService = jsonObject.get("sonhandler.configDb.service").getAsString(); - - String callbackUrl = "http://" + System.getenv("HOSTNAME") + ":8080/callbackUrl"; + 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); @@ -144,6 +144,8 @@ public class ConfigFetchFromCbs { configuration.setPollingTimeout(pollingTimeout); configuration.setBadThreshold(badThreshold); configuration.setPoorThreshold(poorThreshold); + log.info("configuration from CBS {}", configuration.toString()); + } } 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 10329ba..15a93e9 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 @@ -21,13 +21,12 @@ package org.onap.dcaegen2.services.sonhms.model; -import java.util.List; import java.util.Map; public class AdditionalMeasurements { String name; - List> arrayOfNamedHashMap; + Map hashMap ; public AdditionalMeasurements() { @@ -38,16 +37,17 @@ public class AdditionalMeasurements { public void setName(String name) { this.name = name; } - public List> getArrayOfNamedHashMap() { - return arrayOfNamedHashMap; + public Map getHashMap() { + return hashMap; } - public void setArrayOfNamedHashMap(List> arrayOfNamedHashMap) { - this.arrayOfNamedHashMap = arrayOfNamedHashMap; + public void setHashMap(Map hashMap) { + this.hashMap = hashMap; } @Override public String toString() { - return "AdditionalMeasurements [name=" + name + ", arrayOfNamedHashMap=" + arrayOfNamedHashMap + "]"; + return "AdditionalMeasurements [name=" + name + ", hashMap=" + hashMap + "]"; } - + + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Event.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Event.java index b958318..73edc39 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Event.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Event.java @@ -25,7 +25,7 @@ import org.onap.dcaegen2.services.sonhms.CommonEventHeader; public class Event { CommonEventHeader commonEventHeader; - Measurement measurement; + MeasurementFields measurementFields; public Event() { @@ -39,13 +39,15 @@ public class Event { this.commonEventHeader = commonEventHeader; } - public Measurement getMeasurement() { - return measurement; + public MeasurementFields getMeasurementFields() { + return measurementFields; } - public void setMeasurement(Measurement measurement) { - this.measurement = measurement; + public void setMeasurementFields(MeasurementFields measurementFields) { + this.measurementFields = measurementFields; } + + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Flag.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Flag.java new file mode 100644 index 0000000..a5a7d65 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Flag.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * ============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 javax.annotation.PostConstruct; + +import org.springframework.stereotype.Component; + +@Component +public class Flag { + + private String holder; + private int numChilds; + + @PostConstruct + void setup() { + holder = "NONE"; + numChilds = 0; + } + + public String getHolder() { + return holder; + } + + public void setHolder(String holder) { + this.holder = holder; + } + + public int getNumChilds() { + return numChilds; + } + + public void setNumChilds(int numChilds) { + this.numChilds = numChilds; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Measurement.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Measurement.java deleted file mode 100644 index c3863b0..0000000 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Measurement.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * ============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 java.util.List; - -public class Measurement { - - String measurementInterval; - List additionalMeasurements; - - /** - * default constructor - */ - public Measurement() { - - } - public String getMeasurementInterval() { - return measurementInterval; - } - - public void setMeasurementInterval(String measurementInterval) { - this.measurementInterval = measurementInterval; - } - - public List getAdditionalMeasurements() { - return additionalMeasurements; - } - - public void setAdditionalMeasurements(List additionalMeasurements) { - this.additionalMeasurements = additionalMeasurements; - } - - -} 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 new file mode 100644 index 0000000..bdd8641 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/MeasurementFields.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============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 java.util.List; + +public class MeasurementFields { + + String measurementInterval; + String measurementFieldsVersion; + + List additionalMeasurements; + + /** + * default constructor + */ + public MeasurementFields() { + + } + public String getMeasurementInterval() { + return measurementInterval; + } + + public void setMeasurementInterval(String measurementInterval) { + this.measurementInterval = measurementInterval; + } + + public List getAdditionalMeasurements() { + return additionalMeasurements; + } + + 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/PolicyNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotification.java index 35480cf..e432b0c 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 @@ -62,7 +62,7 @@ public class PolicyNotification { * Constructor. * */ - public PolicyNotification(String closedLoopControlName, String requestId, Long alarmStartTime, String pnfName) { + public PolicyNotification(String closedLoopControlName, String requestId, Long alarmStartTime, String pnfName, String action) { this.closedLoopControlName = closedLoopControlName; this.requestId = requestId; this.closedLoopEventClient = "microservice.PCI"; @@ -70,7 +70,7 @@ public class PolicyNotification { this.closedLoopAlarmStart = alarmStartTime; this.from = "PCIMS"; this.version = "1.0.2"; - this.action = "ModifyConfig"; + this.action = action; this.target = "generic-vnf.vnf-id"; this.targetType = "VNF"; this.aai = new HashMap<>(); 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 9cb1d18..0f6dd98 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 @@ -70,7 +70,7 @@ public class OofRestClient { requestInfo.setRequestType(requestType); requestInfo.setNumSolutions(numSolutions); requestInfo.setOptimizers(optimizers); - Map callbackHeader = new HashMap<>(); + Map callbackHeader = new HashMap<>(); callbackHeader.put("Content-Type", "application/json"); requestInfo.setCallbackHeader(callbackHeader); ConfigPolicy config = ConfigPolicy.getInstance(); @@ -81,13 +81,14 @@ public class OofRestClient { log.debug("No config policy available. Using default timeout 60 sec"); } requestInfo.setTimeout(timeout); - + CellInfo cellInfo = new CellInfo(); cellInfo.setCellIdList(cellIdList); cellInfo.setNetworkId(networkId); cellInfo.setTrigger("NbrListChange"); - if(!anrInputList.isEmpty()) + if (!anrInputList.isEmpty()) { cellInfo.setAnrInputList(anrInputList); + } OofRequestBody oofRequestBody = new OofRequestBody(); oofRequestBody.setRequestInfo(requestInfo); oofRequestBody.setCellInfo(cellInfo); @@ -98,11 +99,11 @@ public class OofRestClient { requestBody = mapper.writeValueAsString(oofRequestBody); } catch (JsonProcessingException e) { log.error("Exception when forming JSON String {}", e); - + } - log.debug("requestBody{}", requestBody); + log.info("requestBody{}", requestBody); - String requestUrl = configuration.getOofService() + "/api/oof/v1/pci"; + String requestUrl = configuration.getOofService() + "/api/oof/pci/v1"; log.debug("requestUrl {}", requestUrl); ResponseEntity response = null; response = SonHandlerRestTemplate.sendPostRequestToOof(requestUrl, requestBody, @@ -111,7 +112,7 @@ public class OofRestClient { if (response == null) { throw new OofNotFoundException("Request to oof failed"); } - log.debug("response {}", response); + log.info("response {}", response); return response.getBody(); } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java index 65bd756..2478f82 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java @@ -37,8 +37,6 @@ import org.slf4j.LoggerFactory; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.ResponseEntity; - - public class SdnrRestClient { private static final String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss"; @@ -48,20 +46,6 @@ public class SdnrRestClient { } - /** - * Method to get cell list from SDNR. - * - * @throws ConfigDbNotFoundException - * when request to configDB fails - */ - public static String getCellList(String networkId) throws ConfigDbNotFoundException { - Configuration configuration = Configuration.getInstance(); - String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis())); - String requestUrl = configuration.getConfigDbService() + "/SDNCConfigDBAPI/getCellList" + "/" + networkId + "/" - + ts; - return sendRequest(requestUrl); - } - /** * Method to get neibhbour list from SDNR. * @@ -71,16 +55,19 @@ public class SdnrRestClient { public static List getNbrList(String cellId) throws ConfigDbNotFoundException { Configuration configuration = Configuration.getInstance(); String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis())); - String requestUrl = configuration.getConfigDbService() + "/SDNCConfigDBAPI/getNbrList" + "/" + cellId + "/" - + ts; + String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getNbrList" + "/" + cellId + + "/" + ts; log.debug("request url: {}", requestUrl); String response = sendRequest(requestUrl); List nbrList = new ArrayList<>(); - JSONArray nbrListObj = new JSONArray(response); + JSONObject responseJson = new JSONObject(response); + JSONArray nbrListObj = responseJson.getJSONArray("nbrList"); for (int i = 0; i < nbrListObj.length(); i++) { JSONObject cellObj = nbrListObj.getJSONObject(i); - CellPciPair cell = new CellPciPair(cellObj.getString("cellId"), cellObj.getInt("pciValue")); - nbrList.add(cell); + if (cellObj.getBoolean("ho")) { + CellPciPair cell = new CellPciPair(cellObj.getString("targetCellId"), cellObj.getInt("pciValue")); + nbrList.add(cell); + } } return nbrList; @@ -95,7 +82,7 @@ public class SdnrRestClient { public static int getPci(String cellId) throws ConfigDbNotFoundException { Configuration configuration = Configuration.getInstance(); String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis())); - String requestUrl = configuration.getConfigDbService() + "/SDNCConfigDBAPI/getPCI" + "/" + cellId + "/" + String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getPCI" + "/" + cellId + "/" + ts; String response = sendRequest(requestUrl); JSONObject respObj = new JSONObject(response); @@ -111,24 +98,24 @@ public class SdnrRestClient { public static String getPnfName(String cellId) throws ConfigDbNotFoundException { Configuration configuration = Configuration.getInstance(); String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis())); - String requestUrl = configuration.getConfigDbService() + "/SDNCConfigDBAPI/getPnfName" + "/" + cellId + "/" - + ts; + String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getPnfId" + "/" + cellId + "/" + + ts; String response = sendRequest(requestUrl); JSONObject responseObject = new JSONObject(response); return responseObject.getString("value"); } - /** * Method to send request. */ private static String sendRequest(String url) throws ConfigDbNotFoundException { ResponseEntity response = SonHandlerRestTemplate.sendGetRequest(url, - new ParameterizedTypeReference() {}); + new ParameterizedTypeReference() { + }); if (response == null) { throw new ConfigDbNotFoundException("Cannot reach Config DB"); } - return response.getBody(); + return response.getBody(); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ThreadUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ThreadUtils.java index 96b1a24..5889b63 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ThreadUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ThreadUtils.java @@ -1,22 +1,23 @@ /******************************************************************************* - * ============LICENSE_START======================================================= - * pcims + * ============LICENSE_START======================================================= + * son-handler * ================================================================================ - * Copyright (C) 2018 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========================================================= - ******************************************************************************/ + * 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.utils; diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 28586fd..ae59b6e 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,43 +1,38 @@ - - - - - logFileName - log - + + + + + + + %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + + + + + + + - - - /var/log/onap/son-handler/${logFileName}.log - - ${logFileName}.%i.log.zip - 1 - 5 - - - 5MB - - - %d{dd-MM-yyyy HH:mm:ss.SSS} %magenta([%thread]) - %highlight(%-5level) %logger{36}.%M - %msg%n - - - - - - - diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java index 02a061b..8f161a7 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java @@ -1,22 +1,23 @@ /******************************************************************************* - * ============LICENSE_START======================================================= - * pcims + * ============LICENSE_START======================================================= + * son-handler * ================================================================================ - * Copyright (C) 2018 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========================================================= - ******************************************************************************/ + * 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; diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/FaultFieldsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/FaultFieldsTest.java index c940917..19f3815 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/FaultFieldsTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/FaultFieldsTest.java @@ -38,7 +38,7 @@ public class FaultFieldsTest { faultFields.setEventSeverity("eventSeverity"); faultFields.setEventSourceType("eventSourceType"); - faultFields.setFaultFieldsVersion(0); + faultFields.setFaultFieldsVersion(4.0); faultFields.setAlarmAdditionalInformation(alarmAdditionalInformation); faultFields.setSpecificProblem("specificProblem"); @@ -46,7 +46,7 @@ public class FaultFieldsTest { assertEquals("alarmCondition", faultFields.getAlarmCondition()); assertEquals(1, faultFields.getAlarmAdditionalInformation().getCollisions()); assertEquals(3, faultFields.getAlarmAdditionalInformation().getConfusions()); - assertEquals(0, faultFields.getFaultFieldsVersion()); + assertEquals(4.0, faultFields.getFaultFieldsVersion(), 0); assertEquals("eventSeverity", faultFields.getEventSeverity()); assertEquals("eventSourceType", faultFields.getEventSourceType()); assertEquals("networkId", faultFields.getAlarmAdditionalInformation().getNetworkId()); 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 e2e702c..9cae5b6 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java @@ -1,22 +1,23 @@ /******************************************************************************* - * ============LICENSE_START======================================================= - * pcims + * ============LICENSE_START======================================================= + * son-handler * ================================================================================ - * Copyright (C) 2018 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========================================================= - ******************************************************************************/ + * 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; @@ -38,6 +39,7 @@ import org.mockito.Mockito; 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.utils.BeanUtil; import org.powermock.api.mockito.PowerMockito; @@ -56,8 +58,11 @@ public class PMNotificationHandlerTest { @Mock HandOverMetricsRepository handOverMetricsRepositoryMock; + @Mock + Flag flagMock; + @InjectMocks - PMNotificationHandler pmNotificationHandler; + PmNotificationHandler pmNotificationHandler; @Mock PolicyDmaapClient policyDmaapClient; @@ -88,7 +93,10 @@ public class PMNotificationHandlerTest { PowerMockito.mockStatic(BeanUtil.class); PowerMockito.when(BeanUtil .getBean(HandOverMetricsRepository.class)).thenReturn(handOverMetricsRepositoryMock); + PowerMockito.when(BeanUtil + .getBean(Flag.class)).thenReturn(flagMock); when(handOverMetricsRepositoryMock.save(new HandOverMetrics())).thenReturn(null); + when(flagMock.getHolder()).thenReturn("NONE"); when(policyDmaapClient.sendNotificationToPolicy(Mockito.anyString())).thenReturn(true); assertTrue(pmNotificationHandler.handlePmNotifications(pmNotification, 50)); assertFalse(pmNotificationHandler.handlePmNotifications(null, 0)); 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 ab4119d..536f327 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 @@ -55,7 +55,6 @@ import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.model.PolicyNotification; import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; -import org.onap.dcaegen2.services.sonhms.restclient.Solutions; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest; import org.powermock.api.mockito.PowerMockito; @@ -153,7 +152,7 @@ public class TestChildThreadUtils { String requestId = "a4130fd5-2291-4a83-8992-04e4c9f32731"; Long alarmStart = Long.parseLong("1542445563201"); - String result = childThreadUtils.getNotificationString(pnfName, cellPciPairs, requestId, alarmStart); + String result = childThreadUtils.getNotificationString(pnfName, requestId, "payloadString", alarmStart, "action"); PolicyNotification actual = new PolicyNotification(); try { actual = mapper.readValue(result, PolicyNotification.class); @@ -188,8 +187,18 @@ public class TestChildThreadUtils { pciPairList.add(cell2); pciPairList.add(cell3); pnfsMap.put("pnf1", pciPairList); - when(pnfUtils.getPnfs(Mockito.any(Solutions.class))).thenReturn(pnfsMap); - childThreadUtils.sendToPolicy(async); + when(pnfUtils.getPnfs(async.getSolutions())).thenReturn(pnfsMap); + List remNeighbors = new ArrayList<>(); + remNeighbors.add("EXP006"); + Map> cellRemNeighborsPair = new HashMap<>(); + cellRemNeighborsPair.put("EXP003", remNeighbors); + List>> list = new ArrayList<>(); + list.add(cellRemNeighborsPair); + Map>>> expected = new HashMap<>(); + expected.put("pnfName", list); + when(pnfUtils.getPnfsForAnrSolutions(async.getSolutions().getAnrSolutions())).thenReturn(expected); + assertTrue(childThreadUtils2.sendToPolicy(async)); + } private static String readFromFile(String file) { diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java index 4b36598..d74bff8 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java @@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.sonhms.child; import static org.junit.Assert.assertEquals; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.BufferedReader; @@ -46,6 +47,7 @@ import org.onap.dcaegen2.services.sonhms.dao.CellInfoRepository; import org.onap.dcaegen2.services.sonhms.entity.CellInfo; import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.restclient.AnrSolutions; import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; import org.onap.dcaegen2.services.sonhms.restclient.Solutions; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; @@ -69,6 +71,7 @@ public class TestPnfUtils { private static final Logger log = org.slf4j.LoggerFactory.getLogger(TestPnfUtils.class); private static Solutions solutions = new Solutions(); + private static List anrSolutions = new ArrayList<>(); private static Optional cellInfo; private static Optional cellInfoNull; @@ -81,10 +84,13 @@ public class TestPnfUtils { String solutionsString=readFromFile("/solutions.json"); + String anrSolutionsString = readFromFile("/anrSolutions.json"); ObjectMapper mapper = new ObjectMapper(); try { solutions=mapper.readValue(solutionsString, Solutions.class); + anrSolutions = mapper.readValue(anrSolutionsString, new TypeReference>() { + }); } catch (IOException e) { log.debug("Exception in StateOof Test "+e); e.printStackTrace(); @@ -134,6 +140,33 @@ public class TestPnfUtils { e.printStackTrace(); } } + + @Test + public void testGetPnfsForAnrSolutions() { + Map>>> actual = null ; + Map>>> expected = new HashMap<>(); + try { + PowerMockito.mockStatic(SdnrRestClient.class); + PowerMockito.when(SdnrRestClient.getPnfName(Mockito.anyString())).thenReturn("ncServer1"); + actual = pnfUtils.getPnfsForAnrSolutions(anrSolutions); + } catch (ConfigDbNotFoundException e) { + e.printStackTrace(); + } + List remNeighbors1 = new ArrayList<>(); + List remNeighbors2 = new ArrayList<>(); + remNeighbors1.add("cell2"); + remNeighbors1.add("cell3"); + remNeighbors2.add("cell9"); + Map> cellRemNeighborsPair1 = new HashMap<>(); + Map> cellRemNeighborsPair2 = new HashMap<>(); + cellRemNeighborsPair1.put("cell1", remNeighbors1); + cellRemNeighborsPair2.put("cell8", remNeighbors2); + List>> list = new ArrayList<>(); + list.add(cellRemNeighborsPair1); + list.add(cellRemNeighborsPair2); + expected.put("ncServer1", list); + assertEquals(expected, actual); + } private static String readFromFile(String file) { String content = new String(); try { diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java index 1557e51..59eacc9 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java @@ -37,7 +37,6 @@ import org.mockito.MockitoAnnotations; import org.onap.dcaegen2.services.sonhms.Configuration; import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; -import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -64,36 +63,20 @@ public class SdnrRestClientTest { MockitoAnnotations.initMocks(this); } - @Test - public void getCellListTest() { - - String responseBody="[\n" + - " \"string\"\n" + - "]"; - PowerMockito.mockStatic(SonHandlerRestTemplate.class); - PowerMockito.mockStatic(BeanUtil.class); - PowerMockito.mockStatic(Configuration.class); - PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); - PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.>any())) - .thenReturn(ResponseEntity.ok(responseBody)); - try { - String result=SdnrRestClient.getCellList("12345"); - assertEquals(ResponseEntity.ok(responseBody).getBody(),result); - } catch (ConfigDbNotFoundException e) { - log.debug("ConfigDbNotFoundException {}",e.toString());; - } - - } @Test public void getNbrListTest() { - String responseBody="[\n" + - " {\n" + - " \"cellId\": \"string\",\n" + - " \"pciValue\": 0\n" + - " }\n" + - "]"; + String responseBody="{\n" + + " \"cellId\": \"string\",\n" + + " \"nbrList\": [\n" + + " {\n" + + " \"ho\": true,\n" + + " \"pciValue\": 0,\n" + + " \"targetCellId\": \"string\"\n" + + " }\n" + + " ]\n" + + "}"; PowerMockito.mockStatic(SonHandlerRestTemplate.class); PowerMockito.mockStatic(Configuration.class); PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); @@ -103,11 +86,14 @@ public class SdnrRestClientTest { List result=SdnrRestClient.getNbrList("1"); List nbrList = new ArrayList<>(); String response=ResponseEntity.ok(responseBody).getBody(); - JSONArray nbrListObj = new JSONArray(response); + JSONObject responseJson = new JSONObject(response); + JSONArray nbrListObj = responseJson.getJSONArray("nbrList"); for (int i = 0; i < nbrListObj.length(); i++) { JSONObject cellObj = nbrListObj.getJSONObject(i); - CellPciPair cell = new CellPciPair(cellObj.getString("cellId"), cellObj.getInt("pciValue")); - nbrList.add(cell); + if (cellObj.getBoolean("ho")) { + CellPciPair cell = new CellPciPair(cellObj.getString("targetCellId"), cellObj.getInt("pciValue")); + nbrList.add(cell); + } } assertEquals(nbrList,result); } catch (ConfigDbNotFoundException e) { diff --git a/src/test/resources/anrSolutions.json b/src/test/resources/anrSolutions.json new file mode 100644 index 0000000..77291a3 --- /dev/null +++ b/src/test/resources/anrSolutions.json @@ -0,0 +1,15 @@ +[ + { + "cellId":"cell1", + "removeableNeighbors":[ + "cell2", + "cell3" + ] + }, + { + "cellId":"cell8", + "removeableNeighbors":[ + "cell9" + ] + } +] diff --git a/src/test/resources/pmNotification.json b/src/test/resources/pmNotification.json index a956ae4..7b9dbe1 100644 --- a/src/test/resources/pmNotification.json +++ b/src/test/resources/pmNotification.json @@ -1,56 +1,44 @@ - - { - "event":{ +{ + "event":{ "commonEventHeader":{ - "version":"4.0", - "domain":"measurement", - "eventName":"Measurement_RansimAgent-Wipro_HandoffMetric", - "eventId":"measurement000001", - "sequence":0, - "priority":"Normal", - "reportingEntityId":"cc305d54-75b4-431b-adb2-eb6b9e541234", - "reportingEntityName":"ncserver1", - "sourceId":"de305d54-75b4-431b-adb2-eb6b9e546456", - "sourceName":"Chn0001", - "startEpochMicrosec":1551772223000000, - "lastEpochMicrosec":1551790542000000, - "nfNamingCode":"RansimAgent", - "nfVendorName":"Wipro", - "vesEventListenerVersion":"7.0.1", - "timeZoneOffset":"UTC-05:30" + "version":"4.0.1", + "domain":"measurement", + "eventName":"Measurement_RansimAgent-Wipro_HandoffMetric", + "eventId":"measurement000001", + "sequence":0, + "priority":"Normal", + "reportingEntityId":"cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName":"ncserver1", + "sourceId":"de305d54-75b4-431b-adb2-eb6b9e546456", + "sourceName":"Chn0001", + "startEpochMicrosec":1551772223000000, + "lastEpochMicrosec":1551790542000000, + "nfNamingCode":"RansimAgent", + "nfVendorName":"Wipro", + "vesEventListenerVersion":"7.0.1", + "timeZoneOffset":"UTC-05:30" }, - "measurement":{ - "measurementInterval":180, - "additionalMeasurements":[ - { - "arrayOfNamedHashMap":[ - { - "networkId":"plmnid1" - }, - { - "InterEnbOutAtt_X2HO":"200" - }, - { - "InterEnbOutSucc_X2HO":"190" - } - ], - "name":"Chn0014" - }, - { - "arrayOfNamedHashMap":[ - { - "networkId":"plmnid1" - }, - { - "InterEnbOutAtt_X2HO":"300" - }, - { - "InterEnbOutSucc_X2HO":"210" - } - ], - "name":"Chn0013" - } - ] + "measurementFields":{ + "measurementInterval":180, + "measurementFieldsVersion":"4.0", + "additionalMeasurements":[ + { + "hashMap":{ + "networkId":"plmnid1", + "InterEnbOutAtt_X2HO":"200", + "InterEnbOutSucc_X2HO":"190" + }, + "name":"Chn0014" + }, + { + "hashMap":{ + "networkId":"plmnid1", + "InterEnbOutAtt_X2HO":"300", + "InterEnbOutSucc_X2HO":"210" + }, + "name":"Chn0013" + } + ] } - } - } + } +} \ No newline at end of file diff --git a/src/test/resources/pmNotification1.json b/src/test/resources/pmNotification1.json index 0f046e2..2ad6aa7 100644 --- a/src/test/resources/pmNotification1.json +++ b/src/test/resources/pmNotification1.json @@ -1,55 +1,45 @@ -{ - "event": { - "commonEventHeader": { - "version": "4.0", - "domain": "measurement", - "eventName": "Measurement_RansimAgent-Wipro_HandoffMetric", - "eventId": "measurement000002", - "sequence": 0, - "priority": "Normal", - "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e544567", - "reportingEntityName": "ncserver1", - "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546456", - "sourceName": "Chn0002", - "startEpochMicrosec": 1551772223000000, - "lastEpochMicrosec": 1551790542000000, - "nfNamingCode": "RansimAgent", - "nfVendorName": "Wipro", - "vesEventListenerVersion": "7.0.1", - "timeZoneOffset": "UTC-05:30" + + { + "event":{ + "commonEventHeader":{ + "version":"4.0.1", + "domain":"measurement", + "eventName":"Measurement_RansimAgent-Wipro_HandoffMetric", + "eventId":"measurement000001", + "sequence":0, + "priority":"Normal", + "reportingEntityId":"cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName":"ncserver1", + "sourceId":"de305d54-75b4-431b-adb2-eb6b9e546456", + "sourceName":"Chn0002", + "startEpochMicrosec":1551772223000000, + "lastEpochMicrosec":1551790542000000, + "nfNamingCode":"RansimAgent", + "nfVendorName":"Wipro", + "vesEventListenerVersion":"7.0.1", + "timeZoneOffset":"UTC-05:30" }, - "measurement": { - "measurementInterval": 180, - "additionalMeasurements": [ - { - "arrayOfNamedHashMap": [ - { - "networkId":"plmnid1" - }, - { - "InterEnbOutAtt_X2HO":"300" - }, - { - "InterEnbOutSucc_X2HO":"100" - } - ], - "name": "Chn0004" - }, - { - "arrayOfNamedHashMap": [ - { - "networkId":"plmnid1" - }, - { - "InterEnbOutAtt_X2HO":"250" - }, - { - "InterEnbOutSucc_X2HO":"100" - } - ], - "name": "Chn0001" - } - ] + "measurementFields":{ + "measurementInterval":180, + "measurementFieldsVersion":"4.0", + "additionalMeasurements":[ + { + "hashMap":{ + "networkId":"plmnid1", + "InterEnbOutAtt_X2HO":"300", + "InterEnbOutSucc_X2HO":"100" + }, + "name":"Chn0004" + }, + { + "hashMap":{ + "networkId":"plmnid1", + "InterEnbOutAtt_X2HO":"250", + "InterEnbOutSucc_X2HO":"100" + }, + "name":"Chn0001" + } + ] } - } - } + } +} \ No newline at end of file diff --git a/src/test/resources/policy_notification.json b/src/test/resources/policy_notification.json index 3863d1c..b99a8b9 100644 --- a/src/test/resources/policy_notification.json +++ b/src/test/resources/policy_notification.json @@ -8,11 +8,11 @@ "requestID": "a4130fd5-2291-4a83-8992-04e4c9f32731", "from": "PCIMS", "version": "1.0.2", - "payload": "{\"Configurations\":[{\"data\":{\"FAPService\":{\"alias\":\"Chn0330\",\"X0005b9Lte\":{\"phyCellIdInUse\":6,\"pnfName\":\"ncserver23\"},\"CellConfig\":{\"LTE\":{\"RAN\":{\"Common\":{\"CellIdentity\":\"Chn0330\"}}}}}}},{\"data\":{\"FAPService\":{\"alias\":\"Chn0331\",\"X0005b9Lte\":{\"phyCellIdInUse\":7,\"pnfName\":\"ncserver23\"},\"CellConfig\":{\"LTE\":{\"RAN\":{\"Common\":{\"CellIdentity\":\"Chn0331\"}}}}}}}]}", + "payload": "payloadString", "AAI": { "generic-vnf.prov-status": "ACTIVE", "generic-vnf.is-closed-loop-disabled": "false", "generic-vnf.vnf-id": "ncserver23" }, - "Action": "ModifyConfig" + "Action": "action" } -- cgit 1.2.3-korg