Remove dmaap-blueprint.xml file 55/104955/7
authorGilles Thouenon <gilles.thouenon@orange.com>
Thu, 16 Mar 2023 14:44:31 +0000 (15:44 +0100)
committerGilles Thouenon <gilles.thouenon@orange.com>
Fri, 31 Mar 2023 14:04:20 +0000 (16:04 +0200)
Convert DmaapClientProvider into a Component.

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

dmaap-client/pom.xml
dmaap-client/src/main/java/org/opendaylight/transportpce/dmaap/client/impl/DmaapClientProvider.java
dmaap-client/src/main/resources/OSGI-INF/blueprint/dmaap-blueprint.xml [deleted file]
dmaap-client/src/test/java/org/opendaylight/transportpce/dmaap/client/impl/DmaapClientProviderTest.java

index e4e2e7bfd44698af82ad99ff6dd045b1e6e59dcd..7834390a5d3842d884c0c8935e1584a71f1f1464 100644 (file)
       <groupId>jakarta.ws.rs</groupId>
       <artifactId>jakarta.ws.rs-api</artifactId>
     </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 482a46b782716ca3c826f92349ba48f43e6972bb..51742f2c82eeac1acbc93bbf947ec819cb828fd0 100644 (file)
@@ -11,32 +11,40 @@ 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.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+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.dmaap")
 public class DmaapClientProvider {
+
+    @ObjectClassDefinition
+    public @interface Configuration {
+        @AttributeDefinition
+        String dmaapBaseUrl() default "http://localhost:8080";
+        @AttributeDefinition
+        String dmaapUsername() default "";
+        @AttributeDefinition
+        String dmaapPassword() default "";
+    }
+
     private static final Logger LOG = LoggerFactory.getLogger(DmaapClientProvider.class);
     private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
-    private NotificationService notificationService;
-    private final String baseUrl;
-    private final String username;
-    private final String password;
 
-    public DmaapClientProvider(NotificationService notificationService, String baseUrl,
-            String username, String password) {
-        this.notificationService = notificationService;
-        this.baseUrl = baseUrl;
-        this.username = username;
-        this.password = password;
+    @Activate
+    public DmaapClientProvider(@Reference NotificationService notificationService, Configuration config) {
+        this(notificationService, config.dmaapBaseUrl(), config.dmaapUsername(), config.dmaapPassword());
     }
 
-    /**
-     * Method called when the blueprint container is created.
-     */
-    public void init() {
-        LOG.info("DmaapClientProvider Session Initiated");
+    public DmaapClientProvider(NotificationService notificationService, String baseUrl,
+            String username, String password) {
         listenerRegistration = notificationService.registerNotificationListener(
                 new NbiNotificationsListenerImpl(baseUrl, username, password));
+        LOG.info("DmaapClientProvider Session Initiated");
     }
 
     /**
@@ -46,5 +54,4 @@ public class DmaapClientProvider {
         listenerRegistration.close();
         LOG.info("DmaapClientProvider Closed");
     }
-
 }
diff --git a/dmaap-client/src/main/resources/OSGI-INF/blueprint/dmaap-blueprint.xml b/dmaap-client/src/main/resources/OSGI-INF/blueprint/dmaap-blueprint.xml
deleted file mode 100644 (file)
index ece6f21..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!-- Copyright © 2021 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.dmaap" update-strategy="reload">
-        <cm:default-properties>
-            <cm:property name="dmaap.baseUrl" value="http://localhost:8080" />
-            <cm:property name="dmaap.username" value="" />
-             <cm:property name="dmaap.password" value="" />
-        </cm:default-properties>
-    </cm:property-placeholder>
-    <reference id="notificationService" interface="org.opendaylight.mdsal.binding.api.NotificationService"/>
-
-    <bean id="provider"
-          class="org.opendaylight.transportpce.dmaap.client.impl.DmaapClientProvider"
-          init-method="init" destroy-method="close">
-        <argument ref="notificationService" />
-        <argument value="${dmaap.baseUrl}" />
-        <argument value="${dmaap.username}" />
-        <argument value="${dmaap.password}" />
-    </bean>
-</blueprint>
index 6c66201aa12683e556cd99b01e2c75af07e2525a..79f7edcf3ee0b9a4164dd08a73e7e9295c041652 100644 (file)
@@ -31,11 +31,9 @@ public class DmaapClientProviderTest {
 
     @Test
     void testInitRegisterNbiNotificationsToRpcRegistry() {
-        DmaapClientProvider provider =
-            new DmaapClientProvider(notificationService, "http://localhost", "username", "password");
-        provider.init();
-        (verify(notificationService, times(1)))
-                .registerNotificationListener(Mockito.any(NbiNotificationsListenerImpl.class));
+        new DmaapClientProvider(notificationService, "http://localhost", "username", "password");
+        verify(notificationService, times(1))
+            .registerNotificationListener(Mockito.any(NbiNotificationsListenerImpl.class));
     }
 
 }