From 6b6a445c84c2eb1c85d4e48c2d10a89c3d598bc5 Mon Sep 17 00:00:00 2001 From: Gilles Thouenon Date: Thu, 28 Apr 2022 14:48:09 +0200 Subject: [PATCH] Fix few code issues - remove useless property from DeviceRendererServiceImpl - remove several catching of NPE JIRA: TRNSPRTPCE-662 Signed-off-by: Gilles Thouenon Change-Id: I05815d4df58098a15eabef38c0b51c8af90e57f7 --- .../tpce/module/TransportPCEImpl.java | 2 +- .../pce/gnpy/GnpyServiceImpl.java | 16 +--- .../transportpce/pce/gnpy/GnpyTopoImpl.java | 6 +- .../pce/graph/PostAlgoPathValidator.java | 8 +- .../DeviceRendererServiceImpl.java | 7 +- .../OSGI-INF/blueprint/renderer-blueprint.xml | 1 - ...ceRendererServiceImplCreateOtsOmsTest.java | 2 +- .../validation/ServiceCreateValidation.java | 95 +++++++++---------- .../CreateConnectivityServiceValidation.java | 73 +++++++------- 9 files changed, 92 insertions(+), 118 deletions(-) diff --git a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java index f4beb0be9..276940850 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java @@ -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, diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyServiceImpl.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyServiceImpl.java index 2e93a8e18..26c1b4c6b 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyServiceImpl.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyServiceImpl.java @@ -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 extractPathRequest( diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java index 744e8ee64..abdcb7038 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java @@ -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(); } /* diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java index ec7a97e8e..61e7f145a 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java @@ -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); } diff --git a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImpl.java b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImpl.java index aae347bc2..225488732 100644 --- a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImpl.java +++ b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImpl.java @@ -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; diff --git a/renderer/src/main/resources/OSGI-INF/blueprint/renderer-blueprint.xml b/renderer/src/main/resources/OSGI-INF/blueprint/renderer-blueprint.xml index 071e5114e..72333afe9 100644 --- a/renderer/src/main/resources/OSGI-INF/blueprint/renderer-blueprint.xml +++ b/renderer/src/main/resources/OSGI-INF/blueprint/renderer-blueprint.xml @@ -72,7 +72,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html - diff --git a/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplCreateOtsOmsTest.java b/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplCreateOtsOmsTest.java index 161da2f19..3fd1f28e8 100644 --- a/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplCreateOtsOmsTest.java +++ b/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/DeviceRendererServiceImplCreateOtsOmsTest.java @@ -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 diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/validation/ServiceCreateValidation.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/validation/ServiceCreateValidation.java index 9fa1a07ac..93f80eca1 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/validation/ServiceCreateValidation.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/validation/ServiceCreateValidation.java @@ -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."); } diff --git a/tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/CreateConnectivityServiceValidation.java b/tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/CreateConnectivityServiceValidation.java index e0e20d4da..c25c8a104 100644 --- a/tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/CreateConnectivityServiceValidation.java +++ b/tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/CreateConnectivityServiceValidation.java @@ -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 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 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."); } -- 2.36.6