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);
<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>
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;
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;
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);
}
/**
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" />
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);
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
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() {
import org.opendaylight.yangtools.yang.common.Decimal64;
public class PowerMgmtTest {
- private DataBroker dataBroker;
private OpenRoadmInterfaces openRoadmInterfaces;
private CrossConnect crossConnect;
private DeviceTransactionManager deviceTransactionManager;
@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