Sonar issue fix 34/21034/5
authorIveta Halanova <iveta.halanova@pantheon.sk>
Mon, 25 May 2015 06:10:02 +0000 (08:10 +0200)
committerIveta Halanova <iveta.halanova@pantheon.sk>
Mon, 25 May 2015 08:14:59 +0000 (10:14 +0200)
Extracted parts of code into another private methods in order to
decrease complexity.

Change-Id: I53363643ceecd70579f82dc2a829e043fcaf8d41
Signed-off-by: Iveta Halanova <iveta.halanova@pantheon.sk>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java

index aeed6c91cc0c70359daf54812da70828fcb1c0bd..85b44407f93aee04d3347ad8f13bcd0759123819 100644 (file)
@@ -217,38 +217,44 @@ final class EffectiveRibInWriter implements AutoCloseable {
                     continue;
                 }
                 for (final DataTreeCandidateNode table : tables.getChildNodes()) {
-                    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()) {
-                    case DELETE:
-                        // delete the corresponding effective table
-                        tx.delete(LogicalDatastoreType.OPERATIONAL, effectiveTablePath(peerKey, tableKey));
-                        break;
-                    case MERGE:
-                        // TODO: upstream API should never give us this, as it leaks how the delta was created.
-                        LOG.info("Merge on {} reported, this should never have happened, but attempting to cope", rootPath);
-                        modifyTable(tx, peerKey, tableKey, table);
-                        break;
-                    case SUBTREE_MODIFIED:
-                        modifyTable(tx, peerKey, tableKey, table);
-                        break;
-                    case UNMODIFIED:
-                        LOG.info("Ignoring spurious notification on {} data {}", rootPath, table);
-                        break;
-                    case WRITE:
-                        writeTable(tx, peerKey, tableKey, table);
-                        break;
-                    default:
-                        LOG.warn("Ignoring unhandled root {}", root);
-                        break;
-                    }
+                    changeDataTree(tx, rootPath, root, peerKey, table);
                 }
             }
             tx.submit();
         }
 
+        private void changeDataTree(final DOMDataWriteTransaction tx, final YangInstanceIdentifier rootPath,
+            final DataTreeCandidateNode root, final NodeIdentifierWithPredicates peerKey, final DataTreeCandidateNode table) {
+
+            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()) {
+            case DELETE:
+                // delete the corresponding effective table
+                tx.delete(LogicalDatastoreType.OPERATIONAL, effectiveTablePath(peerKey, tableKey));
+                break;
+            case MERGE:
+                // TODO: upstream API should never give us this, as it leaks how the delta was created.
+                LOG.info("Merge on {} reported, this should never have happened, but attempting to cope", rootPath);
+                modifyTable(tx, peerKey, tableKey, table);
+                break;
+            case SUBTREE_MODIFIED:
+                modifyTable(tx, peerKey, tableKey, table);
+                break;
+            case UNMODIFIED:
+                LOG.info("Ignoring spurious notification on {} data {}", rootPath, table);
+                break;
+            case WRITE:
+                writeTable(tx, peerKey, tableKey, table);
+                break;
+            default:
+                LOG.warn("Ignoring unhandled root {}", root);
+                break;
+            }
+        }
+
         @Override
         public void close() {
             // FIXME: wipe all effective routes?
index 0e4ca53bc66b7410115b3583dccc270d3c0d8f07..071aabbe8a2f9cc9f0f1d2fab2204bfc836eb9a3 100644 (file)
@@ -116,6 +116,48 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
          * calculations when multiple peers have changed a particular entry.
          */
         final Map<RouteUpdateKey, AbstractRouteEntry> toUpdate = new HashMap<>();
+        update(tx, changes, toUpdate);
+
+        // Now walk all updated entries
+        walkThrough(tx, toUpdate);
+
+        tx.submit();
+    }
+
+    private void walkThrough(final DOMDataWriteTransaction tx, final Map<RouteUpdateKey, AbstractRouteEntry> toUpdate) {
+        for (final Entry<RouteUpdateKey, AbstractRouteEntry> e : toUpdate.entrySet()) {
+            LOG.trace("Walking through {}", e);
+            final AbstractRouteEntry entry = e.getValue();
+            final RouteUpdateKey key = e.getKey();
+            final NormalizedNode<?, ?> value;
+
+            if (entry != null) {
+                if (!entry.selectBest(this.ourAs)) {
+                    // Best path has not changed, no need to do anything else. Proceed to next route.
+                    LOG.trace("Continuing");
+                    continue;
+                }
+                value = entry.createValue(key.getRouteId());
+                LOG.trace("Selected best value {}", value);
+            } else {
+                value = null;
+            }
+
+            final YangInstanceIdentifier writePath = this.ribSupport.routePath(this.locRibTarget.node(Routes.QNAME), key.getRouteId());
+            if (value != null) {
+                LOG.debug("Write route to LocRib {}", value);
+                tx.put(LogicalDatastoreType.OPERATIONAL, writePath, value);
+            } else {
+                LOG.debug("Delete route from LocRib {}", entry);
+                tx.delete(LogicalDatastoreType.OPERATIONAL, writePath);
+            }
+            fillAdjRibsOut(tx, entry, value, key);
+        }
+    }
+
+    private void update(final DOMDataWriteTransaction tx, final Collection<DataTreeCandidate> changes,
+        final Map<RouteUpdateKey, AbstractRouteEntry> toUpdate) {
+
         for (final DataTreeCandidate tc : changes) {
             final YangInstanceIdentifier path = tc.getRootPath();
             final NodeIdentifierWithPredicates peerKey = IdentifierUtils.peerKey(path);
@@ -149,37 +191,6 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
                 }
             }
         }
-
-        // Now walk all updated entries
-        for (final Entry<RouteUpdateKey, AbstractRouteEntry> e : toUpdate.entrySet()) {
-            LOG.trace("Walking through {}", e);
-            final AbstractRouteEntry entry = e.getValue();
-            final RouteUpdateKey key = e.getKey();
-            final NormalizedNode<?, ?> value;
-
-            if (entry != null) {
-                if (!entry.selectBest(this.ourAs)) {
-                    // Best path has not changed, no need to do anything else. Proceed to next route.
-                    LOG.trace("Continuing");
-                    continue;
-                }
-                value = entry.createValue(key.getRouteId());
-                LOG.trace("Selected best value {}", value);
-            } else {
-                value = null;
-            }
-
-            final YangInstanceIdentifier writePath = this.ribSupport.routePath(this.locRibTarget.node(Routes.QNAME), key.getRouteId());
-            if (value != null) {
-                LOG.debug("Write route to LocRib {}", value);
-                tx.put(LogicalDatastoreType.OPERATIONAL, writePath, value);
-            } else {
-                LOG.debug("Delete route from LocRib {}", entry);
-                tx.delete(LogicalDatastoreType.OPERATIONAL, writePath);
-            }
-            fillAdjRibsOut(tx, entry, value, key);
-        }
-        tx.submit();
     }
 
     private void fillAdjRibsOut(final DOMDataWriteTransaction tx, final AbstractRouteEntry entry, final NormalizedNode<?, ?> value, final RouteUpdateKey key) {