The blueprint is again extremely simple, migrate it to OSGi DS.
Also correct artifacts declarations, so that device-ownership-service
has a version declaration.
JIRA: OPNFLWPLUG-1112
Change-Id: Ib916383eb517bde7a4a3c2969ef58ec24aea53da
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
<dependency>
<groupId>org.opendaylight.openflowplugin.applications</groupId>
<artifactId>device-ownership-service</artifactId>
- <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.infrautils</groupId>
<artifactId>infrautils-util</artifactId>
</dependency>
</dependencies>
-
</project>
<dependencies>
<dependency>
- <groupId>org.opendaylight.openflowplugin</groupId>
- <artifactId>openflowplugin-api</artifactId>
+ <groupId>com.guicedee.services</groupId>
+ <artifactId>javax.inject</artifactId>
+ <optional>true</optional>
</dependency>
<dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-binding-api</artifactId>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <optional>true</optional>
</dependency>
<dependency>
- <groupId>org.opendaylight.openflowplugin.model</groupId>
- <artifactId>model-inventory</artifactId>
+ <groupId>org.opendaylight.infrautils</groupId>
+ <artifactId>infrautils-util</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.openflowplugin.model</groupId>
- <artifactId>model-flow-service</artifactId>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-binding-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-api</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.openflowplugin</groupId>
<dependency>
<groupId>org.opendaylight.openflowplugin.applications</groupId>
<artifactId>device-ownership-service</artifactId>
- <version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.infrautils</groupId>
- <artifactId>infrautils-util</artifactId>
+ <groupId>org.opendaylight.openflowplugin.model</groupId>
+ <artifactId>model-inventory</artifactId>
</dependency>
<dependency>
- <groupId>com.guicedee.services</groupId>
- <artifactId>javax.inject</artifactId>
- <optional>true</optional>
+ <groupId>org.opendaylight.openflowplugin.model</groupId>
+ <artifactId>model-flow-service</artifactId>
</dependency>
<dependency>
- <groupId>jakarta.annotation</groupId>
- <artifactId>jakarta.annotation-api</artifactId>
- <optional>true</optional>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
</dependencies>
</project>
import static java.util.Objects.requireNonNull;
import java.util.Collection;
-import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
-public class DefaultConfigPusher implements AutoCloseable, ClusteredDataTreeChangeListener<FlowCapableNode> {
+@Component(service = { })
+public final class DefaultConfigPusher implements AutoCloseable, ClusteredDataTreeChangeListener<FlowCapableNode> {
private static final Logger LOG = LoggerFactory.getLogger(DefaultConfigPusher.class);
- private final NodeConfigService nodeConfigService;
- private final DataBroker dataBroker;
private final DeviceOwnershipService deviceOwnershipService;
-
- private Registration listenerRegistration;
+ private final SetConfig setConfig;
+ private final Registration reg;
@Inject
- public DefaultConfigPusher(final NodeConfigService nodeConfigService, final DataBroker dataBroker,
- final DeviceOwnershipService deviceOwnershipService) {
- this.nodeConfigService = nodeConfigService;
- this.dataBroker = dataBroker;
- this.deviceOwnershipService = requireNonNull(deviceOwnershipService, "DeviceOwnershipService can not be null");
- }
-
- @PostConstruct
- public void start() {
- listenerRegistration = dataBroker.registerDataTreeChangeListener(
+ @Activate
+ public DefaultConfigPusher(@Reference final DataBroker dataBroker, @Reference final RpcConsumerRegistry rpcService,
+ @Reference final DeviceOwnershipService deviceOwnershipService) {
+ this.deviceOwnershipService = requireNonNull(deviceOwnershipService);
+ setConfig = rpcService.getRpc(SetConfig.class);
+ reg = dataBroker.registerDataTreeChangeListener(
DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
- InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)),
- this);
+ InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)), this);
LOG.info("DefaultConfigPusher has started.");
}
- @Override
@PreDestroy
+ @Deactivate
+ @Override
public void close() {
- if (listenerRegistration != null) {
- listenerRegistration.close();
- }
+ reg.close();
}
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<FlowCapableNode>> modifications) {
- for (DataTreeModification<FlowCapableNode> modification : modifications) {
+ for (var modification : modifications) {
if (modification.getRootNode().getModificationType() == ModificationType.WRITE) {
- String nodeId = modification.getRootPath().getRootIdentifier()
- .firstKeyOf(Node.class).getId().getValue();
+ final var nodeId = modification.getRootPath().getRootIdentifier().firstKeyOf(Node.class)
+ .getId().getValue();
if (deviceOwnershipService.isEntityOwned(nodeId)) {
- SetConfigInputBuilder setConfigInputBuilder = new SetConfigInputBuilder();
- setConfigInputBuilder.setFlag(SwitchConfigFlag.FRAGNORMAL.toString());
- setConfigInputBuilder.setMissSearchLength(OFConstants.OFPCML_NO_BUFFER);
- setConfigInputBuilder.setNode(new NodeRef(modification.getRootPath()
- .getRootIdentifier().firstIdentifierOf(Node.class)));
- LoggingFutures.addErrorLogging(nodeConfigService.setConfig(setConfigInputBuilder.build()),
- LOG, "addFlow");
+ LoggingFutures.addErrorLogging(setConfig.invoke(new SetConfigInputBuilder()
+ .setFlag(SwitchConfigFlag.FRAGNORMAL.toString())
+ .setMissSearchLength(OFConstants.OFPCML_NO_BUFFER)
+ .setNode(new NodeRef(
+ modification.getRootPath().getRootIdentifier().firstIdentifierOf(Node.class)))
+ .build()), LOG, "addFlow");
} else {
LOG.debug("Node {} is not owned by this controller, so skip setting config", nodeId);
}
}
}
}
-
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
- odl:use-default-for-reference-types="true">
- <bean id="defaultConfigPusher"
- class="org.opendaylight.openflowplugin.openflow.ofswitch.config.DefaultConfigPusher"
- init-method="start"
- destroy-method="close">
- <argument ref="nodeConfigService"/>
- <argument ref="dataBroker"/>
- <argument ref="deviceOwnershipService"/>
- </bean>
-
- <odl:rpc-service id="nodeConfigService"
- interface="org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService"/>
-
- <reference id="dataBroker"
- interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
- <reference id="deviceOwnershipService"
- interface="org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService"/>
-</blueprint>
*/
package org.opendaylight.openflowplugin.openflow.ofswitch.config;
+import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.Collections;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.List;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.DataObjectModification;
import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
private static final InstanceIdentifier<Node> NODE_IID = InstanceIdentifier.create(Nodes.class)
.child(Node.class, new NodeKey(new NodeId("testnode:1")));
@Mock
- private NodeConfigService nodeConfigService;
+ private DataBroker dataBroker;
+ @Mock
+ private RpcConsumerRegistry rpcService;
+ @Mock
+ private SetConfig setConfig;
+ @Mock
+ private ListenableFuture<?> setConfigResult;
@Mock
private DataTreeModification<FlowCapableNode> dataTreeModification;
@Mock
+ private DataObjectModification<FlowCapableNode> dataObjectModification;
+ @Mock
private DeviceOwnershipService deviceOwnershipService;
+ @Mock
+ private ListenerRegistration<?> reg;
@Captor
private ArgumentCaptor<SetConfigInput> setConfigInputCaptor;
@Before
public void setUp() {
- doReturn(RpcResultBuilder.success().buildFuture()).when(nodeConfigService).setConfig(any());
- defaultConfigPusher = new DefaultConfigPusher(nodeConfigService, Mockito.mock(DataBroker.class),
- deviceOwnershipService);
- final DataTreeIdentifier<FlowCapableNode> identifier = DataTreeIdentifier.create(
- LogicalDatastoreType.OPERATIONAL, NODE_IID.augmentation(FlowCapableNode.class));
- Mockito.when(dataTreeModification.getRootPath()).thenReturn(identifier);
- Mockito.when(dataTreeModification.getRootNode()).thenReturn(Mockito.mock(DataObjectModification.class));
- Mockito.when(dataTreeModification.getRootNode().getModificationType()).thenReturn(ModificationType.WRITE);
+ doReturn(RpcResultBuilder.success().buildFuture()).when(setConfig).invoke(any());
+ doReturn(reg).when(dataBroker).registerDataTreeChangeListener(any(), any());
+ doReturn(setConfig).when(rpcService).getRpc(any());
+ defaultConfigPusher = new DefaultConfigPusher(dataBroker, rpcService, deviceOwnershipService);
+ final var identifier = DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+ NODE_IID.augmentation(FlowCapableNode.class));
+ when(dataTreeModification.getRootPath()).thenReturn(identifier);
+ when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification);
+ when(dataTreeModification.getRootNode().getModificationType()).thenReturn(ModificationType.WRITE);
when(deviceOwnershipService.isEntityOwned(any())).thenReturn(true);
}
@Test
public void testOnDataTreeChanged() {
- defaultConfigPusher.onDataTreeChanged(Collections.singleton(dataTreeModification));
- Mockito.verify(nodeConfigService).setConfig(setConfigInputCaptor.capture());
- final SetConfigInput captured = setConfigInputCaptor.getValue();
- Assert.assertEquals(SwitchConfigFlag.FRAGNORMAL.toString(), captured.getFlag());
- Assert.assertEquals(OFConstants.OFPCML_NO_BUFFER, captured.getMissSearchLength());
- Assert.assertEquals(NODE_IID, captured.getNode().getValue());
+ defaultConfigPusher.onDataTreeChanged(List.of(dataTreeModification));
+ verify(setConfig).invoke(setConfigInputCaptor.capture());
+ final var captured = setConfigInputCaptor.getValue();
+ assertEquals(SwitchConfigFlag.FRAGNORMAL.toString(), captured.getFlag());
+ assertEquals(OFConstants.OFPCML_NO_BUFFER, captured.getMissSearchLength());
+ assertEquals(NODE_IID, captured.getNode().getValue());
}
@After
public void tearDown() {
defaultConfigPusher.close();
}
-
}
<dependency>
<groupId>org.opendaylight.openflowplugin.applications</groupId>
<artifactId>device-ownership-service</artifactId>
- <version>${project.version}</version>
</dependency>
</dependencies>
-
</project>
<artifactId>bulk-o-matic</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}.applications</groupId>
+ <artifactId>device-ownership-service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>${project.groupId}.applications</groupId>
<artifactId>forwardingrules-manager</artifactId>