From: Iveta Halanova Date: Mon, 25 May 2015 06:10:02 +0000 (+0200) Subject: Sonar issue fix X-Git-Tag: release/beryllium~356 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=9750e432d3b00ed7b3be18140dce1a18246570d5;p=bgpcep.git Sonar issue fix Extracted parts of code into another private methods in order to decrease complexity. Change-Id: I53363643ceecd70579f82dc2a829e043fcaf8d41 Signed-off-by: Iveta Halanova --- diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java index aeed6c91cc..85b44407f9 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java @@ -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? diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java index 0e4ca53bc6..071aabbe8a 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java @@ -116,6 +116,48 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener { * calculations when multiple peers have changed a particular entry. */ final Map 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 toUpdate) { + for (final Entry 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 changes, + final Map 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 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) {