/* * Copyright © 2020 Orange, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.transportpce.nbinotifications.listener; import java.util.Map; import java.util.Set; import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener; import org.opendaylight.transportpce.nbinotifications.producer.Publisher; import org.opendaylight.transportpce.nbinotifications.utils.NbiNotificationsUtils; import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationAlarmService; import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationAlarmServiceBuilder; import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationProcessService; import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationProcessServiceBuilder; import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationTapiService; import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationTapiServiceBuilder; import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.PublishNotificationAlarmService; import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.PublishNotificationProcessService; import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.PublishTapiNotificationService; import org.opendaylight.yangtools.concepts.Registration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class NbiNotificationsHandler { private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsHandler.class); private Map> publishersServiceMap; private Map> publishersAlarmMap; private Map> tapiPublisherMap; private Registration reg; public NbiNotificationsHandler(Map> publishersServiceMap, Map> publishersAlarmMap, Map> tapiPublisherMap) { this.publishersServiceMap = publishersServiceMap; this.publishersAlarmMap = publishersAlarmMap; this.tapiPublisherMap = tapiPublisherMap; } public CompositeListener getCompositeListener() { return new CompositeListener(Set.of( new CompositeListener.Component<>( PublishNotificationProcessService.class, this::onPublishNotificationProcessService), new CompositeListener.Component<>( PublishNotificationAlarmService.class, this::onPublishNotificationAlarmService), new CompositeListener.Component<>( PublishTapiNotificationService.class, this::onPublishTapiNotificationService) )); } void onPublishNotificationProcessService(PublishNotificationProcessService notification) { LOG.info("Receiving request for publishing notification service"); String publisherName = notification.getPublisherName(); if (!publishersServiceMap.containsKey(publisherName)) { LOG.error("Unknown publisher {}", publisherName); return; } Publisher publisher = publishersServiceMap.get(publisherName); NotificationProcessServiceBuilder notificationProcessServiceBuilder = new NotificationProcessServiceBuilder() .setCommonId(notification.getCommonId()) .setConnectionType(notification.getConnectionType()) .setMessage(notification.getMessage()) .setOperationalState(notification.getOperationalState()) .setResponseFailed(notification.getResponseFailed()) .setServiceAEnd(notification.getServiceAEnd()) .setServiceName(notification.getServiceName()) .setServiceZEnd(notification.getServiceZEnd()); if (notification.getIsTempService()) { // A-to-Z and Z-to-A containers are only needed for temp-service-create notification publisher.sendEvent(notificationProcessServiceBuilder .setAToZ(notification.getAToZ()) .setZToA(notification.getZToA()) .build(), notification.getConnectionType().getName()); } else { publisher.sendEvent(notificationProcessServiceBuilder .build(), notification.getConnectionType().getName()); } } void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) { LOG.info("Receiving request for publishing notification alarm service"); String publisherName = notification.getPublisherName(); if (!publishersAlarmMap.containsKey(publisherName)) { LOG.error("Unknown topic {}", publisherName); return; } Publisher publisherAlarm = publishersAlarmMap.get(publisherName); publisherAlarm.sendEvent(new NotificationAlarmServiceBuilder() .setConnectionType(notification.getConnectionType()) .setMessage(notification.getMessage()) .setOperationalState(notification.getOperationalState()) .setServiceName(notification.getServiceName()) .build(), "alarm" + notification.getConnectionType().getName()); } void onPublishTapiNotificationService(PublishTapiNotificationService notification) { LOG.info("Receiving request for publishing TAPI notification"); String topic = notification.getTopic(); if (!tapiPublisherMap.containsKey(topic)) { LOG.error("Unknown topic {}", topic); return; } Publisher publisher = tapiPublisherMap.get(topic); publisher.sendEvent(new NotificationTapiServiceBuilder( NbiNotificationsUtils.transformTapiNotification(notification)).build(), topic); } public void setPublishersServiceMap(Map> publishersServiceMap) { this.publishersServiceMap = publishersServiceMap; } public void setPublishersAlarmMap(Map> publishersAlarmMap) { this.publishersAlarmMap = publishersAlarmMap; } public void setTapiPublishersMap(Map> tapiPublishersMap) { this.tapiPublisherMap = tapiPublishersMap; } public Publisher getTapiPublisherFromTopic(String topic) { return this.tapiPublisherMap.get(topic); } }