Add blueprint XML wiring for the BGPPeerRegistry 26/40526/8
authorTom Pantelis <tpanteli@brocade.com>
Sat, 18 Jun 2016 19:52:35 +0000 (15:52 -0400)
committerMilos Fabian <milfabia@cisco.com>
Fri, 15 Jul 2016 17:50:28 +0000 (17:50 +0000)
Added blueprint wiring for the StrictBGPPeerRegistry. The
StrictBgpPeerRegistryModule was deprecated but still remains for now
to provide the instance created via blueprint to the config system so it can be
injected into other users. Once the other user(s) are converted to blueprint then
the config yang and Module classes can be removed.

Change-Id: Ieaec3d6e29b457192d3a3acdc5b9e72559403805
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
bgp/rib-impl/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/StrictBgpPeerRegistryModule.java
bgp/rib-impl/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/StrictBgpPeerRegistryModuleFactory.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/StrictBGPPeerRegistry.java
bgp/rib-impl/src/main/resources/org/opendaylight/blueprint/bgp-rib.xml
bgp/rib-impl/src/main/yang/odl-bgp-rib-impl-cfg.yang
bgp/rib-impl/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/AbstractRIBImplModuleTest.java
bgp/rib-impl/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerAcceptorModuleTest.java

index bb2679fc1e611e7cb7665a9170e04ff18a9ad4d6..c2ceb8367e3c5d07a3c39df78ab21c86a51530da 100644 (file)
@@ -7,20 +7,22 @@
  */
 package org.opendaylight.controller.config.yang.bgp.rib.impl;
 
-import com.google.common.base.MoreObjects;
-import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
+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.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
+import org.osgi.framework.BundleContext;
 
 /**
 * Registry of BGP peers that allows only one connection per 2 peers
+*
+* @deprecated Replaced by blueprint wiring
 */
+@Deprecated
 public class StrictBgpPeerRegistryModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractStrictBgpPeerRegistryModule {
+    private BundleContext bundleContext;
+
     public StrictBgpPeerRegistryModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
@@ -36,61 +38,24 @@ public class StrictBgpPeerRegistryModule extends org.opendaylight.controller.con
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        return new GlobalBGPPeerRegistryWrapper(StrictBGPPeerRegistry.GLOBAL);
+        final WaitingServiceTracker<BGPPeerRegistry> tracker =
+                WaitingServiceTracker.create(BGPPeerRegistry.class, bundleContext);
+        final BGPPeerRegistry service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
+
+        return Reflection.newProxy(BGPPeerRegistry.class, new AbstractInvocationHandler() {
+            @Override
+            protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
+                if (method.getName().equals("close")) {
+                    tracker.close();
+                    return null;
+                } else {
+                    return method.invoke(service, args);
+                }
+            }
+        });
     }
 
-    // TODO backwards compatibility, peer-registry has to be mandatory attribute for peers
-    /**
-     * Wrapper for BGPPeerRegistry that prevents from executing close method
-      */
-    private static final class GlobalBGPPeerRegistryWrapper implements BGPPeerRegistry, AutoCloseable {
-        private final StrictBGPPeerRegistry global;
-
-        public GlobalBGPPeerRegistryWrapper(final StrictBGPPeerRegistry global) {
-            this.global = global;
-        }
-
-        @Override
-        public BGPSessionPreferences getPeerPreferences(final IpAddress ip) {
-            return this.global.getPeerPreferences(ip);
-        }
-
-        @Override
-        public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final Open open)
-                throws BGPDocumentedException {
-            return this.global.getPeer(ip, sourceId, remoteId, open);
-        }
-
-        @Override
-        public boolean isPeerConfigured(final IpAddress ip) {
-            return this.global.isPeerConfigured(ip);
-        }
-
-        @Override
-        public void removePeer(final IpAddress ip) {
-            this.global.removePeer(ip);
-        }
-
-        @Override
-        public void removePeerSession(final IpAddress ip) {
-            this.global.removePeerSession(ip);
-        }
-
-        @Override
-        public void addPeer(final IpAddress ip, final BGPSessionListener peer, final BGPSessionPreferences preferences) {
-            this.global.addPeer(ip, peer, preferences);
-        }
-
-        @Override
-        public void close() {
-            // DO nothing, do not close the global instance
-        }
-
-        @Override
-        public String toString() {
-            return MoreObjects.toStringHelper(this)
-                    .add("peers", this.global)
-                    .toString();
-        }
+    void setBundleContext(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
     }
 }
index 7405ede3a44cf24472058fb9ef25cdec36b48236..eec255e4ca298d706a23804e5c2bf53006c12a1c 100644 (file)
@@ -7,6 +7,28 @@
  */
 package org.opendaylight.controller.config.yang.bgp.rib.impl;
 
-public class StrictBgpPeerRegistryModuleFactory extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractStrictBgpPeerRegistryModuleFactory {
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.osgi.framework.BundleContext;
 
+/**
+ * @deprecated Replaced by blueprint wiring
+ */
+@Deprecated
+public class StrictBgpPeerRegistryModuleFactory extends AbstractStrictBgpPeerRegistryModuleFactory {
+    @Override
+    public StrictBgpPeerRegistryModule instantiateModule(String instanceName, DependencyResolver dependencyResolver,
+            StrictBgpPeerRegistryModule oldModule, AutoCloseable oldInstance, BundleContext bundleContext) {
+        StrictBgpPeerRegistryModule module = super.instantiateModule(instanceName, dependencyResolver, oldModule,
+                oldInstance, bundleContext);
+        module.setBundleContext(bundleContext);
+        return module;
+    }
+
+    @Override
+    public StrictBgpPeerRegistryModule instantiateModule(String instanceName, DependencyResolver dependencyResolver,
+            BundleContext bundleContext) {
+        StrictBgpPeerRegistryModule module = super.instantiateModule(instanceName, dependencyResolver, bundleContext);
+        module.setBundleContext(bundleContext);
+        return module;
+    }
 }
index ad2008a9311115aae5cff48eaf9eb8f88846335b..944ca0a843a47337700bb9f3650c15dd7314fd39 100644 (file)
@@ -65,6 +65,10 @@ public final class StrictBGPPeerRegistry implements BGPPeerRegistry {
     @GuardedBy("this")
     private final Map<IpAddress, BGPSessionPreferences> peerPreferences = Maps.newHashMap();
 
+    public static BGPPeerRegistry instance() {
+        return GLOBAL;
+    }
+
     @Override
     public synchronized void addPeer(final IpAddress ip, final BGPSessionListener peer, final BGPSessionPreferences preferences) {
         Preconditions.checkNotNull(ip);
index 48196b30a06f341ef945a1184692c0fd6696695a..9ec73e89e999bf088f9f7cd80241e178cfcc45c0 100644 (file)
   </bean>
 
   <service ref="BGPDispatcher" interface="org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher"/>
+
+  <bean id="BGPPeerRegistry" class="org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry"
+          factory-method="instance"/>
+
+  <service ref="BGPPeerRegistry" interface="org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry"
+          odl:type="default"/>
 </blueprint>
\ No newline at end of file
index c9562ca0ba99e9002b6057ea77c33b30cdd2b017..d92c4277f2a2d8436075da9d64e1825a993b2b7c 100644 (file)
@@ -82,6 +82,7 @@ module odl-bgp-rib-impl-cfg {
 
         base "config:service-type";
         config:java-class "org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry";
+        config:disable-osgi-service-registration;
     }
 
     identity strict-bgp-peer-registry {
index 1d6b3c3c7e7af381216e8daeceeb68776e836cae..88d9f76b17cd37829a8b9bfdd8b17e7e8dd565d9 100755 (executable)
@@ -84,6 +84,7 @@ import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.controller.sal.core.api.model.YangTextSourceProvider;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
@@ -239,6 +240,8 @@ public abstract class AbstractRIBImplModuleTest extends AbstractConfigTest {
                 any(InetSocketAddress.class), any(BGPPeerRegistry.class), anyInt(), any(Optional.class));
 
         setupMockService(RIBExtensionProviderContext.class, new SimpleRIBExtensionProviderContext());
+
+        setupMockService(BGPPeerRegistry.class, StrictBGPPeerRegistry.GLOBAL);
     }
 
     protected void setupMockService(final Class<?> serviceInterface, final Object instance) throws Exception {
index ce381c3580b02dc2aaa9669f10545fc7bcad50c4..6decf52f34a4ac26bc855c1411ccb9d7aeb77976 100644 (file)
@@ -34,9 +34,7 @@ import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.api.jmx.CommitStatus;
-import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
 import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;
-import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
 import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleFactory;
@@ -46,18 +44,13 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 
-public class BGPPeerAcceptorModuleTest extends AbstractConfigTest {
+public class BGPPeerAcceptorModuleTest extends AbstractRIBImplModuleTest {
 
     private static final String INSTANCE_NAME = "bgp-peer-acceptor";
     private static final String FACTORY_NAME = BGPPeerAcceptorModuleFactory.NAME;
 
-    @Before
-    public void setUp() throws Exception {
-        final List<ModuleFactory> moduleFactories = getModuleFactories();
-        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.mockedContext, moduleFactories.toArray(new ModuleFactory[moduleFactories.size()])));
-    }
-
-    private List<ModuleFactory> getModuleFactories() {
+    @Override
+    protected List<ModuleFactory> getModuleFactories() {
         final List<ModuleFactory> moduleFactories = Lists.newArrayList();
         moduleFactories.add(new StrictBgpPeerRegistryModuleFactory());
         moduleFactories.add(new BGPPeerAcceptorModuleFactory());