From ee82f3dc04665e8b86ce5c728a34f9701143e518 Mon Sep 17 00:00:00 2001 From: malar Date: Wed, 1 Sep 2021 15:09:10 +0000 Subject: Refactored code for standardizing configuration retrieval through common method Issue-ID: DCAEGEN2-2905 Signed-off-by: Malarvizhi Paramasivam Change-Id: Id268e066093d63f93ba3679831f2875e4afbaada --- .../java/org/onap/dcaegen2/services/sonhms/Configuration.java | 9 +++++++++ .../org/onap/dcaegen2/services/sonhms/child/ChildThread.java | 6 ++++-- .../onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java | 4 ++-- .../java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java | 5 +++-- .../org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java | 8 +++++--- 5 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java index 8b05f8c..d0a8702 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java @@ -30,6 +30,8 @@ import java.lang.reflect.Type; import java.util.List; import java.util.Map; +import org.onap.dcaegen2.services.sonhms.restclient.ConfigInterface; +import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -463,6 +465,12 @@ public class Configuration { Configuration.instance = instance; } + public ConfigInterface getConfigurationClient() + { + ConfigInterface conf = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()); + return conf; + } + @Override public String toString() { return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword=" @@ -491,6 +499,7 @@ public class Configuration { Type mapType = new TypeToken>() { }.getType(); + JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); streamsSubscribes = new Gson().fromJson(subscribes, mapType); 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 3964927..5e98eb4 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 @@ -61,6 +61,7 @@ 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; +import org.onap.dcaegen2.services.sonhms.restclient.ConfigInterface; import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient; import org.onap.dcaegen2.services.sonhms.restclient.PciSolutions; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; @@ -82,6 +83,7 @@ public class ChildThread implements Runnable { private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThread.class); private static Timestamp startTime; private static String networkId; + Configuration config = Configuration.getInstance(); /** @@ -176,7 +178,7 @@ public class ChildThread implements Runnable { FixedPciCellsRepository fixedPciCellsRepository = BeanUtil.getBean(FixedPciCellsRepository.class); List fixedPciCells = fixedPciCellsRepository.getFixedPciCells(); String cellId = fixedPciCells.get(0); - JSONObject cellData = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getCellData(cellId); + JSONObject cellData = config.getConfigurationClient().getCellData(cellId); networkId = cellData.getJSONObject("Cell").getString("networkId"); } @@ -320,7 +322,7 @@ public class ChildThread implements Runnable { for (PciSolutions pcisolutions : pciSolutionsList) { String cellId = pcisolutions.getCellId(); - int oldPci = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPci(cellId); + int oldPci = config.getConfigurationClient().getPci(cellId); int newPci = pcisolutions.getPci(); PciUpdate pciUpdate = new PciUpdate(); pciUpdate.setCellId(cellId); 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 5876d2b..6b60992 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 @@ -68,6 +68,7 @@ public class ChildThreadUtils { private PnfUtils pnfUtils; private PolicyDmaapClient policyDmaapClient; private HoMetricsComponent hoMetricsComponent; + Configuration configuration = Configuration.getInstance(); /** * Parameterized constructor. @@ -98,7 +99,6 @@ public class ChildThreadUtils { public Boolean triggerOrWait(Map> collisionConfusionResult) { // determine collision or confusion - Configuration configuration = Configuration.getInstance(); int collisionSum = 0; int confusionSum = 0; @@ -226,7 +226,7 @@ public class ChildThreadUtils { lteCell.setBlacklisted("true"); lteCell.setPlmnId(solutions.getNetworkId()); lteCell.setCid(removeableNeighbor); - int pci = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPci(cellId); + int pci = configuration.getConfigurationClient().getPci(cellId); lteCell.setPhyCellId(pci); lteCell.setPnfName(pnfName); lteCellList.add(lteCell); 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 1787b3f..5a2eaa5 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 @@ -45,6 +45,7 @@ import org.slf4j.Logger; public class PnfUtils { private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThreadUtils.class); + Configuration config = Configuration.getInstance(); /** * get pnfs. @@ -64,7 +65,7 @@ public class PnfUtils { if (cellInfo.isPresent()) { pnfName = cellInfo.get().getPnfName(); } else { - pnfName = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPnfName(cellId); + pnfName = config.getConfigurationClient().getPnfName(cellId); cellInfoRepository.save(new CellInfo(cellId, pnfName)); } if (pnfs.containsKey(pnfName)) { @@ -91,7 +92,7 @@ public class PnfUtils { List removeableNeighbors; for (AnrSolutions anrSolution : anrSolutions) { String cellId = anrSolution.getCellId(); - String pnfName = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPnfName(cellId); + String pnfName = config.getConfigurationClient().getPnfName(cellId); removeableNeighbors = anrSolution.getRemoveableNeighbors(); Map> cellRemNeighborsPair = new HashMap<>(); cellRemNeighborsPair.put(cellId, removeableNeighbors); diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java index 7198fce..7ac3b9e 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java @@ -45,6 +45,7 @@ import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.model.FapServiceList; import org.onap.dcaegen2.services.sonhms.model.LteNeighborListInUseLteCell; import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.restclient.ConfigInterface; import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient; import org.onap.dcaegen2.services.sonhms.restclient.CpsClient; import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; @@ -54,6 +55,7 @@ import org.slf4j.LoggerFactory; public class ClusterUtils { private static Logger log = LoggerFactory.getLogger(ClusterUtils.class); + Configuration config = Configuration.getInstance(); public List getAllClusters() { ClusterDetailsComponent clusterDetailsComponent = new ClusterDetailsComponent(); @@ -250,7 +252,7 @@ public class ClusterUtils { val1.setPhysicalCellId(phy); cluster.addEdge(val, val1); - List nbrList = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getNbrList(cell); + List nbrList = config.getConfigurationClient().getNbrList(cell); for (CellPciPair nbr : nbrList) { String cid = nbr.getCellId(); @@ -303,12 +305,12 @@ public class ClusterUtils { */ public Map> findClusterMap(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException { log.info("indide clusterMap"); - int phyCellId = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPci(cellId); + int phyCellId = config.getConfigurationClient().getPci(cellId); CellPciPair main = new CellPciPair(); main.setCellId(cellId); main.setPhysicalCellId(phyCellId); ArrayList cellPciPairs; - cellPciPairs = (ArrayList) ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getNbrList(cellId); + cellPciPairs = (ArrayList) config.getConfigurationClient().getNbrList(cellId); Map> clusterMap = new HashMap<>(); clusterMap.put(main, cellPciPairs); log.info("clusterMap{}", clusterMap); -- cgit 1.2.3-korg