Convert PowerMgmtImpl of olm into a Component 36/104936/4
authorGilles Thouenon <gilles.thouenon@orange.com>
Mon, 13 Mar 2023 16:05:16 +0000 (17:05 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Sun, 26 Mar 2023 20:57:44 +0000 (22:57 +0200)
- clean olm-blueprint.xml file
- remove unused databroker property
- adapt few UT

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

lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
olm/pom.xml
olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java
olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml
olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java
olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtPowerMockTest.java
olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtTest.java

index 4961ec83cd2fdfdc31a58e32e01a58225d1ee915..bbd8f1950b6abba775d238261c45d92d0afac00a 100644 (file)
@@ -161,8 +161,8 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
         MappingUtils mappingUtils = new MappingUtilsImpl(lightyServices.getBindingDataBroker());
         CrossConnect crossConnect = initCrossConnect(mappingUtils);
         OpenRoadmInterfaces openRoadmInterfaces = initOpenRoadmInterfaces(mappingUtils, portMapping);
-        PowerMgmt powerMgmt = new PowerMgmtImpl(lightyServices.getBindingDataBroker(), openRoadmInterfaces,
-                crossConnect, deviceTransactionManager, portMapping, olmtimer1, olmtimer2);
+        PowerMgmt powerMgmt = new PowerMgmtImpl(openRoadmInterfaces, crossConnect, deviceTransactionManager,
+                portMapping, Long.valueOf(olmtimer1).longValue(), Long.valueOf(olmtimer2).longValue());
         OlmPowerService olmPowerService = new OlmPowerServiceImpl(lightyServices.getBindingDataBroker(), powerMgmt,
                 deviceTransactionManager, portMapping, mappingUtils, openRoadmInterfaces);
         TransportpceOlmService olmPowerServiceRpc = new OlmPowerServiceRpcImpl(olmPowerService);
index 38f0fb46711500c5922eafba69654771ed7f95a5..53caef045358665677a6e897f3eafbd4013de619 100644 (file)
@@ -109,6 +109,14 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>com.google.guava</groupId>
       <artifactId>guava</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 0be501425aa0b624026e0fdb452b8b92ddfc9f0f..74537a255bde6c28f802241ab987b7bd8ca7743b 100644 (file)
@@ -15,7 +15,6 @@ import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Optional;
-import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
@@ -32,12 +31,25 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.Op
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.Interface1;
 import org.opendaylight.yangtools.yang.common.Decimal64;
+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")
 public class PowerMgmtImpl implements PowerMgmt {
+
+    @ObjectClassDefinition
+    public @interface Configuration {
+        @AttributeDefinition
+        long timer1() default 120000;
+        @AttributeDefinition
+        long timer2() default 20000;
+    }
     private static final Logger LOG = LoggerFactory.getLogger(PowerMgmtImpl.class);
-    private final DataBroker db;
     private final OpenRoadmInterfaces openRoadmInterfaces;
     private final CrossConnect crossConnect;
     private final DeviceTransactionManager deviceTransactionManager;
@@ -47,42 +59,42 @@ public class PowerMgmtImpl implements PowerMgmt {
     private static final String INTERFACE_NOT_PRESENT = "Interface {} on node {} is not present!";
     private static final double MC_WIDTH_GRAN = 2 * GridConstant.GRANULARITY;
 
-    private long timer1 = 120000;
+    private long timer1;
     // openroadm spec value is 120000, functest value is 3000
-    private long timer2 = 20000;
+    private long timer2;
     // openroadm spec value is 20000, functest value is 2000
 
-    public PowerMgmtImpl(DataBroker db, OpenRoadmInterfaces openRoadmInterfaces, CrossConnect crossConnect,
-            DeviceTransactionManager deviceTransactionManager, PortMapping portMapping) {
-        this.db = db;
-        this.openRoadmInterfaces = openRoadmInterfaces;
-        this.crossConnect = crossConnect;
-        this.deviceTransactionManager = deviceTransactionManager;
-        this.portMapping = portMapping;
+    @Activate
+    public PowerMgmtImpl(@Reference OpenRoadmInterfaces openRoadmInterfaces,
+            @Reference CrossConnect crossConnect,
+            @Reference DeviceTransactionManager deviceTransactionManager,
+            @Reference PortMapping portMapping, final Configuration configuration) {
+        this(openRoadmInterfaces, crossConnect, deviceTransactionManager, portMapping, configuration.timer1(),
+                configuration.timer2());
     }
 
-    public PowerMgmtImpl(DataBroker db, OpenRoadmInterfaces openRoadmInterfaces,
+    public PowerMgmtImpl(OpenRoadmInterfaces openRoadmInterfaces,
                          CrossConnect crossConnect, DeviceTransactionManager deviceTransactionManager,
-            PortMapping portMapping, String timer1, String timer2) {
-        this.db = db;
+            PortMapping portMapping, long timer1, long timer2) {
         this.openRoadmInterfaces = openRoadmInterfaces;
         this.crossConnect = crossConnect;
         this.deviceTransactionManager = deviceTransactionManager;
         this.portMapping = portMapping;
         try {
-            this.timer1 = Long.parseLong(timer1);
+            this.timer1 = Long.valueOf(timer1);
         } catch (NumberFormatException e) {
             this.timer1 = 120000;
             LOG.warn("Failed to retrieve Olm timer1 value from configuration - using default value {}",
                 this.timer1, e);
         }
         try {
-            this.timer2 = Long.parseLong(timer2);
+            this.timer2 = Long.valueOf(timer2);
         } catch (NumberFormatException e) {
             this.timer2 = 20000;
             LOG.warn("Failed to retrieve Olm timer2 value from configuration - using default value {}",
                 this.timer2, e);
         }
+        LOG.debug("PowerMgmtImpl instantiated with olm timers = {} - {}", this.timer1, this.timer2);
     }
 
     /**
index ca76f85b46130ea9783bc1415682122e3f157e95..986cbf56d9a2217931251f361b6ea93d6c220849 100644 (file)
@@ -7,43 +7,14 @@ 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"
-           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
-
-    <cm:property-placeholder persistent-id="org.opendaylight.transportpce" update-strategy="reload">
-        <cm:default-properties>
-            <cm:property name="timer1" value="" />
-            <cm:property name="timer2" value="" />
-            <!--The following values are used to speed-up tests with simulators without convergence times-->
-            <!--cm:property name="timer1" value="3000" /-->
-            <!--cm:property name="timer2" value="2000" /-->
-        </cm:default-properties>
-    </cm:property-placeholder>
-
-
-  <reference id="dataBroker"
-        interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
-  <reference id="rpcProviderService"
-        interface="org.opendaylight.mdsal.binding.api.RpcProviderService" />
-  <reference id="openRoadmInterfaces"
-        interface="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces" />
-  <reference id="crossConnect"
-        interface="org.opendaylight.transportpce.common.crossconnect.CrossConnect" />
-  <reference id="deviceTransactionManager"
-        interface="org.opendaylight.transportpce.common.device.DeviceTransactionManager" />
-  <reference id="portMapping"
-        interface="org.opendaylight.transportpce.common.mapping.PortMapping" />
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+  <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
+  <reference id="rpcProviderService" interface="org.opendaylight.mdsal.binding.api.RpcProviderService" />
+  <reference id="openRoadmInterfaces" interface="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces" />
+  <reference id="deviceTransactionManager" interface="org.opendaylight.transportpce.common.device.DeviceTransactionManager" />
+  <reference id="portMapping" interface="org.opendaylight.transportpce.common.mapping.PortMapping" />
   <reference id="mappingUtils" interface="org.opendaylight.transportpce.common.mapping.MappingUtils" />
-
-  <bean id="powerMgmt" class="org.opendaylight.transportpce.olm.power.PowerMgmtImpl" >
-    <argument ref="dataBroker" />
-    <argument ref="openRoadmInterfaces" />
-    <argument ref="crossConnect" />
-    <argument ref="deviceTransactionManager" />
-    <argument ref="portMapping" />
-    <argument value="${timer1}"/>
-    <argument value="${timer2}"/>
-  </bean>
+  <reference id="powerMgmt" interface="org.opendaylight.transportpce.olm.power.PowerMgmt" />
 
   <bean id="olmPowerServiceImpl" class="org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl">
     <argument ref="dataBroker" />
index 92bc79e65e5ac03774e93ef1612324068634273d..a75623d65bffadf8930e1bd19d89e3f274c9a42b 100644 (file)
@@ -129,8 +129,8 @@ public class OlmPowerServiceRpcImplTest extends AbstractTest {
                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
             this.openRoadmInterfacesImpl710);
         this.portMapping = Mockito.spy(this.portMapping);
-        this.powerMgmt = new PowerMgmtImpl(getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
-            this.deviceTransactionManager, this.portMapping);
+        this.powerMgmt = new PowerMgmtImpl(this.openRoadmInterfaces, this.crossConnect,
+            this.deviceTransactionManager, this.portMapping, 1000, 1000);
         this.olmPowerService = new OlmPowerServiceImpl(getDataBroker(), this.powerMgmt,
             this.deviceTransactionManager, this.portMapping,mappingUtils,openRoadmInterfaces);
         this.olmPowerServiceRpc = new OlmPowerServiceRpcImpl(this.olmPowerService);
index d28c5e6bf669fe25c845c4068643dfb9215eadd7..62fdb6b33b39bb944442780400b5338a63119750 100644 (file)
@@ -111,8 +111,8 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
             this.openRoadmInterfacesImpl710);
         this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
         this.portMapping = Mockito.spy(this.portMapping);
-        this.powerMgmt = new PowerMgmtImpl(getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
-                this.deviceTransactionManager, this.portMapping);
+        this.powerMgmt = new PowerMgmtImpl(this.openRoadmInterfaces, this.crossConnect,
+                this.deviceTransactionManager, this.portMapping, 1000, 1000);
     }
 
     @Test
@@ -235,8 +235,8 @@ public class PowerMgmtPowerMockTest extends AbstractTest {
                 this.mappingUtils, openRoadmInterfacesImpl121Spy, this.openRoadmInterfacesImpl22,
             this.openRoadmInterfacesImpl710);
         openRoadmInterfacesSpy = Mockito.spy(openRoadmInterfacesSpy);
-        return new PowerMgmtImpl(getDataBroker(), openRoadmInterfacesSpy, crossConnectMock,
-                this.deviceTransactionManager, this.portMapping);
+        return new PowerMgmtImpl(openRoadmInterfacesSpy, crossConnectMock,
+                this.deviceTransactionManager, this.portMapping, 0, 0);
     }
 
     private Nodes getXpdrNodesFromNodesBuilderDeg() {
index 6d6f0c147d6ca9ebbf21ab9ef7cd42a2b56e7c33..9c6a562b1f3db301f29eafbf5c3570cffc1ee67a 100644 (file)
@@ -44,7 +44,6 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfa
 import org.opendaylight.yangtools.yang.common.Decimal64;
 
 public class PowerMgmtTest {
-    private DataBroker dataBroker;
     private OpenRoadmInterfaces openRoadmInterfaces;
     private CrossConnect crossConnect;
     private DeviceTransactionManager deviceTransactionManager;
@@ -53,13 +52,13 @@ public class PowerMgmtTest {
 
     @BeforeEach
     void setUp() {
-        this.dataBroker = Mockito.mock(DataBroker.class);
+        Mockito.mock(DataBroker.class);
         this.openRoadmInterfaces = Mockito.mock(OpenRoadmInterfaces.class);
         this.crossConnect = Mockito.mock((CrossConnectImpl.class));
         this.deviceTransactionManager = Mockito.mock(DeviceTransactionManager.class);
         this.portMapping = Mockito.mock(PortMapping.class);
-        this.powerMgmt = new PowerMgmtImpl(this.dataBroker, this.openRoadmInterfaces, this.crossConnect,
-                this.deviceTransactionManager, this.portMapping, "1000", "1000");
+        this.powerMgmt = new PowerMgmtImpl(this.openRoadmInterfaces, this.crossConnect,
+                this.deviceTransactionManager, this.portMapping, 1000, 1000);
     }
 
     @Test