From a07392226a2e30930323959a5f6925812f5192ae Mon Sep 17 00:00:00 2001 From: manuedelf Date: Fri, 9 Oct 2020 15:30:06 +0200 Subject: [PATCH] Technical debt - Service handler Sonar issues JIRA: TRNSPRTPCE-214 Change-Id: Ibdae3184f6f261e371db8d12e4719b105ca61705 Signed-off-by: manuedelf --- .../servicehandler/MappingConstraints.java | 195 ++++++++------- .../servicehandler/ModelMappingUtils.java | 12 +- .../impl/ServicehandlerImpl.java | 66 +++--- .../listeners/PceListenerImpl.java | 186 ++++++++------- .../listeners/RendererListenerImpl.java | 139 ++++++----- .../service/PCEServiceWrapper.java | 222 ++++++++++-------- .../service/RendererServiceWrapper.java | 80 ++++--- .../ServiceDataStoreOperationsImpl.java | 16 +- .../checks/ServicehandlerTxRxCheck.java | 37 +-- 9 files changed, 522 insertions(+), 431 deletions(-) diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/MappingConstraints.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/MappingConstraints.java index ed9c0210f..4dc53d7ec 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/MappingConstraints.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/MappingConstraints.java @@ -87,92 +87,10 @@ public class MappingConstraints { * @return ConstraintsSp HardConstraintsSp or HardConstraintsSp */ private 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 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 + * @param input T + * @param hardConstraintsBuilder HardConstraintsBuilder + * @param softConstraintsBuilder SoftConstraintsBuilder + */ + private 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 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. diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java index 541fe8cc7..124eed52a 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java @@ -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()) diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java index 834c8a62f..fa3beb8a7 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java @@ -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 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 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 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 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); diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java index 89b5b8ed9..65e199b4f 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java @@ -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 !"); } } diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java index 533d23dc0..0669f842c 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java @@ -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") diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapper.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapper.java index e2c8fdc1e..98cccf641 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapper.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapper.java @@ -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 pceCallback = new FutureCallback() { - 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 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 pceCallback = new FutureCallback() { - - 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 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 { + 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 { + 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); + } + } + } } diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java index 0bf493638..6fec7dc56 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java @@ -90,42 +90,8 @@ public class RendererServiceWrapper { .setStatus(RpcStatusEx.Pending) .setStatusMessage("Service compliant, submitting temp service delete Request ...").build(); sendNotifications(notification); - FutureCallback rendererCallback = new FutureCallback() { - - 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 rendererCallback = + new ServiceDeleteOutputFutureCallback(notifType, serviceName); ServiceDeleteInput serviceDeleteInput = createRendererRequestInput(serviceName, serviceHandlerHeader); ListenableFuture 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 { + 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); + } + } } diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImpl.java index bd590e607..96ef8cbff 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImpl.java @@ -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 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