1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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.dmaap;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import java.io.IOException;
26 import java.util.List;
28 import org.onap.dcaegen2.services.sonhms.Configuration;
29 import org.onap.dcaegen2.services.sonhms.dao.FixedPciCellsRepository;
30 import org.onap.dcaegen2.services.sonhms.dao.PciUpdateRepository;
31 import org.onap.dcaegen2.services.sonhms.entity.FixedPciCells;
32 import org.onap.dcaegen2.services.sonhms.model.Configurations;
33 import org.onap.dcaegen2.services.sonhms.model.Payload;
34 import org.onap.dcaegen2.services.sonhms.model.PolicyNotification;
35 import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
36 import org.slf4j.Logger;
38 public class PolicyNotificationCallback extends NotificationCallback {
40 private static final Logger log = org.slf4j.LoggerFactory.getLogger(PolicyNotificationCallback.class);
43 public void activateCallBack(String msg) {
44 handlePolicyNotification(msg);
47 private void handlePolicyNotification(String msg) {
48 log.info("Message received from policy: " +msg);
49 PciUpdateRepository pciUpdateRepository = BeanUtil.getBean(PciUpdateRepository.class);
50 Configuration configuration = Configuration.getInstance();
52 ObjectMapper mapper = new ObjectMapper();
53 PolicyNotification policyResponse = mapper.readValue(msg, PolicyNotification.class);
54 String payload = policyResponse.getPayload();
55 Payload payloadObject = mapper.readValue(payload, Payload.class);
56 List<Configurations> configurationList = payloadObject.getConfiguration();
57 for (Configurations config : configurationList) {
58 int status = config.getStatus().getCode();
60 String cellId = config.getData().getFapservice().getAlias();
62 int negativeAckCount = pciUpdateRepository.getNegativeAckCountforCellId(cellId);
63 if (negativeAckCount > configuration.getPolicyNegativeAckThreshold()) {
64 long fixedPci = pciUpdateRepository.getOldPciforCellId(cellId);
66 FixedPciCellsRepository fixedPciCellsRepository = BeanUtil
67 .getBean(FixedPciCellsRepository.class);
68 FixedPciCells fixedPciCells = new FixedPciCells();
69 fixedPciCells.setCellId(cellId);
70 fixedPciCells.setFixedPci(fixedPci);
71 fixedPciCellsRepository.save(fixedPciCells);
72 pciUpdateRepository.deleterecordforCellId(cellId);
75 pciUpdateRepository.increaseNegativeAckCountforCellId(++negativeAckCount, cellId);
79 String cellId = config.getData().getFapservice().getAlias();
80 pciUpdateRepository.deleterecordforCellId(cellId);
83 String statusToString = Integer.toString(status);
84 log.info("Handled response from policy, status code {}", statusToString);
86 } catch (Exception e) {
87 log.info("caught exception while fetching policy response:" + e);