package org.opendaylight.transportpce.dmaap.client.impl;
import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.opendaylight.transportpce.dmaap.client.listener.NbiNotificationsListenerImpl;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.transportpce.dmaap.client.listener.NbiNotificationsHandler;
+import org.opendaylight.yangtools.concepts.Registration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
}
private static final Logger LOG = LoggerFactory.getLogger(DmaapClientProvider.class);
- private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
+ private Registration listenerRegistration;
@Activate
public DmaapClientProvider(@Reference NotificationService notificationService, Configuration config) {
public DmaapClientProvider(NotificationService notificationService, String baseUrl,
String username, String password) {
- listenerRegistration = notificationService.registerNotificationListener(
- new NbiNotificationsListenerImpl(baseUrl, username, password));
+ final var listener = new NbiNotificationsHandler(baseUrl, username, password);
+ listenerRegistration = notificationService.registerCompositeListener(listener.getCompositeListener());
LOG.info("DmaapClientProvider Session Initiated");
}
*/
package org.opendaylight.transportpce.dmaap.client.listener;
+import java.util.Set;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import org.glassfish.jersey.client.proxy.WebResourceFactory;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.logging.LoggingFeature;
+import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
import org.opendaylight.transportpce.dmaap.client.resource.EventsApi;
import org.opendaylight.transportpce.dmaap.client.resource.config.JsonConfigurator;
import org.opendaylight.transportpce.dmaap.client.resource.model.CreatedEvent;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationAlarmService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishTapiNotificationService;
+import org.opendaylight.yangtools.concepts.Registration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
- private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
+public class NbiNotificationsHandler {
+ private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsHandler.class);
private String topic = "unauthenticated.TPCE";
private EventsApi api;
+ private Registration reg;
- public NbiNotificationsListenerImpl(String baseUrl, String username, String password) {
+ public NbiNotificationsHandler(String baseUrl, String username, String password) {
LOG.info("Dmaap server {} for user {}", baseUrl, username);
Client client = ClientBuilder.newClient();
if (username != null && username.isBlank() && password != null && !password.isBlank()) {
}
- @Override
- public void onPublishNotificationProcessService(PublishNotificationProcessService notification) {
+ 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) {
try {
CreatedEvent response = api.sendEvent(topic, notification);
LOG.info("Response received {}", response);
}
- @Override
- public void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) {
+ private void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) {
}
- @Override
- public void onPublishTapiNotificationService(PublishTapiNotificationService notification) {
+ private void onPublishTapiNotificationService(PublishTapiNotificationService notification) {
}
}
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.opendaylight.transportpce.dmaap.client.listener.NbiNotificationsListenerImpl;
public class DmaapClientProviderTest {
void testInitRegisterNbiNotificationsToRpcRegistry() {
new DmaapClientProvider(notificationService, "http://localhost", "username", "password");
verify(notificationService, times(1))
- .registerNotificationListener(Mockito.any(NbiNotificationsListenerImpl.class));
+ .registerCompositeListener(Mockito.any(NotificationService.CompositeListener.class));
}
}
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirectionKey;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessServiceBuilder;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.process.service.ServiceAEndBuilder;
import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.LoggerFactory;
-public class NbiNotificationsListenerImplTest extends JerseyTest {
+public class NbiNotificationsHandlerTest extends JerseyTest {
@Override
protected Application configure() {
enable(TestProperties.LOG_TRAFFIC);
@Test
void onPublishNotificationServiceTest() {
- Logger logger = (Logger) LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
+ Logger logger = (Logger) LoggerFactory.getLogger(NbiNotificationsHandler.class);
ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
listAppender.start();
logger.addAppender(listAppender);
- NbiNotificationsListener listener = new NbiNotificationsListenerImpl("http://localhost:9998", null, null);
+ NbiNotificationsHandler listener = new NbiNotificationsHandler("http://localhost:9998", null, null);
PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
.setCommonId("CommonId")
.setMessage("Service implemented")
import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
import org.opendaylight.transportpce.common.converter.JsonStringConverter;
import org.opendaylight.transportpce.common.network.NetworkTransactionService;
-import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsListenerImpl;
+import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsHandler;
import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
private static Map<String, Publisher<NotificationProcessService>> publishersServiceMap = new HashMap<>();
private static Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap = new HashMap<>();
- private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
+ private Registration listenerRegistration;
private Registration rpcRegistration;
@Activate
NbiNotificationsImpl nbiImpl = new NbiNotificationsImpl(converterService, converterAlarmService,
converterTapiService, subscriberServer, networkTransactionService, topicManager);
rpcRegistration = rpcProviderService.registerRpcImplementations(nbiImpl.registerRPCs());
- NbiNotificationsListenerImpl nbiNotificationsListener = new NbiNotificationsListenerImpl(
- topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap());
- listenerRegistration = notificationService.registerNotificationListener(nbiNotificationsListener);
- topicManager.setNbiNotificationsListener(nbiNotificationsListener);
+ NbiNotificationsHandler notificationsListener = new NbiNotificationsHandler(
+ topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap());
+ listenerRegistration = notificationService.registerCompositeListener(
+ notificationsListener.getCompositeListener());
+ topicManager.setNbiNotificationsListener(notificationsListener);
LOG.info("NbiNotificationsProvider Session Initiated");
}
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.rev211013.NbiNotificationsListener;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmServiceBuilder;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationAlarmService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishTapiNotificationService;
+import org.opendaylight.yangtools.concepts.Registration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
- private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
+public class NbiNotificationsHandler {
+ private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsHandler.class);
private Map<String, Publisher<NotificationProcessService>> publishersServiceMap;
private Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap;
private Map<String, Publisher<NotificationTapiService>> tapiPublisherMap;
+ private Registration reg;
- public NbiNotificationsListenerImpl(Map<String, Publisher<NotificationProcessService>> publishersServiceMap,
+ public NbiNotificationsHandler(Map<String, Publisher<NotificationProcessService>> publishersServiceMap,
Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap,
Map<String, Publisher<NotificationTapiService>> tapiPublisherMap) {
this.publishersServiceMap = publishersServiceMap;
this.tapiPublisherMap = tapiPublisherMap;
}
- @Override
- public void onPublishNotificationProcessService(PublishNotificationProcessService notification) {
+ 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)) {
.build(), notification.getConnectionType().getName());
}
- @Override
- public void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) {
+ void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) {
LOG.info("Receiving request for publishing notification alarm service");
String publisherName = notification.getPublisherName();
if (!publishersAlarmMap.containsKey(publisherName)) {
.build(), "alarm" + notification.getConnectionType().getName());
}
- @Override
- public void onPublishTapiNotificationService(PublishTapiNotificationService notification) {
+ void onPublishTapiNotificationService(PublishTapiNotificationService notification) {
LOG.info("Receiving request for publishing TAPI notification");
String topic = notification.getTopic();
if (!tapiPublisherMap.containsKey(topic)) {
import java.util.HashMap;
import java.util.Map;
import org.opendaylight.transportpce.common.converter.JsonStringConverter;
-import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsListenerImpl;
+import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsHandler;
import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceSerializer;
import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceSerializer;
private Map<String, Publisher<NotificationTapiService>> tapiPublisherMap = new HashMap<>();
private String publisherServer;
private JsonStringConverter<NotificationTapiService> tapiConverter;
- private NbiNotificationsListenerImpl nbiNotificationsListener;
+ private NbiNotificationsHandler nbiNotificationsListener;
private Map<String, Publisher<NotificationAlarmService>> alarmPublisherMap = new HashMap<>();
private Map<String, Publisher<NotificationProcessService>> processPublisherMap = new HashMap<>();
private JsonStringConverter<NotificationProcessService> processConverter;
return instance;
}
- public void setNbiNotificationsListener(NbiNotificationsListenerImpl nbiNotificationsListener) {
+ public void setNbiNotificationsListener(NbiNotificationsHandler nbiNotificationsListener) {
this.nbiNotificationsListener = nbiNotificationsListener;
}
import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
import org.opendaylight.transportpce.common.network.NetworkTransactionService;
-import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsListenerImpl;
import org.opendaylight.transportpce.test.AbstractTest;
public class NbiNotificationsProviderTest extends AbstractTest {
networkTransactionService);
verify(rpcProviderRegistry, times(1)).registerRpcImplementations(any());
verify(notificationService, times(1))
- .registerNotificationListener(any(NbiNotificationsListenerImpl.class));
+ .registerCompositeListener(any(NotificationService.CompositeListener.class));
}
}
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishTapiNotificationService;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishTapiNotificationServiceBuilder;
-public class NbiNotificationsListenerImplTest extends AbstractTest {
+public class NbiNotificationsHandlerTest extends AbstractTest {
@Mock
private Publisher<NotificationProcessService> publisherService;
@Mock
@Test
void onPublishNotificationServiceTest() {
- NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
+ NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
.setPublisherName("test")
@Test
void onPublishNotificationServiceWrongPublisherTest() {
- NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
+ NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
.setPublisherName("wrongPublisher")
@Test
void onPublishNotificationAlarmServiceTest() {
- NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
+ NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder()
.setPublisherName("test")
@Test
void onPublishNotificationAlarmServiceWrongPublisherTest() {
- NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
+ NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder()
.setPublisherName("wrongPublisher")
@Test
void onPublishTapiNotificationServiceTest() throws ExecutionException, InterruptedException {
- NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
+ NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
PublishTapiNotificationService notification
@Test
void onPublishTapiNotificationServiceTestWrongPublisherTest() {
- NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
+ NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
PublishTapiNotificationService notification
= new PublishTapiNotificationServiceBuilder(NotificationServiceDataUtils.buildReceivedTapiAlarmEvent())
@Test
void getTapiPublisherFromTopicTest() {
- NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
+ NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
assertNull(listener.getTapiPublisherFromTopic("toto"));
assertEquals(publisherTapiService, listener.getTapiPublisherFromTopic("test"));