Technical debt - Service handler Sonar issues 59/92959/1
authormanuedelf <emmanuelle.delfour@orange.com>
Fri, 9 Oct 2020 13:30:06 +0000 (15:30 +0200)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Wed, 14 Oct 2020 08:00:23 +0000 (08:00 +0000)
JIRA: TRNSPRTPCE-214
Change-Id: Ibdae3184f6f261e371db8d12e4719b105ca61705
Signed-off-by: manuedelf <emmanuelle.delfour@orange.com>
(cherry picked from commit a07392226a2e30930323959a5f6925812f5192ae)

servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/MappingConstraints.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapper.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImpl.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerTxRxCheck.java

index ed9c0210f08c972c6b4261d11101ce97f58183bf..4dc53d7ec0c347eca5b0237fbb9f029af8aaa165 100644 (file)
@@ -87,92 +87,10 @@ public class MappingConstraints {
      * @return ConstraintsSp HardConstraintsSp or HardConstraintsSp
      */
     private <T> ConstraintsSp getConstraints(T input) {
-        CoRoutingOrGeneral coRoutingOrGeneral = null;
         HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
         SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
         if ((input  !=  null) && (input instanceof Constraints)) {
-            Constraints constraints = (Constraints)input;
-            coRoutingOrGeneral = constraints.getCoRoutingOrGeneral();
-            General tmpGeneral = null;
-            CoRouting tmpCoRouting = null;
-            if (coRoutingOrGeneral  !=  null) {
-                org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
-                    new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder();
-                org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
-                    new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder();
-                if (coRoutingOrGeneral instanceof General) {
-                    tmpGeneral = (General) coRoutingOrGeneral;
-                    if (tmpGeneral  !=  null) {
-                        Diversity tmpDiversity =  tmpGeneral.getDiversity();
-                        if (tmpDiversity  !=  null) {
-                            finalGeneral.setDiversity(
-                                    new DiversityBuilder()
-                                    .setExistingService(tmpDiversity.getExistingService())
-                                    .setExistingServiceApplicability(
-                                            new ExistingServiceApplicabilityBuilder()
-                                            .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
-                                            .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
-                                            .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
-                                            .build())
-                                    .build());
-                        }
-                        Exclude tmpExclude = tmpGeneral.getExclude();
-                        if (tmpExclude  !=  null) {
-                            List<String> nodeIdList = new ArrayList<>();
-                            for (NodeIdType nodeId : tmpExclude.getNodeId()) {
-                                nodeIdList.add(nodeId.getValue());
-                            }
-                            finalGeneral.setExclude(
-                                    new ExcludeBuilder()
-                                    .setSupportingServiceName(tmpExclude.getSupportingServiceName())
-                                    .setClli(tmpExclude.getSite())
-                                    .setNodeId(nodeIdList)
-                                    //.setAffinity(value)
-                                    //.setSRLG(value)
-                                    .build());
-                        }
-                        Include tmpInclude = tmpGeneral.getInclude();
-                        if (tmpInclude  !=  null) {
-                            finalGeneral.setInclude(
-                                    new IncludeBuilder()
-                                    //.setOrderedHops()
-                                    .build());
-                        }
-                        Latency tmpLatency = tmpGeneral.getLatency();
-                        if (tmpLatency != null) {
-                            finalGeneral.setLatency(
-                                    new LatencyBuilder()
-                                    .setMaxLatency(tmpLatency.getMaxLatency())
-                                    .build());
-                        }
-                    }
-                    tempHard.setCoRoutingOrGeneral(finalGeneral.build())
-                        .setCustomerCode(constraints.getCustomerCode());
-                    tempSoft.setCoRoutingOrGeneral(finalGeneral.build())
-                        .setCustomerCode(constraints.getCustomerCode());
-                } else if (coRoutingOrGeneral instanceof CoRouting) {
-                    tmpCoRouting = (CoRouting)coRoutingOrGeneral;
-                    if (tmpCoRouting  !=  null) {
-                        org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329
-                            .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
-                            tmpCoRouting.getCoRouting();
-                        if (tmpCoRoutingCoRouting  !=  null) {
-                            finalCoRouting.setCoRouting(
-                                    new CoRoutingBuilder()
-                                    .setExistingService(tmpCoRoutingCoRouting.getExistingService())
-                                    .build());
-                        }
-                    }
-                    tempHard.setCoRoutingOrGeneral(finalCoRouting.build())
-                        .setCustomerCode(constraints.getCustomerCode());
-                    tempSoft.setCoRoutingOrGeneral(finalCoRouting.build())
-                        .setCustomerCode(constraints.getCustomerCode());
-                }
-            }
+            updateConstraintBuilders(input, tempHard, tempSoft);
         }
         if (input instanceof HardConstraints) {
             return tempHard.build();
@@ -183,6 +101,117 @@ public class MappingConstraints {
         }
     }
 
+    /**
+     * Update hardConstraintsBuilder and softConstraintsBuilder regarding input.
+     * @param <T> T
+     * @param input T
+     * @param hardConstraintsBuilder HardConstraintsBuilder
+     * @param softConstraintsBuilder SoftConstraintsBuilder
+     */
+    private <T> void updateConstraintBuilders(T input,
+            HardConstraintsBuilder hardConstraintsBuilder,
+            SoftConstraintsBuilder softConstraintsBuilder) {
+        Constraints constraints = (Constraints)input;
+        CoRoutingOrGeneral coRoutingOrGeneral = constraints.getCoRoutingOrGeneral();
+        if (coRoutingOrGeneral  !=  null) {
+            if (coRoutingOrGeneral instanceof General) {
+                updateConstraintBuilders4General(hardConstraintsBuilder, softConstraintsBuilder, constraints);
+            } else if (coRoutingOrGeneral instanceof CoRouting) {
+                updateConstraintBuilders4Corouting(hardConstraintsBuilder, softConstraintsBuilder, constraints);
+            }
+        }
+    }
+
+    /**
+     * Update hardConstraintsBuilder and softConstraintsBuilder for corouting constraints.
+     * @param hardConstraintsBuilder HardConstraintsBuilder
+     * @param softConstraintsBuilder SoftConstraintsBuilder
+     * @param constraints Constraints
+     */
+    private void updateConstraintBuilders4Corouting(HardConstraintsBuilder hardConstraintsBuilder,
+            SoftConstraintsBuilder softConstraintsBuilder, Constraints constraints) {
+        org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017
+            .constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
+            new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017
+                .constraints.sp.co.routing.or.general.CoRoutingBuilder();
+        CoRouting tmpCoRouting = (CoRouting)constraints.getCoRoutingOrGeneral();
+        if (tmpCoRouting  !=  null) {
+            org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329
+                .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
+                tmpCoRouting.getCoRouting();
+            if (tmpCoRoutingCoRouting  !=  null) {
+                finalCoRouting.setCoRouting(
+                        new CoRoutingBuilder()
+                        .setExistingService(tmpCoRoutingCoRouting.getExistingService())
+                        .build());
+            }
+        }
+        hardConstraintsBuilder.setCoRoutingOrGeneral(finalCoRouting.build())
+            .setCustomerCode(constraints.getCustomerCode());
+        softConstraintsBuilder.setCoRoutingOrGeneral(finalCoRouting.build())
+            .setCustomerCode(constraints.getCustomerCode());
+    }
+
+    /**
+     * Update hardConstraintsBuilder and softConstraintsBuilder for general constraints.
+     * @param hardConstraintsBuilder HardConstraintsBuilder
+     * @param softConstraintsBuilder SoftConstraintsBuilder
+     * @param constraints Constraints
+     */
+    private void updateConstraintBuilders4General(HardConstraintsBuilder hardConstraintsBuilder,
+            SoftConstraintsBuilder softConstraintsBuilder, Constraints constraints) {
+        org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017
+            .constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
+            new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017
+                .constraints.sp.co.routing.or.general.GeneralBuilder();
+        General tmpGeneral = (General) constraints.getCoRoutingOrGeneral();
+        if (tmpGeneral  !=  null) {
+            Diversity tmpDiversity =  tmpGeneral.getDiversity();
+            if (tmpDiversity  !=  null) {
+                finalGeneral.setDiversity(
+                        new DiversityBuilder()
+                        .setExistingService(tmpDiversity.getExistingService())
+                        .setExistingServiceApplicability(
+                                new ExistingServiceApplicabilityBuilder()
+                                .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
+                                .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
+                                .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
+                                .build())
+                        .build());
+            }
+            Exclude tmpExclude = tmpGeneral.getExclude();
+            if (tmpExclude  !=  null) {
+                List<String> nodeIdList = new ArrayList<>();
+                for (NodeIdType nodeId : tmpExclude.getNodeId()) {
+                    nodeIdList.add(nodeId.getValue());
+                }
+                finalGeneral.setExclude(
+                        new ExcludeBuilder()
+                        .setSupportingServiceName(tmpExclude.getSupportingServiceName())
+                        .setClli(tmpExclude.getSite())
+                        .setNodeId(nodeIdList)
+                        .build());
+            }
+            Include tmpInclude = tmpGeneral.getInclude();
+            if (tmpInclude  !=  null) {
+                finalGeneral.setInclude(
+                        new IncludeBuilder()
+                        .build());
+            }
+            Latency tmpLatency = tmpGeneral.getLatency();
+            if (tmpLatency != null) {
+                finalGeneral.setLatency(
+                        new LatencyBuilder()
+                        .setMaxLatency(tmpLatency.getMaxLatency())
+                        .build());
+            }
+        }
+        hardConstraintsBuilder.setCoRoutingOrGeneral(finalGeneral.build())
+            .setCustomerCode(constraints.getCustomerCode());
+        softConstraintsBuilder.setCoRoutingOrGeneral(finalGeneral.build())
+            .setCustomerCode(constraints.getCustomerCode());
+    }
+
     /**
      * map hard/soft constraints from Service 1.2
      * to ServicePath 1.4.
index 541fe8cc7885e03b5ff1436748619ad66c6617fe..124eed52a6e3033a038617390bc76727176c7810 100644 (file)
@@ -63,15 +63,9 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public final class ModelMappingUtils {
 
-    private static final Logger LOG =
-        LoggerFactory.getLogger(org.opendaylight.transportpce.servicehandler.ModelMappingUtils.class);
-    private static final String TERMINATION_POINT = "TerminationPoint";
-
     private ModelMappingUtils() {
     }
 
@@ -93,7 +87,8 @@ public final class ModelMappingUtils {
             .setOtuServiceRate(input.getServiceAEnd().getOtuServiceRate())
             .setOduServiceRate(input.getServiceAEnd().getOduServiceRate())
             .setClli(input.getServiceAEnd().getClli())
-            .setOtuServiceRate(input.getServiceAEnd().getOtuServiceRate()) // set otu and odu
+            // set otu and odu
+            .setOtuServiceRate(input.getServiceAEnd().getOtuServiceRate())
             .setOduServiceRate(input.getServiceZEnd().getOduServiceRate())
             .setClli(input.getServiceAEnd().getClli())
             .setNodeId(new NodeIdType(input.getServiceAEnd().getNodeId().getValue()).getValue())
@@ -111,7 +106,8 @@ public final class ModelMappingUtils {
             .setOtuServiceRate(input.getServiceZEnd().getOtuServiceRate())
             .setOduServiceRate(input.getServiceZEnd().getOduServiceRate())
             .setClli(input.getServiceZEnd().getClli())
-            .setOtuServiceRate(input.getServiceAEnd().getOtuServiceRate()) // set otu and odu
+            // set otu and odu
+            .setOtuServiceRate(input.getServiceAEnd().getOtuServiceRate())
             .setOduServiceRate(input.getServiceZEnd().getOduServiceRate())
             .setClli(input.getServiceZEnd().getClli())
             .setNodeId(new NodeIdType(input.getServiceZEnd().getNodeId().getValue()).getValue())
index 834c8a62fc00d422f0355a6d4cc45d1897c52ffe..fa3beb8a7a5b7d040402b8eddfa2185e9760e8ee 100644 (file)
@@ -91,8 +91,14 @@ import org.slf4j.LoggerFactory;
  * Top level service interface providing main OpenROADM controller services.
  */
 public class ServicehandlerImpl implements OrgOpenroadmServiceService {
-
     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerImpl.class);
+    private static final String TEMP_SERVICE_CREATE_MSG = "tempServiceCreate: {}";
+    private static final String TEMP_SERVICE_DELETE_MSG = "tempServiceDelete: {}";
+    private static final String SERVICE_RESTORATION_MSG = "serviceRestoration: {}";
+    private static final String SERVICE_RECONFIGURE_MSG = "serviceReconfigure: {}";
+    private static final String SERVICE_FEASABILITY_CHECK_MSG = "serviceFeasabilityCheck: {}";
+    private static final String SERVICE_DELETE_MSG = "serviceDelete: {}";
+    private static final String SERVICE_CREATE_MSG = "serviceCreate: {}";
 
     private DataBroker db;
     private ServiceDataStoreOperations serviceDataStoreOperations;
@@ -158,7 +164,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
                 new ServiceInput(input), RpcActions.ServiceCreate);
         if (! validationResult.isSuccess()) {
-            LOG.warn("serviceCreate: {}", LogMessages.ABORT_VALID_FAILED);
+            LOG.warn(SERVICE_CREATE_MSG, LogMessages.ABORT_VALID_FAILED);
             return ModelMappingUtils.createCreateServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
@@ -168,10 +174,10 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
-        LOG.debug("serviceCreate: {}", LogMessages.PCE_CALLING);
+        LOG.debug(SERVICE_CREATE_MSG, LogMessages.PCE_CALLING);
         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
         if (output == null) {
-            LOG.warn("serviceCreate: {}", LogMessages.ABORT_PCE_FAILED);
+            LOG.warn(SERVICE_CREATE_MSG, LogMessages.ABORT_PCE_FAILED);
             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
         }
@@ -196,25 +202,17 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
                 input.getServiceDeleteReqInfo().getServiceName(),
                 input.getSdncRequestHeader(), null, RpcActions.ServiceDelete, false, true);
         if (!serviceHandlerCheckResult.hasPassed()) {
-            LOG.warn("serviceDelete: {}", LogMessages.ABORT_SERVICE_NON_COMPLIANT);
+            LOG.warn(SERVICE_DELETE_MSG, LogMessages.ABORT_SERVICE_NON_COMPLIANT);
             return ModelMappingUtils.createDeleteServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     LogMessages.SERVICE_NON_COMPLIANT, ResponseCodes.RESPONSE_FAILED);
         }
 
         //Check presence of service to be deleted
-//TODO check if an expected bug was justifying this NPE handling
-//        try {
         Optional<Services> serviceOpt = this.serviceDataStoreOperations.getService(serviceName);
-//        } catch (NullPointerException e) {
-//            LOG.error("Something wrong when retrieving service '{}' from datastore : ", serviceName, e);
-//            return ModelMappingUtils.createDeleteServiceReply(
-//                    input, ResponseCodes.FINAL_ACK_YES,
-//                    LogMessages.serviceNotInDS(serviceName), ResponseCodes.RESPONSE_FAILED);
-//        }
         Services service;
         if (!serviceOpt.isPresent()) {
-            LOG.warn("serviceDelete: {}", LogMessages.serviceNotInDS(serviceName));
+            LOG.warn(SERVICE_DELETE_MSG, LogMessages.serviceNotInDS(serviceName));
             return ModelMappingUtils.createDeleteServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     LogMessages.serviceNotInDS(serviceName), ResponseCodes.RESPONSE_FAILED);
@@ -234,7 +232,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
                 serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, service);
 
         if (output == null) {
-            LOG.error("serviceDelete: {}", LogMessages.RENDERER_DELETE_FAILED);
+            LOG.error(SERVICE_DELETE_MSG, LogMessages.RENDERER_DELETE_FAILED);
             return ModelMappingUtils.createDeleteServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     LogMessages.RENDERER_DELETE_FAILED, ResponseCodes.RESPONSE_FAILED);
@@ -256,7 +254,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(serviceInput,
                 RpcActions.ServiceFeasibilityCheck);
         if (! validationResult.isSuccess()) {
-            LOG.warn("serviceFeasabilityCheck: {}", LogMessages.ABORT_VALID_FAILED);
+            LOG.warn(SERVICE_FEASABILITY_CHECK_MSG, LogMessages.ABORT_VALID_FAILED);
             return ModelMappingUtils.createCreateServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
@@ -267,10 +265,10 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
-        LOG.debug("serviceFeasabilityCheck: {}", LogMessages.PCE_CALLING);
+        LOG.debug(SERVICE_FEASABILITY_CHECK_MSG, LogMessages.PCE_CALLING);
         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
         if (output == null) {
-            LOG.warn("serviceFeasabilityCheck: {}", LogMessages.ABORT_PCE_FAILED);
+            LOG.warn(SERVICE_FEASABILITY_CHECK_MSG, LogMessages.ABORT_PCE_FAILED);
             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
         }
@@ -287,7 +285,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         LOG.info("RPC serviceReconfigure received for {}", serviceName);
         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
         if (!servicesObject.isPresent()) {
-            LOG.warn("serviceReconfigure: {}", LogMessages.serviceNotInDS(serviceName));
+            LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.serviceNotInDS(serviceName));
             return ModelMappingUtils.createCreateServiceReply(
                 input,
                 LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed);
@@ -296,7 +294,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         OperationResult validationResult = ServiceCreateValidation
                 .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceReconfigure);
         if (!validationResult.isSuccess()) {
-            LOG.warn("serviceReconfigure: {}", LogMessages.ABORT_VALID_FAILED);
+            LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.ABORT_VALID_FAILED);
             return ModelMappingUtils.createCreateServiceReply(
                     input,
                     validationResult.getResultMessage(), RpcStatus.Failed);
@@ -313,7 +311,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
                 .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
                         ServiceNotificationTypes.ServiceDeleteResult, null);
         if (output == null) {
-            LOG.error("serviceReconfigure: {}", LogMessages.RENDERER_DELETE_FAILED);
+            LOG.error(SERVICE_RECONFIGURE_MSG, LogMessages.RENDERER_DELETE_FAILED);
             return ModelMappingUtils.createCreateServiceReply(
                     input,
                     LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Successful);
@@ -333,7 +331,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
 
         if (!servicesObject.isPresent()) {
-            LOG.warn("serviceRestoration: {}", LogMessages.serviceNotInDS(serviceName));
+            LOG.warn(SERVICE_RESTORATION_MSG, LogMessages.serviceNotInDS(serviceName));
             return ModelMappingUtils.createRestoreServiceReply(
                     LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed);
         }
@@ -342,7 +340,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         State state = service.getOperationalState();
 
         if (state == State.InService) {
-            LOG.error("serviceRestoration: {}", LogMessages.serviceInService(serviceName));
+            LOG.error(SERVICE_RESTORATION_MSG, LogMessages.serviceInService(serviceName));
             return ModelMappingUtils.createRestoreServiceReply(
                     LogMessages.serviceInService(serviceName), RpcStatus.Failed);
         }
@@ -393,7 +391,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
             .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
                 ServiceNotificationTypes.ServiceDeleteResult, null);
         if (output == null) {
-            LOG.error("serviceRestoration: {}", LogMessages.RENDERER_DELETE_FAILED);
+            LOG.error(SERVICE_RESTORATION_MSG, LogMessages.RENDERER_DELETE_FAILED);
             return ModelMappingUtils.createRestoreServiceReply(
                      LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Failed);
         }
@@ -504,7 +502,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
                 commonId, null, null, RpcActions.ServiceDelete, false, false
             );
         if (!serviceHandlerCheckResult.hasPassed()) {
-            LOG.warn("tempServiceDelete: {}", LogMessages.ABORT_SERVICE_NON_COMPLIANT);
+            LOG.warn(TEMP_SERVICE_DELETE_MSG, LogMessages.ABORT_SERVICE_NON_COMPLIANT);
             return ModelMappingUtils.createDeleteServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     LogMessages.SERVICE_NON_COMPLIANT, ResponseCodes.RESPONSE_FAILED);
@@ -512,19 +510,11 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
 
         //Check presence of service to be deleted
         LOG.debug("service common-id '{}' is compliant", commonId);
-//TODO check if an expected bug was justifying this NPE handling
-//        try {
         Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list.Services>
                 service =
             this.serviceDataStoreOperations.getTempService(commonId);
-//        } catch (NullPointerException e) {
-//            LOG.info("failed to get service '{}' from datastore : ", commonId, e);
-//            return ModelMappingUtils.createDeleteServiceReply(
-//                    input, ResponseCodes.FINAL_ACK_YES,
-//                    LogMessages.serviceNotInDS(CommonId), ResponseCodes.RESPONSE_FAILED);
-//        }
         if (!service.isPresent()) {
-            LOG.error("tempServiceDelete: {}", LogMessages.serviceNotInDS(commonId));
+            LOG.error(TEMP_SERVICE_DELETE_MSG, LogMessages.serviceNotInDS(commonId));
             return ModelMappingUtils.createDeleteServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     LogMessages.serviceNotInDS(commonId), ResponseCodes.RESPONSE_FAILED);
@@ -540,7 +530,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteOutput output =
                 this.rendererServiceWrapper.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
         if (output == null) {
-            LOG.error("tempServiceDelete: {}", LogMessages.RENDERER_DELETE_FAILED);
+            LOG.error(TEMP_SERVICE_DELETE_MSG, LogMessages.RENDERER_DELETE_FAILED);
             return ModelMappingUtils.createDeleteServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     LogMessages.RENDERER_DELETE_FAILED, ResponseCodes.RESPONSE_FAILED);
@@ -559,14 +549,14 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
                 new ServiceInput(input), RpcActions.TempServiceCreate);
         if (! validationResult.isSuccess()) {
-            LOG.warn("tempServiceCreate: {}", LogMessages.ABORT_VALID_FAILED);
+            LOG.warn(TEMP_SERVICE_CREATE_MSG, LogMessages.ABORT_VALID_FAILED);
             return ModelMappingUtils.createCreateServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
         }
 
         // Starting service create operation
-        LOG.debug("tempServiceCreate: {}", LogMessages.PCE_CALLING);
+        LOG.debug(TEMP_SERVICE_CREATE_MSG, LogMessages.PCE_CALLING);
         this.pceListenerImpl.setInput(new ServiceInput(input));
         this.pceListenerImpl.setServiceReconfigure(false);
         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
@@ -576,7 +566,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService {
         this.rendererListenerImpl.setTempService(true);
         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
         if (output == null) {
-            LOG.warn("tempServiceCreate: {}", LogMessages.ABORT_PCE_FAILED);
+            LOG.warn(TEMP_SERVICE_CREATE_MSG, LogMessages.ABORT_PCE_FAILED);
             return ModelMappingUtils.createCreateServiceReply(
                     input, ResponseCodes.FINAL_ACK_YES,
                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
index 89b5b8ed949c8a83114e9ae353b618bb815e526b..65e199b4fa0470d0b762b9c0ecc807f6700ab9da 100644 (file)
@@ -58,107 +58,119 @@ public class PceListenerImpl implements TransportpcePceListener {
     public void onServicePathRpcResult(ServicePathRpcResult notification) {
         if (!compareServicePathRpcResult(notification)) {
             servicePathRpcResult = notification;
-            PathDescription pathDescription = null;
             switch (servicePathRpcResult.getNotificationType().getIntValue()) {
                 /* path-computation-request. */
                 case 1:
-                    LOG.info("PCE '{}' Notification received : {}",servicePathRpcResult.getNotificationType().getName(),
-                            notification);
-                    if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
-                        LOG.info("PCE calculation done OK !");
-                        if (servicePathRpcResult.getPathDescription() != null) {
-                            pathDescription = new PathDescriptionBuilder()
-                                    .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
-                                .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection()).build();
-                            LOG.info("PathDescription gets : {}", pathDescription);
-                            if (!serviceFeasiblity) {
-                                if (input == null) {
-                                    LOG.error("Input is null !");
-                                    return;
-                                }
-                                OperationResult operationResult = null;
-                                if (tempService) {
-                                    operationResult = this.serviceDataStoreOperations
-                                        .createTempService(input.getTempServiceCreateInput());
-                                    if (!operationResult.isSuccess()) {
-                                        LOG.error("Temp Service not created in datastore !");
-                                    }
-                                } else {
-                                    operationResult = this.serviceDataStoreOperations
-                                        .createService(input.getServiceCreateInput());
-                                    if (!operationResult.isSuccess()) {
-                                        LOG.error("Service not created in datastore !");
-                                    }
-                                }
-                                ResponseParameters responseParameters = new ResponseParametersBuilder()
-                                        .setPathDescription(new org.opendaylight.yang.gen.v1.http.org
-                                                .transportpce.b.c._interface.service.types.rev200128
-                                                .response.parameters.sp.response.parameters
-                                                .PathDescriptionBuilder(pathDescription).build())
-                                        .build();
-                                PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
-                                        .setResponseParameters(responseParameters).build();
-                                OperationResult operationServicePathSaveResult =
-                                        this.serviceDataStoreOperations.createServicePath(input, pceResponse);
-                                if (!operationServicePathSaveResult.isSuccess()) {
-                                    LOG.error("Service Path not created in datastore !");
-                                }
-                                ServiceImplementationRequestInput serviceImplementationRequest =
-                                        ModelMappingUtils.createServiceImplementationRequest(input, pathDescription);
-                                LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
-                                this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
-                            } else {
-                                LOG.warn("service-feasibility-check RPC ");
-                            }
-                        } else {
-                            LOG.error("'PathDescription' parameter is null ");
-                            return;
-                        }
-                    } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
-                        LOG.error("PCE path computation failed !");
-                        return;
-                    }
+                    onPathComputationResult(notification);
                     break;
                 /* cancel-resource-reserve. */
                 case 2:
-                    if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
-                        LOG.info("PCE cancel resource done OK !");
-                        OperationResult deleteServicePathOperationResult =
-                                this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
-                        if (!deleteServicePathOperationResult.isSuccess()) {
-                            LOG.warn("Service path was not removed from datastore!");
-                        }
-                        OperationResult deleteServiceOperationResult = null;
+                    onCancelResourceResult();
+                    break;
+                default:
+                    break;
+            }
+        } else {
+            LOG.warn("ServicePathRpcResult already wired !");
+        }
+    }
+
+    /**
+     * Process path computation request result.
+     * @param notification the result notification.
+     */
+    private void onPathComputationResult(ServicePathRpcResult notification) {
+        LOG.info("PCE '{}' Notification received : {}",servicePathRpcResult.getNotificationType().getName(),
+                notification);
+        if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
+            LOG.info("PCE calculation done OK !");
+            if (servicePathRpcResult.getPathDescription() != null) {
+                PathDescription pathDescription = new PathDescriptionBuilder()
+                        .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
+                    .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection()).build();
+                LOG.info("PathDescription gets : {}", pathDescription);
+                if (!serviceFeasiblity) {
+                    if (input == null) {
+                        LOG.error("Input is null !");
+                    } else {
+                        OperationResult operationResult = null;
                         if (tempService) {
-                            deleteServiceOperationResult =
-                                    this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
-                            if (!deleteServiceOperationResult.isSuccess()) {
-                                LOG.warn("Service was not removed from datastore!");
+                            operationResult = this.serviceDataStoreOperations
+                                    .createTempService(input.getTempServiceCreateInput());
+                            if (!operationResult.isSuccess()) {
+                                LOG.error("Temp Service not created in datastore !");
                             }
                         } else {
-                            deleteServiceOperationResult =
-                                    this.serviceDataStoreOperations.deleteService(input.getServiceName());
-                            if (!deleteServiceOperationResult.isSuccess()) {
-                                LOG.warn("Service was not removed from datastore!");
+                            operationResult = this.serviceDataStoreOperations
+                                    .createService(input.getServiceCreateInput());
+                            if (!operationResult.isSuccess()) {
+                                LOG.error("Service not created in datastore !");
                             }
                         }
-                        /**
-                         * if it was an RPC serviceReconfigure, re-launch PCR.
-                         */
-                        if (this.serviceReconfigure) {
-                            LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
-                            this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
-                            this.serviceReconfigure = false;
+                        ResponseParameters responseParameters = new ResponseParametersBuilder()
+                                .setPathDescription(new org.opendaylight.yang.gen.v1.http.org
+                                        .transportpce.b.c._interface.service.types.rev200128
+                                        .response.parameters.sp.response.parameters
+                                        .PathDescriptionBuilder(pathDescription).build())
+                                .build();
+                        PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
+                                .setResponseParameters(responseParameters).build();
+                        OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations
+                                .createServicePath(input, pceResponse);
+                        if (!operationServicePathSaveResult.isSuccess()) {
+                            LOG.error("Service Path not created in datastore !");
                         }
-                    } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
-                        LOG.info("PCE cancel resource failed !");
+                        ServiceImplementationRequestInput serviceImplementationRequest = ModelMappingUtils
+                                .createServiceImplementationRequest(input, pathDescription);
+                        LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
+                        this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
                     }
-                    break;
-                default:
-                    break;
+                } else {
+                    LOG.warn("service-feasibility-check RPC ");
+                }
+            } else {
+                LOG.error("'PathDescription' parameter is null ");
             }
-        } else {
-            LOG.warn("ServicePathRpcResult already wired !");
+        } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
+            LOG.error("PCE path computation failed !");
+        }
+    }
+
+    /**
+     * Process cancel resource result.
+     */
+    private void onCancelResourceResult() {
+        if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
+            LOG.info("PCE cancel resource done OK !");
+            OperationResult deleteServicePathOperationResult =
+                    this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
+            if (!deleteServicePathOperationResult.isSuccess()) {
+                LOG.warn("Service path was not removed from datastore!");
+            }
+            OperationResult deleteServiceOperationResult = null;
+            if (tempService) {
+                deleteServiceOperationResult =
+                        this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
+                if (!deleteServiceOperationResult.isSuccess()) {
+                    LOG.warn("Service was not removed from datastore!");
+                }
+            } else {
+                deleteServiceOperationResult =
+                        this.serviceDataStoreOperations.deleteService(input.getServiceName());
+                if (!deleteServiceOperationResult.isSuccess()) {
+                    LOG.warn("Service was not removed from datastore!");
+                }
+            }
+            /**
+             * if it was an RPC serviceReconfigure, re-launch PCR.
+             */
+            if (this.serviceReconfigure) {
+                LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
+                this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
+                this.serviceReconfigure = false;
+            }
+        } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
+            LOG.info("PCE cancel resource failed !");
         }
     }
 
index 533d23dc01973b5ce4c9fcf2bf4f68faed654331..0669f842c3827c882e2acc4898b10290fc330c68 100644 (file)
@@ -56,64 +56,11 @@ public class RendererListenerImpl implements TransportpceRendererListener {
             switch (notifType) {
                 /* service-implementation-request. */
                 case 3 :
-                    if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
-                        LOG.info("Service implemented !");
-                        if (serviceDataStoreOperations == null) {
-                            return;
-                        }
-                        OperationResult operationResult = null;
-                        if (tempService) {
-                            operationResult = this.serviceDataStoreOperations.modifyTempService(
-                                    serviceRpcResultSp.getServiceName(),
-                                    State.InService, AdminStates.InService);
-                            if (!operationResult.isSuccess()) {
-                                LOG.warn("Temp Service status not updated in datastore !");
-                            }
-                        } else {
-                            operationResult = this.serviceDataStoreOperations.modifyService(
-                                    serviceRpcResultSp.getServiceName(),
-                                    State.InService, AdminStates.InService);
-                            if (!operationResult.isSuccess()) {
-                                LOG.warn("Service status not updated in datastore !");
-                            }
-                        }
-                    } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
-                        LOG.error("Renderer implementation failed !");
-                        OperationResult deleteServicePathOperationResult =
-                                this.serviceDataStoreOperations.deleteServicePath(serviceName);
-                        if (!deleteServicePathOperationResult.isSuccess()) {
-                            LOG.warn("Service path was not removed from datastore!");
-                        }
-                        if (tempService) {
-                            OperationResult deleteServiceOperationResult =
-                                    this.serviceDataStoreOperations.deleteTempService(serviceName);
-                            if (!deleteServiceOperationResult.isSuccess()) {
-                                LOG.warn("Temp Service was not removed from datastore!");
-                            }
-                        } else {
-                            OperationResult deleteServiceOperationResult =
-                                    this.serviceDataStoreOperations.deleteService(serviceName);
-                            if (!deleteServiceOperationResult.isSuccess()) {
-                                LOG.warn("Service was not removed from datastore!");
-                            }
-                        }
-                    }
+                    onServiceImplementationResult(serviceName);
                     break;
                 /* service-delete. */
                 case 4 :
-                    if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
-                        LOG.info("Service '{}' deleted !", serviceName);
-                        if (this.input != null) {
-                            LOG.info("sending PCE cancel resource reserve for '{}'",  this.input.getServiceName());
-                            this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
-                                    ServiceNotificationTypes.ServiceDeleteResult);
-                        } else {
-                            LOG.error("ServiceInput parameter is null !");
-                        }
-                    } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
-                        LOG.error("Renderer service delete failed !");
-                        return;
-                    }
+                    onServiceDeleteResult(serviceName);
                     break;
                 default:
                     break;
@@ -123,6 +70,88 @@ public class RendererListenerImpl implements TransportpceRendererListener {
         }
     }
 
+    /**
+     * Process service delete result for serviceName.
+     * @param serviceName String
+     */
+    private void onServiceDeleteResult(String serviceName) {
+        if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
+            LOG.info("Service '{}' deleted !", serviceName);
+            if (this.input != null) {
+                LOG.info("sending PCE cancel resource reserve for '{}'",  this.input.getServiceName());
+                this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
+                        ServiceNotificationTypes.ServiceDeleteResult);
+            } else {
+                LOG.error("ServiceInput parameter is null !");
+            }
+        } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
+            LOG.error("Renderer service delete failed !");
+        }
+    }
+
+    /**
+     * Process service implementation result for serviceName.
+     * @param serviceName String
+     * @param serviceName String
+     */
+    private void onServiceImplementationResult(String serviceName) {
+        if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
+            onSuccededServiceImplementation();
+        } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
+            onFailedServiceImplementation(serviceName);
+        }
+    }
+
+    /**
+     * Process succeeded service implementation for service.
+     */
+    private void onSuccededServiceImplementation() {
+        LOG.info("Service implemented !");
+        if (serviceDataStoreOperations != null) {
+            OperationResult operationResult = null;
+            if (tempService) {
+                operationResult = this.serviceDataStoreOperations.modifyTempService(
+                        serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
+                if (!operationResult.isSuccess()) {
+                    LOG.warn("Temp Service status not updated in datastore !");
+                }
+            } else {
+                operationResult = this.serviceDataStoreOperations
+                        .modifyService(serviceRpcResultSp.getServiceName(),
+                                State.InService, AdminStates.InService);
+                if (!operationResult.isSuccess()) {
+                    LOG.warn("Service status not updated in datastore !");
+                }
+            }
+        }
+    }
+
+    /**
+     * Process failed service implementation for serviceName.
+     * @param serviceName String
+     */
+    private void onFailedServiceImplementation(String serviceName) {
+        LOG.error("Renderer implementation failed !");
+        OperationResult deleteServicePathOperationResult =
+                this.serviceDataStoreOperations.deleteServicePath(serviceName);
+        if (!deleteServicePathOperationResult.isSuccess()) {
+            LOG.warn("Service path was not removed from datastore!");
+        }
+        if (tempService) {
+            OperationResult deleteServiceOperationResult =
+                    this.serviceDataStoreOperations.deleteTempService(serviceName);
+            if (!deleteServiceOperationResult.isSuccess()) {
+                LOG.warn("Temp Service was not removed from datastore!");
+            }
+        } else {
+            OperationResult deleteServiceOperationResult =
+                    this.serviceDataStoreOperations.deleteService(serviceName);
+            if (!deleteServiceOperationResult.isSuccess()) {
+                LOG.warn("Service was not removed from datastore!");
+            }
+        }
+    }
+
     @SuppressFBWarnings(
         value = "ES_COMPARING_STRINGS_WITH_EQ",
         justification = "false positives, not strings but real object references comparisons")
index e2c8fdc1ebef227ef50ed0c3ad3ae33b64c97e97..98cccf641acbf176f14d6da0268e2ed9db71d441 100644 (file)
@@ -48,6 +48,10 @@ import org.slf4j.LoggerFactory;
 
 public class PCEServiceWrapper {
 
+    private static final String NOTIFICATION_OFFER_REJECTED_MSG = "notification offer rejected : ";
+
+    private static final String PERFORMING_PCE_MSG = "performing PCE ...";
+
     private static final Logger LOG = LoggerFactory.getLogger(PCEServiceWrapper.class);
 
     private final PathComputationService pathComputationService;
@@ -63,7 +67,7 @@ public class PCEServiceWrapper {
     }
 
     public PathComputationRequestOutput performPCE(ServiceCreateInput serviceCreateInput, boolean reserveResource) {
-        LOG.info("performing PCE ...");
+        LOG.info(PERFORMING_PCE_MSG);
         if (validateParams(serviceCreateInput.getServiceName(), serviceCreateInput.getSdncRequestHeader())) {
             return performPCE(serviceCreateInput.getHardConstraints(), serviceCreateInput.getSoftConstraints(),
                     serviceCreateInput.getServiceName(), serviceCreateInput.getSdncRequestHeader(),
@@ -76,7 +80,7 @@ public class PCEServiceWrapper {
 
     public PathComputationRequestOutput performPCE(TempServiceCreateInput tempServiceCreateInput,
             boolean reserveResource) {
-        LOG.info("performing PCE ...");
+        LOG.info(PERFORMING_PCE_MSG);
         if (validateParams(tempServiceCreateInput.getCommonId(), tempServiceCreateInput.getSdncRequestHeader())) {
             return performPCE(tempServiceCreateInput.getHardConstraints(), tempServiceCreateInput.getSoftConstraints(),
                     tempServiceCreateInput.getCommonId(), tempServiceCreateInput.getSdncRequestHeader(),
@@ -89,7 +93,7 @@ public class PCEServiceWrapper {
 
     public PathComputationRequestOutput performPCE(ServiceFeasibilityCheckInput serviceFeasibilityCheckInput,
             boolean reserveResource) {
-        LOG.info("performing PCE ...");
+        LOG.info(PERFORMING_PCE_MSG);
         if (validateParams(serviceFeasibilityCheckInput.getCommonId(),
                 serviceFeasibilityCheckInput.getSdncRequestHeader())) {
             return performPCE(serviceFeasibilityCheckInput.getHardConstraints(),
@@ -116,55 +120,10 @@ public class PCEServiceWrapper {
         try {
             notificationPublishService.putNotification(notification);
         } catch (InterruptedException e) {
-            LOG.info("notification offer rejected : ", e);
+            LOG.info(NOTIFICATION_OFFER_REJECTED_MSG, e);
         }
-        FutureCallback<PathComputationRequestOutput> pceCallback = new FutureCallback<PathComputationRequestOutput>() {
-            String message = "";
-            ServiceRpcResultSh notification = null;
-
-            @Override
-            public void onSuccess(PathComputationRequestOutput response) {
-                if (response != null) {
-                    /**
-                     * If PCE reply is received before timer expiration with a positive result, a
-                     * service is created with admin and operational status 'down'.
-                     */
-                    message = "PCE replied to PCR Request !";
-                    LOG.info("PCE replied to PCR Request : {}", response);
-                    notification = new ServiceRpcResultShBuilder().setNotificationType(notifType)
-                            .setServiceName(serviceName)
-                            .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
-                    try {
-                        notificationPublishService.putNotification(notification);
-                    } catch (InterruptedException e) {
-                        LOG.info("notification offer rejected : ", e);
-                    }
-                } else {
-                    message = "PCE failed ";
-                    notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName("")
-                            .setStatus(RpcStatusEx.Failed).setStatusMessage(message).build();
-                    try {
-                        notificationPublishService.putNotification(notification);
-                    } catch (InterruptedException e) {
-                        LOG.info("notification offer rejected : ", e);
-                    }
-                }
-            }
-
-            @Override
-            public void onFailure(Throwable arg0) {
-                LOG.error("Path not calculated..");
-                notification = new ServiceRpcResultShBuilder().setNotificationType(notifType)
-                        .setServiceName(serviceName)
-                        .setStatus(RpcStatusEx.Failed).setStatusMessage("PCR Request failed  : " + arg0.getMessage())
-                        .build();
-                try {
-                    notificationPublishService.putNotification(notification);
-                } catch (InterruptedException e) {
-                    LOG.info("notification offer rejected : ", e);
-                }
-            }
-        };
+        FutureCallback<PathComputationRequestOutput> pceCallback =
+                new PathComputationRequestOutputCallback(notifType, serviceName);
         PathComputationRequestInput pathComputationRequestInput = createPceRequestInput(serviceName, sdncRequestHeader,
                 mappingConstraints.getServicePathHardConstraints(), mappingConstraints.getServicePathSoftConstraints(),
                 reserveResource, serviceAEnd, serviceZEnd);
@@ -233,55 +192,10 @@ public class PCEServiceWrapper {
         try {
             notificationPublishService.putNotification(notification);
         } catch (InterruptedException e) {
-            LOG.info("notification offer rejected : ", e);
+            LOG.info(NOTIFICATION_OFFER_REJECTED_MSG, e);
         }
-        FutureCallback<CancelResourceReserveOutput> pceCallback = new FutureCallback<CancelResourceReserveOutput>() {
-
-            String message = "";
-            ServiceRpcResultSh notification = null;
-
-            @Override
-            public void onSuccess(CancelResourceReserveOutput response) {
-                if (response != null) {
-                    /**
-                     * If PCE reply is received before timer expiration with a positive result, a
-                     * service is created with admin and operational status 'down'.
-                     */
-                    message = "PCE replied to CRR Request !";
-                    LOG.info("PCE replied to CRR Request : {}", response);
-                    notification =
-                            new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName(serviceName)
-                                    .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
-                    try {
-                        notificationPublishService.putNotification(notification);
-                    } catch (InterruptedException e) {
-                        LOG.info("notification offer rejected : ", e);
-                    }
-                } else {
-                    message = "PCE failed ";
-                    notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName("")
-                            .setStatus(RpcStatusEx.Failed).setStatusMessage(message).build();
-                    try {
-                        notificationPublishService.putNotification(notification);
-                    } catch (InterruptedException e) {
-                        LOG.info("notification offer rejected : ", e);
-                    }
-                }
-            }
-
-            @Override
-            public void onFailure(Throwable arg0) {
-                LOG.error("Cancel resource failed !");
-                notification = new ServiceRpcResultShBuilder().setNotificationType(notifType)
-                        .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
-                        .setStatusMessage("CRR Request failed  : " + arg0.getMessage()).build();
-                try {
-                    notificationPublishService.putNotification(notification);
-                } catch (InterruptedException e) {
-                    LOG.info("notification offer rejected : ", e);
-                }
-            }
-        };
+        FutureCallback<CancelResourceReserveOutput> pceCallback =
+                new CancelResourceReserveOutputFutureCallback(notifType, serviceName);
         CancelResourceReserveInput cancelResourceReserveInput = mappingCancelResourceReserve(serviceName, null);
         ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder();
         if (cancelResourceReserveInput != null) {
@@ -328,4 +242,114 @@ public class PCEServiceWrapper {
     private static boolean checkString(String value) {
         return ((value != null) && (value.compareTo("") != 0));
     }
+
+    private final class CancelResourceReserveOutputFutureCallback
+            implements FutureCallback<CancelResourceReserveOutput> {
+        private final ServiceNotificationTypes notifType;
+        private final String serviceName;
+        String message = "";
+        ServiceRpcResultSh notification = null;
+
+        private CancelResourceReserveOutputFutureCallback(ServiceNotificationTypes notifType, String serviceName) {
+            this.notifType = notifType;
+            this.serviceName = serviceName;
+        }
+
+        @Override
+        public void onSuccess(CancelResourceReserveOutput response) {
+            if (response != null) {
+                /**
+                 * If PCE reply is received before timer expiration with a positive result, a
+                 * service is created with admin and operational status 'down'.
+                 */
+                message = "PCE replied to CRR Request !";
+                LOG.info("PCE replied to CRR Request : {}", response);
+                notification =
+                        new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName(serviceName)
+                                .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
+                try {
+                    notificationPublishService.putNotification(notification);
+                } catch (InterruptedException e) {
+                    LOG.info(NOTIFICATION_OFFER_REJECTED_MSG, e);
+                }
+            } else {
+                message = "PCE failed ";
+                notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName("")
+                        .setStatus(RpcStatusEx.Failed).setStatusMessage(message).build();
+                try {
+                    notificationPublishService.putNotification(notification);
+                } catch (InterruptedException e) {
+                    LOG.info(NOTIFICATION_OFFER_REJECTED_MSG, e);
+                }
+            }
+        }
+
+        @Override
+        public void onFailure(Throwable arg0) {
+            LOG.error("Cancel resource failed !");
+            notification = new ServiceRpcResultShBuilder().setNotificationType(notifType)
+                    .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
+                    .setStatusMessage("CRR Request failed  : " + arg0.getMessage()).build();
+            try {
+                notificationPublishService.putNotification(notification);
+            } catch (InterruptedException e) {
+                LOG.info(NOTIFICATION_OFFER_REJECTED_MSG, e);
+            }
+        }
+    }
+
+    private final class PathComputationRequestOutputCallback implements FutureCallback<PathComputationRequestOutput> {
+        private final ServiceNotificationTypes notifType;
+        private final String serviceName;
+        String message = "";
+        ServiceRpcResultSh notification = null;
+
+        private PathComputationRequestOutputCallback(ServiceNotificationTypes notifType, String serviceName) {
+            this.notifType = notifType;
+            this.serviceName = serviceName;
+        }
+
+        @Override
+        public void onSuccess(PathComputationRequestOutput response) {
+            if (response != null) {
+                /**
+                 * If PCE reply is received before timer expiration with a positive result, a
+                 * service is created with admin and operational status 'down'.
+                 */
+                message = "PCE replied to PCR Request !";
+                LOG.info("PCE replied to PCR Request : {}", response);
+                notification = new ServiceRpcResultShBuilder().setNotificationType(notifType)
+                        .setServiceName(serviceName)
+                        .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
+                try {
+                    notificationPublishService.putNotification(notification);
+                } catch (InterruptedException e) {
+                    LOG.info(NOTIFICATION_OFFER_REJECTED_MSG, e);
+                }
+            } else {
+                message = "PCE failed ";
+                notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName("")
+                        .setStatus(RpcStatusEx.Failed).setStatusMessage(message).build();
+                try {
+                    notificationPublishService.putNotification(notification);
+                } catch (InterruptedException e) {
+                    LOG.info(NOTIFICATION_OFFER_REJECTED_MSG, e);
+                }
+            }
+        }
+
+        @Override
+        public void onFailure(Throwable arg0) {
+            LOG.error("Path not calculated..");
+            notification = new ServiceRpcResultShBuilder().setNotificationType(notifType)
+                    .setServiceName(serviceName)
+                    .setStatus(RpcStatusEx.Failed).setStatusMessage("PCR Request failed  : " + arg0.getMessage())
+                    .build();
+            try {
+                notificationPublishService.putNotification(notification);
+            } catch (InterruptedException e) {
+                LOG.info(NOTIFICATION_OFFER_REJECTED_MSG, e);
+            }
+        }
+    }
 }
index 0bf4936382b94d9db7b87077e4a281913c63df17..6fec7dc5612be5530ca865315108a894e9d90a02 100644 (file)
@@ -90,42 +90,8 @@ public class RendererServiceWrapper {
                 .setStatus(RpcStatusEx.Pending)
                 .setStatusMessage("Service compliant, submitting temp service delete Request ...").build();
         sendNotifications(notification);
-        FutureCallback<ServiceDeleteOutput> rendererCallback = new FutureCallback<ServiceDeleteOutput>() {
-
-            String message = "";
-            ServiceRpcResultSh notification = null;
-
-            @Override
-            public void onSuccess(ServiceDeleteOutput response) {
-                if (response != null) {
-                    /**
-                     * If PCE reply is received before timer expiration with a positive result, a
-                     * service is created with admin and operational status 'down'.
-                     */
-                    message = "Renderer replied to service delete Request !";
-                    LOG.info("Renderer replied to service delete Request : {}", response);
-                    notification =
-                            new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName(serviceName)
-                                    .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
-                    sendNotifications(notification);
-                } else {
-                    message = "Renderer service delete failed ";
-                    notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName("")
-                            .setStatus(RpcStatusEx.Failed).setStatusMessage(message).build();
-                    sendNotifications(notification);
-                }
-            }
-
-            @Override
-            public void onFailure(Throwable arg0) {
-                LOG.error("Renderer service delete failed !");
-                notification = new ServiceRpcResultShBuilder().setNotificationType(notifType)
-                        .setServiceName(serviceName)
-                        .setStatus(RpcStatusEx.Failed)
-                        .setStatusMessage("Renderer service delete request failed  : " + arg0.getMessage()).build();
-                sendNotifications(notification);
-            }
-        };
+        FutureCallback<ServiceDeleteOutput> rendererCallback =
+                new ServiceDeleteOutputFutureCallback(notifType, serviceName);
         ServiceDeleteInput serviceDeleteInput = createRendererRequestInput(serviceName, serviceHandlerHeader);
         ListenableFuture<ServiceDeleteOutput> renderer =
                 this.rendererServiceOperations.serviceDelete(serviceDeleteInput, service);
@@ -167,5 +133,47 @@ public class RendererServiceWrapper {
     private static boolean checkString(String value) {
         return ((value != null) && (value.compareTo("") != 0));
     }
+
+    private final class ServiceDeleteOutputFutureCallback implements FutureCallback<ServiceDeleteOutput> {
+        private final ServiceNotificationTypes notifType;
+        private final String serviceName;
+        String message = "";
+        ServiceRpcResultSh notification = null;
+
+        private ServiceDeleteOutputFutureCallback(ServiceNotificationTypes notifType, String serviceName) {
+            this.notifType = notifType;
+            this.serviceName = serviceName;
+        }
+
+        @Override
+        public void onSuccess(ServiceDeleteOutput response) {
+            if (response != null) {
+                /**
+                 * If PCE reply is received before timer expiration with a positive result, a
+                 * service is created with admin and operational status 'down'.
+                 */
+                message = "Renderer replied to service delete Request !";
+                LOG.info("Renderer replied to service delete Request : {}", response);
+                notification = new ServiceRpcResultShBuilder().setNotificationType(notifType)
+                        .setServiceName(serviceName).setStatus(RpcStatusEx.Successful).setStatusMessage(message)
+                        .build();
+                sendNotifications(notification);
+            } else {
+                message = "Renderer service delete failed ";
+                notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName("")
+                        .setStatus(RpcStatusEx.Failed).setStatusMessage(message).build();
+                sendNotifications(notification);
+            }
+        }
+
+        @Override
+        public void onFailure(Throwable arg0) {
+            LOG.error("Renderer service delete failed !");
+            notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName(serviceName)
+                    .setStatus(RpcStatusEx.Failed)
+                    .setStatusMessage("Renderer service delete request failed  : " + arg0.getMessage()).build();
+            sendNotifications(notification);
+        }
+    }
 }
 
index bd590e607a2f088e28abc091a88b338c2c4c227a..96ef8cbffe75934bec960e4513c5269612f92b52 100644 (file)
@@ -44,6 +44,8 @@ import org.slf4j.LoggerFactory;
 
 public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperations {
     private static final Logger LOG = LoggerFactory.getLogger(ServiceDataStoreOperationsImpl.class);
+    private static final String CREATE_MSG = "create";
+    private static final String DELETING_SERVICE_MSG = "Deleting '{}' Service";
     private DataBroker dataBroker;
 
     // This is class is public so that these messages can be accessed from Junit (avoid duplications).
@@ -141,7 +143,7 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation
 
     @Override
     public OperationResult deleteService(String serviceName) {
-        LOG.debug("Deleting '{}' Service", serviceName);
+        LOG.debug(DELETING_SERVICE_MSG, serviceName);
         try {
             WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
             InstanceIdentifier<Services> iid =
@@ -157,7 +159,7 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation
 
     @Override
     public OperationResult deleteTempService(String commonId) {
-        LOG.debug("Deleting '{}' Service", commonId);
+        LOG.debug(DELETING_SERVICE_MSG, commonId);
         try {
             WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
             InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list
@@ -241,8 +243,8 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation
             writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
             return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
         } catch (TimeoutException | InterruptedException | ExecutionException e) {
-            LOG.warn("createService : {}", LogMessages.failedTo("create", serviceCreateInput.getServiceName()), e);
-            return OperationResult.failed(LogMessages.failedTo("create", serviceCreateInput.getServiceName()));
+            LOG.warn("createService : {}", LogMessages.failedTo(CREATE_MSG, serviceCreateInput.getServiceName()), e);
+            return OperationResult.failed(LogMessages.failedTo(CREATE_MSG, serviceCreateInput.getServiceName()));
         }
     }
 
@@ -341,8 +343,8 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation
                 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
                 return null;
             } catch (InterruptedException | TimeoutException | ExecutionException e) {
-                LOG.error("writeOrModifyOrDeleteServiceList : {}", LogMessages.failedTo("create", serviceName), e);
-                return LogMessages.failedTo("create", serviceName);
+                LOG.error("writeOrModifyOrDeleteServiceList : {}", LogMessages.failedTo(CREATE_MSG, serviceName), e);
+                return LogMessages.failedTo(CREATE_MSG, serviceName);
             }
         }
 
@@ -361,7 +363,7 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation
                 action = "modifyService";
                 break;
             case 1 : /* Delete */
-                LOG.debug("Deleting '{}' Service", serviceName);
+                LOG.debug(DELETING_SERVICE_MSG, serviceName);
                 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
                 action = "deleteService";
                 break;
index 519f85cfb761678f2049edd8a63a060ce9f76b6c..cdcedfeda2b0cdea9dd67ab861363500eb8a3adf 100644 (file)
@@ -25,6 +25,7 @@ public final class ServicehandlerTxRxCheck {
     // This is class is public so that these messages can be accessed from Junit (avoid duplications).
     public static final class LogMessages {
 
+        private static final String SERVICE = "Service ";
         public static final String TXDIR_NOT_SET;
         public static final String TXDIR_PORT_NOT_SET;
         public static final String TXDIR_LGX_NOT_SET;
@@ -43,19 +44,19 @@ public final class ServicehandlerTxRxCheck {
         }
 
         public static String endpointTypeNotSet(ServiceEndpointType endpointType) {
-            return "Service " + endpointType + " is not set";
+            return SERVICE + endpointType + " is not set";
         }
 
         public static String rateNotSet(ServiceEndpointType endpointType) {
-            return "Service " + endpointType + " rate is not set";
+            return SERVICE + endpointType + " rate is not set";
         }
 
         public static String formatNotSet(ServiceEndpointType endpointType) {
-            return "Service " + endpointType + " format is not set";
+            return SERVICE + endpointType + " format is not set";
         }
 
         public static String clliNotSet(ServiceEndpointType endpointType) {
-            return "Service " + endpointType + " clli is not set";
+            return SERVICE + endpointType + " clli is not set";
         }
 
         private LogMessages() {
@@ -71,7 +72,7 @@ public final class ServicehandlerTxRxCheck {
      * @return true if String ok false if not
      */
     public static boolean checkString(String value) {
-        return ((value != null) && (value.compareTo("") != 0));
+        return (value != null && !value.isEmpty());
     }
 
     /**
@@ -81,6 +82,9 @@ public final class ServicehandlerTxRxCheck {
      *            port info
      * @return true if String ok false if not
      */
+    @SuppressWarnings("java:S1067")
+    //sonar issue Reduce the number of conditional operators (4) used in the expression (maximum allowed 3)
+    //won't be fixed because of functional checks needed
     public static boolean checkPort(Port port) {
         boolean result = false;
         if (port != null) {
@@ -90,10 +94,11 @@ public final class ServicehandlerTxRxCheck {
             String portRack = port.getPortRack();
             String portShelf = port.getPortShelf();
 
-            if (checkString(portDeviceName) && checkString(portType) && checkString(portName) && checkString(portRack)
-                    && checkString(portShelf)) {
-                result = true;
-            }
+            return checkString(portDeviceName)
+                    && checkString(portType)
+                    && checkString(portName)
+                    && checkString(portRack)
+                    && checkString(portShelf);
         }
         return result;
     }
@@ -164,18 +169,14 @@ public final class ServicehandlerTxRxCheck {
             return new ComplianceCheckResult(false, LogMessages.endpointTypeNotSet(endpointType));
         }
 
-//TODO check if an expected bug was justifying this NPE handling
-//        try {
+        if (serviceEnd.getServiceRate() == null) {
+            String message = "Something wrong when accessing Service " + endpointType + " rate, format or clli";
+            return new ComplianceCheckResult(false, message);
+        }
         Long serviceRate = serviceEnd.getServiceRate().toJava();
         ServiceFormat serviceformat = serviceEnd.getServiceFormat();
         String clli = serviceEnd.getClli();
-//        } catch (NullPointerException e) {
-//            String message = "Something wrong when accessing Service " + endpointType + " rate, format or clli";
-//            LOG.error("Service TxRx info check: {}",message, e);
-//            return new ComplianceCheckResult(false, message);
-//        }
-
-        if ((serviceRate == null) || (serviceRate <= 0)) {
+        if (serviceRate <= 0) {
             return new ComplianceCheckResult(false, LogMessages.rateNotSet(endpointType));
         }
         if (serviceformat == null) {