Convert GnpyConsumerImpl into a Component 42/104942/5
authorGilles Thouenon <gilles.thouenon@orange.com>
Tue, 14 Mar 2023 14:24:42 +0000 (15:24 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Sun, 26 Mar 2023 20:57:45 +0000 (22:57 +0200)
JIRA: TRNSPRTPCE-736
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: Ic471eaeb51b2772507f7aa1ba44e9c5db3dd8cb6

pce/pom.xml
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/consumer/GnpyConsumerImpl.java
pce/src/main/resources/OSGI-INF/blueprint/pce-blueprint.xml

index 54ce3bd6770a723b84fab8abcc5c6f2a5c67f82d..04bd19e0a1952a044cf1f9ddfd0614478c628671 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 b0854e02b128628d5527e67a2276ed76c00aa2cd..7d307636ac6d99187a48bfcdb5f5b060cf21126b 100644 (file)
@@ -19,14 +19,36 @@ import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
 import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.Request;
 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result;
+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.pce")
 public class GnpyConsumerImpl implements GnpyConsumer {
+    @ObjectClassDefinition
+    public @interface Configuration {
+        @AttributeDefinition
+        String url() default "http://127.0.0.1:8008";
+        @AttributeDefinition
+        String username() default "gnpy";
+        @AttributeDefinition
+        String password() default "gnpy";
+    }
+
     private static final Logger LOG = LoggerFactory.getLogger(GnpyConsumerImpl.class);
 
     private final GnpyResource api;
 
+    @Activate
+    public GnpyConsumerImpl(final Configuration configuration,
+            @Reference BindingDOMCodecServices bindingDOMCodecServices) {
+        this(configuration.url(), configuration.username(), configuration.password(), bindingDOMCodecServices);
+    }
+
     public GnpyConsumerImpl(String baseUrl, String username, String password,
             BindingDOMCodecServices bindingDOMCodecServices) {
         JsonStringConverter<Request> gnpyRequestConverter = new JsonStringConverter<>(bindingDOMCodecServices);
index c8da033f44094ad5573fd9ba923d5264407d90ca..a42a0f8a69174b588c997f207729c257af06ec20 100755 (executable)
@@ -9,22 +9,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
 Author: Martial Coulibaly <martial.coulibaly@gfi.com> on behalf of Orange
 -->
-<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.pce" update-strategy="reload">
-        <cm:default-properties>
-            <cm:property name="url" value="http://127.0.0.1:8008" />
-            <cm:property name="username" value="gnpy" />
-            <cm:property name="password" value="gnpy" />
-        </cm:default-properties>
-    </cm:property-placeholder>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
 
   <reference id="networkTransactionImpl" interface="org.opendaylight.transportpce.common.network.NetworkTransactionService" />
-  <reference id="bindingDOMCodecServices" interface="org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices" />
-  <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
   <reference id="rpcService" interface="org.opendaylight.mdsal.binding.api.RpcProviderService"/>
   <reference id="notificationPublishService" interface="org.opendaylight.mdsal.binding.api.NotificationPublishService"/>
   <reference id="portMapping" interface="org.opendaylight.transportpce.common.mapping.PortMapping"/>
+  <reference id="gnpyConsumer" interface="org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumer"/>
 
   <bean id="pceServiceImpl"
         class="org.opendaylight.transportpce.pce.service.PathComputationServiceImpl"
@@ -35,14 +26,6 @@ Author: Martial Coulibaly <martial.coulibaly@gfi.com> on behalf of Orange
     <argument ref="portMapping" />
   </bean>
 
-  <bean id="gnpyConsumer"
-        class="org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumerImpl">
-     <argument value="${url}"/>
-     <argument value="${username}"/>
-     <argument value="${password}"/>
-     <argument ref="bindingDOMCodecServices" />
-  </bean>
-
   <bean id="provider"
         class="org.opendaylight.transportpce.pce.impl.PceProvider"
         init-method="init" destroy-method="close">