Fix few code issues 65/100865/3
authorGilles Thouenon <gilles.thouenon@orange.com>
Thu, 28 Apr 2022 12:48:09 +0000 (14:48 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Mon, 2 May 2022 10:21:48 +0000 (12:21 +0200)
- remove useless property from DeviceRendererServiceImpl
- remove several catching of NPE

JIRA: TRNSPRTPCE-662
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: I05815d4df58098a15eabef38c0b51c8af90e57f7

lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyServiceImpl.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java
pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImpl.java
renderer/src/main/resources/OSGI-INF/blueprint/renderer-blueprint.xml
renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplCreateOtsOmsTest.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/validation/ServiceCreateValidation.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/CreateConnectivityServiceValidation.java

index f4beb0be900e1334e8f67d954c08021008bc9af2..276940850bddb42f12e478f5083ff4c8755df50d 100644 (file)
@@ -181,7 +181,7 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
                 portMapping);
         DeviceRendererService deviceRendererService = new DeviceRendererServiceImpl(
                 lightyServices.getBindingDataBroker(), deviceTransactionManager, openRoadmInterfaceFactory,
-                openRoadmInterfaces, crossConnect, portMapping, networkModelService);
+                openRoadmInterfaces, crossConnect, portMapping);
         OtnDeviceRendererService otnDeviceRendererService = new OtnDeviceRendererServiceImpl(openRoadmInterfaceFactory,
                 crossConnect, openRoadmInterfaces, deviceTransactionManager, networkModelService);
         rendererProvider = initRenderer(lightyServices, olmPowerServiceRpc, deviceRendererService,
index 2e93a8e1849c7f5ab209742c54b547f5af405743..26c1b4c6b50b01f7524518bd02adc0e4f0d710fa 100644 (file)
@@ -112,12 +112,8 @@ public class GnpyServiceImpl {
         this.mapDisgNodeRefNode = gnpyTopo.getMapDisgNodeRefNode();
         this.mapLinkFiber = gnpyTopo.getMapLinkFiber();
         this.trxList = gnpyTopo.getTrxList();
-        try {
-            this.pathRequest = extractPathRequest(input, atoz, requestId.toJava(), pceHardConstraints);
-            this.synchronization = extractSynchronization(requestId);
-        } catch (NullPointerException e) {
-            throw new GnpyException("In GnpyServiceImpl: one of the elements is null",e);
-        }
+        this.pathRequest = extractPathRequest(input, atoz, requestId.toJava(), pceHardConstraints);
+        this.synchronization = extractSynchronization(requestId);
     }
 
     public GnpyServiceImpl(PathComputationRequestInput input, ZToADirection ztoa, Uint32 requestId,
@@ -126,12 +122,8 @@ public class GnpyServiceImpl {
         this.mapDisgNodeRefNode = gnpyTopo.getMapDisgNodeRefNode();
         this.mapLinkFiber = gnpyTopo.getMapLinkFiber();
         this.trxList = gnpyTopo.getTrxList();
-        try {
-            pathRequest = extractPathRequest(input, ztoa, requestId.toJava(), pceHardConstraints);
-            synchronization = extractSynchronization(requestId);
-        } catch (NullPointerException e) {
-            throw new GnpyException("In GnpyServiceImpl: one of the elements of service is null",e);
-        }
+        pathRequest = extractPathRequest(input, ztoa, requestId.toJava(), pceHardConstraints);
+        synchronization = extractSynchronization(requestId);
     }
 
     private Map<PathRequestKey, PathRequest> extractPathRequest(
index 744e8ee6424999a49c47933b1e4fc8ed1b27a5c9..abdcb703801eff7f0d6571f09edd7c4cf663dddd 100644 (file)
@@ -97,11 +97,7 @@ public class GnpyTopoImpl {
      */
     public GnpyTopoImpl(final NetworkTransactionService networkTransactionService) throws GnpyException {
         this.networkTransactionService = networkTransactionService;
-        try {
-            extractTopo();
-        } catch (NullPointerException e) {
-            throw new GnpyException("In GnpyTopoImpl: one of the elements is null",e);
-        }
+        extractTopo();
     }
 
     /*
index ec7a97e8e4ef4089597a2aa3d4c801dbb5df1473..61e7f145aa52e840d302b93e5cd0cae3b06e977a 100644 (file)
@@ -163,13 +163,13 @@ public class PostAlgoPathValidator {
         double latency = 0;
 
         for (PceGraphEdge edge : path.getEdgeList()) {
-            try {
-                latency += edge.link().getLatency();
-                LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
-            } catch (NullPointerException e) {
+            if (edge.link() == null || edge.link().getLatency() == null) {
                 LOG.warn("- In checkLatency: the link {} does not contain latency field",
                     edge.link().getLinkId().getValue());
+                return false;
             }
+            latency += edge.link().getLatency();
+            LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
         }
         return (latency < maxLatency);
     }
index aae347bc25350459005b822edbc461674ed8d11e..22548873271e42420fe60604781e0d5677c313ad 100644 (file)
@@ -43,7 +43,6 @@ import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
-import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServiceListTopology;
 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
@@ -92,18 +91,16 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
     private final OpenRoadmInterfaces openRoadmInterfaces;
     private final CrossConnect crossConnect;
     private final PortMapping portMapping;
-    private final NetworkModelService networkModelService;
 
     public DeviceRendererServiceImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
             OpenRoadmInterfaceFactory openRoadmInterfaceFactory, OpenRoadmInterfaces openRoadmInterfaces,
-            CrossConnect crossConnect, PortMapping portMapping, NetworkModelService networkModelService) {
+            CrossConnect crossConnect, PortMapping portMapping) {
         this.dataBroker = dataBroker;
         this.deviceTransactionManager = deviceTransactionManager;
         this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
         this.openRoadmInterfaces = openRoadmInterfaces;
         this.crossConnect = crossConnect;
         this.portMapping = portMapping;
-        this.networkModelService = networkModelService;
     }
 
     @SuppressWarnings("rawtypes")
@@ -131,8 +128,6 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
         ForkJoinPool forkJoinPool = new ForkJoinPool();
         ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
             String nodeId = node.getNodeId();
-            // take the index of the node
-            int nodeIndex = nodes.indexOf(node);
             LOG.info("Starting provisioning for node : {}", nodeId);
             AEndApiInfo apiInfoA = null;
             ZEndApiInfo apiInfoZ = null;
index 071e5114e8eb0765bf42c94664008602eb6b4d19..72333afe9639fed9512656e883ce89ad2fc67721 100644 (file)
@@ -72,7 +72,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <argument ref="openRoadmInterfaces" />
     <argument ref="crossConnect" />
     <argument ref="portMapping" />
-    <argument ref="networkModelService" />
   </bean>
 
   <bean id="otnDeviceRenderer" class="org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererServiceImpl" >
index 161da2f19f59e3571b1819a1e531f5731b1c28c5..3fd1f28e8cfcadb0d310eaed4f3a577e2ca02b4c 100644 (file)
@@ -100,7 +100,7 @@ public class DeviceRendererServiceImplCreateOtsOmsTest extends AbstractTest {
         this.crossConnect = Mockito.spy(this.crossConnect);
         this.deviceRendererService = new DeviceRendererServiceImpl(getDataBroker(),
             this.deviceTransactionManager, this.openRoadmInterfaceFactory, this.openRoadmInterfaces,
-            this.crossConnect, portMapping, null);
+            this.crossConnect, portMapping);
     }
 
     @Test
index 9fa1a07acf4ec53b93d1961bda495f5e0a1272e9..93f80eca1ae333ba1a440e6aacb2a4d01e36de39 100644 (file)
@@ -31,61 +31,56 @@ public final class ServiceCreateValidation {
          * -request header compliancy are verified.
          */
         LOG.debug("checking Service Compliance ...");
-        try {
-            String serviceNmame = input.getServiceName();
-            SdncRequestHeader sdncRequestHeader = input.getSdncRequestHeader();
-            ConnectionType conType = input.getConnectionType();
-            ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.check(
-                    serviceNmame, sdncRequestHeader, conType, rpcActions, true, true);
-            if (serviceHandlerCheckResult.hasPassed()) {
-                LOG.debug("Service request compliant !");
-            } else {
-                return OperationResult.failed(serviceHandlerCheckResult.getMessage());
-            }
+        String serviceNmame = input.getServiceName();
+        SdncRequestHeader sdncRequestHeader = input.getSdncRequestHeader();
+        ConnectionType conType = input.getConnectionType();
+        ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.check(
+                serviceNmame, sdncRequestHeader, conType, rpcActions, true, true);
+        if (serviceHandlerCheckResult.hasPassed()) {
+            LOG.debug("Service request compliant !");
+        } else {
+            return OperationResult.failed(serviceHandlerCheckResult.getMessage());
+        }
+        /*
+         * If compliant, service-request parameters are verified in order to
+         * check if there is no missing parameter that prevents calculating
+         * a path and implement a service.
+         */
+        LOG.debug("checking Tx/Rx Info for AEnd ...");
+        ComplianceCheckResult txrxCheckAEnd = ServicehandlerTxRxCheck.check(input.getServiceAEnd(),
+                ServiceEndpointType.SERVICEAEND);
+        if (txrxCheckAEnd.hasPassed()) {
+            LOG.debug("Tx/Rx Info for AEnd checked !");
+        } else {
+            return OperationResult.failed(txrxCheckAEnd.getMessage());
+        }
+
+        LOG.debug("checking Tx/Rx Info for ZEnd ...");
+        ComplianceCheckResult txrxCheckZEnd = ServicehandlerTxRxCheck.check(input.getServiceZEnd(),
+                ServiceEndpointType.SERVICEZEND);
+        if (txrxCheckZEnd.hasPassed()) {
+            LOG.debug("Tx/Rx Info for ZEnd checked");
             /*
-             * If compliant, service-request parameters are verified in order to
-             * check if there is no missing parameter that prevents calculating
-             * a path and implement a service.
+             * If OK, common-id is verified in order to see if there is
+             * no routing policy provided. If yes, the routing
+             * constraints of the policy are recovered and coherency
+             * with hard/soft constraints provided in the input of the
+             * RPC.
              */
-            LOG.debug("checking Tx/Rx Info for AEnd ...");
-            ComplianceCheckResult txrxCheckAEnd = ServicehandlerTxRxCheck.check(input.getServiceAEnd(),
-                    ServiceEndpointType.SERVICEAEND);
-            if (txrxCheckAEnd.hasPassed()) {
-                LOG.debug("Tx/Rx Info for AEnd checked !");
-            } else {
-                return OperationResult.failed(txrxCheckAEnd.getMessage());
-            }
-
-            LOG.debug("checking Tx/Rx Info for ZEnd ...");
-            ComplianceCheckResult txrxCheckZEnd = ServicehandlerTxRxCheck.check(input.getServiceZEnd(),
-                    ServiceEndpointType.SERVICEZEND);
-            if (txrxCheckZEnd.hasPassed()) {
-                LOG.debug("Tx/Rx Info for ZEnd checked");
-                /*
-                 * If OK, common-id is verified in order to see if there is
-                 * no routing policy provided. If yes, the routing
-                 * constraints of the policy are recovered and coherency
-                 * with hard/soft constraints provided in the input of the
-                 * RPC.
-                 */
-            } else {
-                return OperationResult.failed(txrxCheckZEnd.getMessage());
-            }
+        } else {
+            return OperationResult.failed(txrxCheckZEnd.getMessage());
+        }
 
-            if (input.getCommonId() != null) {
-                LOG.debug("Common-id specified");
-                // Check coherency with hard/soft constraints
-                if (CheckCoherencyHardSoft.check(input.getHardConstraints(), input.getSoftConstraints())) {
-                    LOG.debug("hard/soft constraints coherent !");
-                } else {
-                    return OperationResult.failed("hard/soft constraints are not coherent !");
-                }
+        if (input.getCommonId() != null) {
+            LOG.debug("Common-id specified");
+            // Check coherency with hard/soft constraints
+            if (CheckCoherencyHardSoft.check(input.getHardConstraints(), input.getSoftConstraints())) {
+                LOG.debug("hard/soft constraints coherent !");
             } else {
-                LOG.warn("Common-id not specified !");
+                return OperationResult.failed("hard/soft constraints are not coherent !");
             }
-        } catch (NullPointerException e) {
-            LOG.error("one of input parameter is null ",e);
-            return OperationResult.failed("one of input parameter is null.");
+        } else {
+            LOG.warn("Common-id not specified !");
         }
         return OperationResult.ok("Validation successful.");
     }
index e0e20d4da564e0d68653ab1346e34ef01fcd44b0..c25c8a10477eb286eb7665508b5518b964e3ace5 100644 (file)
@@ -33,47 +33,44 @@ public final class CreateConnectivityServiceValidation {
     public static OperationResult validateCreateConnectivityServiceRequest(CreateConnectivityServiceInput input) {
 
         LOG.info("checking rpc create-connectivity-service input parameters...");
-        try {
-            LOG.info("checking EndPoints...");
-            List<EndPoint> endPointList = new ArrayList<>(input.getEndPoint().values());
-            ComplianceCheckResult endPointCheckResult = EndPointCheck.check(endPointList);
-            if (endPointCheckResult.hasPassed()) {
-                LOG.info("create-connectivity-service end-points compliant !");
-            } else {
-                return OperationResult.failed(endPointCheckResult.getMessage());
-            }
-
-            LOG.info("checking ConnConstraint...");
-            ConnectivityConstraint connectivityConstraint = input.getConnectivityConstraint();
-            ComplianceCheckResult conConstraintCheckResult = ConnConstraintCheck.check(connectivityConstraint);
-            if (conConstraintCheckResult.hasPassed()) {
-                LOG.info("create-connectivity-service connectivity constraints compliant !");
-            } else {
-                return OperationResult.failed(conConstraintCheckResult.getMessage());
-            }
+        LOG.info("checking EndPoints...");
+        if (input.getEndPoint() == null) {
+            return OperationResult.failed("Service End-Point must not be null");
+        }
+        List<EndPoint> endPointList = new ArrayList<>(input.getEndPoint().values());
+        ComplianceCheckResult endPointCheckResult = EndPointCheck.check(endPointList);
+        if (endPointCheckResult.hasPassed()) {
+            LOG.info("create-connectivity-service end-points compliant !");
+        } else {
+            return OperationResult.failed(endPointCheckResult.getMessage());
+        }
 
-            LOG.info("checking ResilienceConstraint...");
-            ResilienceConstraint resilienceConstraintList = input.getResilienceConstraint();
-            ComplianceCheckResult resilienceConstraintCheckResult = ResilienceConstraintCheck.check(
-                resilienceConstraintList);
-            if (resilienceConstraintCheckResult.hasPassed()) {
-                LOG.info("create-connectivity-service resilience constraints compliant !");
-            } else {
-                return OperationResult.failed(resilienceConstraintCheckResult.getMessage());
-            }
+        LOG.info("checking ConnConstraint...");
+        ConnectivityConstraint connectivityConstraint = input.getConnectivityConstraint();
+        ComplianceCheckResult conConstraintCheckResult = ConnConstraintCheck.check(connectivityConstraint);
+        if (conConstraintCheckResult.hasPassed()) {
+            LOG.info("create-connectivity-service connectivity constraints compliant !");
+        } else {
+            return OperationResult.failed(conConstraintCheckResult.getMessage());
+        }
 
-            LOG.info("checking TopoConstraint...");
-            TopologyConstraint topoConstraint = input.getTopologyConstraint();
-            ComplianceCheckResult topoConstraintCheckResult = TopoConstraintCheck.check(topoConstraint);
-            if (topoConstraintCheckResult.hasPassed()) {
-                LOG.info("create-connectivity-service topo constraints compliant !");
-            } else {
-                return OperationResult.failed(topoConstraintCheckResult.getMessage());
-            }
+        LOG.info("checking ResilienceConstraint...");
+        ResilienceConstraint resilienceConstraintList = input.getResilienceConstraint();
+        ComplianceCheckResult resilienceConstraintCheckResult = ResilienceConstraintCheck.check(
+            resilienceConstraintList);
+        if (resilienceConstraintCheckResult.hasPassed()) {
+            LOG.info("create-connectivity-service resilience constraints compliant !");
+        } else {
+            return OperationResult.failed(resilienceConstraintCheckResult.getMessage());
+        }
 
-        } catch (NullPointerException e) {
-            LOG.error("one of input parameter is null ", e);
-            return OperationResult.failed("one of input parameter is null.");
+        LOG.info("checking TopoConstraint...");
+        TopologyConstraint topoConstraint = input.getTopologyConstraint();
+        ComplianceCheckResult topoConstraintCheckResult = TopoConstraintCheck.check(topoConstraint);
+        if (topoConstraintCheckResult.hasPassed()) {
+            LOG.info("create-connectivity-service topo constraints compliant !");
+        } else {
+            return OperationResult.failed(topoConstraintCheckResult.getMessage());
         }
         return OperationResult.ok("Validation successful.");
     }