defer OVSDB port 6640 opening until system is ready 67/72767/3
authorMichael Vorburger <vorburger@redhat.com>
Thu, 7 Jun 2018 16:13:01 +0000 (18:13 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Mon, 18 Jun 2018 14:08:07 +0000 (16:08 +0200)
JIRA: OVSDB-458
Change-Id: Ic51e0bf3144489b0dc0297191d01c16bdc0e26a5
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
southbound/southbound-features/odl-ovsdb-southbound-impl/pom.xml
southbound/southbound-impl/pom.xml
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java
southbound/southbound-impl/src/main/resources/org/opendaylight/blueprint/southbound.xml
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/SouthboundProviderTest.java

index ff97219267145d66b0804faf761ee9cc888aca29..a22a1dc957d9270f909c3879be74e3f8eb4accec 100644 (file)
@@ -26,6 +26,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <name>ODL :: ovsdb :: ${project.artifactId}</name>
 
     <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.infrautils</groupId>
+            <artifactId>odl-infrautils-ready</artifactId>
+            <version>1.4.0-SNAPSHOT</version>
+            <type>xml</type>
+            <classifier>features</classifier>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>odl-mdsal-broker</artifactId>
index 7cb0fa11293466fd9496ec4eb9074a75c4847497..3b0073bc542e4cfd16cc1b9fbfde11e2b3fa2b67 100644 (file)
@@ -65,6 +65,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.infrautils</groupId>
+      <artifactId>ready-api</artifactId>
+      <version>1.4.0-SNAPSHOT</version>
+    </dependency>
     <!-- external dependencies -->
     <dependency>
       <groupId>org.opendaylight.infrautils</groupId>
index 990a0df76f409b417dc32428e3bcbd2874190235..0365316c45502ddde8442f9fb7903f7fb1153123 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.infrautils.diagstatus.DiagStatusService;
 import org.opendaylight.infrautils.diagstatus.ServiceState;
+import org.opendaylight.infrautils.ready.SystemReadyMonitor;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.eos.binding.api.Entity;
@@ -47,7 +48,9 @@ import org.slf4j.LoggerFactory;
 public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topology>, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(SouthboundProvider.class);
+
     private static final String ENTITY_TYPE = "ovsdb-southbound-provider";
+    private static final String SKIP_MONITORING_MANAGER_STATUS_PARAM = "skip-monitoring-manager-status";
 
     public static DataBroker getDb() {
         return db;
@@ -64,7 +67,8 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
     private SouthboundPluginInstanceEntityOwnershipListener providerOwnershipChangeListener;
     private final OvsdbConnection ovsdbConnection;
     private final InstanceIdentifierCodec instanceIdentifierCodec;
-    private static final String SKIP_MONITORING_MANAGER_STATUS_PARAM = "skip-monitoring-manager-status";
+    private final SystemReadyMonitor systemReadyMonitor;
+
     private final AtomicBoolean registered = new AtomicBoolean(false);
     private ListenerRegistration<SouthboundProvider> operTopologyRegistration;
     private final OvsdbDiagStatusProvider ovsdbStatusProvider;
@@ -74,16 +78,16 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
             final OvsdbConnection ovsdbConnection,
             final DOMSchemaService schemaService,
             final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer,
+            final SystemReadyMonitor systemReadyMonitor,
             final DiagStatusService diagStatusService) {
-
         this.db = dataBroker;
         this.entityOwnershipService = entityOwnershipServiceDependency;
         registration = null;
         this.ovsdbConnection = ovsdbConnection;
-        ovsdbStatusProvider = new OvsdbDiagStatusProvider(diagStatusService);
-
+        this.ovsdbStatusProvider = new OvsdbDiagStatusProvider(diagStatusService);
         this.instanceIdentifierCodec = new InstanceIdentifierCodec(schemaService,
                 bindingNormalizedNodeSerializer);
+        this.systemReadyMonitor = systemReadyMonitor;
         LOG.info("SouthboundProvider ovsdbConnectionService Initialized");
     }
 
@@ -177,7 +181,11 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
         if (!registered.getAndSet(true)) {
             LOG.info("Starting the ovsdb port");
             ovsdbConnection.registerConnectionListener(cm);
-            ovsdbConnection.startOvsdbManager();
+            LOG.info("Registering deferred system ready listener to start OVSDB Manager later");
+            systemReadyMonitor.registerListener(() -> {
+                ovsdbConnection.startOvsdbManager();
+                LOG.info("Started OVSDB Manager (in system ready listener)");
+            });
             //mdsal registration/deregistration in mdsal update callback should be avoided
             new Thread(() -> {
                 if (operTopologyRegistration != null) {
index 987c6b5f4ef879fb757157418b03f40916447790..9402c7249d4bfba192ad2a97095bcb38f922bc76 100644 (file)
@@ -14,6 +14,8 @@
     interface="org.opendaylight.mdsal.dom.api.DOMSchemaService" />
   <reference id="bindingNormalizedNodeSerializer"
     interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer" />
+  <reference id="systemReadyMonitor"
+    interface="org.opendaylight.infrautils.ready.SystemReadyMonitor" />
   <reference id="diagStatusService" interface="org.opendaylight.infrautils.diagstatus.DiagStatusService" />
 
     <cm:property-placeholder persistent-id="org.opendaylight.ovsdb.southbound" update-strategy="none">
@@ -33,6 +35,7 @@
     <argument ref="ovsdbConnection" />
     <argument ref="schemaService" />
     <argument ref="bindingNormalizedNodeSerializer" />
+    <argument ref="systemReadyMonitor" />
     <argument ref="diagStatusService"/>
     <property name="skipMonitoringManagerStatus" value="${skip-monitoring-manager-status}"/>
   </bean>
index 254e559d1869cabcaef8d5bb46f54331c1f7d431..3551b5e3108eddf4b26e017c47ef4dd1835a1afa 100644 (file)
@@ -26,6 +26,9 @@ import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.infrautils.diagstatus.DiagStatusService;
+import org.opendaylight.infrautils.ready.SystemReadyListener;
+import org.opendaylight.infrautils.ready.SystemReadyMonitor;
+import org.opendaylight.infrautils.ready.SystemState;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.eos.binding.api.Entity;
@@ -69,6 +72,7 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
                 Mockito.mock(BindingNormalizedNodeSerializer.class),
+                new ImmediateSystemReadyMonitor(),
                 Mockito.mock(DiagStatusService.class))) {
 
             // Initiate the session
@@ -95,6 +99,7 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
                 Mockito.mock(BindingNormalizedNodeSerializer.class),
+                new ImmediateSystemReadyMonitor(),
                 Mockito.mock(DiagStatusService.class))) {
 
             // Initiate the session
@@ -123,6 +128,7 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
                 Mockito.mock(BindingNormalizedNodeSerializer.class),
+                new ImmediateSystemReadyMonitor(),
                 Mockito.mock(DiagStatusService.class))) {
 
             southboundProvider.init();
@@ -146,6 +152,7 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
                 Mockito.mock(BindingNormalizedNodeSerializer.class),
+                new ImmediateSystemReadyMonitor(),
                 Mockito.mock(DiagStatusService.class))) {
 
             southboundProvider.init();
@@ -177,4 +184,18 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                     topologyIid).checkedGet().isPresent());
         }
     }
+
+    private static class ImmediateSystemReadyMonitor implements SystemReadyMonitor {
+
+        @Override
+        public SystemState getSystemState() {
+            return SystemState.ACTIVE;
+        }
+
+        @Override
+        public void registerListener(SystemReadyListener listener) {
+            listener.onSystemBootReady();
+        }
+
+    }
 }