Enable UUID and name in TAPI RPCs 89/97889/9
authorerrea <errea@eurecom.fr>
Thu, 14 Oct 2021 15:12:04 +0000 (17:12 +0200)
committererrea <errea@eurecom.fr>
Tue, 2 Nov 2021 17:34:48 +0000 (18:34 +0100)
Improvement to enable the use of either UUID or name
when performing TAPI rpcs.

JIRA: TRNSPRTPCE-564
Signed-off-by: errea <errea@eurecom.fr>
Change-Id: I8d9a2c4c25514bad0be0115a53fd6fd243187780

tapi/src/main/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImpl.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java

index cd5d1da72a2609f76cdf9bf07f60f8bd76dfb56f..c62645344fa24bc294d9d33607f23921a1328c61 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.transportpce.tapi.connectivity;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
@@ -230,7 +230,7 @@ public class TapiConnectivityImpl implements TapiConnectivityService {
     public ListenableFuture<RpcResult<GetConnectivityServiceDetailsOutput>> getConnectivityServiceDetails(
             GetConnectivityServiceDetailsInput input) {
         // TODO Auto-generated method stub
-        Uuid serviceUuid = new Uuid(input.getServiceIdOrName());
+        Uuid serviceUuid = getUuidFromIput(input.getServiceIdOrName());
         ConnectivityService service = this.tapiContext.getConnectivityService(serviceUuid);
         if (service == null) {
             LOG.error("Service {} doesnt exist in tapi context", input.getServiceIdOrName());
@@ -254,8 +254,7 @@ public class TapiConnectivityImpl implements TapiConnectivityService {
     public ListenableFuture<RpcResult<GetConnectionDetailsOutput>> getConnectionDetails(
             GetConnectionDetailsInput input) {
         // TODO Auto-generated method stub
-        Uuid connectionUuid = new Uuid(UUID.nameUUIDFromBytes(input.getConnectionIdOrName()
-            .getBytes(Charset.forName("UTF-8"))).toString());
+        Uuid connectionUuid = getUuidFromIput(input.getConnectionIdOrName());
         Connection connection = this.tapiContext.getConnection(connectionUuid);
         if (connection == null) {
             LOG.error("Connection {} doesnt exist in tapi context", input.getConnectionIdOrName());
@@ -273,7 +272,7 @@ public class TapiConnectivityImpl implements TapiConnectivityService {
         // TODO add try
         if (input.getServiceIdOrName() != null) {
             try {
-                Uuid serviceUuid = new Uuid(input.getServiceIdOrName());
+                Uuid serviceUuid = getUuidFromIput(input.getServiceIdOrName());
                 this.tapiContext.deleteConnectivityService(serviceUuid);
                 ListenableFuture<RpcResult<ServiceDeleteOutput>> output =
                     this.serviceHandler.serviceDelete(new ServiceDeleteInputBuilder()
@@ -329,14 +328,10 @@ public class TapiConnectivityImpl implements TapiConnectivityService {
     public ListenableFuture<RpcResult<GetConnectionEndPointDetailsOutput>> getConnectionEndPointDetails(
             GetConnectionEndPointDetailsInput input) {
         // TODO Auto-generated method stub
-        Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(input.getTopologyIdOrName()
-            .getBytes(Charset.forName("UTF-8"))).toString());
-        Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(input.getNodeIdOrName()
-            .getBytes(Charset.forName("UTF-8"))).toString());
-        Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(input.getNepIdOrName()
-            .getBytes(Charset.forName("UTF-8"))).toString());
-        Uuid cepUuid = new Uuid(UUID.nameUUIDFromBytes(input.getCepIdOrName()
-            .getBytes(Charset.forName("UTF-8"))).toString());
+        Uuid topoUuid = getUuidFromIput(input.getTopologyIdOrName());
+        Uuid nodeUuid = getUuidFromIput(input.getNodeIdOrName());
+        Uuid nepUuid = getUuidFromIput(input.getNepIdOrName());
+        Uuid cepUuid = getUuidFromIput(input.getCepIdOrName());
         ConnectionEndPoint cep = this.tapiContext.getTapiCEP(topoUuid, nodeUuid, nepUuid, cepUuid);
         if (cep == null) {
             LOG.error("Cep doesnt exist in tapi context");
@@ -346,4 +341,15 @@ public class TapiConnectivityImpl implements TapiConnectivityService {
         return RpcResultBuilder.success(new GetConnectionEndPointDetailsOutputBuilder().setConnectionEndPoint(
             new ConnectionEndPointBuilder(cep).build()).build()).buildFuture();
     }
+
+    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());
+        }
+    }
 }
index aa47df70207c82f6314ca2d6bbf00edc99e7a96d..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;
@@ -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) {
@@ -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());
+        }
+    }
 }