Use version 13.1.0 of openroadm-network models
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / topology / TapiTopologyImpl.java
index 4cbb8565f36714c374de6e671f77f71298243af7..2bd1b333f3d011757f260f684f4a0b558e2e5fb6 100644 (file)
@@ -19,6 +19,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
+import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
@@ -31,15 +32,15 @@ import org.opendaylight.transportpce.common.NetworkUtils;
 import org.opendaylight.transportpce.tapi.TapiStringConstants;
 import org.opendaylight.transportpce.tapi.utils.TapiContext;
 import org.opendaylight.transportpce.tapi.utils.TapiLink;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.Mapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.MappingKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.network.Nodes;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.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;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
+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.mapping.MappingKey;
+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.openroadm.common.network.rev230526.Link1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmLinkType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmTpType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
@@ -107,7 +108,7 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.to
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.TopologyKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
@@ -140,8 +141,9 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
                 .getTapiNode(topoUuid, nodeUuid);
         if (node == null) {
             LOG.error("Invalid TAPI node name");
-            return RpcResultBuilder.<GetNodeDetailsOutput>failed().withError(RpcError.ErrorType.RPC,
-                "Invalid Tapi Node name").buildFuture();
+            return RpcResultBuilder.<GetNodeDetailsOutput>failed()
+                .withError(ErrorType.RPC, "Invalid Tapi Node name")
+                .buildFuture();
         }
         return RpcResultBuilder.success(new GetNodeDetailsOutputBuilder()
                 .setNode(new org.opendaylight.yang.gen.v1.urn
@@ -164,7 +166,8 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
                 if (!(topologyMap != null && topologyMap.containsKey(new TopologyKey(topoUuid)))) {
                     LOG.error("Topology {} not found in datastore", input.getTopologyIdOrName());
                     return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
-                        .withError(RpcError.ErrorType.RPC, "Invalid Topology name").buildFuture();
+                        .withError(ErrorType.RPC, "Invalid Topology name")
+                        .buildFuture();
                 }
                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology
                     topology = topologyMap.get(new TopologyKey(topoUuid));
@@ -175,7 +178,8 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
             }
             LOG.error("Invalid TAPI topology name");
             return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
-                .withError(RpcError.ErrorType.RPC, "Invalid Topology name").buildFuture();
+                .withError(ErrorType.RPC, "Invalid Topology name")
+                .buildFuture();
         }
         try {
             LOG.info("Building TAPI Topology abstraction for {}", input.getTopologyIdOrName());
@@ -188,7 +192,8 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         } catch (TapiTopologyException e) {
             LOG.error("error building TAPI topology");
             return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
-                .withError(RpcError.ErrorType.RPC, "Error building topology").buildFuture();
+                .withError(ErrorType.RPC, "Error building topology")
+                .buildFuture();
         }
     }
 
@@ -221,7 +226,7 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         FluentFuture<Optional<Network>> topologyFuture = dataBroker.newReadOnlyTransaction()
             .read(LogicalDatastoreType.CONFIGURATION, networkIID);
         try {
-            topology = topologyFuture.get().get();
+            topology = topologyFuture.get().orElseThrow();
         } catch (InterruptedException e) {
             Thread.currentThread().interrupt();
             throw new TapiTopologyException("Unable to get from mdsal topology: " + networkIID
@@ -258,7 +263,7 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
             String portMappingNodeId = entry.getValue().getSupportingNode().values().stream()
                 .filter(sn -> sn.getNetworkRef().getValue().equals(NetworkUtils.UNDERLAY_NETWORK_ID))
                 .findFirst()
-                .get().getNodeRef().getValue();
+                .orElseThrow().getNodeRef().getValue();
             List<String> networkPortList = new ArrayList<>();
             for (TerminationPoint tp: entry.getValue().augmentation(Node1.class).getTerminationPoint().values()) {
                 if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)
@@ -285,9 +290,12 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
             tapiNodeList.putAll(tapiFactory.getTapiNodes());
             tapiLinkList.putAll(tapiFactory.getTapiLinks());
         }
-        if (openroadmTopo.nonnullNode().values().stream().filter(nt ->
-                nt.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1.class)
-                    .getNodeType().equals(OpenroadmNodeType.SRG)).count() > 0) {
+        if (openroadmTopo.nonnullNode().values().stream()
+                .filter(nt -> nt
+                    .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Node1.class)
+                    .getNodeType()
+                    .equals(OpenroadmNodeType.SRG))
+                .count() > 0) {
             tapiFactory.convertRoadmInfrastructure();
             tapiNodeList.putAll(tapiFactory.getTapiNodes());
             tapiLinkList.putAll(tapiFactory.getTapiLinks());
@@ -326,8 +334,9 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         OwnedNodeEdgePoint nep = this.tapiContext.getTapiNEP(topoUuid, nodeUuid, nepUuid);
         if (nep == null) {
             LOG.error("Invalid TAPI nep name");
-            return RpcResultBuilder.<GetNodeEdgePointDetailsOutput>failed().withError(RpcError.ErrorType.RPC,
-                "Invalid NEP name").buildFuture();
+            return RpcResultBuilder.<GetNodeEdgePointDetailsOutput>failed()
+                .withError(ErrorType.RPC, "Invalid NEP name")
+                .buildFuture();
         }
         return RpcResultBuilder.success(new GetNodeEdgePointDetailsOutputBuilder()
                 .setNodeEdgePoint(new NodeEdgePointBuilder(nep).build()).build()).buildFuture();
@@ -343,8 +352,9 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
                 .getTapiLink(topoUuid, linkUuid);
         if (link == null) {
             LOG.error("Invalid TAPI link name");
-            return RpcResultBuilder.<GetLinkDetailsOutput>failed().withError(RpcError.ErrorType.RPC,
-                "Invalid Link name").buildFuture();
+            return RpcResultBuilder.<GetLinkDetailsOutput>failed()
+                .withError(ErrorType.RPC, "Invalid Link name")
+                .buildFuture();
         }
         return RpcResultBuilder.success(new GetLinkDetailsOutputBuilder().setLink(new LinkBuilder(link).build())
                 .build()).buildFuture();
@@ -359,8 +369,9 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
                 topologyMap = this.tapiContext.getTopologyContext();
         if (topologyMap.isEmpty()) {
             LOG.error("No topologies exist in tapi context");
-            return RpcResultBuilder.<GetTopologyListOutput>failed().withError(RpcError.ErrorType.APPLICATION,
-                "No topologies exist in tapi context").buildFuture();
+            return RpcResultBuilder.<GetTopologyListOutput>failed()
+                .withError(ErrorType.APPLICATION, "No topologies exist in tapi context")
+                .buildFuture();
         }
         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.list.output.TopologyKey,
             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.list.output.Topology>
@@ -387,7 +398,7 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         return new NodeBuilder()
                 .setUuid(nodeUuid)
                 .setName(Map.of(name.key(), name))
-                .setLayerProtocolName(List.of(LayerProtocolName.ETH))
+                .setLayerProtocolName(Set.of(LayerProtocolName.ETH))
                 .setAdministrativeState(AdministrativeState.UNLOCKED)
                 .setOperationalState(OperationalState.ENABLED)
                 .setLifecycleState(LifecycleState.INSTALLED)
@@ -401,14 +412,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.rev210511.TerminationPoint1.class)
-                .getAssociatedConnectionMapPort();
+                    org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1.class)
+                .getAssociatedConnectionMapTp().iterator().next().getValue();
         } else {
             networkLcp = tp.getTpId().getValue();
         }
         @NonNull
         KeyedInstanceIdentifier<Mapping, MappingKey> pmIID = InstanceIdentifier.create(
-            org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.Network.class)
+            org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.Network.class)
             .child(Nodes.class, new NodesKey(nodeIdPortMap)).child(Mapping.class, new MappingKey(networkLcp));
         @NonNull
         FluentFuture<Optional<Mapping>> mappingOpt = dataBroker.newReadOnlyTransaction().read(
@@ -416,7 +427,7 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         Mapping mapping = null;
         if (mappingOpt.isDone()) {
             try {
-                mapping = mappingOpt.get().get();
+                mapping = mappingOpt.get().orElseThrow();
             } catch (InterruptedException | ExecutionException e) {
                 LOG.error("Error getting mapping for {}", networkLcp, e);
                 return false;
@@ -499,12 +510,14 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips =
             this.tapiContext.getTapiContext().getServiceInterfacePoint();
         if (sips == null || sips.isEmpty()) {
-            return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed().withError(RpcError.ErrorType.RPC,
-                "No sips in datastore").buildFuture();
+            return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed()
+                .withError(ErrorType.RPC, "No sips in datastore")
+                .buildFuture();
         }
         if (!sips.containsKey(new ServiceInterfacePointKey(sipUuid))) {
-            return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed().withError(RpcError.ErrorType.RPC,
-                "Sip doesnt exist in datastore").buildFuture();
+            return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed()
+                .withError(ErrorType.RPC, "Sip doesnt exist in datastore")
+                .buildFuture();
         }
         org.opendaylight.yang.gen.v1.urn
             .onf.otcc.yang.tapi.common.rev181210.get.service._interface.point.details.output.Sip outSip =
@@ -522,8 +535,9 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService
         Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips =
             this.tapiContext.getTapiContext().getServiceInterfacePoint();
         if (sips == null || sips.isEmpty()) {
-            return RpcResultBuilder.<GetServiceInterfacePointListOutput>failed().withError(RpcError.ErrorType.RPC,
-                "No sips in datastore").buildFuture();
+            return RpcResultBuilder.<GetServiceInterfacePointListOutput>failed()
+                .withError(ErrorType.RPC, "No sips in datastore")
+                .buildFuture();
         }
         Map<SipKey, Sip> outSipMap = new HashMap<>();
         for (ServiceInterfacePoint sip : sips.values()) {