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;
24 import fj.data.Either;
26 import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient;
27 import org.onap.dcaegen2.services.sonhms.model.PMNotification;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class PmThread implements Runnable {
33 private static Logger log = LoggerFactory.getLogger(PmThread.class);
35 private NewPmNotification newPmNotification;
38 private DmaapNotificationsComponent dmaapNotificationsComponent;
40 private PmNotificationHandler pmNotificationHandler;
43 * parameterized constructor.
45 public PmThread(NewPmNotification newPmNotification) {
47 this.newPmNotification = newPmNotification;
48 dmaapNotificationsComponent = new DmaapNotificationsComponent();
49 pmNotificationHandler = new PmNotificationHandler(new PolicyDmaapClient());
54 log.info("PM thread starting ...");
55 // check for PM notifications
60 if (newPmNotification.getNewNotif()) {
61 log.info("New PM notification from Dmaap");
62 Either<PMNotification, Integer> pmNotification = dmaapNotificationsComponent.getPmNotifications();
63 if (pmNotification.isRight()) {
64 if (pmNotification.right().value() == 400) {
65 log.error("error parsing pm notifications");
66 } else if (pmNotification.right().value() == 404) {
67 log.info("Queue is empty");
68 newPmNotification.setNewNotif(false);
70 } else if (pmNotification.isLeft()) {
71 Configuration configuration = Configuration.getInstance();
72 Boolean result = pmNotificationHandler.handlePmNotifications(pmNotification.left().value(),
73 configuration.getBadThreshold());
74 log.info("pm notification handler result {}", result);
78 } catch (Exception e) {
79 log.error("Exception in PM Thread ", e);