BGP Logs improvement
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / EffectiveRibInWriter.java
index d8c35f432c871a0023f16a94c13593e74a83bdc7..818de4cc1132866c682c8be9b13f52ec3c25d3be 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
 import java.util.Collection;
@@ -32,9 +33,11 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -80,7 +83,7 @@ final class EffectiveRibInWriter implements AutoCloseable {
         }
 
         private void processRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, final AbstractImportPolicy policy, final YangInstanceIdentifier routesPath, final DataTreeCandidateNode route) {
-            LOG.debug("Process route {}", route);
+            LOG.debug("Process route {}", route.getIdentifier());
             final YangInstanceIdentifier routeId = ribSupport.routePath(routesPath, route.getIdentifier());
             switch (route.getModificationType()) {
             case DELETE:
@@ -123,31 +126,34 @@ final class EffectiveRibInWriter implements AutoCloseable {
             final AbstractImportPolicy policy = EffectiveRibInWriter.this.peerPolicyTracker.policyFor(IdentifierUtils.peerId(peerKey));
 
             for (final DataTreeCandidateNode child : children) {
-                LOG.debug("Process table {} type {}", child, child.getModificationType());
-                final YangInstanceIdentifier childPath = tablePath.node(child.getIdentifier());
+                final PathArgument childIdentifier = child.getIdentifier();
+                final Optional<NormalizedNode<?, ?>> childDataAfter = child.getDataAfter();
+                LOG.debug("Process table {} type {}, dataAfter {}, dataBefore {}", childIdentifier, child
+                    .getModificationType(), childDataAfter, child.getDataBefore());
+                final YangInstanceIdentifier childPath = tablePath.node(childIdentifier);
                 switch (child.getModificationType()) {
                 case DELETE:
                 case DISAPPEARED:
-                    tx.delete(LogicalDatastoreType.OPERATIONAL, tablePath.node(child.getIdentifier()));
+                    tx.delete(LogicalDatastoreType.OPERATIONAL, tablePath.node(childIdentifier));
                     break;
                 case UNMODIFIED:
                     // No-op
                     break;
                 case SUBTREE_MODIFIED:
-                    if (TABLE_ROUTES.equals(child.getIdentifier())) {
+                    if (TABLE_ROUTES.equals(childIdentifier)) {
                         for (final DataTreeCandidateNode route : ribSupport.changedRoutes(child)) {
                             processRoute(tx, ribSupport, policy, childPath, route);
                         }
                     } else {
-                        tx.put(LogicalDatastoreType.OPERATIONAL, childPath, child.getDataAfter().get());
+                        tx.put(LogicalDatastoreType.OPERATIONAL, childPath, childDataAfter.get());
                     }
                     break;
                 case APPEARED:
                 case WRITE:
-                    tx.put(LogicalDatastoreType.OPERATIONAL, childPath, child.getDataAfter().get());
+                    tx.put(LogicalDatastoreType.OPERATIONAL, childPath, childDataAfter.get());
                     // Routes are special, as they may end up being filtered. The previous put conveniently
                     // ensured that we have them in at target, so a subsequent delete will not fail :)
-                    if (TABLE_ROUTES.equals(child.getIdentifier())) {
+                    if (TABLE_ROUTES.equals(childIdentifier)) {
                         for (final DataTreeCandidateNode route : ribSupport.changedRoutes(child)) {
                             processRoute(tx, ribSupport, policy, childPath, route);
                         }
@@ -180,7 +186,8 @@ final class EffectiveRibInWriter implements AutoCloseable {
             final YangInstanceIdentifier tablePath = effectiveTablePath(peerKey, tableKey);
 
             // Create an empty table
-            ribSupport.clearTable(tx,tablePath);
+            LOG.trace("Create Empty table", tablePath);
+            ribSupport.clearTable(tx, tablePath);
 
             processTableChildren(tx, ribSupport.getRibSupport(), peerKey, tablePath, table.getChildNodes());
         }
@@ -208,12 +215,12 @@ final class EffectiveRibInWriter implements AutoCloseable {
                 // filter out any change outside AdjRibsIn
                 final DataTreeCandidateNode ribIn =  root.getModifiedChild(ADJRIBIN_NID);
                 if (ribIn == null) {
-                    LOG.debug("Skipping change {}", tc.getRootNode());
+                    LOG.debug("Skipping change {}", root.getIdentifier());
                     continue;
                 }
                 final DataTreeCandidateNode tables = ribIn.getModifiedChild(TABLES_NID);
                 if (tables == null) {
-                    LOG.debug("Skipping change {}", tc.getRootNode());
+                    LOG.debug("Skipping change {}", root.getIdentifier());
                     continue;
                 }
                 for (final DataTreeCandidateNode table : tables.getChildNodes()) {
@@ -233,12 +240,14 @@ final class EffectiveRibInWriter implements AutoCloseable {
             final PathArgument lastArg = table.getIdentifier();
             Verify.verify(lastArg instanceof NodeIdentifierWithPredicates, "Unexpected type %s in path %s", lastArg.getClass(), rootPath);
             final NodeIdentifierWithPredicates tableKey = (NodeIdentifierWithPredicates) lastArg;
-
-            switch (root.getModificationType()) {
+            final ModificationType modificationType = root.getModificationType();
+            switch (modificationType) {
             case DELETE:
             case DISAPPEARED:
+                final YangInstanceIdentifier effectiveTablePath = effectiveTablePath(peerKey, tableKey);
+                LOG.debug("Delete Effective Table {} modification type {}, ", effectiveTablePath, modificationType);
                 // delete the corresponding effective table
-                tx.delete(LogicalDatastoreType.OPERATIONAL, effectiveTablePath(peerKey, tableKey));
+                tx.delete(LogicalDatastoreType.OPERATIONAL, effectiveTablePath);
                 break;
             case SUBTREE_MODIFIED:
                 modifyTable(tx, peerKey, tableKey, table);