Enable UUID and name in TAPI RPCs
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / topology / TapiTopologyImpl.java
index fe9418af2e51e63cfa36f36709db3b709ab39f45..3e2ed2aec7daad484ee090d12feafe9729d50a7b 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.transportpce.tapi.topology;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -28,10 +29,10 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.InstanceIdentifiers;
 import org.opendaylight.transportpce.common.NetworkUtils;
 import org.opendaylight.transportpce.tapi.utils.TapiContext;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210425.mapping.Mapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210425.mapping.MappingKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210425.network.Nodes;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210425.network.NodesKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.MappingKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.Nodes;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
@@ -127,11 +128,9 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
     public ListenableFuture<RpcResult<GetNodeDetailsOutput>> getNodeDetails(GetNodeDetailsInput input) {
         // TODO Auto-generated method stub
         // TODO -> maybe we get errors when having CEPs?
-        Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(input.getTopologyIdOrName().getBytes(Charset.forName("UTF-8")))
-                .toString());
+        Uuid topoUuid = getUuidFromIput(input.getTopologyIdOrName());
         // Node id: if roadm -> ROADM+PHOTONIC_MEDIA. if xpdr -> XPDR-XPDR+DSR/OTSi
-        Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(input.getNodeIdOrName().getBytes(Charset.forName("UTF-8")))
-                .toString());
+        Uuid nodeUuid = getUuidFromIput(input.getNodeIdOrName());
         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node = this.tapiContext
                 .getTapiNode(topoUuid, nodeUuid);
         if (node == null) {
@@ -309,15 +308,12 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
             GetNodeEdgePointDetailsInput input) {
         // TODO Auto-generated method stub
         // TODO -> maybe we get errors when having CEPs?
-        Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(input.getTopologyIdOrName().getBytes(Charset.forName("UTF-8")))
-                .toString());
+        Uuid topoUuid = getUuidFromIput(input.getTopologyIdOrName());
         // Node id: if roadm -> ROADMid+PHOTONIC_MEDIA. if xpdr -> XPDRid-XPDRnbr+DSR/OTSi
-        Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(input.getNodeIdOrName().getBytes(Charset.forName("UTF-8")))
-                .toString());
+        Uuid nodeUuid = getUuidFromIput(input.getNodeIdOrName());
         // NEP id: if roadm -> ROADMid+PHOTONIC_MEDIA/MC/OTSiMC+TPid.
         // if xpdr -> XPDRid-XPDRnbr+DSR/eODU/iODU/iOTSi/eOTSi/PHOTONIC_MEDIA+TPid
-        Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(input.getEpIdOrName().getBytes(Charset.forName("UTF-8")))
-                .toString());
+        Uuid nepUuid = getUuidFromIput(input.getEpIdOrName());
         OwnedNodeEdgePoint nep = this.tapiContext.getTapiNEP(topoUuid, nodeUuid, nepUuid);
         if (nep == null) {
             LOG.error("Invalid TAPI nep name");
@@ -331,11 +327,9 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
     @Override
     public ListenableFuture<RpcResult<GetLinkDetailsOutput>> getLinkDetails(GetLinkDetailsInput input) {
         // TODO Auto-generated method stub
-        Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(input.getTopologyIdOrName().getBytes(Charset.forName("UTF-8")))
-                .toString());
+        Uuid topoUuid = getUuidFromIput(input.getTopologyIdOrName());
         // Link id: same as OR link id
-        Uuid linkUuid = new Uuid(UUID.nameUUIDFromBytes(input.getLinkIdOrName().getBytes(Charset.forName("UTF-8")))
-                .toString());
+        Uuid linkUuid = getUuidFromIput(input.getLinkIdOrName());
         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link link = this.tapiContext
                 .getTapiLink(topoUuid, linkUuid);
         if (link == null) {
@@ -398,14 +392,14 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         String networkLcp;
         if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERCLIENT)) {
             networkLcp = tp.augmentation(
-                org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1.class)
+                org.opendaylight.yang.gen.v1.http.transportpce.topology.rev210511.TerminationPoint1.class)
                 .getAssociatedConnectionMapPort();
         } else {
             networkLcp = tp.getTpId().getValue();
         }
         @NonNull
         KeyedInstanceIdentifier<Mapping, MappingKey> pmIID = InstanceIdentifier.create(
-            org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210425.Network.class)
+            org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.Network.class)
             .child(Nodes.class, new NodesKey(nodeIdPortMap)).child(Mapping.class, new MappingKey(networkLcp));
         @NonNull
         FluentFuture<Optional<Mapping>> mappingOpt = dataBroker.newReadOnlyTransaction().read(
@@ -428,9 +422,9 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         switch (networkPortDirection) {
             case "bidirectional":
                 count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo)
-                    && lk.getSource().getSourceTp().equals(networkLcp)).count();
+                    && lk.getSource().getSourceTp().getValue().equals(networkLcp)).count();
                 count += xpdIn.stream().filter(lk -> lk.getDestination().getDestNode().getValue().equals(nodeIdTopo)
-                    && lk.getDestination().getDestTp().equals(networkLcp)).count();
+                    && lk.getDestination().getDestTp().getValue().equals(networkLcp)).count();
                 return (count == 2);
             case "tx":
             case "rx":
@@ -438,15 +432,15 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
                 String partnerLcp = mapping.getPartnerLcp();
                 if (mapping.getPortQual().equals("tx")) {
                     count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo)
-                        && lk.getSource().getSourceTp().equals(networkLcp)).count();
+                        && lk.getSource().getSourceTp().getValue().equals(networkLcp)).count();
                     count += xpdIn.stream().filter(lk -> lk.getDestination().getDestNode().getValue().equals(nodeIdTopo)
-                        && lk.getDestination().getDestTp().equals(partnerLcp)).count();
+                        && lk.getDestination().getDestTp().getValue().equals(partnerLcp)).count();
                 }
                 if (mapping.getPortQual().equals("rx")) {
                     count += xpdIn.stream().filter(lk -> lk.getDestination().getDestNode().getValue().equals(nodeIdTopo)
-                        && lk.getDestination().getDestTp().equals(networkLcp)).count();
+                        && lk.getDestination().getDestTp().getValue().equals(networkLcp)).count();
                     count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo)
-                        && lk.getSource().getSourceTp().equals(partnerLcp)).count();
+                        && lk.getSource().getSourceTp().getValue().equals(partnerLcp)).count();
                 }
                 return (count == 2);
             default:
@@ -492,7 +486,7 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
     @Override
     public ListenableFuture<RpcResult<GetServiceInterfacePointDetailsOutput>>
             getServiceInterfacePointDetails(GetServiceInterfacePointDetailsInput input) {
-        Uuid sipUuid = new Uuid(input.getSipIdOrName());
+        Uuid sipUuid = getUuidFromIput(input.getSipIdOrName());
         Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips =
             this.tapiContext.getTapiContext().getServiceInterfacePoint();
         if (sips == null || sips.isEmpty()) {
@@ -537,4 +531,15 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         // TODO --> not yet implemented
         return null;
     }
+
+    private Uuid getUuidFromIput(String serviceIdOrName) {
+        try {
+            UUID.fromString(serviceIdOrName);
+            LOG.info("Given attribute {} is a UUID", serviceIdOrName);
+            return new Uuid(serviceIdOrName);
+        } catch (IllegalArgumentException e) {
+            LOG.info("Given attribute {} is not a UUID", serviceIdOrName);
+            return new Uuid(UUID.nameUUIDFromBytes(serviceIdOrName.getBytes(StandardCharsets.UTF_8)).toString());
+        }
+    }
 }