1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Wipro Limited.
6 * ==============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 *******************************************************************************/
22 package org.onap.dcaegen2.services.sonhms.child;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.Optional;
30 import org.onap.dcaegen2.services.sonhms.dao.CellInfoRepository;
31 import org.onap.dcaegen2.services.sonhms.entity.CellInfo;
32 import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
33 import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
34 import org.onap.dcaegen2.services.sonhms.restclient.AnrSolutions;
35 import org.onap.dcaegen2.services.sonhms.restclient.PciSolutions;
36 import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
37 import org.onap.dcaegen2.services.sonhms.restclient.Solutions;
38 import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
39 import org.slf4j.Logger;
43 public class PnfUtils {
45 private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThreadUtils.class);
51 public Map<String, List<CellPciPair>> getPnfs(Solutions solutions) throws ConfigDbNotFoundException {
53 Map<String, List<CellPciPair>> pnfs = new HashMap<>();
54 List<PciSolutions> pciSolutions = solutions.getPciSolutions();
55 for (PciSolutions pciSolution : pciSolutions) {
56 String cellId = pciSolution.getCellId();
57 int pci = pciSolution.getPci();
60 CellInfoRepository cellInfoRepository = BeanUtil.getBean(CellInfoRepository.class);
61 Optional<CellInfo> cellInfo = cellInfoRepository.findById(cellId);
62 if (cellInfo.isPresent()) {
63 pnfName = cellInfo.get().getPnfName();
65 pnfName = SdnrRestClient.getPnfName(cellId);
66 cellInfoRepository.save(new CellInfo(cellId, pnfName));
68 if (pnfs.containsKey(pnfName)) {
69 pnfs.get(pnfName).add(new CellPciPair(cellId, pci));
71 List<CellPciPair> cellPciPairs = new ArrayList<>();
72 cellPciPairs.add(new CellPciPair(cellId, pci));
73 pnfs.put(pnfName, cellPciPairs);
81 * get pnfs for ANR solutions
84 public Map<String, List<Map<String,List<String>>>> getPnfsForAnrSolutions(List<AnrSolutions> anrSolutions) throws ConfigDbNotFoundException {
86 Map<String, List<Map<String,List<String>>>> anrPnfs = new HashMap<>();
88 List<String> removeableNeighbors;
89 for(AnrSolutions anrSolution : anrSolutions) {
90 String cellId = anrSolution.getCellId();
91 String pnfName = SdnrRestClient.getPnfName(cellId);
92 removeableNeighbors = anrSolution.getRemoveableNeighbors();
93 Map<String,List<String>> cellRemNeighborsPair = new HashMap<>();
94 cellRemNeighborsPair.put(cellId, removeableNeighbors);
95 if(anrPnfs.containsKey(pnfName)) {
96 anrPnfs.get(pnfName).add(cellRemNeighborsPair);
98 List<Map<String,List<String>>> anrCells = new ArrayList<>();
99 anrCells.add(cellRemNeighborsPair);
100 anrPnfs.put(pnfName, anrCells);
103 log.info("anr Pnfs {}",anrPnfs.toString());