From 53db5e7daf9b1b2577709ae0389dac99c77e9a85 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 7 Feb 2024 10:12:29 +0100 Subject: [PATCH] Ditch blueprint from of-switch-config-pusher 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 --- applications/lldp-speaker/pom.xml | 2 - applications/of-switch-config-pusher/pom.xml | 37 ++++++----- .../ofswitch/config/DefaultConfigPusher.java | 63 +++++++++---------- .../blueprint/of-switch-config-pusher.xml | 21 ------- .../config/DefaultConfigPusherTest.java | 53 ++++++++++------ applications/table-miss-enforcer/pom.xml | 2 - artifacts/pom.xml | 5 ++ 7 files changed, 87 insertions(+), 96 deletions(-) delete mode 100644 applications/of-switch-config-pusher/src/main/resources/OSGI-INF/blueprint/of-switch-config-pusher.xml diff --git a/applications/lldp-speaker/pom.xml b/applications/lldp-speaker/pom.xml index f802537918..4b6f0e18f3 100644 --- a/applications/lldp-speaker/pom.xml +++ b/applications/lldp-speaker/pom.xml @@ -41,12 +41,10 @@ org.opendaylight.openflowplugin.applications device-ownership-service - ${project.version} org.opendaylight.infrautils infrautils-util - diff --git a/applications/of-switch-config-pusher/pom.xml b/applications/of-switch-config-pusher/pom.xml index cfb35b674e..d7e79d3f02 100644 --- a/applications/of-switch-config-pusher/pom.xml +++ b/applications/of-switch-config-pusher/pom.xml @@ -14,20 +14,26 @@ - org.opendaylight.openflowplugin - openflowplugin-api + com.guicedee.services + javax.inject + true - org.opendaylight.mdsal - mdsal-binding-api + jakarta.annotation + jakarta.annotation-api + true - org.opendaylight.openflowplugin.model - model-inventory + org.opendaylight.infrautils + infrautils-util - org.opendaylight.openflowplugin.model - model-flow-service + org.opendaylight.mdsal + mdsal-binding-api + + + org.opendaylight.openflowplugin + openflowplugin-api org.opendaylight.openflowplugin @@ -36,21 +42,18 @@ org.opendaylight.openflowplugin.applications device-ownership-service - ${project.version} - org.opendaylight.infrautils - infrautils-util + org.opendaylight.openflowplugin.model + model-inventory - com.guicedee.services - javax.inject - true + org.opendaylight.openflowplugin.model + model-flow-service - jakarta.annotation - jakarta.annotation-api - true + org.osgi + org.osgi.service.component.annotations diff --git a/applications/of-switch-config-pusher/src/main/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusher.java b/applications/of-switch-config-pusher/src/main/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusher.java index 12a1094b55..7e307c18e7 100644 --- a/applications/of-switch-config-pusher/src/main/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusher.java +++ b/applications/of-switch-config-pusher/src/main/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusher.java @@ -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 { +@Component(service = { }) +public final class DefaultConfigPusher implements AutoCloseable, ClusteredDataTreeChangeListener { 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> modifications) { - for (DataTreeModification 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 index 578a879764..0000000000 --- a/applications/of-switch-config-pusher/src/main/resources/OSGI-INF/blueprint/of-switch-config-pusher.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - diff --git a/applications/of-switch-config-pusher/src/test/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusherTest.java b/applications/of-switch-config-pusher/src/test/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusherTest.java index 27d7ebab7b..68a312adcf 100644 --- a/applications/of-switch-config-pusher/src/test/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusherTest.java +++ b/applications/of-switch-config-pusher/src/test/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusherTest.java @@ -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_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 dataTreeModification; @Mock + private DataObjectModification dataObjectModification; + @Mock private DeviceOwnershipService deviceOwnershipService; + @Mock + private ListenerRegistration reg; @Captor private ArgumentCaptor setConfigInputCaptor; @Before public void setUp() { - doReturn(RpcResultBuilder.success().buildFuture()).when(nodeConfigService).setConfig(any()); - defaultConfigPusher = new DefaultConfigPusher(nodeConfigService, Mockito.mock(DataBroker.class), - deviceOwnershipService); - final DataTreeIdentifier 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(); } - } diff --git a/applications/table-miss-enforcer/pom.xml b/applications/table-miss-enforcer/pom.xml index 5dcdc11aa3..763bf3623e 100644 --- a/applications/table-miss-enforcer/pom.xml +++ b/applications/table-miss-enforcer/pom.xml @@ -41,8 +41,6 @@ org.opendaylight.openflowplugin.applications device-ownership-service - ${project.version} - diff --git a/artifacts/pom.xml b/artifacts/pom.xml index 4f069f1332..6c700f2b24 100644 --- a/artifacts/pom.xml +++ b/artifacts/pom.xml @@ -167,6 +167,11 @@ bulk-o-matic ${project.version} + + ${project.groupId}.applications + device-ownership-service + ${project.version} + ${project.groupId}.applications forwardingrules-manager -- 2.36.6