Deprecate SwitchConnectionProviderModule 58/38658/2
authorTom Pantelis <tpanteli@brocade.com>
Mon, 9 May 2016 23:59:15 +0000 (19:59 -0400)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Wed, 1 Jun 2016 08:09:28 +0000 (08:09 +0000)
Deprecate the SwitchConnectionProviderModule and corresponding yang.
The createInstance method was modified to obtain the corresponding
service instance created via blueprint from the OSGi registry using
a ServiceTracker.

Change-Id: Ie156466e08d4a5758ceae63f6c877f8210632cfb
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/SwitchConnectionProviderModule.java
openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/SwitchConnectionProviderModuleFactory.java
openflow-protocol-impl/src/main/yang/openflow-switch-connection-provider-impl.yang
openflow-protocol-spi/src/main/yang/openflow-switch-connection-provider.yang

index 6ded9bfbb2cb33100225070873ecf4e76efc0a2f..a9756bdd32c55339e076f676bb324196cb017a25 100644 (file)
@@ -9,29 +9,19 @@
 */
 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
 
-import com.google.common.base.MoreObjects;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.List;
-
-import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
-import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
-import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
-import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import com.google.common.reflect.AbstractInvocationHandler;
+import com.google.common.reflect.Reflection;
+import java.lang.reflect.Method;
+import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
+import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
+import org.osgi.framework.BundleContext;
 
 /**
-*
-*/
-public final class SwitchConnectionProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractSwitchConnectionProviderModule
- {
-
-    private static Logger LOG = LoggerFactory
-            .getLogger(SwitchConnectionProviderModule.class);
+ * @deprecated Replaced by blueprint wiring
+ */
+@Deprecated
+public final class SwitchConnectionProviderModule extends AbstractSwitchConnectionProviderModule {
+    private BundleContext bundleContext;
 
     /**
      * @param identifier
@@ -53,160 +43,34 @@ public final class SwitchConnectionProviderModule extends org.opendaylight.yang.
     }
 
     @Override
-    protected void customValidation(){
-        // Add custom validation for module attributes here.
-    }
-
-    @Override
-    public java.lang.AutoCloseable createInstance() {
-        LOG.info("SwitchConnectionProvider started.");
-        final SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
-        try {
-            final ConnectionConfiguration connConfiguration = createConnectionConfiguration();
-            switchConnectionProviderImpl.setConfiguration(connConfiguration);
-        } catch (final UnknownHostException e) {
-            throw new IllegalArgumentException(e.getMessage(), e);
-        }
-        return switchConnectionProviderImpl;
-    }
-
-    /**
-     * @return instance configuration object
-     * @throws UnknownHostException
-     */
-    private ConnectionConfiguration createConnectionConfiguration() throws UnknownHostException {
-        final InetAddress address = extractIpAddressBin(getAddress());
-        final Integer port = getPort();
-        final long switchIdleTimeout = getSwitchIdleTimeout();
-        final Tls tlsConfig = getTls();
-        final Threads threads = getThreads();
-        final Boolean useBarrier = getUseBarrier();
-        final TransportProtocol transportProtocol = getTransportProtocol();
-
-        return new ConnectionConfiguration() {
-            @Override
-            public InetAddress getAddress() {
-                return address;
-            }
-            @Override
-            public int getPort() {
-                return port;
-            }
-            @Override
-            public Object getTransferProtocol() {
-                return transportProtocol;
-            }
-            @Override
-            public TlsConfiguration getTlsConfiguration() {
-                if (tlsConfig == null || !(TransportProtocol.TLS.equals(transportProtocol))) {
-                    return null;
-                }
-                return new TlsConfiguration() {
-                    @Override
-                    public KeystoreType getTlsTruststoreType() {
-                        return MoreObjects.firstNonNull(tlsConfig.getTruststoreType(), null);
-                    }
-                    @Override
-                    public String getTlsTruststore() {
-                        return MoreObjects.firstNonNull(tlsConfig.getTruststore(), null);
-                    }
-                    @Override
-                    public KeystoreType getTlsKeystoreType() {
-                        return MoreObjects.firstNonNull(tlsConfig.getKeystoreType(), null);
-                    }
-                    @Override
-                    public String getTlsKeystore() {
-                        return MoreObjects.firstNonNull(tlsConfig.getKeystore(), null);
-                    }
-                    @Override
-                    public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsKeystorePathType() {
-                        return MoreObjects.firstNonNull(tlsConfig.getKeystorePathType(), null);
-                    }
-                    @Override
-                    public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsTruststorePathType() {
-                        return MoreObjects.firstNonNull(tlsConfig.getTruststorePathType(), null);
-                    }
-                    @Override
-                    public String getKeystorePassword() {
-                        return MoreObjects.firstNonNull(tlsConfig.getKeystorePassword(), null);
-                    }
-                    @Override
-                    public String getCertificatePassword() {
-                        return MoreObjects.firstNonNull(tlsConfig.getCertificatePassword(), null);
-                    }
-                    @Override
-                    public String getTruststorePassword() {
-                        return MoreObjects.firstNonNull(tlsConfig.getTruststorePassword(), null);
-                    }
-                    @Override
-                    public List<String> getCipherSuites() {
-                        return tlsConfig.getCipherSuites();
-                    }
-                };
-            }
-            @Override
-            public long getSwitchIdleTimeout() {
-                return switchIdleTimeout;
-            }
+    public AutoCloseable createInstance() {
+        // The service is provided via blueprint so wait for and return it here for backwards compatibility.
+        String typeFilter = String.format("(type=%s)", getIdentifier().getInstanceName());
+        final WaitingServiceTracker<SwitchConnectionProvider> tracker = WaitingServiceTracker.create(
+                SwitchConnectionProvider.class, bundleContext, typeFilter);
+        final SwitchConnectionProvider actualService = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
+
+        // We don't want to call close on the actual service as its life cycle is controlled by blueprint but
+        // we do want to close the tracker so create a proxy to override close appropriately.
+        return Reflection.newProxy(SwitchConnectionProvider.class, new AbstractInvocationHandler() {
             @Override
-            public Object getSslContext() {
-                // TODO Auto-generated method stub
-                return null;
-            }
-            @Override
-            public ThreadConfiguration getThreadConfiguration() {
-                if (threads == null) {
+            protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
+                if (method.getName().equals("close")) {
+                    tracker.close();
                     return null;
+                } else {
+                    return method.invoke(actualService, args);
                 }
-                return new ThreadConfiguration() {
-
-                    @Override
-                    public int getWorkerThreadCount() {
-                        return threads.getWorkerThreads();
-                    }
-
-                    @Override
-                    public int getBossThreadCount() {
-                        return threads.getBossThreads();
-                    }
-                };
             }
-
-            @Override
-            public boolean useBarrier() {
-                return useBarrier;
-            }
-        };
+        });
     }
 
-    /**
-     * @param address
-     * @return
-     * @throws UnknownHostException
-     */
-    private static InetAddress extractIpAddressBin(final IpAddress address) throws UnknownHostException {
-        byte[] addressBin = null;
-        if (address != null) {
-            if (address.getIpv4Address() != null) {
-                addressBin = address2bin(address.getIpv4Address().getValue());
-            } else if (address.getIpv6Address() != null) {
-                addressBin = address2bin(address.getIpv6Address().getValue());
-            }
-        }
-
-        if (addressBin == null) {
-            return null;
-        } else {
-            return InetAddress.getByAddress(addressBin);
-        }
+    public void setBundleContext(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
     }
 
-    /**
-     * @param value
-     * @return
-     */
-    private static byte[] address2bin(final String value) {
-        //TODO: translate ipv4 or ipv6 into byte[]
-        return null;
+    @Override
+    public boolean canReuseInstance(AbstractSwitchConnectionProviderModule oldModule) {
+        return true;
     }
 }
index 6bf14239d91305c445db4085adc4abd0864db6b0..ca41fc392378e7e6f7d098b3403cf80921faec1c 100644 (file)
@@ -9,11 +9,28 @@
 */
 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
 
-/**
-*
-*/
-public class SwitchConnectionProviderModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractSwitchConnectionProviderModuleFactory
-{
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.osgi.framework.BundleContext;
 
+/**
+ * @deprecated Replaced by blueprint wiring
+ */
+@Deprecated
+public class SwitchConnectionProviderModuleFactory extends AbstractSwitchConnectionProviderModuleFactory {
+    @Override
+    public SwitchConnectionProviderModule instantiateModule(String instanceName, DependencyResolver dependencyResolver,
+            SwitchConnectionProviderModule oldModule, AutoCloseable oldInstance, BundleContext bundleContext) {
+        SwitchConnectionProviderModule module = super.instantiateModule(instanceName, dependencyResolver, oldModule,
+                oldInstance, bundleContext);
+        module.setBundleContext(bundleContext);
+        return module;
+    }
 
+    @Override
+    public SwitchConnectionProviderModule instantiateModule(String instanceName, DependencyResolver dependencyResolver,
+            BundleContext bundleContext) {
+        SwitchConnectionProviderModule module = super.instantiateModule(instanceName, dependencyResolver, bundleContext);
+        module.setBundleContext(bundleContext);
+        return module;
+    }
 }
index 1610ff1badea324d976253423731eae6fecbf3fe..b41b3847474c688ee9b69a2859095cea7c1f956a 100644 (file)
@@ -21,6 +21,7 @@ module openflow-switch-connection-provider-impl {
         base "config:module-type";
         config:provided-service openflow-switch-connection-provider:openflow-switch-connection-provider;
         config:java-name-prefix SwitchConnectionProvider;
+        status deprecated;
     }
 
     identity statistics-collection-service-impl {
index 3ed7c20bf08297e8f88f8b4d2f8f04b23cc8b340..25b38d19aa7211151a2bfee0928579fd4a2fc43b 100644 (file)
@@ -16,6 +16,8 @@ module openflow-switch-connection-provider {
     identity openflow-switch-connection-provider {
          base "config:service-type";
          config:java-class "org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider";
+         config:disable-osgi-service-registration;
+         status deprecated;
     }
 
     identity statistics-collection-service {