From d629f558e1fafd8130f265ec3876fa85f5646ae4 Mon Sep 17 00:00:00 2001 From: malar Date: Wed, 19 Jan 2022 14:23:36 +0000 Subject: Fix bug in triggering control loop for PCI collision/confusion - by replacing Config DB with CPS Issue-ID: DCAEGEN2-3057 Signed-off-by: Malarvizhi Paramasivam Change-Id: I122022c1ad7e4dc007e8565bac694813d4a35bef --- .../dcaegen2/services/sonhms/Configuration.java | 51 +++++++++++----------- .../services/sonhms/restclient/CpsClient.java | 23 +++++++--- .../services/sonhms/restclient/SdnrRestClient.java | 16 ++++--- .../services/sonhms/restclient/CpsClientTest.java | 19 ++++---- 4 files changed, 63 insertions(+), 46 deletions(-) (limited to 'src') 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 2ddeaa6..1824e92 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019-2021 Wipro Limited. + * Copyright (C) 2019-2022 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -390,28 +390,28 @@ public class Configuration { } public int getPolicyNegativeAckThreshold() { - return policyNegativeAckThreshold; - } + return policyNegativeAckThreshold; + } - public void setPolicyNegativeAckThreshold(int policyNegativeAckThreshold) { - this.policyNegativeAckThreshold = policyNegativeAckThreshold; - } + public void setPolicyNegativeAckThreshold(int policyNegativeAckThreshold) { + this.policyNegativeAckThreshold = policyNegativeAckThreshold; + } - public long getPolicyFixedPciTimeInterval() { - return policyFixedPciTimeInterval; - } + public long getPolicyFixedPciTimeInterval() { + return policyFixedPciTimeInterval; + } - public void setPolicyFixedPciTimeInterval(long policyFixedPciTimeInterval) { - this.policyFixedPciTimeInterval = policyFixedPciTimeInterval; - } + public void setPolicyFixedPciTimeInterval(long policyFixedPciTimeInterval) { + this.policyFixedPciTimeInterval = policyFixedPciTimeInterval; + } - public String getNfNamingCode() { - return nfNamingCode; - } + public String getNfNamingCode() { + return nfNamingCode; + } - public void setNfNamingCode(String nfNamingCode) { - this.nfNamingCode = nfNamingCode; - } + public void setNfNamingCode(String nfNamingCode) { + this.nfNamingCode = nfNamingCode; + } public static Logger getLog() { return log; @@ -465,13 +465,6 @@ public class Configuration { Configuration.instance = instance; } - public ConfigInterface getConfigurationClient() - { - ConfigInterface conf = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()); - log.info("ConfigurationClient obj is : " + conf); - return conf; - } - @Override public String toString() { return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword=" @@ -554,12 +547,18 @@ public class Configuration { getCellDataUrl = jsonObject.get("cps.get.celldata").getAsString(); getPnfUrl = jsonObject.get("cps.get.pnf.url").getAsString(); getPciUrl = jsonObject.get("cps.get.pci.url").getAsString(); + getNbrListUrl = jsonObject.get("cps.get.nbr.list.url").getAsString(); ConfigClientType = jsonObject.get("sonhandler.clientType").getAsString(); log.info("configuration from CBS {}", this); } - + public ConfigInterface getConfigurationClient() + { + ConfigInterface conf = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()); + log.info("ConfigurationClient obj is : " + conf); + return conf; + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java index f19c9e8..282fe91 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2021 Wipro Limited. + * Copyright (C) 2021-2022 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,9 +65,10 @@ public class CpsClient extends ConfigInterface { reqbody.put("inputParameters", inputparam); log.debug("request url: {}", requestUrl); String response = sendRequest(requestUrl, reqbody); + log.info("Response from CPS is : " + response); List nbrList = new ArrayList<>(); - - JSONArray nbrListObj = new JSONArray(response); + JSONObject responseJson = new JSONObject(response); + JSONArray nbrListObj = responseJson.getJSONArray("NRCellRelation"); for (int i = 0; i < nbrListObj.length(); i++) { JSONObject cellObj = nbrListObj.getJSONObject(i); JSONObject obj = cellObj.getJSONObject("attributes"); @@ -95,8 +96,11 @@ public class CpsClient extends ConfigInterface { inputparam.put("cellId", cellId); reqbody.put("inputParameters", inputparam); String response = sendRequest(requestUrl, reqbody); + log.info("Response from CPS is : " + response); JSONObject respObj = new JSONObject(response); - return respObj.getInt("value"); + int obj = respObj.getInt("nRPCI"); + log.info("The nRPCI value is " + obj ); + return respObj.getInt("nRPCI"); } /** @@ -107,14 +111,20 @@ public class CpsClient extends ConfigInterface { @Override public String getPnfName(String cellId) throws CpsNotFoundException { Configuration configuration = Configuration.getInstance(); + String responseObject = ""; String requestUrl = configuration.getCpsServiceUrl() + "/" + configuration.getGetPnfUrl(); JSONObject inputparam = new JSONObject(); JSONObject reqbody = new JSONObject(); inputparam.put("cellId", cellId); reqbody.put("inputParameters", inputparam); String response = sendRequest(requestUrl, reqbody); - JSONObject responseObject = new JSONObject(response); - return responseObject.getString("value"); + log.info("Response from CPS is : " + response); + JSONArray requestArray = new JSONArray(response); + for (int i=0;i nbrList = new ArrayList<>(); JSONObject responseJson = new JSONObject(response); JSONArray nbrListObj = responseJson.getJSONArray("nbrList"); @@ -94,6 +95,7 @@ public class SdnrRestClient extends ConfigInterface { String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getPCI" + "/" + cellId + "/" + ts; String response = sendRequest(requestUrl); + log.info("Response from configdb getPci is : " + response); JSONObject respObj = new JSONObject(response); return respObj.getInt("value"); } @@ -112,6 +114,7 @@ public class SdnrRestClient extends ConfigInterface { String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getPnfId" + "/" + cellId + "/" + ts; String response = sendRequest(requestUrl); + log.info("Response from configdb getPnfName is : " + response); JSONObject responseObject = new JSONObject(response); return responseObject.getString("value"); } @@ -125,11 +128,12 @@ public class SdnrRestClient extends ConfigInterface { @Override public JSONObject getCellData(String cellId) throws ConfigDbNotFoundException { - Configuration configuration = Configuration.getInstance(); - String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getCell" + "/" + cellId; - String response = sendRequest(requestUrl); - JSONObject responseObject = new JSONObject(response); - return responseObject; + Configuration configuration = Configuration.getInstance(); + String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getCell" + "/" + cellId; + String response = sendRequest(requestUrl); + log.info("Response from configdb getCellData is : " + response); + JSONObject responseObject = new JSONObject(response); + return responseObject; } diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java index a531b4d..e43a635 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2021 Wipro Limited. + * Copyright (C) 2021-2022 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -103,7 +103,7 @@ public class CpsClientTest { @Test public void getPciTest() { - String responseBody = "{\n" + " \"attribute-name\": \"string\",\n" + " \"value\": 0\n" + "}"; + String responseBody = "{\n" + " \"nRPCI\": \"11\",\n" + " \"value\": 0\n" + "}"; PowerMockito.mockStatic(SonHandlerRestTemplate.class); PowerMockito.mockStatic(Configuration.class); PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); @@ -116,7 +116,7 @@ public class CpsClientTest { int result = cps.getPci("1"); String response = ResponseEntity.ok(responseBody).getBody(); JSONObject respObj = new JSONObject(response); - assertEquals(respObj.getInt("value"), result); + assertEquals(respObj.getInt("nRPCI"), result); } catch (CpsNotFoundException e) { log.debug("CpsNotFoundException {}", e.toString()); ; @@ -127,7 +127,7 @@ public class CpsClientTest { @Test public void getPnfNameTest() { - String responseBody = "{\n" + " \"attribute-name\": \"string\",\n" + " \"value\": \"string\"\n" + "}"; + String responseBody = "[{\n" + " \"idGNBCUCPFunction\": \"cucpserver1\",\n" + " \"value\": \"string\"\n" + "}]"; PowerMockito.mockStatic(SonHandlerRestTemplate.class); PowerMockito.mockStatic(Configuration.class); PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); @@ -136,10 +136,13 @@ public class CpsClientTest { Matchers.>any())) .thenReturn(ResponseEntity.ok(responseBody)); try { - String result = cps.getPnfName("1"); + String result = cps.getPnfName("cucpserver1"); String response = ResponseEntity.ok(responseBody).getBody(); - JSONObject respObj = new JSONObject(response); - assertEquals(respObj.getString("value"), result); + + JSONArray requestArray = new JSONArray(response); + for (int i=0;i