diff options
author | krishnaa96 <krishna.moorthy6@wipro.com> | 2019-04-10 14:28:53 +0530 |
---|---|---|
committer | krishnaa96 <krishna.moorthy6@wipro.com> | 2019-04-10 18:01:28 +0530 |
commit | 2896a24832902865313cd16081bba8b2d079748f (patch) | |
tree | feb17dfb42f15d1f33dc76363aa5ce5835ded445 /src/main/java | |
parent | 80b0c61808d0958ef7d38a772a206f2c17dfd2a5 (diff) |
Fix bugs and formatting issues
Added minor functionality changes
License formatting fixed
Change-Id: Ieed4aab7562256eaf15627de0cee53cfe1cc8956
Issue-ID: DCAEGEN2-1111
Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com>
Diffstat (limited to 'src/main/java')
18 files changed, 364 insertions, 213 deletions
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 index 0482b83..0df0bdb 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/PmNotificationHandler.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; @@ -24,6 +25,10 @@ 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; @@ -33,6 +38,7 @@ 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; @@ -44,21 +50,21 @@ import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class PMNotificationHandler { +public class PmNotificationHandler { private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); PolicyDmaapClient policyDmaapClient; - public PMNotificationHandler() { + public PmNotificationHandler() { } - public PMNotificationHandler(PolicyDmaapClient policyDmaapClient) { + public PmNotificationHandler(PolicyDmaapClient policyDmaapClient) { this.policyDmaapClient = policyDmaapClient; } /** - * handle pm notifications. + * handle PM notifications. */ public Boolean handlePmNotifications(PMNotification pmNotification, int badThreshold) { HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); @@ -67,12 +73,12 @@ public class PMNotificationHandler { List<HoDetails> hoDetailsList = new ArrayList<>(); List<LteCell> lteCellList = new ArrayList<>(); String srcCellId = pmNotification.getEvent().getCommonEventHeader().getSourceName(); - for (AdditionalMeasurements additionalMeasurements : pmNotification.getEvent().getMeasurement() + for (AdditionalMeasurements additionalMeasurements : pmNotification.getEvent().getMeasurementFields() .getAdditionalMeasurements()) { int attemptsCount = Integer - .parseInt(additionalMeasurements.getArrayOfNamedHashMap().get(1).get("InterEnbOutAtt_X2HO")); + .parseInt(additionalMeasurements.getHashMap().get("InterEnbOutAtt_X2HO")); int successCount = Integer - .parseInt(additionalMeasurements.getArrayOfNamedHashMap().get(2).get("InterEnbOutSucc_X2HO")); + .parseInt(additionalMeasurements.getHashMap().get("InterEnbOutSucc_X2HO")); float successRate = ((float) successCount / attemptsCount) * 100; if (successRate >= badThreshold) { HoDetails hoDetails = new HoDetails(); @@ -81,21 +87,30 @@ public class PMNotificationHandler { hoDetails.setSuccessCount(successCount); hoDetails.setSuccessRate(successRate); hoDetailsList.add(hoDetails); - log.info("not bad neighbor {}",additionalMeasurements.getName()); + log.info("not bad neighbor {}", additionalMeasurements.getName()); } else { - log.info(" bad neighbor {}",additionalMeasurements.getName()); + 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.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(); @@ -106,7 +121,7 @@ public class PMNotificationHandler { log.error("Error in writing handover metrics json ", e); return false; } - handOverMetricsRepository.updateHoMetrics(newHoDetailsString, srcCellId); + handOverMetricsRepository.updateHoMetrics(newHoDetailsString, srcCellId); } } if (!hoDetailsList.isEmpty()) { @@ -134,11 +149,16 @@ public class PMNotificationHandler { new NeighborListInUse(null, lteCellList, String.valueOf(lteCellList.size())))))))); configurations.add(configuration); Payload payload = new Payload(configurations); - log.info("payload : {}", payload); + 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); - 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; @@ -156,14 +176,13 @@ 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 { + } 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 index 608e61f..d2d509f 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/PMThread.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/PmThread.java @@ -28,24 +28,25 @@ import org.onap.dcaegen2.services.sonhms.model.PMNotification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class PMThread implements Runnable { +public class PmThread implements Runnable { - private static Logger log = LoggerFactory.getLogger(PMThread.class); + private static Logger log = LoggerFactory.getLogger(PmThread.class); private NewPmNotification newPmNotification; + private DmaapNotificationsComponent dmaapNotificationsComponent; - private PMNotificationHandler pmNotificationHandler; + private PmNotificationHandler pmNotificationHandler; /** * parameterized constructor. */ - public PMThread(NewPmNotification newPmNotification) { + public PmThread(NewPmNotification newPmNotification) { super(); this.newPmNotification = newPmNotification; dmaapNotificationsComponent = new DmaapNotificationsComponent(); - pmNotificationHandler = new PMNotificationHandler(new PolicyDmaapClient()); + pmNotificationHandler = new PmNotificationHandler(new PolicyDmaapClient()); } @Override 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<String> 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<List<AnrInput>, 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<AnrInput> 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<List<AnrInput>, Integer> checkAnrTrigger(List<String> cellidList) { List<AnrInput> 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<CellPciPair> cellPciPairs, String requestId, - Long alarmStartTime) { - ArrayList<Configurations> 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<String, List<CellPciPair>> pnfs = pnfUtils.getPnfs(solutions); - for (Map.Entry<String, List<CellPciPair>> entry : pnfs.entrySet()) { String pnfName = entry.getKey(); List<CellPciPair> cellPciPairs = entry.getValue(); + ArrayList<Configurations> 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<String, List<Map<String,List<String>>>> anrPnfs; List<Configurations> configurations = new ArrayList<>(); - for (AnrSolutions anrSolution : solutions.getAnrSolutions()) { - String cellId = anrSolution.getCellId(); - List<LteCell> 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<String, List<Map<String,List<String>>>> entry : anrPnfs.entrySet()) { + String pnfName = entry.getKey(); + for(Map<String,List<String>> cellRemNeighborsPair : anrPnfs.get(pnfName)) { + for(Map.Entry<String, List<String>> entry1 : cellRemNeighborsPair.entrySet()) { + String cellId = entry1.getKey(); + List<LteCell> 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<String, List<Map<String,List<String>>>> getPnfsForAnrSolutions(List<AnrSolutions> anrSolutions) throws ConfigDbNotFoundException { + + Map<String, List<Map<String,List<String>>>> anrPnfs = new HashMap<>(); + + List<String> removeableNeighbors; + for(AnrSolutions anrSolution : anrSolutions) { + String cellId = anrSolution.getCellId(); + String pnfName = SdnrRestClient.getPnfName(cellId); + removeableNeighbors = anrSolution.getRemoveableNeighbors(); + Map<String,List<String>> cellRemNeighborsPair = new HashMap<>(); + cellRemNeighborsPair.put(cellId, removeableNeighbors); + if(anrPnfs.containsKey(pnfName)) { + anrPnfs.get(pnfName).add(cellRemNeighborsPair); + }else { + List<Map<String,List<String>>> 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<Map<String, Object>>() {}.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<String> 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<Map<String,String>> arrayOfNamedHashMap; + Map<String,String> hashMap ; public AdditionalMeasurements() { @@ -38,16 +37,17 @@ public class AdditionalMeasurements { public void setName(String name) { this.name = name; } - public List<Map<String, String>> getArrayOfNamedHashMap() { - return arrayOfNamedHashMap; + public Map<String, String> getHashMap() { + return hashMap; } - public void setArrayOfNamedHashMap(List<Map<String, String>> arrayOfNamedHashMap) { - this.arrayOfNamedHashMap = arrayOfNamedHashMap; + public void setHashMap(Map<String, String> 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/MeasurementFields.java index c3863b0..bdd8641 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Measurement.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/MeasurementFields.java @@ -23,15 +23,17 @@ package org.onap.dcaegen2.services.sonhms.model; import java.util.List; -public class Measurement { +public class MeasurementFields { String measurementInterval; + String measurementFieldsVersion; + List<AdditionalMeasurements> additionalMeasurements; /** * default constructor */ - public Measurement() { + public MeasurementFields() { } public String getMeasurementInterval() { @@ -50,5 +52,12 @@ public class Measurement { 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<String,String> callbackHeader = new HashMap<>(); + Map<String, String> 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<String> 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"; @@ -49,20 +47,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. * * @throws ConfigDbNotFoundException @@ -71,16 +55,19 @@ public class SdnrRestClient { public static List<CellPciPair> 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<CellPciPair> 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<String> response = SonHandlerRestTemplate.sendGetRequest(url, - new ParameterizedTypeReference<String>() {}); + new ParameterizedTypeReference<String>() { + }); 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; |