*/
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);
}
@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;
}
}
*/
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;
+ }
}
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;
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 {
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;
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());