Fix TAPI Sonar issues 42/90242/6
authormanuedelf <emmanuelle.delfour@gmail.com>
Thu, 4 Jun 2020 08:33:58 +0000 (10:33 +0200)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Mon, 8 Jun 2020 07:36:08 +0000 (09:36 +0200)
JIRA: TRNSPRTPCE-215
Change-Id: I7ce7da54928748392ecb68877a8159cddbd40b4b

tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/TapiImpl.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/TapiProvider.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/ConvertORTopoObjectToTapiTopoObject.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/utils/MappingUtils.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/utils/TapiUtils.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/checks/ConnConstraintCheck.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/checks/EndPointCheck.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/checks/TopoConstraintCheck.java

index 8d010079c663995e34f0d5f1f2d802164100ef06..a43e638bbf5a2398dca6cd6152c5baa58f056bab 100644 (file)
@@ -19,8 +19,6 @@ import org.opendaylight.transportpce.tapi.utils.MappingUtils;
 import org.opendaylight.transportpce.tapi.utils.TapiUtils;
 import org.opendaylight.transportpce.tapi.validation.CreateConnectivityServiceValidation;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
-//import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput;
-//import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
 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.common.rev181210.global._class.Name;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
@@ -70,7 +68,7 @@ public class TapiImpl implements TapiConnectivityService {
     @Override
     public ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> createConnectivityService(
         CreateConnectivityServiceInput input) {
-        LOG.info("RPC create-connectivity received: {}", input.getEndPoint().toString());
+        LOG.info("RPC create-connectivity received: {}", input.getEndPoint());
         OperationResult validationResult = CreateConnectivityServiceValidation.validateCreateConnectivityServiceRequest(
             input);
         if (validationResult.isSuccess()) {
@@ -150,11 +148,7 @@ public class TapiImpl implements TapiConnectivityService {
     @Override
     public ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> deleteConnectivityService(
         DeleteConnectivityServiceInput input) {
-        LOG.info("RPC delete-connectivity received");
-        //ServiceDeleteInput inputSh = null;
-        //this.serviceHandler.serviceDelete(inputSh);
-        this.serviceHandler.serviceDelete(null);
-        //TODO to continue...
+        //TODO Auto-generated method stub
         return null;
     }
 
index 78ce5441cf0a89e51057c731b5bba239b1aa71f9..03708beb7d9bf24bc6c319ad3a44978ba3b0d0f8 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.transportpce.tapi.utils.TapiListener;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -37,9 +36,7 @@ public class TapiProvider {
     private final DataBroker dataBroker;
     private final RpcProviderService rpcProviderService;
     private ObjectRegistration<TapiConnectivityService> rpcRegistration;
-    private ObjectRegistration<TapiTopologyService> rpcRegistration2;
     private final ServiceHandlerOperations serviceHandler;
-    private ListenerRegistration<TapiListener> listenerRegistration;
     private final TapiListener tapiListener;
 
     public TapiProvider(DataBroker dataBroker, RpcProviderService rpcProviderService,
@@ -58,10 +55,10 @@ public class TapiProvider {
         TapiImpl tapi = new TapiImpl(this.serviceHandler);
         TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker);
         rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
-        rpcRegistration2 = rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
+        rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
         @NonNull
         InstanceIdentifier<ServiceInterfacePoints> sipIID = InstanceIdentifier.create(ServiceInterfacePoints.class);
-        listenerRegistration = dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
+        dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
             LogicalDatastoreType.CONFIGURATION, sipIID), tapiListener);
     }
 
@@ -70,7 +67,6 @@ public class TapiProvider {
      */
     public void close() {
         LOG.info("TapiProvider Session Closed");
-        // pcelistenerRegistration.close();
         rpcRegistration.close();
     }
 
index 175e8788ba76c629d8bae414e5da3abc32750fac..657ed265f9876ced2471ab7c659b431189804297 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.transportpce.tapi.topology;
 
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -62,11 +61,17 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.no
 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.LinkBuilder;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeBuilder;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class ConvertORTopoObjectToTapiTopoObject {
 
+    private static final String DSR_PLUS = "DSR+";
+    private static final String PLUS_DSR = "+DSR";
+    private static final String OT_SI = "+OTSi";
+    private static final String E_OT_SI = "eOTSi+";
+    private static final String I_OT_SI = "iOTSi+";
     private static final Logger LOG = LoggerFactory.getLogger(ConvertORTopoObjectToTapiTopoObject.class);
     private String ietfNodeId;
     private List<TerminationPoint> oorClientPortList;
@@ -98,31 +103,37 @@ public class ConvertORTopoObjectToTapiTopoObject {
         this.uuidMap = new HashMap<>();
     }
 
-
     public void convertNode() {
-        //node creation [DSR/ODU]
+        // node creation [DSR/ODU]
         LOG.info("creation of a DSR/ODU node");
         Uuid nodeUuid = new Uuid(UUID.randomUUID().toString());
-        this.uuidMap.put(this.ietfNodeId + "+DSR", nodeUuid);
-        List<Name> dsrNodeNames = Arrays.asList(new NameBuilder().setValueName("dsr/odu node name")
-            .setValue(this.ietfNodeId).build());
+        this.uuidMap.put(this.ietfNodeId + PLUS_DSR, nodeUuid);
+        List<Name> dsrNodeNames = Arrays.asList(
+            new NameBuilder()
+                .setValueName("dsr/odu node name")
+                .setValue(this.ietfNodeId)
+                .build());
+
         List<LayerProtocolName> dsrLayerProtocols = Arrays.asList(LayerProtocolName.DSR, LayerProtocolName.ODU);
         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology
             .Node dsrNode = createTapiNode(dsrNodeNames, dsrLayerProtocols);
         tapiNodes.add(dsrNode);
 
-        //node creation [otsi]
+        // node creation [otsi]
         LOG.info("creation of an OTSi node");
         nodeUuid = new Uuid(UUID.randomUUID().toString());
-        this.uuidMap.put(this.ietfNodeId + "+OTSi", nodeUuid);
-        List<Name> otsiNodeNames = Arrays.asList(new NameBuilder().setValueName("otsi node name")
-            .setValue(this.ietfNodeId).build());
+        this.uuidMap.put(this.ietfNodeId + OT_SI, nodeUuid);
+        List<Name> otsiNodeNames = Arrays.asList(
+            new NameBuilder()
+                .setValueName("otsi node name")
+                .setValue(this.ietfNodeId)
+                .build());
         List<LayerProtocolName> otsiLayerProtocols = Arrays.asList(LayerProtocolName.PHOTONICMEDIA);
         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology
             .Node otsiNode = createTapiNode(otsiNodeNames, otsiLayerProtocols);
         tapiNodes.add(otsiNode);
 
-        //transitional link cration between network nep of DSR/ODU node and iNep of otsi node
+        // transitional link cration between network nep of DSR/ODU node and iNep of otsi node
         LOG.info("creation of transitional links between DSR/ODU and OTSi nodes");
         createTapiTransitionalLinks();
     }
@@ -140,115 +151,144 @@ public class ConvertORTopoObjectToTapiTopoObject {
             .build();
         ruleList.add(rule);
         if (layerProtocols.contains(LayerProtocolName.DSR)) {
-            nodeUuid = this.uuidMap.get(this.ietfNodeId + "+DSR");
-            // client nep creation on DSR/ODU node
-            for (int i = 0; i < oorClientPortList.size(); i++) {
-                Uuid nepUuid = new Uuid(UUID.randomUUID().toString());
-                this.uuidMap.put("DSR+" + oorClientPortList.get(i).getTpId().getValue(), nepUuid);
-                List<Name> onedNames = Arrays.asList(new NameBuilder().setValueName(new StringBuilder("NodeEdgePoint_C")
-                    .append(i + 1).toString()).setValue(oorClientPortList.get(i).getTpId().getValue()).build());
-                OwnedNodeEdgePoint onep = createNep(oorClientPortList.get(i), onedNames, LayerProtocolName.ETH,
-                    LayerProtocolName.DSR, true, "DSR+");
-                onepl.add(onep);
-            }
-            // network nep creation on DSR/ODU node
-            for (int i = 0; i < oorNetworkPortList.size(); i++) {
-                Uuid nepUuid = new Uuid(UUID.randomUUID().toString());
-                this.uuidMap.put("DSR+" + oorNetworkPortList.get(i).getTpId().getValue(), nepUuid);
-                List<Name> onedNames = Arrays.asList(new NameBuilder().setValueName(new StringBuilder("NodeEdgePoint_N")
-                    .append(i + 1).toString()).setValue(oorNetworkPortList.get(i).getTpId().getValue()).build());
-                OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), onedNames, LayerProtocolName.ODU,
-                    LayerProtocolName.DSR, true, "DSR+");
-                onepl.add(onep);
-            }
-            // create NodeRuleGroup
-            for (NonBlockingList nbl : this.oorOduSwitchingPool.getNonBlockingList()) {
-                List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
-                    .NodeEdgePoint> nepList = new ArrayList<>();
-                for (TpId tp : nbl.getTpList()) {
-                    org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
-                        .NodeEdgePoint nep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology
-                        .rev181210.node.rule.group.NodeEdgePointBuilder()
-                        .setTopologyUuid(tapiTopoUuid)
-                        .setNodeUuid(this.uuidMap.get(this.ietfNodeId + "+DSR"))
-                        .setNodeEdgePointUuid(this.uuidMap.get("DSR+" + tp.getValue()))
-                        .build();
-                    nepList.add(nep);
-                }
-                NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
-                    .setUuid(new Uuid(UUID.randomUUID().toString()))
-                    .setRule(ruleList)
-                    .setNodeEdgePoint(nepList)
-                    .build();
-                nodeRuleGroupList.add(nodeRuleGroup);
-            }
+            nodeUuid = getNodeUuid4Dsr(onepl, nodeRuleGroupList, ruleList);
         } else if (layerProtocols.contains(LayerProtocolName.PHOTONICMEDIA)) {
-            nodeUuid = this.uuidMap.get(this.ietfNodeId + "+OTSi");
-            // iNep creation on otsi node
-            for (int i = 0; i < oorNetworkPortList.size(); i++) {
-                Uuid nepUuid1 = new Uuid(UUID.randomUUID().toString());
-                this.uuidMap.put("iOTSi+" + oorNetworkPortList.get(i).getTpId().getValue(), nepUuid1);
-                List<Name> onedNames = Arrays.asList(new NameBuilder().setValueName(new StringBuilder("iNodeEdgePoint_")
-                    .append(i + 1).toString()).setValue(oorNetworkPortList.get(i).getTpId().getValue()).build());
-                OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), onedNames,
-                    LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true, "iOTSi+");
-                onepl.add(onep);
-            }
-            // eNep creation on otsi node
-            for (int i = 0; i < oorNetworkPortList.size(); i++) {
-                Uuid nepUuid2 = new Uuid(UUID.randomUUID().toString());
-                this.uuidMap.put("eOTSi+" + oorNetworkPortList.get(i).getTpId().getValue(), nepUuid2);
-                List<Name> onedNames = Arrays.asList(new NameBuilder().setValueName(new StringBuilder("eNodeEdgePoint_")
-                    .append(i + 1).toString()).setValue(oorNetworkPortList.get(i).getTpId().getValue()).build());
-                OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), onedNames,
-                    LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true, "eOTSi+");
-                onepl.add(onep);
-            }
-            // create NodeRuleGroup
-            for (TerminationPoint tp : this.oorNetworkPortList) {
-                List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
-                    .NodeEdgePoint> nepList = new ArrayList<>();
-                org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
-                    .NodeEdgePoint inep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
-                    .node.rule.group.NodeEdgePointBuilder()
-                    .setTopologyUuid(tapiTopoUuid)
-                    .setNodeUuid(this.uuidMap.get(this.ietfNodeId + "+OTSi"))
-                    .setNodeEdgePointUuid(this.uuidMap.get("iOTSi+" + tp.getTpId().getValue()))
-                    .build();
+            nodeUuid = getNodeUuid4Phonic(onepl, nodeRuleGroupList, ruleList);
+        } else {
+            LOG.error("Undefined LayerProtocolName for {} node {}", nodeNames.get(0).getValueName(),
+                    nodeNames.get(0).getValue());
+        }
+
+        // create tapi node
+
+        return new NodeBuilder()
+                .setUuid(nodeUuid)
+                .setName(nodeNames)
+                .setLayerProtocolName(layerProtocols)
+                .setAdministrativeState(AdministrativeState.UNLOCKED)
+                .setOperationalState(OperationalState.ENABLED)
+                .setLifecycleState(LifecycleState.INSTALLED)
+                .setOwnedNodeEdgePoint(onepl)
+                .setNodeRuleGroup(nodeRuleGroupList)
+                .build();
+    }
+
+    private Uuid getNodeUuid4Phonic(List<OwnedNodeEdgePoint> onepl, List<NodeRuleGroup> nodeRuleGroupList,
+            List<Rule> ruleList) {
+        Uuid nodeUuid;
+        nodeUuid = this.uuidMap.get(this.ietfNodeId + OT_SI);
+        // iNep creation on otsi node
+        for (int i = 0; i < oorNetworkPortList.size(); i++) {
+            Uuid nepUuid1 = new Uuid(UUID.randomUUID().toString());
+            this.uuidMap.put(I_OT_SI + oorNetworkPortList.get(i).getTpId().getValue(), nepUuid1);
+            List<Name> onedNames = Arrays.asList(
+                    new NameBuilder()
+                    .setValueName(new StringBuilder("iNodeEdgePoint_").append(i + 1).toString())
+                    .setValue(oorNetworkPortList.get(i).getTpId().getValue())
+                    .build());
+
+            OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), onedNames,
+                LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true, I_OT_SI);
+            onepl.add(onep);
+        }
+        // eNep creation on otsi node
+        for (int i = 0; i < oorNetworkPortList.size(); i++) {
+            Uuid nepUuid2 = new Uuid(UUID.randomUUID().toString());
+            this.uuidMap.put(E_OT_SI + oorNetworkPortList.get(i).getTpId().getValue(), nepUuid2);
+            List<Name> onedNames = Arrays.asList(
+                    new NameBuilder()
+                    .setValueName(new StringBuilder("eNodeEdgePoint_").append(i + 1).toString())
+                    .setValue(oorNetworkPortList.get(i).getTpId().getValue())
+                    .build());
+
+            OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), onedNames,
+                LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true, E_OT_SI);
+            onepl.add(onep);
+        }
+        // create NodeRuleGroup
+        for (TerminationPoint tp : this.oorNetworkPortList) {
+            List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
+                .NodeEdgePoint> nepList = new ArrayList<>();
+            org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
+                .NodeEdgePoint inep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
+                .node.rule.group.NodeEdgePointBuilder()
+                .setTopologyUuid(tapiTopoUuid)
+                .setNodeUuid(this.uuidMap.get(this.ietfNodeId + OT_SI))
+                .setNodeEdgePointUuid(this.uuidMap.get(I_OT_SI + tp.getTpId().getValue()))
+                .build();
+            org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
+                .NodeEdgePoint enep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
+                .node.rule.group.NodeEdgePointBuilder()
+                .setTopologyUuid(tapiTopoUuid)
+                .setNodeUuid(this.uuidMap.get(this.ietfNodeId + OT_SI))
+                .setNodeEdgePointUuid(this.uuidMap.get(E_OT_SI + tp.getTpId().getValue()))
+                .build();
+            nepList.add(inep);
+            nepList.add(enep);
+            NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
+                .setUuid(new Uuid(UUID.randomUUID().toString()))
+                .setRule(ruleList)
+                .setNodeEdgePoint(nepList)
+                .build();
+            nodeRuleGroupList.add(nodeRuleGroup);
+        }
+        return nodeUuid;
+    }
+
+    private Uuid getNodeUuid4Dsr(List<OwnedNodeEdgePoint> onepl, List<NodeRuleGroup> nodeRuleGroupList,
+            List<Rule> ruleList) {
+        Uuid nodeUuid;
+        nodeUuid = this.uuidMap.get(this.ietfNodeId + PLUS_DSR);
+        // client nep creation on DSR/ODU node
+        for (int i = 0; i < oorClientPortList.size(); i++) {
+            Uuid nepUuid = new Uuid(UUID.randomUUID().toString());
+            this.uuidMap.put(DSR_PLUS + oorClientPortList.get(i).getTpId().getValue(), nepUuid);
+            List<Name> onedNames = Arrays.asList(
+                    new NameBuilder()
+                    .setValueName(new StringBuilder("NodeEdgePoint_C").append(i + 1).toString())
+                    .setValue(oorClientPortList.get(i).getTpId().getValue())
+                    .build());
+
+            OwnedNodeEdgePoint onep = createNep(oorClientPortList.get(i), onedNames, LayerProtocolName.ETH,
+                LayerProtocolName.DSR, true, DSR_PLUS);
+            onepl.add(onep);
+        }
+        // network nep creation on DSR/ODU node
+        for (int i = 0; i < oorNetworkPortList.size(); i++) {
+            Uuid nepUuid = new Uuid(UUID.randomUUID().toString());
+            this.uuidMap.put(DSR_PLUS + oorNetworkPortList.get(i).getTpId().getValue(), nepUuid);
+            List<Name> onedNames = Arrays.asList(
+                    new NameBuilder()
+                    .setValueName(new StringBuilder("NodeEdgePoint_N").append(i + 1).toString())
+                    .setValue(oorNetworkPortList.get(i).getTpId().getValue())
+                    .build());
+
+            OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), onedNames, LayerProtocolName.ODU,
+                LayerProtocolName.DSR, true, DSR_PLUS);
+            onepl.add(onep);
+        }
+        // create NodeRuleGroup
+        for (NonBlockingList nbl : this.oorOduSwitchingPool.getNonBlockingList()) {
+            List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
+                .NodeEdgePoint> nepList = new ArrayList<>();
+            for (TpId tp : nbl.getTpList()) {
                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
-                    .NodeEdgePoint enep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
+                    .NodeEdgePoint nep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
                     .node.rule.group.NodeEdgePointBuilder()
                     .setTopologyUuid(tapiTopoUuid)
-                    .setNodeUuid(this.uuidMap.get(this.ietfNodeId + "+OTSi"))
-                    .setNodeEdgePointUuid(this.uuidMap.get("eOTSi+" + tp.getTpId().getValue()))
+                    .setNodeUuid(this.uuidMap.get(this.ietfNodeId + PLUS_DSR))
+                    .setNodeEdgePointUuid(this.uuidMap.get(DSR_PLUS + tp.getValue()))
                     .build();
-                nepList.add(inep);
-                nepList.add(enep);
-                NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
-                    .setUuid(new Uuid(UUID.randomUUID().toString()))
-                    .setRule(ruleList)
-                    .setNodeEdgePoint(nepList)
-                    .build();
-                nodeRuleGroupList.add(nodeRuleGroup);
+                nepList.add(nep);
             }
-        } else {
-            LOG.error("Undefined LayerProtocolName for {} node {}", nodeNames.get(0).getValueName(), nodeNames.get(0)
-                .getValue());
+            NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
+                .setUuid(new Uuid(UUID.randomUUID().toString()))
+                .setRule(ruleList)
+                .setNodeEdgePoint(nepList)
+                .build();
+            nodeRuleGroupList.add(nodeRuleGroup);
         }
-
-        // create tapi node
-        org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node tapiNode =
-            new NodeBuilder()
-            .setUuid(nodeUuid)
-            .setName(nodeNames)
-            .setLayerProtocolName(layerProtocols)
-            .setAdministrativeState(AdministrativeState.UNLOCKED)
-            .setOperationalState(OperationalState.ENABLED)
-            .setLifecycleState(LifecycleState.INSTALLED)
-            .setOwnedNodeEdgePoint(onepl)
-            .setNodeRuleGroup(nodeRuleGroupList)
-            .build();
-        return tapiNode;
+        return nodeUuid;
     }
 
     private OwnedNodeEdgePoint createNep(TerminationPoint oorTp, List<Name> nepNames, LayerProtocolName nepProtocol,
@@ -287,7 +327,7 @@ public class ConvertORTopoObjectToTapiTopoObject {
             .getSupportedInterfaceCapability();
         for (SupportedInterfaceCapability sic : sicList) {
             switch (lpn.getName()) {
-                case "DSR" :
+                case "DSR":
                     if (sic.getIfCapType().getSimpleName().equals("If10GEODU2e")) {
                         sclpqList.add(DIGITALSIGNALTYPE10GigELAN.class);
                         sclpqList.add(ODUTYPEODU2E.class);
@@ -298,7 +338,7 @@ public class ConvertORTopoObjectToTapiTopoObject {
                         sclpqList.add(ODUTYPEODU4.class);
                     }
                     break;
-                case "PHOTONIC_MEDIA" :
+                case "PHOTONIC_MEDIA":
                     if (sic.getIfCapType().getSimpleName().equals("IfOCHOTU4ODU4")) {
                         sclpqList.add(PHOTONICLAYERQUALIFIEROTSi.class);
                         sclpqList.add(PHOTONICLAYERQUALIFIEROMS.class);
@@ -315,19 +355,19 @@ public class ConvertORTopoObjectToTapiTopoObject {
     private void createTapiTransitionalLinks() {
         for (TerminationPoint tp : this.oorNetworkPortList) {
             List<NodeEdgePoint> nepList = new ArrayList<>();
-            String sourceKey = "DSR+" + tp.getTpId().getValue();
+            String sourceKey = DSR_PLUS + tp.getTpId().getValue();
             Uuid sourceUuidTp = this.uuidMap.get(sourceKey);
-            String destKey = "iOTSi+" + tp.getTpId().getValue();
+            String destKey = I_OT_SI + tp.getTpId().getValue();
             Uuid destUuidTp = this.uuidMap.get(destKey);
             NodeEdgePoint sourceNep = new NodeEdgePointBuilder()
                 .setTopologyUuid(this.tapiTopoUuid)
-                .setNodeUuid(this.uuidMap.get(this.ietfNodeId + "+DSR"))
+                .setNodeUuid(this.uuidMap.get(this.ietfNodeId + PLUS_DSR))
                 .setNodeEdgePointUuid(sourceUuidTp)
                 .build();
             nepList.add(sourceNep);
             NodeEdgePoint destNep = new NodeEdgePointBuilder()
                 .setTopologyUuid(this.tapiTopoUuid)
-                .setNodeUuid(this.uuidMap.get(this.ietfNodeId + "+OTSi"))
+                .setNodeUuid(this.uuidMap.get(this.ietfNodeId + OT_SI))
                 .setNodeEdgePointUuid(destUuidTp)
                 .build();
             nepList.add(destNep);
@@ -338,7 +378,7 @@ public class ConvertORTopoObjectToTapiTopoObject {
                 .setNodeEdgePoint(nepList)
                 .setDirection(ForwardingDirection.BIDIRECTIONAL)
                 .setAvailableCapacity(new AvailableCapacityBuilder().setTotalSize(
-                    new TotalSizeBuilder().setUnit(CapacityUnit.GBPS).setValue(new BigInteger("100")).build()).build());
+                    new TotalSizeBuilder().setUnit(CapacityUnit.GBPS).setValue(Uint64.valueOf(100)).build()).build());
             this.tapiLinks.add(transiLinkBldr.build());
         }
     }
index 5fd5c4d43cb2f93ac7c191d47c102501c61b039b..59773c0831be610a18b038df4272370d15c80daf 100644 (file)
@@ -136,14 +136,12 @@ public class TapiTopologyImpl implements TapiTopologyService {
             LOG.error("Impossible to retrieve openroadm-topology from mdsal", e);
             return null;
         }
-        Network openroadmTopo = null;
-        if (optionalOpenroadmTop.isPresent()) {
-            openroadmTopo = optionalOpenroadmTop.get();
-        } else {
+
+        if (!optionalOpenroadmTop.isPresent()) {
             LOG.warn("Openroadm topology is not present, returning null");
             return null;
         }
-
+        Network openroadmTopo = optionalOpenroadmTop.get();
         List<Node> nodeList = openroadmTopo.getNode();
         List<Link> linkList = null;
         if (openroadmTopo.augmentation(Network1.class) != null) {
@@ -180,14 +178,13 @@ public class TapiTopologyImpl implements TapiTopologyService {
         }
         List<String> goodTpList = extractGoodTpList(clientPortMap);
         // tapi topology creation
-        List<Name> names = new ArrayList<Name>();
+        List<Name> names = new ArrayList<>();
         names.add(new NameBuilder().setValue("topo ethernet").setValueName("Topo Name").build());
         Uuid uuid = new Uuid(UUID.randomUUID().toString());
         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node>
             tapiNodeList = new ArrayList<>();
         tapiNodeList.add(createTapiNode(goodTpList));
-        Topology topology = new TopologyBuilder().setName(names).setUuid(uuid).setNode(tapiNodeList).build();
-        return topology;
+        return new TopologyBuilder().setName(names).setUuid(uuid).setNode(tapiNodeList).build();
 
     }
 
@@ -234,13 +231,12 @@ public class TapiTopologyImpl implements TapiTopologyService {
                 tapiNodeList.addAll(tapiFactory.getTapiNodes());
                 tapiLinkList.addAll(tapiFactory.getTapiLinks());
             }
-            Topology topology = new TopologyBuilder()
-                .setName(Arrays.asList(new NameBuilder().setValue("T0 - Multi-layer topology")
-                    .setValueName("TAPI Topology Name").build()))
-                .setUuid(topoUuid)
-                .setNode(tapiNodeList)
-                .setLink(tapiLinkList).build();
-            return topology;
+            return new TopologyBuilder()
+                    .setName(Arrays.asList(new NameBuilder().setValue("T0 - Multi-layer topology")
+                            .setValueName("TAPI Topology Name").build()))
+                    .setUuid(topoUuid)
+                    .setNode(tapiNodeList)
+                    .setLink(tapiLinkList).build();
         } else {
             return null;
         }
@@ -267,14 +263,14 @@ public class TapiTopologyImpl implements TapiTopologyService {
 
     private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node createTapiNode(List<
         String> tpList) {
-        List<Name> names = new ArrayList<Name>();
+        List<Name> names = new ArrayList<>();
         Name name = new NameBuilder().setValueName("node name").setValue("TapiNode1").build();
         names.add(name);
         List<LayerProtocolName> layerProtocols = new ArrayList<>();
         layerProtocols.add(LayerProtocolName.ETH);
-        List<OwnedNodeEdgePoint> onepl = new ArrayList<OwnedNodeEdgePoint>();
+        List<OwnedNodeEdgePoint> onepl = new ArrayList<>();
         for (int i = 0; i < tpList.size(); i++) {
-            List<Name> onedNames = new ArrayList<Name>();
+            List<Name> onedNames = new ArrayList<>();
             onedNames.add(new NameBuilder().setValueName("OwnedNodeEdgePoint " + i).setValue(tpList.get(i)).build());
             OwnedNodeEdgePoint onep = new OwnedNodeEdgePointBuilder().setUuid(new Uuid(UUID.randomUUID().toString()))
                 .setLayerProtocolName(LayerProtocolName.ETH).setMappedServiceInterfacePoint(createSIP(1))
@@ -285,11 +281,15 @@ public class TapiTopologyImpl implements TapiTopologyService {
                 .build();
             onepl.add(onep);
         }
-        org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node = new NodeBuilder()
-            .setUuid(new Uuid(UUID.randomUUID().toString())).setName(names).setLayerProtocolName(layerProtocols)
-            .setAdministrativeState(AdministrativeState.UNLOCKED).setOperationalState(OperationalState.ENABLED)
-            .setLifecycleState(LifecycleState.INSTALLED).setOwnedNodeEdgePoint(onepl).build();
-        return node;
+
+        return new NodeBuilder()
+                .setUuid(new Uuid(UUID.randomUUID().toString()))
+                .setName(names).setLayerProtocolName(layerProtocols)
+                .setAdministrativeState(AdministrativeState.UNLOCKED)
+                .setOperationalState(OperationalState.ENABLED)
+                .setLifecycleState(LifecycleState.INSTALLED)
+                .setOwnedNodeEdgePoint(onepl)
+                .build();
     }
 
     private List<MappedServiceInterfacePoint> createSIP(int nb) {
index 3abc859badfac5e1a4af607cccf3aeabdc1bb4be..6aca970f4b1acc62ecdfa8e4050fb62e01c3edf5 100644 (file)
@@ -23,7 +23,7 @@ public final class MappingUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(MappingUtils.class);
 
-    private static Map<Uuid, GenericServiceEndpoint> map = new HashMap<Uuid, GenericServiceEndpoint>();
+    private static Map<Uuid, GenericServiceEndpoint> map = new HashMap<>();
 
     private MappingUtils() {
     }
@@ -71,8 +71,7 @@ public final class MappingUtils {
             Set<Entry<Uuid, GenericServiceEndpoint>> entries = map.entrySet();
             LOG.info("Displaying the static map...");
             for (Entry<Uuid, GenericServiceEndpoint> entry : entries) {
-                LOG.info("uuid = {} \t service end point = {}", entry.getKey().toString(), entry.getValue().getValue()
-                    .toString());
+                LOG.info("uuid = {} \t service end point = {}", entry.getKey(), entry.getValue().getValue());
             }
         } else {
             LOG.info("Static map is empty - Nothing to display");
index 501b5c4a1b4e54332f1aea0a00210f01eaf10397..24afebda49d4efbe4a4bb0baeb488b4a78a830b7 100644 (file)
@@ -23,9 +23,15 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEndBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEnd;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEndBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 public final class TapiUtils {
 
+    private static final String LGX_PORT_NAME = "Some lgx-port-name";
+    private static final String PORT_TYPE = "some port type";
+    private static final String LGX_DEVICE_NAME = "Some lgx-device-name";
+    private static final String PORT_RACK_VALUE = "000000.00";
+
     private TapiUtils() {
     }
 
@@ -52,46 +58,82 @@ public final class TapiUtils {
 
     public static ServiceAEnd buildServiceAEnd(String nodeid, String clli, String txPortDeviceName,
         String txPortName, String rxPortDeviceName, String rxPortName) {
-        ServiceAEnd serviceAEnd = new ServiceAEndBuilder().setClli(clli).setNodeId(new NodeIdType(nodeid)).setOpticType(
-            OpticTypes.Gray).setServiceFormat(
-                ServiceFormat.Ethernet).setServiceRate(Long.valueOf(100))
-            .setTxDirection(
-                new TxDirectionBuilder()
-                    .setPort(new PortBuilder().setPortDeviceName(txPortDeviceName).setPortName(txPortName)
-                        .setPortRack("000000.00").setPortShelf("00").setPortType("some port type").build())
-                    .setLgx(new LgxBuilder().setLgxDeviceName("Some lgx-device-name").setLgxPortName(
-                        "Some lgx-port-name").setLgxPortRack("000000.00").setLgxPortShelf("00").build())
-                    .build())
-            .setRxDirection(
-                new RxDirectionBuilder()
-                    .setPort(new PortBuilder().setPortDeviceName(rxPortDeviceName).setPortName(rxPortName)
-                        .setPortRack("000000.00").setPortShelf("00").setPortType("some port type").build())
-                    .setLgx(new LgxBuilder().setLgxDeviceName("Some lgx-device-name").setLgxPortName(
-                        "Some lgx-port-name").setLgxPortRack("000000.00").setLgxPortShelf("00").build()).build())
-            .build();
-        return serviceAEnd;
+        return new ServiceAEndBuilder()
+                .setClli(clli)
+                .setNodeId(new NodeIdType(nodeid))
+                .setOpticType(OpticTypes.Gray)
+                .setServiceFormat(ServiceFormat.Ethernet)
+                .setServiceRate(Uint32.valueOf(100))
+                .setTxDirection(new TxDirectionBuilder()
+                        .setPort(new PortBuilder()
+                                .setPortDeviceName(txPortDeviceName)
+                                .setPortName(txPortName)
+                                .setPortRack(PORT_RACK_VALUE)
+                                .setPortShelf("00")
+                                .setPortType(PORT_TYPE)
+                                .build())
+                        .setLgx(new LgxBuilder()
+                                .setLgxDeviceName(LGX_DEVICE_NAME)
+                                .setLgxPortName(LGX_PORT_NAME)
+                                .setLgxPortRack(PORT_RACK_VALUE)
+                                .setLgxPortShelf("00")
+                                .build())
+                        .build())
+                .setRxDirection(new RxDirectionBuilder()
+                        .setPort(new PortBuilder()
+                                .setPortDeviceName(rxPortDeviceName)
+                                .setPortName(rxPortName)
+                        .setPortRack(PORT_RACK_VALUE)
+                        .setPortShelf("00")
+                        .setPortType(PORT_TYPE)
+                        .build())
+                        .setLgx(new LgxBuilder()
+                                .setLgxDeviceName(LGX_DEVICE_NAME)
+                                .setLgxPortName(LGX_PORT_NAME)
+                                .setLgxPortRack(PORT_RACK_VALUE)
+                                .setLgxPortShelf("00")
+                                .build())
+                        .build())
+                .build();
     }
 
     public static ServiceZEnd buildServiceZEnd(String nodeid, String clli, String txPortDeviceName,
         String txPortName, String rxPortDeviceName, String rxPortName) {
-        ServiceZEnd serviceZEnd = new ServiceZEndBuilder().setClli(clli).setNodeId(new NodeIdType(nodeid)).setOpticType(
-            OpticTypes.Gray).setServiceFormat(
-                ServiceFormat.Ethernet).setServiceRate(Long.valueOf(100))
-            .setTxDirection(
-                new TxDirectionBuilder()
-                    .setPort(new PortBuilder().setPortDeviceName(txPortDeviceName).setPortName(txPortName)
-                        .setPortRack("000000.00").setPortShelf("00").setPortType("some port type").build())
-                    .setLgx(new LgxBuilder().setLgxDeviceName("Some lgx-device-name").setLgxPortName(
-                        "Some lgx-port-name").setLgxPortRack("000000.00").setLgxPortShelf("00").build())
-                    .build())
-            .setRxDirection(
-                new RxDirectionBuilder()
-                    .setPort(new PortBuilder().setPortDeviceName(rxPortDeviceName).setPortName(rxPortName)
-                        .setPortRack("000000.00").setPortShelf("00").setPortType("some port type").build())
-                    .setLgx(new LgxBuilder().setLgxDeviceName("Some lgx-device-name").setLgxPortName(
-                        "Some lgx-port-name").setLgxPortRack("000000.00").setLgxPortShelf("00").build()).build())
-            .build();
-        return serviceZEnd;
+        return  new ServiceZEndBuilder().setClli(clli).setNodeId(new NodeIdType(nodeid))
+                .setOpticType(OpticTypes.Gray)
+                .setServiceFormat(ServiceFormat.Ethernet)
+                .setServiceRate(Uint32.valueOf(100))
+                .setTxDirection(new TxDirectionBuilder()
+                        .setPort(new PortBuilder()
+                                .setPortDeviceName(txPortDeviceName)
+                                .setPortName(txPortName)
+                                .setPortRack(PORT_RACK_VALUE)
+                                .setPortShelf("00")
+                                .setPortType(PORT_TYPE)
+                                .build())
+                        .setLgx(new LgxBuilder()
+                                .setLgxDeviceName(LGX_DEVICE_NAME)
+                                .setLgxPortName(LGX_PORT_NAME)
+                                .setLgxPortRack(PORT_RACK_VALUE)
+                                .setLgxPortShelf("00")
+                                .build())
+                        .build())
+                .setRxDirection(new RxDirectionBuilder()
+                        .setPort(new PortBuilder()
+                                .setPortDeviceName(rxPortDeviceName)
+                                .setPortName(rxPortName)
+                                .setPortRack(PORT_RACK_VALUE)
+                                .setPortShelf("00")
+                                .setPortType(PORT_TYPE)
+                                .build())
+                        .setLgx(new LgxBuilder()
+                                .setLgxDeviceName(LGX_DEVICE_NAME)
+                                .setLgxPortName(LGX_PORT_NAME)
+                                .setLgxPortRack(PORT_RACK_VALUE)
+                                .setLgxPortShelf("00")
+                                .build())
+                        .build())
+                .build();
     }
 
     private static ServiceAEnd getServiceAEnd(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
index e4e089867f48b1958ac8dfe2273f95563e29d2ca..490d27c10df2c2288786571367c45623d2b89c0f 100644 (file)
@@ -10,13 +10,9 @@ package org.opendaylight.transportpce.tapi.validation.checks;
 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.ServiceType;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.ConnectivityConstraint;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public final class ConnConstraintCheck {
 
-    private static final Logger LOG = LoggerFactory.getLogger(ConnConstraintCheck.class);
-
     private ConnConstraintCheck() {
     }
 
index a29b278de36b484e1286f9d10fbbf7f33c293726..105889d1bb905dc8b7d98d71bc4761ca2608e526 100644 (file)
@@ -34,7 +34,7 @@ public final class EndPointCheck {
         } else {
             for (EndPoint ep : epl) {
                 //to do
-                LOG.info("ep = {}", ep.toString());
+                LOG.info("ep = {}", ep);
             }
         }
 
index 4edf07d57921c0adaafb727381097565fa132bcc..8a07469702b91dc9f2f8531e02c8b314dd7bced2 100644 (file)
@@ -20,29 +20,86 @@ public final class TopoConstraintCheck {
     }
 
     public static boolean checkString(String value) {
-        return ((value != null) && (value.compareTo("") != 0));
+        return ((value != null) && (!value.isEmpty()));
     }
 
     public static ComplianceCheckResult check(TopologyConstraint tc) {
         boolean result = true;
         String message = "";
-        LOG.info("tc = {}", tc.toString());
-        if (tc.getAvoidTopology() == null || tc.getExcludeLink() == null || tc.getExcludeNode() == null || tc
-            .getExcludePath() == null || tc.getIncludeLink() == null || tc.getIncludeNode() == null || tc
-                .getIncludePath() == null || tc.getIncludeTopology() == null || tc
-                    .getPreferredTransportLayer() == null) {
+        LOG.info("tc = {}", tc);
+        if (checkNull(tc)) {
             LOG.info("tc is null");
-            result = true;
             message = "Topology constraints are not managet yet";
-        } else if (tc.getAvoidTopology().isEmpty() || tc.getExcludeLink().isEmpty() || tc.getExcludeNode().isEmpty()
-            || tc
-                .getExcludePath().isEmpty() || tc.getIncludeLink().isEmpty() || tc.getIncludeNode().isEmpty() || tc
-                    .getIncludePath().isEmpty() || tc.getIncludeTopology().isEmpty() || tc.getPreferredTransportLayer()
-                        .isEmpty()) {
+        } else if (checkEmpty(tc)) {
             result = false;
             message = "Topology constraints are not managet yet";
         }
 
         return new ComplianceCheckResult(result, message);
     }
+
+    private static boolean checkNull(TopologyConstraint tc) {
+        if (tc == null) {
+            return true;
+        }
+        if (tc.getAvoidTopology() == null) {
+            return true;
+        }
+        if (tc.getExcludeLink() == null) {
+            return true;
+        }
+        if (tc.getExcludeNode() == null) {
+            return true;
+        }
+        if (tc.getExcludePath() == null) {
+            return true;
+        }
+        if (tc.getIncludeLink() == null) {
+            return true;
+        }
+        if (tc.getIncludeNode() == null) {
+            return true;
+        }
+        if (tc.getIncludePath() == null) {
+            return true;
+        }
+        if (tc.getIncludeTopology() == null) {
+            return true;
+        }
+        return tc.getPreferredTransportLayer() == null;
+    }
+
+    //Due to number of check to do, cyclomatic complexity cannot be easily improved
+    @java.lang.SuppressWarnings("squid:MethodCyclomaticComplexity")
+    private static boolean checkEmpty(TopologyConstraint tc) {
+        if (tc == null) {
+            return true;
+        }
+        if (tc.getAvoidTopology() != null && tc.getAvoidTopology().isEmpty()) {
+            return true;
+        }
+        if (tc.getExcludeLink() != null && tc.getExcludeLink().isEmpty()) {
+            return true;
+        }
+        if (tc.getExcludeNode() != null && tc.getExcludeNode().isEmpty()) {
+            return true;
+        }
+        if (tc.getExcludePath() != null && tc.getExcludePath().isEmpty()) {
+            return true;
+        }
+        if (tc.getIncludeLink() != null && tc.getIncludeLink().isEmpty()) {
+            return true;
+        }
+        if (tc.getIncludeNode() != null && tc.getIncludeNode().isEmpty()) {
+            return true;
+        }
+        if (tc.getIncludePath() != null && tc.getIncludePath().isEmpty()) {
+            return true;
+        }
+        if (tc.getIncludeTopology() != null && tc.getIncludeTopology().isEmpty()) {
+            return true;
+        }
+        return tc.getPreferredTransportLayer() != null && tc.getPreferredTransportLayer().isEmpty();
+
+    }
 }