Sonar Warning Fix: complexity issues 34/23634/8
authorIveta Halanova <iveta.halanova@pantheon.sk>
Wed, 1 Jul 2015 08:35:15 +0000 (10:35 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 1 Jul 2015 13:45:41 +0000 (13:45 +0000)
NodeChangedListener:
- extracted for cycle into private updateTransaction method
Stateful07TopologySessionListener
- extracted building the Path variable
FSNlriParser
- switch extraction into private method setFlowspecType

Change-Id: Iec4d2d179527560150046531cc02fd198ea3d323
Signed-off-by: Iveta Halanova <iveta.halanova@pantheon.sk>
bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSNlriParser.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java
pcep/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/NodeChangedListener.java

index 33d2d34af964c9f65f96b9877c78e37b6d6716ad..ba9459835538293e9ac78c15e053ecb743e15374 100644 (file)
@@ -403,54 +403,57 @@ public class FSNlriParser implements NlriParser, NlriSerializer {
 
         while (nlri.isReadable()) {
             final FlowspecBuilder builder = new FlowspecBuilder();
-            // read type
             final ComponentType type = ComponentType.forValue(nlri.readUnsignedByte());
             builder.setComponentType(type);
-            switch (type) {
-            case DestinationPrefix:
-                builder.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(Ipv4Util.prefixForByteBuf(nlri)).build());
-                break;
-            case SourcePrefix:
-                builder.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(Ipv4Util.prefixForByteBuf(nlri)).build());
-                break;
-            case ProtocolIp:
-                builder.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(parseProtocolIp(nlri)).build());
-                break;
-            case Port:
-                builder.setFlowspecType(new PortCaseBuilder().setPorts(parsePort(nlri)).build());
-                break;
-            case DestinationPort:
-                builder.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(parseDestinationPort(nlri)).build());
-                break;
-            case SourcePort:
-                builder.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(parseSourcePort(nlri)).build());
-                break;
-            case IcmpType:
-                builder.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(parseIcmpType(nlri)).build());
-                break;
-            case IcmpCode:
-                builder.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(parseIcmpCode(nlri)).build());
-                break;
-            case TcpFlags:
-                builder.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(parseTcpFlags(nlri)).build());
-                break;
-            case PacketLength:
-                builder.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(parsePacketLength(nlri)).build());
-                break;
-            case Dscp:
-                builder.setFlowspecType(new DscpCaseBuilder().setDscps(parseDscp(nlri)).build());
-                break;
-            case Fragment:
-                builder.setFlowspecType(new FragmentCaseBuilder().setFragments(parseFragment(nlri)).build());
-                break;
-            default:
-                break;
-            }
+            setFlowspecType(builder, type, nlri);
             fss.add(builder.build());
         }
         return fss;
     }
 
+    private static void setFlowspecType(final FlowspecBuilder builder, final ComponentType type, final ByteBuf nlri) {
+        switch (type) {
+        case DestinationPrefix:
+            builder.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(Ipv4Util.prefixForByteBuf(nlri)).build());
+            break;
+        case SourcePrefix:
+            builder.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(Ipv4Util.prefixForByteBuf(nlri)).build());
+            break;
+        case ProtocolIp:
+            builder.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(parseProtocolIp(nlri)).build());
+            break;
+        case Port:
+            builder.setFlowspecType(new PortCaseBuilder().setPorts(parsePort(nlri)).build());
+            break;
+        case DestinationPort:
+            builder.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(parseDestinationPort(nlri)).build());
+            break;
+        case SourcePort:
+            builder.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(parseSourcePort(nlri)).build());
+            break;
+        case IcmpType:
+            builder.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(parseIcmpType(nlri)).build());
+            break;
+        case IcmpCode:
+            builder.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(parseIcmpCode(nlri)).build());
+            break;
+        case TcpFlags:
+            builder.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(parseTcpFlags(nlri)).build());
+            break;
+        case PacketLength:
+            builder.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(parsePacketLength(nlri)).build());
+            break;
+        case Dscp:
+            builder.setFlowspecType(new DscpCaseBuilder().setDscps(parseDscp(nlri)).build());
+            break;
+        case Fragment:
+            builder.setFlowspecType(new FragmentCaseBuilder().setFragments(parseFragment(nlri)).build());
+            break;
+        default:
+            break;
+        }
+    }
+
     private static List<ProtocolIps> parseProtocolIp(final ByteBuf nlri) {
         final List<ProtocolIps> ips = new ArrayList<>();
         boolean end = false;
index d81214e515267dbe66cfb087a2f07c16ef703bcb..9464b500441a1d996fa6310613eddd132e66eac9 100644 (file)
@@ -72,6 +72,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLspBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.StatefulTlvBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -170,7 +171,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
         final PlspId plspid = lsp.getPlspId();
         if (!lsp.isSync() && (lsp.getPlspId() == null || plspid.getValue() == 0)) {
             stateSynchronizationAchieved(ctx);
-            return true; //continue;
+            return true;
         }
         final ReportedLspBuilder rlb = new ReportedLspBuilder();
         boolean solicited = false;
@@ -185,6 +186,18 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
                 return false;
             }
         }
+        rlb.setPath(Collections.singletonList(buildPath(report, srp, plspid, lsp)));
+
+        String name = lookupLspName(plspid);
+        if (report.getLsp().getTlvs() != null && report.getLsp().getTlvs().getSymbolicPathName() != null) {
+            name = Charsets.UTF_8.decode(ByteBuffer.wrap(report.getLsp().getTlvs().getSymbolicPathName().getPathName().getValue())).toString();
+        }
+        updateLsp(ctx, plspid, name, rlb, solicited, lsp.isRemove());
+        LOG.debug("LSP {} updated", lsp);
+        return true;
+    }
+
+    private Path buildPath(final Reports report, final Srp srp, final PlspId plspid, final Lsp lsp) {
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder();
         if (report.getPath() != null) {
             pb.fieldsFrom(report.getPath());
@@ -201,7 +214,6 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
             pst = null;
         }
         pb.addAugmentation(Path1.class, p1Builder.build());
-        String name = lookupLspName(plspid);
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.Tlvs tlvs = report.getLsp().getTlvs();
         if (tlvs != null) {
             if (tlvs.getLspIdentifiers() != null) {
@@ -209,14 +221,8 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
             } else if (!isDefaultPST(pst)) {
                 pb.setLspId(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId(lsp.getPlspId().getValue()));
             }
-            if (tlvs.getSymbolicPathName() != null) {
-                name = Charsets.UTF_8.decode(ByteBuffer.wrap(tlvs.getSymbolicPathName().getPathName().getValue())).toString();
-            }
         }
-        rlb.setPath(Collections.singletonList(pb.build()));
-        updateLsp(ctx, plspid, name, rlb, solicited, lsp.isRemove());
-        LOG.debug("LSP {} updated", lsp);
-        return true;
+        return pb.build();
     }
 
     @Override
index abcf958e7483ce9359844f2924b1e6fbd2227f88..e9c8957e98103468ee6221f81474fcd86001ceb4 100644 (file)
@@ -121,7 +121,7 @@ public final class NodeChangedListener implements DataChangeListener {
     }
 
     private SupportingNode createSupportingNode(final NodeId sni, final Boolean inControl) {
-        final SupportingNodeKey sk = new SupportingNodeKey(sni, source);
+        final SupportingNodeKey sk = new SupportingNodeKey(sni, this.source);
         final SupportingNodeBuilder snb = new SupportingNodeBuilder();
         snb.setNodeRef(sni);
         snb.setKey(sk);
@@ -402,11 +402,30 @@ public final class NodeChangedListener implements DataChangeListener {
         }
 
         // We now have list of all affected LSPs. Walk them create/remove them
+        updateTransaction(trans, lsps, o, u, c);
+
+        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.submit()), new FutureCallback<Void>() {
+            @Override
+            public void onSuccess(final Void result) {
+                LOG.trace("Topology change committed successfully");
+            }
+
+            @Override
+            public void onFailure(final Throwable t) {
+                LOG.error("Failed to propagate a topology change, target topology became inconsistent", t);
+            }
+        });
+    }
+
+    private void updateTransaction(final ReadWriteTransaction trans, final Set<InstanceIdentifier<ReportedLsp>> lsps,
+        final Map<InstanceIdentifier<?>, ? extends DataObject> old, final Map<InstanceIdentifier<?>, DataObject> updated,
+        final Map<InstanceIdentifier<?>, DataObject> created) {
+
         for (final InstanceIdentifier<ReportedLsp> i : lsps) {
-            final ReportedLsp oldValue = (ReportedLsp) o.get(i);
-            ReportedLsp newValue = (ReportedLsp) u.get(i);
+            final ReportedLsp oldValue = (ReportedLsp) old.get(i);
+            ReportedLsp newValue = (ReportedLsp) updated.get(i);
             if (newValue == null) {
-                newValue = (ReportedLsp) c.get(i);
+                newValue = (ReportedLsp) created.get(i);
             }
 
             LOG.debug("Updating lsp {} value {} -> {}", i, oldValue, newValue);
@@ -425,18 +444,6 @@ public final class NodeChangedListener implements DataChangeListener {
                 }
             }
         }
-
-        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.submit()), new FutureCallback<Void>() {
-            @Override
-            public void onSuccess(final Void result) {
-                LOG.trace("Topology change committed successfully");
-            }
-
-            @Override
-            public void onFailure(final Throwable t) {
-                LOG.error("Failed to propagate a topology change, target topology became inconsistent", t);
-            }
-        });
     }
 
     public static InstanceIdentifier<Link> linkIdentifier(final InstanceIdentifier<Topology> topology, final NodeId node, final String name) {