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 com.fasterxml.jackson.annotation.JsonInclude.Include;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
28 import java.util.ArrayList;
29 import java.util.List;
31 import java.util.UUID;
33 import org.onap.dcaegen2.services.sonhms.ConfigPolicy;
34 import org.onap.dcaegen2.services.sonhms.Configuration;
35 import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository;
36 import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient;
37 import org.onap.dcaegen2.services.sonhms.entity.SonRequests;
38 import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
39 import org.onap.dcaegen2.services.sonhms.model.CellConfig;
40 import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
41 import org.onap.dcaegen2.services.sonhms.model.Common;
42 import org.onap.dcaegen2.services.sonhms.model.Configurations;
43 import org.onap.dcaegen2.services.sonhms.model.Data;
44 import org.onap.dcaegen2.services.sonhms.model.FapService;
45 import org.onap.dcaegen2.services.sonhms.model.Lte;
46 import org.onap.dcaegen2.services.sonhms.model.LteCell;
47 import org.onap.dcaegen2.services.sonhms.model.NeighborListInUse;
48 import org.onap.dcaegen2.services.sonhms.model.Payload;
49 import org.onap.dcaegen2.services.sonhms.model.PolicyNotification;
50 import org.onap.dcaegen2.services.sonhms.model.Ran;
51 import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte;
52 import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody;
53 import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
54 import org.onap.dcaegen2.services.sonhms.restclient.Solutions;
55 import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
56 import org.slf4j.Logger;
58 public class ChildThreadUtils {
60 private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThreadUtils.class);
61 private ConfigPolicy configPolicy;
62 private PnfUtils pnfUtils;
63 private PolicyDmaapClient policyDmaapClient;
66 * Parameterized constructor.
68 public ChildThreadUtils(ConfigPolicy configPolicy, PnfUtils pnfUtils, PolicyDmaapClient policyDmaapClient) {
69 this.configPolicy = configPolicy;
70 this.pnfUtils = pnfUtils;
71 this.policyDmaapClient = policyDmaapClient;
77 public void saveRequest(String transactionId, long childThreadId) {
78 SonRequestsRepository sonRequestsRepository = BeanUtil.getBean(SonRequestsRepository.class);
80 SonRequests sonRequest = new SonRequests();
81 sonRequest.setTransactionId(transactionId);
82 sonRequest.setChildThreadId(childThreadId);
83 sonRequestsRepository.save(sonRequest);
87 * Determines whether to trigger Oof or wait for notifications.
89 public Boolean triggerOrWait(Map<String, ArrayList<Integer>> collisionConfusionResult) {
90 // determine collision or confusion
92 Configuration configuration = Configuration.getInstance();
96 for (Map.Entry<String, ArrayList<Integer>> entry : collisionConfusionResult.entrySet()) {
98 ArrayList<Integer> arr;
99 arr = entry.getValue();
100 // check for 0 collision and confusion
101 if (!arr.isEmpty()) {
102 collisionSum = collisionSum + arr.get(0);
103 confusionSum = confusionSum + arr.get(1);
106 return ((collisionSum >= configuration.getMinCollision()) && (confusionSum >= configuration.getMinConfusion()));
111 * get policy notification string from oof result.
114 public String getNotificationString(String pnfName, String requestId, String payloadString, Long alarmStartTime,
117 String closedLoopControlName = "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459";
119 closedLoopControlName = (String) configPolicy.getConfig().get("PCI_MODCONFIG_POLICY_NAME");
120 } catch (NullPointerException e) {
121 log.error("Config policy not found, Using default");
124 PolicyNotification policyNotification = new PolicyNotification(closedLoopControlName, requestId, alarmStartTime,
127 policyNotification.setClosedLoopControlName(closedLoopControlName);
128 policyNotification.setPayload(payloadString);
129 ObjectMapper mapper = new ObjectMapper();
130 mapper.setSerializationInclusion(Include.NON_NULL);
132 String notification = "";
134 notification = mapper.writeValueAsString(policyNotification);
135 } catch (JsonProcessingException e1) {
136 log.debug("JSON processing exception: {}", e1);
142 * Sends Dmaap notification to Policy.
144 * @throws ConfigDbNotFoundException
145 * when config db is unreachable
147 public Boolean sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException {
149 if (log.isDebugEnabled()) {
150 log.debug(async.toString());
154 solutions = async.getSolutions();
155 if (!solutions.getPciSolutions().isEmpty()) {
156 Map<String, List<CellPciPair>> pnfs = pnfUtils.getPnfs(solutions);
157 for (Map.Entry<String, List<CellPciPair>> entry : pnfs.entrySet()) {
158 String pnfName = entry.getKey();
159 List<CellPciPair> cellPciPairs = entry.getValue();
160 ArrayList<Configurations> configurations = new ArrayList<>();
161 for (CellPciPair cellPciPair : cellPciPairs) {
162 String cellId = cellPciPair.getCellId();
163 int pci = cellPciPair.getPhysicalCellId();
164 Configurations configuration = new Configurations(new Data(new FapService(cellId,
165 new X0005b9Lte(pci, pnfName), new CellConfig(new Lte(new Ran(new Common(cellId), null))))),
167 configurations.add(configuration);
170 Payload payload = new Payload(configurations);
171 ObjectMapper mapper = new ObjectMapper();
172 mapper.setSerializationInclusion(Include.NON_NULL);
173 String payloadString = "";
175 payloadString = mapper.writeValueAsString(payload);
176 } catch (JsonProcessingException e) {
177 log.debug("JSON processing exception: {}", e);
180 String requestId = UUID.randomUUID().toString();
182 String notification = getNotificationString(pnfName, requestId, payloadString,
183 System.currentTimeMillis(), "ModifyConfig");
184 log.info("Policy Notification: {}", notification);
185 boolean status = policyDmaapClient.sendNotificationToPolicy(notification);
186 log.debug("sent Message: {}", status);
188 log.debug("Message sent to policy");
190 log.debug("Sending notification to policy failed");
192 policyDmaapClient.handlePolicyResponse(requestId);
193 log.info("handled policy response in ModifyConfig");
197 if (!solutions.getAnrSolutions().isEmpty()) {
198 Map<String, List<Map<String, List<String>>>> anrPnfs;
199 List<Configurations> configurations = new ArrayList<>();
200 anrPnfs = pnfUtils.getPnfsForAnrSolutions(solutions.getAnrSolutions());
201 for (Map.Entry<String, List<Map<String, List<String>>>> entry : anrPnfs.entrySet()) {
202 String pnfName = entry.getKey();
203 for (Map<String, List<String>> cellRemNeighborsPair : anrPnfs.get(pnfName)) {
204 for (Map.Entry<String, List<String>> entry1 : cellRemNeighborsPair.entrySet()) {
205 String cellId = entry1.getKey();
206 List<LteCell> lteCellList = new ArrayList<>();
207 for (String removeableNeighbor : entry1.getValue()) {
208 LteCell lteCell = new LteCell();
209 lteCell.setBlacklisted("true");
210 lteCell.setPlmnId(solutions.getNetworkId());
211 lteCell.setCid(removeableNeighbor);
212 int pci = SdnrRestClient.getPci(cellId);
213 lteCell.setPhyCellId(pci);
214 lteCell.setPnfName(pnfName);
215 lteCellList.add(lteCell);
217 Configurations configuration = new Configurations(new Data(new FapService(cellId, null,
218 new CellConfig(new Lte(new Ran(new Common(cellId), new NeighborListInUse(null,
219 lteCellList, String.valueOf(lteCellList.size()))))))),
221 configurations.add(configuration);
224 Payload payload = new Payload(configurations);
225 ObjectMapper mapper = new ObjectMapper();
226 mapper.setSerializationInclusion(Include.NON_NULL);
227 String payloadString = null;
229 payloadString = mapper.writeValueAsString(payload);
230 } catch (JsonProcessingException e) {
231 log.error("Exception in writing anrupdate string", e);
233 String requestId = UUID.randomUUID().toString();
234 String notification = getNotificationString(pnfName, requestId, payloadString,
235 System.currentTimeMillis(), "ModifyConfigANR");
236 log.info("Policy Notification: {}", notification);
237 Boolean result = policyDmaapClient.sendNotificationToPolicy(notification);
238 log.info("send notification to policy result {} ", result);
239 policyDmaapClient.handlePolicyResponse(requestId);
240 log.info("handled policy response in ModifyConfigANR");