BUG-731 : refactored stateful listeners 83/11883/3
authorDana Kutenicsova <dkutenic@cisco.com>
Fri, 10 Oct 2014 12:53:35 +0000 (14:53 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Fri, 10 Oct 2014 13:34:08 +0000 (15:34 +0200)
- moved nullchecks for input LSP to separate method (should fix most complexity warnings)
- moved MBB procedure to separate method

Change-Id: Icf791b41dedb408340fe4cbe2e439bceab1c1b30
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful02TopologySessionListener.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java

index 46ad4cab9cbbc18830ecf96358e11e9dcc149d37..2424fec4857e30ccef33bdf53dd9b789a5adb42f 100644 (file)
@@ -31,8 +31,9 @@ import org.opendaylight.protocol.pcep.TerminationReason;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MessageHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.LspId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
@@ -292,48 +293,17 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
         LOG.debug("Saved LSP {} with name {}", id, name);
         this.lsps.put(id, name);
 
-        // just one path should be reported
-        Preconditions.checkState(rlb.getPath().size() == 1);
-        final LspId reportedLspId = rlb.getPath().get(0).getLspId();
-        // check previous report for existing paths
+
         final ReportedLsp previous = this.lspData.get(name);
         // if no previous report about the lsp exist, just proceed
         if (previous != null) {
-            final List<Path> updatedPaths = new ArrayList<>(previous.getPath());
-            LOG.debug("Found previous paths {} to this lsp name {}", updatedPaths, name);
-            for (final Path path : previous.getPath()) {
-                //we found reported path in previous reports
-                if (path.getLspId().getValue() == 0 || path.getLspId().equals(reportedLspId)) {
-                    LOG.debug("Match on lsp-id {}", path.getLspId().getValue() );
-                    // path that was reported previously and does have the same lsp-id, path will be updated
-                    final boolean r = updatedPaths.remove(path);
-                    LOG.trace("Request removed? {}", r);
-                }
-            }
-            // if the path does not exist in previous report, add it to path list, it's a new ERO
-            // only one path will be added
-            //lspId is 0 means confirmation message that shouldn't be added (because we have no means of deleting it later)
-            LOG.trace("Adding new path {} to {}", rlb.getPath(), updatedPaths);
-            updatedPaths.addAll(rlb.getPath());
-            if (remove) {
-                if (reportedLspId.getValue() == 0) {
-                    // if lsp-id also 0, remove all paths
-                    LOG.debug("Removing all paths.");
-                    updatedPaths.clear();
-                } else {
-                    // path is marked to be removed
-                    LOG.debug("Removing path {} from {}", rlb.getPath(), updatedPaths);
-                    final boolean r = updatedPaths.removeAll(rlb.getPath());
-                    LOG.trace("Request removed? {}", r);
-                }
-            }
+            final List<Path> updatedPaths = makeBeforeBreak(rlb, previous, name, remove);
             // if all paths or the last path were deleted, delete whole tunnel
-            if (updatedPaths.isEmpty()) {
+            if (updatedPaths == null || updatedPaths.isEmpty()) {
                 LOG.debug("All paths were removed, removing LSP with {}.", id);
                 removeLsp(ctx, id);
                 return;
             }
-            LOG.debug("Setting new paths {} to lsp {}", updatedPaths, name);
             rlb.setPath(updatedPaths);
         }
         rlb.setKey(new ReportedLspKey(name));
@@ -353,6 +323,43 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
         this.lspData.put(name, rl);
     }
 
+    private List<Path> makeBeforeBreak(final ReportedLspBuilder rlb, final ReportedLsp previous, final String name, final boolean remove) {
+        // just one path should be reported
+        Preconditions.checkState(rlb.getPath().size() == 1);
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId reportedLspId = rlb.getPath().get(0).getLspId();
+        // check previous report for existing paths
+        final List<Path> updatedPaths = new ArrayList<>(previous.getPath());
+        LOG.debug("Found previous paths {} to this lsp name {}", updatedPaths, name);
+        for (final Path path : previous.getPath()) {
+            //we found reported path in previous reports
+            if (path.getLspId().getValue() == 0 || path.getLspId().equals(reportedLspId)) {
+                LOG.debug("Match on lsp-id {}", path.getLspId().getValue() );
+                // path that was reported previously and does have the same lsp-id, path will be updated
+                final boolean r = updatedPaths.remove(path);
+                LOG.trace("Request removed? {}", r);
+            }
+        }
+        // if the path does not exist in previous report, add it to path list, it's a new ERO
+        // only one path will be added
+        //lspId is 0 means confirmation message that shouldn't be added (because we have no means of deleting it later)
+        LOG.trace("Adding new path {} to {}", rlb.getPath(), updatedPaths);
+        updatedPaths.addAll(rlb.getPath());
+        if (remove) {
+            if (reportedLspId.getValue() == 0) {
+                // if lsp-id also 0, remove all paths
+                LOG.debug("Removing all paths.");
+                updatedPaths.clear();
+            } else {
+                // path is marked to be removed
+                LOG.debug("Removing path {} from {}", rlb.getPath(), updatedPaths);
+                final boolean r = updatedPaths.removeAll(rlb.getPath());
+                LOG.trace("Request removed? {}", r);
+            }
+        }
+        LOG.debug("Setting new paths {} to lsp {}", updatedPaths, name);
+        return updatedPaths;
+    }
+
     /**
      * Indicate that the peer has completed state synchronization.
      *
@@ -409,4 +416,6 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
     protected final synchronized <T extends DataObject> ListenableFuture<Optional<T>> readOperationalData(final InstanceIdentifier<T> id) {
         return this.nodeState.readOperationalData(id);
     }
+
+    protected abstract Object validateReportedLsp(final Optional<ReportedLsp> rep, final LspId input);
 }
index 4c30187c6ec23bd384cac3d4faec85a3c249934c..ecbd986a7aa8ccc785145900174fdfe1bf333558 100644 (file)
@@ -44,9 +44,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.LspId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspArgs;
@@ -110,27 +110,24 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi
             }
 
             final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.object.lsp.Tlvs tlvs = lsp.getTlvs();
-            final String name;
-            if (tlvs != null && tlvs.getSymbolicPathName() != null) {
-                name = Charsets.UTF_8.decode(ByteBuffer.wrap(tlvs.getSymbolicPathName().getPathName().getValue())).toString();
-            } else {
-                name = lookupLspName(id);
-            }
+            final String name = (tlvs != null && tlvs.getSymbolicPathName() != null) ?
+                Charsets.UTF_8.decode(ByteBuffer.wrap(tlvs.getSymbolicPathName().getPathName().getValue())).toString()
+                : lookupLspName(id);
 
-            final ReportedLspBuilder rlb = new ReportedLspBuilder();
-            rlb.addAugmentation(ReportedLsp1.class, new ReportedLsp1Builder().setLsp(lsp).build());
             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();
+            // set 0 by default, as the first report does not contain LSPIdentifiersTLV
+            pb.setLspId(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId(0L));
             if (r.getPath() != null) {
                 pb.fieldsFrom(r.getPath());
             }
-            // set 0 by default, as the first report does not contain LSPIdentifiersTLV
-            pb.setLspId(new LspId(0L));
+
+            final ReportedLspBuilder rlb = new ReportedLspBuilder();
+            rlb.addAugmentation(ReportedLsp1.class, new ReportedLsp1Builder().setLsp(lsp).build());
             rlb.setPath(Collections.singletonList(pb.build()));
             boolean solicited = false;
 
             if (id.getValue() != 0) {
                 solicited = true;
-
                 final PCEPRequest req = removeRequest(name);
                 if (req != null) {
                     LOG.debug("Request {} resulted in LSP operational state {}", id, lsp.isOperational());
@@ -168,7 +165,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi
                     return OperationResults.UNSENT.future();
                 }
 
-                final SymbolicPathNameBuilder name = new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(input.getName().getBytes()));
+                final SymbolicPathNameBuilder name = new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(input.getName().getBytes(Charsets.UTF_8)));
 
                 // Build the request
                 final RequestsBuilder rb = new RequestsBuilder();
@@ -199,20 +196,14 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi
         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
             @Override
             public ListenableFuture<OperationResult> apply(final Optional<ReportedLsp> rep) {
-                if (!rep.isPresent()) {
-                    LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
+                final Lsp reportedLsp = validateReportedLsp(rep, input);
+                if (reportedLsp == null) {
+                    LOG.warn("Reported LSP does not contain LSP object.");
                     return OperationResults.UNSENT.future();
                 }
-
-                final ReportedLsp1 ra = rep.get().getAugmentation(ReportedLsp1.class);
-                Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
-                final Lsp reportedLsp = ra.getLsp();
-                Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
-
                 // Build the request and send it
                 final UpdatesBuilder rb = new UpdatesBuilder();
                 rb.setLsp(new LspBuilder().setRemove(Boolean.TRUE).setPlspId(reportedLsp.getPlspId()).setDelegate(reportedLsp.isDelegate()).build());
-
                 final PcupdMessageBuilder ib = new PcupdMessageBuilder(MESSAGE_HEADER);
                 ib.setUpdates(Collections.singletonList(rb.build()));
                 return sendMessage(new PcupdBuilder().setPcupdMessage(ib.build()).build(), rep.get().getName(), null);
@@ -230,19 +221,13 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi
         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
             @Override
             public ListenableFuture<OperationResult> apply(final Optional<ReportedLsp> rep) {
-                if (!rep.isPresent()) {
-                    LOG.warn("Node {} does not contain LSP {}", input.getNode(), input.getName());
+                final Lsp reportedLsp = validateReportedLsp(rep, input);
+                if (reportedLsp == null) {
                     return OperationResults.UNSENT.future();
                 }
-
-                final ReportedLsp1 ra = rep.get().getAugmentation(ReportedLsp1.class);
-                Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
-                final Lsp reportedLsp = ra.getLsp();
-                Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
                 final Arguments2 args = input.getArguments().getAugmentation(Arguments2.class);
                 Preconditions.checkArgument(args != null, "Input is missing operational tag.");
                 Preconditions.checkArgument(input.getArguments().getEro() != null, "Input is missing ERO object.");
-
                 // Build the PCUpd request and send it
                 final UpdatesBuilder rb = new UpdatesBuilder();
                 rb.setLsp(new LspBuilder().setPlspId(reportedLsp.getPlspId()).setDelegate(reportedLsp.isDelegate()).setOperational(args.isOperational()).build());
@@ -276,24 +261,28 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi
         return Futures.transform(f, new Function<Optional<ReportedLsp>, OperationResult>() {
             @Override
             public OperationResult apply(final Optional<ReportedLsp> rep) {
-                if (!rep.isPresent()) {
-                    LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
-                    return OperationResults.UNSENT;
-                }
-
-                final ReportedLsp1 ra = rep.get().getAugmentation(ReportedLsp1.class);
-                if (ra == null) {
-                    LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName());
-                    return OperationResults.UNSENT;
-                }
-                final Lsp reportedLsp = ra.getLsp();
-                Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
-                if (reportedLsp.isOperational().equals(op)) {
-                    return OperationResults.SUCCESS;
-                } else {
+                final Lsp reportedLsp = validateReportedLsp(rep, input);
+                if (reportedLsp == null) {
                     return OperationResults.UNSENT;
                 }
+                return reportedLsp.isOperational().equals(op) ? OperationResults.SUCCESS : OperationResults.UNSENT;
             }
         });
     }
+
+    @Override
+    protected Lsp validateReportedLsp(final Optional<ReportedLsp> rep, final LspId input) {
+        if (!rep.isPresent()) {
+            LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
+            return null;
+        }
+        final ReportedLsp1 ra = rep.get().getAugmentation(ReportedLsp1.class);
+        if (ra == null) {
+            LOG.warn("Reported LSP reported null from data-store.");
+            return null;
+        }
+        final Lsp reportedLsp = ra.getLsp();
+        Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
+        return reportedLsp;
+    }
 }
index f6a41aa5c4bc9fa05607ff1f33624afcbb62ff06..ba15a73366669d18d9daf0a6a0b66e0f4c19660f 100644 (file)
@@ -57,9 +57,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.LspId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspArgs;
@@ -104,47 +104,46 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
         }
     }
 
-    @Override
-    protected boolean onMessage(final MessageContext ctx, final Message message) {
-        if (message instanceof PcerrMessage) {
-            final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessage errMsg = ((PcerrMessage) message).getPcerrMessage();
-            if (errMsg.getErrorType() instanceof StatefulCase) {
-                final StatefulCase stat = (StatefulCase)errMsg.getErrorType();
-                for (final Srps srps : stat.getStateful().getSrps()) {
-                    final SrpIdNumber id = srps.getSrp().getOperationId();
-                    if (id.getValue() != 0) {
-                        final PCEPRequest req = removeRequest(id);
-                        if (req != null) {
-                            req.done(OperationResults.createFailed(errMsg.getErrors()));
-                        } else {
-                            LOG.warn("Request ID {} not found in outstanding DB", id);
-                        }
+    private boolean handleErrorMessage(final PcerrMessage message) {
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessage errMsg = message.getPcerrMessage();
+        if (errMsg.getErrorType() instanceof StatefulCase) {
+            final StatefulCase stat = (StatefulCase)errMsg.getErrorType();
+            for (final Srps srps : stat.getStateful().getSrps()) {
+                final SrpIdNumber id = srps.getSrp().getOperationId();
+                if (id.getValue() != 0) {
+                    final PCEPRequest req = removeRequest(id);
+                    if (req != null) {
+                        req.done(OperationResults.createFailed(errMsg.getErrors()));
+                    } else {
+                        LOG.warn("Request ID {} not found in outstanding DB", id);
                     }
                 }
-            } else {
-                LOG.warn("Unhandled PCErr message {}.", errMsg);
-                return true;
             }
-            return false;
+        } else {
+            LOG.warn("Unhandled PCErr message {}.", errMsg);
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    protected boolean onMessage(final MessageContext ctx, final Message message) {
+        if (message instanceof PcerrMessage) {
+            return handleErrorMessage((PcerrMessage) message);
         }
         if (!(message instanceof PcrptMessage)) {
             return true;
         }
-
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.PcrptMessage rpt = ((PcrptMessage) message).getPcrptMessage();
         for (final Reports report : rpt.getReports()) {
             final Lsp lsp = report.getLsp();
             final PlspId plspid = lsp.getPlspId();
-
             if (!lsp.isSync() && (lsp.getPlspId() == null || plspid.getValue() == 0)) {
                 stateSynchronizationAchieved(ctx);
                 continue;
             }
-
             final ReportedLspBuilder rlb = new ReportedLspBuilder();
-
             boolean solicited = false;
-
             final Srp srp = report.getSrp();
             if (srp != null) {
                 final SrpIdNumber id = srp.getOperationId();
@@ -180,17 +179,6 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
                     }
                 }
             }
-            final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.Tlvs tlvs = report.getLsp().getTlvs();
-            final String name;
-            if (tlvs != null && tlvs.getSymbolicPathName() != null) {
-                name = Charsets.UTF_8.decode(ByteBuffer.wrap(tlvs.getSymbolicPathName().getPathName().getValue())).toString();
-            } else {
-                name = null;
-            }
-            LspId lspid = null;
-            if (tlvs != null && tlvs.getLspIdentifiers() != null) {
-                lspid = tlvs.getLspIdentifiers().getLspId();
-            }
             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());
@@ -198,7 +186,16 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
             // LSP is mandatory (if there is none, parser will throw an exception)
             // this is to ensure a path will be created at any rate
             pb.addAugmentation(Path1.class, new Path1Builder().setLsp(report.getLsp()).build());
-            pb.setLspId(lspid);
+            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) {
+                    pb.setLspId(tlvs.getLspIdentifiers().getLspId());
+                }
+                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);
@@ -267,17 +264,10 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
             @Override
             public ListenableFuture<OperationResult> apply(final Optional<ReportedLsp> rep) {
-                if (!rep.isPresent()) {
-                    LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
+                final Lsp reportedLsp = validateReportedLsp(rep, input);
+                if (reportedLsp == null) {
                     return OperationResults.UNSENT.future();
                 }
-
-                // it doesn't matter how many lsps there are in the path list, we only need delegate & plspid that is the same in each path
-                final Path1 ra = rep.get().getPath().get(0).getAugmentation(Path1.class);
-                Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
-                final Lsp reportedLsp = ra.getLsp();
-                Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
-
                 // Build the request and send it
                 final RequestsBuilder rb = new RequestsBuilder();
                 rb.setSrp(new SrpBuilder().addAugmentation(Srp1.class, new Srp1Builder().setRemove(Boolean.TRUE).build()).setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build());
@@ -301,27 +291,17 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
             @Override
             public ListenableFuture<OperationResult> apply(final Optional<ReportedLsp> rep) {
-                if (!rep.isPresent()) {
-                    LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
+                final Lsp reportedLsp = validateReportedLsp(rep, input);
+                if (reportedLsp == null) {
                     return OperationResults.UNSENT.future();
                 }
-
-                // it doesn't matter how many lsps there are in the path list, we only need plspid that is the same in each path
-                final Path1 ra = rep.get().getPath().get(0).getAugmentation(Path1.class);
-                Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
-                final Lsp reportedLsp = ra.getLsp();
-                Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
-
                 // create mandatory objects
                 final Srp srp = new SrpBuilder().setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build();
 
                 final Lsp inputLsp = input.getArguments().getAugmentation(Arguments3.class).getLsp();
-                Lsp lsp = null;
-                if (inputLsp != null) {
-                    lsp = new LspBuilder().setPlspId(reportedLsp.getPlspId()).setDelegate((inputLsp.isDelegate() != null) ? inputLsp.isDelegate() : false).setTlvs(inputLsp.getTlvs()).setAdministrative((inputLsp.isAdministrative() != null) ? inputLsp.isAdministrative() : false).build();
-                } else {
-                    lsp = new LspBuilder().setPlspId(reportedLsp.getPlspId()).build();
-                }
+                final Lsp lsp = (inputLsp != null) ?
+                    new LspBuilder().setPlspId(reportedLsp.getPlspId()).setDelegate((inputLsp.isDelegate() != null) ? inputLsp.isDelegate() : false).setTlvs(inputLsp.getTlvs()).setAdministrative((inputLsp.isAdministrative() != null) ? inputLsp.isAdministrative() : false).build()
+                    : new LspBuilder().setPlspId(reportedLsp.getPlspId()).build();
                 Message msg = null;
                 // the D bit that was reported decides the type of PCE message sent
                 Preconditions.checkNotNull(reportedLsp.isDelegate());
@@ -394,4 +374,18 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
             }
         });
     }
+
+    @Override
+    protected Lsp validateReportedLsp(final Optional<ReportedLsp> rep, final LspId input) {
+        if (!rep.isPresent()) {
+            LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
+            return null;
+        }
+        // it doesn't matter how many lsps there are in the path list, we only need data that is the same in each path
+        final Path1 ra = rep.get().getPath().get(0).getAugmentation(Path1.class);
+        Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
+        final Lsp reportedLsp = ra.getLsp();
+        Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
+        return reportedLsp;
+    }
 }