Convert PathComputationServiceImpl into Component 43/104943/5
authorGilles Thouenon <gilles.thouenon@orange.com>
Tue, 14 Mar 2023 14:41:02 +0000 (15:41 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Sun, 26 Mar 2023 20:57:45 +0000 (22:57 +0200)
Adapt UT and blueprint file accordingly.

JIRA: TRNSPRTPCE-736
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: Ifbcd73c6a2390bbaa5fa468617ff46ba1515892c

pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java
pce/src/main/resources/OSGI-INF/blueprint/pce-blueprint.xml
pce/src/test/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImplTest.java

index 32942c2bd12d9a92de028e557cc51b7335d7009f..3bda9da106ae4c8e72ce4298b9c1fa9ec1edca7f 100644 (file)
@@ -55,9 +55,13 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.ServicePathNotificationTypes;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.handler.header.ServiceHandlerHeaderBuilder;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Component(immediate = true)
 public class PathComputationServiceImpl implements PathComputationService {
 
     private static final Logger LOG = LoggerFactory.getLogger(PathComputationServiceImpl.class);
@@ -68,22 +72,17 @@ public class PathComputationServiceImpl implements PathComputationService {
     private final GnpyConsumer gnpyConsumer;
     private PortMapping portMapping;
 
-    public PathComputationServiceImpl(NetworkTransactionService networkTransactionService,
-                                      NotificationPublishService notificationPublishService,
-                                      GnpyConsumer gnpyConsumer, PortMapping portMapping) {
+    @Activate
+    public PathComputationServiceImpl(@Reference NetworkTransactionService networkTransactionService,
+            @Reference NotificationPublishService notificationPublishService,
+            @Reference GnpyConsumer gnpyConsumer,
+            @Reference PortMapping portMapping) {
         this.notificationPublishService = notificationPublishService;
         this.networkTransactionService = networkTransactionService;
         this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5));
         this.gnpyConsumer = gnpyConsumer;
         this.portMapping = portMapping;
-    }
-
-    public void init() {
-        LOG.info("init ...");
-    }
-
-    public void close() {
-        LOG.info("close.");
+        LOG.debug("PathComputationServiceImpl instantiated");
     }
 
     @SuppressFBWarnings(
index a42a0f8a69174b588c997f207729c257af06ec20..1ba493936b2b2e7483105a849b0f11f389835688 100755 (executable)
@@ -11,20 +11,8 @@ Author: Martial Coulibaly <martial.coulibaly@gfi.com> on behalf of Orange
 -->
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
 
-  <reference id="networkTransactionImpl" interface="org.opendaylight.transportpce.common.network.NetworkTransactionService" />
   <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"
-        init-method="init" destroy-method="close">
-    <argument ref="networkTransactionImpl"/>
-    <argument ref="notificationPublishService" />
-    <argument ref="gnpyConsumer" />
-    <argument ref="portMapping" />
-  </bean>
+  <reference id="pceServiceImpl" interface="org.opendaylight.transportpce.pce.service.PathComputationService"/>
 
   <bean id="provider"
         class="org.opendaylight.transportpce.pce.impl.PceProvider"
@@ -32,8 +20,4 @@ Author: Martial Coulibaly <martial.coulibaly@gfi.com> on behalf of Orange
     <argument ref="rpcService" />
     <argument ref="pceServiceImpl" />
   </bean>
-
-  <service ref="pceServiceImpl"
-        interface="org.opendaylight.transportpce.pce.service.PathComputationService"/>
-
 </blueprint>
index 66ae13a72a91f84fa84844b8ed9b6a00b0698ebb..4408d094ed0e3ff4f726888a2ba29f067a1e55b6 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.transportpce.pce.service;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 import java.util.Map;
-import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
@@ -40,7 +39,6 @@ public class PathComputationServiceImplTest extends AbstractTest {
         pathComputationServiceImpl = new PathComputationServiceImpl(
                 networkTransactionService,
                 this.getNotificationPublishService(), null, null);
-        pathComputationServiceImpl.init();
     }
 
     @Test
@@ -79,9 +77,4 @@ public class PathComputationServiceImplTest extends AbstractTest {
         pathComputationServiceImpl.generateGnpyResponse(null,"path");
         assertNotNull(pathComputationServiceImpl.pathComputationRerouteRequest(PceTestData.getPCEReroute()));
     }
-
-    @AfterEach
-    void destroy() {
-        pathComputationServiceImpl.close();
-    }
 }