Remove renderer-blueprint 41/104941/5
authorGilles Thouenon <gilles.thouenon@orange.com>
Tue, 14 Mar 2023 09:02:53 +0000 (10:02 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Sun, 26 Mar 2023 20:57:45 +0000 (22:57 +0200)
Convert RendererProvier into a Component.
Instantiate manually DeviceRendererRPCImpl and
TransportPCEServicePathRPCImpl since OSGI does not start them directly
when they are also converted to Components.

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

lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/RendererProvider.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/rpcs/DeviceRendererRPCImpl.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/rpcs/TransportPCEServicePathRPCImpl.java
renderer/src/main/resources/OSGI-INF/blueprint/renderer-blueprint.xml [deleted file]
renderer/src/test/java/org/opendaylight/transportpce/renderer/RendererProviderTest.java

index 2fcca728e6c30c849b95d41da70c4fd50ad34f2e..87008451b477bf0682ea50fd334ea8e993efe999 100644 (file)
@@ -87,6 +87,7 @@ import org.opendaylight.transportpce.tapi.topology.TapiPortMappingListener;
 import org.opendaylight.transportpce.tapi.utils.TapiLink;
 import org.opendaylight.transportpce.tapi.utils.TapiListener;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererService;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.tapinetworkutils.rev210408.TransportpceTapinetworkutilsService;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.OrgOpenroadmServiceService;
 import org.slf4j.Logger;
@@ -241,8 +242,6 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
     protected boolean initProcedure() {
         LOG.info("Initializing PCE provider ...");
         pceProvider.init();
-        LOG.info("Initializing renderer provider ...");
-        rendererProvider.init();
         LOG.info("Initializing service-handler provider ...");
         servicehandlerProvider.init();
         if (tapiProvider != null) {
@@ -308,8 +307,8 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
                 deviceRendererService, otnDeviceRendererService, olmPowerServiceRpc,
                 lightyServices.getBindingDataBroker(), lightyServices.getBindingNotificationPublishService(),
                 portMapping);
-        return new RendererProvider(lightyServices.getRpcProviderService(), deviceRendererRPC,
-                rendererServiceOperations);
+        return new RendererProvider(lightyServices.getRpcProviderService(), deviceRendererService,
+                otnDeviceRendererService, rendererServiceOperations);
     }
 
     private OpenRoadmInterfaceFactory initOpenRoadmFactory(MappingUtils mappingUtils,
index 3bfacdc7373f0c956c14fb29ffad2a5e408453bc..2f66a4ecb1e55a0070220af6452d2f2174b7cae2 100644 (file)
@@ -8,38 +8,40 @@
 package org.opendaylight.transportpce.renderer;
 
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
+import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
 import org.opendaylight.transportpce.renderer.rpcs.DeviceRendererRPCImpl;
 import org.opendaylight.transportpce.renderer.rpcs.TransportPCEServicePathRPCImpl;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.TransportpceDeviceRendererService;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererService;
 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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Component
 public class RendererProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(RendererProvider.class);
     private final RpcProviderService rpcProviderService;
     private DeviceRendererRPCImpl deviceRendererRPCImpl;
+    private TransportPCEServicePathRPCImpl transportPCEServicePathRPCImpl;
     private ObjectRegistration<DeviceRendererRPCImpl> deviceRendererRegistration;
     private ObjectRegistration<TransportpceRendererService> tpceServiceRegistry;
-    private RendererServiceOperations rendererServiceOperations;
 
-    public RendererProvider(RpcProviderService rpcProviderService, DeviceRendererRPCImpl deviceRendererRPCImpl,
-            RendererServiceOperations rendererServiceOperations) {
+    @Activate
+    public RendererProvider(@Reference RpcProviderService rpcProviderService,
+            @Reference DeviceRendererService deviceRenderer,
+            @Reference OtnDeviceRendererService otnDeviceRendererService,
+            @Reference RendererServiceOperations rendererServiceOperations) {
         this.rpcProviderService = rpcProviderService;
-        this.deviceRendererRPCImpl = deviceRendererRPCImpl;
-        this.rendererServiceOperations = rendererServiceOperations;
-    }
-
-    /**
-     * Method called when the blueprint container is created.
-     */
-    public void init() {
+        this.deviceRendererRPCImpl = new DeviceRendererRPCImpl(deviceRenderer, otnDeviceRendererService);
+        this.transportPCEServicePathRPCImpl = new TransportPCEServicePathRPCImpl(rendererServiceOperations);
         LOG.info("RendererProvider Session Initiated");
-        TransportPCEServicePathRPCImpl transportPCEServicePathRPCImpl =
-            new TransportPCEServicePathRPCImpl(this.rendererServiceOperations);
         this.deviceRendererRegistration = this.rpcProviderService
                 .registerRpcImplementation(TransportpceDeviceRendererService.class, deviceRendererRPCImpl);
         this.tpceServiceRegistry = this.rpcProviderService
@@ -49,6 +51,7 @@ public class RendererProvider {
     /**
      * Method called when the blueprint container is destroyed.
      */
+    @Deactivate
     public void close() {
         LOG.info("RendererProvider Closed");
         if (this.deviceRendererRegistration != null) {
@@ -58,5 +61,4 @@ public class RendererProvider {
             this.tpceServiceRegistry.close();
         }
     }
-
-}
+}
\ No newline at end of file
index eba065eeba618d9766cc3c3a0311153ed86c4e14..78bd06c327224624176a42c089242752c26161b4 100644 (file)
@@ -39,6 +39,7 @@ public class DeviceRendererRPCImpl implements TransportpceDeviceRendererService
                                  OtnDeviceRendererService otnDeviceRendererService) {
         this.deviceRenderer = deviceRenderer;
         this.otnDeviceRendererService = otnDeviceRendererService;
+        LOG.debug("DeviceRendererRPCImpl instantiated");
     }
 
     /**
index 31bdda59fcc8c76f07eaf5e5f0f706e18a6e59c9..38c7fd25210ad5ebedf79d2c5aa33d9752a37e4b 100644 (file)
@@ -28,6 +28,7 @@ public class TransportPCEServicePathRPCImpl implements TransportpceRendererServi
 
     public TransportPCEServicePathRPCImpl(RendererServiceOperations rendererServiceOperations) {
         this.rendererServiceOperations = rendererServiceOperations;
+        LOG.debug("TransportPCEServicePathRPCImpl instantiated");
     }
 
     @Override
@@ -56,6 +57,4 @@ public class TransportPCEServicePathRPCImpl implements TransportpceRendererServi
         }
         return ModelMappingUtils.createServiceImplementationRpcResponse(output);
     }
-
 }
-
diff --git a/renderer/src/main/resources/OSGI-INF/blueprint/renderer-blueprint.xml b/renderer/src/main/resources/OSGI-INF/blueprint/renderer-blueprint.xml
deleted file mode 100644 (file)
index e56b693..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
-Copyright © 2016 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">
-
-  <reference id="rpcProviderService" interface="org.opendaylight.mdsal.binding.api.RpcProviderService" />
-  <reference id="deviceRenderer" interface="org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService" />
-  <reference id="otnDeviceRenderer" interface="org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService"/>
-  <reference id="rendererServiceOperations" interface="org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations" />
-
-  <bean id="deviceRendererRPCImpl" class="org.opendaylight.transportpce.renderer.rpcs.DeviceRendererRPCImpl" >
-    <argument ref="deviceRenderer" />
-    <argument ref="otnDeviceRenderer" />
-  </bean>
-
-  <bean id="rendererProvider" class="org.opendaylight.transportpce.renderer.RendererProvider"
-        init-method="init" destroy-method="close">
-    <argument ref="rpcProviderService" />
-    <argument ref="deviceRendererRPCImpl" />
-    <argument ref="rendererServiceOperations" />
-  </bean>
-
-</blueprint>
index 590475793ffcba013c8f17d35ed01146f8de4ee8..d6845de1fd6120acf7995a12843e068ef539ea19 100644 (file)
@@ -16,6 +16,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
+import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
 import org.opendaylight.transportpce.renderer.rpcs.DeviceRendererRPCImpl;
 import org.opendaylight.transportpce.renderer.rpcs.TransportPCEServicePathRPCImpl;
@@ -27,15 +29,15 @@ public class RendererProviderTest extends AbstractTest {
     @Mock
     RpcProviderService rpcProviderService;
     @Mock
-    private RendererServiceOperations rendererServiceOperations;
+    DeviceRendererService deviceRenderer;
     @Mock
-    DeviceRendererRPCImpl deviceRendererRPC;
+    OtnDeviceRendererService otnDeviceRendererService;
+    @Mock
+    RendererServiceOperations rendererServiceOperations;
 
     @Test
     void testInitMethodRegistersRendererToRpcService() {
-        RendererProvider provider =
-            new RendererProvider(rpcProviderService, deviceRendererRPC, rendererServiceOperations);
-        provider.init();
+        new RendererProvider(rpcProviderService, deviceRenderer, otnDeviceRendererService, rendererServiceOperations);
 
         verify(rpcProviderService, times(1))
             .registerRpcImplementation(any(), any(TransportPCEServicePathRPCImpl.class));