summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authormalar <malarvizhi.44@wipro.com>2021-08-29 17:17:21 +0000
committermalar <malarvizhi.44@wipro.com>2021-08-29 17:17:21 +0000
commitafb7bc0c146474e2492d29a70fa1c82689e8e3ed (patch)
tree7e5b536066e189e51e38a5fa81adb4dbe2479389 /src/main
parentd9b2a6fef81bf657eac6224dba75254db49c926b (diff)
Implement CPS Client in SON Handler
Issue-ID: DCAEGEN2-2883 Signed-off-by: Malarvizhi Paramasivam <malarvizhi.44@wipro.com> Change-Id: Ife63f6eeb9e277c472a4773fe78345e18b753511
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java100
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java19
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java8
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java8
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java14
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/CpsNotFoundException.java41
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigInterface.java73
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigurationClient.java52
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java149
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java27
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java18
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java3
12 files changed, 473 insertions, 39 deletions
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 563491c..8b05f8c 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-2020 Wipro Limited.
+ * Copyright (C) 2019-2021 Wipro Limited.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,6 +45,11 @@ public class Configuration {
private String pgPassword;
private List<String> dmaapServers;
private String configDbService;
+ private String cpsServiceUrl;
+ private String getCellDataUrl;
+ private String getNbrListUrl;
+ private String getPciUrl;
+ private String getPnfUrl;
private String oofService;
private String oofEndpoint;
private String cg;
@@ -74,6 +79,35 @@ public class Configuration {
private int policyNegativeAckThreshold;
private long policyFixedPciTimeInterval;
private String nfNamingCode;
+ private String ConfigClientType;
+ private String CpsUsername;
+ private String CpsPassword;
+
+ public String getCpsUsername()
+ {
+ return CpsUsername;
+ }
+ public void setCpsUsername(String CpsUsername)
+ {
+ this.CpsUsername = CpsUsername;
+ }
+ public String getCpsPassword()
+ {
+ return CpsPassword;
+ }
+ public void setCpsPassword(String CpsPassword)
+ {
+ this.CpsPassword = CpsPassword;
+ }
+
+ public String getConfigClientType()
+ {
+ return ConfigClientType;
+ }
+ public void setConfigClientType(String ConfigClientType)
+ {
+ this.ConfigClientType = ConfigClientType;
+ }
public int getPoorCountThreshold() {
return poorCountThreshold;
@@ -377,11 +411,64 @@ public class Configuration {
this.nfNamingCode = nfNamingCode;
}
- @Override
+ public static Logger getLog() {
+ return log;
+ }
+
+ public static void setLog(Logger log) {
+ Configuration.log = log;
+ }
+
+ public String getCpsServiceUrl() {
+ return cpsServiceUrl;
+ }
+
+ public void setCpsServiceUrl(String cpsServiceUrl) {
+ this.cpsServiceUrl = cpsServiceUrl;
+ }
+
+ public String getGetCellDataUrl() {
+ return getCellDataUrl;
+ }
+
+ public void setGetCellDataUrl(String getCellDataUrl) {
+ this.getCellDataUrl = getCellDataUrl;
+ }
+
+ public String getGetNbrListUrl() {
+ return getNbrListUrl;
+ }
+
+ public void setGetNbrListUrl(String getNbrListUrl) {
+ this.getNbrListUrl = getNbrListUrl;
+ }
+
+ public String getGetPciUrl() {
+ return getPciUrl;
+ }
+
+ public void setGetPciUrl(String getPciUrl) {
+ this.getPciUrl = getPciUrl;
+ }
+
+ public String getGetPnfUrl() {
+ return getPnfUrl;
+ }
+
+ public void setGetPnfUrl(String getPnfUrl) {
+ this.getPnfUrl = getPnfUrl;
+ }
+
+ public static void setInstance(Configuration instance) {
+ Configuration.instance = instance;
+ }
+
+ @Override
public String toString() {
return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword="
+ pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService
- + ", oofService=" + oofService + ", oofEndpoint=" + oofEndpoint + ", cg=" + cg + ", cid=" + cid
+ + ", cpsServiceUrl=" + cpsServiceUrl + ", CpsUsername=" + CpsUsername + ",CpsPassword=" + CpsPassword + ",ConfigClientType=" + ConfigClientType + ", getCellDataUrl=" + getCellDataUrl + ", getNbrListUrl="
+ + getNbrListUrl + ", getPciUrl=" + getPciUrl + ", getPnfUrl=" + getPnfUrl + ", oofService=" + oofService + ", oofEndpoint=" + oofEndpoint + ", cg=" + cg + ", cid=" + cid
+ ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + ", minCollision="
+ minCollision + ", minConfusion=" + minConfusion + ", sourceId=" + sourceId + ", callbackUrl="
+ callbackUrl + ", pciOptimizer=" + pciOptimizer + ", pciAnrOptimizer=" + pciAnrOptimizer
@@ -410,6 +497,8 @@ public class Configuration {
JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes");
streamsPublishes = new Gson().fromJson(publishes, mapType);
+ CpsUsername = jsonObject.get("cps.username").getAsString();
+ CpsPassword = jsonObject.get("cps.password").getAsString();
pgPort = jsonObject.get("postgres.port").getAsInt();
pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt();
pgPassword = jsonObject.get("postgres.password").getAsString();
@@ -451,6 +540,11 @@ public class Configuration {
policyNegativeAckThreshold = jsonObject.get("sonhandler.policyNegativeAckThreshold").getAsInt();
policyFixedPciTimeInterval = jsonObject.get("sonhandler.policyFixedPciTimeInterval").getAsLong();
nfNamingCode = jsonObject.get("sonhandler.nfNamingCode").getAsString();
+ cpsServiceUrl = jsonObject.get("cps.service.url").getAsString();
+ getCellDataUrl = jsonObject.get("cps.get.celldata").getAsString();
+ getPnfUrl = jsonObject.get("cps.get.pnf.url").getAsString();
+ getPciUrl = jsonObject.get("cps.get.pci.url").getAsString();
+ ConfigClientType = jsonObject.get("sonhandler.clientType").getAsString();
log.info("configuration from CBS {}", this);
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 325de6f..64d8593 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java
@@ -42,6 +42,7 @@ import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails;
import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
import org.onap.dcaegen2.services.sonhms.model.ClusterMap;
+import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException;
import org.onap.dcaegen2.services.sonhms.model.FapServiceList;
import org.onap.dcaegen2.services.sonhms.model.LteNeighborListInUseLteCell;
import org.onap.dcaegen2.services.sonhms.model.Notification;
@@ -110,8 +111,8 @@ public class EventHandler {
&& !faultNotificationtoClusterMapping.getCellsinCluster().isEmpty()) {
try {
handleMatchedFmCells(faultNotificationtoClusterMapping, clusterDetails);
- } catch (ConfigDbNotFoundException e) {
- log.error("Config DB Exception {}", e);
+ } catch (ConfigDbNotFoundException | CpsNotFoundException e) {
+ log.error("Config DB Exception {} or Cps Exception {} ", e);
}
}
// unmatched new cells
@@ -128,7 +129,7 @@ public class EventHandler {
*
*/
private void handleMatchedFmCells(FaultNotificationtoClusterMapping faultNotificationtoClusterMapping,
- List<ClusterDetails> clusterDetails) throws ConfigDbNotFoundException {
+ List<ClusterDetails> clusterDetails) throws ConfigDbNotFoundException, CpsNotFoundException {
Map<String, String> cellsinCluster = faultNotificationtoClusterMapping.getCellsinCluster();
log.info("Handling Matching cells for FM notification");
@@ -184,7 +185,7 @@ public class EventHandler {
cluster.setCollisionConfusionMap(collisionConfusionMap);
newClusters.add(cluster);
- } catch (ConfigDbNotFoundException e) {
+ } catch (ConfigDbNotFoundException | CpsNotFoundException e) {
log.error("Error connecting with configDB {}", e);
}
}
@@ -198,8 +199,8 @@ public class EventHandler {
Map<String, ArrayList<Integer>> collisionConfusionMap = cluster.getCollisionConfusionMap();
collisionConfusionMap.put(cellId, collisionConfusionCount);
cluster.setCollisionConfusionMap(collisionConfusionMap);
- } catch (ConfigDbNotFoundException e) {
- log.error("Config DB not found {}", e);
+ } catch (ConfigDbNotFoundException | CpsNotFoundException e) {
+ log.error("Config DB or CPS not found {}", e);
}
newClusters.remove(cluster);
newClusters.add(modifiedCluster);
@@ -244,7 +245,7 @@ public class EventHandler {
}
- private void handleUnMatchingCells(List<FapServiceList> newCells) throws ConfigDbNotFoundException {
+ private void handleUnMatchingCells(List<FapServiceList> newCells) throws ConfigDbNotFoundException, CpsNotFoundException {
log.info("handling unmatched cells");
@@ -261,8 +262,8 @@ public class EventHandler {
.getLteNeighborListInUseLteCell().get(0).getPlmnid());
cluster.setCollisionConfusionMap(new HashMap<>());
newClusters.add(cluster);
- } catch (ConfigDbNotFoundException e) {
- log.error("Error connecting with configDB {}", e);
+ } catch (ConfigDbNotFoundException | CpsNotFoundException e) {
+ log.error("Error connecting with configDB {} or CPS {}", e);
}
}
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 fd2de30..3964927 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019-2020 Wipro Limited.
+ * Copyright (C) 2019-2021 Wipro Limited.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,8 +61,8 @@ 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.ConfigurationClient;
import org.onap.dcaegen2.services.sonhms.restclient.PciSolutions;
-import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils;
import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils;
@@ -176,7 +176,7 @@ public class ChildThread implements Runnable {
FixedPciCellsRepository fixedPciCellsRepository = BeanUtil.getBean(FixedPciCellsRepository.class);
List<String> fixedPciCells = fixedPciCellsRepository.getFixedPciCells();
String cellId = fixedPciCells.get(0);
- JSONObject cellData = SdnrRestClient.getCellData(cellId);
+ JSONObject cellData = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getCellData(cellId);
networkId = cellData.getJSONObject("Cell").getString("networkId");
}
@@ -320,7 +320,7 @@ public class ChildThread implements Runnable {
for (PciSolutions pcisolutions : pciSolutionsList) {
String cellId = pcisolutions.getCellId();
- int oldPci = SdnrRestClient.getPci(cellId);
+ int oldPci = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).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 d04e6cb..5876d2b 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019-2020 Wipro Limited.
+ * Copyright (C) 2019-2021 Wipro Limited.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ import java.util.UUID;
import org.onap.dcaegen2.services.sonhms.ConfigPolicy;
import org.onap.dcaegen2.services.sonhms.Configuration;
+import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException;
import org.onap.dcaegen2.services.sonhms.HoMetricsComponent;
import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository;
import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient;
@@ -55,6 +56,7 @@ import org.onap.dcaegen2.services.sonhms.model.Ran;
import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte;
import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody;
import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
+import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient;
import org.onap.dcaegen2.services.sonhms.restclient.Solutions;
import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
import org.slf4j.Logger;
@@ -162,7 +164,7 @@ public class ChildThreadUtils {
* @throws ConfigDbNotFoundException
* when config db is unreachable
*/
- public Boolean sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException {
+ public Boolean sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException, CpsNotFoundException {
if (log.isDebugEnabled()) {
log.debug(async.toString());
@@ -224,7 +226,7 @@ public class ChildThreadUtils {
lteCell.setBlacklisted("true");
lteCell.setPlmnId(solutions.getNetworkId());
lteCell.setCid(removeableNeighbor);
- int pci = SdnrRestClient.getPci(cellId);
+ int pci = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).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 66f8221..1787b3f 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019 Wipro Limited.
+ * Copyright (C) 2019-2021 Wipro Limited.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,12 +27,16 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
+import org.onap.dcaegen2.services.sonhms.Configuration;
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.exceptions.CpsNotFoundException;
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.ConfigurationClient;
+import org.onap.dcaegen2.services.sonhms.restclient.CpsClient;
import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
import org.onap.dcaegen2.services.sonhms.restclient.Solutions;
import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
@@ -46,7 +50,7 @@ public class PnfUtils {
* get pnfs.
*
*/
- public Map<String, List<CellPciPair>> getPnfs(Solutions solutions) throws ConfigDbNotFoundException {
+ public Map<String, List<CellPciPair>> getPnfs(Solutions solutions) throws ConfigDbNotFoundException, CpsNotFoundException {
Map<String, List<CellPciPair>> pnfs = new HashMap<>();
List<PciSolutions> pciSolutions = solutions.getPciSolutions();
@@ -60,7 +64,7 @@ public class PnfUtils {
if (cellInfo.isPresent()) {
pnfName = cellInfo.get().getPnfName();
} else {
- pnfName = SdnrRestClient.getPnfName(cellId);
+ pnfName = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPnfName(cellId);
cellInfoRepository.save(new CellInfo(cellId, pnfName));
}
if (pnfs.containsKey(pnfName)) {
@@ -80,14 +84,14 @@ public class PnfUtils {
*
*/
public Map<String, List<Map<String, List<String>>>> getPnfsForAnrSolutions(List<AnrSolutions> anrSolutions)
- throws ConfigDbNotFoundException {
+ throws ConfigDbNotFoundException, CpsNotFoundException {
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);
+ String pnfName = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPnfName(cellId);
removeableNeighbors = anrSolution.getRemoveableNeighbors();
Map<String, List<String>> cellRemNeighborsPair = new HashMap<>();
cellRemNeighborsPair.put(cellId, removeableNeighbors);
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/CpsNotFoundException.java b/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/CpsNotFoundException.java
new file mode 100644
index 0000000..f62c9ba
--- /dev/null
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/CpsNotFoundException.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2021 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.exceptions;
+
+/**
+ * Exception class for CPS when CPS client is not found
+ * and information cannot be retrieved
+ *
+ * @see org.onap.dcaegen2.services.sonhms.restclient.CpsClient
+ */
+
+public class CpsNotFoundException extends Exception {
+
+ /**
+ * serial version.
+ */
+ private static final long serialVersionUID = 1L;
+
+ public CpsNotFoundException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigInterface.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigInterface.java
new file mode 100644
index 0000000..ff34cbf
--- /dev/null
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigInterface.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2021 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.restclient;
+
+import org.json.JSONObject;
+import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
+import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException;
+import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
+
+import java.util.List;
+
+/**
+ * An abstract base class which contains the methods for CpsClient and SdnrRestClient classes
+ *
+ * @see CpsClient,SdnrRestClient
+ */
+
+public abstract class ConfigInterface
+{
+ /**
+ * Abstract method to get neighbour list from SDNR or CPS based on the client
+ * mentioned in configuration.
+ *
+ * @throws ConfigDbNotFoundException,CpsNotFoundException when request to configDB or CPS fails
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+ public abstract List<CellPciPair> getNbrList(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException;
+
+ /**
+ * Abstract method to get PCI from SDNR or CPS based on the client mentioned.
+ *
+ * @throws ConfigDbNotFoundException,CpsNotFoundException when request to configDB or CPS fails
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+ public abstract int getPci(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException;
+
+ /**
+ * Abstract method to get PNF name from SDNR or CPS based on the client mentioned.
+ *
+ * @throws ConfigDbNotFoundException,CpsNotFoundException
+ * when request to configDB or CPS fails
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+ public abstract String getPnfName(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException;
+
+ /**
+ * Abstract method to get CellData name from SDNR or CPS based on the client mentioned.
+ *
+ * @throws ConfigDbNotFoundException,CpsNotFoundException
+ * when request to configDB or CPS fails
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+ public abstract JSONObject getCellData(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException;
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigurationClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigurationClient.java
new file mode 100644
index 0000000..3430469
--- /dev/null
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigurationClient.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2021 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.restclient;
+
+/**
+ * Class with method to get the Client type depending on the
+ * configuration client specified.
+ *
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+
+public class ConfigurationClient
+{
+ /**
+ * Method to get the Client type.
+ *
+ * @param config_name client name(CPS or ConfigDB)
+ * @return configuration client type
+ *
+ */
+ public static ConfigInterface configClient(String config_name)
+ {
+ if (config_name == null || config_name.isEmpty())
+ return null;
+ if ("ConfigDB".equals(config_name)) {
+ return new SdnrRestClient();
+ }
+ else if ("CPS".equals(config_name)) {
+ return new CpsClient();
+ }
+ return null;
+ }
+}
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
new file mode 100644
index 0000000..20b95c7
--- /dev/null
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2021 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.restclient;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.onap.dcaegen2.services.sonhms.Configuration;
+import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException;
+import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
+import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * A subclass which contains the methods
+ * to get required information from the CPS Client
+ *
+ */
+
+public class CpsClient extends ConfigInterface {
+
+ private static Logger log = LoggerFactory.getLogger(CpsClient.class);
+
+ public CpsClient() {
+
+ }
+
+ /**
+ * Method to get neighbour list from CPS.
+ *
+ * @throws CpsNotFoundException when request to CPS fails
+ */
+ @Override
+ public List<CellPciPair> getNbrList(String cellId) throws CpsNotFoundException {
+
+ Configuration configuration = Configuration.getInstance();
+ String requestUrl = configuration.getCpsServiceUrl() + "/" + configuration.getGetNbrListUrl();
+ JSONObject inputparam = new JSONObject();
+ JSONObject reqbody = new JSONObject();
+ inputparam.put("cellId", cellId);
+ reqbody.put("inputParameters", inputparam);
+ log.debug("request url: {}", requestUrl);
+ String response = sendRequest(requestUrl, reqbody);
+ List<CellPciPair> nbrList = new ArrayList<>();
+
+ JSONArray nbrListObj = new JSONArray(response);
+ for (int i = 0; i < nbrListObj.length(); i++) {
+ JSONObject cellObj = nbrListObj.getJSONObject(i);
+ JSONObject obj = cellObj.getJSONObject("attributes");
+ if (obj.getBoolean("isHOAllowed")) {
+ CellPciPair cell = new CellPciPair(obj.getString("nRTCI"), obj.getInt("nRPCI"));
+ nbrList.add(cell);
+ }
+ }
+
+ return nbrList;
+ }
+
+ /**
+ * Method to get PCI from CPS.
+ *
+ * @throws CpsNotFoundException when request to CPS fails
+ */
+ @Override
+ public int getPci(String cellId) throws CpsNotFoundException {
+
+ Configuration configuration = Configuration.getInstance();
+ String requestUrl = configuration.getCpsServiceUrl() + "/" + configuration.getGetPciUrl();
+ JSONObject inputparam = new JSONObject();
+ JSONObject reqbody = new JSONObject();
+ inputparam.put("cellId", cellId);
+ reqbody.put("inputParameters", inputparam);
+ String response = sendRequest(requestUrl, reqbody);
+ JSONObject respObj = new JSONObject(response);
+ return respObj.getInt("value");
+ }
+
+ /**
+ * Method to get PNF name from CPS.
+ *
+ * @throws CpsNotFoundException when request to CPS fails
+ */
+ @Override
+ public String getPnfName(String cellId) throws CpsNotFoundException {
+ Configuration configuration = Configuration.getInstance();
+ 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");
+ }
+
+ /**
+ * Method to get CellData name from CPS.
+ *
+ * @throws CpsNotFoundException when request to CPS fails
+ */
+ @Override
+ public JSONObject getCellData(String cellId) throws CpsNotFoundException {
+
+ Configuration configuration = Configuration.getInstance();
+ String requestUrl = configuration.getCpsServiceUrl() + "/" + configuration.getGetCellDataUrl();
+ 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;
+ }
+
+ private String sendRequest(String url, JSONObject reqbody) throws CpsNotFoundException {
+ ResponseEntity<String> response = SonHandlerRestTemplate.sendPostRequest(url, reqbody.toString(),
+ new ParameterizedTypeReference<String>() {
+ });
+ if (response == null) {
+ throw new CpsNotFoundException("Cannot reach Config DB");
+ }
+ return response.getBody();
+ }
+
+} \ No newline at end of file
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 a390bbe..9a05b88 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019-2020 Wipro Limited.
+ * Copyright (C) 2019-2021 Wipro Limited.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,12 +37,18 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.ResponseEntity;
-public class SdnrRestClient {
+/**
+ * A subclass which contains the methods
+ * to get required information from the SDNR Client
+ *
+ */
+
+public class SdnrRestClient extends ConfigInterface {
private static final String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss";
private static Logger log = LoggerFactory.getLogger(SdnrRestClient.class);
- private SdnrRestClient() {
+ public SdnrRestClient() {
}
@@ -52,7 +58,8 @@ public class SdnrRestClient {
* @throws ConfigDbNotFoundException
* when request to configDB fails
*/
- public static List<CellPciPair> getNbrList(String cellId) throws ConfigDbNotFoundException {
+ @Override
+ public 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() + "/api/sdnc-config-db/v3/getNbrList" + "/" + cellId
@@ -79,7 +86,9 @@ public class SdnrRestClient {
* @throws ConfigDbNotFoundException
* when request to configDB fails
*/
- public static int getPci(String cellId) throws ConfigDbNotFoundException {
+
+ @Override
+ public int getPci(String cellId) throws ConfigDbNotFoundException {
Configuration configuration = Configuration.getInstance();
String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis()));
String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getPCI" + "/" + cellId + "/"
@@ -95,7 +104,9 @@ public class SdnrRestClient {
* @throws ConfigDbNotFoundException
* when request to configDB fails
*/
- public static String getPnfName(String cellId) throws ConfigDbNotFoundException {
+
+ @Override
+ public String getPnfName(String cellId) throws ConfigDbNotFoundException {
Configuration configuration = Configuration.getInstance();
String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis()));
String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getPnfId" + "/" + cellId + "/"
@@ -111,7 +122,9 @@ public class SdnrRestClient {
* @throws ConfigDbNotFoundException
* when request to configDB fails
*/
- public static JSONObject getCellData(String cellId) throws ConfigDbNotFoundException {
+
+ @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);
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 7228f78..7198fce 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019 Wipro Limited.
+ * Copyright (C) 2019-2021 Wipro Limited.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,16 +33,20 @@ import java.util.Set;
import java.util.UUID;
import org.onap.dcaegen2.services.sonhms.ClusterDetailsComponent;
+import org.onap.dcaegen2.services.sonhms.Configuration;
import org.onap.dcaegen2.services.sonhms.FaultNotificationtoClusterMapping;
import org.onap.dcaegen2.services.sonhms.NotificationToClusterMapping;
import org.onap.dcaegen2.services.sonhms.child.Graph;
import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository;
import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails;
import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
+import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException;
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.ConfigurationClient;
+import org.onap.dcaegen2.services.sonhms.restclient.CpsClient;
import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -226,8 +230,8 @@ public class ClusterUtils {
/**
* Create cluster.
*/
- public Graph createCluster(Map<CellPciPair, ArrayList<CellPciPair>> clusterMap) throws ConfigDbNotFoundException {
-
+ public Graph createCluster(Map<CellPciPair, ArrayList<CellPciPair>> clusterMap) throws ConfigDbNotFoundException, CpsNotFoundException
+ {
Graph cluster = new Graph();
log.debug("cluster formation started");
@@ -246,7 +250,7 @@ public class ClusterUtils {
val1.setPhysicalCellId(phy);
cluster.addEdge(val, val1);
- List<CellPciPair> nbrList = SdnrRestClient.getNbrList(cell);
+ List<CellPciPair> nbrList = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getNbrList(cell);
for (CellPciPair nbr : nbrList) {
String cid = nbr.getCellId();
@@ -297,14 +301,14 @@ public class ClusterUtils {
/**
* Find cluster Map.
*/
- public Map<CellPciPair, ArrayList<CellPciPair>> findClusterMap(String cellId) throws ConfigDbNotFoundException {
+ public Map<CellPciPair, ArrayList<CellPciPair>> findClusterMap(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException {
log.info("indide clusterMap");
- int phyCellId = SdnrRestClient.getPci(cellId);
+ int phyCellId = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPci(cellId);
CellPciPair main = new CellPciPair();
main.setCellId(cellId);
main.setPhysicalCellId(phyCellId);
ArrayList<CellPciPair> cellPciPairs;
- cellPciPairs = (ArrayList<CellPciPair>) SdnrRestClient.getNbrList(cellId);
+ cellPciPairs = (ArrayList<CellPciPair>) ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getNbrList(cellId);
Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = new HashMap<>();
clusterMap.put(main, cellPciPairs);
log.info("clusterMap{}", clusterMap);
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java
index d32a78c..e3eb8a7 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019 Wipro Limited.
+ * Copyright (C) 2019-2021 Wipro Limited.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@ import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
+import org.onap.dcaegen2.services.sonhms.Configuration;
import org.slf4j.Logger;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;