Remove static instantiations from RendererProvider 47/104947/7
authorGilles Thouenon <gilles.thouenon@orange.com>
Tue, 14 Mar 2023 12:56:43 +0000 (13:56 +0100)
committerGilles Thouenon <gilles.thouenon@orange.com>
Fri, 31 Mar 2023 07:36:20 +0000 (09:36 +0200)
Convert DeviceRendererRPCImpl and TransportPCEServicePathRPCImpl
into Components.

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

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/test/java/org/opendaylight/transportpce/renderer/RendererProviderTest.java

index 0596c089030df6ea68a7957c77ba808d8e54699f..9ee5b91c0a45f6fc8a9fafb4f52cbc10edb1b385 100644 (file)
@@ -64,6 +64,7 @@ import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererS
 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperationsImpl;
 import org.opendaylight.transportpce.renderer.rpcs.DeviceRendererRPCImpl;
+import org.opendaylight.transportpce.renderer.rpcs.TransportPCEServicePathRPCImpl;
 import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl;
 import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerProvider;
 import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelListenerImpl;
@@ -304,7 +305,8 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
                 lightyServices.getBindingDataBroker(), lightyServices.getBindingNotificationPublishService(),
                 portMapping);
         return new RendererProvider(lightyServices.getRpcProviderService(), deviceRendererService,
-                otnDeviceRendererService, rendererServiceOperations);
+                otnDeviceRendererService, deviceRendererRPC,
+                new TransportPCEServicePathRPCImpl(rendererServiceOperations));
     }
 
     private OpenRoadmInterfaceFactory initOpenRoadmFactory(MappingUtils mappingUtils,
index 2f66a4ecb1e55a0070220af6452d2f2174b7cae2..41aed38be2165ab372d6b1f91f54aa9caff7aebc 100644 (file)
@@ -10,9 +10,6 @@ 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;
@@ -28,19 +25,16 @@ 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<TransportpceDeviceRendererService> deviceRendererRegistration;
     private ObjectRegistration<TransportpceRendererService> tpceServiceRegistry;
 
     @Activate
     public RendererProvider(@Reference RpcProviderService rpcProviderService,
             @Reference DeviceRendererService deviceRenderer,
             @Reference OtnDeviceRendererService otnDeviceRendererService,
-            @Reference RendererServiceOperations rendererServiceOperations) {
+            @Reference TransportpceDeviceRendererService deviceRendererRPCImpl,
+            @Reference TransportpceRendererService transportPCEServicePathRPCImpl) {
         this.rpcProviderService = rpcProviderService;
-        this.deviceRendererRPCImpl = new DeviceRendererRPCImpl(deviceRenderer, otnDeviceRendererService);
-        this.transportPCEServicePathRPCImpl = new TransportPCEServicePathRPCImpl(rendererServiceOperations);
         LOG.info("RendererProvider Session Initiated");
         this.deviceRendererRegistration = this.rpcProviderService
                 .registerRpcImplementation(TransportpceDeviceRendererService.class, deviceRendererRPCImpl);
index 78bd06c327224624176a42c089242752c26161b4..39141700b7875bd321eebeb6bae7e427bb083c4e 100644 (file)
@@ -26,17 +26,22 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.re
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.TransportpceDeviceRendererService;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+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 DeviceRendererRPCImpl implements TransportpceDeviceRendererService {
 
     private static final Logger LOG = LoggerFactory.getLogger(DeviceRendererRPCImpl.class);
     private DeviceRendererService deviceRenderer;
     private OtnDeviceRendererService otnDeviceRendererService;
 
-    public DeviceRendererRPCImpl(DeviceRendererService deviceRenderer,
-                                 OtnDeviceRendererService otnDeviceRendererService) {
+    @Activate
+    public DeviceRendererRPCImpl(@Reference DeviceRendererService deviceRenderer,
+            @Reference OtnDeviceRendererService otnDeviceRendererService) {
         this.deviceRenderer = deviceRenderer;
         this.otnDeviceRendererService = otnDeviceRendererService;
         LOG.debug("DeviceRendererRPCImpl instantiated");
index 38c7fd25210ad5ebedf79d2c5aa33d9752a37e4b..f43204df44b584719ad9320b805325d120692236 100644 (file)
@@ -17,16 +17,21 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererService;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+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 TransportPCEServicePathRPCImpl implements TransportpceRendererService {
 
     private static final Logger LOG = LoggerFactory.getLogger(TransportPCEServicePathRPCImpl.class);
 
     private final RendererServiceOperations rendererServiceOperations;
 
-    public TransportPCEServicePathRPCImpl(RendererServiceOperations rendererServiceOperations) {
+    @Activate
+    public TransportPCEServicePathRPCImpl(@Reference RendererServiceOperations rendererServiceOperations) {
         this.rendererServiceOperations = rendererServiceOperations;
         LOG.debug("TransportPCEServicePathRPCImpl instantiated");
     }
index d6845de1fd6120acf7995a12843e068ef539ea19..611326ae35a891e8f6c82a7a8f87acb9b801a5d5 100644 (file)
@@ -18,7 +18,6 @@ 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;
 import org.opendaylight.transportpce.test.AbstractTest;
@@ -33,11 +32,14 @@ public class RendererProviderTest extends AbstractTest {
     @Mock
     OtnDeviceRendererService otnDeviceRendererService;
     @Mock
-    RendererServiceOperations rendererServiceOperations;
+    DeviceRendererRPCImpl deviceRendererRPCImpl;
+    @Mock
+    TransportPCEServicePathRPCImpl transportPCEServicePathRPCImpl;
 
     @Test
     void testInitMethodRegistersRendererToRpcService() {
-        new RendererProvider(rpcProviderService, deviceRenderer, otnDeviceRendererService, rendererServiceOperations);
+        new RendererProvider(rpcProviderService, deviceRenderer, otnDeviceRendererService, deviceRendererRPCImpl,
+            transportPCEServicePathRPCImpl);
 
         verify(rpcProviderService, times(1))
             .registerRpcImplementation(any(), any(TransportPCEServicePathRPCImpl.class));