Ditch blueprint from of-switch-config-pusher 73/110173/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Feb 2024 09:12:29 +0000 (10:12 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Feb 2024 09:31:24 +0000 (10:31 +0100)
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>
applications/lldp-speaker/pom.xml
applications/of-switch-config-pusher/pom.xml
applications/of-switch-config-pusher/src/main/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusher.java
applications/of-switch-config-pusher/src/main/resources/OSGI-INF/blueprint/of-switch-config-pusher.xml [deleted file]
applications/of-switch-config-pusher/src/test/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusherTest.java
applications/table-miss-enforcer/pom.xml
artifacts/pom.xml

index f802537918d5c5d995911e5079c2b9a4151afebe..4b6f0e18f3eb0ea03fa56ed0cdb6862ca41f0210 100644 (file)
         <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>
index cfb35b674e8b1af1fe886d35a240586409cec2b4..d7e79d3f02c6d1acdc4ca216c5119c0ed6c4e4fd 100644 (file)
 
     <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>
index 12a1094b55dcc4871dacebff483d776eed4e506b..7e307c18e7c76d148df7080b6586ce701adcc039 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.openflowplugin.openflow.ofswitch.config;
 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;
@@ -20,6 +19,7 @@ import org.opendaylight.mdsal.binding.api.DataBroker;
 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;
@@ -27,68 +27,63 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.Fl
 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);
                 }
             }
         }
     }
-
 }
diff --git a/applications/of-switch-config-pusher/src/main/resources/OSGI-INF/blueprint/of-switch-config-pusher.xml b/applications/of-switch-config-pusher/src/main/resources/OSGI-INF/blueprint/of-switch-config-pusher.xml
deleted file mode 100644 (file)
index 578a879..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?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>
index 27d7ebab7b80bfcc5cd475ba197d5d9084bac8b4..68a312adcfd694490194219458a75c40290c2e0b 100644 (file)
@@ -7,26 +7,28 @@
  */
 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;
@@ -35,9 +37,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 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;
 
@@ -50,40 +53,50 @@ public class DefaultConfigPusherTest {
     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();
     }
-
 }
index 5dcdc11aa308a38ffbd89f35f480f41f705a73e7..763bf3623ed43cff6559fc3d38c1274a97dc7f78 100644 (file)
@@ -41,8 +41,6 @@
       <dependency>
           <groupId>org.opendaylight.openflowplugin.applications</groupId>
           <artifactId>device-ownership-service</artifactId>
-          <version>${project.version}</version>
       </dependency>
   </dependencies>
-
 </project>
index 4f069f13328f521cef479a42b847a3033ccc3600..6c700f2b24b92c646fdd5ed68883c018828f5751 100644 (file)
                 <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>