OVSDB-458 DiagStatus support for OVSDB 77/72777/3
authorVishal Thapar <vthapar@redhat.com>
Fri, 8 Jun 2018 04:00:23 +0000 (09:30 +0530)
committerVishal Thapar <vthapar@redhat.com>
Mon, 18 Jun 2018 01:30:18 +0000 (01:30 +0000)
Change-Id: I5a3d46d612d478746d25f1e7c0ef4095f995c839
Signed-off-by: Vishal Thapar <vthapar@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/OvsdbDiagStatusProvider.java [new file with mode: 0644]
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 aa9458794aa24efcfd887835a5ee93d2723dc323..ff97219267145d66b0804faf761ee9cc888aca29 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-Copyright © 2017 Red Hat, Inc. and others.
+Copyright © 2017, 2018 Red Hat, Inc. and others.
 
 This program and the accompanying materials are made available under the
 terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -33,6 +33,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
             <type>xml</type>
             <classifier>features</classifier>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.infrautils</groupId>
+            <artifactId>odl-infrautils-diagstatus</artifactId>
+            <version>1.4.0-SNAPSHOT</version>
+            <type>xml</type>
+            <classifier>features</classifier>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>odl-ovsdb-southbound-api</artifactId>
@@ -52,6 +59,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
             <artifactId>southbound-impl</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+        </dependency>
     </dependencies>
 
     <!--
index cea789fbb85f3af401c919766f6dbcf9f1f1a53e..7cb0fa11293466fd9496ec4eb9074a75c4847497 100644 (file)
@@ -66,6 +66,20 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <artifactId>guava</artifactId>
     </dependency>
     <!-- external dependencies -->
+    <dependency>
+      <groupId>org.opendaylight.infrautils</groupId>
+      <artifactId>diagstatus-api</artifactId>
+      <version>1.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.cdi</groupId>
+      <artifactId>pax-cdi-api</artifactId>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.sonarsource.java</groupId>
       <artifactId>sonar-jacoco-listeners</artifactId>
diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbDiagStatusProvider.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbDiagStatusProvider.java
new file mode 100644 (file)
index 0000000..71185ae
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.southbound;
+
+import org.opendaylight.infrautils.diagstatus.DiagStatusService;
+import org.opendaylight.infrautils.diagstatus.ServiceDescriptor;
+import org.opendaylight.infrautils.diagstatus.ServiceState;
+import org.opendaylight.infrautils.diagstatus.ServiceStatusProvider;
+import org.ops4j.pax.cdi.api.OsgiServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@OsgiServiceProvider(classes = ServiceStatusProvider.class)
+public class OvsdbDiagStatusProvider implements ServiceStatusProvider {
+
+    private static final Logger LOG = LoggerFactory.getLogger(OvsdbDiagStatusProvider.class);
+    private static final String OVSDB_SERVICE_NAME = "OVSDB";
+
+    private final DiagStatusService diagStatusService;
+    private volatile ServiceDescriptor serviceDescriptor;
+
+    public OvsdbDiagStatusProvider(final DiagStatusService diagStatusService) {
+        this.diagStatusService = diagStatusService;
+        diagStatusService.register(OVSDB_SERVICE_NAME);
+    }
+
+
+    public void reportStatus(ServiceState serviceState, String description) {
+        LOG.debug("reporting status as {} for {}", serviceState, OVSDB_SERVICE_NAME);
+        serviceDescriptor = new ServiceDescriptor(OVSDB_SERVICE_NAME, serviceState, description);
+        diagStatusService.report(serviceDescriptor);
+    }
+
+    @Override
+    public ServiceDescriptor getServiceDescriptor() {
+        // TODO Check 6640 port status to report dynamic status
+        return serviceDescriptor;
+    }
+}
index 154c881f0d99d7d1ef0f7949691e0218fcbd65c9..990a0df76f409b417dc32428e3bcbd2874190235 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014, 2018 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -21,6 +21,8 @@ import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 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.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.eos.binding.api.Entity;
@@ -65,16 +67,20 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
     private static final String SKIP_MONITORING_MANAGER_STATUS_PARAM = "skip-monitoring-manager-status";
     private final AtomicBoolean registered = new AtomicBoolean(false);
     private ListenerRegistration<SouthboundProvider> operTopologyRegistration;
+    private final OvsdbDiagStatusProvider ovsdbStatusProvider;
 
     public SouthboundProvider(final DataBroker dataBroker,
             final EntityOwnershipService entityOwnershipServiceDependency,
             final OvsdbConnection ovsdbConnection,
             final DOMSchemaService schemaService,
-            final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer) {
+            final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer,
+            final DiagStatusService diagStatusService) {
+
         this.db = dataBroker;
         this.entityOwnershipService = entityOwnershipServiceDependency;
         registration = null;
         this.ovsdbConnection = ovsdbConnection;
+        ovsdbStatusProvider = new OvsdbDiagStatusProvider(diagStatusService);
 
         this.instanceIdentifierCodec = new InstanceIdentifierCodec(schemaService,
                 bindingNormalizedNodeSerializer);
@@ -86,6 +92,7 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
      */
     public void init() {
         LOG.info("SouthboundProvider Session Initiated");
+        ovsdbStatusProvider.reportStatus(ServiceState.STARTING, "OVSDB initialization in progress");
         this.txInvoker = new TransactionInvokerImpl(db);
         cm = new OvsdbConnectionManager(db, txInvoker, entityOwnershipService, ovsdbConnection,
                 instanceIdentifierCodec);
@@ -119,6 +126,7 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
         try {
             txInvoker.close();
         } catch (InterruptedException e) {
+            ovsdbStatusProvider.reportStatus(ServiceState.ERROR, "OVSDB service shutdown error");
             LOG.debug("SouthboundProvider failed to close TransactionInvoker.");
         }
         cm.close();
@@ -129,6 +137,7 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
             operTopologyRegistration.close();
             operTopologyRegistration = null;
         }
+        ovsdbStatusProvider.reportStatus(ServiceState.UNREGISTERED, "OVSDB Service stopped");
     }
 
     private void initializeOvsdbTopology(LogicalDatastoreType type) {
@@ -176,6 +185,7 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
                     operTopologyRegistration = null;
                 }
             }).start();
+            ovsdbStatusProvider.reportStatus(ServiceState.OPERATIONAL, "OVSDB initialization complete");
         }
     }
 
index a674ab20c77b0b8f4c95ccf8ad50211601c25fc9..987c6b5f4ef879fb757157418b03f40916447790 100644 (file)
@@ -14,8 +14,9 @@
     interface="org.opendaylight.mdsal.dom.api.DOMSchemaService" />
   <reference id="bindingNormalizedNodeSerializer"
     interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer" />
+  <reference id="diagStatusService" interface="org.opendaylight.infrautils.diagstatus.DiagStatusService" />
 
-  <cm:property-placeholder persistent-id="org.opendaylight.ovsdb.southbound" update-strategy="none">
+    <cm:property-placeholder persistent-id="org.opendaylight.ovsdb.southbound" update-strategy="none">
     <cm:default-properties>
       <cm:property name="skip-monitoring-manager-status" value="false"/>
     </cm:default-properties>
@@ -32,6 +33,7 @@
     <argument ref="ovsdbConnection" />
     <argument ref="schemaService" />
     <argument ref="bindingNormalizedNodeSerializer" />
+    <argument ref="diagStatusService"/>
     <property name="skipMonitoringManagerStatus" value="${skip-monitoring-manager-status}"/>
   </bean>
 
index 7da291c494e8dadfeecb6e922fd81ed0cc90f73e..254e559d1869cabcaef8d5bb46f54331c1f7d431 100644 (file)
@@ -25,6 +25,7 @@ import org.mockito.Mockito;
 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.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.eos.binding.api.Entity;
@@ -67,7 +68,8 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                 entityOwnershipService,
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
-                Mockito.mock(BindingNormalizedNodeSerializer.class))) {
+                Mockito.mock(BindingNormalizedNodeSerializer.class),
+                Mockito.mock(DiagStatusService.class))) {
 
             // Initiate the session
             southboundProvider.init();
@@ -92,7 +94,8 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                 entityOwnershipService,
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
-                Mockito.mock(BindingNormalizedNodeSerializer.class))) {
+                Mockito.mock(BindingNormalizedNodeSerializer.class),
+                Mockito.mock(DiagStatusService.class))) {
 
             // Initiate the session
             southboundProvider.init();
@@ -119,7 +122,8 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                 entityOwnershipService,
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
-                Mockito.mock(BindingNormalizedNodeSerializer.class))) {
+                Mockito.mock(BindingNormalizedNodeSerializer.class),
+                Mockito.mock(DiagStatusService.class))) {
 
             southboundProvider.init();
 
@@ -141,7 +145,8 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
                 entityOwnershipService,
                 Mockito.mock(OvsdbConnection.class),
                 Mockito.mock(DOMSchemaService.class),
-                Mockito.mock(BindingNormalizedNodeSerializer.class))) {
+                Mockito.mock(BindingNormalizedNodeSerializer.class),
+                Mockito.mock(DiagStatusService.class))) {
 
             southboundProvider.init();