Turn PortMappingImpl into a component 52/104352/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Feb 2023 16:59:30 +0000 (17:59 +0100)
committerGilles Thouenon <gilles.thouenon@orange.com>
Tue, 14 Feb 2023 15:14:55 +0000 (15:14 +0000)
This is a simple component with three constituents. Split it out of
blueprint.
Also, remove portMapppingVersionXX parameter from
OpenRoadmUnterfacesImplXX and adapt code consequently.

Change-Id: I0036d0609276374538a26ec13fa03153446e8644
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingImpl.java
common/src/main/java/org/opendaylight/transportpce/common/openroadminterfaces/OpenRoadmInterfacesImpl221.java
common/src/main/java/org/opendaylight/transportpce/common/openroadminterfaces/OpenRoadmInterfacesImpl710.java
common/src/main/resources/OSGI-INF/blueprint/common-blueprint.xml
lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java
olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtPowerMockTest.java

index 85f7280bab8eb46b7293afde7323c95411d4f181..9d15dffac4826e5cd3f3a569b3c6d789ae4c88ac 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.ReadTransaction;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.Network;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.OpenroadmNodeVersion;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
@@ -34,10 +35,13 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.open
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.Uint16;
+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
 public class PortMappingImpl implements PortMapping {
 
     private static final Logger LOG = LoggerFactory.getLogger(PortMappingImpl.class);
@@ -47,6 +51,15 @@ public class PortMappingImpl implements PortMapping {
     private final PortMappingVersion221 portMappingVersion22;
     private final PortMappingVersion121 portMappingVersion121;
 
+    @Activate
+    public PortMappingImpl(@Reference DataBroker dataBroker,
+            @Reference DeviceTransactionManager deviceTransactionManager) {
+        this(dataBroker,
+            new PortMappingVersion710(dataBroker, deviceTransactionManager),
+            new PortMappingVersion221(dataBroker, deviceTransactionManager),
+            new PortMappingVersion121(dataBroker, deviceTransactionManager));
+    }
+
     public PortMappingImpl(DataBroker dataBroker, PortMappingVersion710 portMappingVersion710,
         PortMappingVersion221 portMappingVersion22, PortMappingVersion121 portMappingVersion121) {
 
index c31e82fedb0f1a1283f0c591293aeaa64480f7a8..e3a0d83b90fa982476d0325d53b44daf58cb0163 100755 (executable)
@@ -47,11 +47,10 @@ public class OpenRoadmInterfacesImpl221 {
     private final PortMapping portMapping;
     private final PortMappingVersion221 portMapping221;
 
-    public OpenRoadmInterfacesImpl221(DeviceTransactionManager deviceTransactionManager,
-            PortMapping portMapping, PortMappingVersion221 portMapping221) {
+    public OpenRoadmInterfacesImpl221(DeviceTransactionManager deviceTransactionManager, PortMapping portMapping) {
         this.deviceTransactionManager = deviceTransactionManager;
         this.portMapping = portMapping;
-        this.portMapping221 = portMapping221;
+        this.portMapping221 = portMapping.getPortMappingVersion221();
     }
 
     public void postInterface(String nodeId, InterfaceBuilder ifBuilder) throws OpenRoadmInterfaceException {
index 2ae9eec004cd3cfb237429ec19119ac5d3bc7911..7adf3950c86dc640527ea36855331450c7902ffe 100644 (file)
@@ -47,11 +47,10 @@ public class OpenRoadmInterfacesImpl710 {
     private final PortMapping portMapping;
     private final PortMappingVersion710 portMapping710;
 
-    public OpenRoadmInterfacesImpl710(DeviceTransactionManager deviceTransactionManager,
-            PortMapping portMapping, PortMappingVersion710 portMapping710) {
+    public OpenRoadmInterfacesImpl710(DeviceTransactionManager deviceTransactionManager, PortMapping portMapping) {
         this.deviceTransactionManager = deviceTransactionManager;
         this.portMapping = portMapping;
-        this.portMapping710 = portMapping710;
+        this.portMapping710 = portMapping.getPortMappingVersion710();
     }
 
     public void postInterface(String nodeId, InterfaceBuilder ifBuilder) throws OpenRoadmInterfaceException {
index 5f59db573ab9e0504e70e9839fc7a14b2e065abf..b57d2b577b70d0531b9b883291b65c2c845b67e6 100644 (file)
@@ -9,9 +9,9 @@ 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="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker" />
     <reference id="deviceTransactionManager" interface="org.opendaylight.transportpce.common.device.DeviceTransactionManager" />
     <reference id="mappingUtils" interface="org.opendaylight.transportpce.common.mapping.MappingUtils" />
+    <reference id="portMapping" interface="org.opendaylight.transportpce.common.mapping.PortMapping" />
 
     <bean id="openRoadmInterfaces121" class="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121" >
         <argument ref="deviceTransactionManager" />
@@ -20,13 +20,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <bean id="openRoadmInterfaces221" class="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221" >
         <argument ref="deviceTransactionManager" />
         <argument ref="portMapping" />
-        <argument ref="portMapping221" />
     </bean>
 
     <bean id="openRoadmInterfaces710" class="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710" >
         <argument ref="deviceTransactionManager" />
         <argument ref="portMapping" />
-        <argument ref="portMapping710" />
     </bean>
 
     <bean id="openRoadmInterfaces" class="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl" >
@@ -37,30 +35,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
         <argument ref="openRoadmInterfaces710" />
     </bean>
 
-    <bean id="portMapping121" class="org.opendaylight.transportpce.common.mapping.PortMappingVersion121" >
-        <argument ref="dataBroker" />
-        <argument ref="deviceTransactionManager" />
-    </bean>
-
-    <bean id="portMapping221" class="org.opendaylight.transportpce.common.mapping.PortMappingVersion221" >
-        <argument ref="dataBroker" />
-        <argument ref="deviceTransactionManager" />
-    </bean>
-
-    <bean id="portMapping710" class="org.opendaylight.transportpce.common.mapping.PortMappingVersion710" >
-        <argument ref="dataBroker" />
-        <argument ref="deviceTransactionManager" />
-    </bean>
-
-    <bean id="portMapping" class="org.opendaylight.transportpce.common.mapping.PortMappingImpl" >
-        <argument ref="dataBroker" />
-        <argument ref="portMapping221" />
-        <argument ref="portMapping121" />
-        <argument ref="portMapping710" />
-    </bean>
-
     <service ref="openRoadmInterfaces" interface="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces" />
 
-    <service ref="portMapping" interface="org.opendaylight.transportpce.common.mapping.PortMapping" />
-
 </blueprint>
index a888672b2c6ab3ab671d099eb51b75c63ed5629d..0505c1269937e8b108bc9d342591089e5bb1c61b 100644 (file)
@@ -354,9 +354,9 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
         OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(
                 deviceTransactionManager);
         OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(
-                deviceTransactionManager, portMapping, portMapping.getPortMappingVersion221());
+                deviceTransactionManager, portMapping);
         OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(
-                deviceTransactionManager, portMapping, portMapping.getPortMappingVersion710());
+                deviceTransactionManager, portMapping);
         return new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils, openRoadmInterfacesImpl121,
                 openRoadmInterfacesImpl221, openRoadmInterfacesImpl710);
     }
index dd277af6244666cc310d8be278db1f1097b797b2..5277ac687aa33e1a8a1dae91bc3e9d2ab0f42baf 100644 (file)
@@ -121,10 +121,8 @@ public class OlmPowerServiceRpcImplTest extends AbstractTest {
         this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
             this.portMappingVersion22, this.portMappingVersion121);
         this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
-        this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping,
-            this.portMappingVersion22);
-        this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager, this.portMapping,
-            this.portMappingVersion710);
+        this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping);
+        this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager, this.portMapping);
         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
             this.openRoadmInterfacesImpl710);
index 36c8d097f70926ab8918e954bf530854df5eee9f..637316a9c4d3f59743fae6c8bf1698264a1c0a95 100644 (file)
@@ -103,10 +103,8 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
         this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
             this.portMappingVersion22, this.portMappingVersion121);
         this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
-        this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping,
-            this.portMappingVersion22);
-        this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager, this.portMapping,
-            this.portMappingVersion710);
+        this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping);
+        this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager, this.portMapping);
         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
             this.openRoadmInterfacesImpl710);