From: Gilles Thouenon Date: Mon, 13 Mar 2023 16:05:16 +0000 (+0100) Subject: Convert PowerMgmtImpl of olm into a Component X-Git-Tag: 8.0.0~91 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=refs%2Fchanges%2F36%2F104936%2F4;p=transportpce.git Convert PowerMgmtImpl of olm into a Component - clean olm-blueprint.xml file - remove unused databroker property - adapt few UT JIRA: TRNSPRTPCE-736 Signed-off-by: Gilles Thouenon Change-Id: I0dca530c26a299cf68569c7be85819f0a217a323 --- diff --git a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java index 4961ec83c..bbd8f1950 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java @@ -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); diff --git a/olm/pom.xml b/olm/pom.xml index 38f0fb467..53caef045 100644 --- a/olm/pom.xml +++ b/olm/pom.xml @@ -109,6 +109,14 @@ and is available at http://www.eclipse.org/legal/epl-v10.html com.google.guava guava + + org.osgi + org.osgi.service.component.annotations + + + org.osgi + org.osgi.service.metatype.annotations + diff --git a/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java b/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java index 0be501425..74537a255 100644 --- a/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java +++ b/olm/src/main/java/org/opendaylight/transportpce/olm/power/PowerMgmtImpl.java @@ -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); } /** diff --git a/olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml b/olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml index ca76f85b4..986cbf56d 100644 --- a/olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml +++ b/olm/src/main/resources/OSGI-INF/blueprint/olm-blueprint.xml @@ -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 --> - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - + diff --git a/olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java b/olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java index 92bc79e65..a75623d65 100644 --- a/olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java +++ b/olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java @@ -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); diff --git a/olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtPowerMockTest.java b/olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtPowerMockTest.java index d28c5e6bf..62fdb6b33 100644 --- a/olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtPowerMockTest.java +++ b/olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtPowerMockTest.java @@ -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() { diff --git a/olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtTest.java b/olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtTest.java index 6d6f0c147..9c6a562b1 100644 --- a/olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtTest.java +++ b/olm/src/test/java/org/opendaylight/transportpce/olm/power/PowerMgmtTest.java @@ -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