Migrate datastore callback 61/101961/5
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 3 Aug 2022 13:14:09 +0000 (15:14 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 5 Aug 2022 11:31:35 +0000 (13:31 +0200)
TopologyNodeState should not see the session, that should be part of
SessionListener lifecycle. Return the datastore future back to caller
so we can clean this up in future.

JIRA: BGPCEP-1005
Change-Id: I995ecf4d57fc90d37aab8208a2364603161b308f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyNodeState.java

index cf90355f2a47269b3952f4cd589470db339a6a1d..7afbd42674a462e1f27d07171204a3cb308571f6 100644 (file)
@@ -178,11 +178,25 @@ public abstract class AbstractTopologySessionListener implements TopologySession
                             initialNodeState.augmentation(Node1.class).getPathComputationClient().getReportedLsp());
                     }
                 }
-                state.storeNode(topologyAugment,
-                        new Node1Builder().setPathComputationClient(pccBuilder.build()).build(), psession);
 
+                final var storeFuture = state.storeNode(topologyAugment,
+                        new Node1Builder().setPathComputationClient(pccBuilder.build()).build());
                 listenerState = stateRegistry.bind(nodeId, new SessionStateImpl(this, psession));
                 LOG.info("Session with {} attached to topology node {}", peerAddress, nodeId);
+
+                storeFuture.addCallback(new FutureCallback<CommitInfo>() {
+                    @Override
+                    public void onSuccess(final CommitInfo result) {
+                        LOG.trace("Node stored {} for session {} updated successfully", topologyAugment, psession);
+                    }
+
+                    @Override
+                    public void onFailure(final Throwable cause) {
+                        LOG.error("Failed to store node {} for session {}, terminating it", topologyAugment, psession,
+                            cause);
+                        session.close(TerminationReason.UNKNOWN);
+                    }
+                }, MoreExecutors.directExecutor());
             }
         }
     }
index 098e32fa291c855caf01dcfc314b6113a5c58403..95ab551b473cb8759ec3d2d2664e0e15cb8065c3 100644 (file)
@@ -28,8 +28,6 @@ import org.opendaylight.mdsal.binding.api.TransactionChainListener;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.protocol.pcep.PCEPSession;
-import org.opendaylight.protocol.pcep.TerminationReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.lsp.metadata.Metadata;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
@@ -187,28 +185,14 @@ final class TopologyNodeState implements TransactionChainListener {
         }, MoreExecutors.directExecutor());
     }
 
-    void storeNode(final InstanceIdentifier<Node1> topologyAugment, final Node1 ta, final PCEPSession session) {
+    @NonNull FluentFuture<? extends @NonNull CommitInfo> storeNode(final InstanceIdentifier<Node1> topologyAugment,
+            final Node1 ta) {
         LOG.trace("Peer data {} set to {}", topologyAugment, ta);
-
-        final FluentFuture<? extends CommitInfo> future;
         synchronized (this) {
             final WriteTransaction trans = chain.newWriteOnlyTransaction();
             trans.put(LogicalDatastoreType.OPERATIONAL, topologyAugment, ta);
             // All set, commit the modifications
-            future = trans.commit();
+            return trans.commit();
         }
-
-        future.addCallback(new FutureCallback<CommitInfo>() {
-            @Override
-            public void onSuccess(final CommitInfo result) {
-                LOG.trace("Node stored {} for session {} updated successfully", topologyAugment, session);
-            }
-
-            @Override
-            public void onFailure(final Throwable cause) {
-                LOG.error("Failed to store node {} for session {}, terminating it", topologyAugment, session, cause);
-                session.close(TerminationReason.UNKNOWN);
-            }
-        }, MoreExecutors.directExecutor());
     }
 }