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 --- .../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 ++-- 21 files changed, 633 insertions(+), 482 deletions(-) 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 (limited to 'src/main/java/org') 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; -- cgit 1.2.3-korg