1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2021 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;
24 import fj.data.Either;
26 import java.sql.Timestamp;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
31 import java.util.concurrent.BlockingQueue;
32 import java.util.concurrent.Executors;
33 import java.util.concurrent.LinkedBlockingQueue;
35 import org.onap.dcaegen2.services.sonhms.model.FapServiceList;
36 import org.onap.dcaegen2.services.sonhms.model.Notification;
37 import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils;
38 import org.onap.dcaegen2.services.sonhms.utils.ThreadUtils;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 public class MainThread implements Runnable {
44 private static Logger log = LoggerFactory.getLogger(MainThread.class);
46 private NewSdnrNotification newNotification;
48 private NewFmNotification newFmNotification;
50 private BlockingQueue<List<String>> childStatusQueue;
52 private DmaapNotificationsComponent dmaapNotificationsComponent;
54 private FaultNotificationComponent faultNotificationComponent;
56 private EventHandler eventHandler;
58 private Map<String, FaultEvent> bufferedFmNotificationCells;
60 private List<String> sdnrNotificationCells;
62 private Boolean isTimer;
64 private Timestamp startTimer;
66 List<FaultEvent> fmNotificationToBuffer;
69 * parameterized constructor.
71 public MainThread(NewSdnrNotification newNotification, NewFmNotification newFmNotification) {
73 this.newFmNotification = newFmNotification;
74 this.newNotification = newNotification;
75 childStatusQueue = new LinkedBlockingQueue<>();
76 dmaapNotificationsComponent = new DmaapNotificationsComponent();
77 faultNotificationComponent = new FaultNotificationComponent();
78 sdnrNotificationCells = new ArrayList<>();
79 fmNotificationToBuffer = new ArrayList<>();
80 bufferedFmNotificationCells = new HashMap<>();
81 eventHandler = new EventHandler(childStatusQueue,
82 Executors.newFixedThreadPool(Configuration.getInstance().getMaximumClusters()), new HashMap<>(),
83 new ClusterUtils(), new ThreadUtils());
85 startTimer = new Timestamp(System.currentTimeMillis());
91 log.info("Starting Main Thread");
93 // Check for Notifications from Dmaap and Child thread
98 Timestamp currentTime = new Timestamp(System.currentTimeMillis());
100 Long difference = currentTime.getTime() - startTimer.getTime();
101 if (difference > 5000) {
102 log.info("FM handling difference > 5000");
104 for (String sdnrCell : sdnrNotificationCells) {
105 bufferedFmNotificationCells.remove(sdnrCell);
108 log.info("FM bufferedFMNotificationCells {}", bufferedFmNotificationCells.values());
109 List<FaultEvent> fmNotificationsToHandle = new ArrayList<>(bufferedFmNotificationCells.values());
110 Boolean result = eventHandler.handleFaultNotification(fmNotificationsToHandle);
111 bufferedFmNotificationCells = new HashMap<>();
113 log.info("FM notification handling {}", result);
118 if (!childStatusQueue.isEmpty()) {
119 List<String> childState = childStatusQueue.poll();
120 if (childState != null) {
121 eventHandler.handleChildStatusUpdate(childState);
125 if (newNotification.getNewNotif()) {
126 Either<Notification, Integer> notification = dmaapNotificationsComponent.getSdnrNotifications();
127 if (notification.isRight()) {
128 if (notification.right().value() == 400) {
129 log.error("Error parsing the notification from SDNR");
130 } else if (notification.right().value() == 404) {
131 newNotification.setNewNotif(false);
133 } else if (notification.isLeft()) {
134 List<FapServiceList> fapServiceLists = (notification.left().value()).getPayload()
135 .getRadioAccess().getFapServiceList();
136 for (FapServiceList fapServiceList : fapServiceLists) {
137 sdnrNotificationCells.add(fapServiceList.getAlias());
141 Boolean result = eventHandler.handleSdnrNotification(notification.left().value());
142 log.debug("SDNR notification handling {}", result);
147 if (newFmNotification.getNewNotif()) {
148 log.info("newFmNotification has come");
150 String faultCellId = "";
151 Either<List<FaultEvent>, Integer> fmNotifications = faultNotificationComponent
152 .getFaultNotifications();
153 if (fmNotifications.isRight()) {
154 if (fmNotifications.right().value() == 400) {
155 log.info("Error parsing notifications");
156 } else if (fmNotifications.right().value() == 404) {
157 newFmNotification.setNewNotif(false);
160 for (FaultEvent fmNotification : fmNotifications.left().value()) {
161 if (fmNotification.getEvent().getFaultFields().getSpecificProblem()
162 .equals("Optimised PCI")) {
163 log.info("PCI problem cleared for :" + fmNotification);
164 } else if ((fmNotification.getEvent().getFaultFields().getAlarmCondition()
165 .equalsIgnoreCase("RanPciCollisionConfusionOccurred")))
167 faultCellId = fmNotification.getEvent().getCommonEventHeader().getSourceName();
168 bufferedFmNotificationCells.put(faultCellId, fmNotification);
169 log.info("Buffered FM cell {}", faultCellId);
170 log.info("fmNotification{}", fmNotification);
172 log.info("Error resolving faultNotification for :" + fmNotification);
176 if (!(bufferedFmNotificationCells.isEmpty())) {
177 log.info("bufferedFMNotificationCells before staring timer {}",
178 bufferedFmNotificationCells.keySet());
180 for (String sdnrCell : sdnrNotificationCells) {
181 bufferedFmNotificationCells.remove(sdnrCell);
184 startTimer = new Timestamp(System.currentTimeMillis());
186 log.info("Buffered FM cell {}", bufferedFmNotificationCells.keySet());
192 } catch (Exception e) {
193 log.error("Exception in main Thread", e);