diff options
Diffstat (limited to 'src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java')
-rw-r--r-- | src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java | 127 |
1 files changed, 92 insertions, 35 deletions
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java b/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java index e2223d7..fe809ec 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.java @@ -23,8 +23,13 @@ package org.onap.dcaegen2.services.sonhms; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.ObjectMapper; + +import fj.data.Either; + import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import org.onap.dcaegen2.services.sonhms.child.ChildThreadUtils; @@ -67,34 +72,94 @@ public class PmNotificationHandler { /** * handle PM notifications. */ - public Boolean handlePmNotifications(PmNotification pmNotification, int badThreshold) { - HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); + public Boolean handlePmNotifications(PmNotification pmNotification, int badThreshold, int poorThreshold, + int badCountThreshold) { Boolean result; + Boolean newEntryFlag = false; try { List<HoDetails> hoDetailsList = new ArrayList<>(); List<LteCell> lteCellList = new ArrayList<>(); String srcCellId = pmNotification.getEvent().getCommonEventHeader().getSourceName(); + /* + * check whether entry already exists if yes : read the hometrics and update it + * with latest info else store the current data + */ + HoMetricsComponent hoMetricsComponent = new HoMetricsComponent(); + Either<List<HoDetails>, Integer> hoMetrics = hoMetricsComponent.getHoMetrics(srcCellId); + Map<String, Integer> dstCellIdPcPair = new HashMap<>(); + Map<String, Integer> dstCellIdBcPair = new HashMap<>(); + if (hoMetrics.isLeft()) { + List<HoDetails> oldHoDetailsList = hoMetrics.left().value(); + for (HoDetails hodetail : oldHoDetailsList) { + dstCellIdBcPair.put(hodetail.getDstCellId(), hodetail.getBadCount()); + dstCellIdPcPair.put(hodetail.getDstCellId(), hodetail.getPoorCount()); + } + + } else if (hoMetrics.right().value() == 404) { + newEntryFlag = true; + log.info("no history of srcCell found"); + } 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) { + + if (successRate >= badThreshold && successRate <= poorThreshold) { // poor neighbor HoDetails hoDetails = new HoDetails(); hoDetails.setDstCellId(additionalMeasurements.getName()); hoDetails.setAttemptsCount(attemptsCount); hoDetails.setSuccessCount(successCount); hoDetails.setSuccessRate(successRate); + int pc = 1; + int bc = 0; + if (dstCellIdPcPair.containsKey(additionalMeasurements.getName())) { + pc = dstCellIdPcPair.get(additionalMeasurements.getName()) + 1; + } + hoDetails.setBadCount(bc); + hoDetails.setPoorCount(pc); hoDetailsList.add(hoDetails); - log.info("not bad neighbor {}", additionalMeasurements.getName()); - } else { + log.info("poor neighbor {}", additionalMeasurements.getName()); + } else if (successRate < badThreshold) { // bad neighbor 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); + HoDetails hoDetails = new HoDetails(); + hoDetails.setDstCellId(additionalMeasurements.getName()); + hoDetails.setAttemptsCount(attemptsCount); + hoDetails.setSuccessCount(successCount); + hoDetails.setSuccessRate(successRate); + int bc = 1; + int pc = 0; + if (dstCellIdBcPair.containsKey(additionalMeasurements.getName())) { + bc = dstCellIdBcPair.get(additionalMeasurements.getName()) + 1; + } + if (dstCellIdPcPair.containsKey(additionalMeasurements.getName())) { + pc = dstCellIdPcPair.get(additionalMeasurements.getName()); + } + hoDetails.setBadCount(bc); + hoDetails.setPoorCount(pc); + hoDetailsList.add(hoDetails); + if (bc >= badCountThreshold) { + 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); + hoDetailsList.remove(hoDetails); + } + + } else if (successRate > poorThreshold) { // good neighbor + HoDetails hoDetails = new HoDetails(); + hoDetails.setDstCellId(additionalMeasurements.getName()); + hoDetails.setAttemptsCount(attemptsCount); + hoDetails.setSuccessCount(successCount); + hoDetails.setSuccessRate(successRate); + int pc = 0; + int bc = 0; + hoDetails.setBadCount(bc); + hoDetails.setPoorCount(pc); + hoDetailsList.add(hoDetails); + log.info("good neighbor {}", additionalMeasurements.getName()); } } if (!lteCellList.isEmpty()) { @@ -109,24 +174,21 @@ public class PmNotificationHandler { 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()) { + if (!hoDetailsList.isEmpty() && newEntryFlag) { result = saveToHandOverMetrics(hoDetailsList, srcCellId); log.debug("save HO metrics result {} ", result); + } else if (!hoDetailsList.isEmpty()) { + String hoDetailsString = null; + ObjectMapper mapper = new ObjectMapper(); + try { + hoDetailsString = mapper.writeValueAsString(hoDetailsList); + } catch (Exception e) { + log.error("Error in writing handover metrics json ", e); + return false; + } + hoMetricsComponent.update(hoDetailsString, srcCellId); } } catch (Exception e) { @@ -153,7 +215,7 @@ public class PmNotificationHandler { log.info("payload : {}", payload); String anrUpdateString = mapper.writeValueAsString(payload); ChildThreadUtils childUtils = new ChildThreadUtils(ConfigPolicy.getInstance(), new PnfUtils(), - new PolicyDmaapClient(new DmaapUtils(), Configuration.getInstance())); + new PolicyDmaapClient(new DmaapUtils(), Configuration.getInstance()), new HoMetricsComponent()); String requestId = UUID.randomUUID().toString(); String notification = childUtils.getNotificationString( pmNotification.getEvent().getCommonEventHeader().getReportingEntityName(), requestId, @@ -182,15 +244,10 @@ public class PmNotificationHandler { 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); - } + HandOverMetrics handOverMetrics = new HandOverMetrics(); + handOverMetrics.setHoDetails(hoDetailsString); + handOverMetrics.setSrcCellId(srcCellId); + handOverMetricsRepository.save(handOverMetrics); return true; } } |