BGPCEP-730: Fix ModifiedNodeDoesNotExistException
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / config / AppPeer.java
index 43e0d8bdb52eaa2de22179a740c373e89a559483..4ea4e3fa22102e365951b3b6a323da78fe4bca65 100644 (file)
@@ -17,9 +17,6 @@ import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
 import org.opendaylight.protocol.bgp.rib.impl.ApplicationPeer;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
@@ -73,12 +70,7 @@ public final class AppPeer implements PeerBean, BGPPeerStateConsumer {
     @Override
     public synchronized void close() {
         if (this.bgpAppPeerSingletonService != null) {
-            try {
-                this.bgpAppPeerSingletonService.close();
-                this.bgpAppPeerSingletonService = null;
-            } catch (final Exception e) {
-                LOG.warn("Failed to close application peer instance", e);
-            }
+            this.bgpAppPeerSingletonService = null;
         }
         if (this.serviceRegistration != null) {
             this.serviceRegistration.unregister();
@@ -86,6 +78,13 @@ public final class AppPeer implements PeerBean, BGPPeerStateConsumer {
         }
     }
 
+    @Override
+    public synchronized void instantiateServiceInstance() {
+        if (this.bgpAppPeerSingletonService != null) {
+            this.bgpAppPeerSingletonService.instantiateServiceInstance();
+        }
+    }
+
     @Override
     public synchronized ListenableFuture<Void> closeServiceInstance() {
         if (this.bgpAppPeerSingletonService != null) {
@@ -110,13 +109,10 @@ public final class AppPeer implements PeerBean, BGPPeerStateConsumer {
         this.serviceRegistration = serviceRegistration;
     }
 
-    private final class BgpAppPeerSingletonService implements ClusterSingletonService, BGPPeerStateConsumer,
-            AutoCloseable {
+    private final class BgpAppPeerSingletonService implements BGPPeerStateConsumer {
         private final ApplicationPeer applicationPeer;
         private final DOMDataTreeChangeService dataTreeChangeService;
         private final ApplicationRibId appRibId;
-        private final ServiceGroupIdentifier serviceGroupIdentifier;
-        private ClusterSingletonServiceRegistration singletonServiceRegistration;
         @GuardedBy("this")
         private boolean isServiceInstantiated;
 
@@ -124,26 +120,10 @@ public final class AppPeer implements PeerBean, BGPPeerStateConsumer {
             this.applicationPeer = new ApplicationPeer(appRibId, neighborAddress, rib);
             this.appRibId = appRibId;
             this.dataTreeChangeService = rib.getService();
-            this.serviceGroupIdentifier = rib.getRibIServiceGroupIdentifier();
-            LOG.info("Application Peer Singleton Service {} registered, Application peer {}",
-                    getIdentifier().getValue(), this.appRibId.getValue());
-            //this need to be always the last step
-            this.singletonServiceRegistration = rib.registerClusterSingletonService(this);
         }
 
-        @Override
-        public void close() throws Exception {
-            if (this.singletonServiceRegistration != null) {
-                this.singletonServiceRegistration.close();
-                this.singletonServiceRegistration = null;
-            }
-        }
-
-        @Override
         public synchronized void instantiateServiceInstance() {
             this.isServiceInstantiated = true;
-            LOG.info("Application Peer Singleton Service {} instantiated, Application peer {}",
-                    getIdentifier().getValue(), this.appRibId.getValue());
             final YangInstanceIdentifier yangIId = YangInstanceIdentifier.builder().node(ApplicationRib.QNAME)
                     .nodeWithKey(ApplicationRib.QNAME, APP_ID_QNAME, this.appRibId.getValue())
                     .node(Tables.QNAME).node(Tables.QNAME).build();
@@ -151,24 +131,16 @@ public final class AppPeer implements PeerBean, BGPPeerStateConsumer {
                     new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yangIId));
         }
 
-        @Override
         public synchronized ListenableFuture<Void> closeServiceInstance() {
             if (!this.isServiceInstantiated) {
-                LOG.trace("Application Peer Singleton Service {} instance already closed, Application peer {}",
-                        getIdentifier().getValue(), this.appRibId.getValue());
+                LOG.trace("Application peer already closed {}", this.appRibId.getValue());
                 return Futures.immediateFuture(null);
             }
-            LOG.info("Application Peer Singleton Service {} instance closed, Application peer {}",
-                    getIdentifier().getValue(), this.appRibId.getValue());
+            LOG.info("Application peer instance closed {}", this.appRibId.getValue());
             this.isServiceInstantiated = false;
             return this.applicationPeer.close();
         }
 
-        @Override
-        public ServiceGroupIdentifier getIdentifier() {
-            return this.serviceGroupIdentifier;
-        }
-
         @Override
         public BGPPeerState getPeerState() {
             return this.applicationPeer.getPeerState();