Remove nobinotifications-blueprint.xml file 54/104954/6
authorGilles Thouenon <gilles.thouenon@orange.com>
Thu, 16 Mar 2023 14:22:38 +0000 (15:22 +0100)
committerGilles Thouenon <gilles.thouenon@orange.com>
Fri, 31 Mar 2023 14:04:13 +0000 (16:04 +0200)
- convert NbiNotificationsProvider into a Component
- adapt NbiNotificationsProviderTest accordingly

JIRA: TRNSPRTPCE-736
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: I298b7d1bf6f18f06a0bb3687f4df2363311629cf
(cherry picked from commit 0e5a378adbacbe904865e220a01fded2f597ff07)

lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
nbinotifications/pom.xml
nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProvider.java
nbinotifications/src/main/resources/OSGI-INF/blueprint/nobinotifications-blueprint.xml [deleted file]
nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProviderTest.java

index 19b5523a52bcd930cc2a47a40415dcd6e633694d..8eb97e47f498e416f48af8e48a883ceca1e5594c 100644 (file)
@@ -9,10 +9,6 @@ package io.lighty.controllers.tpce.module;
 
 import io.lighty.core.controller.api.AbstractLightyModule;
 import io.lighty.core.controller.api.LightyServices;
-
-import java.util.Arrays;
-import java.util.List;
-
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
@@ -108,12 +104,6 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
     private TapiProvider tapiProvider;
     // nbi-notifications beans
     private NbiNotificationsProvider nbiNotificationsProvider;
-    /**
-     * List of publisher topics.
-     */
-    private final List<String> publisherServiceList = Arrays.asList("PceListener", "ServiceHandlerOperations",
-            "ServiceHandler", "RendererListener");
-    private final List<String> publisherAlarmList = Arrays.asList("ServiceListener");
 
     public TransportPCEImpl(LightyServices lightyServices, boolean activateNbiNotification, boolean activateTapi,
                             String olmtimer1, String olmtimer2) {
@@ -207,7 +197,7 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
         if (activateNbiNotification) {
             LOG.info("Creating nbi-notifications beans ...");
             nbiNotificationsProvider = new NbiNotificationsProvider(
-                    publisherServiceList, publisherAlarmList, null, null, lightyServices.getRpcProviderService(),
+                    null, null, lightyServices.getRpcProviderService(),
                     lightyServices.getNotificationService(), lightyServices.getAdapterContext().currentSerializer(),
                     networkTransaction);
         }
@@ -220,7 +210,6 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
         }
         if (nbiNotificationsProvider != null) {
             LOG.info("Initializing nbi-notifications provider ...");
-            nbiNotificationsProvider.init();
         }
         LOG.info("Init done.");
         return true;
index 7c16ea13f094d88994112367609873e278921129..344e249910f8203375d73e2b00714e16db11446b 100644 (file)
       <artifactId>kafka-clients</artifactId>
       <version>${kafka.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.metatype.annotations</artifactId>
+    </dependency>
 
     <!-- Testing Dependencies -->
     <dependency>
index 863d689a3af8db038276ca6435902caf1f8b2c2d..ac4c6ef8e61660e4d9b4e32a496e9185fa2c98dc 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.transportpce.nbinotifications.impl;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -26,72 +27,84 @@ import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapi
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationService;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Component(configurationPid = "org.opendaylight.transportpce.nbinotifications")
 public class NbiNotificationsProvider {
 
+    @ObjectClassDefinition
+    public @interface Configuration {
+        @AttributeDefinition
+        String suscriberServer() default "";
+        @AttributeDefinition
+        String publisherServer() default "";
+    }
+
     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 final RpcProviderService rpcService;
-    private final NotificationService notificationService;
-    private final JsonStringConverter<NotificationProcessService> converterService;
-    private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
-    private final JsonStringConverter<NotificationTapiService> converterTapiService;
-    private final String subscriberServer;
-    private ObjectRegistration<NbiNotificationsService> rpcRegistration;
     private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
-    private TopicManager topicManager = TopicManager.getInstance();
-    private final NetworkTransactionService networkTransactionService;
+    private List<ObjectRegistration<NbiNotificationsImpl>> rpcRegistrations = new ArrayList<>();
 
+    @Activate
+    public NbiNotificationsProvider(@Reference RpcProviderService rpcProviderService,
+            @Reference NotificationService notificationService,
+            @Reference BindingDOMCodecServices bindingDOMCodecServices,
+            @Reference NetworkTransactionService networkTransactionService,
+            final Configuration configuration) {
+        this(configuration.suscriberServer(), configuration.publisherServer(), rpcProviderService, notificationService,
+                bindingDOMCodecServices, networkTransactionService);
+    }
 
-    public NbiNotificationsProvider(List<String> publishersService, List<String> publishersAlarm,
-                                    String subscriberServer, String publisherServer,
-                                    RpcProviderService rpcProviderService, NotificationService notificationService,
-                                    BindingDOMCodecServices bindingDOMCodecServices,
-                                    NetworkTransactionService networkTransactionService) {
-        this.rpcService = rpcProviderService;
-        this.notificationService = notificationService;
-        this.topicManager.setPublisherServer(publisherServer);
-        converterService =  new JsonStringConverter<>(bindingDOMCodecServices);
-        this.topicManager.setProcessConverter(converterService);
-        for (String publisherService: publishersService) {
+    public NbiNotificationsProvider(String subscriberServer, String publisherServer,
+            RpcProviderService rpcProviderService, NotificationService notificationService,
+            BindingDOMCodecServices bindingDOMCodecServices, NetworkTransactionService networkTransactionService) {
+        List<String> publishersServiceList = List.of("PceListener", "ServiceHandlerOperations", "ServiceHandler",
+                "RendererListener");
+        TopicManager topicManager = TopicManager.getInstance();
+        topicManager.setPublisherServer(publisherServer);
+        JsonStringConverter<NotificationProcessService> converterService =
+            new JsonStringConverter<>(bindingDOMCodecServices);
+        topicManager.setProcessConverter(converterService);
+        for (String publisherService: publishersServiceList) {
             LOG.info("Creating publisher for the following class {}", publisherService);
-            this.topicManager.addProcessTopic(publisherService);
+            topicManager.addProcessTopic(publisherService);
         }
-        converterAlarmService = new JsonStringConverter<>(bindingDOMCodecServices);
-        this.topicManager.setAlarmConverter(converterAlarmService);
-        for (String publisherAlarm: publishersAlarm) {
+        JsonStringConverter<NotificationAlarmService> converterAlarmService =
+                new JsonStringConverter<>(bindingDOMCodecServices);
+        topicManager.setAlarmConverter(converterAlarmService);
+        List<String> publishersAlarmList = List.of("ServiceListener");
+        for (String publisherAlarm: publishersAlarmList) {
             LOG.info("Creating publisher for the following class {}", publisherAlarm);
-            this.topicManager.addAlarmTopic(publisherAlarm);
+            topicManager.addAlarmTopic(publisherAlarm);
         }
-        this.subscriberServer = subscriberServer;
-        converterTapiService = new JsonStringConverter<>(bindingDOMCodecServices);
+        JsonStringConverter<NotificationTapiService> converterTapiService =
+                new JsonStringConverter<>(bindingDOMCodecServices);
         LOG.info("baozhi tapi converter: {}", converterTapiService);
-        this.topicManager.setTapiConverter(converterTapiService);
-        this.networkTransactionService = networkTransactionService;
-    }
+        topicManager.setTapiConverter(converterTapiService);
 
-    /**
-     * Method called when the blueprint container is created.
-     */
-    public void init() {
-        LOG.info("NbiNotificationsProvider Session Initiated");
         NbiNotificationsImpl nbiImpl = new NbiNotificationsImpl(converterService, converterAlarmService,
-            converterTapiService, subscriberServer, this.networkTransactionService, this.topicManager);
-        rpcRegistration = rpcService.registerRpcImplementation(NbiNotificationsService.class, nbiImpl);
-        rpcService.registerRpcImplementation(TapiNotificationService.class, nbiImpl);
-        NbiNotificationsListenerImpl nbiNotificationsListener =
-                new NbiNotificationsListenerImpl(this.topicManager.getProcessTopicMap(),
-                        this.topicManager.getAlarmTopicMap(), this.topicManager.getTapiTopicMap());
+            converterTapiService, subscriberServer, networkTransactionService, topicManager);
+        rpcRegistrations.add(rpcProviderService.registerRpcImplementation(NbiNotificationsService.class, nbiImpl));
+        rpcRegistrations.add(rpcProviderService.registerRpcImplementation(TapiNotificationService.class, nbiImpl));
+        NbiNotificationsListenerImpl nbiNotificationsListener = new NbiNotificationsListenerImpl(
+                topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap());
         listenerRegistration = notificationService.registerNotificationListener(nbiNotificationsListener);
-        this.topicManager.setNbiNotificationsListener(nbiNotificationsListener);
+        topicManager.setNbiNotificationsListener(nbiNotificationsListener);
+        LOG.info("NbiNotificationsProvider Session Initiated");
     }
 
     /**
      * Method called when the blueprint container is destroyed.
      */
+    @Deactivate
     public void close() {
         for (Publisher<NotificationProcessService> publisher : publishersServiceMap.values()) {
             publisher.close();
@@ -99,9 +112,8 @@ public class NbiNotificationsProvider {
         for (Publisher<NotificationAlarmService> publisherAlarm : publishersAlarmMap.values()) {
             publisherAlarm.close();
         }
-        rpcRegistration.close();
+        rpcRegistrations.forEach(reg -> reg.close());
         listenerRegistration.close();
         LOG.info("NbiNotificationsProvider Closed");
     }
-
 }
diff --git a/nbinotifications/src/main/resources/OSGI-INF/blueprint/nobinotifications-blueprint.xml b/nbinotifications/src/main/resources/OSGI-INF/blueprint/nobinotifications-blueprint.xml
deleted file mode 100644 (file)
index 5b0176c..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!-- Copyright © 2020 Orange 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 -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
-    <cm:property-placeholder persistent-id="org.opendaylight.transportpce.nbinotifications" update-strategy="reload">
-        <cm:default-properties>
-            <cm:property name="suscriber.server" value="" />
-            <cm:property name="publisher.server" value="" />
-        </cm:default-properties>
-    </cm:property-placeholder>
-    <reference id="rpcService" interface="org.opendaylight.mdsal.binding.api.RpcProviderService"/>
-    <reference id="notificationService" interface="org.opendaylight.mdsal.binding.api.NotificationService"/>
-    <reference id="bindingDOMCodecServices" interface="org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices" />
-    <reference id="networkTransactionImpl"
-               interface="org.opendaylight.transportpce.common.network.NetworkTransactionService" />
-    <bean id="provider"
-        class="org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsProvider"
-        init-method="init" destroy-method="close">
-        <argument>
-            <list value-type="java.lang.String">
-                <value>PceListener</value>
-                <value>ServiceHandlerOperations</value>
-                <value>ServiceHandler</value>
-                <value>RendererListener</value>
-            </list>
-        </argument>
-        <argument>
-            <list value-type="java.lang.String">
-                <value>ServiceListener</value>
-            </list>
-        </argument>
-        <argument value="${suscriber.server}"/>
-        <argument value="${publisher.server}"/>
-        <argument ref="rpcService" />
-        <argument ref="notificationService" />
-        <argument ref="bindingDOMCodecServices" />
-        <argument ref="networkTransactionImpl" />
-    </bean>
-</blueprint>
index bbf2e62e063d8ebbcda1996ead49050c8853a471..68a93c3289bf0fda9a19a061db25a9e6d06a9ebe 100644 (file)
@@ -11,7 +11,6 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-import java.util.Arrays;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.mockito.Mock;
@@ -28,7 +27,6 @@ public class NbiNotificationsProviderTest  extends AbstractTest {
 
     @Mock
     RpcProviderService rpcProviderRegistry;
-
     @Mock
     private NotificationService notificationService;
 
@@ -40,11 +38,9 @@ public class NbiNotificationsProviderTest  extends AbstractTest {
     @Test
     void initTest() {
         networkTransactionService = new NetworkTransactionImpl(getDataBroker());
-        NbiNotificationsProvider provider = new NbiNotificationsProvider(
-                Arrays.asList("topic1", "topic2"), Arrays.asList("topic1", "topic2"), "localhost:8080",
-                "localhost:8080", rpcProviderRegistry, notificationService,
-                getDataStoreContextUtil().getBindingDOMCodecServices(), networkTransactionService);
-        provider.init();
+        NbiNotificationsProvider provider = new NbiNotificationsProvider("localhost:8080", "localhost:8080",
+                rpcProviderRegistry, notificationService, getDataStoreContextUtil().getBindingDOMCodecServices(),
+                networkTransactionService);
         verify(rpcProviderRegistry, times(2))
                 .registerRpcImplementation(any(), any(NbiNotificationsImpl.class));
         verify(notificationService, times(1))