X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=servicehandler%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fservicehandler%2Fimpl%2FServicehandlerImpl.java;h=fa3beb8a7a5b7d040402b8eddfa2185e9760e8ee;hb=a07392226a2e30930323959a5f6925812f5192ae;hp=44ef53a17c0fc6b1e62c71be6994dac6bde24205;hpb=abbca95c8944ec742d71bd87d2363c9c00c41844;p=transportpce.git 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 44ef53a17..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 @@ -8,71 +8,81 @@ package org.opendaylight.transportpce.servicehandler.impl; import com.google.common.util.concurrent.ListenableFuture; - import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Optional; -import java.util.concurrent.ExecutionException; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.pce.service.PathComputationService; +import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.DowngradeConstraints; import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; import org.opendaylight.transportpce.servicehandler.ServiceInput; +import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl; +import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl; import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; +import org.opendaylight.transportpce.servicehandler.service.RendererServiceWrapper; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl; import org.opendaylight.transportpce.servicehandler.validation.ServiceCreateValidation; import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult; -import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerCompliancyCheck; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.NetworkReOptimizationInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.NetworkReOptimizationOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.OrgOpenroadmServiceService; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReversionInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReversionOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRollInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRollOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input.ServiceAEndBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input.ServiceZEndBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfo.TailRetention; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services; +import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerComplianceCheck; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.RpcActions; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.sdnc.request.header.SdncRequestHeaderBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev190531.RpcStatus; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.EquipmentNotificationInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.EquipmentNotificationOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.NetworkReOptimizationInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.NetworkReOptimizationOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateComplexResultNotificationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateComplexResultNotificationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateResultNotificationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateResultNotificationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteComplexResultNotificationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteComplexResultNotificationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteResultNotificationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteResultNotificationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckBulkInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckBulkOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteConfirmInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteConfirmOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReversionInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReversionOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRollInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRollOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.delete.input.ServiceDeleteReqInfo.TailRetention; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.delete.input.ServiceDeleteReqInfoBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,185 +91,315 @@ 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; - private RendererServiceOperations rendererServiceOperations; private PCEServiceWrapper pceServiceWrapper; + private RendererServiceWrapper rendererServiceWrapper; + private PceListenerImpl pceListenerImpl; + private RendererListenerImpl rendererListenerImpl; //TODO: remove private request fields as they are in global scope public ServicehandlerImpl(DataBroker databroker, PathComputationService pathComputationService, - RendererServiceOperations rendererServiceOperations) { + RendererServiceOperations rendererServiceOperations, NotificationPublishService notificationPublishService, + PceListenerImpl pceListenerImpl, RendererListenerImpl rendererListenerImpl, + NetworkModelWavelengthService networkModelWavelengthService) { this.db = databroker; - this.rendererServiceOperations = rendererServiceOperations; this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.db); this.serviceDataStoreOperations.initialize(); - this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService); + this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService); + this.rendererServiceWrapper = new RendererServiceWrapper(rendererServiceOperations, notificationPublishService); + this.pceListenerImpl = pceListenerImpl; + this.rendererListenerImpl = rendererListenerImpl; + } + + + // This is class is public so that these messages can be accessed from Junit (avoid duplications). + public static final class LogMessages { + + public static final String PCE_CALLING; + public static final String ABORT_PCE_FAILED; + public static final String PCE_FAILED; + public static final String ABORT_SERVICE_NON_COMPLIANT; + public static final String SERVICE_NON_COMPLIANT; + public static final String RENDERER_DELETE_FAILED; + public static final String ABORT_VALID_FAILED; + + // Static blocks are generated once and spare memory. + static { + PCE_CALLING = "Calling PCE"; + ABORT_PCE_FAILED = "Aborting: PCE calculation failed "; + PCE_FAILED = "PCE calculation failed"; + ABORT_SERVICE_NON_COMPLIANT = "Aborting: non-compliant service "; + SERVICE_NON_COMPLIANT = "non-compliant service"; + RENDERER_DELETE_FAILED = "Renderer service delete failed"; + ABORT_VALID_FAILED = "Aborting: validation of service create request failed"; + } + + public static String serviceNotInDS(String serviceName) { + return "Service '" + serviceName + "' does not exist in datastore"; + } + + public static String serviceInService(String serviceName) { + return "Service '" + serviceName + "' is in 'inService' state"; + } + + private LogMessages() { + } } @Override public ListenableFuture> serviceCreate(ServiceCreateInput input) { - LOG.info("RPC service creation received"); + LOG.info("RPC serviceCreate received"); // Validation OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest( new ServiceInput(input), RpcActions.ServiceCreate); if (! validationResult.isSuccess()) { - LOG.warn("Aborting service create because validation of service create request failed: {}", - validationResult.getResultMessage()); - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, + LOG.warn(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.info("Commencing PCE"); - //TODO: createService service status into datastore - PathComputationRequestOutput pceResponse = this.pceServiceWrapper.performPCE(input, true); - String pceResponseCode = pceResponse.getConfigurationResponseCommon().getResponseCode(); - if (!ResponseCodes.RESPONSE_OK.equals(pceResponseCode)) { - LOG.info("PCE calculation failed {}", pceResponseCode); + this.pceListenerImpl.setInput(new ServiceInput(input)); + this.pceListenerImpl.setServiceReconfigure(false); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations); + this.rendererListenerImpl.setServiceInput(new ServiceInput(input)); + LOG.debug(SERVICE_CREATE_MSG, LogMessages.PCE_CALLING); + PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true); + if (output == null) { + LOG.warn(SERVICE_CREATE_MSG, LogMessages.ABORT_PCE_FAILED); return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, - pceResponse.getConfigurationResponseCommon().getResponseMessage(), ResponseCodes.RESPONSE_FAILED); - } - - LOG.info("PCE calculation done OK {}", pceResponseCode); - - OperationResult operationResult = this.serviceDataStoreOperations.createService(input, pceResponse); - if (!operationResult.isSuccess()) { - String message = "Service status not updated in datastore !"; - LOG.info(message); - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_FAILED); - } - - OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations.createServicePath( - new ServiceInput(input), pceResponse); - if (!operationServicePathSaveResult.isSuccess()) { - String message = "Service Path not updated in datastore !"; - LOG.info(message); - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_FAILED); - } - - ServiceImplementationRequestInput serviceImplementationRequest = - ModelMappingUtils.createServiceImplementationRequest(new ServiceInput(input), pceResponse); - ServiceImplementationRequestOutput serviceImplementationRequestOutput = this.rendererServiceOperations - .serviceImplementation(serviceImplementationRequest); - if (ResponseCodes.RESPONSE_OK - .equals(serviceImplementationRequestOutput.getConfigurationResponseCommon().getResponseCode())) { - String message = "Service rendered successfully !"; - LOG.info(message); - operationResult = this.serviceDataStoreOperations.modifyService(input.getServiceName(), State.InService, - State.InService); - if (!operationResult.isSuccess()) { - LOG.warn("Service status not updated in datastore !"); - } - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_OK); - } else { - String message = "Service rendering has failed !"; - LOG.warn(message); - - OperationResult deleteServicePathOperationResult = - this.serviceDataStoreOperations.deleteServicePath(input.getServiceName()); - if (!deleteServicePathOperationResult.isSuccess()) { - LOG.warn("Service path was not removed from datastore!"); - } - - OperationResult deleteServiceOperationResult = - this.serviceDataStoreOperations.deleteService(input.getServiceName()); - if (!deleteServiceOperationResult.isSuccess()) { - LOG.warn("Service was not removed from datastore!"); - } - - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_FAILED); + LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED); } + LOG.info("RPC serviceCreate in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createCreateServiceReply( + input, common.getAckFinalIndicator(), + common.getResponseMessage(), common.getResponseCode()); } @Override public ListenableFuture> serviceDelete(ServiceDeleteInput input) { - LOG.info("RPC serviceDelete request received for {}", input.getServiceDeleteReqInfo().getServiceName()); - String message = ""; + String serviceName = input.getServiceDeleteReqInfo().getServiceName(); + LOG.info("RPC serviceDelete request received for {}", serviceName); /* * Upon receipt of service-deleteService RPC, service header and sdnc-request - * header compliancy are verified. + * header compliance are verified. */ - LOG.info("checking Service Compliancy ..."); - ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerCompliancyCheck.check( + ComplianceCheckResult serviceHandlerCheckResult = + ServicehandlerComplianceCheck.check( input.getServiceDeleteReqInfo().getServiceName(), input.getSdncRequestHeader(), null, RpcActions.ServiceDelete, false, true); - if (serviceHandlerCheckResult.hasPassed()) { - LOG.info("Service compliant !"); - } else { - LOG.info("Service is not compliant !"); - return ModelMappingUtils - .createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - "Service not compliant !", ResponseCodes.RESPONSE_FAILED); + if (!serviceHandlerCheckResult.hasPassed()) { + 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 - String serviceName = input.getServiceDeleteReqInfo().getServiceName(); - LOG.info("serviceName : {}", serviceName); - try { - Optional service = this.serviceDataStoreOperations.getService(serviceName); - if (!service.isPresent()) { - message = "Service '" + serviceName + "' does not exist in datastore"; - LOG.error(message); - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - message, ResponseCodes.RESPONSE_FAILED); - } - } catch (NullPointerException e) { - LOG.info("failed to get service '{}' from datastore : ", serviceName, e); - } - - LOG.debug("Service '{}' present in datastore !", serviceName); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput( - new ServiceInput(input)); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteOutput output = this.rendererServiceOperations.serviceDelete(serviceDeleteInput); - - if (!ResponseCodes.RESPONSE_OK - .equals(output.getConfigurationResponseCommon().getResponseCode())) { - message = "Service delete failed!"; - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_FAILED); + Optional serviceOpt = this.serviceDataStoreOperations.getService(serviceName); + Services service; + if (!serviceOpt.isPresent()) { + LOG.warn(SERVICE_DELETE_MSG, LogMessages.serviceNotInDS(serviceName)); + return ModelMappingUtils.createDeleteServiceReply( + input, ResponseCodes.FINAL_ACK_YES, + LogMessages.serviceNotInDS(serviceName), ResponseCodes.RESPONSE_FAILED); } - - OperationResult deleteServicePathOperationResult = - this.serviceDataStoreOperations.deleteServicePath(input.getServiceDeleteReqInfo().getServiceName()); - if (!deleteServicePathOperationResult.isSuccess()) { - LOG.warn("Service path was not removed from datastore!"); - } - - OperationResult deleteServiceOperationResult = - this.serviceDataStoreOperations.deleteService(input.getServiceDeleteReqInfo().getServiceName()); - if (!deleteServiceOperationResult.isSuccess()) { - LOG.warn("Service was not removed from datastore!"); + service = serviceOpt.get(); + LOG.debug("serviceDelete: Service '{}' found in datastore", serviceName); + this.pceListenerImpl.setInput(new ServiceInput(input)); + this.pceListenerImpl.setServiceReconfigure(false); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations); + this.rendererListenerImpl.setServiceInput(new ServiceInput(input)); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520 + .ServiceDeleteInput serviceDeleteInput = + ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteOutput output = + this.rendererServiceWrapper.performRenderer( + serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, service); + + if (output == null) { + LOG.error(SERVICE_DELETE_MSG, LogMessages.RENDERER_DELETE_FAILED); + return ModelMappingUtils.createDeleteServiceReply( + input, ResponseCodes.FINAL_ACK_YES, + LogMessages.RENDERER_DELETE_FAILED, ResponseCodes.RESPONSE_FAILED); } - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - "Service delete was successful!", ResponseCodes.RESPONSE_OK); + LOG.debug("RPC serviceDelete in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createDeleteServiceReply( + input, common.getAckFinalIndicator(), + common.getResponseMessage(), common.getResponseCode()); } @Override public ListenableFuture> serviceFeasibilityCheck( ServiceFeasibilityCheckInput input) { - throw new UnsupportedOperationException("Not implemented yet"); + LOG.info("RPC serviceFeasibilityCheck received"); + // Validation + ServiceInput serviceInput = new ServiceInput(input); + OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(serviceInput, + RpcActions.ServiceFeasibilityCheck); + if (! validationResult.isSuccess()) { + LOG.warn(SERVICE_FEASABILITY_CHECK_MSG, LogMessages.ABORT_VALID_FAILED); + return ModelMappingUtils.createCreateServiceReply( + input, ResponseCodes.FINAL_ACK_YES, + validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED); + } + this.pceListenerImpl.setInput(new ServiceInput(input)); + this.pceListenerImpl.setServiceReconfigure(false); + this.pceListenerImpl.setServiceFeasiblity(true); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations); + this.rendererListenerImpl.setServiceInput(new ServiceInput(input)); + LOG.debug(SERVICE_FEASABILITY_CHECK_MSG, LogMessages.PCE_CALLING); + PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true); + if (output == null) { + LOG.warn(SERVICE_FEASABILITY_CHECK_MSG, LogMessages.ABORT_PCE_FAILED); + return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, + LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED); + } + LOG.info("RPC serviceFeasibilityCheck in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createCreateServiceReply( + input, common.getAckFinalIndicator(), + common.getResponseMessage(), common.getResponseCode()); } @Override public ListenableFuture> serviceReconfigure(ServiceReconfigureInput input) { - throw new UnsupportedOperationException("Not implemented yet"); + String serviceName = input.getServiceName(); + LOG.info("RPC serviceReconfigure received for {}", serviceName); + Optional servicesObject = this.serviceDataStoreOperations.getService(serviceName); + if (!servicesObject.isPresent()) { + LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.serviceNotInDS(serviceName)); + return ModelMappingUtils.createCreateServiceReply( + input, + LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed); + } + LOG.debug("Service '{}' found in datastore", serviceName); + OperationResult validationResult = ServiceCreateValidation + .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceReconfigure); + if (!validationResult.isSuccess()) { + LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.ABORT_VALID_FAILED); + return ModelMappingUtils.createCreateServiceReply( + input, + validationResult.getResultMessage(), RpcStatus.Failed); + } + this.pceListenerImpl.setInput(new ServiceInput(input)); + this.pceListenerImpl.setServiceReconfigure(true); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations); + this.rendererListenerImpl.setServiceInput(new ServiceInput(input)); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520 + .ServiceDeleteInput serviceDeleteInput = + ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520 + .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput, + ServiceNotificationTypes.ServiceDeleteResult, null); + if (output == null) { + LOG.error(SERVICE_RECONFIGURE_MSG, LogMessages.RENDERER_DELETE_FAILED); + return ModelMappingUtils.createCreateServiceReply( + input, + LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Successful); + //TODO check if RpcStatus.Successful is really expected here + } + LOG.info("RPC serviceReconfigure in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createCreateServiceReply( + input, + common.getResponseMessage(), RpcStatus.Successful); } @Override public ListenableFuture> serviceRestoration(ServiceRestorationInput input) { - throw new UnsupportedOperationException("Not implemented yet"); + String serviceName = input.getServiceName(); + LOG.info("RPC serviceRestoration received for {}", serviceName); + Optional servicesObject = this.serviceDataStoreOperations.getService(serviceName); + + if (!servicesObject.isPresent()) { + LOG.warn(SERVICE_RESTORATION_MSG, LogMessages.serviceNotInDS(serviceName)); + return ModelMappingUtils.createRestoreServiceReply( + LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed); + } + + Services service = servicesObject.get(); + State state = service.getOperationalState(); + + if (state == State.InService) { + LOG.error(SERVICE_RESTORATION_MSG, LogMessages.serviceInService(serviceName)); + return ModelMappingUtils.createRestoreServiceReply( + LogMessages.serviceInService(serviceName), RpcStatus.Failed); + } + + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder() + .setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl()) + .setRequestId(service.getSdncRequestHeader().getRequestId()) + .setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId()) + .setRpcAction(RpcActions.ServiceDelete); + ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder() + .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder() + .setServiceName(serviceName) + .setDueDate(datetime) + .setTailRetention(TailRetention.No).build()) + .setSdncRequestHeader(sdncBuilder.build()); + ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build()); + serviceInput.setServiceAEnd(service.getServiceAEnd()); + serviceInput.setServiceZEnd(service.getServiceZEnd()); + serviceInput.setConnectionType(service.getConnectionType()); + HardConstraints hardConstraints = service.getHardConstraints(); + if (hardConstraints == null) { + LOG.warn("service '{}' HardConstraints is not set !", serviceName); + } else { + SoftConstraints softConstraints = service.getSoftConstraints(); + if (softConstraints == null) { + LOG.warn("service '{}' SoftConstraints is not set !", serviceName); + serviceInput.setSoftConstraints(DowngradeConstraints.convertToSoftConstraints(hardConstraints)); + serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints)); + } else { + LOG.info("converting hard constraints to soft constraints ..."); + serviceInput.setSoftConstraints( + DowngradeConstraints.updateSoftConstraints(hardConstraints, softConstraints)); + serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints)); + } + } + this.pceListenerImpl.setInput(serviceInput); + this.pceListenerImpl.setServiceReconfigure(true); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setServiceInput(serviceInput); + this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520 + .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput( + new ServiceInput(deleteInputBldr.build())); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520 + .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput, + ServiceNotificationTypes.ServiceDeleteResult, null); + if (output == null) { + LOG.error(SERVICE_RESTORATION_MSG, LogMessages.RENDERER_DELETE_FAILED); + return ModelMappingUtils.createRestoreServiceReply( + LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Failed); + } + LOG.info("RPC serviceRestore in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createRestoreServiceReply( + common.getResponseMessage(), RpcStatus.Successful); + } @Override @@ -278,72 +418,55 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { @Override public ListenableFuture> serviceReroute(ServiceRerouteInput input) { - LOG.info("RPC service reroute received"); - String message = ""; - try { - Optional servicesObject = this.serviceDataStoreOperations.getService(input.getServiceName()); - if (servicesObject.isPresent()) { - ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder(); - DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); - OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); - DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); - deleteInputBldr.setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder() - .setServiceName(input.getServiceName()).setDueDate(datetime) - .setTailRetention(TailRetention.No).build()); - SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder(); - sdncBuilder.setNotificationUrl(servicesObject.get().getSdncRequestHeader().getNotificationUrl()); - sdncBuilder.setRequestId(servicesObject.get().getSdncRequestHeader().getRequestId()); - sdncBuilder.setRequestSystemId(servicesObject.get().getSdncRequestHeader().getRequestSystemId()); - sdncBuilder.setRpcAction(RpcActions.ServiceDelete); - deleteInputBldr.setSdncRequestHeader(sdncBuilder.build()); - // Calling delete service - ServiceDeleteOutput serviceDeleteOutput = serviceDelete(deleteInputBldr.build()).get().getResult(); - // Calling create request now - if (!ResponseCodes.RESPONSE_OK - .equals(serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode())) { - message = "Service delete failed!"; - return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - message, RpcStatus.Failed); - } - ServiceCreateInputBuilder serviceCreateBldr = new ServiceCreateInputBuilder(); - serviceCreateBldr.setServiceName(input.getServiceName() + 2); - serviceCreateBldr.setCommonId(servicesObject.get().getCommonId()); - serviceCreateBldr.setConnectionType(servicesObject.get().getConnectionType()); - serviceCreateBldr.setCustomer(servicesObject.get().getCustomer()); - serviceCreateBldr.setCustomerContact(servicesObject.get().getCustomerContact()); - serviceCreateBldr.setDueDate(servicesObject.get().getDueDate()); - serviceCreateBldr.setEndDate(servicesObject.get().getEndDate()); - serviceCreateBldr.setHardConstraints(servicesObject.get().getHardConstraints()); - serviceCreateBldr.setNcCode(servicesObject.get().getNcCode()); - serviceCreateBldr.setNciCode(servicesObject.get().getNciCode()); - serviceCreateBldr.setOperatorContact(servicesObject.get().getOperatorContact()); - serviceCreateBldr.setSdncRequestHeader(servicesObject.get().getSdncRequestHeader()); - serviceCreateBldr.setSecondaryNciCode(servicesObject.get().getSecondaryNciCode()); - ServiceAEndBuilder serviceAendBuilder = new ServiceAEndBuilder(servicesObject.get().getServiceAEnd()); - serviceCreateBldr.setServiceAEnd(serviceAendBuilder.build()); - ServiceZEndBuilder serviceZendBuilder = new ServiceZEndBuilder(servicesObject.get().getServiceZEnd()); - serviceCreateBldr.setServiceZEnd(serviceZendBuilder.build()); - serviceCreateBldr.setSoftConstraints(servicesObject.get().getSoftConstraints()); - ServiceCreateOutput serviceCreateOutput = serviceCreate(serviceCreateBldr.build()).get().getResult(); - if (!ResponseCodes.RESPONSE_OK - .equals(serviceCreateOutput.getConfigurationResponseCommon().getResponseCode())) { - message = "Service create failed!"; - return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - message, RpcStatus.Failed); - } - message = "Service reroute successfully !"; - return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - message, RpcStatus.Successful); - } else { - LOG.error("Service '{}' is not present", input.getServiceName()); - message = "Service '" + input.getServiceName() + "' is not present"; - } - } catch (InterruptedException | ExecutionException e) { - LOG.info("Exception caught" , e); + String serviceName = input.getServiceName(); + LOG.info("RPC serviceReroute received for {}", serviceName); + Optional servicesObject = this.serviceDataStoreOperations.getService(serviceName); + if (!servicesObject.isPresent()) { + LOG.warn("serviceReroute: {}", LogMessages.serviceNotInDS(serviceName)); + return ModelMappingUtils.createRerouteServiceReply( + input, ResponseCodes.FINAL_ACK_NO, + LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed); } - ServiceRerouteOutputBuilder output = new ServiceRerouteOutputBuilder() - .setHardConstraints(null).setSoftConstraints(null).setStatus(RpcStatus.Failed).setStatusMessage(message); - return RpcResultBuilder.success(output).buildFuture(); + Services service = servicesObject.get(); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder() + .setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl()) + .setRequestId(service.getSdncRequestHeader().getRequestId()) + .setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId()) + .setRpcAction(RpcActions.ServiceDelete); + ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder() + .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder() + .setServiceName(serviceName).setDueDate(datetime) + .setTailRetention(TailRetention.No).build()) + .setSdncRequestHeader(sdncBuilder.build()); + ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build()); + serviceInput.setServiceAEnd(service.getServiceAEnd()); + serviceInput.setServiceZEnd(service.getServiceZEnd()); + serviceInput.setConnectionType(service.getConnectionType()); + this.pceListenerImpl.setInput(serviceInput); + this.pceListenerImpl.setServiceReconfigure(true); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setServiceInput(serviceInput); + this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520 + .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput( + new ServiceInput(deleteInputBldr.build())); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520 + .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput, + ServiceNotificationTypes.ServiceDeleteResult, null); + if (output == null) { + LOG.error("serviceReroute: {}", LogMessages.RENDERER_DELETE_FAILED); + return ModelMappingUtils.createRerouteServiceReply( + input, ResponseCodes.FINAL_ACK_YES, + LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Failed); + } + LOG.info("RPC ServiceReroute in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createRerouteServiceReply( + input, common.getAckFinalIndicator(), + common.getResponseMessage(), RpcStatus.Successful); } @Override @@ -367,147 +490,131 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { @Override public ListenableFuture> tempServiceDelete(TempServiceDeleteInput input) { - LOG.info("RPC temp serviceDelete request received for {}", input.getCommonId()); - String message = ""; + String commonId = input.getCommonId(); + LOG.info("RPC temp serviceDelete request received for {}", commonId); /* * Upon receipt of service-deleteService RPC, service header and sdnc-request * header compliancy are verified. */ - LOG.info("checking Service Compliancy ..."); - ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerCompliancyCheck.check(input.getCommonId(), - null, null, RpcActions.ServiceDelete, false, false); - if (serviceHandlerCheckResult.hasPassed()) { - LOG.info("Service compliant !"); - } else { - LOG.info("Service is not compliant !"); - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - "Service not compliant !", ResponseCodes.RESPONSE_FAILED); + LOG.debug("checking Service Compliance ..."); + ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.check( + commonId, null, null, RpcActions.ServiceDelete, false, false + ); + if (!serviceHandlerCheckResult.hasPassed()) { + 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); } //Check presence of service to be deleted - String commonId = input.getCommonId(); - LOG.info("service common-id : {}", commonId); - try { - Optional service = this.serviceDataStoreOperations.getTempService(commonId); - if (!service.isPresent()) { - message = "Service '" + commonId + "' does not exist in datastore"; - LOG.error(message); - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - message, ResponseCodes.RESPONSE_FAILED); - } - } catch (NullPointerException e) { - LOG.info("failed to get service '{}' from datastore : ", commonId, e); - } - - LOG.debug("Service '{}' present in datastore !", commonId); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput( - new ServiceInput(input)); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteOutput output = this.rendererServiceOperations.serviceDelete(serviceDeleteInput); - - if (!ResponseCodes.RESPONSE_OK - .equals(output.getConfigurationResponseCommon().getResponseCode())) { - message = "Service delete failed!"; - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_FAILED); - } - - OperationResult deleteServicePathOperationResult = - this.serviceDataStoreOperations.deleteServicePath(input.getCommonId()); - if (!deleteServicePathOperationResult.isSuccess()) { - LOG.warn("Service path was not removed from datastore!"); + LOG.debug("service common-id '{}' is compliant", commonId); + Optional + service = + this.serviceDataStoreOperations.getTempService(commonId); + if (!service.isPresent()) { + LOG.error(TEMP_SERVICE_DELETE_MSG, LogMessages.serviceNotInDS(commonId)); + return ModelMappingUtils.createDeleteServiceReply( + input, ResponseCodes.FINAL_ACK_YES, + LogMessages.serviceNotInDS(commonId), ResponseCodes.RESPONSE_FAILED); } - OperationResult deleteServiceOperationResult = - this.serviceDataStoreOperations.deleteTempService(input.getCommonId()); - if (!deleteServiceOperationResult.isSuccess()) { - LOG.warn("Service was not removed from datastore!"); + LOG.info("Service '{}' present in datastore !", commonId); + this.pceListenerImpl.setInput(new ServiceInput(input)); + this.pceListenerImpl.setServiceReconfigure(false); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setServiceInput(new ServiceInput(input)); + this.rendererListenerImpl.setTempService(true); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteOutput output = + this.rendererServiceWrapper.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult); + if (output == null) { + 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); } - - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - "Service delete was successful!", ResponseCodes.RESPONSE_OK); + LOG.info("RPC tempServiceDelete in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createDeleteServiceReply( + input, common.getAckFinalIndicator(), + common.getResponseMessage(), common.getResponseCode()); } @Override public ListenableFuture> tempServiceCreate(TempServiceCreateInput input) { - LOG.info("RPC temp service creation received"); + LOG.info("RPC tempServiceCreate received"); // Validation OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest( new ServiceInput(input), RpcActions.TempServiceCreate); if (! validationResult.isSuccess()) { - LOG.warn("Aborting service create because validation of service create request failed: {}", - validationResult.getResultMessage()); - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, + 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.info("Commencing PCE"); - //TODO: createService service status into datastore - PathComputationRequestOutput pceResponse = this.pceServiceWrapper.performPCE(input, true); - String pceResponseCode = pceResponse.getConfigurationResponseCommon().getResponseCode(); - if (!ResponseCodes.RESPONSE_OK.equals(pceResponseCode)) { - LOG.info("PCE calculation failed {}", pceResponseCode); - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, - pceResponse.getConfigurationResponseCommon().getResponseMessage(), ResponseCodes.RESPONSE_FAILED); - } - - LOG.info("PCE calculation done OK {}", pceResponseCode); - - OperationResult operationResult = this.serviceDataStoreOperations.createTempService(input, pceResponse); - if (!operationResult.isSuccess()) { - String message = "Service status not updated in datastore !"; - LOG.info(message); - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_FAILED); + LOG.debug(TEMP_SERVICE_CREATE_MSG, LogMessages.PCE_CALLING); + this.pceListenerImpl.setInput(new ServiceInput(input)); + this.pceListenerImpl.setServiceReconfigure(false); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.pceListenerImpl.setTempService(true); + this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations); + this.rendererListenerImpl.setServiceInput(new ServiceInput(input)); + this.rendererListenerImpl.setTempService(true); + PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true); + if (output == null) { + LOG.warn(TEMP_SERVICE_CREATE_MSG, LogMessages.ABORT_PCE_FAILED); + return ModelMappingUtils.createCreateServiceReply( + input, ResponseCodes.FINAL_ACK_YES, + LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED); } + LOG.info("RPC tempServiceCreate in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createCreateServiceReply( + input, common.getAckFinalIndicator(), + common.getResponseMessage(), common.getResponseCode()); + } - OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations.createServicePath( - new ServiceInput(input), pceResponse); - if (!operationServicePathSaveResult.isSuccess()) { - String message = "Service Path not updated in datastore !"; - LOG.info(message); - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_FAILED); - } + @Override + public ListenableFuture> serviceDeleteComplexResultNotificationRequest( + ServiceDeleteComplexResultNotificationRequestInput input) { + // TODO Auto-generated method stub + return null; + } - ServiceImplementationRequestInput serviceImplementationRequest = - ModelMappingUtils.createServiceImplementationRequest(new ServiceInput(input), pceResponse); - ServiceImplementationRequestOutput serviceImplementationRequestOutput = this.rendererServiceOperations - .serviceImplementation(serviceImplementationRequest); - if (ResponseCodes.RESPONSE_OK - .equals(serviceImplementationRequestOutput.getConfigurationResponseCommon().getResponseCode())) { - String message = "Service rendered successfully !"; - LOG.info(message); - operationResult = this.serviceDataStoreOperations.modifyTempService(input.getCommonId(), State.InService, - State.InService); - if (!operationResult.isSuccess()) { - LOG.warn("Service status not updated in datastore !"); - } - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_OK); - } else { - String message = "Service rendering has failed !"; - LOG.warn(message); + @Override + public ListenableFuture> serviceCreateResultNotificationRequest( + ServiceCreateResultNotificationRequestInput input) { + // TODO Auto-generated method stub + return null; + } - OperationResult deleteServicePathOperationResult = - this.serviceDataStoreOperations.deleteServicePath(input.getCommonId()); - if (!deleteServicePathOperationResult.isSuccess()) { - LOG.warn("Service path was not removed from datastore!"); - } + @Override + public ListenableFuture> serviceDeleteResultNotificationRequest( + ServiceDeleteResultNotificationRequestInput input) { + // TODO Auto-generated method stub + return null; + } - OperationResult deleteServiceOperationResult = - this.serviceDataStoreOperations.deleteService(input.getCommonId()); - if (!deleteServiceOperationResult.isSuccess()) { - LOG.warn("Service was not removed from datastore!"); - } + @Override + public ListenableFuture> serviceCreateComplexResultNotificationRequest( + ServiceCreateComplexResultNotificationRequestInput input) { + // TODO Auto-generated method stub + return null; + } - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_FAILED); - } + @Override + public ListenableFuture> serviceFeasibilityCheckBulk( + ServiceFeasibilityCheckBulkInput input) { + // TODO Auto-generated method stub + return null; } }