Refactor TAPI topology TAPIOrLinkListener
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / R2RTapiLinkDiscovery.java
index 3af6fec15a1c878adc4a3003358cfc5a3fbec211..886aac77888ab8e992268ec43ff2970d0773869e 100644 (file)
@@ -21,11 +21,11 @@ import org.opendaylight.transportpce.common.Timeouts;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
 import org.opendaylight.transportpce.tapi.utils.TapiLink;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.Network;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.cp.to.degree.CpToDegree;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.Mapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.Nodes;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.NodesKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.Network;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.cp.to.degree.CpToDegree;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.network.Nodes;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.network.NodesKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceData;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
@@ -34,10 +34,10 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.conta
 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.Direction;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LayerProtocolName;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.LinkKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -76,7 +76,8 @@ public class R2RTapiLinkDiscovery {
                     return new HashMap<>();
                 }
                 // get neighbor list
-                NbrList nbr121List = protocol121Object.get().augmentation(Protocols1.class).getLldp().getNbrList();
+                NbrList nbr121List = protocol121Object.orElseThrow().augmentation(Protocols1.class).getLldp()
+                    .getNbrList();
                 LOG.info("LLDP subtree is present. Device has {} neighbours", nbr121List.getIfName().size());
                 // try to create rdm2rdm link
                 return rdm2rdmLinkCreatev121(nodeId, tapiTopoUuid, nbr121List);
@@ -98,7 +99,7 @@ public class R2RTapiLinkDiscovery {
                     LOG.warn("LLDP subtree is missing or incomplete: isolated openroadm device");
                     return new HashMap<>();
                 }
-                var nbr221List = protocol221Object.get().augmentation(
+                var nbr221List = protocol221Object.orElseThrow().augmentation(
                         org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1.class)
                     .getLldp().getNbrList();
                 LOG.info("LLDP subtree is present. Device has {} neighbours", nbr221List.getIfName().size());
@@ -115,21 +116,21 @@ public class R2RTapiLinkDiscovery {
 
     private boolean hasNoNeighbor121(Optional<Protocols> protocol121Object) {
         return protocol121Object.isEmpty()
-                || protocol121Object.get().augmentation(Protocols1.class) == null
-                || protocol121Object.get().augmentation(Protocols1.class).getLldp() == null
-                || protocol121Object.get().augmentation(Protocols1.class).getLldp().getNbrList() == null;
+                || protocol121Object.orElseThrow().augmentation(Protocols1.class) == null
+                || protocol121Object.orElseThrow().augmentation(Protocols1.class).getLldp() == null
+                || protocol121Object.orElseThrow().augmentation(Protocols1.class).getLldp().getNbrList() == null;
     }
 
     private boolean hasNoNeighbor221(Optional<
             org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org
                     .openroadm.device.Protocols> protocol221Object) {
         return protocol221Object.isEmpty()
-                || protocol221Object.get().augmentation(
+                || protocol221Object.orElseThrow().augmentation(
                         org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1.class) == null
-                || protocol221Object.get().augmentation(
+                || protocol221Object.orElseThrow().augmentation(
                         org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1.class)
                     .getLldp() == null
-                || protocol221Object.get().augmentation(
+                || protocol221Object.orElseThrow().augmentation(
                         org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1.class)
                     .getLldp().getNbrList() == null;
     }
@@ -248,11 +249,14 @@ public class R2RTapiLinkDiscovery {
             + "DestDegId: {}, DestTPId: {}", nodeId.getValue(), srcDegId, srcTpTx, destNodeId, destDegId, destTpRx);
         Link omsLink = this.tapiLink.createTapiLink(nodeId.getValue(), srcTpTx, destNodeId.getValue(), destTpTx,
             TapiStringConstants.OMS_RDM_RDM_LINK, TapiStringConstants.PHTNC_MEDIA, TapiStringConstants.PHTNC_MEDIA,
-            TapiStringConstants.PHTNC_MEDIA, TapiStringConstants.PHTNC_MEDIA,
+            TapiStringConstants.PHTNC_MEDIA_OTS, TapiStringConstants.PHTNC_MEDIA_OTS,
             this.tapiLink.getAdminState(nodeId.getValue(), destNodeId.getValue(), srcTpTx, destTpTx),
             this.tapiLink.getOperState(nodeId.getValue(), destNodeId.getValue(), srcTpTx, destTpTx),
             Set.of(LayerProtocolName.PHOTONICMEDIA), Set.of(LayerProtocolName.PHOTONICMEDIA.getName()), tapiTopoUuid);
         LOG.info("Tapi R2R Link OMS link created = {}", omsLink);
+        LOG.debug("inputAdminstate= {}, inputoperstate = {}",
+            this.tapiLink.getAdminState(nodeId.getValue(), destNodeId.getValue(), srcTpTx, destTpTx),
+            this.tapiLink.getOperState(nodeId.getValue(), destNodeId.getValue(), srcTpTx, destTpTx));
         return omsLink;
     }
 
@@ -263,12 +267,12 @@ public class R2RTapiLinkDiscovery {
 
             Optional<Nodes> nodesObject = this.networkTransactionService.read(LogicalDatastoreType.CONFIGURATION,
                 nodesIID).get();
-            if (nodesObject.isEmpty() || (nodesObject.get().getCpToDegree() == null)) {
+            if (nodesObject.isEmpty() || (nodesObject.orElseThrow().getCpToDegree() == null)) {
                 LOG.warn("Could not find mapping for Interface {} for nodeId {}", interfaceName,
                     nodeId.getValue());
                 return null;
             }
-            Collection<CpToDegree> cpToDeg = nodesObject.get().nonnullCpToDegree().values();
+            Collection<CpToDegree> cpToDeg = nodesObject.orElseThrow().nonnullCpToDegree().values();
             Stream<CpToDegree> cpToDegStream = cpToDeg.stream().filter(cp -> cp.getInterfaceName() != null)
                 .filter(cp -> cp.getInterfaceName().equals(interfaceName));
             if (cpToDegStream != null) {
@@ -277,8 +281,8 @@ public class R2RTapiLinkDiscovery {
                     LOG.debug("Not found so returning nothing");
                     return null;
                 }
-                LOG.debug("Found and returning {}",firstCpToDegree.get().getDegreeNumber().intValue());
-                return firstCpToDegree.get().getDegreeNumber().intValue();
+                LOG.debug("Found and returning {}",firstCpToDegree.orElseThrow().getDegreeNumber().intValue());
+                return firstCpToDegree.orElseThrow().getDegreeNumber().intValue();
             } else {
                 LOG.warn("CircuitPack stream couldnt find anything for nodeId: {} and interfaceName: {}",
                     nodeId.getValue(),interfaceName);
@@ -295,8 +299,8 @@ public class R2RTapiLinkDiscovery {
         try {
             Optional<Nodes> nodesObject = this.networkTransactionService.read(LogicalDatastoreType.CONFIGURATION,
                 nodesIID).get();
-            if (nodesObject.isPresent() && (nodesObject.get().getMapping() != null)) {
-                Collection<Mapping> mappingList = nodesObject.get().nonnullMapping().values();
+            if (nodesObject.isPresent() && (nodesObject.orElseThrow().getMapping() != null)) {
+                Collection<Mapping> mappingList = nodesObject.orElseThrow().nonnullMapping().values();
                 mappingList = mappingList.stream().filter(mp -> mp.getLogicalConnectionPoint().contains("DEG"
                     + degreeCounter)).collect(Collectors.toList());
                 if (mappingList.size() == 1) {