Use config for southbound (take 2) 78/27578/9
authorStephen Kitt <skitt@redhat.com>
Wed, 23 Sep 2015 16:25:39 +0000 (18:25 +0200)
committerSam Hague <shague@redhat.com>
Fri, 23 Oct 2015 21:14:06 +0000 (21:14 +0000)
Remove unused/commented code
ConfigActivator is gone completely.
The multi-threading tests in SouthboundIT are limited to a single
thread to get the tests to pass for now (we need to handle
connections/disconnections properly).

Change-Id: I544a2d4f802c1ccdfe9593a0722ad0e0c8f27139
Signed-off-by: Stephen Kitt <skitt@redhat.com>
Signed-off-by: Sam Hague <shague@redhat.com>
13 files changed:
library/impl/pom.xml
library/impl/src/main/config/default-config.xml
library/impl/src/main/java/org/opendaylight/ovsdb/lib/ConfigActivator.java [deleted file]
library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/LibraryProvider.java
library/impl/src/main/yang/library-impl.yang
southbound/southbound-features/pom.xml
southbound/southbound-features/src/main/features/features.xml
southbound/southbound-impl/pom.xml
southbound/southbound-impl/src/main/config/default-config.xml
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java
southbound/southbound-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/southbound/impl/rev141210/SouthboundImplModule.java
southbound/southbound-impl/src/main/yang/southbound-impl.yang
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java

index 8112ddc1bf8813363d2eb4007d4480bcd50840b6..0dac7dd7951ef1ffad26ccd625688512db6e7545 100644 (file)
@@ -94,6 +94,19 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       </testResource>
     </testResources>
     <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>
+              org.opendaylight.ovsdb.lib.*,
+              org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.library.impl.rev141210.*
+            </Export-Package>
+          </instructions>
+        </configuration>
+      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-checkstyle-plugin</artifactId>
index e8b159f436ad3b6d262b87e754c20499a12cd00d..c0b80df871f4daf919d4b2c3621132c87c619ae4 100644 (file)
@@ -25,6 +25,15 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
           </broker>
         </module>
       </modules>
+      <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+        <service>
+          <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:library:impl">prefix:connection-service</type>
+          <instance>
+            <name>connection-service</name>
+            <provider>/modules/module[type='library'][name='library-default']</provider>
+          </instance>
+        </service>
+      </services>
     </data>
   </configuration>
 </snapshot>
diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/ConfigActivator.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/ConfigActivator.java
deleted file mode 100644 (file)
index 1092ccd..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright © 2015 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.lib;
-
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * "Configuration" activator for the OVSDB library.
- */
-public class ConfigActivator implements BundleActivator {
-    /**
-     * Logger.
-     */
-    private static final Logger LOG = LoggerFactory.getLogger(ConfigActivator.class);
-
-    /**
-     * Parent provider context.
-     */
-    private final BindingAwareBroker.ProviderContext providerContext;
-
-    /**
-     * Creates an instance of the activator.
-     *
-     * @param providerContext The parent provider context.
-     */
-    public ConfigActivator(BindingAwareBroker.ProviderContext providerContext) {
-        LOG.info("OVSDB library ConfigActivator created.");
-        this.providerContext = providerContext;
-    }
-
-    @Override
-    public void start(BundleContext context) throws Exception {
-        LOG.info("OVSDB library ConfigActivator starting.");
-        context.registerService(OvsdbConnection.class, new OvsdbConnectionService(), null);
-        // TODO Need to indicate that OvsdbConnectionListeners should register with the connection service
-        // (if I've understood correctly, the old dependency manager would call registerConnectionListener()
-        // whenever an instance of OvsdbConnection is retrieved, and unregisterConnectionListener() when it
-        // is no longer used)
-        // (All current users register manually...)
-    }
-
-    @Override
-    public void stop(BundleContext context) throws Exception {
-        LOG.info("OVSDB library ConfigActivator stopping.");
-    }
-}
index 63c5783b82a2bb0d6a6cdd3552afd4f256bfd7e6..30cd8119858224fec2a3f1e8f70dced848a50177 100644 (file)
@@ -7,46 +7,76 @@
  */
 package org.opendaylight.ovsdb.lib.impl;
 
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import java.net.InetAddress;
+import java.util.Collection;
+
+import javax.net.ssl.SSLContext;
+
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
-import org.opendaylight.ovsdb.lib.ConfigActivator;
+import org.opendaylight.ovsdb.lib.OvsdbClient;
 import org.opendaylight.ovsdb.lib.OvsdbConnection;
+import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class LibraryProvider implements BindingAwareProvider, AutoCloseable {
+public class LibraryProvider implements BindingAwareProvider, AutoCloseable, OvsdbConnection {
 
     private static final Logger LOG = LoggerFactory.getLogger(LibraryProvider.class);
-    private final BundleContext bundleContext;
-    private DataBroker dataBroker;
-    private ConfigActivator activator;
 
     public LibraryProvider(BundleContext bundleContext) {
         LOG.info("LibraryProvider: bundleContext: {}", bundleContext);
-        this.bundleContext = bundleContext;
     }
 
     @Override
     public void onSessionInitiated(ProviderContext providerContext) {
         LOG.info("LibraryProvider Session Initiated");
-        dataBroker = providerContext.getSALService(DataBroker.class);
-        LOG.info("LibraryProvider: onSessionInitiated dataBroker: {}", dataBroker);
-        this.activator = new ConfigActivator(providerContext);
-        try {
-            activator.start(bundleContext);
-        } catch (Exception e) {
-            LOG.warn("Failed to start LibraryProvider: ", e);
-        }
     }
 
     @Override
     public void close() throws Exception {
         LOG.info("LibraryProvider Closed");
-        if (activator != null) {
-            activator.stop(bundleContext);
-        }
     }
 
+    @Override
+    public OvsdbClient connect(InetAddress address, int port) {
+        return OvsdbConnectionService.getService().connect(address, port);
+    }
+
+    @Override
+    public OvsdbClient connectWithSsl(
+            InetAddress address, int port, SSLContext sslContext) {
+        return OvsdbConnectionService.getService().connectWithSsl(address, port, sslContext);
+    }
+
+    @Override
+    public void disconnect(OvsdbClient client) {
+        OvsdbConnectionService.getService().disconnect(client);
+    }
+
+    @Override
+    public boolean startOvsdbManager(int ovsdbListenPort) {
+        return OvsdbConnectionService.getService().startOvsdbManager(ovsdbListenPort);
+    }
+
+    @Override
+    public boolean startOvsdbManagerWithSsl(int ovsdbListenPort, SSLContext sslContext) {
+        return OvsdbConnectionService.getService().startOvsdbManagerWithSsl(ovsdbListenPort, sslContext);
+    }
+
+    @Override
+    public void registerConnectionListener(OvsdbConnectionListener listener) {
+        OvsdbConnectionService.getService().registerConnectionListener(listener);
+    }
+
+    @Override
+    public void unregisterConnectionListener(OvsdbConnectionListener listener) {
+        OvsdbConnectionService.getService().unregisterConnectionListener(listener);
+    }
+
+    @Override
+    public Collection<OvsdbClient> getConnections() {
+        return OvsdbConnectionService.getService().getConnections();
+    }
 }
index 97b0f086adcd487c221459b1b20c17dc15c5c7b2..21932fb6d09ec6b4b7a816e2cd53bc4e06e07bbc 100644 (file)
@@ -17,6 +17,12 @@ module library {
     identity library {
         base config:module-type;
         config:java-name-prefix Library;
+        config:provided-service connection-service;
+    }
+
+    identity connection-service {
+        base config:service-type;
+        config:java-class "org.opendaylight.ovsdb.lib.OvsdbConnection";
     }
 
     augment "/config:modules/config:module/config:configuration" {
index eb3a9506cf4a2b34cea1869fef780563a49a0e5c..fb2b3fe623faac552e471f4843d41199ab133a3b 100644 (file)
@@ -119,5 +119,12 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
       <artifactId>southbound-api</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>library-features</artifactId>
+      <type>xml</type>
+      <classifier>features</classifier>
+      <version>${project.version}</version>
+    </dependency>
   </dependencies>
 </project>
index b66393266559ec1f479b6041a4d4346439933b22..db97088b5dc9252ece6d6731747a7e0fd95ed1af 100644 (file)
@@ -14,6 +14,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <repository>mvn:org.opendaylight.controller/features-mdsal/${mdsal.version}/xml/features</repository>
   <repository>mvn:org.opendaylight.netconf/features-restconf/${restconf.version}/xml/features</repository>
   <repository>mvn:org.opendaylight.mdsal.model/features-mdsal-model/${mdsal.model.version}/xml/features</repository>
+  <repository>mvn:org.opendaylight.ovsdb/library-features/${project.version}/xml/features</repository>
   <feature name='odl-ovsdb-southbound-api' version='${project.version}' description='OpenDaylight :: southbound :: api '>
     <feature version='${mdsal.model.version}'>odl-mdsal-models</feature>
     <bundle>mvn:org.opendaylight.ovsdb/southbound-api/${project.version}</bundle>
@@ -22,6 +23,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <feature version='${mdsal.version}'>odl-mdsal-broker</feature>
     <feature version='${project.version}'>odl-ovsdb-southbound-api</feature>
     <bundle>mvn:org.opendaylight.ovsdb/southbound-impl/${project.version}</bundle>
+    <bundle>mvn:org.opendaylight.ovsdb/library/${project.version}</bundle>
     <bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.version}</bundle>
     <bundle>mvn:com.fasterxml.jackson.core/jackson-core/${jackson.version}</bundle>
     <bundle>mvn:com.fasterxml.jackson.core/jackson-databind/${jackson.version}</bundle>
@@ -34,6 +36,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <bundle>mvn:io.netty/netty-common/${netty.version}</bundle>
     <bundle>mvn:io.netty/netty-handler/${netty.version}</bundle>
     <bundle>mvn:io.netty/netty-transport/${netty.version}</bundle>
+    <feature version="${project.version}">odl-ovsdb-library</feature>
     <configfile finalname="etc/opendaylight/karaf/southbound-impl-default-config.xml">mvn:org.opendaylight.ovsdb/southbound-impl/${project.version}/xml/config</configfile>
   </feature>
   <feature name='odl-ovsdb-southbound-impl-rest' version='${project.version}' description='OpenDaylight :: southbound :: impl :: REST '>
index f5e09078a0307523e4866dfe6b8938ff2397e931..4d94cb1921a4296e94ae1c4a6496742ac2740697 100644 (file)
@@ -102,8 +102,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
         <artifactId>maven-bundle-plugin</artifactId>
         <configuration>
           <instructions>
-            <Private-Package>!org.opendaylight.ovsdb.lib.osgi,org.opendaylight.ovsdb.lib.*,org.opendaylight.ovsdb.schema.openvswitch</Private-Package>
-            <Export-Package>org.opendaylight.ovsdb.southbound.*,org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.southbound.impl.rev141210</Export-Package>
+            <!--<Private-Package>!org.opendaylight.ovsdb.lib.osgi,org.opendaylight.ovsdb.lib.*,org.opendaylight.ovsdb.schema.openvswitch</Private-Package>-->
+            <Export-Package>org.opendaylight.ovsdb.southbound.*,org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.southbound.impl.rev141210.*</Export-Package>
           </instructions>
         </configuration>
       </plugin>
index 547f31ca685dacb094f8a938adea851ac62d6cef..92e91c2803d8f472b297e1f25c57afff833368a3 100644 (file)
@@ -9,7 +9,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 -->
 <snapshot>
   <required-capabilities>
-    <!--<capability>urn:opendaylight:params:xml:ns:yang:southbound:impl?module=southbound-impl&amp;revision=2015-01-05</capability>-->
+    <capability>urn:opendaylight:params:xml:ns:yang:southbound:impl?module=southbound-impl&amp;revision=2014-12-10</capability>
+    <capability>urn:opendaylight:params:xml:ns:yang:library:impl?module=library&amp;revision=2014-12-10</capability>
   </required-capabilities>
   <configuration>
 
@@ -34,6 +35,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
              <type xmlns:ns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:entity-ownership-service">ns:entity-ownership-service</type>
              <name>entity-ownership-service</name>
           </clustering-entity-ownership-service>
+          <connection-service>
+            <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:library:impl">prefix:connection-service</type>
+            <name>connection-service</name>
+          </connection-service>
         </module>
       </modules>
     </data>
index 0b388af8c5a70d2967ab3355149cd0ee95df9096..008aafcd50130baef2ff5382db1111bcc465b0f4 100644 (file)
@@ -57,9 +57,12 @@ public class SouthboundProvider implements BindingAwareProvider, AutoCloseable {
 
 
     public SouthboundProvider(
-            EntityOwnershipService entityOwnershipServiceDependency) {
+            EntityOwnershipService entityOwnershipServiceDependency,
+            OvsdbConnection ovsdbConnection) {
         this.entityOwnershipService = entityOwnershipServiceDependency;
         registration = null;
+        this.ovsdbConnection = ovsdbConnection;
+        LOG.info("SouthboundProvider ovsdbConnectionService: {}", ovsdbConnection);
     }
 
     @Override
@@ -83,11 +86,8 @@ public class SouthboundProvider implements BindingAwareProvider, AutoCloseable {
             if (ownershipStateOpt.isPresent()) {
                 EntityOwnershipState ownershipState = ownershipStateOpt.get();
                 if (ownershipState.hasOwner() && !ownershipState.isOwner()) {
-                    if (ovsdbConnection == null) {
-                        ovsdbConnection = new OvsdbConnectionService();
-                        ovsdbConnection.registerConnectionListener(cm);
-                        ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT);
-                    }
+                    ovsdbConnection.registerConnectionListener(cm);
+                    ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT);
                 }
             }
         } catch (CandidateAlreadyRegisteredException e) {
index 5014d144549a43120d1f984a965540077020b698..5c543dfc4d0898b624ffecb032996f1058e59417 100644 (file)
@@ -31,7 +31,8 @@ public class SouthboundImplModule extends org.opendaylight.yang.gen.v1.urn.opend
     public java.lang.AutoCloseable createInstance() {
         SouthboundUtil.setInstanceIdentifierCodec(new InstanceIdentifierCodec(getSchemaServiceDependency(),
                 getBindingNormalizedNodeSerializerDependency()));
-        SouthboundProvider provider = new SouthboundProvider(getClusteringEntityOwnershipServiceDependency());
+        SouthboundProvider provider = new SouthboundProvider(getClusteringEntityOwnershipServiceDependency(),
+                getConnectionServiceDependency());
         getBrokerDependency().registerProvider(provider);
         return provider;
     }
index 89a2eac74f8fe0e88981eb50bd0d79e46a257e35..f4c98d40e6c4eff6f4660196185848a2c0f71a3a 100644 (file)
@@ -7,6 +7,7 @@ module southbound-impl {
     import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
     import opendaylight-md-sal-dom {prefix dom; revision-date 2013-10-28;}
     import opendaylight-entity-ownership-service {prefix eos; revision-date 2015-08-10;}
+    import library { prefix library; revision-date 2014-12-10; }
 
     description
         "Service definition for southbound project";
@@ -56,6 +57,14 @@ module southbound-impl {
                     }
                 }
             }
+            container connection-service {
+                uses config:service-ref {
+                    refine type {
+                        mandatory true;
+                        config:required-identity library:connection-service;
+                    }
+                }
+            }
         }
     }
 }
index 2322031b4bb54b2829ebbc2f157b294792e8b5a9..118d859d797e8176a53905ec41457616bdbecfed 100644 (file)
@@ -129,7 +129,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     private static final Logger LOG = LoggerFactory.getLogger(SouthboundIT.class);
     private static final int OVSDB_UPDATE_TIMEOUT = 1000;
     private static final String FORMAT_STR = "%s_%s_%d";
-    public static final int NUM_THREADS = 4;
+    public static final int NUM_THREADS = 1;
     private static String addressStr;
     private static int portNumber;
     private static String connectionType;