Refactored code for standardizing configuration retrieval through common method 67/123767/4 2.1.4
authormalar <malarvizhi.44@wipro.com>
Wed, 1 Sep 2021 15:09:10 +0000 (15:09 +0000)
committermalar <malarvizhi.44@wipro.com>
Fri, 3 Sep 2021 04:35:44 +0000 (04:35 +0000)
Issue-ID: DCAEGEN2-2905
Signed-off-by: Malarvizhi Paramasivam <malarvizhi.44@wipro.com>
Change-Id: Id268e066093d63f93ba3679831f2875e4afbaada

Changelog.md
src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java
src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java
src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java
src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java
src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java
src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java
src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java
src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java

index d2e3f47..02649a6 100644 (file)
@@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/)
 and this project adheres to [Semantic Versioning](http://semver.org/).
 
-## [2.1.4] - 21/06/2021
+## [2.1.4] - 2021/06/21
          - [DCAEGEN2-2711](https://jira.onap.org/browse/DCAEGEN2-2711) - Update sdk version to load policies from a file mounted by policy sidecar container
          - [DCAEGEN2-2809](https://jira.onap.org/browse/DCAEGEN2-2809) - Remove security vulnerabilities
          - [DCAEGEN2-2884](https://jira.onap.org/browse/DCAEGEN2-2884) - Update FM message spec to VES 7.2
          - [DCAEGEN2-2883](https://jira.onap.org/browse/DCAEGEN2-2883) - Implement CPS Client in SON Handler
+         - [DCAEGEN2-2905](https://jira.onap.org/browse/DCAEGEN2-2905) - Refactored code for standardizing configuration retrieval through common method
 
-## [2.1.3] - 03/02/2021
+## [2.1.3] - 2021/02/03
          - [DCAEGEN2-2599](https://jira.onap.org/browse/DCAEGEN2-2599) - Remove security vulnerabilities
index 8b05f8c..d0a8702 100644 (file)
@@ -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<Map<String, Object>>() {
         }.getType();
 
+
         JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes");
         streamsSubscribes = new Gson().fromJson(subscribes, mapType);
 
index 3964927..5e98eb4 100644 (file)
@@ -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<String> 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);
index 5876d2b..6b60992 100644 (file)
@@ -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<String, ArrayList<Integer>> 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);
index 1787b3f..5a2eaa5 100644 (file)
@@ -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<String> 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<String, List<String>> cellRemNeighborsPair = new HashMap<>();
             cellRemNeighborsPair.put(cellId, removeableNeighbors);
index 7198fce..7ac3b9e 100644 (file)
@@ -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<ClusterDetails> getAllClusters() {
         ClusterDetailsComponent clusterDetailsComponent = new ClusterDetailsComponent();
@@ -250,7 +252,7 @@ public class ClusterUtils {
             val1.setPhysicalCellId(phy);
             cluster.addEdge(val, val1);
 
-            List<CellPciPair> nbrList = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getNbrList(cell);
+            List<CellPciPair> nbrList = config.getConfigurationClient().getNbrList(cell);
 
             for (CellPciPair nbr : nbrList) {
                 String cid = nbr.getCellId();
@@ -303,12 +305,12 @@ public class ClusterUtils {
      */
     public Map<CellPciPair, ArrayList<CellPciPair>> 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<CellPciPair> cellPciPairs;
-        cellPciPairs = (ArrayList<CellPciPair>) ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getNbrList(cellId);
+        cellPciPairs = (ArrayList<CellPciPair>) config.getConfigurationClient().getNbrList(cellId);
         Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = new HashMap<>();
         clusterMap.put(main, cellPciPairs);
         log.info("clusterMap{}", clusterMap);
index 8baed64..ba3d4c0 100644 (file)
@@ -201,8 +201,7 @@ public class TestChildThreadUtils {
         }
 
                PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr);
-               PowerMockito.when(ConfigurationClient.configClient(config.getConfigClientType()))
-                               .thenReturn(sdnr);
+               PowerMockito.when(config.getConfigurationClient()).thenReturn(sdnr);
                PowerMockito.doReturn(3).when(sdnr, "getPci", Mockito.anyString());
                PowerMockito.doReturn("pnfName").when(sdnr, "getPnfName", Mockito.anyString());
         when(policyDmaapClient.sendNotificationToPolicy(Mockito.anyString())).thenReturn(true);
index e54748b..607f0c0 100644 (file)
@@ -136,7 +136,7 @@ public class TestPnfUtils {
         .thenReturn(cellInfoNull);
         try {
             PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr);
-            PowerMockito.when(ConfigurationClient.configClient(config.getConfigClientType()))
+            PowerMockito.when(config.getConfigurationClient())
                     .thenReturn(sdnr);
             PowerMockito.doReturn(pnfName).when(sdnr, "getPnfName", Mockito.anyString());
             PowerMockito.when(cellInfoRepositoryMock.save(new CellInfo(cellId, pnfName))).thenReturn(new CellInfo());
@@ -169,8 +169,7 @@ public class TestPnfUtils {
 
          try {
              PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr);
-             PowerMockito.when(ConfigurationClient.configClient(config.getConfigClientType()))
-                     .thenReturn(sdnr);
+             PowerMockito.when(config.getConfigurationClient()).thenReturn(sdnr);
              PowerMockito.doReturn("ncServer1").when(sdnr, "getPnfName", Mockito.anyString());
             actual = pnfUtils.getPnfsForAnrSolutions(anrSolutions);
         } catch (ConfigDbNotFoundException e) {
index 32d2a47..104ec88 100644 (file)
@@ -57,6 +57,7 @@ import org.onap.dcaegen2.services.sonhms.model.FapServiceList;
 import org.onap.dcaegen2.services.sonhms.model.Notification;
 import org.onap.dcaegen2.services.sonhms.Configuration;
 import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException;
+import org.onap.dcaegen2.services.sonhms.restclient.ConfigInterface;
 import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient;
 import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
 import org.powermock.api.mockito.PowerMockito;
@@ -172,8 +173,7 @@ public class ClusterUtilsTest {
         Configuration config = Configuration.getInstance();
 
         PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr);
-        PowerMockito.when(ConfigurationClient.configClient(config.getConfigClientType()))
-                .thenReturn(sdnr);
+        PowerMockito.when(config.getConfigurationClient()).thenReturn(sdnr);
         PowerMockito.doReturn(nbrList).when(sdnr, "getNbrList", Mockito.anyString());
 
         clusterMap.put(new CellPciPair("45", 310), (ArrayList<CellPciPair>) firstNbrList);