Remove OSGi dependency from bgp modules
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / config / RibImpl.java
index e750ad3a652bbc70996eaef63b4655eed4235b71..2d0ededb2c1de6f12409e45157da5ed13c028b88 100644 (file)
@@ -9,12 +9,11 @@
 package org.opendaylight.protocol.bgp.rib.impl.config;
 
 import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getAfiSafiWithDefault;
-import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getClusterIdentifier;
+import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getGlobalClusterIdentifier;
 import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.toTableTypes;
 
 import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -26,11 +25,11 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.BGPRibRoutingPolicyFactory;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
-import org.opendaylight.protocol.bgp.rib.impl.BGPPeerTrackerImpl;
 import org.opendaylight.protocol.bgp.rib.impl.CodecsRegistryImpl;
 import org.opendaylight.protocol.bgp.rib.impl.RIBImpl;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
@@ -47,18 +46,18 @@ import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.g
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 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.multiprotocol.rev171207.BgpTableType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.RibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.Rib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.RibKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.RibKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -73,14 +72,13 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
     private final DOMSchemaService domSchemaService;
     private final BGPRibRoutingPolicyFactory policyProvider;
     private RIBImpl ribImpl;
-    private ServiceRegistration<?> serviceRegistration;
     private ListenerRegistration<SchemaContextListener> schemaContextRegistration;
     private List<AfiSafi> afiSafi;
     private AsNumber asNumber;
     private Ipv4Address routerId;
 
     private ClusterIdentifier clusterId;
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
 
     public RibImpl(
             final RIBExtensionConsumerContext contextProvider,
@@ -112,7 +110,7 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
         final Config globalConfig = global.getConfig();
         final AsNumber globalAs = globalConfig.getAs();
         final Ipv4Address globalRouterId = global.getConfig().getRouterId();
-        final ClusterIdentifier globalClusterId = getClusterIdentifier(globalConfig);
+        final ClusterIdentifier globalClusterId = getGlobalClusterIdentifier(globalConfig);
         return this.afiSafi.containsAll(globalAfiSafi) && globalAfiSafi.containsAll(this.afiSafi)
                 && globalAs.equals(this.asNumber)
                 && globalRouterId.getValue().equals(this.routerId.getValue())
@@ -184,11 +182,11 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
         return this.ribImpl.getDataBroker();
     }
 
-    ListenableFuture<Void> closeServiceInstance() {
+    FluentFuture<? extends CommitInfo> closeServiceInstance() {
         if (this.ribImpl != null) {
             return this.ribImpl.closeServiceInstance();
         }
-        return Futures.immediateFuture(null);
+        return CommitInfo.emptyFluentFuture();
     }
 
     @Override
@@ -205,18 +203,6 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
             this.schemaContextRegistration.close();
             this.schemaContextRegistration = null;
         }
-        if (this.serviceRegistration != null) {
-            try {
-                this.serviceRegistration.unregister();
-            } catch (final IllegalStateException e) {
-                LOG.warn("Failed to unregister {} service instance", this, e);
-            }
-            this.serviceRegistration = null;
-        }
-    }
-
-    void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
-        this.serviceRegistration = serviceRegistration;
     }
 
     @Override
@@ -252,10 +238,9 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
         final Config globalConfig = global.getConfig();
         this.asNumber = globalConfig.getAs();
         this.routerId = globalConfig.getRouterId();
-        this.clusterId = getClusterIdentifier(globalConfig);
-        final BGPPeerTrackerImpl peerTracker = new BGPPeerTrackerImpl();
+        this.clusterId = getGlobalClusterIdentifier(globalConfig);
         final Map<TablesKey, PathSelectionMode> pathSelectionModes = OpenConfigMappingUtil
-                .toPathSelectionMode(this.afiSafi, tableTypeRegistry, peerTracker).entrySet()
+                .toPathSelectionMode(this.afiSafi, tableTypeRegistry).entrySet()
                 .stream()
                 .collect(Collectors.toMap(entry ->
                         new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
@@ -266,6 +251,7 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
                 this.extensions.getClassLoadingStrategy());
 
         return new RIBImpl(
+                tableTypeRegistry,
                 new RibId(bgpInstanceName),
                 this.asNumber,
                 new BgpId(this.routerId),
@@ -275,7 +261,6 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
                 this.domBroker,
                 this.dataBroker,
                 ribPolicy,
-                peerTracker,
                 toTableTypes(this.afiSafi, tableTypeRegistry),
                 pathSelectionModes);
     }
@@ -290,4 +275,9 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
             this.ribImpl.instantiateServiceInstance();
         }
     }
+
+    @Override
+    public void refreshTable(final TablesKey tk, final PeerId peerId) {
+        this.ribImpl.refreshTable(tk, peerId);
+    }
 }