diff options
author | ramya <ramya.ravichandran5@wipro.com> | 2019-03-11 17:34:41 +0530 |
---|---|---|
committer | ramya <ramya.ravichandran5@wipro.com> | 2019-03-11 17:37:12 +0530 |
commit | 3cd4023832810e8b65f85a9db807c8bafec38d82 (patch) | |
tree | 13175e409ca3b29eccffacd75538ded25cfdb518 /src | |
parent | 79f9e63b3e531ae7ca4eaa7224ab8a740ad578cb (diff) |
code coverage for M3
Change-Id: Ib421ce2ac9357a3210d99293497f9e304f8cd2f5
Issue-ID: DCAEGEN2-1259
Signed-off-by: Ramya Ravichandran<ramya.ravichandran5@wipro.com>
Diffstat (limited to 'src')
194 files changed, 6667 insertions, 4681 deletions
diff --git a/src/main/docker/postgres_scripts/init_db.sh b/src/main/docker/postgres_scripts/init_db.sh index cbc27a6..f01eea6 100644 --- a/src/main/docker/postgres_scripts/init_db.sh +++ b/src/main/docker/postgres_scripts/init_db.sh @@ -1,3 +1,23 @@ #!/bin/bash +#******************************************************************************* +# ============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========================================================= +# +#******************************************************************************* psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'pci_ms'" | grep -q 1 || psql -U postgres -c "CREATE DATABASE pci_ms" diff --git a/src/main/docker/son-handler/entrypoint.sh b/src/main/docker/son-handler/entrypoint.sh index bf69065..36e3178 100644 --- a/src/main/docker/son-handler/entrypoint.sh +++ b/src/main/docker/son-handler/entrypoint.sh @@ -1,4 +1,24 @@ #!/bin/bash +#******************************************************************************* +# ============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========================================================= +# +#******************************************************************************* sed -i s/DMAAP_SERVER/$DMAAPSERVER/ /etc/config.json sed -i s/SDNR_SERVICE/$SDNRSERVICE/ /etc/config.json diff --git a/src/main/java/com/wipro/www/sonhms/BufferNotificationState.java b/src/main/java/com/wipro/www/sonhms/BufferNotificationState.java deleted file mode 100644 index 62d485f..0000000 --- a/src/main/java/com/wipro/www/sonhms/BufferNotificationState.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BufferNotificationState implements SonState { - private static Logger log = LoggerFactory.getLogger(BufferNotificationState.class); - - @Override - public void stateChange(SonContext sonContext) { - log.debug("inside buffer notification state"); - WaitState waitState = WaitState.getInstance(); - sonContext.setPciState(waitState); - sonContext.stateChange(sonContext); - - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/BufferedNotificationHandlingState.java b/src/main/java/com/wipro/www/sonhms/BufferedNotificationHandlingState.java deleted file mode 100644 index ef76bdb..0000000 --- a/src/main/java/com/wipro/www/sonhms/BufferedNotificationHandlingState.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -public class BufferedNotificationHandlingState implements SonState { - - @Override - public void stateChange(SonContext sonContext) { - // any other pci context change to be done - WaitState waitState = WaitState.getInstance(); - sonContext.setPciState(waitState); - sonContext.stateChange(sonContext); - - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/ChildStatusUpdateState.java b/src/main/java/com/wipro/www/sonhms/ChildStatusUpdateState.java deleted file mode 100644 index b8d0cf4..0000000 --- a/src/main/java/com/wipro/www/sonhms/ChildStatusUpdateState.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.wipro.www.sonhms.model.FapServiceList; - -import java.io.IOException; -import java.util.List; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ChildStatusUpdateState implements SonState { - private static Logger log = LoggerFactory.getLogger(ChildStatusUpdateState.class); - - @Override - public void stateChange(SonContext sonContext) { - if (sonContext.getChildStatus(sonContext.getChildThreadId()).equals("triggeredOof")) { - WaitState waitState = WaitState.getInstance(); - sonContext.setPciState(waitState); - sonContext.stateChange(sonContext); - } else if (sonContext.getChildStatus(sonContext.getChildThreadId()).equals("success")) { - BufferNotificationComponent bufferNotificationComponent = new BufferNotificationComponent(); - ClusterDetailsComponent clusterDetailsComponent = new ClusterDetailsComponent(); - String clusterId = clusterDetailsComponent.getClusterId(sonContext.getChildThreadId()); - List<String> bufferedNotifications = bufferNotificationComponent.getBufferedNotification(clusterId); - if ((bufferedNotifications == null) || bufferedNotifications.isEmpty()) { - // resource clean up - // kill the child thread cleanup resources for the cluster - log.debug("no buffered notification to be handled"); - - Set<Thread> setOfThread = Thread.getAllStackTraces().keySet(); - for (Thread thread : setOfThread) { - if (thread.getId() == sonContext.getChildThreadId()) { - sonContext.deleteChildStatus(); - thread.interrupt(); - } - } - - sonContext.setPciState(new ResourceCleanupState()); - sonContext.stateChange(sonContext); - - } else { - // forward to child thread - ObjectMapper mapper = new ObjectMapper(); - log.debug("handling buffer notification"); - long childThreadId = sonContext.getChildThreadId(); - for (String notification : bufferedNotifications) { - FapServiceList fapServiceList; - try { - fapServiceList = mapper.readValue(notification, FapServiceList.class); - log.debug("fapServiceList{}", fapServiceList); - - SdnrNotificationHandlingState.getChildThreadMap().get(childThreadId) - .putInQueueWithNotify(fapServiceList); - sonContext.setPciState(new BufferedNotificationHandlingState()); - sonContext.stateChange(sonContext); - - } catch (IOException e) { - log.error("caught in child status update {}", e); - } - - } - } - } - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/ChildTriggeringState.java b/src/main/java/com/wipro/www/sonhms/ChildTriggeringState.java deleted file mode 100644 index 6683085..0000000 --- a/src/main/java/com/wipro/www/sonhms/ChildTriggeringState.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ChildTriggeringState implements SonState { - private static Logger log = LoggerFactory.getLogger(ChildTriggeringState.class); - - @Override - public void stateChange(SonContext sonContext) { - // any other pci context change to be done - - log.debug("inside child trigger state"); - WaitState waitState = WaitState.getInstance(); - sonContext.setPciState(waitState); - sonContext.stateChange(sonContext); - - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/ConfigPolicy.java b/src/main/java/com/wipro/www/sonhms/ConfigPolicy.java deleted file mode 100644 index 6d2994f..0000000 --- a/src/main/java/com/wipro/www/sonhms/ConfigPolicy.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import java.util.Map; - -public class ConfigPolicy { - - private static ConfigPolicy instance = null; - private Map<String, Object> config; - - protected ConfigPolicy() { - - } - - /** - * Get instance of class. - */ - public static ConfigPolicy getInstance() { - if (instance == null) { - instance = new ConfigPolicy(); - } - return instance; - } - - public Map<String, Object> getConfig() { - return config; - } - - public void setConfig(Map<String, Object> config) { - this.config = config; - } - - @Override - public String toString() { - return "ConfigPolicy [config=" + config + "]"; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/MainThread.java b/src/main/java/com/wipro/www/sonhms/MainThread.java deleted file mode 100644 index 2b6c843..0000000 --- a/src/main/java/com/wipro/www/sonhms/MainThread.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import java.util.List; -import java.util.concurrent.LinkedBlockingQueue; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MainThread implements Runnable { - private static Logger log = LoggerFactory.getLogger(MainThread.class); - - private NewNotification newNotification; - - @Override - public void run() { - log.debug("Starting pci context"); - SonContext sonContext = new SonContext(new LinkedBlockingQueue<List<String>>(), newNotification); - log.debug("initializing pci state to wait state"); - WaitState waitState = WaitState.getInstance(); - sonContext.setPciState(waitState); - sonContext.stateChange(sonContext); - } - - public MainThread(NewNotification newNotification) { - super(); - this.newNotification = newNotification; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/MainThreadComponent.java b/src/main/java/com/wipro/www/sonhms/MainThreadComponent.java deleted file mode 100644 index 2b8516d..0000000 --- a/src/main/java/com/wipro/www/sonhms/MainThreadComponent.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -@Component -public class MainThreadComponent { - - private static Logger log = LoggerFactory.getLogger(MainThreadComponent.class); - - private ExecutorService pool; - - public ExecutorService getPool() { - return pool; - } - - /** - * main thread initialization. - */ - public void init(NewNotification newNotification) { - log.debug("initializing main thread"); - log.debug("initializing executors"); - Configuration configuration = Configuration.getInstance(); - int maximumClusters = configuration.getMaximumClusters(); - log.debug("pool creating"); - pool = Executors.newFixedThreadPool(maximumClusters); - log.debug("pool created"); - Thread thread = new Thread(new MainThread(newNotification)); - thread.start(); - } -} diff --git a/src/main/java/com/wipro/www/sonhms/NewNotification.java b/src/main/java/com/wipro/www/sonhms/NewNotification.java deleted file mode 100644 index 5d4f704..0000000 --- a/src/main/java/com/wipro/www/sonhms/NewNotification.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -public class NewNotification { - - private Boolean newNotif; - - public Boolean getNewNotif() { - return newNotif; - } - - public void setNewNotif(Boolean newNotif) { - this.newNotif = newNotif; - } - - public NewNotification(Boolean newNotif) { - super(); - this.newNotif = newNotif; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/ResourceCleanupState.java b/src/main/java/com/wipro/www/sonhms/ResourceCleanupState.java deleted file mode 100644 index 1487b5e..0000000 --- a/src/main/java/com/wipro/www/sonhms/ResourceCleanupState.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -public class ResourceCleanupState implements SonState { - - @Override - public void stateChange(SonContext sonContext) { - // any other pci context change to be done - WaitState waitState = WaitState.getInstance(); - sonContext.setPciState(waitState); - sonContext.stateChange(sonContext); - - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/SdnrNotificationHandlingState.java b/src/main/java/com/wipro/www/sonhms/SdnrNotificationHandlingState.java deleted file mode 100644 index 2637790..0000000 --- a/src/main/java/com/wipro/www/sonhms/SdnrNotificationHandlingState.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.wipro.www.sonhms.child.ChildThread; -import com.wipro.www.sonhms.child.Graph; -import com.wipro.www.sonhms.dao.CellInfoRepository; -import com.wipro.www.sonhms.dao.ClusterDetailsRepository; -import com.wipro.www.sonhms.entity.CellInfo; -import com.wipro.www.sonhms.entity.ClusterDetails; -import com.wipro.www.sonhms.exceptions.ConfigDbNotFoundException; -import com.wipro.www.sonhms.model.CellPciPair; -import com.wipro.www.sonhms.model.FapServiceList; -import com.wipro.www.sonhms.model.LteNeighborListInUseLteCell; -import com.wipro.www.sonhms.model.Notification; -import com.wipro.www.sonhms.model.ThreadId; -import com.wipro.www.sonhms.restclient.SdnrRestClient; -import com.wipro.www.sonhms.utils.BeanUtil; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - -import org.slf4j.Logger; - -public class SdnrNotificationHandlingState implements SonState { - private static Map<Long, ChildThread> childThreadMap = new HashMap<>(); - private static final Logger log = org.slf4j.LoggerFactory.getLogger(SdnrNotificationHandlingState.class); - - @Override - public void stateChange(SonContext sonContext) { - // logic to determine if notif to be processed - log.debug("inside statechange of sdnr notif state"); - String notification = sonContext.getSdnrNotification(); - Notification notificationObject; - try { - - ObjectMapper mapper = new ObjectMapper(); - notificationObject = mapper.readValue(notification, Notification.class); - log.debug("notificationObject{}", notificationObject); - - List<FapServiceList> serviceList = notificationObject.getPayload().getRadioAccess().getFapServiceList(); - for (FapServiceList fapService : serviceList) { - String cellId = fapService.getCellConfig().getLte().getRan().getCellIdentity(); - log.debug("cellId:{}", cellId); - log.debug("inside for loop"); - - List<ClusterDetails> clusterDetails = getAllClusters(); - - ClusterDetails clusterDetail = getClusterForNotification(fapService, clusterDetails); - - if (clusterDetail == null) { - // form the cluster - Graph cluster = createCluster(fapService); - // save to db - UUID clusterId = UUID.randomUUID(); - cluster.setGraphId(clusterId); - // create the child thread - log.debug("creating new child"); - BlockingQueue<FapServiceList> queue = new LinkedBlockingQueue<>(); - ThreadId threadId = new ThreadId(); - threadId.setChildThreadId(0); - ChildThread child = new ChildThread(sonContext.getChildStatusUpdate(), cluster, queue, threadId); - queue.put(fapService); - MainThreadComponent mainThreadComponent = BeanUtil.getBean(MainThreadComponent.class); - mainThreadComponent.getPool().execute(child); - - waitForThreadId(threadId); - - saveCluster(cluster, clusterId, threadId.getChildThreadId()); - addChildThreadMap(threadId.getChildThreadId(), child); - sonContext.addChildStatus(threadId.getChildThreadId(), "processingNotifications"); - - } - - else { - if (isOofTriggeredForCluster(sonContext, clusterDetail)) { - sonContext.setNotifToBeProcessed(false); - bufferNotification(fapService, clusterDetail.getClusterId()); - } else { - sonContext.setNotifToBeProcessed(true); - log.debug("childThreadId:{}", clusterDetail.getChildThreadId()); - childThreadMap.get(clusterDetail.getChildThreadId()).putInQueue(fapService); - } - } - } - } catch (Exception e) { - log.error("caught in sdnr notif handling state{}", e); - } - - WaitState waitState = WaitState.getInstance(); - sonContext.setPciState(waitState); - sonContext.stateChange(sonContext); - } - - private void waitForThreadId(ThreadId threadId) { - try { - synchronized (threadId) { - while (threadId.getChildThreadId() == 0) { - threadId.wait(); - } - } - } catch (InterruptedException e) { - - log.error("ChildThread queue error {}", e); - Thread.currentThread().interrupt(); - } - } - - private String saveCluster(Graph cluster, UUID clusterId, Long threadId) { - - String cellPciNeighbourString = cluster.getPciNeighbourJson(); - - log.debug("cluster hahsmap to string : {}", cellPciNeighbourString); - cluster.setGraphId(clusterId); - - ClusterDetails details = new ClusterDetails(); - details.setClusterId(clusterId.toString()); - details.setClusterInfo(cellPciNeighbourString); - details.setChildThreadId(threadId); - - ClusterDetailsRepository clusterDetailsRepository = BeanUtil.getBean(ClusterDetailsRepository.class); - clusterDetailsRepository.save(details); - - return clusterId.toString(); - } - - private Graph createCluster(FapServiceList fapService) throws ConfigDbNotFoundException { - - Graph cluster = new Graph(); - log.debug("cluster formation started"); - int phycellId = fapService.getX0005b9Lte().getPhyCellIdInUse(); - String cellId = fapService.getCellConfig().getLte().getRan().getCellIdentity(); - - CellInfoRepository cellInfoRepository = BeanUtil.getBean(CellInfoRepository.class); - cellInfoRepository.save(new CellInfo(cellId, fapService.getX0005b9Lte().getPnfName())); - - CellPciPair val = new CellPciPair(); - val.setCellId(cellId); - val.setPhysicalCellId(phycellId); - List<LteNeighborListInUseLteCell> neighbourlist; - neighbourlist = fapService.getCellConfig().getLte().getRan().getNeighborListInUse() - .getLteNeighborListInUseLteCell(); - log.debug("Neighbor list size: {}", neighbourlist.size()); - - for (int i = 0; i < neighbourlist.size(); i++) { - String cell = neighbourlist.get(i).getAlias(); - int phy = neighbourlist.get(i).getPhyCellId(); - - cellInfoRepository.save(new CellInfo(cell, neighbourlist.get(i).getPnfName())); - - log.debug("cellID: {}", cell); - log.debug("PCI: {}", phy); - CellPciPair val1 = new CellPciPair(); - val1.setCellId(cell); - val1.setPhysicalCellId(phy); - cluster.addEdge(val, val1); - log.debug("cluster: {}", cluster); - - List<CellPciPair> nbrList = SdnrRestClient.getNbrList(neighbourlist.get(i).getAlias()); - - for (CellPciPair nbr : nbrList) { - String cid = nbr.getCellId(); - int pci = nbr.getPhysicalCellId(); - CellPciPair val3 = new CellPciPair(); - val3.setCellId(cid); - val3.setPhysicalCellId(pci); - - cluster.addEdge(val1, val3); - } - } - - log.debug("final cluster: {}", cluster); - return cluster; - } - - private void bufferNotification(FapServiceList fapService, String clusterId) { - - ObjectMapper mapper = new ObjectMapper(); - BufferNotificationComponent bufferNotifComponent = new BufferNotificationComponent(); - String serviceListString = ""; - try { - serviceListString = mapper.writeValueAsString(fapService); - } catch (JsonProcessingException e) { - log.debug("JSON processing exception: {}", e); - } - bufferNotifComponent.bufferNotification(serviceListString, clusterId); - - } - - private boolean isOofTriggeredForCluster(SonContext pciContext, ClusterDetails clusterDetail) { - Long childThreadId = clusterDetail.getChildThreadId(); - String childStatus = pciContext.getChildStatus(childThreadId); - return childStatus.equals("triggeredOof"); - - } - - private ClusterDetails getClusterForNotification(FapServiceList fapService, List<ClusterDetails> clusterDetails) { - - String cellId = fapService.getCellConfig().getLte().getRan().getCellIdentity(); - Map<CellPciPair, ArrayList<CellPciPair>> cellPciNeighbourMap; - - for (ClusterDetails clusterDetail : clusterDetails) { - Graph cluster = new Graph(clusterDetail.getClusterInfo()); - cellPciNeighbourMap = cluster.getCellPciNeighbourMap(); - Set<CellPciPair> keys = cellPciNeighbourMap.keySet(); - Iterator<CellPciPair> traverse = keys.iterator(); - while (traverse.hasNext()) { - CellPciPair key = traverse.next(); - String currentCellId = key.getCellId(); - if (cellId.equals(currentCellId)) { - return clusterDetail; - } - } - } - - return null; - } - - private List<ClusterDetails> getAllClusters() { - ClusterDetailsComponent clusterDetailsComponent = new ClusterDetailsComponent(); - return clusterDetailsComponent.getClusterDetails(); - } - - public static void addChildThreadMap(Long childThreadId, ChildThread child) { - childThreadMap.put(childThreadId, child); - } - - public static Map<Long, ChildThread> getChildThreadMap() { - return childThreadMap; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/SonContext.java b/src/main/java/com/wipro/www/sonhms/SonContext.java deleted file mode 100644 index 491dccc..0000000 --- a/src/main/java/com/wipro/www/sonhms/SonContext.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.BlockingQueue; - -public class SonContext implements SonState { - private SonState pciState; - boolean notifToBeProcessed; - private String sdnrNotification; - private long childThreadId; - private Map<Long, String> childStatus; - private BlockingQueue<List<String>> childStatusUpdate; - private NewNotification newNotification; - - public String getSdnrNotification() { - return sdnrNotification; - } - - public void setSdnrNotification(String sdnrNotification) { - this.sdnrNotification = sdnrNotification; - } - - SonContext(SonState pciState) { - this.pciState = pciState; - this.childStatus = new HashMap<>(); - } - - public SonContext() { - - } - - /** - * Parameterized constructor. - */ - public SonContext(BlockingQueue<List<String>> childStatusUpdate, NewNotification newNotification) { - this.setChildStatusUpdate(childStatusUpdate); - this.setNewNotification(newNotification); - this.childStatus = new HashMap<>(); - } - - public SonState getPciState() { - return pciState; - } - - public long getChildThreadId() { - return childThreadId; - } - - public void setChildThreadId(long childThreadId) { - this.childThreadId = childThreadId; - } - - public void setPciState(SonState pciState) { - this.pciState = pciState; - } - - public boolean isNotifToBeProcessed() { - return notifToBeProcessed; - } - - public void setNotifToBeProcessed(boolean notifToBeProcessed) { - this.notifToBeProcessed = notifToBeProcessed; - } - - @Override - public void stateChange(SonContext pciContext) { - this.pciState.stateChange(pciContext); - } - - public BlockingQueue<List<String>> getChildStatusUpdate() { - return childStatusUpdate; - } - - public void setChildStatusUpdate(BlockingQueue<List<String>> childStatusUpdate) { - this.childStatusUpdate = childStatusUpdate; - } - - public void addChildStatus(Long threadId, String status) { - this.childStatus.put(threadId, status); - } - - public String getChildStatus(Long threadId) { - return childStatus.get(threadId); - - } - - public NewNotification getNewNotification() { - return newNotification; - } - - public void setNewNotification(NewNotification newNotification) { - this.newNotification = newNotification; - } - - public void deleteChildStatus() { - this.childStatus.remove(childThreadId); - - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/SonRequestsComponent.java b/src/main/java/com/wipro/www/sonhms/SonRequestsComponent.java deleted file mode 100644 index 5b57850..0000000 --- a/src/main/java/com/wipro/www/sonhms/SonRequestsComponent.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import com.wipro.www.sonhms.dao.SonRequestsRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - -@Component -public class SonRequestsComponent { - - @Autowired - private SonRequestsRepository sonRequestsRepository; - - public long getChildThread(String transactionId) { - return sonRequestsRepository.getChildThreadMapping(transactionId); - } - -} - diff --git a/src/main/java/com/wipro/www/sonhms/SonState.java b/src/main/java/com/wipro/www/sonhms/SonState.java deleted file mode 100644 index c287c6b..0000000 --- a/src/main/java/com/wipro/www/sonhms/SonState.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -public interface SonState { - - public void stateChange(SonContext pciContext); -} diff --git a/src/main/java/com/wipro/www/sonhms/WaitState.java b/src/main/java/com/wipro/www/sonhms/WaitState.java deleted file mode 100644 index a74f795..0000000 --- a/src/main/java/com/wipro/www/sonhms/WaitState.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import com.wipro.www.sonhms.dao.DmaapNotificationsRepository; -import com.wipro.www.sonhms.utils.BeanUtil; -import java.util.ArrayList; -import java.util.List; -import org.slf4j.Logger; - - - -public class WaitState implements SonState { - - private static WaitState instance; - private List<String> sdnrNotification = new ArrayList<>(); - private static final Logger log = org.slf4j.LoggerFactory.getLogger(WaitState.class); - - protected WaitState() { - - } - - /** - * singleton. - */ - public static WaitState getInstance() { - if (instance == null) { - return new WaitState(); - } - return instance; - } - - public void putSdnrNotification(String notification) { - sdnrNotification.add(notification); - log.debug("sdnrNotification size: {}", sdnrNotification.size()); - } - - @Override - public void stateChange(SonContext pciContext) { - log.debug("inside state change of wait state"); - - while (pciContext.getChildStatusUpdate().isEmpty() && !pciContext.getNewNotification().getNewNotif()) { - } - - List<String> childStatus = pciContext.getChildStatusUpdate().poll(); - if (childStatus != null) { - Long threadId = Long.parseLong(childStatus.get(0)); - log.debug("threadId: {}", threadId); - log.debug("childStatus: {}", childStatus.get(1)); - pciContext.setChildThreadId(threadId); - pciContext.addChildStatus(threadId, childStatus.get(1)); - pciContext.setPciState(new ChildStatusUpdateState()); - pciContext.stateChange(pciContext); - } - - DmaapNotificationsRepository dmaapNotificationsRepository = BeanUtil - .getBean(DmaapNotificationsRepository.class); - String notification = dmaapNotificationsRepository.getNotificationFromQueue(); - if (notification != null) { - log.debug("notification from sdnr:{}", notification); - pciContext.setSdnrNotification(notification); - pciContext.setPciState(new SdnrNotificationHandlingState()); - pciContext.stateChange(pciContext); - } else { - pciContext.getNewNotification().setNewNotif(false); - log.debug("setting new notification to false"); - pciContext.setPciState(this); - pciContext.stateChange(pciContext); - } - - } -} diff --git a/src/main/java/com/wipro/www/sonhms/child/ClusterModification.java b/src/main/java/com/wipro/www/sonhms/child/ClusterModification.java deleted file mode 100644 index 9926cf4..0000000 --- a/src/main/java/com/wipro/www/sonhms/child/ClusterModification.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.child; - -import com.wipro.www.sonhms.model.CellPciPair; -import com.wipro.www.sonhms.model.FapServiceList; -import com.wipro.www.sonhms.model.LteNeighborListInUseLteCell; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; - - - -public class ClusterModification { - private static final Logger log = org.slf4j.LoggerFactory.getLogger(ClusterModification.class); - - /** - * Forms a modified cluster for the existing cluster. - */ - - public Graph clustermod(Graph cluster, FapServiceList fapser) { - - int phycellId = fapser.getX0005b9Lte().getPhyCellIdInUse(); - String cellId = fapser.getCellConfig().getLte().getRan().getCellIdentity(); - CellPciPair mainCellPciPair = new CellPciPair(); - mainCellPciPair.setCellId(cellId); - mainCellPciPair.setPhysicalCellId(phycellId); - List<LteNeighborListInUseLteCell> newNeighbourList; - newNeighbourList = fapser.getCellConfig().getLte().getRan().getNeighborListInUse() - .getLteNeighborListInUseLteCell(); - - Map<CellPciPair, ArrayList<CellPciPair>> clusterMap; - clusterMap = cluster.getCellPciNeighbourMap(); - - // coe - - List<CellPciPair> tempCellPair = new ArrayList<>(); - for (Map.Entry<CellPciPair, ArrayList<CellPciPair>> entry : clusterMap.entrySet()) { - CellPciPair oldClusterKeys = entry.getKey(); - tempCellPair.add(oldClusterKeys); - } - - for (CellPciPair entry : tempCellPair) { - String cell = entry.getCellId(); - int physicalCell = entry.getPhysicalCellId(); - CellPciPair mapVal = new CellPciPair(); - mapVal.setCellId(cell); - mapVal.setPhysicalCellId(physicalCell); - - if (cellId.equals(cell)) { - - // removes the old neighbours and adds new neighbours for that cell - cluster.updateVertex(mapVal, mainCellPciPair); - - } - - } - - /////// update cluster with new pci values for the same cell - - if (clusterMap.containsKey(mainCellPciPair)) { - ArrayList<CellPciPair> oldClusterArray; - oldClusterArray = clusterMap.get(mainCellPciPair); - oldClusterArray.clear(); - - for (int i = 0; i < newNeighbourList.size(); i++) { - String cid = newNeighbourList.get(i).getAlias(); - int phy = newNeighbourList.get(i).getPhyCellId(); - CellPciPair val2 = new CellPciPair(); - val2.setCellId(cid); - val2.setPhysicalCellId(phy); - cluster.addEdge(mainCellPciPair, val2); - } - - } - - for (CellPciPair entry : tempCellPair) { - String cell = entry.getCellId(); - int physicalCell = entry.getPhysicalCellId(); - CellPciPair mapVal = new CellPciPair(); - mapVal.setCellId(cell); - mapVal.setPhysicalCellId(physicalCell); - for (int j = 0; j < newNeighbourList.size(); j++) { - String cid1 = newNeighbourList.get(j).getAlias(); - int phy1 = newNeighbourList.get(j).getPhyCellId(); - CellPciPair val3 = new CellPciPair(); - val3.setCellId(cid1); - val3.setPhysicalCellId(phy1); - - if (cid1.equals(cell)) { - - // removes the old neighbours and adds new neighbours for that cell - cluster.updateVertex(mapVal, val3); - - } - - } - } - - for (int j = 0; j < newNeighbourList.size(); j++) { - String cid1 = newNeighbourList.get(j).getAlias(); - int phy1 = newNeighbourList.get(j).getPhyCellId(); - CellPciPair val3 = new CellPciPair(); - val3.setCellId(cid1); - val3.setPhysicalCellId(phy1); - if (clusterMap.containsKey(val3)) { - cluster.addEdge(mainCellPciPair, val3); - } - - } - - for (int k = 0; k < newNeighbourList.size(); k++) { - String cid2 = newNeighbourList.get(k).getAlias(); - int phy2 = newNeighbourList.get(k).getPhyCellId(); - CellPciPair val5 = new CellPciPair(); - val5.setCellId(cid2); - val5.setPhysicalCellId(phy2); - cluster.addEdge(mainCellPciPair, val5); - } - - log.debug("Modified Cluster {}", cluster); - - return cluster; - } - -}
\ No newline at end of file diff --git a/src/main/java/com/wipro/www/sonhms/child/StateOof.java b/src/main/java/com/wipro/www/sonhms/child/StateOof.java deleted file mode 100644 index 3215c46..0000000 --- a/src/main/java/com/wipro/www/sonhms/child/StateOof.java +++ /dev/null @@ -1,271 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.child; - -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.wipro.www.sonhms.ConfigPolicy; -import com.wipro.www.sonhms.Configuration; -import com.wipro.www.sonhms.dao.CellInfoRepository; -import com.wipro.www.sonhms.dao.SonRequestsRepository; -import com.wipro.www.sonhms.dmaap.PolicyDmaapClient; -import com.wipro.www.sonhms.entity.CellInfo; -import com.wipro.www.sonhms.entity.PciRequests; -import com.wipro.www.sonhms.exceptions.ConfigDbNotFoundException; -import com.wipro.www.sonhms.exceptions.OofNotFoundException; -import com.wipro.www.sonhms.model.CellConfig; -import com.wipro.www.sonhms.model.CellPciPair; -import com.wipro.www.sonhms.model.Common; -import com.wipro.www.sonhms.model.Configurations; -import com.wipro.www.sonhms.model.Data; -import com.wipro.www.sonhms.model.FapService; -import com.wipro.www.sonhms.model.Lte; -import com.wipro.www.sonhms.model.Payload; -import com.wipro.www.sonhms.model.PolicyNotification; -import com.wipro.www.sonhms.model.Ran; -import com.wipro.www.sonhms.model.X0005b9Lte; -import com.wipro.www.sonhms.restclient.AsyncResponseBody; -import com.wipro.www.sonhms.restclient.OofRestClient; -import com.wipro.www.sonhms.restclient.SdnrRestClient; -import com.wipro.www.sonhms.restclient.Solution; -import com.wipro.www.sonhms.restclient.SonSolution; -import com.wipro.www.sonhms.utils.BeanUtil; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.BlockingQueue; - -import org.slf4j.Logger; - -public class StateOof { - private static final Logger log = org.slf4j.LoggerFactory.getLogger(StateOof.class); - private BlockingQueue<List<String>> childStatusUpdate; - - public StateOof() { - - } - - /** - * Parameterized Constructor. - * - */ - public StateOof(BlockingQueue<List<String>> childStatusUpdate) { - super(); - this.childStatusUpdate = childStatusUpdate; - } - - /** - * Triggers OOF. - * @throws OofNotFoundException when trigger oof fails - */ - public void triggerOof(Map<String, ArrayList<Integer>> result, String networkId) throws OofNotFoundException { - // check for 0 collision and 0 confusion - ArrayList<String> cellidList = new ArrayList<>(); - ArrayList<String> cellIds = new ArrayList<>(); - - for (Map.Entry<String, ArrayList<Integer>> entry : result.entrySet()) { - String key = entry.getKey(); - ArrayList<Integer> arr; - arr = entry.getValue(); - if (!arr.isEmpty()) { - Set<Integer> set = new HashSet<>(arr); - if (((set.size() == 1) && !set.contains(0)) || (set.size() != 1)) { - cellIds.add(key); - - } - } - - } - - for (String cell : cellIds) { - log.debug("cellidList entries: {}", cell); - cellidList.add(cell); - } - log.debug("the cells triggering the oof are {}", cellidList); - - UUID transactionId = UUID.randomUUID(); - - Configuration config = Configuration.getInstance(); - int numSolutions = config.getNumSolutions(); - List<String> optimizers = config.getOptimizers(); - - String oofResponse = OofRestClient.queryOof(numSolutions, transactionId.toString(), "create", cellidList, - networkId, optimizers); - log.debug("Synchronous Response {}", oofResponse); - - List<String> childStatus = new ArrayList<>(); - childStatus.add(Long.toString(Thread.currentThread().getId())); - childStatus.add("triggeredOof"); - try { - childStatusUpdate.put(childStatus); - } catch (InterruptedException e1) { - log.debug("Interrupted execption {}", e1); - Thread.currentThread().interrupt(); - - } - - // Store Request details in Database - - PciRequests pciRequest = new PciRequests(); - - long childThreadId = Thread.currentThread().getId(); - pciRequest.setTransactionId(transactionId.toString()); - pciRequest.setChildThreadId(childThreadId); - SonRequestsRepository pciRequestsRepository = BeanUtil.getBean(SonRequestsRepository.class); - pciRequestsRepository.save(pciRequest); - - while (!ChildThread.getResponseMap().containsKey(childThreadId)) { - - } - - AsyncResponseBody asynResponseBody = ChildThread.getResponseMap().get(childThreadId); - - try { - sendToPolicy(asynResponseBody, networkId); - } catch (ConfigDbNotFoundException e1) { - log.debug("Config DB is unreachable: {}", e1); - } - - pciRequestsRepository = BeanUtil.getBean(SonRequestsRepository.class); - pciRequestsRepository.deleteByChildThreadId(childThreadId); - - childStatus = new ArrayList<>(); - childStatus.add(Long.toString(Thread.currentThread().getId())); - childStatus.add("success"); - try { - childStatusUpdate.put(childStatus); - } catch (InterruptedException e) { - log.debug("InterruptedException {}", e); - Thread.currentThread().interrupt(); - - } - - } - - /** - * Sends Dmaap notification to Policy. - * - * @throws ConfigDbNotFoundException - * when config db is unreachable - */ - private void sendToPolicy(AsyncResponseBody async, String networkId) throws ConfigDbNotFoundException { - - if (log.isDebugEnabled()) { - log.debug(async.toString()); - } - - List<Solution> solutions; - solutions = async.getSolutions(); - - Map<String, List<CellPciPair>> pnfs = getPnfs(solutions); - - for (Map.Entry<String, List<CellPciPair>> entry : pnfs.entrySet()) { - String pnfName = entry.getKey(); - List<CellPciPair> cellPciPairs = entry.getValue(); - - String notification = getNotificationString(pnfName, cellPciPairs, networkId); - log.debug("Policy Notification: {}", notification); - PolicyDmaapClient policy = new PolicyDmaapClient(); - boolean status = policy.sendNotificationToPolicy(notification); - log.debug("sent Message: {}", status); - if (status) { - log.debug("Message sent to policy"); - } else { - log.debug("Sending notification to policy failed"); - } - - } - } - - private String getNotificationString(String pnfName, List<CellPciPair> cellPciPairs, String networkId) { - 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))))))); - configurations.add(configuration); - } - - Payload payload = new Payload(configurations); - ObjectMapper mapper = new ObjectMapper(); - String payloadString = ""; - try { - payloadString = mapper.writeValueAsString(payload); - } catch (JsonProcessingException e) { - log.debug("JSON processing exception: {}", e); - } - PolicyNotification policyNotification = new PolicyNotification(); - ConfigPolicy configPolicy = ConfigPolicy.getInstance(); - String closedLoopControlName = (String) configPolicy.getConfig().get("PCI_MODCONFIG_POLICY_NAME"); - policyNotification.setClosedLoopControlName(closedLoopControlName); - policyNotification.setPayload(payloadString); - - mapper.setSerializationInclusion(Include.NON_NULL); - String notification = ""; - try { - notification = mapper.writeValueAsString(policyNotification); - } catch (JsonProcessingException e1) { - log.debug("JSON processing exception: {}", e1); - } - return notification; - } - - private Map<String, List<CellPciPair>> getPnfs(List<Solution> solutions) throws ConfigDbNotFoundException { - - Map<String, List<CellPciPair>> pnfs = new HashMap<>(); - - for (Solution solution : solutions) { - List<SonSolution> pciSolutions = solution.getPciSolutions(); - for (SonSolution pciSolution : pciSolutions) { - String cellId = pciSolution.getCellId(); - int pci = pciSolution.getPci(); - - String pnfName = ""; - CellInfoRepository cellInfoRepository = BeanUtil.getBean(CellInfoRepository.class); - Optional<CellInfo> cellInfo = cellInfoRepository.findById(cellId); - if (cellInfo.isPresent()) { - pnfName = cellInfo.get().getPnfName(); - } else { - pnfName = SdnrRestClient.getPnfName(cellId); - cellInfoRepository.save(new CellInfo(cellId, pnfName)); - } - if (pnfs.containsKey(pnfName)) { - pnfs.get(pnfName).add(new CellPciPair(cellId, pci)); - } else { - List<CellPciPair> cellPciPairs = new ArrayList<>(); - cellPciPairs.add(new CellPciPair(cellId, pci)); - pnfs.put(pnfName, cellPciPairs); - } - } - - } - return pnfs; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/dao/CellInfoRepository.java b/src/main/java/com/wipro/www/sonhms/dao/CellInfoRepository.java deleted file mode 100644 index c4e1f8b..0000000 --- a/src/main/java/com/wipro/www/sonhms/dao/CellInfoRepository.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.dao; - -import com.wipro.www.sonhms.entity.CellInfo; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - - -@Repository -public interface CellInfoRepository extends CrudRepository<CellInfo, String> { - - // public void - -} diff --git a/src/main/java/com/wipro/www/sonhms/dao/DmaapNotificationsRepository.java b/src/main/java/com/wipro/www/sonhms/dao/DmaapNotificationsRepository.java deleted file mode 100644 index 1ac2ff4..0000000 --- a/src/main/java/com/wipro/www/sonhms/dao/DmaapNotificationsRepository.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.dao; - -import com.wipro.www.sonhms.entity.DmaapNotifications; - -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - - -@Repository -public interface DmaapNotificationsRepository extends CrudRepository<DmaapNotifications, String> { - - @Query(nativeQuery = true, - value = "DELETE FROM dmaap_notifications " - + "WHERE notification = ( SELECT notification FROM dmaap_notifications ORDER BY " - + "created_at FOR UPDATE SKIP LOCKED LIMIT 1 ) RETURNING notification;") - - public String getNotificationFromQueue(); - -} diff --git a/src/main/java/com/wipro/www/sonhms/dao/SonRequestsRepository.java b/src/main/java/com/wipro/www/sonhms/dao/SonRequestsRepository.java deleted file mode 100644 index 6b0458d..0000000 --- a/src/main/java/com/wipro/www/sonhms/dao/SonRequestsRepository.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.dao; - -import com.wipro.www.sonhms.entity.PciRequests; - -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - - -@Repository -@Transactional -public interface SonRequestsRepository extends CrudRepository<PciRequests, String> { - - @Query(nativeQuery = true, value = "SELECT child_thread_id FROM pci_requests WHERE transaction_id = ?1") - public long getChildThreadMapping(String transactionId); - - @Modifying - @Query(nativeQuery = true, value = "DELETE FROM pci_requests WHERE child_thread_id = ?1") - public void deleteByChildThreadId(Long threadId); - -} diff --git a/src/main/java/com/wipro/www/sonhms/dmaap/NotificationProducer.java b/src/main/java/com/wipro/www/sonhms/dmaap/NotificationProducer.java deleted file mode 100644 index 7dd505f..0000000 --- a/src/main/java/com/wipro/www/sonhms/dmaap/NotificationProducer.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.dmaap; - -import com.att.nsa.cambria.client.CambriaBatchingPublisher; -import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder; - -import java.io.IOException; -import java.security.GeneralSecurityException; -import java.util.List; - -public class NotificationProducer { - - private List<String> servers; - private String apiKey; - private String secret; - - /** - * Parameterised constructor. - */ - public NotificationProducer(List<String> servers, String apiKey, String secret) { - super(); - this.servers = servers; - this.apiKey = apiKey; - this.secret = secret; - } - - /** - * sends notification to dmaap. - */ - public int sendNotification(String topic, String msg) throws GeneralSecurityException, IOException { - CambriaBatchingPublisher cambriaBatchingPublisher = null; - cambriaBatchingPublisher = new PublisherBuilder().usingHosts(servers).onTopic(topic) - .authenticatedBy(apiKey, secret).build(); - return cambriaBatchingPublisher.send("", msg); - - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/dmaap/PolicyDmaapClient.java b/src/main/java/com/wipro/www/sonhms/dmaap/PolicyDmaapClient.java deleted file mode 100644 index f1491b4..0000000 --- a/src/main/java/com/wipro/www/sonhms/dmaap/PolicyDmaapClient.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.dmaap; - -import com.wipro.www.sonhms.Configuration; - -import java.io.IOException; -import java.security.GeneralSecurityException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class PolicyDmaapClient { - - private static Logger log = LoggerFactory.getLogger(PolicyDmaapClient.class); - - /** - * Method stub for sending notification to policy. - */ - public boolean sendNotificationToPolicy(String msg) { - - Configuration configuration = Configuration.getInstance(); - NotificationProducer notificationProducer = new NotificationProducer(configuration.getServers(), - configuration.getPcimsApiKey(), configuration.getPcimsSecretKey()); - try { - int result = notificationProducer.sendNotification(configuration.getPolicyTopic(), msg); - log.debug("result: {}", result); - } catch (GeneralSecurityException | IOException e) { - log.debug("exception when sending notification to policy", e); - return false; - } - return true; - } -} diff --git a/src/main/java/com/wipro/www/sonhms/exceptions/ConfigDbNotFoundException.java b/src/main/java/com/wipro/www/sonhms/exceptions/ConfigDbNotFoundException.java deleted file mode 100644 index 70127b5..0000000 --- a/src/main/java/com/wipro/www/sonhms/exceptions/ConfigDbNotFoundException.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.exceptions; - -public class ConfigDbNotFoundException extends Exception { - - /** - * serial version. - */ - private static final long serialVersionUID = 1L; - - public ConfigDbNotFoundException(String message) { - super(message); - } -} diff --git a/src/main/java/com/wipro/www/sonhms/exceptions/OofNotFoundException.java b/src/main/java/com/wipro/www/sonhms/exceptions/OofNotFoundException.java deleted file mode 100644 index fb95a0f..0000000 --- a/src/main/java/com/wipro/www/sonhms/exceptions/OofNotFoundException.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.exceptions; - -public class OofNotFoundException extends Exception { - /** - * serial version. - */ - private static final long serialVersionUID = 1L; - - public OofNotFoundException(String message) { - super(message); - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/CellConfig.java b/src/main/java/com/wipro/www/sonhms/model/CellConfig.java deleted file mode 100644 index 1fab733..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/CellConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - */ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class CellConfig { - - @JsonProperty(value = "LTE") - private Lte lte; - - public CellConfig() { - - } - - public CellConfig(Lte lte) { - super(); - this.lte = lte; - } - - public Lte getLte() { - return lte; - } - - public void setLte(Lte lte) { - this.lte = lte; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/Common.java b/src/main/java/com/wipro/www/sonhms/model/Common.java deleted file mode 100644 index f317467..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/Common.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Common { - - @JsonProperty(value = "CellIdentity") - private String cellIdentity; - - public Common() { - - } - - public Common(String cellIdentity) { - super(); - this.cellIdentity = cellIdentity; - } - - public String getCellIdentity() { - return cellIdentity; - } - - public void setCellIdentity(String cellIdentity) { - this.cellIdentity = cellIdentity; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/Configurations.java b/src/main/java/com/wipro/www/sonhms/model/Configurations.java deleted file mode 100644 index f5dcd7e..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/Configurations.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Configurations { - @JsonProperty("data") - private Data data; - - /** - * constructor. - * - */ - public Configurations() { - - } - - /** - * Parameterized constructor. - * - */ - public Configurations(Data data) { - super(); - this.data = data; - } - - public Data getData() { - return data; - } - - public void setData(Data data) { - this.data = data; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/Data.java b/src/main/java/com/wipro/www/sonhms/model/Data.java deleted file mode 100644 index 6bff144..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/Data.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Data { - - @JsonProperty("FAPService") - private FapService fapservice; - - public Data() { - - } - - public Data(FapService fapservice) { - super(); - this.fapservice = fapservice; - } - - public FapService getFapservice() { - return fapservice; - } - - public void setFapservice(FapService fapservice) { - this.fapservice = fapservice; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/Lte.java b/src/main/java/com/wipro/www/sonhms/model/Lte.java deleted file mode 100644 index 871f100..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/Lte.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Lte { - - @JsonProperty(value = "RAN") - private Ran ran; - - public Lte() { - - } - - public Lte(Ran ran) { - super(); - this.ran = ran; - } - - public Ran getRan() { - return ran; - } - - public void setRan(Ran ran) { - this.ran = ran; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/NotificationCellConfig.java b/src/main/java/com/wipro/www/sonhms/model/NotificationCellConfig.java deleted file mode 100644 index a3acaf0..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/NotificationCellConfig.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class NotificationCellConfig { - - @JsonProperty("LTE") - private NotificationLte lte; - - public NotificationCellConfig() { - - } - - /** - * Parameterized Constructor. - */ - - public NotificationCellConfig(NotificationLte lte) { - super(); - this.lte = lte; - } - - public NotificationLte getLte() { - return lte; - } - - public void setLte(NotificationLte lte) { - this.lte = lte; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/NotificationLte.java b/src/main/java/com/wipro/www/sonhms/model/NotificationLte.java deleted file mode 100644 index f1e26e7..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/NotificationLte.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class NotificationLte { - - @JsonProperty("RAN") - private NotificationRan ran; - - public NotificationLte() { - - } - - /** - * Parameterized Constructor. - */ - - public NotificationLte(NotificationRan ran) { - super(); - this.ran = ran; - } - - public NotificationRan getRan() { - return ran; - } - - public void setRan(NotificationRan ran) { - this.ran = ran; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/NotificationPayload.java b/src/main/java/com/wipro/www/sonhms/model/NotificationPayload.java deleted file mode 100644 index fea882b..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/NotificationPayload.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class NotificationPayload { - - @JsonProperty("RadioAccess") - private RadioAccess radioAccess; - - public NotificationPayload() { - - } - - /** - * Parameterized Constructor. - */ - - public NotificationPayload(RadioAccess radioAccess) { - super(); - this.radioAccess = radioAccess; - } - - public RadioAccess getRadioAccess() { - return radioAccess; - } - - public void setRadioAccess(RadioAccess radioAccess) { - this.radioAccess = radioAccess; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/Payload.java b/src/main/java/com/wipro/www/sonhms/model/Payload.java deleted file mode 100644 index 9f10acb..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/Payload.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -public class Payload { - - @JsonProperty("Configurations") - private List<Configurations> configuration; - - public Payload() { - - } - - public Payload(List<Configurations> configuration) { - super(); - this.configuration = configuration; - } - - public List<Configurations> getConfiguration() { - return configuration; - } - - public void setConfiguration(List<Configurations> configuration) { - this.configuration = configuration; - } - - @Override - public String toString() { - return "Payload [configuration=" + configuration + "]"; - - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/Ran.java b/src/main/java/com/wipro/www/sonhms/model/Ran.java deleted file mode 100644 index d4dda3a..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/Ran.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Ran { - - @JsonProperty(value = "Common") - private Common common; - - public Ran() { - - } - - /** - * Parameterized constructor. - */ - public Ran(Common common) { - super(); - this.common = common; - } - - public Common getCommon() { - return common; - } - - public void setCommon(Common common) { - this.common = common; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/Response.java b/src/main/java/com/wipro/www/sonhms/model/Response.java deleted file mode 100644 index e34c10f..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/Response.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Response { - - @JsonProperty(value = "cellId") - private String cellId; - - private int pci; - - public String getCellId() { - return cellId; - } - - public void setCellId(String cellId) { - this.cellId = cellId; - } - - public int getPci() { - return pci; - } - - public void setPci(int pci) { - this.pci = pci; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/SdnrResponse.java b/src/main/java/com/wipro/www/sonhms/model/SdnrResponse.java deleted file mode 100644 index b57b20e..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/SdnrResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import java.util.List; - -public class SdnrResponse { - - private List<Response> response; - - public List<Response> getResponse() { - return response; - } - - public void setResponse(List<Response> response) { - this.response = response; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/model/ThreadId.java b/src/main/java/com/wipro/www/sonhms/model/ThreadId.java deleted file mode 100644 index d0139f2..0000000 --- a/src/main/java/com/wipro/www/sonhms/model/ThreadId.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -public class ThreadId { - - private long childThreadId; - - public long getChildThreadId() { - return childThreadId; - } - - public void setChildThreadId(long childThreadId) { - this.childThreadId = childThreadId; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/restclient/CellInfo.java b/src/main/java/com/wipro/www/sonhms/restclient/CellInfo.java deleted file mode 100644 index 77d4003..0000000 --- a/src/main/java/com/wipro/www/sonhms/restclient/CellInfo.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -import java.util.ArrayList; -import java.util.List; - -public class CellInfo { - String networkId = null; - List<String> cellIdList = new ArrayList<>(); - - public String getNetworkId() { - return networkId; - } - - public void setNetworkId(String networkId) { - this.networkId = networkId; - } - - public List<String> getCellIdList() { - return cellIdList; - } - - public void setCellIdList(List<String> cellIdList) { - this.cellIdList = cellIdList; - } - - - -} diff --git a/src/main/java/com/wipro/www/sonhms/restclient/OofRequestBody.java b/src/main/java/com/wipro/www/sonhms/restclient/OofRequestBody.java deleted file mode 100644 index edee572..0000000 --- a/src/main/java/com/wipro/www/sonhms/restclient/OofRequestBody.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -public class OofRequestBody { - - protected RequestInfo requestInfo = new RequestInfo(); - protected CellInfo cellInfo = new CellInfo(); - - public RequestInfo getRequestInfo() { - return requestInfo; - } - - public void setRequestInfo(RequestInfo requestInfo) { - this.requestInfo = requestInfo; - } - - public CellInfo getCellInfo() { - return cellInfo; - } - - public void setCellInfo(CellInfo cellInfo) { - this.cellInfo = cellInfo; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/restclient/PolicyRequestBody.java b/src/main/java/com/wipro/www/sonhms/restclient/PolicyRequestBody.java deleted file mode 100644 index e9e7b0d..0000000 --- a/src/main/java/com/wipro/www/sonhms/restclient/PolicyRequestBody.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -public class PolicyRequestBody { - - String configName = null; - String policyName = null; - String requestId = null; - - public String getConfigName() { - return configName; - } - - public void setConfigName(String configName) { - this.configName = configName; - } - - public String getPolicyName() { - return policyName; - } - - public void setPolicyName(String policyName) { - this.policyName = policyName; - } - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/restclient/SonSolution.java b/src/main/java/com/wipro/www/sonhms/restclient/SonSolution.java deleted file mode 100644 index 4872fc7..0000000 --- a/src/main/java/com/wipro/www/sonhms/restclient/SonSolution.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -public class SonSolution { - - String cellId = null; - int pci; - - public String getCellId() { - return cellId; - } - - public void setCellId(String cellId) { - this.cellId = cellId; - } - - public int getPci() { - return pci; - } - - public void setPci(int pci) { - this.pci = pci; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/utils/BeanUtil.java b/src/main/java/com/wipro/www/sonhms/utils/BeanUtil.java deleted file mode 100644 index 9d7cdb3..0000000 --- a/src/main/java/com/wipro/www/sonhms/utils/BeanUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.utils; - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Service; - -@Service -public class BeanUtil implements ApplicationContextAware { - private static ApplicationContext context; - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - context = applicationContext; - } - - public static <T> T getBean(Class<T> beanClass) { - return context.getBean(beanClass); - } -} diff --git a/src/main/java/com/wipro/www/sonhms/utils/FileIo.java b/src/main/java/com/wipro/www/sonhms/utils/FileIo.java deleted file mode 100644 index 929ae95..0000000 --- a/src/main/java/com/wipro/www/sonhms/utils/FileIo.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.utils; - -import java.io.BufferedReader; -import java.io.FileReader; - -public class FileIo { - - private FileIo() { - - } - - /** - * Reads from File. - */ - public static String readFromFile(String file) { - String content = ""; - try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { - content = bufferedReader.readLine(); - String temp; - while ((temp = bufferedReader.readLine()) != null) { - content = content.concat(temp); - } - content = content.trim(); - } catch (Exception e) { - content = null; - } - return content; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/utils/HttpRequester.java b/src/main/java/com/wipro/www/sonhms/utils/HttpRequester.java deleted file mode 100644 index 4e4e411..0000000 --- a/src/main/java/com/wipro/www/sonhms/utils/HttpRequester.java +++ /dev/null @@ -1,284 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.utils; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HttpRequester { - - private static final String ACCEPT = "Accept"; - private static final String JSON = "application/json"; - private static final String CONTENT = "Content-Type"; - private static final String UTF = "UTF-8"; - private static final String FAILMSG = "Post failed"; - private static final String AUTH = "Authorization"; - private static Logger log = LoggerFactory.getLogger(HttpRequester.class); - - public static class MyHostnameVerifier implements HostnameVerifier { - - @Override - public boolean verify(String hostname, SSLSession session) { - // verification of hostname is switched off - log.debug("Hostname: {}", hostname); - return true; - } - } - - /** - * Send Post Request. - */ - public static String sendPostRequest(String requestUrl, String requestBody) { - String response = ""; - - try { - URL url = new URL(requestUrl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setRequestMethod("POST"); - connection.setRequestProperty(ACCEPT, JSON); - connection.setRequestProperty(CONTENT, JSON); - OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), UTF); - writer.write(requestBody); - writer.close(); - BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String temp; - int responseCode = connection.getResponseCode(); - log.debug("response code: {}", responseCode); - response = br.readLine(); - while ((temp = br.readLine()) != null) { - response = response.concat(temp); - } - br.close(); - connection.disconnect(); - - if (response == null) { - response = String.valueOf(responseCode); - } - - } catch (Exception e) { - response = FAILMSG; - } - - return response; - } - - /** - * Send Post Request to policy. - */ - public static String sendPostToPolicy(String requestUrl, String requestBody) { - String response = ""; - log.debug("inside post to policy"); - - try { - URL url = new URL(requestUrl); - - HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); - connection.setHostnameVerifier(new MyHostnameVerifier()); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setRequestMethod("POST"); - connection.setRequestProperty(ACCEPT, JSON); - connection.setRequestProperty(CONTENT, JSON); - connection.setRequestProperty("ClientAuth", "cHl0aG9uOnRlc3Q="); - connection.setRequestProperty("Environment", "TEST"); - connection.setRequestProperty(AUTH, "Basic dGVzdHBkcDphbHBoYTEyMw=="); - OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), UTF); - writer.write(requestBody); - writer.close(); - BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String temp; - int responseCode = connection.getResponseCode(); - log.debug("response code: {}", responseCode); - response = br.readLine(); - while ((temp = br.readLine()) != null) { - response = response.concat(temp); - } - br.close(); - connection.disconnect(); - - } catch (Exception e) { - log.debug("Exception during post to policy: {}", e); - response = FAILMSG; - } - - return response; - } - - /** - * Send Get Request. - */ - public static String sendGetRequest(String requestUrl) { - String response = ""; - int returnCode = 0; - - try { - URL url = new URL(requestUrl); - HttpURLConnection connection = null; - connection = (HttpURLConnection) url.openConnection(); - connection.setDoInput(true); - connection.setRequestMethod("GET"); - connection.setRequestProperty(ACCEPT, JSON); - returnCode = connection.getResponseCode(); - InputStream connectionIn = null; - if (returnCode == 200) { - connectionIn = connection.getInputStream(); - BufferedReader buffer = new BufferedReader(new InputStreamReader(connectionIn)); - String inputLine; - while ((inputLine = buffer.readLine()) != null) { - response = response.concat(inputLine); - } - buffer.close(); - } - - else { - response = ""; - log.debug("return code: {}", returnCode); - } - } catch (Exception e) { - log.debug("Get failed,Exception : {}", e); - response = ""; - } - return response; - - } - - /** - * Send Get Request to SDNR. - */ - public String sendGetRequest(String requestUrl, String requestBody) { - String response; - try { - URL url = new URL(requestUrl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setRequestMethod("POST"); - connection.setRequestProperty(ACCEPT, "text/plain"); - connection.setRequestProperty(CONTENT, JSON); - connection.setRequestProperty(AUTH, "Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA=="); - OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), UTF); - writer.write(requestBody); - writer.close(); - BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String temp; - response = br.readLine(); - while ((temp = br.readLine()) != null) { - response = response.concat(temp); - } - br.close(); - connection.disconnect(); - - } catch (Exception e) { - response = FAILMSG; - } - - return response; - } - - /** - * Send Post Request. - */ - public String sendPostRequest1(String requestUrl, String requestBody) { - String response; - try { - URL url = new URL(requestUrl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setRequestMethod("POST"); - connection.setRequestProperty(ACCEPT, JSON); - connection.setRequestProperty(CONTENT, JSON); - connection.setRequestProperty(AUTH, "Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA=="); - connection.setRequestProperty("Content-Length", "" + requestBody.length()); - OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), UTF); - writer.write(requestBody); - writer.close(); - BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String temp; - response = br.readLine(); - while ((temp = br.readLine()) != null) { - response = response.concat(temp); - } - br.close(); - connection.disconnect(); - - } catch (Exception e) { - response = FAILMSG; - } - - return response; - } - - /** - * Send Post Request to oof. - */ - public static String sendPostRequestToOof(String requestUrl, String requestBody) { - String response = ""; - - try { - URL url = new URL(requestUrl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setRequestMethod("POST"); - connection.setRequestProperty(ACCEPT, JSON); - connection.setRequestProperty(CONTENT, JSON); - connection.setRequestProperty(AUTH, "Basic cGNpX3Rlc3Q6cGNpX3Rlc3Rwd2Q="); - OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), UTF); - writer.write(requestBody); - writer.close(); - BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String temp; - int responseCode = connection.getResponseCode(); - log.debug("response code: {}", responseCode); - response = br.readLine(); - while ((temp = br.readLine()) != null) { - response = response.concat(temp); - } - br.close(); - connection.disconnect(); - - if (response == null) { - log.debug("Response code: {}", responseCode); - } - - } catch (Exception e) { - log.debug("exception occured when posting: {}", e); - return null; - } - - return response; - } - -} diff --git a/src/main/java/com/wipro/www/sonhms/Application.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java index 4c831b4..7eb9e62 100644 --- a/src/main/java/com/wipro/www/sonhms/Application.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java @@ -1,29 +1,30 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms; +package org.onap.dcaegen2.services.sonhms; import com.fasterxml.jackson.databind.ObjectMapper; -import com.wipro.www.sonhms.dmaap.DmaapClient; -import com.wipro.www.sonhms.restclient.PolicyRestClient; -import com.wipro.www.sonhms.utils.FileIo; +import org.onap.dcaegen2.services.sonhms.dmaap.DmaapClient; +import org.onap.dcaegen2.services.sonhms.restclient.PolicyRestClient; +import org.onap.dcaegen2.services.sonhms.utils.FileIo; import java.io.IOException; import java.util.ArrayList; diff --git a/src/main/java/com/wipro/www/sonhms/BufferNotificationComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponent.java index 6074a31..50dec11 100644 --- a/src/main/java/com/wipro/www/sonhms/BufferNotificationComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponent.java @@ -1,28 +1,29 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import com.wipro.www.sonhms.dao.BufferedNotificationsRepository; -import com.wipro.www.sonhms.entity.BufferedNotifications; -import com.wipro.www.sonhms.utils.BeanUtil; + * 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; + +import org.onap.dcaegen2.services.sonhms.dao.BufferedNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.entity.BufferedNotifications; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import java.util.List; public class BufferNotificationComponent { diff --git a/src/main/java/com/wipro/www/sonhms/ClusterDetailsComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponent.java index 939f9e1..8e4b357 100644 --- a/src/main/java/com/wipro/www/sonhms/ClusterDetailsComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponent.java @@ -1,28 +1,29 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import com.wipro.www.sonhms.dao.ClusterDetailsRepository; -import com.wipro.www.sonhms.entity.ClusterDetails; -import com.wipro.www.sonhms.utils.BeanUtil; + * 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; + +import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository; +import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import java.util.List; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/ConfigPolicy.java b/src/main/java/org/onap/dcaegen2/services/sonhms/ConfigPolicy.java new file mode 100644 index 0000000..7c065ac --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/ConfigPolicy.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============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; + +import java.util.Map; + +public class ConfigPolicy { + + private static ConfigPolicy instance = null; + private Map<String, Object> config; + + protected ConfigPolicy() { + + } + + /** + * Get instance of class. + */ + public static ConfigPolicy getInstance() { + if (instance == null) { + instance = new ConfigPolicy(); + } + return instance; + } + + public Map<String, Object> getConfig() { + return config; + } + + public void setConfig(Map<String, Object> config) { + this.config = config; + } + + @Override + public String toString() { + return "ConfigPolicy [config=" + config + "]"; + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/Configuration.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java index fb53f9b..a90a0b9 100644 --- a/src/main/java/com/wipro/www/sonhms/Configuration.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; + * 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; import java.util.List; @@ -50,6 +51,33 @@ public class Configuration { private int numSolutions; private int bufferTime; private int maximumClusters; + private String consulHost; + private String hostName; + private String configBindingService; + + public String getConsulHost() { + return consulHost; + } + + public void setConsulHost(String consulHost) { + this.consulHost = consulHost; + } + + public String getHostName() { + return hostName; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + public String getConfigBindingService() { + return configBindingService; + } + + public void setConfigBindingService(String configBindingService) { + this.configBindingService = configBindingService; + } public int getMaximumClusters() { return maximumClusters; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/ConfigurationFetcher.java b/src/main/java/org/onap/dcaegen2/services/sonhms/ConfigurationFetcher.java new file mode 100644 index 0000000..4a55393 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/ConfigurationFetcher.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============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; + +import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; + + +public class ConfigurationFetcher { + private static Logger log = LoggerFactory.getLogger(ConfigurationFetcher.class); + + /** + * method that fetches config from config binding service. + */ + public void fetchFromCbs() { + + Configuration configuration = Configuration.getInstance(); + String consulHost = configuration.getConsulHost(); + String configBindingService = configuration.getConfigBindingService(); + ResponseEntity<String> response = null; + String requestUrl = ""; + if ((consulHost != null) && (configBindingService != null)) { + requestUrl = consulHost + ":8500/v1/catalog/service/" + configBindingService; + response = SonHandlerRestTemplate.sendPostRequest(requestUrl, "", + new ParameterizedTypeReference<String>() {}); + } + JSONTokener jsonTokener = new JSONTokener(response.getBody()); + JSONObject cbsjobj = (JSONObject) new JSONArray(jsonTokener).get(0); + String cbsUrl = ""; + String configurationRequestUrl = ""; + ResponseEntity<String> configurationResponse = null; + if (cbsjobj.has("ServiceAddress") && cbsjobj.has("ServicePort")) { + cbsUrl = cbsjobj.getString("ServiceAddress") + ":" + cbsjobj.getInt("ServicePort"); + + } + + configurationRequestUrl = cbsUrl + "/service_component/" + configuration.getHostName(); + configurationResponse = SonHandlerRestTemplate.sendPostRequest1(configurationRequestUrl, "", + new ParameterizedTypeReference<String>() {}); + JSONObject config = new JSONObject(new JSONTokener(configurationResponse.getBody())); + String configString = config.toString(); + log.debug("config:{}",configString); + } + + +}
\ No newline at end of file diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java new file mode 100644 index 0000000..f28de63 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============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; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import fj.data.Either; + +import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DmaapNotificationsComponent { + + private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); + + /** + * Get dmaap notifications. + */ + public Either<Notification, Integer> getDmaapNotifications() { + DmaapNotificationsRepository dmaapNotificationsRepository = BeanUtil + .getBean(DmaapNotificationsRepository.class); + String notificationString = dmaapNotificationsRepository.getNotificationFromQueue(); + ObjectMapper mapper = new ObjectMapper(); + + Notification notification = new Notification(); + try { + notification = mapper.readValue(notificationString, Notification.class); + return Either.left(notification); + } catch (IOException e) { + log.error("Exception in parsing notification", notificationString, e); + return Either.right(400); + } + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java new file mode 100644 index 0000000..312ca60 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java @@ -0,0 +1,252 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * pcims + * ================================================================================ + * 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========================================================= + ******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.dcaegen2.services.sonhms.child.ChildThread; +import org.onap.dcaegen2.services.sonhms.child.Graph; +import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails; +import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; +import org.onap.dcaegen2.services.sonhms.utils.ThreadUtils; + +import fj.data.Either; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class EventHandler { + + private static Logger log = LoggerFactory.getLogger(EventHandler.class); + + private static Map<Long, ChildThread> childThreadMap = new HashMap<>(); + + private BlockingQueue<List<String>> childStatusQueue; + + private Map<Long, String> childStatus; + + private ExecutorService pool; + + private ClusterUtils clusterUtils; + + private ThreadUtils threadUtils; + + /** + * Constructor. + */ + public EventHandler(BlockingQueue<List<String>> childStatusQueue, ExecutorService pool, + Map<Long, String> childStatus, ClusterUtils clusterUtils, ThreadUtils threadUtils) { + + this.childStatusQueue = childStatusQueue; + this.childStatus = childStatus; + this.pool = pool; + this.clusterUtils = clusterUtils; + this.threadUtils = threadUtils; + } + + /** + * handle sdnr notification. + */ + public Boolean handleSdnrNotification(Notification notification) { + // Check if notification matches with a cluster + + try { + List<ClusterDetails> clusterDetails = clusterUtils.getAllClusters(); + + NotificationToClusterMapping mapping = new NotificationToClusterMapping(); + mapping = clusterUtils.getClustersForNotification(notification, clusterDetails); + + // Matching cells + System.out.println(mapping); + if (mapping.getCellsinCluster() != null) { + handleMatchingCells(mapping.getCellsinCluster(), clusterDetails); + } + + // unmatched cells + if (mapping.getNewCells() != null) { + handleUnMatchingCells(mapping.getNewCells()); + } + } catch (Exception e) { + log.error("Exception in sdnr notification handling {}", e); + return false; + } + + return true; + + } + + private void handleUnMatchingCells(List<FapServiceList> newCells) { + List<Graph> newClusters = new ArrayList<>(); + + for (FapServiceList fapService : newCells) { + + Either<Graph, Integer> existingCluster = clusterUtils.getClusterForCell(fapService, newClusters); + if (existingCluster.isRight()) { + try { + Graph cluster = clusterUtils.createCluster(fapService); + newClusters.add(cluster); + } catch (ConfigDbNotFoundException e) { + log.error("Error connecting with configDB {}", e); + } + } + + else { + Graph cluster = existingCluster.left().value(); + + Graph modifiedCluster = clusterUtils.modifyCluster(cluster, fapService); + newClusters.remove(cluster); + newClusters.add(modifiedCluster); + } + + } + + // create new child thread + + threadUtils.createNewThread(newClusters, childStatusQueue, pool, this); + + } + + private void handleMatchingCells(Map<FapServiceList, String> cellsInCluster, List<ClusterDetails> clusterDetails) { + for (Entry<FapServiceList, String> entry : cellsInCluster.entrySet()) { + + FapServiceList fapService = entry.getKey(); + String clusterId = entry.getValue(); + Either<ClusterDetails, Integer> clusterDetail = clusterUtils.getClusterDetailsFromClusterId(clusterId, + clusterDetails); + + if (clusterDetail.isRight()) { + log.error("Cannot find the cluster for Cluster ID"); + return; + } else { + long threadId = clusterDetail.left().value().getChildThreadId(); + + if (childStatus.get(threadId).equals("triggeredOof")) { + log.info("OOF triggered for the cluster, buffering notification"); + bufferNotification(fapService, clusterId); + } else { + childThreadMap.get(threadId).putInQueue(fapService); + } + } + } + } + + private void bufferNotification(FapServiceList fapService, String clusterId) { + ObjectMapper mapper = new ObjectMapper(); + BufferNotificationComponent bufferNotifComponent = new BufferNotificationComponent(); + String serviceListString = ""; + try { + serviceListString = mapper.writeValueAsString(fapService); + } catch (JsonProcessingException e) { + log.debug("JSON processing exception: {}", e); + } + bufferNotifComponent.bufferNotification(serviceListString, clusterId); + + } + + /** + * handle child status update. + */ + public void handleChildStatusUpdate(List<String> childStatus) { + + // update Child status in data structure + Long childThreadId = Long.parseLong(childStatus.get(0)); + addChildStatus(childThreadId, childStatus.get(1)); + + // if child status is OOF result success, handle buffered notifications + if (childStatus.get(1).equals("success")) { + BufferNotificationComponent bufferNotificationComponent = new BufferNotificationComponent(); + ClusterDetailsComponent clusterDetailsComponent = new ClusterDetailsComponent(); + String clusterId = clusterDetailsComponent.getClusterId(childThreadId); + List<String> bufferedNotifications = bufferNotificationComponent.getBufferedNotification(clusterId); + + if (bufferedNotifications == null || bufferedNotifications.isEmpty()) { + log.info("No buffered notification for this thread"); + + Set<Thread> setOfThread = Thread.getAllStackTraces().keySet(); + for (Thread thread : setOfThread) { + if (thread.getId() == childThreadId) { + deleteChildStatus(childThreadId); + thread.interrupt(); + } + } + } else { + handleBufferedNotifications(childThreadId, bufferedNotifications); + } + } + // else kill the child thread + + } + + private void handleBufferedNotifications(Long childThreadId, List<String> bufferedNotifications) { + + ObjectMapper mapper = new ObjectMapper(); + for (String notification : bufferedNotifications) { + FapServiceList fapServiceList; + try { + fapServiceList = mapper.readValue(notification, FapServiceList.class); + log.debug("fapServiceList{}", fapServiceList); + + childThreadMap.get(childThreadId).putInQueueWithNotify(fapServiceList); + + } catch (IOException e) { + log.error("Error parsing the buffered notification, skipping {}", e); + } + } + } + + public static void addChildThreadMap(Long childThreadId, ChildThread child) { + childThreadMap.put(childThreadId, child); + } + + public static Map<Long, ChildThread> getChildThreadMap() { + return childThreadMap; + } + + public void addChildStatus(Long threadId, String status) { + this.childStatus.put(threadId, status); + } + + public String getChildStatus(Long threadId) { + return childStatus.get(threadId); + + } + + public void deleteChildStatus(Long childThreadId) { + this.childStatus.remove(childThreadId); + + } + + public ExecutorService getPool() { + return pool; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java new file mode 100644 index 0000000..2026500 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * ============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; + +import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; +import org.onap.dcaegen2.services.sonhms.utils.ThreadUtils; + +import fj.data.Either; + +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MainThread implements Runnable { + private static Logger log = LoggerFactory.getLogger(MainThread.class); + + private NewNotification newNotification; + + private BlockingQueue<List<String>> childStatusQueue; + + private DmaapNotificationsComponent dmaapNotificationsComponent; + + private EventHandler eventHandler; + + /** + * parameterized constructor. + */ + public MainThread(NewNotification newNotification) { + super(); + this.newNotification = newNotification; + childStatusQueue = new LinkedBlockingQueue<>(); + dmaapNotificationsComponent = new DmaapNotificationsComponent(); + eventHandler = new EventHandler(childStatusQueue, + Executors.newFixedThreadPool(Configuration.getInstance().getMaximumClusters()), + new HashMap<>(), new ClusterUtils(), new ThreadUtils()); + } + + @Override + public void run() { + log.info("Starting Main Thread"); + + // Check for Notifications from Dmaap and Child thread + Boolean done = false; + + while (!done) { + try { + if (!childStatusQueue.isEmpty()) { + List<String> childState = childStatusQueue.poll(); + if (childState != null) { + eventHandler.handleChildStatusUpdate(childState); + } + } + + if (newNotification.getNewNotif()) { + Either<Notification, Integer> notification = dmaapNotificationsComponent.getDmaapNotifications(); + if (notification.isRight()) { + log.error("Error parsing the notification from SDNR"); + } else if (notification.isLeft()) { + Boolean result = eventHandler.handleSdnrNotification(notification.left().value()); + log.debug("SDNR notification handling {}", result); + } + + } + + } catch (Exception e) { + log.error("Exception in main Thread", e); + done = true; + } + + } + + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java new file mode 100644 index 0000000..f83541a --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============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; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class MainThreadComponent { + + private static Logger log = LoggerFactory.getLogger(MainThreadComponent.class); + + + + /** + * main thread initialization. + */ + public void init(NewNotification newNotification) { + log.debug("initializing main thread"); + Thread thread = new Thread(new MainThread(newNotification)); + thread.start(); + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/NewNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/NewNotification.java new file mode 100644 index 0000000..9f6e57f --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/NewNotification.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * ============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; + +public class NewNotification { + + private Boolean newNotif; + + public Boolean getNewNotif() { + return newNotif; + } + + public void setNewNotif(Boolean newNotif) { + this.newNotif = newNotif; + } + + public NewNotification(Boolean newNotif) { + super(); + this.newNotif = newNotif; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/NotificationToClusterMapping.java b/src/main/java/org/onap/dcaegen2/services/sonhms/NotificationToClusterMapping.java new file mode 100644 index 0000000..14961e5 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/NotificationToClusterMapping.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * ============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; + +import org.onap.dcaegen2.services.sonhms.model.FapServiceList; + +import java.util.List; +import java.util.Map; + + +public class NotificationToClusterMapping { + + private Map<FapServiceList, String> cellsinCluster; + + private List<FapServiceList> newCells; + + public Map<FapServiceList, String> getCellsinCluster() { + return cellsinCluster; + } + + public void setCellsinCluster(Map<FapServiceList, String> cellsinCluster) { + this.cellsinCluster = cellsinCluster; + } + + public List<FapServiceList> getNewCells() { + return newCells; + } + + public void setNewCells(List<FapServiceList> newCells) { + this.newCells = newCells; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cellsinCluster == null) ? 0 : cellsinCluster.hashCode()); + result = prime * result + ((newCells == null) ? 0 : newCells.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + NotificationToClusterMapping other = (NotificationToClusterMapping) obj; + if (cellsinCluster == null) { + if (other.cellsinCluster != null) { + return false; + } + } else if (!cellsinCluster.equals(other.cellsinCluster)) { + return false; + } + if (newCells == null) { + if (other.newCells != null) { + return false; + } + } else if (!newCells.equals(other.newCells)) { + return false; + } + return true; + } + + + + +} diff --git a/src/main/java/com/wipro/www/sonhms/SonController.java b/src/main/java/org/onap/dcaegen2/services/sonhms/SonController.java index 8923614..15aa907 100644 --- a/src/main/java/com/wipro/www/sonhms/SonController.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/SonController.java @@ -1,28 +1,28 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - - -import com.wipro.www.sonhms.child.ChildThread; -import com.wipro.www.sonhms.restclient.AsyncResponseBody; + * 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; + +import org.onap.dcaegen2.services.sonhms.child.ChildThread; +import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/SonRequestsComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/SonRequestsComponent.java new file mode 100644 index 0000000..51607fa --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/SonRequestsComponent.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * ============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; + +import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +@Component +public class SonRequestsComponent { + + @Autowired + private SonRequestsRepository sonRequestsRepository; + + public long getChildThread(String transactionId) { + return sonRequestsRepository.getChildThreadMapping(transactionId); + } + +} + diff --git a/src/main/java/com/wipro/www/sonhms/Topic.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Topic.java index 3be2087..616d389 100644 --- a/src/main/java/com/wipro/www/sonhms/Topic.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Topic.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms; +package org.onap.dcaegen2.services.sonhms; public class Topic { diff --git a/src/main/java/com/wipro/www/sonhms/child/ChildThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java index 718cc46..eff7a84 100644 --- a/src/main/java/com/wipro/www/sonhms/child/ChildThread.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java @@ -1,32 +1,33 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.child; - - -import com.wipro.www.sonhms.Configuration; -import com.wipro.www.sonhms.dao.ClusterDetailsRepository; -import com.wipro.www.sonhms.model.FapServiceList; -import com.wipro.www.sonhms.model.ThreadId; -import com.wipro.www.sonhms.restclient.AsyncResponseBody; -import com.wipro.www.sonhms.utils.BeanUtil; + * 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.child; + +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository; +import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.model.ThreadId; +import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; import java.sql.Timestamp; import java.util.ArrayList; @@ -44,8 +45,7 @@ public class ChildThread implements Runnable { private BlockingQueue<List<String>> childStatusUpdate; private BlockingQueue<FapServiceList> queue = new LinkedBlockingQueue<>(); - // static BlockingQueue<AsyncResponseBody> asynchronousResponse = new - // LinkedBlockingQueue<>(); + private static Map<Long, AsyncResponseBody> responseMap = new HashMap<>(); private Graph cluster; private ThreadId threadId; @@ -98,7 +98,7 @@ public class ChildThread implements Runnable { */ public static void putResponse(Long threadId, AsyncResponseBody obj) { synchronized (responseMap) { - responseMap.put(threadId, obj); + responseMap.put(threadId, obj); } } @@ -130,7 +130,7 @@ public class ChildThread implements Runnable { ClusterFormation clusterFormation = new ClusterFormation(queue); StateOof oof = new StateOof(childStatusUpdate); - ClusterModification clusterModification = new ClusterModification(); + ClusterUtils clusterUtils = new ClusterUtils(); Detection detect = new Detection(); try { @@ -152,7 +152,7 @@ public class ChildThread implements Runnable { if (isNotificationsBuffered()) { List<FapServiceList> fapServiceLists = bufferNotification(); for (FapServiceList fapService : fapServiceLists) { - cluster = clusterModification.clustermod(cluster, fapService); + cluster = clusterUtils.modifyCluster(cluster, fapService); } String cellPciNeighbourString = cluster.getPciNeighbourJson(); UUID clusterId = cluster.getGraphId(); 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 new file mode 100644 index 0000000..d7ff57a --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * ============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.child; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.dcaegen2.services.sonhms.ConfigPolicy; +import org.onap.dcaegen2.services.sonhms.model.CellConfig; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +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.Lte; +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 java.util.ArrayList; +import java.util.List; +import org.slf4j.Logger; + +public class ChildThreadUtils { + + private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThreadUtils.class); + ConfigPolicy configPolicy; + + public ChildThreadUtils(ConfigPolicy configPolicy) { + this.configPolicy = configPolicy; + } + + + /** + * 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))))))); + configurations.add(configuration); + } + + Payload payload = new Payload(configurations); + ObjectMapper mapper = new ObjectMapper(); + String payloadString = ""; + try { + payloadString = mapper.writeValueAsString(payload); + } catch (JsonProcessingException e) { + log.debug("JSON processing exception: {}", e); + } + + String closedLoopControlName = (String) configPolicy.getConfig().get("PCI_MODCONFIG_POLICY_NAME"); + PolicyNotification policyNotification = new PolicyNotification(closedLoopControlName, + requestId, alarmStartTime, pnfName); + + policyNotification.setClosedLoopControlName(closedLoopControlName); + policyNotification.setPayload(payloadString); + + mapper.setSerializationInclusion(Include.NON_NULL); + String notification = ""; + try { + notification = mapper.writeValueAsString(policyNotification); + } catch (JsonProcessingException e1) { + log.debug("JSON processing exception: {}", e1); + } + return notification; + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/child/ClusterFormation.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ClusterFormation.java index 7b3d5bf..9a594a1 100644 --- a/src/main/java/com/wipro/www/sonhms/child/ClusterFormation.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ClusterFormation.java @@ -1,31 +1,33 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.child; - -import com.wipro.www.sonhms.ConfigPolicy; -import com.wipro.www.sonhms.Configuration; -import com.wipro.www.sonhms.dao.ClusterDetailsRepository; -import com.wipro.www.sonhms.entity.ClusterDetails; -import com.wipro.www.sonhms.model.FapServiceList; -import com.wipro.www.sonhms.utils.BeanUtil; + * 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.child; + +import org.onap.dcaegen2.services.sonhms.ConfigPolicy; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository; +import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails; +import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; import java.sql.Timestamp; import java.util.ArrayList; @@ -41,7 +43,7 @@ public class ClusterFormation { private static final Logger log = org.slf4j.LoggerFactory.getLogger(ClusterFormation.class); private BlockingQueue<FapServiceList> queue; - private ClusterModification clusterModification; + private ClusterUtils clusterUtils; private Detection detect; Properties confProp; ClusterDetails details = new ClusterDetails(); @@ -58,7 +60,7 @@ public class ClusterFormation { super(); this.queue = queue; this.detect = new Detection(); - this.clusterModification = new ClusterModification(); + this.clusterUtils = new ClusterUtils(); } /** @@ -123,7 +125,7 @@ public class ClusterFormation { if ((difference < (timer * 1000)) && (!queue.isEmpty())) { newNotification = queue.poll(); - cluster = clusterModification.clustermod(cluster, newNotification); + cluster = clusterUtils.modifyCluster(cluster, newNotification); // update cluster in DB String cellPciNeighbourString = cluster.getPciNeighbourJson(); diff --git a/src/main/java/com/wipro/www/sonhms/child/Detection.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/Detection.java index fc2e941..847e2d5 100644 --- a/src/main/java/com/wipro/www/sonhms/child/Detection.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/Detection.java @@ -1,26 +1,27 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.child; - -import com.wipro.www.sonhms.model.CellPciPair; + * 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.child; + +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/com/wipro/www/sonhms/child/Graph.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/Graph.java index 5e48dfc..eedbd94 100644 --- a/src/main/java/com/wipro/www/sonhms/child/Graph.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/Graph.java @@ -1,29 +1,31 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.child; + * 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.child; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.wipro.www.sonhms.model.CellNeighbourList; -import com.wipro.www.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.model.CellNeighbourList; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import java.io.IOException; import java.util.ArrayList; @@ -50,8 +52,7 @@ public class Graph { /** * Parameterized constructor. */ - @SuppressWarnings("unchecked") - public Graph(String clusterInfo) { + public Graph(String clusterInfo) { JSONArray cells = new JSONArray(clusterInfo); Map<CellPciPair, ArrayList<CellPciPair>> cellMap = new HashMap<>(); @@ -61,7 +62,8 @@ public class Graph { ObjectMapper mapper = new ObjectMapper(); ArrayList<CellPciPair> neighbours = new ArrayList<>(); try { - neighbours = mapper.readValue(cell.getString("neighbours"), ArrayList.class); + neighbours = mapper.readValue(cell.getString("neighbours"), + new TypeReference<ArrayList<CellPciPair>>() { }); } catch (JSONException | IOException e) { log.debug("Error parsing json: {}", e); } @@ -199,4 +201,42 @@ public class Graph { return pciNeighbourJson; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cellPciNeighbourMap == null) ? 0 : cellPciNeighbourMap.hashCode()); + result = prime * result + ((graphId == null) ? 0 : graphId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Graph other = (Graph) obj; + if (cellPciNeighbourMap == null) { + if (other.cellPciNeighbourMap != null) { + return false; + } + } else if (!cellPciNeighbourMap.equals(other.cellPciNeighbourMap)) { + return false; + } + if (graphId == null) { + if (other.graphId != null) { + return false; + } + } else if (!graphId.equals(other.graphId)) { + return false; + } + 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 new file mode 100644 index 0000000..560fd52 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * ============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.child; + +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.SdnrRestClient; +import org.onap.dcaegen2.services.sonhms.restclient.Solution; +import org.onap.dcaegen2.services.sonhms.restclient.SonSolution; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + + + +public class PnfUtils { + + /** + * get pnfs. + * + */ + public Map<String, List<CellPciPair>> getPnfs(List<Solution> solutions) throws ConfigDbNotFoundException { + + Map<String, List<CellPciPair>> pnfs = new HashMap<>(); + + for (Solution solution : solutions) { + List<SonSolution> pciSolutions = solution.getPciSolutions(); + for (SonSolution pciSolution : pciSolutions) { + String cellId = pciSolution.getCellId(); + int pci = pciSolution.getPci(); + + String pnfName = ""; + CellInfoRepository cellInfoRepository = BeanUtil.getBean(CellInfoRepository.class); + Optional<CellInfo> cellInfo = cellInfoRepository.findById(cellId); + if (cellInfo.isPresent()) { + pnfName = cellInfo.get().getPnfName(); + } else { + pnfName = SdnrRestClient.getPnfName(cellId); + cellInfoRepository.save(new CellInfo(cellId, pnfName)); + } + if (pnfs.containsKey(pnfName)) { + pnfs.get(pnfName).add(new CellPciPair(cellId, pci)); + } else { + List<CellPciPair> cellPciPairs = new ArrayList<>(); + cellPciPairs.add(new CellPciPair(cellId, pci)); + pnfs.put(pnfName, cellPciPairs); + } + } + + } + return pnfs; + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java new file mode 100644 index 0000000..d731725 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * ============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.child; + +import org.onap.dcaegen2.services.sonhms.ConfigPolicy; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository; +import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; +import org.onap.dcaegen2.services.sonhms.entity.PciRequests; +import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; +import org.onap.dcaegen2.services.sonhms.restclient.OofRestClient; +import org.onap.dcaegen2.services.sonhms.restclient.Solution; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.BlockingQueue; + +import org.slf4j.Logger; + +public class StateOof { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(StateOof.class); + private BlockingQueue<List<String>> childStatusUpdate; + + public StateOof() { + + } + + /** + * Parameterized Constructor. + * + */ + public StateOof(BlockingQueue<List<String>> childStatusUpdate) { + super(); + this.childStatusUpdate = childStatusUpdate; + } + + /** + * Triggers OOF. + * @throws OofNotFoundException when trigger oof fails + */ + public void triggerOof(Map<String, ArrayList<Integer>> result, + String networkId) throws OofNotFoundException, InterruptedException { + // check for 0 collision and 0 confusion + ArrayList<String> cellidList = new ArrayList<>(); + ArrayList<String> cellIds = new ArrayList<>(); + + for (Map.Entry<String, ArrayList<Integer>> entry : result.entrySet()) { + String key = entry.getKey(); + ArrayList<Integer> arr; + arr = entry.getValue(); + if (!arr.isEmpty()) { + Set<Integer> set = new HashSet<>(arr); + if (((set.size() == 1) && !set.contains(0)) || (set.size() != 1)) { + cellIds.add(key); + + } + } + + } + + for (String cell : cellIds) { + log.debug("cellidList entries: {}", cell); + cellidList.add(cell); + } + log.debug("the cells triggering the oof are {}", cellidList); + + UUID transactionId = UUID.randomUUID(); + + Configuration config = Configuration.getInstance(); + int numSolutions = config.getNumSolutions(); + List<String> optimizers = config.getOptimizers(); + + String oofResponse = OofRestClient.queryOof(numSolutions, transactionId.toString(), "create", cellidList, + networkId, optimizers); + log.debug("Synchronous Response {}", oofResponse); + + List<String> childStatus = new ArrayList<>(); + childStatus.add(Long.toString(Thread.currentThread().getId())); + childStatus.add("triggeredOof"); + try { + childStatusUpdate.put(childStatus); + } catch (InterruptedException e1) { + log.debug("Interrupted execption {}", e1); + Thread.currentThread().interrupt(); + + } + + // Store Request details in Database + + PciRequests pciRequest = new PciRequests(); + + long childThreadId = Thread.currentThread().getId(); + pciRequest.setTransactionId(transactionId.toString()); + pciRequest.setChildThreadId(childThreadId); + SonRequestsRepository pciRequestsRepository = BeanUtil.getBean(SonRequestsRepository.class); + pciRequestsRepository.save(pciRequest); + + while (!ChildThread.getResponseMap().containsKey(childThreadId)) { + Thread.sleep(100); + } + + AsyncResponseBody asynResponseBody = ChildThread.getResponseMap().get(childThreadId); + + try { + sendToPolicy(asynResponseBody); + } catch (ConfigDbNotFoundException e1) { + log.debug("Config DB is unreachable: {}", e1); + } + + pciRequestsRepository = BeanUtil.getBean(SonRequestsRepository.class); + pciRequestsRepository.deleteByChildThreadId(childThreadId); + + childStatus = new ArrayList<>(); + childStatus.add(Long.toString(Thread.currentThread().getId())); + childStatus.add("success"); + try { + childStatusUpdate.put(childStatus); + } catch (InterruptedException e) { + log.debug("InterruptedException {}", e); + Thread.currentThread().interrupt(); + + } + + } + + /** + * Sends Dmaap notification to Policy. + * + * @throws ConfigDbNotFoundException + * when config db is unreachable + */ + private void sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException { + + if (log.isDebugEnabled()) { + log.debug(async.toString()); + } + + List<Solution> solutions; + solutions = async.getSolutions(); + + PnfUtils pnfUtils = new PnfUtils(); + 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(); + + ChildThreadUtils childThreadUtils = new ChildThreadUtils(ConfigPolicy.getInstance()); + String notification = childThreadUtils.getNotificationString(pnfName, cellPciPairs, + UUID.randomUUID().toString(), System.currentTimeMillis()); + log.debug("Policy Notification: {}", notification); + PolicyDmaapClient policy = new PolicyDmaapClient(); + boolean status = policy.sendNotificationToPolicy(notification); + log.debug("sent Message: {}", status); + if (status) { + log.debug("Message sent to policy"); + } else { + log.debug("Sending notification to policy failed"); + } + + } + } + + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/controller/HealthCheck.java b/src/main/java/org/onap/dcaegen2/services/sonhms/controller/HealthCheck.java new file mode 100644 index 0000000..d0d9321 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/controller/HealthCheck.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * ============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.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HealthCheck { + @RequestMapping(value = "/healthcheck", method = RequestMethod.GET) + ResponseEntity<HttpStatus> healthCheck() { + return new ResponseEntity(HttpStatus.OK); + } +} diff --git a/src/main/java/com/wipro/www/sonhms/dao/BufferedNotificationsRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/BufferedNotificationsRepository.java index bdbdb6e..43bb1f3 100644 --- a/src/main/java/com/wipro/www/sonhms/dao/BufferedNotificationsRepository.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/BufferedNotificationsRepository.java @@ -1,26 +1,27 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.dao; - -import com.wipro.www.sonhms.entity.BufferedNotifications; + * 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.dao; + +import org.onap.dcaegen2.services.sonhms.entity.BufferedNotifications; import java.util.List; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/CellInfoRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/CellInfoRepository.java new file mode 100644 index 0000000..80066ad --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/CellInfoRepository.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============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.dao; + +import org.onap.dcaegen2.services.sonhms.entity.CellInfo; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + + +@Repository +public interface CellInfoRepository extends CrudRepository<CellInfo, String> { + + // public void + +} diff --git a/src/main/java/com/wipro/www/sonhms/dao/ClusterDetailsRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/ClusterDetailsRepository.java index a833fbf..babef00 100644 --- a/src/main/java/com/wipro/www/sonhms/dao/ClusterDetailsRepository.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/ClusterDetailsRepository.java @@ -1,26 +1,27 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.dao; - -import com.wipro.www.sonhms.entity.ClusterDetails; + * 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.dao; + +import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails; import java.util.List; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/DmaapNotificationsRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/DmaapNotificationsRepository.java new file mode 100644 index 0000000..356dca6 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/DmaapNotificationsRepository.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * ============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.dao; + +import org.onap.dcaegen2.services.sonhms.entity.DmaapNotifications; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + + +@Repository +public interface DmaapNotificationsRepository extends CrudRepository<DmaapNotifications, String> { + + @Query(nativeQuery = true, + value = "DELETE FROM dmaap_notifications " + + "WHERE notification = ( SELECT notification FROM dmaap_notifications ORDER BY " + + "created_at FOR UPDATE SKIP LOCKED LIMIT 1 ) RETURNING notification;") + + public String getNotificationFromQueue(); + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/SonRequestsRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/SonRequestsRepository.java new file mode 100644 index 0000000..b54661b --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/SonRequestsRepository.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============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.dao; + +import org.onap.dcaegen2.services.sonhms.entity.PciRequests; + +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Repository +@Transactional +public interface SonRequestsRepository extends CrudRepository<PciRequests, String> { + + @Query(nativeQuery = true, value = "SELECT child_thread_id FROM pci_requests WHERE transaction_id = ?1") + public long getChildThreadMapping(String transactionId); + + @Modifying + @Query(nativeQuery = true, value = "DELETE FROM pci_requests WHERE child_thread_id = ?1") + public void deleteByChildThreadId(Long threadId); + +} diff --git a/src/main/java/com/wipro/www/sonhms/dmaap/DmaapClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java index 051b00e..002f835 100644 --- a/src/main/java/com/wipro/www/sonhms/dmaap/DmaapClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.dmaap; + * 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.dmaap; import com.att.nsa.apiClient.http.HttpException; import com.att.nsa.cambria.client.CambriaClient; @@ -27,12 +28,11 @@ import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder; import com.att.nsa.cambria.client.CambriaClientBuilders.TopicManagerBuilder; import com.att.nsa.cambria.client.CambriaConsumer; import com.att.nsa.cambria.client.CambriaTopicManager; -import com.wipro.www.sonhms.Configuration; -import com.wipro.www.sonhms.NewNotification; -import com.wipro.www.sonhms.Topic; -import com.wipro.www.sonhms.dao.DmaapNotificationsRepository; -import com.wipro.www.sonhms.entity.DmaapNotifications; - +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.NewNotification; +import org.onap.dcaegen2.services.sonhms.Topic; +import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.entity.DmaapNotifications; import java.io.IOException; import java.net.MalformedURLException; diff --git a/src/main/java/com/wipro/www/sonhms/dmaap/NotificationConsumer.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationConsumer.java index 1bdbac2..ba6b83d 100644 --- a/src/main/java/com/wipro/www/sonhms/dmaap/NotificationConsumer.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationConsumer.java @@ -1,27 +1,28 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.dmaap; + * 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.dmaap; import com.att.nsa.cambria.client.CambriaConsumer; -import com.wipro.www.sonhms.dmaap.DmaapClient.NotificationCallback; +import org.onap.dcaegen2.services.sonhms.dmaap.DmaapClient.NotificationCallback; import java.io.IOException; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducer.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducer.java new file mode 100644 index 0000000..e1db372 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducer.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============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.dmaap; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import java.io.IOException; +import java.security.GeneralSecurityException; + +public class NotificationProducer { + + private CambriaBatchingPublisher cambriaBatchingPublisher; + + + /** + * Parameterised constructor. + */ + public NotificationProducer(CambriaBatchingPublisher cambriaBatchingPublisher) { + super(); + this.cambriaBatchingPublisher = cambriaBatchingPublisher; + } + + /** + * sends notification to dmaap. + */ + public int sendNotification(String msg) throws GeneralSecurityException, IOException { + + int result = cambriaBatchingPublisher.send("", msg); + System.out.println(result); + return result; + + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java new file mode 100644 index 0000000..4d5d23b --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============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.dmaap; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder; +import org.onap.dcaegen2.services.sonhms.Configuration; + +import java.io.IOException; +import java.security.GeneralSecurityException; + +public class PolicyDmaapClient { + + + /** + * Method stub for sending notification to policy. + */ + public boolean sendNotificationToPolicy(String msg) { + + Configuration configuration = Configuration.getInstance(); + CambriaBatchingPublisher cambriaBatchingPublisher; + try { + cambriaBatchingPublisher = new PublisherBuilder().usingHosts(configuration.getServers()) + .onTopic(configuration.getPolicyTopic()) + .authenticatedBy(configuration.getPcimsApiKey(), configuration.getPcimsSecretKey()).build(); + NotificationProducer notificationProducer = new NotificationProducer(cambriaBatchingPublisher); + notificationProducer.sendNotification(msg); + } catch (GeneralSecurityException | IOException e) { + return false; + } + return true; + } +} diff --git a/src/main/java/com/wipro/www/sonhms/entity/BufferedNotifications.java b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotifications.java index 9ac10aa..34cce77 100644 --- a/src/main/java/com/wipro/www/sonhms/entity/BufferedNotifications.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotifications.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.entity; + * 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.entity; import java.sql.Timestamp; diff --git a/src/main/java/com/wipro/www/sonhms/entity/CellInfo.java b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/CellInfo.java index e2bb326..0c546d6 100644 --- a/src/main/java/com/wipro/www/sonhms/entity/CellInfo.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/CellInfo.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms.entity; +package org.onap.dcaegen2.services.sonhms.entity; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/src/main/java/com/wipro/www/sonhms/entity/ClusterDetails.java b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/ClusterDetails.java index 59868eb..37dc5bd 100644 --- a/src/main/java/com/wipro/www/sonhms/entity/ClusterDetails.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/ClusterDetails.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.entity; + * 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.entity; import javax.persistence.Column; import javax.persistence.Entity; @@ -77,4 +78,10 @@ public class ClusterDetails { this.clusterInfo = clusterInfo; } + @Override + public String toString() { + return "ClusterDetails [clusterId=" + clusterId + ", clusterInfo=" + clusterInfo + ", childThreadId=" + + childThreadId + "]"; + } + } diff --git a/src/main/java/com/wipro/www/sonhms/entity/DmaapNotifications.java b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotifications.java index 925a9e6..2e30efc 100644 --- a/src/main/java/com/wipro/www/sonhms/entity/DmaapNotifications.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotifications.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms.entity; +package org.onap.dcaegen2.services.sonhms.entity; import java.sql.Timestamp; diff --git a/src/main/java/com/wipro/www/sonhms/entity/PciRequests.java b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PciRequests.java index cce914d..79120ee 100644 --- a/src/main/java/com/wipro/www/sonhms/entity/PciRequests.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PciRequests.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms.entity; +package org.onap.dcaegen2.services.sonhms.entity; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/ConfigDbNotFoundException.java b/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/ConfigDbNotFoundException.java new file mode 100644 index 0000000..e1f040b --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/ConfigDbNotFoundException.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * ============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.exceptions; + +public class ConfigDbNotFoundException extends Exception { + + /** + * serial version. + */ + private static final long serialVersionUID = 1L; + + public ConfigDbNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/OofNotFoundException.java b/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/OofNotFoundException.java new file mode 100644 index 0000000..0bbeff3 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/OofNotFoundException.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * ============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.exceptions; + +public class OofNotFoundException extends Exception { + /** + * serial version. + */ + private static final long serialVersionUID = 1L; + + public OofNotFoundException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellConfig.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellConfig.java new file mode 100644 index 0000000..1f4f62e --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellConfig.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class CellConfig { + + @JsonProperty(value = "LTE") + private Lte lte; + + public CellConfig() { + + } + + public CellConfig(Lte lte) { + super(); + this.lte = lte; + } + + public Lte getLte() { + return lte; + } + + public void setLte(Lte lte) { + this.lte = lte; + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/model/CellNeighbourList.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourList.java index 5bbff6d..18fdac4 100644 --- a/src/main/java/com/wipro/www/sonhms/model/CellNeighbourList.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourList.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms.model; +package org.onap.dcaegen2.services.sonhms.model; public class CellNeighbourList { diff --git a/src/main/java/com/wipro/www/sonhms/model/CellPciPair.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellPciPair.java index fb4c91a..866c51e 100644 --- a/src/main/java/com/wipro/www/sonhms/model/CellPciPair.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellPciPair.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; + * 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 com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Common.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Common.java new file mode 100644 index 0000000..8a54f76 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Common.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class Common { + + @JsonProperty(value = "CellIdentity") + private String cellIdentity; + + public Common() { + + } + + public Common(String cellIdentity) { + super(); + this.cellIdentity = cellIdentity; + } + + public String getCellIdentity() { + return cellIdentity; + } + + public void setCellIdentity(String cellIdentity) { + this.cellIdentity = cellIdentity; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java new file mode 100644 index 0000000..e043aaf --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class Configurations { + @JsonProperty("data") + private Data data; + + /** + * constructor. + * + */ + public Configurations() { + + } + + /** + * Parameterized constructor. + * + */ + public Configurations(Data data) { + super(); + this.data = data; + } + + public Data getData() { + return data; + } + + public void setData(Data data) { + this.data = data; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Data.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Data.java new file mode 100644 index 0000000..43b6204 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Data.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class Data { + + @JsonProperty("FAPService") + private FapService fapservice; + + public Data() { + + } + + public Data(FapService fapservice) { + super(); + this.fapservice = fapservice; + } + + public FapService getFapservice() { + return fapservice; + } + + public void setFapservice(FapService fapservice) { + this.fapservice = fapservice; + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/model/FapService.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/FapService.java index c949922..90b6f23 100644 --- a/src/main/java/com/wipro/www/sonhms/model/FapService.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/FapService.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; + * 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 com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/com/wipro/www/sonhms/model/FapServiceList.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/FapServiceList.java index 96cde4c..1e38927 100644 --- a/src/main/java/com/wipro/www/sonhms/model/FapServiceList.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/FapServiceList.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; + * 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 com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Lte.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Lte.java new file mode 100644 index 0000000..4ba5537 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Lte.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class Lte { + + @JsonProperty(value = "RAN") + private Ran ran; + + public Lte() { + + } + + public Lte(Ran ran) { + super(); + this.ran = ran; + } + + public Ran getRan() { + return ran; + } + + public void setRan(Ran ran) { + this.ran = ran; + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/model/LteNeighborListInUseLteCell.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java index fe85d47..961e5f0 100644 --- a/src/main/java/com/wipro/www/sonhms/model/LteNeighborListInUseLteCell.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; + * 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 com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/com/wipro/www/sonhms/model/NeighborListInUse.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NeighborListInUse.java index d240a88..50df1d8 100644 --- a/src/main/java/com/wipro/www/sonhms/model/NeighborListInUse.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NeighborListInUse.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms.model; +package org.onap.dcaegen2.services.sonhms.model; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/src/main/java/com/wipro/www/sonhms/model/Notification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Notification.java index 417e443..f74896a 100644 --- a/src/main/java/com/wipro/www/sonhms/model/Notification.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Notification.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; + * 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 com.fasterxml.jackson.annotation.JsonProperty; @@ -109,4 +110,11 @@ public class Notification { this.version = version; } + @Override + public String toString() { + return "Notification [requestId=" + requestId + ", aai=" + aai + ", from=" + from + ", version=" + version + + ", action=" + action + ", payload=" + payload + "]"; + } + + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationCellConfig.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationCellConfig.java new file mode 100644 index 0000000..aa771fe --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationCellConfig.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class NotificationCellConfig { + + @JsonProperty("LTE") + private NotificationLte lte; + + public NotificationCellConfig() { + + } + + /** + * Parameterized Constructor. + */ + + public NotificationCellConfig(NotificationLte lte) { + super(); + this.lte = lte; + } + + public NotificationLte getLte() { + return lte; + } + + public void setLte(NotificationLte lte) { + this.lte = lte; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationLte.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationLte.java new file mode 100644 index 0000000..584db11 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationLte.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class NotificationLte { + + @JsonProperty("RAN") + private NotificationRan ran; + + public NotificationLte() { + + } + + /** + * Parameterized Constructor. + */ + + public NotificationLte(NotificationRan ran) { + super(); + this.ran = ran; + } + + public NotificationRan getRan() { + return ran; + } + + public void setRan(NotificationRan ran) { + this.ran = ran; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayload.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayload.java new file mode 100644 index 0000000..9fed1e7 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayload.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class NotificationPayload { + + @JsonProperty("RadioAccess") + private RadioAccess radioAccess; + + public NotificationPayload() { + + } + + /** + * Parameterized Constructor. + */ + + public NotificationPayload(RadioAccess radioAccess) { + super(); + this.radioAccess = radioAccess; + } + + public RadioAccess getRadioAccess() { + return radioAccess; + } + + public void setRadioAccess(RadioAccess radioAccess) { + this.radioAccess = radioAccess; + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/model/NotificationRan.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationRan.java index cc0e085..6215ebb 100644 --- a/src/main/java/com/wipro/www/sonhms/model/NotificationRan.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NotificationRan.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; + * 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 com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Payload.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Payload.java new file mode 100644 index 0000000..dd10a1f --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Payload.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +public class Payload { + + @JsonProperty("Configurations") + private List<Configurations> configuration; + + public Payload() { + + } + + public Payload(List<Configurations> configuration) { + super(); + this.configuration = configuration; + } + + public List<Configurations> getConfiguration() { + return configuration; + } + + public void setConfiguration(List<Configurations> configuration) { + this.configuration = configuration; + } + + @Override + public String toString() { + return "Payload [configuration=" + configuration + "]"; + + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/model/PolicyNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotification.java index e367b0b..076c7b5 100644 --- a/src/main/java/com/wipro/www/sonhms/model/PolicyNotification.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotification.java @@ -1,30 +1,30 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; + * 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 com.fasterxml.jackson.annotation.JsonProperty; import java.util.HashMap; import java.util.Map; -import java.util.UUID; public class PolicyNotification { @@ -55,10 +55,19 @@ public class PolicyNotification { * constructor. */ public PolicyNotification() { - this.requestId = UUID.randomUUID().toString(); + + } + + /** + * Constructor. + * + */ + public PolicyNotification(String closedLoopControlName, String requestId, Long alarmStartTime, String pnfName) { + this.closedLoopControlName = closedLoopControlName; + this.requestId = requestId; this.closedLoopEventClient = "microservice.PCI"; this.closedLoopEventStatus = "ONSET"; - this.closedLoopAlarmStart = System.currentTimeMillis(); + this.closedLoopAlarmStart = alarmStartTime; this.from = "PCIMS"; this.version = "1.0.2"; this.action = "ModifyConfig"; @@ -67,8 +76,7 @@ public class PolicyNotification { this.aai = new HashMap<>(); aai.put("generic-vnf.is-closed-loop-disabled", "false"); aai.put("generic-vnf.prov-status", "ACTIVE"); - aai.put("generic-vnf.vnf-id", "notused"); - + aai.put("generic-vnf.vnf-id", pnfName); } public long getClosedLoopAlarmStart() { @@ -176,4 +184,23 @@ public class PolicyNotification { + ", payload=" + payload + "]"; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((aai == null) ? 0 : aai.hashCode()); + result = prime * result + ((action == null) ? 0 : action.hashCode()); + result = prime * result + (int) (closedLoopAlarmStart ^ (closedLoopAlarmStart >>> 32)); + result = prime * result + ((closedLoopControlName == null) ? 0 : closedLoopControlName.hashCode()); + result = prime * result + ((closedLoopEventClient == null) ? 0 : closedLoopEventClient.hashCode()); + result = prime * result + ((closedLoopEventStatus == null) ? 0 : closedLoopEventStatus.hashCode()); + result = prime * result + ((from == null) ? 0 : from.hashCode()); + result = prime * result + ((payload == null) ? 0 : payload.hashCode()); + result = prime * result + ((requestId == null) ? 0 : requestId.hashCode()); + result = prime * result + ((target == null) ? 0 : target.hashCode()); + result = prime * result + ((targetType == null) ? 0 : targetType.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + } diff --git a/src/main/java/com/wipro/www/sonhms/model/RadioAccess.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/RadioAccess.java index cc1ee4a..775c14d 100644 --- a/src/main/java/com/wipro/www/sonhms/model/RadioAccess.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/RadioAccess.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms.model; +package org.onap.dcaegen2.services.sonhms.model; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Ran.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Ran.java new file mode 100644 index 0000000..f2be944 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Ran.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class Ran { + + @JsonProperty(value = "Common") + private Common common; + + public Ran() { + + } + + /** + * Parameterized constructor. + */ + public Ran(Common common) { + super(); + this.common = common; + } + + public Common getCommon() { + return common; + } + + public void setCommon(Common common) { + this.common = common; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Response.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Response.java new file mode 100644 index 0000000..46237db --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Response.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.annotation.JsonProperty; + +public class Response { + + @JsonProperty(value = "cellId") + private String cellId; + + private int pci; + + public String getCellId() { + return cellId; + } + + public void setCellId(String cellId) { + this.cellId = cellId; + } + + public int getPci() { + return pci; + } + + public void setPci(int pci) { + this.pci = pci; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponse.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponse.java new file mode 100644 index 0000000..7fb73b7 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponse.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============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 java.util.List; + +public class SdnrResponse { + + private List<Response> response; + + public List<Response> getResponse() { + return response; + } + + public void setResponse(List<Response> response) { + this.response = response; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/ThreadId.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/ThreadId.java new file mode 100644 index 0000000..37d741d --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/ThreadId.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * ============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; + +public class ThreadId { + + private long childThreadId; + + public long getChildThreadId() { + return childThreadId; + } + + public void setChildThreadId(long childThreadId) { + this.childThreadId = childThreadId; + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/model/X0005b9Lte.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/X0005b9Lte.java index cb52715..d6dc61e 100644 --- a/src/main/java/com/wipro/www/sonhms/model/X0005b9Lte.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/X0005b9Lte.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; + * 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 com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/com/wipro/www/sonhms/restclient/AsyncResponseBody.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBody.java index 94e6919..61e0421 100644 --- a/src/main/java/com/wipro/www/sonhms/restclient/AsyncResponseBody.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBody.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; + * 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.restclient; import java.util.List; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfo.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfo.java new file mode 100644 index 0000000..edac16f --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfo.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * ============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.restclient; + +import java.util.ArrayList; +import java.util.List; + +public class CellInfo { + String networkId = null; + List<String> cellIdList = new ArrayList<>(); + + public String getNetworkId() { + return networkId; + } + + public void setNetworkId(String networkId) { + this.networkId = networkId; + } + + public List<String> getCellIdList() { + return cellIdList; + } + + public void setCellIdList(List<String> cellIdList) { + this.cellIdList = cellIdList; + } + + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBody.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBody.java new file mode 100644 index 0000000..2e5eeaa --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBody.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * ============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.restclient; + +public class OofRequestBody { + + protected RequestInfo requestInfo = new RequestInfo(); + protected CellInfo cellInfo = new CellInfo(); + + public RequestInfo getRequestInfo() { + return requestInfo; + } + + public void setRequestInfo(RequestInfo requestInfo) { + this.requestInfo = requestInfo; + } + + public CellInfo getCellInfo() { + return cellInfo; + } + + public void setCellInfo(CellInfo cellInfo) { + this.cellInfo = cellInfo; + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/restclient/OofRestClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java index 7b95d90..a9ce305 100644 --- a/src/main/java/com/wipro/www/sonhms/restclient/OofRestClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java @@ -1,36 +1,39 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; +package org.onap.dcaegen2.services.sonhms.restclient; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.wipro.www.sonhms.ConfigPolicy; -import com.wipro.www.sonhms.Configuration; -import com.wipro.www.sonhms.exceptions.OofNotFoundException; -import com.wipro.www.sonhms.utils.HttpRequester; +import org.onap.dcaegen2.services.sonhms.ConfigPolicy; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException; +import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; import java.util.List; import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; public class OofRestClient { private static Logger log = LoggerFactory.getLogger(OofRestClient.class); @@ -48,7 +51,7 @@ public class OofRestClient { List<String> cellIdList, String networkId, List<String> optimizers) throws OofNotFoundException { log.debug("inside queryoof"); - String response = ""; + ResponseEntity<String> response = null; Configuration configuration = Configuration.getInstance(); try { UUID requestUuid = UUID.randomUUID(); @@ -85,17 +88,17 @@ public class OofRestClient { String requestUrl = configuration.getOofService() + "/api/oof/v1/pci"; log.debug("requestUrl {}", requestUrl); - response = HttpRequester.sendPostRequestToOof(requestUrl, requestBody); + response = SonHandlerRestTemplate.sendPostRequestToOof(requestUrl, requestBody,new ParameterizedTypeReference<String>() {}); if (response == null) { throw new OofNotFoundException("Request to oof failed"); } log.debug("response {}", response); - return response; + return response.getBody(); } catch (JsonProcessingException e) { log.debug("exception{}", e); } - return response; + return response.getBody(); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBody.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBody.java new file mode 100644 index 0000000..a7c9f08 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBody.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * ============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.restclient; + +public class PolicyRequestBody { + + String configName = null; + String policyName = null; + String requestId = null; + + public String getConfigName() { + return configName; + } + + public void setConfigName(String configName) { + this.configName = configName; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + +} diff --git a/src/main/java/com/wipro/www/sonhms/restclient/PolicyRestClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClient.java index 7c286af..7334df2 100644 --- a/src/main/java/com/wipro/www/sonhms/restclient/PolicyRestClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClient.java @@ -1,33 +1,36 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; +package org.onap.dcaegen2.services.sonhms.restclient; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.wipro.www.sonhms.Configuration; -import com.wipro.www.sonhms.utils.HttpRequester; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; public class PolicyRestClient { private static Logger log = LoggerFactory.getLogger(PolicyRestClient.class); @@ -43,7 +46,7 @@ public class PolicyRestClient { log.debug("inside fetconfig from policy"); Configuration configuration = Configuration.getInstance(); - String response = ""; + ResponseEntity<String> response = null; String configName = configuration.getConfigName(); String policyName = configuration.getPolicyName(); @@ -60,14 +63,14 @@ public class PolicyRestClient { log.debug("policyRequestBody{}", requestBody); String requestUrl = configuration.getPolicyService() + "/pdp/api/getConfig"; - response = HttpRequester.sendPostToPolicy(requestUrl, requestBody); + response = SonHandlerRestTemplate.sendPostToPolicy(requestUrl, requestBody,new ParameterizedTypeReference<String>() {}); log.debug("policy response{}", response); - return response; + return response.getBody(); } catch (JsonProcessingException e) { log.debug("exception", e); } - return response; + return response.getBody(); } diff --git a/src/main/java/com/wipro/www/sonhms/restclient/RequestInfo.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfo.java index 6dcbf63..ff53b33 100644 --- a/src/main/java/com/wipro/www/sonhms/restclient/RequestInfo.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfo.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; + * 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.restclient; import java.util.List; diff --git a/src/main/java/com/wipro/www/sonhms/restclient/SdnrRestClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java index c37791f..0894146 100644 --- a/src/main/java/com/wipro/www/sonhms/restclient/SdnrRestClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java @@ -1,29 +1,30 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -import com.wipro.www.sonhms.Configuration; -import com.wipro.www.sonhms.exceptions.ConfigDbNotFoundException; -import com.wipro.www.sonhms.model.CellPciPair; -import com.wipro.www.sonhms.utils.HttpRequester; + * 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.restclient; + +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; import java.sql.Time; import java.text.SimpleDateFormat; @@ -34,6 +35,8 @@ import org.json.JSONArray; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; @@ -55,7 +58,7 @@ public class SdnrRestClient { 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.getSdnrService() + "/SDNCConfigDBAPI/getCellList" + "/" + networkId + "/" + String requestUrl = configuration.getSdnrService() + "/SDNCConfigDBAPI/getCellList" + "/" + networkId + "/" + encode(ts); return sendRequest(requestUrl); } @@ -110,7 +113,7 @@ public class SdnrRestClient { Configuration configuration = Configuration.getInstance(); String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis())); String requestUrl = configuration.getSdnrService() + "/SDNCConfigDBAPI/getPnfName" + "/" + cellId + "/" - + encode(ts); + + encode(ts); String response = sendRequest(requestUrl); JSONObject responseObject = new JSONObject(response); return responseObject.getString("value"); @@ -127,11 +130,12 @@ public class SdnrRestClient { * Method to send request. */ private static String sendRequest(String url) throws ConfigDbNotFoundException { - String response = HttpRequester.sendGetRequest(url); - if (response.equals("")) { + ResponseEntity<String> response = SonHandlerRestTemplate.sendGetRequest(url, + new ParameterizedTypeReference<String>() {}); + if (response.equals(null)) { throw new ConfigDbNotFoundException("Cannot reach Config DB"); } - return response; + return response.getBody(); } } diff --git a/src/main/java/com/wipro/www/sonhms/restclient/Solution.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solution.java index 765501a..66af930 100644 --- a/src/main/java/com/wipro/www/sonhms/restclient/Solution.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solution.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; +package org.onap.dcaegen2.services.sonhms.restclient; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SonSolution.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SonSolution.java new file mode 100644 index 0000000..25f474a --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SonSolution.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * ============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.restclient; + +public class SonSolution { + + String cellId = null; + int pci; + + public String getCellId() { + return cellId; + } + + public void setCellId(String cellId) { + this.cellId = cellId; + } + + public int getPci() { + return pci; + } + + public void setPci(int pci) { + this.pci = pci; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/AppConfig.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/AppConfig.java new file mode 100644 index 0000000..a30288a --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/AppConfig.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============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.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.converter.ByteArrayHttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class AppConfig { + + + /** + * Rest Template bean. + */ + @Bean + public static RestTemplate initRestTemplateForPdfAsByteArrayAndSelfSignedHttps() { + RestTemplate restTemplate = new RestTemplate(useApacheHttpClientWithSelfSignedSupport()); + restTemplate.getMessageConverters().add(generateByteArrayHttpMessageConverter()); + return restTemplate; + } + + private static HttpComponentsClientHttpRequestFactory useApacheHttpClientWithSelfSignedSupport() { + CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) + .build(); + HttpComponentsClientHttpRequestFactory useApacheHttpClient = new HttpComponentsClientHttpRequestFactory(); + useApacheHttpClient.setHttpClient(httpClient); + return useApacheHttpClient; + } + + private static ByteArrayHttpMessageConverter generateByteArrayHttpMessageConverter() { + ByteArrayHttpMessageConverter byteArrayHttpMessageConverter = new ByteArrayHttpMessageConverter(); + + List<MediaType> supportedApplicationTypes = new ArrayList<MediaType>(); + supportedApplicationTypes.add(new MediaType("application", "pdf")); + byteArrayHttpMessageConverter.setSupportedMediaTypes(supportedApplicationTypes); + return byteArrayHttpMessageConverter; + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/BeanUtil.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/BeanUtil.java new file mode 100644 index 0000000..63a738c --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/BeanUtil.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * ============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.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Service; + +@Service +public class BeanUtil implements ApplicationContextAware { + private static ApplicationContext context; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + context = applicationContext; + } + + public static <T> T getBean(Class<T> beanClass) { + return context.getBean(beanClass); + } +} 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 new file mode 100644 index 0000000..79d0c61 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java @@ -0,0 +1,344 @@ +/******************************************************************************* + * ============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.utils; + +import org.onap.dcaegen2.services.sonhms.ClusterDetailsComponent; +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.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.SdnrRestClient; + +import fj.data.Either; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +public class ClusterUtils { + + private static Logger log = LoggerFactory.getLogger(ClusterUtils.class); + + public List<ClusterDetails> getAllClusters() { + ClusterDetailsComponent clusterDetailsComponent = new ClusterDetailsComponent(); + return clusterDetailsComponent.getClusterDetails(); + } + + /** + * Get clusters for notifications. + */ + public NotificationToClusterMapping getClustersForNotification(Notification notification, + List<ClusterDetails> clusterDetails) { + + NotificationToClusterMapping mapping = new NotificationToClusterMapping(); + + Map<FapServiceList, String> cellsInCluster = new HashMap<>(); + List<FapServiceList> newCells = new ArrayList<>(); + + List<FapServiceList> fapServiceList = notification.getPayload().getRadioAccess().getFapServiceList(); + + for (FapServiceList fapService : fapServiceList) { + + for (ClusterDetails clusterDetail : clusterDetails) { + + Set<String> cellsInNotification = getCellsInNotification(fapService); + + Graph cluster = new Graph(clusterDetail.getClusterInfo()); + + Set<String> clusterCells = getCellsInCluster(cluster); + + log.debug("cells in cluster {}", clusterCells); + + cellsInNotification.retainAll(clusterCells); + + if (!cellsInNotification.isEmpty()) { + log.debug("cell or it's neighbour in the cluster"); + cellsInCluster.put(fapService, clusterDetail.getClusterId()); + break; + } + } + + if (!cellsInCluster.containsKey(fapService)) { + newCells.add(fapService); + } + } + + mapping.setCellsinCluster(cellsInCluster); + mapping.setNewCells(newCells); + return mapping; + } + + /** + * Get cluster details from cluster ID. + */ + public Either<ClusterDetails, Integer> getClusterDetailsFromClusterId(String clusterId, + List<ClusterDetails> clusterDetails) { + + for (ClusterDetails clusterDetail : clusterDetails) { + if (clusterDetail.getClusterId().equals(clusterId)) { + return Either.left(clusterDetail); + } + } + return Either.right(404); + } + + /** + * Get clusters for Cell. + */ + public Either<Graph, Integer> getClusterForCell(FapServiceList fapService, List<Graph> newClusters) { + + if (newClusters.isEmpty()) { + return Either.right(404); + } + + + for (Graph cluster : newClusters) { + + Set<String> cellsInNotification = getCellsInNotification(fapService); + Set<String> clusterCells = getCellsInCluster(cluster); + + cellsInNotification.retainAll(clusterCells); + + if (!(cellsInNotification.isEmpty())) { + return Either.left(cluster); + } + + } + + return Either.right(404); + } + + private Set<String> getCellsInNotification(FapServiceList fapService) { + Set<String> cellsInNotification = new HashSet<>(); + cellsInNotification.add(fapService.getAlias()); + List<LteNeighborListInUseLteCell> nbrList = fapService.getCellConfig().getLte().getRan().getNeighborListInUse() + .getLteNeighborListInUseLteCell(); + for (LteNeighborListInUseLteCell nbr : nbrList) { + cellsInNotification.add(nbr.getAlias()); + } + + return cellsInNotification; + } + + private Set<String> getCellsInCluster(Graph cluster) { + Map<CellPciPair, ArrayList<CellPciPair>> cellPciNeighbourMap = cluster.getCellPciNeighbourMap(); + log.debug("cell_pci_map {}", cellPciNeighbourMap); + Set<CellPciPair> keys = cellPciNeighbourMap.keySet(); + Set<String> clusterCells = new HashSet<>(); + for (CellPciPair cellPciPair : keys) { + log.debug("cells {}", cellPciPair.getCellId()); + clusterCells.add(cellPciPair.getCellId()); + } + + return clusterCells; + } + + /** + * Create cluster from notification. + */ + public Graph createCluster(FapServiceList fapService) throws ConfigDbNotFoundException { + + Graph cluster = new Graph(); + log.debug("cluster formation started"); + int phycellId = fapService.getX0005b9Lte().getPhyCellIdInUse(); + String cellId = fapService.getCellConfig().getLte().getRan().getCellIdentity(); + + CellPciPair val = new CellPciPair(); + val.setCellId(cellId); + val.setPhysicalCellId(phycellId); + List<LteNeighborListInUseLteCell> neighbourlist; + neighbourlist = fapService.getCellConfig().getLte().getRan().getNeighborListInUse() + .getLteNeighborListInUseLteCell(); + log.debug("Neighbor list size: {}", neighbourlist.size()); + + for (int i = 0; i < neighbourlist.size(); i++) { + String cell = neighbourlist.get(i).getAlias(); + int phy = neighbourlist.get(i).getPhyCellId(); + + log.debug("cellID: {}", cell); + log.debug("PCI: {}", phy); + CellPciPair val1 = new CellPciPair(); + val1.setCellId(cell); + val1.setPhysicalCellId(phy); + cluster.addEdge(val, val1); + log.debug("cluster: {}", cluster); + + List<CellPciPair> nbrList = SdnrRestClient.getNbrList(neighbourlist.get(i).getAlias()); + + for (CellPciPair nbr : nbrList) { + String cid = nbr.getCellId(); + int pci = nbr.getPhysicalCellId(); + CellPciPair val3 = new CellPciPair(); + val3.setCellId(cid); + val3.setPhysicalCellId(pci); + + cluster.addEdge(val1, val3); + } + } + + log.debug("final cluster: {}", cluster); + return cluster; + } + + /** + * Save cluster. + */ + public String saveCluster(Graph cluster, UUID clusterId, Long threadId) { + + String cellPciNeighbourString = cluster.getPciNeighbourJson(); + + log.debug("cluster hahsmap to string : {}", cellPciNeighbourString); + cluster.setGraphId(clusterId); + + ClusterDetails details = new ClusterDetails(); + details.setClusterId(clusterId.toString()); + details.setClusterInfo(cellPciNeighbourString); + details.setChildThreadId(threadId); + + ClusterDetailsRepository clusterDetailsRepository = BeanUtil.getBean(ClusterDetailsRepository.class); + clusterDetailsRepository.save(details); + + return clusterId.toString(); + } + + /** + * update cluster. + */ + public Graph modifyCluster(Graph cluster, FapServiceList fapser) { + + int phycellId = fapser.getX0005b9Lte().getPhyCellIdInUse(); + String cellId = fapser.getCellConfig().getLte().getRan().getCellIdentity(); + CellPciPair mainCellPciPair = new CellPciPair(); + mainCellPciPair.setCellId(cellId); + mainCellPciPair.setPhysicalCellId(phycellId); + List<LteNeighborListInUseLteCell> newNeighbourList; + newNeighbourList = fapser.getCellConfig().getLte().getRan().getNeighborListInUse() + .getLteNeighborListInUseLteCell(); + + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap; + clusterMap = cluster.getCellPciNeighbourMap(); + + // coe + + List<CellPciPair> tempCellPair = new ArrayList<>(); + for (Map.Entry<CellPciPair, ArrayList<CellPciPair>> entry : clusterMap.entrySet()) { + CellPciPair oldClusterKeys = entry.getKey(); + tempCellPair.add(oldClusterKeys); + } + + for (CellPciPair entry : tempCellPair) { + String cell = entry.getCellId(); + int physicalCell = entry.getPhysicalCellId(); + CellPciPair mapVal = new CellPciPair(); + mapVal.setCellId(cell); + mapVal.setPhysicalCellId(physicalCell); + + if (cellId.equals(cell)) { + + // removes the old neighbours and adds new neighbours for that cell + cluster.updateVertex(mapVal, mainCellPciPair); + + } + + } + + /////// update cluster with new pci values for the same cell + + if (clusterMap.containsKey(mainCellPciPair)) { + ArrayList<CellPciPair> oldClusterArray; + oldClusterArray = clusterMap.get(mainCellPciPair); + oldClusterArray.clear(); + + for (int i = 0; i < newNeighbourList.size(); i++) { + String cid = newNeighbourList.get(i).getAlias(); + int phy = newNeighbourList.get(i).getPhyCellId(); + CellPciPair val2 = new CellPciPair(); + val2.setCellId(cid); + val2.setPhysicalCellId(phy); + cluster.addEdge(mainCellPciPair, val2); + } + + } + + for (CellPciPair entry : tempCellPair) { + String cell = entry.getCellId(); + int physicalCell = entry.getPhysicalCellId(); + CellPciPair mapVal = new CellPciPair(); + mapVal.setCellId(cell); + mapVal.setPhysicalCellId(physicalCell); + for (int j = 0; j < newNeighbourList.size(); j++) { + String cid1 = newNeighbourList.get(j).getAlias(); + int phy1 = newNeighbourList.get(j).getPhyCellId(); + CellPciPair val3 = new CellPciPair(); + val3.setCellId(cid1); + val3.setPhysicalCellId(phy1); + + if (cid1.equals(cell)) { + + // removes the old neighbours and adds new neighbours for that cell + cluster.updateVertex(mapVal, val3); + + } + + } + } + + for (int j = 0; j < newNeighbourList.size(); j++) { + String cid1 = newNeighbourList.get(j).getAlias(); + int phy1 = newNeighbourList.get(j).getPhyCellId(); + CellPciPair val3 = new CellPciPair(); + val3.setCellId(cid1); + val3.setPhysicalCellId(phy1); + if (clusterMap.containsKey(val3)) { + cluster.addEdge(mainCellPciPair, val3); + } + + } + + for (int k = 0; k < newNeighbourList.size(); k++) { + String cid2 = newNeighbourList.get(k).getAlias(); + int phy2 = newNeighbourList.get(k).getPhyCellId(); + CellPciPair val5 = new CellPciPair(); + val5.setCellId(cid2); + val5.setPhysicalCellId(phy2); + cluster.addEdge(mainCellPciPair, val5); + } + + log.debug("Modified Cluster {}", cluster); + + return cluster; + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/FileIo.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/FileIo.java new file mode 100644 index 0000000..7eaafbe --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/FileIo.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * ============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.utils; + +import java.io.BufferedReader; +import java.io.FileReader; + +public class FileIo { + + private FileIo() { + + } + + /** + * Reads from File. + */ + public static String readFromFile(String file) { + String content = ""; + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { + content = bufferedReader.readLine(); + String temp; + while ((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + } catch (Exception e) { + content = null; + } + return content; + } + +} 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 new file mode 100644 index 0000000..7745117 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * ============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.utils; + +import java.util.Collections; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +@Component +public class SonHandlerRestTemplate { + @Autowired + static RestTemplate restTemplate; + + private static final String AUTH = "Authorization"; + private static final String EXCEPTION_MSG = "Exception caught during request {}"; + private static final Logger log = org.slf4j.LoggerFactory.getLogger(SonHandlerRestTemplate.class); + + private SonHandlerRestTemplate() { + + } + + /** + * Send Post Request. + */ + + public static <T> ResponseEntity<T> sendPostRequest(String requestUrl, String requestBody, + ParameterizedTypeReference<T> responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); + try { + return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); + } catch (Exception e) { + log.debug(EXCEPTION_MSG, e.getMessage()); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + /** + * Send Post Request to policy. + */ + public static <T> ResponseEntity<T> sendPostToPolicy(String requestUrl, String requestBody, + ParameterizedTypeReference<T> responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("ClientAuth", "cHl0aG9uOnRlc3Q="); + headers.add(AUTH, "Basic dGVzdHBkcDphbHBoYTEyMw== "); + headers.add("Environment", "TEST"); + HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); + try { + return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); + } catch (Exception e) { + log.debug(EXCEPTION_MSG, e.getMessage()); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + /** + * Send Get Request. + */ + + public static <T> ResponseEntity<T> sendGetRequest(String requestUrl, ParameterizedTypeReference<T> responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + HttpEntity<Void> requestEntity = new HttpEntity<>(headers); + try { + return restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, responseType); + } catch (Exception e) { + log.debug(EXCEPTION_MSG, e.getMessage()); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + /** + * Send Get Request to SDNR. + */ + + public static <T> ResponseEntity<T> sendGetRequest(String requestUrl, String requestBody, + ParameterizedTypeReference<T> responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add(AUTH, "Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA=="); + HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); + try { + return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); + } catch (Exception e) { + log.debug(EXCEPTION_MSG, e.getMessage()); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + /** + * Send Post Request1. + */ + + public static <T> ResponseEntity<T> sendPostRequest1(String requestUrl, String requestBody, + ParameterizedTypeReference<T> responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add(AUTH, "Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA=="); + HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); + try { + return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); + } catch (Exception e) { + log.debug(EXCEPTION_MSG, e.getMessage()); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + /** + * Send Post Request to oof. + */ + + public static <T> ResponseEntity<T> sendPostRequestToOof(String requestUrl, String requestBody, + ParameterizedTypeReference<T> responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add(AUTH, "Basic cGNpX3Rlc3Q6cGNpX3Rlc3Rwd2Q="); + HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); + try { + return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); + } catch (Exception e) { + log.debug(EXCEPTION_MSG, e.getMessage()); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + +} 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 new file mode 100644 index 0000000..07e7219 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ThreadUtils.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * pcims + * ================================================================================ + * 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========================================================= + ******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.utils; + +import org.onap.dcaegen2.services.sonhms.EventHandler; +import org.onap.dcaegen2.services.sonhms.child.ChildThread; +import org.onap.dcaegen2.services.sonhms.child.Graph; +import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.model.ThreadId; + +import java.util.List; +import java.util.UUID; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +public class ThreadUtils { + + private static Logger log = LoggerFactory.getLogger(ThreadUtils.class); + + /** + * Create thread. + */ + public Boolean createNewThread(List<Graph> newClusters, BlockingQueue<List<String>> childStatusQueue, + ExecutorService pool, EventHandler eventHandler) { + for (Graph cluster : newClusters) { + + BlockingQueue<FapServiceList> queue = new LinkedBlockingQueue<>(); + ThreadId threadId = new ThreadId(); + threadId.setChildThreadId(0); + ChildThread child = new ChildThread(childStatusQueue, cluster, queue, threadId); + pool.execute(child); + waitForThreadId(threadId); + UUID clusterId = UUID.randomUUID(); + + ClusterUtils clusterUtils = new ClusterUtils(); + clusterUtils.saveCluster(cluster, clusterId, threadId.getChildThreadId()); + EventHandler.addChildThreadMap(threadId.getChildThreadId(), child); + eventHandler.addChildStatus(threadId.getChildThreadId(), "processingNotifications"); + } + return true; + + } + + private void waitForThreadId(ThreadId threadId) { + + ThreadId thread = threadId; + try { + synchronized (thread) { + while (thread.getChildThreadId() == 0) { + thread.wait(); + } + } + } catch (InterruptedException e) { + + log.error("ChildThread queue error {}", e); + Thread.currentThread().interrupt(); + } + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 335ad96..5905adf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,22 +1,24 @@ -#------------------------------------------------------------------------------- -# ============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========================================================= +# +############################################################################### + spring.datasource.url= jdbc:postgresql://pcims-db:5432/sonh_ms spring.datasource.username=postgres diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index f37bd58..160ff9c 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,23 +1,24 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - ============LICENSE_START======================================================= - pcims - ================================================================================ - 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========================================================= ---> + ============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========================================================= + + --> <configuration> <appender name="FILE-THREAD" class="ch.qos.logback.classic.sift.SiftingAppender"> <discriminator> diff --git a/src/test/java/com/wipro/www/sonhms/ApplicationTest.java b/src/test/java/com/wipro/www/sonhms/ApplicationTest.java deleted file mode 100644 index 892e0c2..0000000 --- a/src/test/java/com/wipro/www/sonhms/ApplicationTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ -package com.wipro.www.sonhms; - -public class ApplicationTest { - -} diff --git a/src/test/java/com/wipro/www/sonhms/ChildStatusUpdateStateTest.java b/src/test/java/com/wipro/www/sonhms/ChildStatusUpdateStateTest.java deleted file mode 100644 index ea426bf..0000000 --- a/src/test/java/com/wipro/www/sonhms/ChildStatusUpdateStateTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -public class ChildStatusUpdateStateTest { - -} diff --git a/src/test/java/com/wipro/www/sonhms/ConfigPolicyTest.java b/src/test/java/com/wipro/www/sonhms/ConfigPolicyTest.java deleted file mode 100644 index 85b1c44..0000000 --- a/src/test/java/com/wipro/www/sonhms/ConfigPolicyTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.ConfigPolicy; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; - - -public class ConfigPolicyTest { - - @Test - public void configPolicyTest() { - ConfigPolicy configPolicy = ConfigPolicy.getInstance(); - Map<String, Object> config = new HashMap<String, Object>(); - config.put("policyName", "pcims_policy"); - configPolicy.setConfig(config); - assertEquals(config, configPolicy.getConfig()); - } -} diff --git a/src/test/java/com/wipro/www/sonhms/SdnrNotificationHandlingStateTest.java b/src/test/java/com/wipro/www/sonhms/SdnrNotificationHandlingStateTest.java deleted file mode 100644 index d6e2dfc..0000000 --- a/src/test/java/com/wipro/www/sonhms/SdnrNotificationHandlingStateTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import org.junit.Test; - -public class SdnrNotificationHandlingStateTest { - - @Test - public void sdnrNotificationHandlingState() { - - } -} diff --git a/src/test/java/com/wipro/www/sonhms/SonContextTest.java b/src/test/java/com/wipro/www/sonhms/SonContextTest.java deleted file mode 100644 index e7e6790..0000000 --- a/src/test/java/com/wipro/www/sonhms/SonContextTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.wipro.www.sonhms.SdnrNotificationHandlingState; -import com.wipro.www.sonhms.SonContext; - -import java.util.List; -import java.util.concurrent.BlockingQueue; - -import org.junit.Test; - - - -public class SonContextTest { - - private BlockingQueue<List<String>> childStatusUpdate; - - @Test - public void sonContextTest() { - SonContext sonContext = new SonContext(); - sonContext.setChildThreadId(1); - sonContext.setNotifToBeProcessed(true); - sonContext.setSdnrNotification("notification"); - sonContext.setChildStatusUpdate(childStatusUpdate); - NewNotification newNotification = new NewNotification(true); - sonContext.setNewNotification(newNotification); - SdnrNotificationHandlingState pciState = new SdnrNotificationHandlingState(); - sonContext.setPciState(pciState); - assertEquals(1, sonContext.getChildThreadId()); - assertTrue(sonContext.isNotifToBeProcessed()); - assertEquals("notification", sonContext.getSdnrNotification()); - assertEquals(pciState, sonContext.getPciState()); - assertEquals(childStatusUpdate, sonContext.getChildStatusUpdate()); - assertEquals(newNotification, sonContext.getNewNotification()); - - } -} diff --git a/src/test/java/com/wipro/www/sonhms/WaitStateTest.java b/src/test/java/com/wipro/www/sonhms/WaitStateTest.java deleted file mode 100644 index 10ae3d7..0000000 --- a/src/test/java/com/wipro/www/sonhms/WaitStateTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ -package com.wipro.www.sonhms; - -public class WaitStateTest { - -} diff --git a/src/test/java/com/wipro/www/sonhms/child/TestClusterModification.java b/src/test/java/com/wipro/www/sonhms/child/TestClusterModification.java deleted file mode 100644 index 148663e..0000000 --- a/src/test/java/com/wipro/www/sonhms/child/TestClusterModification.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.child; - -import static org.junit.Assert.assertNotEquals; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.wipro.www.sonhms.child.ClusterModification; -import com.wipro.www.sonhms.child.Graph; -import com.wipro.www.sonhms.model.CellPciPair; -import com.wipro.www.sonhms.model.FapServiceList; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.ConcurrentModificationException; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; - -public class TestClusterModification { - @Test - public void testClusterModification() { - - CellPciPair cpPair = new CellPciPair(); - cpPair.setCellId("32"); - cpPair.setPhysicalCellId(26); - - CellPciPair cpPair1 = new CellPciPair(); - cpPair1.setCellId("25"); - cpPair1.setPhysicalCellId(23); - - CellPciPair cpPair2 = new CellPciPair(); - cpPair2.setCellId("42"); - cpPair2.setPhysicalCellId(12); - - CellPciPair cpPair3 = new CellPciPair(); - cpPair3.setCellId("56"); - cpPair3.setPhysicalCellId(200); - - CellPciPair cpPair4 = new CellPciPair(); - cpPair4.setCellId("21"); - cpPair4.setPhysicalCellId(6); - - CellPciPair cpPair5 = new CellPciPair(); - cpPair5.setCellId("24"); - cpPair5.setPhysicalCellId(5); - - CellPciPair cpPair6 = new CellPciPair(); - cpPair6.setCellId("38"); - cpPair6.setPhysicalCellId(126); - - CellPciPair cpPair7 = new CellPciPair(); - cpPair7.setCellId("67"); - cpPair7.setPhysicalCellId(300); - - CellPciPair cpPair8 = new CellPciPair(); - cpPair8.setCellId("69"); - cpPair8.setPhysicalCellId(129); - - CellPciPair cpPair9 = new CellPciPair(); - cpPair9.setCellId("78"); - cpPair9.setPhysicalCellId(147); - - ArrayList<CellPciPair> al = new ArrayList<CellPciPair>(); - al.add(cpPair1); - al.add(cpPair2); - al.add(cpPair3); - - ArrayList<CellPciPair> al1 = new ArrayList<CellPciPair>(); - al1.add(cpPair4); - al1.add(cpPair5); - al1.add(cpPair6); - - ArrayList<CellPciPair> al2 = new ArrayList<CellPciPair>(); - al2.add(cpPair7); - al2.add(cpPair8); - al2.add(cpPair9); - - Map<CellPciPair, ArrayList<CellPciPair>> map = new HashMap<CellPciPair, ArrayList<CellPciPair>>(); - - map.put(cpPair, al); - map.put(cpPair1, al1); - map.put(cpPair2, al2); - map.put(cpPair3, new ArrayList<CellPciPair>()); - map.put(cpPair4, new ArrayList<CellPciPair>()); - map.put(cpPair5, new ArrayList<CellPciPair>()); - map.put(cpPair6, new ArrayList<CellPciPair>()); - map.put(cpPair7, new ArrayList<CellPciPair>()); - map.put(cpPair8, new ArrayList<CellPciPair>()); - map.put(cpPair9, new ArrayList<CellPciPair>()); - Graph cluster = new Graph(); - - cluster.setCellPciNeighbourMap(map); - - System.out.println("map before" + cluster.getCellPciNeighbourMap()); - - String notif = "{ \n" + "\"alias\":\"Cell1\",\n" + "\"X0005b9Lte\":{ \n" + "\"phyCellIdInUse\":\"89\",\n" - + "\"pnfName\":\"DU-1\"\n" + "},\n" + "\"CellConfig\":{ \n" + "\"LTE\":{ \n" + "\"RAN\":{ \n" - + "\"CellIdentity\":\"6\",\n" + "\"NeighborListInUse\":{ \n" + "\"LTECellNumberOfEntries\":\"2\",\n" - + "\"LTENeighborListInUseLTECell\":[ \n" + "{ \n" + "\"pnfName\":\"DU-2\",\n" - + "\"enable\":\"true\",\n" + "\"alias\":\"Cell10\",\n" + "\"mustInclude\":\"true\",\n" - + "\"plmnid\":\"123456\",\n" + "\"cid\":\"2\",\n" + "\"phyCellId\":\"22\",\n" - + "\"blacklisted\":\"false\"\n" + "},\n" + "{ \n" + "\"pnfName\":\"DU-3\",\n" - + "\"enable\":\"true\",\n" + "\"alias\":\"Cell15\",\n" + "\"mustInclude\":\"true\",\n" - + "\"plmnid\":\"123456\",\n" + "\"cid\":\"25\",\n" + "\"phyCellId\":\"35\",\n" - + "\"blacklisted\":\"false\"\n" + "}\n" + "]\n" + "}\n" + "}\n" + "}\n" + "}\n" + "}"; - - ObjectMapper mapper = new ObjectMapper(); - FapServiceList fapser = new FapServiceList(); - try { - fapser = mapper.readValue(notif, FapServiceList.class); - } catch (JsonParseException e) { - e.printStackTrace(); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - CellPciPair cpPair11 = new CellPciPair(); - cpPair11.setCellId("2"); - cpPair11.setPhysicalCellId(22); - - CellPciPair cpPair12 = new CellPciPair(); - - cpPair12.setCellId("5"); - cpPair12.setPhysicalCellId(24); - - ArrayList<CellPciPair> al4 = new ArrayList<CellPciPair>(); - - al4.add(cpPair11); - al4.add(cpPair12); - - Map<CellPciPair, ArrayList<CellPciPair>> newMap = new HashMap<CellPciPair, ArrayList<CellPciPair>>(); - newMap.put(cpPair, al); - newMap.put(cpPair1, al4); - newMap.put(cpPair2, al2); - newMap.put(cpPair3, new ArrayList<CellPciPair>()); - newMap.put(cpPair4, new ArrayList<CellPciPair>()); - newMap.put(cpPair5, new ArrayList<CellPciPair>()); - newMap.put(cpPair6, new ArrayList<CellPciPair>()); - newMap.put(cpPair7, new ArrayList<CellPciPair>()); - newMap.put(cpPair8, new ArrayList<CellPciPair>()); - newMap.put(cpPair9, new ArrayList<CellPciPair>()); - newMap.put(cpPair11, new ArrayList<CellPciPair>()); - newMap.put(cpPair12, new ArrayList<CellPciPair>()); - - Graph newCluster = new Graph(); - newCluster.setCellPciNeighbourMap(newMap); - System.out.print("newCluster" + newCluster.getCellPciNeighbourMap()); - - ClusterModification mod = new ClusterModification(); - try { - // System.out.print("Cluster" + mod.clustermod(cluster, - // fapser).getCellPciNeighbourMap().toString()); - - assertNotEquals(newCluster, mod.clustermod(cluster, fapser)); - - } catch (NullPointerException e) { - e.printStackTrace(); - } catch (ConcurrentModificationException e) { - System.out.println("Concureent execption" + e); - - } - } - -} diff --git a/src/test/java/com/wipro/www/sonhms/model/CellConfigTest.java b/src/test/java/com/wipro/www/sonhms/model/CellConfigTest.java deleted file mode 100644 index 68f8b40..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/CellConfigTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class CellConfigTest { - - @Test - public void cellConfigTest() { - - Common common = new Common(); - common.setCellIdentity("cellIdentity"); - Ran ran = new Ran(); - ran.setCommon(common); - Lte lte = new Lte(); - lte.setRan(ran); - CellConfig cellConfig = new CellConfig(); - cellConfig.setLte(lte); - assertEquals(lte, cellConfig.getLte()); - assertEquals(ran, lte.getRan()); - assertEquals(common, ran.getCommon()); - } -} diff --git a/src/test/java/com/wipro/www/sonhms/model/CellNeighbourListTest.java b/src/test/java/com/wipro/www/sonhms/model/CellNeighbourListTest.java deleted file mode 100644 index 8acc0e8..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/CellNeighbourListTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class CellNeighbourListTest { - - @Test - public void cellNeighbourListTest() { - CellNeighbourList cellNeighbourList = new CellNeighbourList(); - cellNeighbourList.setCellId("cellId"); - cellNeighbourList.setNeighbours("neighbour"); - cellNeighbourList.setPhysicalCellId(1); - assertEquals("cellId",cellNeighbourList.getCellId() ); - assertEquals("neighbour",cellNeighbourList.getNeighbours() ); - assertEquals(1,cellNeighbourList.getPhysicalCellId() ); - - } - -} diff --git a/src/test/java/com/wipro/www/sonhms/model/NotificationPayloadTest.java b/src/test/java/com/wipro/www/sonhms/model/NotificationPayloadTest.java deleted file mode 100644 index d1134fa..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/NotificationPayloadTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import org.junit.Test; - -public class NotificationPayloadTest { - - @Test - public void notificationPayloadTest() { - - } - -} diff --git a/src/test/java/com/wipro/www/sonhms/model/PayloadTest.java b/src/test/java/com/wipro/www/sonhms/model/PayloadTest.java deleted file mode 100644 index 1c006f9..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/PayloadTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.model.CellConfig; -import com.wipro.www.sonhms.model.Common; -import com.wipro.www.sonhms.model.Configurations; -import com.wipro.www.sonhms.model.Data; -import com.wipro.www.sonhms.model.FapService; -import com.wipro.www.sonhms.model.Lte; -import com.wipro.www.sonhms.model.Payload; -import com.wipro.www.sonhms.model.Ran; -import com.wipro.www.sonhms.model.X0005b9Lte; - -import java.util.ArrayList; - -import org.junit.Test; - - - -public class PayloadTest { - - @Test - public void payloadTest() { - Common common = new Common("cell1"); - - Ran ran = new Ran(common); - - Lte lte = new Lte(ran); - - CellConfig cellConfig = new CellConfig(lte); - - X0005b9Lte x0005b9Lte = new X0005b9Lte(0, "pnf2"); - - FapService fapService = new FapService("cell6", x0005b9Lte, cellConfig); - - Data data = new Data(fapService); - - Configurations config = new Configurations(data); - ArrayList<Configurations> al = new ArrayList<>(); - al.add(config); - - Payload payload = new Payload(al); - - assertEquals("pnf2", payload.getConfiguration().get(0).getData().getFapservice().getX0005b9Lte().getPnfName()); - - assertEquals("cell6", payload.getConfiguration().get(0).getData().getFapservice().getAlias()); - - } - -} diff --git a/src/test/java/com/wipro/www/sonhms/model/ResponseTest.java b/src/test/java/com/wipro/www/sonhms/model/ResponseTest.java deleted file mode 100644 index c413791..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/ResponseTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class ResponseTest { - - @Test - public void respomseTest() { - Response response = new Response(); - response.setCellId("cellId"); - response.setPci(1); - assertEquals("cellId", response.getCellId()); - assertEquals(1, response.getPci()); - } - -} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/CellInfoTest.java b/src/test/java/com/wipro/www/sonhms/restclient/CellInfoTest.java deleted file mode 100644 index b686f93..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/CellInfoTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.restclient.CellInfo; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; - - -public class CellInfoTest { - @Test - public void cellInfoTest() { - List<String> cellIdLists = new ArrayList<>(); - cellIdLists.add("cell1"); - - CellInfo cellInfo = new CellInfo(); - cellInfo.setNetworkId("NTWK001"); - cellInfo.setCellIdList(cellIdLists); - assertEquals("NTWK001", cellInfo.getNetworkId()); - assertEquals(cellIdLists, cellInfo.getCellIdList()); - - } -} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/OofRestClientTest.java b/src/test/java/com/wipro/www/sonhms/restclient/OofRestClientTest.java deleted file mode 100644 index 2f06f0a..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/OofRestClientTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -public class OofRestClientTest { - -} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/PciSolutionsTest.java b/src/test/java/com/wipro/www/sonhms/restclient/PciSolutionsTest.java deleted file mode 100644 index e7aac21..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/PciSolutionsTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.restclient.SonSolution; - -import org.junit.Test; - - -public class PciSolutionsTest { - @Test - public void pciSolutionsTest() { - SonSolution pciSolutions = new SonSolution(); - pciSolutions.setCellId("EXP001"); - pciSolutions.setPci(101); - assertEquals("EXP001", pciSolutions.getCellId()); - assertEquals(101, pciSolutions.getPci()); - } - -} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/PolicyRequestBodyTest.java b/src/test/java/com/wipro/www/sonhms/restclient/PolicyRequestBodyTest.java deleted file mode 100644 index 0726c31..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/PolicyRequestBodyTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * pcims - * ================================================================================ - * 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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.restclient.PolicyRequestBody; - -import org.junit.Test; - - -public class PolicyRequestBodyTest { - @Test - public void policyRequestBodyTest() { - PolicyRequestBody policyRequestBody = new PolicyRequestBody(); - policyRequestBody.setConfigName("PCIMS_CONFIG_POLICY"); - policyRequestBody.setPolicyName("com.PCIMS_CONFIG_POLICY"); - policyRequestBody.setRequestId("60fe7fe6-2649-4f6c-8468-30eb03fd0527"); - assertEquals("PCIMS_CONFIG_POLICY", policyRequestBody.getConfigName()); - assertEquals("com.PCIMS_CONFIG_POLICY", policyRequestBody.getPolicyName()); - assertEquals("60fe7fe6-2649-4f6c-8468-30eb03fd0527", policyRequestBody.getRequestId()); - - } - -} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/ApplicationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ApplicationTest.java new file mode 100644 index 0000000..1b3453a --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ApplicationTest.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * ============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; + +public class ApplicationTest { + +} diff --git a/src/test/java/com/wipro/www/sonhms/BufferNotificationComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java index 08779e4..19fe536 100644 --- a/src/test/java/com/wipro/www/sonhms/BufferNotificationComponentTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java @@ -1,61 +1,52 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms; +package org.onap.dcaegen2.services.sonhms; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.wipro.www.sonhms.dao.BufferedNotificationsRepository; -import com.wipro.www.sonhms.entity.BufferedNotifications; -import com.wipro.www.sonhms.utils.BeanUtil; - import java.util.ArrayList; import java.util.List; -import java.util.Optional; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.dcaegen2.services.sonhms.dao.BufferedNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.entity.BufferedNotifications; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.web.ProjectedPayload; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ BeanUtil.class }) @SpringBootTest(classes = BufferNotificationComponent.class) -public class BufferNotificationComponentTest { +public class BufferNotificationComponentTest { @Mock private BufferedNotificationsRepository bufferedNotificationsRepositoryMock; @@ -68,7 +59,7 @@ public class BufferNotificationComponentTest { MockitoAnnotations.initMocks(this); } - @Test + @Test public void bufferNotificationTest() { BufferedNotifications bufferedNotifications = new BufferedNotifications(); bufferedNotifications.setClusterId("clusterId"); @@ -77,7 +68,6 @@ public class BufferNotificationComponentTest { PowerMockito.when(BeanUtil.getBean(BufferedNotificationsRepository.class)) .thenReturn(bufferedNotificationsRepositoryMock); when(bufferedNotificationsRepositoryMock.save(bufferedNotifications)).thenReturn(bufferedNotifications); - BufferedNotifications bufferedNotificationsResult = new BufferedNotifications(); bufferNotificationComponent.bufferNotification("notification", "clusterId"); assertEquals(bufferedNotifications, bufferedNotificationsRepositoryMock.save(bufferedNotifications)); diff --git a/src/test/java/com/wipro/www/sonhms/ClusterDetailsComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java index 4be6339..22d0ccf 100644 --- a/src/test/java/com/wipro/www/sonhms/ClusterDetailsComponentTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java @@ -1,56 +1,46 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms; + * 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; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; - -import com.wipro.www.sonhms.dao.ClusterDetailsRepository; -import com.wipro.www.sonhms.entity.ClusterDetails; -import com.wipro.www.sonhms.utils.BeanUtil; - import java.util.ArrayList; import java.util.List; -import java.util.Optional; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository; +import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.web.ProjectedPayload; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigPolicyTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigPolicyTest.java new file mode 100644 index 0000000..ca12095 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigPolicyTest.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============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; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.ConfigPolicy; + + +public class ConfigPolicyTest { + + @Test + public void configPolicyTest() { + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + Map<String, Object> config = new HashMap<String, Object>(); + config.put("policyName", "pcims_policy"); + configPolicy.setConfig(config); + assertEquals(config, configPolicy.getConfig()); + } +} diff --git a/src/test/java/com/wipro/www/sonhms/ConfigurationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java index 06294dd..02a4f07 100644 --- a/src/test/java/com/wipro/www/sonhms/ConfigurationTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java @@ -1,32 +1,33 @@ /******************************************************************************* - * ============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 com.wipro.www.sonhms; +package org.onap.dcaegen2.services.sonhms; import static org.junit.Assert.assertEquals; -import com.wipro.www.sonhms.Configuration; import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.Configuration; public class ConfigurationTest { diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java new file mode 100644 index 0000000..cc4d3ad --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * ============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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; + +import fj.data.Either; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({ BeanUtil.class }) +@SpringBootTest(classes = DmaapNotificationsComponentTest.class) + +public class DmaapNotificationsComponentTest { + + @Mock + DmaapNotificationsRepository dmaapNotificationsRepositoryMock; + + @InjectMocks + DmaapNotificationsComponent component; + + static String notificationString; + + @BeforeClass + public static void setupTest() { + + notificationString = readFromFile("/notification1.json"); + } + + @Test + public void getDmaapNotificationsTestforLeft() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(DmaapNotificationsRepository.class)) + .thenReturn(dmaapNotificationsRepositoryMock); + when(dmaapNotificationsRepositoryMock.getNotificationFromQueue()).thenReturn(notificationString); + + + Either<Notification, Integer> result = component.getDmaapNotifications(); + //assertTrue(result.isLeft()); + assertNotNull(result.left().value()); + + when(dmaapNotificationsRepositoryMock.getNotificationFromQueue()).thenReturn("notification"); + + result = component.getDmaapNotifications(); + int resultRight = result.right().value(); + assertEquals(400, resultRight); + + } + + private static String readFromFile(String file) { + String content = new String(); + try { + + InputStream is = DmaapNotificationsComponentTest.class.getResourceAsStream(file); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); + content = bufferedReader.readLine(); + String temp; + while ((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + bufferedReader.close(); + } catch (Exception e) { + content = null; + } + return content; + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java new file mode 100644 index 0000000..a79e368 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * pcims + * ================================================================================ + * 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========================================================= + ******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.boot.test.context.SpringBootTest; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.dcaegen2.services.sonhms.child.Graph; +import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails; +import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest; +import org.onap.dcaegen2.services.sonhms.utils.ThreadUtils; + +import fj.data.Either; + +@RunWith(MockitoJUnitRunner.class) +@SpringBootTest(classes = EventHandler.class) +public class EventHandlerTest { + + @Mock + ClusterUtils clusterutilsMock; + + @Mock + ExecutorService pool; + + @Mock + ThreadUtils threadUtilsMock; + + private static Notification notification; + private static List<ClusterDetails> clusterDetails = new ArrayList<>(); + + @InjectMocks + EventHandler eventHandler; + + @Before + public void setup() { + + notification = new Notification(); + String notificationString = readFromFile("/notification3.json"); + String clusterInfo1 = readFromFile("/clusterInfo1.json"); + String clusterInfo2 = readFromFile("/clusterInfo2.json"); + String clusterInfo3 = readFromFile("/clusterInfo3.json"); + String clusterInfo4 = readFromFile("/clusterInfo4.json"); + ObjectMapper mapper = new ObjectMapper(); + + try { + notification = mapper.readValue(notificationString, Notification.class); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println(notification.toString()); + + clusterDetails.add(new ClusterDetails("1", clusterInfo1, 35)); + clusterDetails.add(new ClusterDetails("2", clusterInfo2, 36)); + clusterDetails.add(new ClusterDetails("3", clusterInfo3, 37)); + clusterDetails.add(new ClusterDetails("4", clusterInfo4, 38)); + + } + + @Test + public void handleSdnrNotificationTest() { + + String clusterInfo7 = readFromFile("/clusterInfo7.json"); + Graph cluster = new Graph(clusterInfo7); + NotificationToClusterMapping mapping = new NotificationToClusterMapping(); + Map<FapServiceList, String> cellsinCluster = new HashMap<>(); + List<FapServiceList> newCells = new ArrayList<>(); + newCells.add(notification.getPayload().getRadioAccess().getFapServiceList().get(0)); + mapping.setCellsinCluster(cellsinCluster); + mapping.setNewCells(newCells); + Either<Graph, Integer> existingCluster = Either.right(404); + + + Mockito.when(clusterutilsMock.getAllClusters()).thenReturn(clusterDetails); + Mockito.when(clusterutilsMock.getClustersForNotification(notification, clusterDetails)).thenReturn(mapping); + Mockito.when(clusterutilsMock.getClusterForCell(Mockito.any(), Mockito.any())).thenReturn(existingCluster); + Mockito.when(threadUtilsMock.createNewThread(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true); + + try { + Mockito.when(clusterutilsMock.createCluster(Mockito.any())).thenReturn(cluster); + } catch (ConfigDbNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + Assert.assertEquals(true, eventHandler.handleSdnrNotification(notification)); + + + + } + + private static String readFromFile(String file) { + String content = new String(); + try { + + InputStream is = ClusterUtilsTest.class.getResourceAsStream(file); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); + content = bufferedReader.readLine(); + String temp; + while((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + bufferedReader.close(); + } + catch(Exception e) { + content = null; + } + return content; + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/MainThreadTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/MainThreadTest.java new file mode 100644 index 0000000..d06abbf --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/MainThreadTest.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * ============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; + +public class MainThreadTest { + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/TopicTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/TopicTest.java new file mode 100644 index 0000000..6ac6e75 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/TopicTest.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * ============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; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class TopicTest { + + @Test + public void topicTest() { + Topic topic=new Topic(); + topic.setConsumer("consumer"); + topic.setName("name"); + topic.setProducer("producer"); + assertEquals("consumer", topic.getConsumer()); + assertEquals("name", topic.getName()); + assertEquals("producer", topic.getProducer()); + + } +} diff --git a/src/test/java/com/wipro/www/sonhms/child/GraphTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/GraphTest.java index 2132f22..3df7f93 100644 --- a/src/test/java/com/wipro/www/sonhms/child/GraphTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/GraphTest.java @@ -1,35 +1,35 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.child; + * 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.child; import static org.junit.Assert.assertNotEquals; -import com.wipro.www.sonhms.child.Graph; -import com.wipro.www.sonhms.model.CellPciPair; - import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.child.Graph; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.slf4j.Logger; @@ -56,6 +56,7 @@ public class GraphTest { log.debug("graph {}", graph.getCellPciNeighbourMap()); System.out.println("graph" + graph.getCellPciNeighbourMap()); + System.out.println("graphJSON" + graph.getPciNeighbourJson()); assertNotEquals(map, graph.getCellPciNeighbourMap()); } diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java new file mode 100644 index 0000000..03e735f --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * ============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.child; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.dcaegen2.services.sonhms.ConfigPolicy; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.model.PolicyNotification; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest; + +public class TestChildThreadUtils { + + ChildThreadUtils childThreadUtils; + + @Before + public void setup() { + + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + + Map<String, Object> configPolicyMap = new HashMap<>(); + configPolicyMap.put("PCI_MODCONFIG_POLICY_NAME", "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459"); + configPolicy.setConfig(configPolicyMap); + childThreadUtils = new ChildThreadUtils(configPolicy); + } + + @Test + public void getNotificationStringTest() { + + String policy_notif = readFromFile("/policy_notification.json"); + PolicyNotification expected = new PolicyNotification(); + ObjectMapper mapper = new ObjectMapper(); + + try { + expected = mapper.readValue(policy_notif, PolicyNotification.class); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + String pnfName = "ncserver23"; + List<CellPciPair> cellPciPairs = new ArrayList<>(); + + cellPciPairs.add(new CellPciPair("Chn0330", 6)); + cellPciPairs.add(new CellPciPair("Chn0331", 7)); + String requestId = "a4130fd5-2291-4a83-8992-04e4c9f32731"; + Long alarmStart = Long.parseLong("1542445563201"); + + String result = childThreadUtils.getNotificationString(pnfName, cellPciPairs, requestId, alarmStart); + PolicyNotification actual = new PolicyNotification(); + try { + actual = mapper.readValue(result, PolicyNotification.class); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Assert.assertEquals(expected.hashCode(), actual.hashCode()); + } + + private static String readFromFile(String file) { + String content = new String(); + try { + + InputStream is = ClusterUtilsTest.class.getResourceAsStream(file); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); + content = bufferedReader.readLine(); + String temp; + while((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + bufferedReader.close(); + } + catch(Exception e) { + e.printStackTrace(); + content = null; + } + return content; + } +} diff --git a/src/test/java/com/wipro/www/sonhms/child/TestDetection.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestDetection.java index 03ed787..6e42cce 100644 --- a/src/test/java/com/wipro/www/sonhms/child/TestDetection.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestDetection.java @@ -1,35 +1,35 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.child; - - -import com.wipro.www.sonhms.child.Detection; -import com.wipro.www.sonhms.child.Graph; -import com.wipro.www.sonhms.model.CellPciPair; + * 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.child; + import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.child.Detection; +import org.onap.dcaegen2.services.sonhms.child.Graph; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; public class TestDetection { diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java new file mode 100644 index 0000000..e7f822f --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * ============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.child; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.slf4j.Logger; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +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.SdnrRestClient; +import org.onap.dcaegen2.services.sonhms.restclient.Solution; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({BeanUtil.class, SdnrRestClient.class }) +@SpringBootTest(classes = PnfUtils.class) +public class TestPnfUtils { + + @Mock + private CellInfoRepository cellInfoRepositoryMock; + + private static final Logger log = org.slf4j.LoggerFactory.getLogger(TestPnfUtils.class); + private static List<Solution> solutions = new ArrayList<>(); + private static Optional<CellInfo> cellInfo; + private static Optional<CellInfo> cellInfoNull; + + + @InjectMocks + PnfUtils pnfUtils; + + @BeforeClass + public static void setup() { + + + String solutionsString=readFromFile("/solutions.json"); + ObjectMapper mapper = new ObjectMapper(); + + try { + solutions=mapper.readValue(solutionsString,new TypeReference<List<Solution>>(){}); + } catch (IOException e) { + log.debug("Exception in StateOof Test "+e); + e.printStackTrace(); + } + + } + @Before + public void setupTest() { + cellInfo = Optional.of(new CellInfo("EXP001","ncserver1")); + cellInfoNull = Optional.ofNullable(null); + pnfUtils = new PnfUtils(); + MockitoAnnotations.initMocks(this); + } + @Test + public void getPnfsTest() { + Map<String, List<CellPciPair>> pnfs = new HashMap<>(); + List<CellPciPair> cellpciPairList1=new ArrayList<>(); + cellpciPairList1.add(new CellPciPair("EXP001",101)); + List<CellPciPair> cellpciPairList2=new ArrayList<>(); + cellpciPairList2.add(new CellPciPair("EXP002",102)); + String pnfName="ncserver2"; + String cellId="EXP002"; + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.mockStatic(SdnrRestClient.class); + + PowerMockito.when(BeanUtil.getBean(CellInfoRepository.class)) + .thenReturn(cellInfoRepositoryMock); + + Mockito.when(cellInfoRepositoryMock.findById("EXP001")) + .thenReturn(cellInfo); + Mockito.when(cellInfoRepositoryMock.findById(cellId)) + .thenReturn(cellInfoNull); + try { + PowerMockito.when(SdnrRestClient.getPnfName(cellId)) + .thenReturn(pnfName); + PowerMockito.when(cellInfoRepositoryMock.save(new CellInfo(cellId, pnfName))).thenReturn(new CellInfo()); + } catch (ConfigDbNotFoundException e) { + e.printStackTrace(); + } + pnfs.put(pnfName, cellpciPairList2); + pnfs.put("ncserver1", cellpciPairList1); + System.out.println(solutions); + try { + assertEquals(pnfs,pnfUtils.getPnfs(solutions)); + } catch (ConfigDbNotFoundException e) { + log.debug("exception in stateOof test {}", e); + e.printStackTrace(); + } + } + private static String readFromFile(String file) { + String content = new String(); + try { + + InputStream is = ClusterUtilsTest.class.getResourceAsStream(file); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); + content = bufferedReader.readLine(); + String temp; + while((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + bufferedReader.close(); + } + catch(Exception e) { + content = null; + } + return content; + } +}
\ No newline at end of file diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java new file mode 100644 index 0000000..63ba5bd --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * ============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.dmaap; + +import com.att.nsa.cambria.client.CambriaTopicManager; + +import static org.mockito.Mockito.when; + + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; + +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.NewNotification; +import org.mockito.MockitoAnnotations; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = DmaapClientTest.class) +public class DmaapClientTest { + + @Mock + private CambriaTopicManager topicManager; + + + @InjectMocks + DmaapClient client; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + private Boolean newNotif; + + @Test + public void getAllTopicsTest() { + Set<String> topics = new HashSet<String>(); + topics.add("topic1"); + topics.add("topic2"); + Configuration configuration = Configuration.getInstance(); + configuration.setBufferTime(60); + configuration.setCallbackUrl("/callbackUrl"); + configuration.setConfigName("configName"); + List<String> list = new ArrayList<String>(); + list.add("server"); + configuration.setServers(list); + configuration.setCg("cg"); + configuration.setCid("cid"); + configuration.setManagerApiKey("managerApiKey"); + configuration.setManagerSecretKey("managerSecretKey"); + configuration.setMaximumClusters(5); + configuration.setMinCollision(5); + configuration.setMinConfusion(5); + configuration.setNumSolutions(1); + configuration.setOofService("oofService"); + configuration.setOptimizers(list); + configuration.setPcimsApiKey("pcimsApiKey"); + configuration.setPcimsSecretKey("pcimsSecretKey"); + configuration.setPolicyName("policyName"); + configuration.setPolicyService("policyService"); + configuration.setPolicyTopic("policyTopic"); + configuration.setPollingInterval(30); + configuration.setPollingTimeout(100); + configuration.setSdnrService("sdnrService"); + configuration.setSdnrTopic("sdnrTopic"); + configuration.setSourceId("sourceId"); + NewNotification newNotification = new NewNotification(newNotif); + + try { + when(topicManager.getTopics()).thenReturn(topics); + client=Mockito.mock(DmaapClient.class); + client.initClient(newNotification); + Mockito.verify(client).initClient(newNotification); + // Mockito.verifycreateAndConfigureTopics(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java new file mode 100644 index 0000000..c76b953 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============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.dmaap; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import java.io.IOException; +import java.security.GeneralSecurityException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = NotificationProducerTest.class) +public class NotificationProducerTest { + + + @Mock + CambriaBatchingPublisher cambriaBatchingPublisher; + + @InjectMocks + NotificationProducer notificationProducer; + + @Test + public void notificationProducerTest() { + + + + try { + + when(cambriaBatchingPublisher.send(Mockito.anyString(), Mockito.anyString())).thenReturn(0); + int result=notificationProducer.sendNotification("msg"); + assertEquals(0, result); + } catch (GeneralSecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } +} + + diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotificationsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotificationsTest.java new file mode 100644 index 0000000..12a3d4d --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotificationsTest.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============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.entity; + +import static org.junit.Assert.assertEquals; + +import java.sql.Timestamp; + +import org.junit.Test; + +public class BufferedNotificationsTest { + + private Timestamp createdAt; + + @Test + public void bufferedNotificationsTest() { + BufferedNotifications bufferedNotifications=new BufferedNotifications(); + bufferedNotifications.setClusterId("clusterId"); + bufferedNotifications.setNotification("notification"); + bufferedNotifications.setCreatedAt(createdAt); + assertEquals("clusterId", bufferedNotifications.getClusterId()); + assertEquals("notification", bufferedNotifications.getNotification()); + assertEquals(createdAt, bufferedNotifications.getCreatedAt()); + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/entity/CellInfoTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/CellInfoTest.java new file mode 100644 index 0000000..6732cb6 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/CellInfoTest.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============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.entity; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class CellInfoTest { + + @Test + public void cellInfoTest() { + CellInfo cellInfo=new CellInfo(); + cellInfo.setCellId("cellId"); + cellInfo.setPnfName("pnfName"); + assertEquals("cellId", cellInfo.getCellId()); + assertEquals("pnfName", cellInfo.getPnfName()); + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotificationsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotificationsTest.java new file mode 100644 index 0000000..05ea72e --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotificationsTest.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============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.entity; + +import static org.junit.Assert.assertEquals; + +import java.sql.Timestamp; + +import org.junit.Test; + +public class DmaapNotificationsTest { + + private Timestamp createdAt; + + @Test + public void dmaapNotififcationsTest() { + DmaapNotifications dmaapNotifications = new DmaapNotifications(); + dmaapNotifications.setNotification("notification"); + dmaapNotifications.setCreatedAt(createdAt); + assertEquals("notification", dmaapNotifications.getNotification()); + assertEquals(createdAt, dmaapNotifications.getCreatedAt()); + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java new file mode 100644 index 0000000..bf22fd6 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============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.entity; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class PciRequestsTest { + + @Test + public void pciRequestsTest() { + PciRequests pciRequests=new PciRequests(); + pciRequests.setChildThreadId(1L); + pciRequests.setTransactionId("transactionId"); + assertEquals(1L, pciRequests.getChildThreadId()); + assertEquals("transactionId", pciRequests.getTransactionId()); + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellConfigTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellConfigTest.java new file mode 100644 index 0000000..94f58b1 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellConfigTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * ============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 static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class CellConfigTest { + + @Test + public void cellConfigTest() { + + Common common = new Common(); + common.setCellIdentity("cellIdentity"); + Ran ran = new Ran(); + ran.setCommon(common); + Lte lte = new Lte(); + lte.setRan(ran); + CellConfig cellConfig = new CellConfig(); + cellConfig.setLte(lte); + assertEquals(lte, cellConfig.getLte()); + assertEquals(ran, lte.getRan()); + assertEquals(common, ran.getCommon()); + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourListTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourListTest.java new file mode 100644 index 0000000..d9684dd --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourListTest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * ============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 static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class CellNeighbourListTest { + + @Test + public void cellNeighbourListTest() { + CellNeighbourList cellNeighbourList = new CellNeighbourList(); + cellNeighbourList.setCellId("cellId"); + cellNeighbourList.setNeighbours("neighbour"); + cellNeighbourList.setPhysicalCellId(1); + assertEquals("cellId",cellNeighbourList.getCellId() ); + assertEquals("neighbour",cellNeighbourList.getNeighbours() ); + assertEquals(1,cellNeighbourList.getPhysicalCellId() ); + + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayloadTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayloadTest.java new file mode 100644 index 0000000..4505bff --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayloadTest.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * ============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 org.junit.Test; + +public class NotificationPayloadTest { + + @Test + public void notificationPayloadTest() { + + } + +} diff --git a/src/test/java/com/wipro/www/sonhms/model/NotificationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java index 09c6c0a..8ef4778 100644 --- a/src/test/java/com/wipro/www/sonhms/model/NotificationTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java @@ -1,24 +1,25 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.model; + * 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 static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -26,21 +27,21 @@ import static org.junit.Assert.assertNotEquals; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.wipro.www.sonhms.model.FapServiceList; -import com.wipro.www.sonhms.model.LteNeighborListInUseLteCell; -import com.wipro.www.sonhms.model.NeighborListInUse; -import com.wipro.www.sonhms.model.Notification; -import com.wipro.www.sonhms.model.NotificationCellConfig; -import com.wipro.www.sonhms.model.NotificationLte; -import com.wipro.www.sonhms.model.NotificationPayload; -import com.wipro.www.sonhms.model.NotificationRan; -import com.wipro.www.sonhms.model.RadioAccess; -import com.wipro.www.sonhms.model.X0005b9Lte; import java.io.IOException; import java.util.ArrayList; import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.model.LteNeighborListInUseLteCell; +import org.onap.dcaegen2.services.sonhms.model.NeighborListInUse; +import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.model.NotificationCellConfig; +import org.onap.dcaegen2.services.sonhms.model.NotificationLte; +import org.onap.dcaegen2.services.sonhms.model.NotificationPayload; +import org.onap.dcaegen2.services.sonhms.model.NotificationRan; +import org.onap.dcaegen2.services.sonhms.model.RadioAccess; +import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte; public class NotificationTest { diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java new file mode 100644 index 0000000..a7f0a79 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============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 static org.junit.Assert.assertEquals; + +import java.util.ArrayList; + +import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.model.CellConfig; +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.Lte; +import org.onap.dcaegen2.services.sonhms.model.Payload; +import org.onap.dcaegen2.services.sonhms.model.Ran; +import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte; + + + +public class PayloadTest { + + @Test + public void payloadTest() { + Common common = new Common("cell1"); + + Ran ran = new Ran(common); + + Lte lte = new Lte(ran); + + CellConfig cellConfig = new CellConfig(lte); + + X0005b9Lte x0005b9Lte = new X0005b9Lte(0, "pnf2"); + + FapService fapService = new FapService("cell6", x0005b9Lte, cellConfig); + + Data data = new Data(fapService); + + Configurations config = new Configurations(data); + ArrayList<Configurations> al = new ArrayList<>(); + al.add(config); + + Payload payload = new Payload(al); + + assertEquals("pnf2", payload.getConfiguration().get(0).getData().getFapservice().getX0005b9Lte().getPnfName()); + + assertEquals("cell6", payload.getConfiguration().get(0).getData().getFapservice().getAlias()); + + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotificationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotificationTest.java new file mode 100644 index 0000000..b99a9d7 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotificationTest.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * ============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 static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest; + +public class PolicyNotificationTest { + @Test + public void policyNotificationTest() { + PolicyNotification policyNotification=new PolicyNotification(); + Map<String, String> aai=new HashMap<>(); + aai.put("test","test"); + String target="test"; + String targetType="targetType"; + String payload="payload"; + String closedLoopControlName="closedLoopControlName"; + String action="action"; + String version="version"; + String from="from"; + String requestId="requestId"; + String closedLoopEventStatus="closedLoopEventStatus"; + String closedLoopEventClient="closedLoopEventClient"; + long closedLoopAlarmStart=96587958; + policyNotification.setAai(aai); + assertEquals(aai,policyNotification.getAai()); + policyNotification.setTarget(target); + assertEquals(target,policyNotification.getTarget()); + policyNotification.setTargetType(targetType); + assertEquals(targetType,policyNotification.getTargetType()); + policyNotification.setPayload(payload); + assertEquals(payload,policyNotification.getPayload()); + policyNotification.setClosedLoopControlName(closedLoopControlName); + assertEquals(closedLoopControlName,policyNotification.getClosedLoopControlName()); + policyNotification.setAction(action); + assertEquals(action,policyNotification.getAction()); + policyNotification.setVersion(version); + assertEquals(version,policyNotification.getVersion()); + policyNotification.setFrom(from); + assertEquals(from,policyNotification.getFrom()); + policyNotification.setRequestId(requestId); + assertEquals(requestId,policyNotification.getRequestId()); + policyNotification.setClosedLoopEventStatus(closedLoopEventStatus); + assertEquals(closedLoopEventStatus,policyNotification.getClosedLoopEventStatus()); + policyNotification.setClosedLoopEventClient(closedLoopEventClient); + assertEquals(closedLoopEventClient,policyNotification.getClosedLoopEventClient()); + policyNotification.setClosedLoopAlarmStart(closedLoopAlarmStart); + assertEquals(closedLoopAlarmStart,policyNotification.getClosedLoopAlarmStart()); + + String notif1 = readFromFile("/policy_notification.json"); + String notif2 = readFromFile("/policy_notification.json"); + PolicyNotification policyNotification1 = new PolicyNotification(); + PolicyNotification policyNotification2 = new PolicyNotification(); + PolicyNotification policyNotification3 = new PolicyNotification(); + ObjectMapper mapper = new ObjectMapper(); + + try { + policyNotification1 = mapper.readValue(notif1, PolicyNotification.class); + policyNotification2 = mapper.readValue(notif2, PolicyNotification.class); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Assert.assertEquals(policyNotification1.hashCode(), policyNotification2.hashCode()); + Assert.assertNotEquals(policyNotification1.hashCode(), policyNotification3.hashCode()); + + } + + private static String readFromFile(String file) { + String content = new String(); + try { + + InputStream is = ClusterUtilsTest.class.getResourceAsStream(file); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); + content = bufferedReader.readLine(); + String temp; + while((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + bufferedReader.close(); + } + catch(Exception e) { + e.printStackTrace(); + content = null; + } + return content; + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/ResponseTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/ResponseTest.java new file mode 100644 index 0000000..0fcdb1b --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/ResponseTest.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============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 static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ResponseTest { + + @Test + public void respomseTest() { + Response response = new Response(); + response.setCellId("cellId"); + response.setPci(1); + assertEquals("cellId", response.getCellId()); + assertEquals(1, response.getPci()); + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponseTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponseTest.java new file mode 100644 index 0000000..a65f51b --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponseTest.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============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 static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class SdnrResponseTest { + + @Test + public void sdnrResponseTest() { + SdnrResponse sdnrResponse=new SdnrResponse(); + Response response=new Response(); + response.setCellId("cellId"); + response.setPci(2); + List<Response> responseList=new ArrayList<>(); + responseList.add(response); + sdnrResponse.setResponse(responseList); + assertEquals(responseList,sdnrResponse.getResponse()); + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/ThreadIdTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/ThreadIdTest.java new file mode 100644 index 0000000..ad23c3a --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/ThreadIdTest.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============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 static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ThreadIdTest { + + @Test + public void threadIdtest() { + ThreadId threadId=new ThreadId(); + long Id=987957948; + threadId.setChildThreadId(Id); + assertEquals(Id,threadId.getChildThreadId()); + } + +} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/AsyncResponseBodyTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBodyTest.java index 95afd77..085abbb 100644 --- a/src/test/java/com/wipro/www/sonhms/restclient/AsyncResponseBodyTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBodyTest.java @@ -1,33 +1,33 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; - -import com.wipro.www.sonhms.restclient.AsyncResponseBody; -import com.wipro.www.sonhms.restclient.Solution; -import com.wipro.www.sonhms.restclient.SonSolution; + * 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.restclient; import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; +import org.onap.dcaegen2.services.sonhms.restclient.Solution; +import org.onap.dcaegen2.services.sonhms.restclient.SonSolution; diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfoTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfoTest.java new file mode 100644 index 0000000..24ba1ae --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfoTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * ============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.restclient; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.restclient.CellInfo; + + +public class CellInfoTest { + @Test + public void cellInfoTest() { + List<String> cellIdLists = new ArrayList<>(); + cellIdLists.add("cell1"); + + CellInfo cellInfo = new CellInfo(); + cellInfo.setNetworkId("NTWK001"); + cellInfo.setCellIdList(cellIdLists); + assertEquals("NTWK001", cellInfo.getNetworkId()); + assertEquals(cellIdLists, cellInfo.getCellIdList()); + + } +} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/OofRequestBodyTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBodyTest.java index 493095b..eb0d189 100644 --- a/src/test/java/com/wipro/www/sonhms/restclient/OofRequestBodyTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBodyTest.java @@ -1,34 +1,34 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; + * 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.restclient; import static org.junit.Assert.assertEquals; -import com.wipro.www.sonhms.restclient.CellInfo; -import com.wipro.www.sonhms.restclient.OofRequestBody; -import com.wipro.www.sonhms.restclient.RequestInfo; - import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.restclient.CellInfo; +import org.onap.dcaegen2.services.sonhms.restclient.OofRequestBody; +import org.onap.dcaegen2.services.sonhms.restclient.RequestInfo; diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java new file mode 100644 index 0000000..4a9fed5 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * ============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.restclient; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException; +import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({ SonHandlerRestTemplate.class,Configuration.class }) +@SpringBootTest(classes = OofRestClientTest.class) +public class OofRestClientTest { + Configuration configuration = Configuration.getInstance(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void queryOofTest() { + configuration.setBufferTime(60); + configuration.setCallbackUrl("/callbackUrl"); + configuration.setConfigName("configName"); + List<String> list = new ArrayList<String>(); + list.add("server"); + configuration.setServers(list); + configuration.setCg("cg"); + configuration.setCid("cid"); + configuration.setManagerApiKey("managerApiKey"); + configuration.setManagerSecretKey("managerSecretKey"); + configuration.setMaximumClusters(5); + configuration.setMinCollision(5); + configuration.setMinConfusion(5); + configuration.setNumSolutions(1); + configuration.setOofService("oofService"); + configuration.setOptimizers(list); + configuration.setPcimsApiKey("pcimsApiKey"); + configuration.setPcimsSecretKey("pcimsSecretKey"); + configuration.setPolicyName("policyName"); + configuration.setPolicyService("policyService"); + configuration.setPolicyTopic("policyTopic"); + configuration.setPollingInterval(30); + configuration.setPollingTimeout(100); + configuration.setSdnrService("sdnrService"); + configuration.setSdnrTopic("sdnrTopic"); + configuration.setSourceId("sourceId"); + String responseBody="{\n" + + " \"transactionId\": \"xxx-xxx-xxxx\",\n" + + " \"requestId\": \"yyy-yyy-yyyy\",\n" + + " \"requestStatus\": \"accepted\",\n" + + " \"statusMessage\": \"\"\n" + + "}"; + List<String> cellIdList=new ArrayList<String>(); + cellIdList.add("EXP001"); + List<String> optimizers=new ArrayList<String>(); + optimizers.add("pci"); + + PowerMockito.mockStatic(SonHandlerRestTemplate.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + PowerMockito.when(SonHandlerRestTemplate.sendPostRequestToOof(Mockito.anyString(),Mockito.anyString() ,Matchers.<ParameterizedTypeReference<String>>any())) + .thenReturn(ResponseEntity.ok(responseBody)); + + + try { + String result=OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers); + assertEquals(ResponseEntity.ok(responseBody).getBody(), result); + + + } catch (OofNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + PowerMockito.when(SonHandlerRestTemplate.sendPostRequestToOof(Mockito.anyString(),Mockito.anyString() ,Matchers.<ParameterizedTypeReference<String>>any())) + .thenReturn(null); + try { + String result=OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers); + assertEquals(ResponseEntity.ok(responseBody).getBody(), result); + + + } catch (OofNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } + +} + + + diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java new file mode 100644 index 0000000..4f59435 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * ============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.restclient; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.restclient.SonSolution; + + +public class PciSolutionsTest { + @Test + public void pciSolutionsTest() { + SonSolution pciSolutions = new SonSolution(); + pciSolutions.setCellId("EXP001"); + pciSolutions.setPci(101); + assertEquals("EXP001", pciSolutions.getCellId()); + assertEquals(101, pciSolutions.getPci()); + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBodyTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBodyTest.java new file mode 100644 index 0000000..5de8951 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBodyTest.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============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.restclient; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.restclient.PolicyRequestBody; + + +public class PolicyRequestBodyTest { + @Test + public void policyRequestBodyTest() { + PolicyRequestBody policyRequestBody = new PolicyRequestBody(); + policyRequestBody.setConfigName("PCIMS_CONFIG_POLICY"); + policyRequestBody.setPolicyName("com.PCIMS_CONFIG_POLICY"); + policyRequestBody.setRequestId("60fe7fe6-2649-4f6c-8468-30eb03fd0527"); + assertEquals("PCIMS_CONFIG_POLICY", policyRequestBody.getConfigName()); + assertEquals("com.PCIMS_CONFIG_POLICY", policyRequestBody.getPolicyName()); + assertEquals("60fe7fe6-2649-4f6c-8468-30eb03fd0527", policyRequestBody.getRequestId()); + + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClientTest.java new file mode 100644 index 0000000..387b958 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClientTest.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * ============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.restclient; + +import static org.junit.Assert.assertEquals; +import java.util.ArrayList; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.restclient.PolicyRestClient; +import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({ SonHandlerRestTemplate.class, Configuration.class }) +@SpringBootTest(classes = PolicyRestClientTest.class) +public class PolicyRestClientTest { + + Configuration configuration = Configuration.getInstance(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void fetchConfigFromPolicyTest() { + + configuration.setBufferTime(60); + configuration.setCallbackUrl("/callbackUrl"); + configuration.setConfigName("configName"); + List<String> list = new ArrayList<String>(); + list.add("server"); + configuration.setServers(list); + configuration.setCg("cg"); + configuration.setCid("cid"); + configuration.setManagerApiKey("managerApiKey"); + configuration.setManagerSecretKey("managerSecretKey"); + configuration.setMaximumClusters(5); + configuration.setMinCollision(5); + configuration.setMinConfusion(5); + configuration.setNumSolutions(1); + configuration.setOofService("oofService"); + configuration.setOptimizers(list); + configuration.setPcimsApiKey("pcimsApiKey"); + configuration.setPcimsSecretKey("pcimsSecretKey"); + configuration.setPolicyName("policyName"); + configuration.setPolicyService("policyService"); + configuration.setPolicyTopic("policyTopic"); + configuration.setPollingInterval(30); + configuration.setPollingTimeout(100); + configuration.setSdnrService("sdnrService"); + configuration.setSdnrTopic("sdnrTopic"); + configuration.setSourceId("sourceId"); + String responseBody="{\n" + + "\"policyName\": \"com.Config_PCIMS_CONFIG_POLICY\",\n" + + "\"policyVersion\": \"1\",\n" + + "\"configBody\": \"{ \\\"PCI_NEIGHBOR_CHANGE_CLUSTER_TIMEOUT_IN_SECS\\\":60,\n" + + "\\\"PCI_MODCONFIG_POLICY_NAME\\\":\\\"ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-\n" + + "529269fb1459\\\", \\\"PCI_OPTMIZATION_ALGO_CATEGORY_IN_OOF\\\":\\\"OOF-PCI-\n" + + "OPTIMIZATION\\\", \\\"PCI_SDNR_TARGET_NAME\\\":\\\"SDNR\\\" }\",\n" + + "\"policyClass\": \"Config\",\n" + + "\"policyConfigType\": \"Base\",\n" + + "\"ttlDate\": \"2018-08-29T06:28:16.830Z\",\n" + + "\"onapName\": \"DCAE\",\n" + + "\"configName\": \"PCIMS_CONFIG_POLICY\",\n" + + "\"configBodyType\": \"JSON\"\n" + + "}\n" + + ""; + PowerMockito.mockStatic(SonHandlerRestTemplate.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + + PowerMockito.when(SonHandlerRestTemplate.sendPostToPolicy(Mockito.anyString(),Mockito.anyString() ,Matchers.<ParameterizedTypeReference<String>>any())) + .thenReturn(ResponseEntity.ok(responseBody)); + String result=PolicyRestClient.fetchConfigFromPolicy(); + assertEquals(ResponseEntity.ok(responseBody).getBody(), result); + + + + + + } + +} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/RequestInfoTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfoTest.java index f21971b..4d360d8 100644 --- a/src/test/java/com/wipro/www/sonhms/restclient/RequestInfoTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfoTest.java @@ -1,33 +1,33 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; + * 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.restclient; import static org.junit.Assert.assertEquals; -import com.wipro.www.sonhms.restclient.RequestInfo; - import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.restclient.RequestInfo; public class RequestInfoTest { diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java new file mode 100644 index 0000000..c13b698 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * ============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.restclient; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.slf4j.Logger; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({ SonHandlerRestTemplate.class,Configuration.class }) +@SpringBootTest(classes = SdnrRestClientTest.class) +public class SdnrRestClientTest { + + Configuration configuration = Configuration.getInstance(); + private static final Logger log = org.slf4j.LoggerFactory.getLogger(SdnrRestClient.class); + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void getCellListTest() { + + String responseBody="[\n" + + " \"string\"\n" + + "]"; + PowerMockito.mockStatic(SonHandlerRestTemplate.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any())) + .thenReturn(ResponseEntity.ok(responseBody)); + try { + String result=SdnrRestClient.getCellList("12345"); + assertEquals(ResponseEntity.ok(responseBody).getBody(),result); + } catch (ConfigDbNotFoundException e) { + log.debug("ConfigDbNotFoundException {}",e.toString());; + } + + } + + @Test + public void getNbrListTest() { + + String responseBody="[\n" + + " {\n" + + " \"cellId\": \"string\",\n" + + " \"pciValue\": 0\n" + + " }\n" + + "]"; + PowerMockito.mockStatic(SonHandlerRestTemplate.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any())) + .thenReturn(ResponseEntity.ok(responseBody)); + try { + List<CellPciPair> result=SdnrRestClient.getNbrList("1"); + List<CellPciPair> nbrList = new ArrayList<>(); + String response=ResponseEntity.ok(responseBody).getBody(); + JSONArray nbrListObj = new JSONArray(response); + 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); + } + assertEquals(nbrList,result); + } catch (ConfigDbNotFoundException e) { + log.debug("ConfigDbNotFoundException {}",e.toString());; + } + + } + @Test + public void getPciTest() { + + String responseBody="{\n" + + " \"attribute-name\": \"string\",\n" + + " \"value\": 0\n" + + "}"; + PowerMockito.mockStatic(SonHandlerRestTemplate.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any())) + .thenReturn(ResponseEntity.ok(responseBody)); + try { + int result=SdnrRestClient.getPci("1"); + String response=ResponseEntity.ok(responseBody).getBody(); + JSONObject respObj = new JSONObject(response); + assertEquals(respObj.getInt("value"),result); + } catch (ConfigDbNotFoundException e) { + log.debug("ConfigDbNotFoundException {}",e.toString());; + } + + } + @Test + public void getPnfNameTest() { + + String responseBody="{\n" + + " \"attribute-name\": \"string\",\n" + + " \"value\": \"string\"\n" + + "}"; + PowerMockito.mockStatic(SonHandlerRestTemplate.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any())) + .thenReturn(ResponseEntity.ok(responseBody)); + try { + String result=SdnrRestClient.getPnfName("1"); + String response=ResponseEntity.ok(responseBody).getBody(); + JSONObject respObj = new JSONObject(response); + assertEquals(respObj.getString("value"),result); + } catch (ConfigDbNotFoundException e) { + log.debug("ConfigDbNotFoundException {}",e.toString());; + } + + } +} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/SolutionsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SolutionsTest.java index 64985f6..9decce0 100644 --- a/src/test/java/com/wipro/www/sonhms/restclient/SolutionsTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SolutionsTest.java @@ -1,32 +1,33 @@ /******************************************************************************* - * ============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========================================================= - ******************************************************************************/ - -package com.wipro.www.sonhms.restclient; + * 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.restclient; import static org.junit.Assert.assertEquals; -import com.wipro.www.sonhms.restclient.Solution; -import com.wipro.www.sonhms.restclient.SonSolution; import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.onap.dcaegen2.services.sonhms.restclient.Solution; +import org.onap.dcaegen2.services.sonhms.restclient.SonSolution; diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java new file mode 100644 index 0000000..dd3059a --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java @@ -0,0 +1,270 @@ +/******************************************************************************* + * ============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.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +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.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import fj.data.Either; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({ SdnrRestClient.class, BeanUtil.class }) +@SpringBootTest(classes = ClusterUtils.class) +public class ClusterUtilsTest { + + @Mock + private ClusterDetailsRepository clusterDetailsRepositoryMock; + + @InjectMocks + ClusterUtils clusterUtils; + + private static Notification notification1; + private static Notification notification2; + private static List<ClusterDetails> clusterDetailsForGetClusterDetailsFromClusterIdTest; + private static Graph cluster; + private static List<ClusterDetails> clusterDetails = new ArrayList<>(); + + @BeforeClass + public static void setup() { + + notification1 = new Notification(); + notification2 = new Notification(); + clusterDetailsForGetClusterDetailsFromClusterIdTest = new ArrayList<ClusterDetails>(); + + String notificationString1 = readFromFile("/notification1.json"); + String notificationString2 = readFromFile("/notification2.json"); + String clusterDetailsListString=readFromFile("/ClusterDetailsTest.json"); + + String clusterInfo1 = readFromFile("/clusterInfo1.json"); + String clusterInfo2 = readFromFile("/clusterInfo2.json"); + String clusterInfo3 = readFromFile("/clusterInfo3.json"); + String clusterInfo4 = readFromFile("/clusterInfo4.json"); + String clusterInfo = readFromFile("/clusterInfo5.json"); + cluster=new Graph(clusterInfo); + + clusterDetails.add(new ClusterDetails("1", clusterInfo1, 35)); + clusterDetails.add(new ClusterDetails("2", clusterInfo2, 36)); + clusterDetails.add(new ClusterDetails("3", clusterInfo3, 37)); + clusterDetails.add(new ClusterDetails("4", clusterInfo4, 38)); + + + ObjectMapper mapper = new ObjectMapper(); + + try { + notification1 = mapper.readValue(notificationString1, Notification.class); + notification2 = mapper.readValue(notificationString2, Notification.class); + clusterDetailsForGetClusterDetailsFromClusterIdTest=mapper.readValue(clusterDetailsListString,new TypeReference<List<ClusterDetails>>(){}); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + + } + + @Before + public void setupTest() { + clusterUtils = new ClusterUtils(); + MockitoAnnotations.initMocks(this); + } + + @Test + public void getClustersForNotificationTest(){ + + NotificationToClusterMapping expected = new NotificationToClusterMapping(); + Map<FapServiceList, String> cellsinCluster = new HashMap<>(); + cellsinCluster.put(notification1.getPayload().getRadioAccess().getFapServiceList().get(0), "2"); + expected.setCellsinCluster(cellsinCluster); + expected.setNewCells(new ArrayList<FapServiceList>()); + + NotificationToClusterMapping result = clusterUtils.getClustersForNotification(notification1, clusterDetails); + assertEquals(expected, result); + + expected = new NotificationToClusterMapping(); + List<FapServiceList> newCells = new ArrayList<>(); + newCells.add(notification2.getPayload().getRadioAccess().getFapServiceList().get(0)); + expected.setCellsinCluster(new HashMap<>()); + expected.setNewCells(newCells); + + result = clusterUtils.getClustersForNotification(notification2, clusterDetails); + assertEquals(expected, result); + } + + @Test + public void createClusterTest() throws ConfigDbNotFoundException { + + FapServiceList fapServiceList = notification1.getPayload().getRadioAccess().getFapServiceList().get(0); + + List<CellPciPair> nbrList = new ArrayList<>(); + + nbrList.add(new CellPciPair("44", 3)); + + PowerMockito.mockStatic(SdnrRestClient.class); + + PowerMockito.when(SdnrRestClient.getNbrList(Mockito.anyString())).thenReturn(nbrList); + + assertEquals(cluster, clusterUtils.createCluster(fapServiceList)); + + + + } + + @Test + public void getClusterDetailsFromClusterIdTest() { + ClusterDetails responseValue=null; + Integer responseVal = null; + Integer expectedValue=404; + Either<ClusterDetails, Integer> response=clusterUtils.getClusterDetailsFromClusterId("0",clusterDetailsForGetClusterDetailsFromClusterIdTest); + assertTrue(response.isLeft()); + if(response.isLeft()) { + responseValue=response.left().value(); + } + assertEquals(clusterDetailsForGetClusterDetailsFromClusterIdTest.get(0),responseValue); + response=clusterUtils.getClusterDetailsFromClusterId("1",clusterDetailsForGetClusterDetailsFromClusterIdTest); + assertTrue(response.isLeft()); + if(response.isLeft()) { + responseValue=response.left().value(); + } + assertEquals(clusterDetailsForGetClusterDetailsFromClusterIdTest.get(1),responseValue); + response=clusterUtils.getClusterDetailsFromClusterId("9",clusterDetailsForGetClusterDetailsFromClusterIdTest); + assertTrue(response.isRight()); + if(response.isRight()) { + responseVal=response.right().value(); + } + assertEquals(expectedValue,responseVal); + + } + + @Test + public void saveClusterTest() { + ClusterDetails details = new ClusterDetails(); + details.setClusterId("123e4567-e89b-12d3-a456-426655440000"); + details.setClusterInfo("cellPciNeighbourString"); + details.setChildThreadId(978668); + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(ClusterDetailsRepository.class)) + .thenReturn(clusterDetailsRepositoryMock); + Mockito.when(clusterDetailsRepositoryMock.save(details)).thenReturn(details); + Long threadId=(long) 978668; + clusterUtils.saveCluster(cluster, UUID.fromString("123e4567-e89b-12d3-a456-426655440000"),threadId); + assertEquals(details, clusterDetailsRepositoryMock.save(details)); + + } + + @Test + public void getClusterForCellTest() { + FapServiceList fapServiceList= notification1.getPayload().getRadioAccess().getFapServiceList().get(0); + String clusterInfo1=readFromFile("/clusterInfo1.json"); + String clusterInfo2=readFromFile("/clusterInfo2.json"); + Graph graph1=new Graph(clusterInfo1); + Graph graph2=new Graph(clusterInfo2); + List<Graph> newClusters=new ArrayList<Graph>(); + newClusters.add(graph1); + newClusters.add(graph2); + Either<Graph, Integer> result=clusterUtils.getClusterForCell(fapServiceList, newClusters); + assertTrue(result.isLeft()); + + newClusters = new ArrayList<>(); + newClusters.add(graph1); + result=clusterUtils.getClusterForCell(fapServiceList, newClusters); + assertTrue(result.isRight()); + int resultRight=result.right().value(); + assertEquals(404, resultRight); + + List<Graph> emptyList=new ArrayList<Graph>(); + + result=clusterUtils.getClusterForCell(fapServiceList, emptyList); + assertTrue(result.isRight()); + resultRight=result.right().value(); + assertEquals(404, resultRight); + + } + + @Test + public void modifyClusterTest() { + + String clusterInfo = readFromFile("/clusterInfo2.json"); + String clusterInfo2 = readFromFile("/clusterInfo6.json"); + + Graph cluster = new Graph(clusterInfo); + Graph expected = new Graph(clusterInfo2); + + assertEquals(expected, clusterUtils.modifyCluster(cluster, notification1.getPayload().getRadioAccess().getFapServiceList().get(0))); + } + + private static String readFromFile(String file) { + String content = new String(); + try { + + InputStream is = ClusterUtilsTest.class.getResourceAsStream(file); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); + content = bufferedReader.readLine(); + String temp; + while((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + bufferedReader.close(); + } + catch(Exception e) { + content = null; + } + return content; + } +} diff --git a/src/test/resources/ClusterDetailsTest.json b/src/test/resources/ClusterDetailsTest.json new file mode 100644 index 0000000..01839ae --- /dev/null +++ b/src/test/resources/ClusterDetailsTest.json @@ -0,0 +1,10 @@ +[{"clusterId":"0", +"clusterInfo":"", + "childThreadId":986476 +}, +{"clusterId":"1", +"clusterInfo":"", + "childThreadId":986475 +} +] + diff --git a/src/test/resources/clusterInfo1.json b/src/test/resources/clusterInfo1.json new file mode 100644 index 0000000..685d923 --- /dev/null +++ b/src/test/resources/clusterInfo1.json @@ -0,0 +1 @@ +[{"cellId":"29","physicalCellId":209,"neighbours":"[]"},{"cellId":"25","physicalCellId":32,"neighbours":"[{\"physicalCellId\":209,\"cellId\":\"29\"}]"}] diff --git a/src/test/resources/clusterInfo2.json b/src/test/resources/clusterInfo2.json new file mode 100644 index 0000000..6fe6d5e --- /dev/null +++ b/src/test/resources/clusterInfo2.json @@ -0,0 +1 @@ +[{"cellId":"45","physicalCellId":310,"neighbours":"[]"},{"cellId":"47","physicalCellId":302,"neighbours":"[{\"physicalCellId\":310,\"cellId\":\"45\"}]"}] diff --git a/src/test/resources/clusterInfo3.json b/src/test/resources/clusterInfo3.json new file mode 100644 index 0000000..71e7736 --- /dev/null +++ b/src/test/resources/clusterInfo3.json @@ -0,0 +1 @@ +[{"cellId":"72","physicalCellId":2,"neighbours":"[]"},{"cellId":"63","physicalCellId":5,"neighbours":"[{\"physicalCellId\":2,\"cellId\":\"72\"}]"}] diff --git a/src/test/resources/clusterInfo4.json b/src/test/resources/clusterInfo4.json new file mode 100644 index 0000000..4da8c07 --- /dev/null +++ b/src/test/resources/clusterInfo4.json @@ -0,0 +1 @@ +[{"cellId":"2","physicalCellId":20,"neighbours":"[]"},{"cellId":"5","physicalCellId":30,"neighbours":"[{\"physicalCellId\":20,\"cellId\":\"2\"}]"}] diff --git a/src/test/resources/clusterInfo5.json b/src/test/resources/clusterInfo5.json new file mode 100644 index 0000000..7612d10 --- /dev/null +++ b/src/test/resources/clusterInfo5.json @@ -0,0 +1 @@ +[{"cellId":"44","physicalCellId":3,"neighbours":"[]"},{"cellId":"48","physicalCellId":0,"neighbours":"[{\"physicalCellId\":3,\"cellId\":\"44\"}]"},{"cellId":"45","physicalCellId":310,"neighbours":"[{\"physicalCellId\":0,\"cellId\":\"48\"}]"}] diff --git a/src/test/resources/clusterInfo6.json b/src/test/resources/clusterInfo6.json new file mode 100644 index 0000000..88e0763 --- /dev/null +++ b/src/test/resources/clusterInfo6.json @@ -0,0 +1 @@ +[{"cellId":"48","physicalCellId":0,"neighbours":"[]"},{"cellId":"45","physicalCellId":310,"neighbours":"[{\"physicalCellId\":0,\"cellId\":\"48\"}]"},{"cellId":"47","physicalCellId":302,"neighbours":"[{\"physicalCellId\":310,\"cellId\":\"45\"}]"}] diff --git a/src/test/resources/clusterInfo7.json b/src/test/resources/clusterInfo7.json new file mode 100644 index 0000000..1d8dc7d --- /dev/null +++ b/src/test/resources/clusterInfo7.json @@ -0,0 +1 @@ +[{"cellId":"82","physicalCellId":32,"neighbours":"[]"},{"cellId":"81","physicalCellId":31,"neighbours":"[{\"physicalCellId\":32,\"cellId\":\"82\"}]"}] diff --git a/src/test/resources/notification1.json b/src/test/resources/notification1.json new file mode 100644 index 0000000..87f60e6 --- /dev/null +++ b/src/test/resources/notification1.json @@ -0,0 +1,45 @@ +{ + "requestID":"9d2d790e-a5f0-11e8-98d0-529269fb1459", + "AAI":{ + + }, + "from":"SDNR", + "version":"1.0.2", + "Action":"NeighborListModified", + "Payload":{ + "RadioAccess":{ + "FAPServiceNumberOfEntries":"1", + "FAPServiceList":[ + { + "alias":"45", + "X0005b9Lte":{ + "phyCellIdInUse":"310", + "pnfName":"ncserver2" + }, + "CellConfig":{ + "LTE":{ + "RAN":{ + "CellIdentity":"45", + "NeighborListInUse":{ + "LTECellNumberOfEntries":"1", + "LTENeighborListInUseLTECell":[ + { + "pnfName":"ncserver1", + "enable":"true", + "alias":"48", + "mustInclude":"true", + "plmnid":"ran-1", + "cid":"48", + "phyCellId":"0", + "blacklisted":"false" + } + ] + } + } + } + } + } + ] + } + } +} diff --git a/src/test/resources/notification2.json b/src/test/resources/notification2.json new file mode 100644 index 0000000..702b643 --- /dev/null +++ b/src/test/resources/notification2.json @@ -0,0 +1,55 @@ +{ + "requestID":"9d2d790e-a5f0-11e8-98d0-529269fb1459", + "AAI":{ + + }, + "from":"SDNR", + "version":"1.0.2", + "Action":"NeighborListModified", + "Payload":{ + "RadioAccess":{ + "FAPServiceNumberOfEntries":"1", + "FAPServiceList":[ + { + "alias":"120", + "X0005b9Lte":{ + "phyCellIdInUse":"2", + "pnfName":"ncserver2" + }, + "CellConfig":{ + "LTE":{ + "RAN":{ + "CellIdentity":"120", + "NeighborListInUse":{ + "LTECellNumberOfEntries":"3", + "LTENeighborListInUseLTECell":[ + { + "pnfName":"ncserver1", + "enable":"true", + "alias":"123", + "mustInclude":"true", + "plmnid":"ran-1", + "cid":"123", + "phyCellId":"6", + "blacklisted":"false" + }, + { + "pnfName":"ncserver1", + "enable":"true", + "alias":"49", + "mustInclude":"true", + "plmnid":"ran-1", + "cid":"124", + "phyCellId":"4", + "blacklisted":"false" + } + ] + } + } + } + } + } + ] + } + } +} diff --git a/src/test/resources/notification3.json b/src/test/resources/notification3.json new file mode 100644 index 0000000..4a3a2a0 --- /dev/null +++ b/src/test/resources/notification3.json @@ -0,0 +1,45 @@ +{ + "requestID":"9d2d790e-a5f0-11e8-98d0-529269fb1459", + "AAI":{ + + }, + "from":"SDNR", + "version":"1.0.2", + "Action":"NeighborListModified", + "Payload":{ + "RadioAccess":{ + "FAPServiceNumberOfEntries":"1", + "FAPServiceList":[ + { + "alias":"81", + "X0005b9Lte":{ + "phyCellIdInUse":"31", + "pnfName":"ncserver2" + }, + "CellConfig":{ + "LTE":{ + "RAN":{ + "CellIdentity":"81", + "NeighborListInUse":{ + "LTECellNumberOfEntries":"1", + "LTENeighborListInUseLTECell":[ + { + "pnfName":"ncserver1", + "enable":"true", + "alias":"82", + "mustInclude":"true", + "plmnid":"ran-1", + "cid":"82", + "phyCellId":"32", + "blacklisted":"false" + } + ] + } + } + } + } + } + ] + } + } +} diff --git a/src/test/resources/policy_notification.json b/src/test/resources/policy_notification.json new file mode 100644 index 0000000..b9a6910 --- /dev/null +++ b/src/test/resources/policy_notification.json @@ -0,0 +1,20 @@ +{ + + "closedLoopControlName":"ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459", + "closedLoopAlarmStart":1542445563201, + "closedLoopEventClient":"microservice.PCI", + "closedLoopEventStatus":"ONSET", + "target_type":"VNF", + "target":"generic-vnf.vnf-id", + "requestID":"a4130fd5-2291-4a83-8992-04e4c9f32731", + "from":"PCIMS", + "version":"1.0.2", + "payload":"{\"Configurations\":[{\"data\":{\"FAPService\":{\"alias\":\"Chn0330\",\"X0005b9Lte\":{\"phyCellIdInUse\":6,\"pnfName\":\"ncserver23\"},\"CellConfig\":{\"LTE\":{\"RAN\":{\"Common\":{\"CellIdentity\":\"Chn0330\"}}}}}}},{\"data\":{\"FAPService\":{\"alias\":\"Chn0331\",\"X0005b9Lte\":{\"phyCellIdInUse\":7,\"pnfName\":\"ncserver23\"},\"CellConfig\":{\"LTE\":{\"RAN\":{\"Common\":{\"CellIdentity\":\"Chn0331\"}}}}}}}]}", + "AAI":{ + "generic-vnf.prov-status":"ACTIVE", + "generic-vnf.is-closed-loop-disabled":"false", + "generic-vnf.vnf-id":"ncserver23" + }, + "Action":"ModifyConfig" + +} diff --git a/src/test/resources/solutions.json b/src/test/resources/solutions.json new file mode 100644 index 0000000..cf82283 --- /dev/null +++ b/src/test/resources/solutions.json @@ -0,0 +1 @@ +[{"startTime":"2016-10-01T00:30+01:00","finishTime":"2016-10-01T00:40+01.00","networkId":"NTWK005","pciSolutions":[{"cellId":"EXP001","pci":"101"},{"cellId":"EXP002","pci":"102"}]}] |