Migrate HwvtepSouthboundProvider to OSGi DS 14/104414/8
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 16 Feb 2023 06:40:08 +0000 (07:40 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 24 Jan 2024 13:04:11 +0000 (14:04 +0100)
This is a very simple component, migrate it over to OSGi DS, removing
the need for a blueprint.

JIRA: OVSDB-468
Change-Id: Ib48059afa9d3dbbf4ae015ca456bfaa290a91e57
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/reconciliation/configuration/HwvtepReconciliationManager.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/TransactionInvoker.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/TransactionInvokerImpl.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/OSGI-INF/blueprint/hwvtepsouthbound.xml [deleted file]

index f395d294bfd3d21a1eaafa305daf64d7e0db677e..4c7c55364f6ed50879bb0a7f3ed0be92f9ad55b3 100644 (file)
@@ -80,6 +80,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <artifactId>jakarta.annotation-api</artifactId>
       <optional>true</optional>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.karaf.shell</groupId>
       <artifactId>org.apache.karaf.shell.core</artifactId>
index 041efecc8e37318313102c2441a7dbeced8824ae..3c3d3ac217e61a3f6d629e5f8676223de2e53d2d 100644 (file)
@@ -96,14 +96,14 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
         this.db = db;
         this.txInvoker = txInvoker;
         this.entityOwnershipService = entityOwnershipService;
-        this.hwvtepDeviceEntityOwnershipListener = new HwvtepDeviceEntityOwnershipListener(this,entityOwnershipService);
-        this.reconciliationManager = new ReconciliationManager(db);
-        this.hwvtepOperGlobalListener = new HwvtepOperGlobalListener(db, this);
+        hwvtepDeviceEntityOwnershipListener = new HwvtepDeviceEntityOwnershipListener(this,entityOwnershipService);
+        reconciliationManager = new ReconciliationManager(db);
+        hwvtepOperGlobalListener = new HwvtepOperGlobalListener(db, this);
         this.ovsdbConnectionService = ovsdbConnectionService;
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         if (hwvtepDeviceEntityOwnershipListener != null) {
             hwvtepDeviceEntityOwnershipListener.close();
         }
@@ -111,7 +111,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
             hwvtepOperGlobalListener.close();
         }
 
-        for (HwvtepConnectionInstance client: clients.values()) {
+        for (HwvtepConnectionInstance client : clients.values()) {
             client.disconnect();
         }
         DependencyQueue.close();
@@ -518,7 +518,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
     }
 
     public void reconcileConnection(final InstanceIdentifier<Node> iid, final HwvtepGlobalAugmentation hwvtepNode) {
-        this.retryConnection(iid, hwvtepNode,
+        retryConnection(iid, hwvtepNode,
                 ConnectionReconciliationTriggers.ON_CONTROLLER_INITIATED_CONNECTION_FAILURE);
     }
 
index 50b133b22c8ec178bba4db4cc0ea56f95fc7ced2..dca2e0c2fce0079311885dfb35950096bf0c0c30 100644 (file)
@@ -13,7 +13,6 @@ import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
-import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -45,11 +44,16 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 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 HwvtepSouthboundProvider
+@Component(service = HwvtepSouthboundProviderInfo.class)
+public final class HwvtepSouthboundProvider
         implements HwvtepSouthboundProviderInfo, ClusteredDataTreeChangeListener<Topology>, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(HwvtepSouthboundProvider.class);
@@ -69,9 +73,11 @@ public class HwvtepSouthboundProvider
     private ListenerRegistration<HwvtepSouthboundProvider> operTopologyRegistration;
 
     @Inject
-    public HwvtepSouthboundProvider(final DataBroker dataBroker, final EntityOwnershipService entityOwnership,
-            final OvsdbConnection ovsdbConnection, final DOMSchemaService schemaService,
-            final BindingNormalizedNodeSerializer serializer) {
+    @Activate
+    public HwvtepSouthboundProvider(@Reference final DataBroker dataBroker,
+            @Reference final EntityOwnershipService entityOwnership,
+            @Reference final OvsdbConnection ovsdbConnection, @Reference final DOMSchemaService schemaService,
+            @Reference final BindingNormalizedNodeSerializer serializer) {
         this.dataBroker = dataBroker;
         entityOwnershipService = entityOwnership;
         registration = null;
@@ -79,14 +85,6 @@ public class HwvtepSouthboundProvider
         // FIXME: eliminate this static wiring
         HwvtepSouthboundUtil.setInstanceIdentifierCodec(new InstanceIdentifierCodec(schemaService, serializer));
         LOG.info("HwvtepSouthboundProvider ovsdbConnectionService: {}", ovsdbConnection);
-    }
-
-    /**
-     * Used by blueprint when starting the container.
-     */
-    @PostConstruct
-    public void init() {
-        LOG.info("HwvtepSouthboundProvider Session Initiated");
         txInvoker = new TransactionInvokerImpl(dataBroker);
         cm = new HwvtepConnectionManager(dataBroker, txInvoker, entityOwnershipService, ovsdbConnection);
         hwvtepDTListener = new HwvtepDataChangeListener(dataBroker, cm);
@@ -117,20 +115,17 @@ public class HwvtepSouthboundProvider
                 LOG.error("Timed out to get eos notification opening the port now");
             }
         }, HwvtepSouthboundConstants.PORT_OPEN_MAX_DELAY_IN_MINS, TimeUnit.MINUTES);
+
+        LOG.info("HwvtepSouthboundProvider Session Initiated");
     }
 
-    @Override
     @PreDestroy
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    public void close() throws Exception {
-        LOG.info("HwvtepSouthboundProvider Closed");
+    @Deactivate
+    @Override
+    public void close() {
         if (txInvoker != null) {
-            try {
-                txInvoker.close();
-                txInvoker = null;
-            } catch (Exception e) {
-                LOG.error("HWVTEP Southbound Provider failed to close TransactionInvoker", e);
-            }
+            txInvoker.close();
+            txInvoker = null;
         }
         if (cm != null) {
             cm.close();
@@ -156,6 +151,7 @@ public class HwvtepSouthboundProvider
             operTopologyRegistration.close();
             operTopologyRegistration = null;
         }
+        LOG.info("HwvtepSouthboundProvider Closed");
     }
 
     private void initializeHwvtepTopology(final LogicalDatastoreType type) {
@@ -201,8 +197,6 @@ public class HwvtepSouthboundProvider
         }
     }
 
-
-
     private void openOvsdbPort() {
         if (!registered.getAndSet(true)) {
             LOG.info("Starting the ovsdb port");
index 422ff64e5101975a408257077601b862f2b1e049..221da699b5e2fb51a1e304891dcd7015f7a9916f 100644 (file)
@@ -42,7 +42,7 @@ public final class HwvtepReconciliationManager implements ClusteredDataTreeChang
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         if (registration != null) {
             registration.close();
         }
index b46526b736b7d249433724bfa30833f11defc708..bb9f14ca47e6dbf0087f0dfa9fa5e2d9051897ad 100644 (file)
@@ -5,12 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
 
 public interface TransactionInvoker {
 
     void invoke(TransactionCommand command);
 
-    void close() throws Exception;
+    void close();
 }
index c06a0779cfb2093e4c592ce3b48c3074473932d0..3be894d0e56524b54c7e1535ab9b36e5aec8dc46 100644 (file)
@@ -57,7 +57,7 @@ public final class TransactionInvokerImpl implements TransactionInvoker, Transac
 
     public TransactionInvokerImpl(final DataBroker db) {
         this.db = db;
-        this.chain = db.createTransactionChain(this);
+        chain = db.createTransactionChain(this);
         ThreadFactory threadFact = new ThreadFactoryBuilder().setNameFormat("transaction-invoker-impl-%d")
                 .setUncaughtExceptionHandler(this).build();
         executor = Executors.newSingleThreadExecutor(threadFact);
@@ -207,9 +207,9 @@ public final class TransactionInvokerImpl implements TransactionInvoker, Transac
     }
 
     @Override
-    public void close() throws Exception {
-        this.chain.close();
-        this.executor.shutdown();
+    public void close() {
+        chain.close();
+        executor.shutdown();
     }
 
     @Override
diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/OSGI-INF/blueprint/hwvtepsouthbound.xml b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/OSGI-INF/blueprint/hwvtepsouthbound.xml
deleted file mode 100644 (file)
index dc6c001..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-    <!-- FIXME: Auto-generated, to be migrated -->
-    <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
-    <reference id="bindingNormalizedNodeSerializer" interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer"/>
-    <reference id="dOMSchemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
-    <reference id="entityOwnershipService" interface="org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService"/>
-    <reference id="ovsdbConnection" interface="org.opendaylight.ovsdb.lib.OvsdbConnection"/>
-    <bean id="hwvtepSouthboundProvider" class="org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundProvider" init-method="init" destroy-method="close">
-        <argument ref="dataBroker"/>
-        <argument ref="entityOwnershipService"/>
-        <argument ref="ovsdbConnection"/>
-        <argument ref="dOMSchemaService"/>
-        <argument ref="bindingNormalizedNodeSerializer"/>
-    </bean>
-    <service ref="hwvtepSouthboundProvider" interface="org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundProviderInfo"/>
-</blueprint>