From c3212dea41910175d12de2732d36d0b6943beb2d Mon Sep 17 00:00:00 2001 From: Martial COULIBALY Date: Mon, 26 Nov 2018 17:19:10 +0100 Subject: [PATCH] Service-notification handling for serviceHandler - Modify RPC serviceCreate / serviceDelete/ serviceReroute to add support for notifcation - Add / Modify PCEListenerImpl and RendererListener class to execute tasks after received notifications - Modify SH provider to add notifcations listeners for PCE and Renderer - Add / Modify Junit Tests JIRA: TRNSPRTPCE-50 JIRA: TRNSPRTPCE-71 Change-Id: I3000c7c7ed935dc51c7b68da5581b74445287024 Signed-off-by: Martial COULIBALY --- .../transportpce/common/ResponseCodes.java | 1 + .../servicehandler/ModelMappingUtils.java | 10 +- .../servicehandler/ServiceInput.java | 54 +- .../impl/ServicehandlerImpl.java | 395 +++++--------- .../impl/ServicehandlerProvider.java | 22 +- .../listeners/PceListenerImpl.java | 164 +++++- .../listeners/RendererListenerImpl.java | 153 ++++++ .../service/PCEServiceWrapper.java | 263 ++++++++-- .../service/RendererServiceWrapper.java | 172 ++++++ .../service/ServiceDataStoreOperations.java | 17 +- .../ServiceDataStoreOperationsImpl.java | 9 +- .../stub/StubPceServiceOperations.java | 210 ++++++++ .../stub/StubRendererServiceOperations.java | 214 +++++++- .../servicehandler/stub/StubrendererImpl.java | 179 ------- .../blueprint/servicehandler-blueprint.xml | 5 + .../servicehandler/ModelMappingUtilsTest.java | 2 +- .../impl/ServiceHandlerImplTest.java | 496 +++--------------- .../listeners/PceListenerImplTest.java | 314 +++++++++++ .../listeners/RendererListenerImplTest.java | 242 +++++++++ .../listensers/PceListenserImplTest.java | 81 --- .../service/PCEServiceWrapperTest.java | 170 ++++-- .../service/RendererServiceWrapperTest.java | 159 ++++++ .../ServiceDataStoreOperationsImplTest.java | 29 +- .../servicehandler/utils/InjectField.java | 33 ++ .../MockedNotificationServiceWrapper.java | 62 +++ .../utils/ModelMappingUtils.java | 353 +++++++++++++ .../utils/ServiceDataUtils.java | 124 ++++- .../transportpce/test/AbstractTest.java | 10 + tests/SH_stubs.diff | 48 +- .../transportpce_tests/test_servicehandler.py | 18 +- 30 files changed, 2854 insertions(+), 1155 deletions(-) create mode 100644 servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java create mode 100644 servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java create mode 100644 servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubPceServiceOperations.java delete mode 100644 servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImplTest.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImplTest.java delete mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listensers/PceListenserImplTest.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/InjectField.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/MockedNotificationServiceWrapper.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ModelMappingUtils.java diff --git a/common/src/main/java/org/opendaylight/transportpce/common/ResponseCodes.java b/common/src/main/java/org/opendaylight/transportpce/common/ResponseCodes.java index 1c0965dcd..4e49623fd 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/ResponseCodes.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/ResponseCodes.java @@ -16,6 +16,7 @@ public final class ResponseCodes { public static final String SUCCESS_RESULT = "Success"; public static final String FAILED_RESULT = "Failed"; + public static final String IN_PORGRESS_RESULT = "In Progress"; private ResponseCodes() { } 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 2bc8c957a..ae8d48e6f 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java @@ -8,11 +8,13 @@ package org.opendaylight.transportpce.servicehandler; import com.google.common.util.concurrent.ListenableFuture; + import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.path.computation.request.input.ServiceAEnd; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.path.computation.request.input.ServiceAEndBuilder; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.path.computation.request.input.ServiceZEnd; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.path.computation.request.input.ServiceZEndBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescription; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInputBuilder; 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.ServiceImplementationRequestInputBuilder; @@ -62,7 +64,7 @@ public final class ModelMappingUtils { } public static ServiceImplementationRequestInput createServiceImplementationRequest(ServiceInput input, - PathComputationRequestOutput pceResponse) { + PathDescription pathDescription) { ServiceImplementationRequestInputBuilder serviceImplementationRequestInputBuilder = new ServiceImplementationRequestInputBuilder(); serviceImplementationRequestInputBuilder.setServiceName(input.getServiceName()); @@ -98,10 +100,8 @@ public final class ModelMappingUtils { .request.input.PathDescriptionBuilder pathDescBuilder = new org.opendaylight.yang.gen.v1.http.org .opendaylight.transportpce.renderer.rev171017.service.implementation.request.input .PathDescriptionBuilder(); - pathDescBuilder.setAToZDirection(pceResponse.getResponseParameters() - .getPathDescription().getAToZDirection()); - pathDescBuilder.setZToADirection(pceResponse.getResponseParameters() - .getPathDescription().getZToADirection()); + pathDescBuilder.setAToZDirection(pathDescription.getAToZDirection()); + pathDescBuilder.setZToADirection(pathDescription.getZToADirection()); serviceImplementationRequestInputBuilder.setPathDescription(pathDescBuilder.build()); return serviceImplementationRequestInputBuilder.build(); } diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ServiceInput.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ServiceInput.java index ae7e337e1..b8781c507 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ServiceInput.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ServiceInput.java @@ -14,9 +14,13 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev1 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints; import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints; 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.ServiceDeleteInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput; +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; /** * Super class of {@link ServiceCreateInput} and {@link TempServiceCreateInput}. @@ -36,19 +40,6 @@ public class ServiceInput { private String customer; private String customerContact; - public ServiceInput(TempServiceCreateInput tempServiceCreateInput) { - setServiceName(tempServiceCreateInput.getCommonId()); - setCommonId(tempServiceCreateInput.getCommonId()); - setConnectionType(tempServiceCreateInput.getConnectionType()); - setSdncRequestHeader(tempServiceCreateInput.getSdncRequestHeader()); - setHardConstraints(tempServiceCreateInput.getHardConstraints()); - setSoftConstraints(tempServiceCreateInput.getSoftConstraints()); - setServiceAEnd(tempServiceCreateInput.getServiceAEnd()); - setServiceZEnd(tempServiceCreateInput.getServiceZEnd()); - setCustomer(tempServiceCreateInput.getCustomer()); - setCustomerContact(tempServiceCreateInput.getCustomerContact()); - } - public ServiceInput(ServiceCreateInput serviceCreateInput) { setServiceName(serviceCreateInput.getServiceName()); setCommonId(serviceCreateInput.getCommonId()); @@ -67,6 +58,19 @@ public class ServiceInput { setSdncRequestHeader(serviceDeleteInput.getSdncRequestHeader()); } + public ServiceInput(TempServiceCreateInput tempServiceCreateInput) { + setServiceName(tempServiceCreateInput.getCommonId()); + setCommonId(tempServiceCreateInput.getCommonId()); + setConnectionType(tempServiceCreateInput.getConnectionType()); + setSdncRequestHeader(tempServiceCreateInput.getSdncRequestHeader()); + setHardConstraints(tempServiceCreateInput.getHardConstraints()); + setSoftConstraints(tempServiceCreateInput.getSoftConstraints()); + setServiceAEnd(tempServiceCreateInput.getServiceAEnd()); + setServiceZEnd(tempServiceCreateInput.getServiceZEnd()); + setCustomer(tempServiceCreateInput.getCustomer()); + setCustomerContact(tempServiceCreateInput.getCustomerContact()); + } + public ServiceInput(TempServiceDeleteInput tempServiceDeleteInput) { String comId = tempServiceDeleteInput.getCommonId(); setServiceName(comId); @@ -74,6 +78,30 @@ public class ServiceInput { setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId(comId).build()); } + public ServiceCreateInput getServiceCreateInput() { + return new ServiceCreateInputBuilder().setServiceName(serviceName) + .setCommonId(commonId) + .setConnectionType(connectionType) + .setSdncRequestHeader(sdncRequestHeader) + .setHardConstraints(hardConstraints) + .setSoftConstraints(softConstraints) + .setServiceAEnd(new ServiceAEndBuilder(serviceAEnd).build()) + .setServiceZEnd(new ServiceZEndBuilder(serviceZEnd).build()) + .setCustomer(customer) + .setCustomerContact(customerContact).build(); + } + + public TempServiceCreateInput getTempServiceCreateInput() { + return new TempServiceCreateInputBuilder().setCommonId(commonId) + .setConnectionType(connectionType).setSdncRequestHeader(sdncRequestHeader) + .setHardConstraints(hardConstraints).setSoftConstraints(softConstraints) + .setServiceAEnd(new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service + .create.input.ServiceAEndBuilder(serviceAEnd).build()) + .setServiceZEnd(new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service + .create.input.ServiceZEndBuilder(serviceZEnd).build()).setCustomer(customer) + .setCustomerContact(customerContact).build(); + } + public String getServiceName() { return serviceName; } 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 435e809ab..b2fc9994a 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 @@ -13,9 +13,9 @@ 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.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.pce.service.PathComputationService; @@ -23,26 +23,27 @@ import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; 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.ServiceNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon; 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; @@ -55,7 +56,6 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.Service 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; @@ -66,14 +66,11 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempSer 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.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; @@ -87,19 +84,24 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { 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; } @Override @@ -114,75 +116,21 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED); } - - // Starting service create operation + 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.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.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 = null; - try { - serviceImplementationRequestOutput = - this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest).get(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("Renderer Service implementation failed !"); - } - 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); + PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true); + if (output != null) { + LOG.info("Service compliant, serviceCreate in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createCreateServiceReply(input, common.getAckFinalIndicator(), + common.getResponseMessage(), common.getResponseCode()); } 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); + return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, + "PCE calculation failed", ResponseCodes.RESPONSE_FAILED); } } @@ -220,42 +168,33 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { message, ResponseCodes.RESPONSE_FAILED); } } catch (NullPointerException e) { - LOG.info("failed to get service '{}' from datastore : ", serviceName, e); + LOG.error("failed to get service '{}' from datastore : ", serviceName, e); + message = "Service '" + serviceName + "' does not exist in datastore"; + LOG.error(message); + return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, + ResponseCodes.RESPONSE_FAILED); } - - LOG.debug("Service '{}' present in datastore !", serviceName); + LOG.info("Service '{}' present 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.rev171017 .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput( new ServiceInput(input)); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteOutput output = null; - try { - output = this.rendererServiceOperations.serviceDelete(serviceDeleteInput).get(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("Renderer Service delete failed !"); - } - - 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.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!"); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput output = + this.rendererServiceWrapper.performRenderer(serviceDeleteInput, + ServiceNotificationTypes.ServiceDeleteResult); + if (output != null) { + LOG.info("Service present in datastore, service-delete in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createDeleteServiceReply(input, common.getAckFinalIndicator(), + common.getResponseMessage(), common.getResponseCode()); + } else { + return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, + "Renderer service delete failed !", ResponseCodes.RESPONSE_FAILED); } - - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - "Service delete was successful!", ResponseCodes.RESPONSE_OK); } @Override @@ -292,70 +231,52 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { 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); + Optional servicesObject = this.serviceDataStoreOperations.getService(input.getServiceName()); + if (servicesObject.isPresent()) { + Services service = servicesObject.get(); + 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(service.getSdncRequestHeader().getNotificationUrl()); + sdncBuilder.setRequestId(service.getSdncRequestHeader().getRequestId()); + sdncBuilder.setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId()); + sdncBuilder.setRpcAction(RpcActions.ServiceDelete); + deleteInputBldr.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.rev171017 + .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput( + new ServiceInput(deleteInputBldr.build())); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 + .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput, + ServiceNotificationTypes.ServiceDeleteResult); + if (output != null) { + LOG.info("Service present in datastore, service-reroute in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createRerouteServiceReply(input, common.getAckFinalIndicator(), + common.getResponseMessage(), RpcStatus.Successful); } else { - LOG.error("Service '{}' is not present", input.getServiceName()); - message = "Service '" + input.getServiceName() + "' is not present"; + return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES, + "Renderer service delete failed !", RpcStatus.Failed); } - } catch (InterruptedException | ExecutionException e) { - LOG.info("Exception caught" , e); + } else { + LOG.error("Service '{}' is not present", input.getServiceName()); + message = "Service '" + input.getServiceName() + "' is not present"; + return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_NO, message, + RpcStatus.Failed); } - ServiceRerouteOutputBuilder output = new ServiceRerouteOutputBuilder() - .setHardConstraints(null).setSoftConstraints(null).setStatus(RpcStatus.Failed).setStatusMessage(message); - return RpcResultBuilder.success(output).buildFuture(); } @Override @@ -413,39 +334,24 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { 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 = null; - try { - output = this.rendererServiceOperations.serviceDelete(serviceDeleteInput).get(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("Renderer Service delete failed ! "); - } - - 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!"); - } - - 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.rev171017.ServiceDeleteOutput output = + this.rendererServiceWrapper.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult); + if (output != null) { + LOG.info("Temp Service present in datastore, service-delete in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createDeleteServiceReply(input, common.getAckFinalIndicator(), + common.getResponseMessage(), common.getResponseCode()); + } else { + return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, + "Renderer service delete failed !", ResponseCodes.RESPONSE_FAILED); } - - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - "Service delete was successful!", ResponseCodes.RESPONSE_OK); } @Override @@ -463,72 +369,23 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { // 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); - } - - 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 = null; - try { - serviceImplementationRequestOutput = - this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest).get(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("Renderer service implementation failed !"); - } - 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); + 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); + this.pceServiceWrapper.performPCE(input, true); + PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true); + if (output != null) { + LOG.info("Service compliant, temp serviceCreate in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createCreateServiceReply(input, common.getAckFinalIndicator(), + common.getResponseMessage(), common.getResponseCode()); } else { - String message = "Service rendering has failed !"; - LOG.warn(message); - - OperationResult deleteServicePathOperationResult = - this.serviceDataStoreOperations.deleteServicePath(input.getCommonId()); - if (!deleteServicePathOperationResult.isSuccess()) { - LOG.warn("Service path was not removed from datastore!"); - } - - OperationResult deleteServiceOperationResult = - this.serviceDataStoreOperations.deleteService(input.getCommonId()); - if (!deleteServiceOperationResult.isSuccess()) { - LOG.warn("Service was not removed from datastore!"); - } - - return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message, - ResponseCodes.RESPONSE_FAILED); + return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, + "PCE calculation failed", ResponseCodes.RESPONSE_FAILED); } } diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProvider.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProvider.java index 003637e5e..47944d10a 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProvider.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProvider.java @@ -9,6 +9,7 @@ package org.opendaylight.transportpce.servicehandler.impl; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.controller.md.sal.binding.api.NotificationService; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; @@ -16,7 +17,9 @@ 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.listeners.PceListenerImpl; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.TransportpcePceListener; +import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.TransportpcePceListener; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.TransportpceRendererListener; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.OrgOpenroadmServiceService; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.slf4j.Logger; @@ -36,7 +39,9 @@ public class ServicehandlerProvider { private final RpcProviderRegistry rpcRegistry; private final NotificationService notificationService; private final NetworkModelWavelengthService networkModelWavelengthService; + private final NotificationPublishService notificationPublishService; private ListenerRegistration pcelistenerRegistration; + private ListenerRegistration rendererlistenerRegistration; private RpcRegistration rpcRegistration; private PathComputationService pathComputationService; private RendererServiceOperations rendererServiceOperations; @@ -44,13 +49,15 @@ public class ServicehandlerProvider { public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry, NotificationService notificationService, PathComputationService pathComputationService, RendererServiceOperations rendererServiceOperations, - NetworkModelWavelengthService networkModelWavelengthService) { + NetworkModelWavelengthService networkModelWavelengthService, + NotificationPublishService notificationPublishService) { this.dataBroker = dataBroker; this.rpcRegistry = rpcProviderRegistry; this.notificationService = notificationService; this.pathComputationService = pathComputationService; this.rendererServiceOperations = rendererServiceOperations; this.networkModelWavelengthService = networkModelWavelengthService; + this.notificationPublishService = notificationPublishService; } /** @@ -58,9 +65,15 @@ public class ServicehandlerProvider { */ public void init() { LOG.info("ServicehandlerProvider Session Initiated"); + final PceListenerImpl pceListenerImpl = new PceListenerImpl(rendererServiceOperations, + pathComputationService, notificationPublishService, null); + final RendererListenerImpl rendererListenerImpl = + new RendererListenerImpl(pathComputationService, notificationPublishService); + pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl); + rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl); final ServicehandlerImpl servicehandler = new ServicehandlerImpl(dataBroker, pathComputationService, - rendererServiceOperations, networkModelWavelengthService); - final PceListenerImpl pceListener = new PceListenerImpl(); + rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, + networkModelWavelengthService); rpcRegistration = rpcRegistry.addRpcImplementation(OrgOpenroadmServiceService.class, servicehandler); } @@ -70,6 +83,7 @@ public class ServicehandlerProvider { public void close() { LOG.info("ServicehandlerProvider Closed"); pcelistenerRegistration.close(); + rendererlistenerRegistration.close(); rpcRegistration.close(); } 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 fa0ebfb8f..0d5b266d1 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 @@ -7,49 +7,151 @@ */ package org.opendaylight.transportpce.servicehandler.listeners; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.common.OperationResult; +import org.opendaylight.transportpce.pce.service.PathComputationService; +import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; +import org.opendaylight.transportpce.servicehandler.ServiceInput; +import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; +import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResult; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.TransportpcePceListener; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescription; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescriptionBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParameters; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParametersBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Deprecated public class PceListenerImpl implements TransportpcePceListener { private static final Logger LOG = LoggerFactory.getLogger(PceListenerImpl.class); - private ServicePathRpcResult servicePathRpcResult = null; + private ServicePathRpcResult servicePathRpcResult; + private RendererServiceOperations rendererServiceOperations; + private ServiceDataStoreOperations serviceDataStoreOperations; + private PCEServiceWrapper pceServiceWrapper; + private ServiceInput input; + private Boolean serviceReconfigure; + private Boolean tempService; + + public PceListenerImpl(RendererServiceOperations rendererServiceOperations, + PathComputationService pathComputationService, NotificationPublishService notificationPublishService, + ServiceDataStoreOperations serviceDataStoreOperations) { + this.rendererServiceOperations = rendererServiceOperations; + this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService); + this.serviceDataStoreOperations = serviceDataStoreOperations; + setServiceReconfigure(false); + setInput(null); + setTempService(false); + } @Override public void onServicePathRpcResult(ServicePathRpcResult notification) { if (!compareServicePathRpcResult(notification)) { servicePathRpcResult = notification; - StringBuilder build = new StringBuilder(); - build.append( - "Received '" + notification.getNotificationType() + "' StubPce notification " + "from service '" - + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'"); - build.append(" with StatusMessage '" + notification.getStatusMessage() + "'"); - if ((notification.getStatus() == RpcStatusEx.Successful) && (notification.getNotificationType() - .getIntValue() == ServicePathNotificationTypes.PathComputationRequest.getIntValue())) { - build.append(" PathDescription : " + notification.getPathDescription().toString()); - /* - * switch (action.getIntValue()) { case 1: //service-create case - * 3: //service-delete case 8: //service-reconfigure case 9: - * //service-restoration case 10://service-reversion case - * 11://service-reroute break; - * - * default: break; } - */ + PathDescription pathDescription = null; + switch (servicePathRpcResult.getNotificationType().getIntValue()) { + case 1: /** path-computation-request. */ + 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 (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.rev171016.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.error("'PathDescription' parameter is null "); + return; + } + } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) { + LOG.error("PCE path computation failed !"); + return; + } + break; + case 2: /** cancel-resource-reserve. */ + 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 !"); + } + break; + default: + break; } - - LOG.info(build.toString()); } else { - LOG.info("ServicePathRpcResult already wired !"); + LOG.warn("ServicePathRpcResult already wired !"); } } - @Deprecated private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) { Boolean result = true; if (servicePathRpcResult == null) { @@ -71,4 +173,20 @@ public class PceListenerImpl implements TransportpcePceListener { return result; } + public void setInput(ServiceInput serviceInput) { + this.input = serviceInput; + } + + public void setServiceReconfigure(Boolean serv) { + this.serviceReconfigure = serv; + } + + public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) { + this.serviceDataStoreOperations = serviceData; + } + + public void setTempService(Boolean tempService) { + this.tempService = tempService; + } + } 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 new file mode 100644 index 000000000..492b73cfe --- /dev/null +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java @@ -0,0 +1,153 @@ +/* + * Copyright © 2017 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.listeners; + +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.common.OperationResult; +import org.opendaylight.transportpce.pce.service.PathComputationService; +import org.opendaylight.transportpce.servicehandler.ServiceInput; +import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; +import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSp; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.TransportpceRendererListener; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Calls to listen to Renderer notifications. + * + * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange + * + */ +public class RendererListenerImpl implements TransportpceRendererListener { + + private static final Logger LOG = LoggerFactory.getLogger(RendererListenerImpl.class); + private ServiceRpcResultSp serviceRpcResultSp; + private ServiceDataStoreOperations serviceDataStoreOperations; + private ServiceInput input; + private PCEServiceWrapper pceServiceWrapper; + private Boolean tempService; + + public RendererListenerImpl(PathComputationService pathComputationService, + NotificationPublishService notificationPublishService) { + this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService); + setServiceInput(null); + setTempService(false); + } + + @Override + public void onServiceRpcResultSp(ServiceRpcResultSp notification) { + if (!compareServiceRpcResultSp(notification)) { + serviceRpcResultSp = notification; + String serviceName = serviceRpcResultSp.getServiceName(); + int notifType = serviceRpcResultSp.getNotificationType().getIntValue(); + LOG.info("Renderer '{}' Notification received : {}", serviceRpcResultSp.getNotificationType().getName(), + notification); + switch (notifType) { + case 3 : /** service-implementation-request. */ + if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) { + LOG.info("Service implemented !"); + OperationResult operationResult = null; + if (tempService) { + operationResult = this.serviceDataStoreOperations.modifyTempService( + serviceRpcResultSp.getServiceName(), + State.InService, State.InService); + if (!operationResult.isSuccess()) { + LOG.warn("Temp Service status not updated in datastore !"); + } + } else { + operationResult = this.serviceDataStoreOperations.modifyService( + serviceRpcResultSp.getServiceName(), + State.InService, State.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!"); + } + } + } + break; + + case 4 : /** service-delete. */ + 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; + } + break; + + default: + break; + } + } else { + LOG.warn("ServiceRpcResultSp already wired !"); + } + } + + private Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) { + Boolean result = true; + if (serviceRpcResultSp == null) { + result = false; + } else { + if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) { + result = false; + } + if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) { + result = false; + } + if (serviceRpcResultSp.getStatus() != notification.getStatus()) { + result = false; + } + if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) { + result = false; + } + } + return result; + } + + public void setServiceInput(ServiceInput serviceInput) { + this.input = serviceInput; + } + + public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) { + this.serviceDataStoreOperations = serviceData; + } + + public void setTempService(Boolean tempService) { + this.tempService = tempService; + } +} 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 19fc931fb..c274c3b2f 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 @@ -7,25 +7,42 @@ */ package org.opendaylight.transportpce.servicehandler.service; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; -import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.pce.service.PathComputationService; import org.opendaylight.transportpce.servicehandler.MappingConstraints; import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveOutputBuilder; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInputBuilder; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultSh; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultShBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceEndpoint; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.RoutingConstraintsSp.PceMetric; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraints; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.SoftConstraints; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParameters; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParametersBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.handler.header.ServiceHandlerHeaderBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,46 +52,123 @@ public class PCEServiceWrapper { private static final Logger LOG = LoggerFactory.getLogger(PCEServiceWrapper.class); private final PathComputationService pathComputationService; + private final NotificationPublishService notificationPublishService; + private ServiceRpcResultSh notification = null; + private final ListeningExecutorService executor; - public PCEServiceWrapper(PathComputationService pathComputationService) { + public PCEServiceWrapper(PathComputationService pathComputationService, + NotificationPublishService notificationPublishService) { this.pathComputationService = pathComputationService; + this.notificationPublishService = notificationPublishService; + executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5)); } public PathComputationRequestOutput performPCE(ServiceCreateInput serviceCreateInput, boolean reserveResource) { - return performPCE(serviceCreateInput.getHardConstraints(), serviceCreateInput.getSoftConstraints(), - serviceCreateInput.getServiceName(), serviceCreateInput.getSdncRequestHeader(), - serviceCreateInput.getServiceAEnd(), serviceCreateInput.getServiceZEnd(), reserveResource); + LOG.info("performing PCE ..."); + if (validateParams(serviceCreateInput.getServiceName(), serviceCreateInput.getSdncRequestHeader())) { + return performPCE(serviceCreateInput.getHardConstraints(), serviceCreateInput.getSoftConstraints(), + serviceCreateInput.getServiceName(), serviceCreateInput.getSdncRequestHeader(), + serviceCreateInput.getServiceAEnd(), serviceCreateInput.getServiceZEnd(), + ServiceNotificationTypes.ServiceCreateResult, reserveResource); + } else { + return returnPCEFailed(); + } } public PathComputationRequestOutput performPCE(TempServiceCreateInput tempServiceCreateInput, boolean reserveResource) { - return performPCE(tempServiceCreateInput.getHardConstraints(), tempServiceCreateInput.getSoftConstraints(), - tempServiceCreateInput.getCommonId(), tempServiceCreateInput.getSdncRequestHeader(), - tempServiceCreateInput.getServiceAEnd(), tempServiceCreateInput.getServiceZEnd(), reserveResource); + LOG.info("performing PCE ..."); + if (validateParams(tempServiceCreateInput.getCommonId(), tempServiceCreateInput.getSdncRequestHeader())) { + return performPCE(tempServiceCreateInput.getHardConstraints(), tempServiceCreateInput.getSoftConstraints(), + tempServiceCreateInput.getCommonId(), tempServiceCreateInput.getSdncRequestHeader(), + tempServiceCreateInput.getServiceAEnd(), tempServiceCreateInput.getServiceZEnd(), + ServiceNotificationTypes.ServiceCreateResult, reserveResource); + } else { + return returnPCEFailed(); + } } private PathComputationRequestOutput performPCE(org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains .rev161014.routing.constraints.HardConstraints hardConstraints, org.opendaylight.yang.gen.v1.http.org .openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints softConstraints, String serviceName, SdncRequestHeader sdncRequestHeader, ServiceEndpoint serviceAEnd, - ServiceEndpoint serviceZEnd, boolean reserveResource) { + ServiceEndpoint serviceZEnd, ServiceNotificationTypes notifType, boolean reserveResource) { MappingConstraints mappingConstraints = new MappingConstraints(hardConstraints, softConstraints); mappingConstraints.serviceToServicePathConstarints(); - PathComputationRequestInput pathComputationRequestInput = - createPceRequestInput(serviceName, sdncRequestHeader,mappingConstraints.getServicePathHardConstraints(), - mappingConstraints.getServicePathSoftConstraints(), reserveResource, serviceAEnd, - serviceZEnd); - LOG.debug("Calling path computation."); - ListenableFuture pathComputationRequestOutput - = this.pathComputationService.pathComputationRequest(pathComputationRequestInput); - LOG.debug("Path computation done."); - PathComputationRequestOutput output = null; + LOG.info("Calling path computation."); + notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName(serviceName) + .setStatus(RpcStatusEx.Pending) + .setStatusMessage("Service compliant, submitting PathComputation Request ...").build(); try { - output = pathComputationRequestOutput.get(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("PCE RPC path computation failed !"); + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : " + e); } - return output; + 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); + } + } + }; + PathComputationRequestInput pathComputationRequestInput = createPceRequestInput(serviceName, sdncRequestHeader, + mappingConstraints.getServicePathHardConstraints(), mappingConstraints.getServicePathSoftConstraints(), + reserveResource, serviceAEnd, serviceZEnd); + ListenableFuture pce = this.pathComputationService + .pathComputationRequest(pathComputationRequestInput); + Futures.addCallback(pce, pceCallback, executor); + + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setRequestId(sdncRequestHeader.getRequestId()) + .setResponseCode(ResponseCodes.RESPONSE_OK) + .setResponseMessage("PCE calculation in progress") + .build(); + ResponseParameters reponseParameters = new ResponseParametersBuilder().build(); + return new PathComputationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon) + .setResponseParameters(reponseParameters) + .build(); } private PathComputationRequestInput createPceRequestInput(String serviceName, @@ -101,16 +195,123 @@ public class PCEServiceWrapper { private CancelResourceReserveInput mappingCancelResourceReserve(String serviceName, SdncRequestHeader sdncRequestHeader) { - LOG.debug("Mapping ServiceCreateInput or ServiceFeasibilityCheckInput or serviceReconfigureInput to PCE" - + "requests"); - ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder(); - if (sdncRequestHeader != null) { - serviceHandlerHeader.setRequestId(sdncRequestHeader.getRequestId()); + LOG.info("Mapping to PCE Cancel resource request input"); + CancelResourceReserveInputBuilder cancelResourceReserveInput = new CancelResourceReserveInputBuilder(); + if (serviceName != null) { + ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder(); + if (sdncRequestHeader != null) { + serviceHandlerHeader.setRequestId(sdncRequestHeader.getRequestId()); + } + cancelResourceReserveInput.setServiceName(serviceName) + .setServiceHandlerHeader(serviceHandlerHeader.build()); + return cancelResourceReserveInput.build(); + } else { + LOG.error("Service Name (common-id for Temp service) is not set"); + return null; } - CancelResourceReserveInputBuilder cancelResourceReserveInput = new CancelResourceReserveInputBuilder() - .setServiceName(serviceName) - .setServiceHandlerHeader(serviceHandlerHeader.build()); - return cancelResourceReserveInput.build(); } + public CancelResourceReserveOutput cancelPCEResource(String serviceName, ServiceNotificationTypes notifType) { + LOG.info("Calling cancel resource reserve computation."); + notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName(serviceName) + .setStatus(RpcStatusEx.Pending) + .setStatusMessage("submitting Cancel resource reserve Request ...").build(); + try { + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : " + 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); + } + } + }; + CancelResourceReserveInput cancelResourceReserveInput = mappingCancelResourceReserve(serviceName, null); + ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder(); + if (cancelResourceReserveInput != null) { + String requestId = cancelResourceReserveInput.getServiceHandlerHeader().getRequestId(); + ListenableFuture pce = + this.pathComputationService.cancelResourceReserve(cancelResourceReserveInput); + Futures.addCallback(pce, pceCallback, executor); + if (requestId != null) { + configurationResponseCommon.setRequestId(requestId); + } + configurationResponseCommon.setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress"); + return new CancelResourceReserveOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()).build(); + } else { + configurationResponseCommon.setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("PCE failed !"); + return new CancelResourceReserveOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()).build(); + } + } + + private static PathComputationRequestOutput returnPCEFailed() { + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setResponseCode(ResponseCodes.RESPONSE_FAILED) + .setResponseMessage("PCE calculation failed").build(); + ResponseParameters reponseParameters = new ResponseParametersBuilder().build(); + return new PathComputationRequestOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon) + .setResponseParameters(reponseParameters).build(); + } + + private Boolean validateParams(String serviceName, SdncRequestHeader sdncRequestHeader) { + boolean result = true; + if (!checkString(serviceName)) { + result = false; + LOG.error("Service Name (common-id for Temp service) is not set"); + } else if (sdncRequestHeader == null) { + LOG.error("Service sdncRequestHeader 'request-id' is not set"); + result = false; + } + return result; + } + + private static boolean checkString(String value) { + return ((value != null) && (value.compareTo("") != 0)); + } } 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 new file mode 100644 index 000000000..5c8c5e1e3 --- /dev/null +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java @@ -0,0 +1,172 @@ +/* + * Copyright © 2017 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.service; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; + +import java.util.concurrent.Executors; + +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.common.ResponseCodes; +import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultSh; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultShBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.handler.header.ServiceHandlerHeader; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.handler.header.ServiceHandlerHeaderBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Class to call RendererServiceOperations. + * + * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange + * + */ +public class RendererServiceWrapper { + + private static final Logger LOG = LoggerFactory.getLogger(RendererServiceWrapper.class); + private final RendererServiceOperations rendererServiceOperations; + private final NotificationPublishService notificationPublishService; + private ServiceRpcResultSh notification = null; + private final ListeningExecutorService executor; + + public RendererServiceWrapper(RendererServiceOperations rendererServiceOperations, + NotificationPublishService notificationPublishService) { + this.rendererServiceOperations = rendererServiceOperations; + this.notificationPublishService = notificationPublishService; + this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5)); + } + + private void sendNotifications(ServiceRpcResultSh notif) { + try { + notificationPublishService.putNotification(notif); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : " + e); + } + } + + public ServiceDeleteOutput performRenderer(ServiceDeleteInput serviceDeleteInput, + ServiceNotificationTypes notifType) { + if (validateParams(serviceDeleteInput.getServiceName(), serviceDeleteInput.getServiceHandlerHeader(), false)) { + return performRenderer(serviceDeleteInput.getServiceName(), serviceDeleteInput.getServiceHandlerHeader(), + ServiceNotificationTypes.ServiceDeleteResult); + } else { + return returnRendererFailed(); + } + } + + public ServiceDeleteOutput performRenderer(TempServiceDeleteInput tempServiceDeleteInput, + ServiceNotificationTypes notifType) { + String commonId = tempServiceDeleteInput.getCommonId(); + if (validateParams(commonId, null, true)) { + ServiceHandlerHeader serviceHandler = new ServiceHandlerHeaderBuilder().setRequestId(commonId).build(); + return performRenderer(tempServiceDeleteInput.getCommonId(), serviceHandler, + ServiceNotificationTypes.ServiceDeleteResult); + } else { + return returnRendererFailed(); + } + } + + private ServiceDeleteOutput performRenderer(String serviceName, ServiceHandlerHeader serviceHandlerHeader, + ServiceNotificationTypes notifType) { + notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName(serviceName) + .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); + } + }; + ServiceDeleteInput serviceDeleteInput = createRendererRequestInput(serviceName, serviceHandlerHeader); + ListenableFuture renderer = + this.rendererServiceOperations.serviceDelete(serviceDeleteInput); + Futures.addCallback(renderer, rendererCallback, executor); + ConfigurationResponseCommon value = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setRequestId(serviceDeleteInput.getServiceHandlerHeader().getRequestId()) + .setResponseCode(ResponseCodes.RESPONSE_OK) + .setResponseMessage("Renderer service delete in progress").build(); + return new ServiceDeleteOutputBuilder().setConfigurationResponseCommon(value).build(); + } + + private ServiceDeleteInput createRendererRequestInput(String serviceName, + ServiceHandlerHeader serviceHandlerHeader) { + LOG.info("Mapping ServiceDeleteInput or TempServiceDelete to Renderer requests"); + return new ServiceDeleteInputBuilder().setServiceHandlerHeader(serviceHandlerHeader).setServiceName(serviceName) + .build(); + } + + private static ServiceDeleteOutput returnRendererFailed() { + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setResponseCode(ResponseCodes.RESPONSE_FAILED) + .setResponseMessage("Renderer service delete failed !").build(); + return new ServiceDeleteOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon).build(); + } + + private Boolean validateParams(String serviceName, ServiceHandlerHeader serviceHandlerHeader, boolean temp) { + boolean result = true; + if (!checkString(serviceName)) { + result = false; + LOG.error("Service Name (common-id for Temp service) is not set"); + } else if (!temp && (serviceHandlerHeader == null)) { + LOG.error("Service serviceHandlerHeader 'request-id' is not set"); + result = false; + } + return result; + } + + private static boolean checkString(String value) { + return ((value != null) && (value.compareTo("") != 0)); + } +} + diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperations.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperations.java index 7109b9a52..087e60c01 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperations.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperations.java @@ -8,6 +8,7 @@ package org.opendaylight.transportpce.servicehandler.service; import java.util.Optional; + import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.servicehandler.ServiceInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; @@ -89,13 +90,10 @@ public interface ServiceDataStoreOperations { /** * create new service entry. * - * @param serviceCreateInput - * serviceCreateInput data for creation of service - * @param outputFromPce - * output from pce request which is used as input for creating of service. + * @param serviceCreateInput serviceCreateInput data for creation of service * @return result of createService operation */ - OperationResult createService(ServiceCreateInput serviceCreateInput, PathComputationRequestOutput outputFromPce); + OperationResult createService(ServiceCreateInput serviceCreateInput); /** * create new servicePath entry. @@ -111,14 +109,11 @@ public interface ServiceDataStoreOperations { /** * create new Temp service entry. * - * @param tempServiceCreateInput - * tempServiceCreateInput data for creation of service - * @param outputFromPce - * output from pce request which is used as input for creating of service. + * @param tempServiceCreateInput tempServiceCreateInput data for creation of + * service * @return result of createTempService operation */ - OperationResult createTempService(TempServiceCreateInput tempServiceCreateInput, - PathComputationRequestOutput outputFromPce); + OperationResult createTempService(TempServiceCreateInput tempServiceCreateInput); /** * deleteServicePath by name. 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 a2a849929..40e89a5d2 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 @@ -163,7 +163,8 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation InstanceIdentifier iid = InstanceIdentifier.create(ServiceList.class) .child(Services.class, new ServicesKey(serviceName)); Services services = new ServicesBuilder(readService.get()).setOperationalState(operationalState) - .setAdministrativeState(administrativeState).build(); + .setAdministrativeState(administrativeState) + .build(); writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, services); writeTx.submit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(SUCCESSFUL_MESSAGE); @@ -213,8 +214,7 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation } @Override - public OperationResult createService(ServiceCreateInput serviceCreateInput, - PathComputationRequestOutput outputFromPce) { + public OperationResult createService(ServiceCreateInput serviceCreateInput) { LOG.debug("Writing '{}' Service", serviceCreateInput.getServiceName()); try { InstanceIdentifier iid = InstanceIdentifier.create(ServiceList.class) @@ -232,8 +232,7 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation } @Override - public OperationResult createTempService(TempServiceCreateInput tempServiceCreateInput, - PathComputationRequestOutput outputFromPce) { + public OperationResult createTempService(TempServiceCreateInput tempServiceCreateInput) { LOG.debug("Writing '{}' Temp Service", tempServiceCreateInput.getCommonId()); try { InstanceIdentifier cancelResourceReserve(CancelResourceReserveInput input) { + return executor.submit(new Callable() { + @Override + public CancelResourceReserveOutput call() throws Exception { + String serviceName = input.getServiceName(); + RpcStatusEx rpcStatusEx = RpcStatusEx.Pending; + ServicePathRpcResult notification = new ServicePathRpcResultBuilder() + .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage("Service compliant, submitting cancel resource Request ...").build(); + sendNotifications(notification); + String message = ""; + String responseCode = null; + ConfigurationResponseCommon configurationResponseCommon = null; + CancelResourceReserveOutput output = null; + try { + LOG.info("Wait for 5s til beginning the PCE cancel resource request"); + Thread.sleep(5000); // sleep for 1s + } catch (InterruptedException e) { + message = "path computation service failed !"; + LOG.error("path computation service failed !", e); + responseCode = ResponseCodes.RESPONSE_FAILED; + rpcStatusEx = RpcStatusEx.Failed; + notification = new ServicePathRpcResultBuilder() + .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve) + .setStatus(rpcStatusEx).setStatusMessage(message).setServiceName(serviceName).build(); + sendNotifications(notification); + configurationResponseCommon = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode).setResponseMessage(message).build(); + output = new CancelResourceReserveOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + } + if (pceFailed) { + LOG.info("forcing pce to fail"); + message = "pce failed !"; + rpcStatusEx = RpcStatusEx.Failed; + LOG.error(message); + responseCode = ResponseCodes.RESPONSE_FAILED; + } else { + message = "path computated !"; + rpcStatusEx = RpcStatusEx.Successful; + LOG.error(message); + responseCode = ResponseCodes.RESPONSE_OK; + } + notification = new ServicePathRpcResultBuilder() + .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve) + .setStatus(RpcStatusEx.Successful).setStatusMessage(message) + .setServiceName(serviceName).build(); + sendNotifications(notification); + configurationResponseCommon = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode).setResponseMessage(message).build(); + output = new CancelResourceReserveOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + return output; + } + }); + + } + + @Override + public ListenableFuture pathComputationRequest(PathComputationRequestInput input) { + return executor.submit(new Callable() { + @Override + public PathComputationRequestOutput call() throws Exception { + String serviceName = input.getServiceName(); + RpcStatusEx rpcStatusEx = RpcStatusEx.Pending; + ServicePathRpcResult notification = new ServicePathRpcResultBuilder() + .setNotificationType(ServicePathNotificationTypes.PathComputationRequest) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage("Service compliant, submitting pathComputation Request ...").build(); + sendNotifications(notification); + String message = ""; + String responseCode = null; + ConfigurationResponseCommon configurationResponseCommon = null; + PathComputationRequestOutput output = null; + try { + LOG.info("Wait for 5s til beginning the PCE pathComputation request"); + Thread.sleep(5000); // sleep for 1s + } catch (InterruptedException e) { + message = "path computation service failed !"; + LOG.error("path computation service failed !", e); + responseCode = ResponseCodes.RESPONSE_FAILED; + rpcStatusEx = RpcStatusEx.Failed; + notification = new ServicePathRpcResultBuilder() + .setNotificationType(ServicePathNotificationTypes.PathComputationRequest) + .setStatus(rpcStatusEx).setStatusMessage(message).setServiceName(serviceName).build(); + sendNotifications(notification); + configurationResponseCommon = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode).setResponseMessage(message).build(); + output = new PathComputationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + } + PathDescription value; + if (pceFailed) { + value = null; + LOG.info("forcing pce to fail"); + message = "pce failed !"; + rpcStatusEx = RpcStatusEx.Failed; + LOG.error(message); + responseCode = ResponseCodes.RESPONSE_FAILED; + } else { + value = createPathDescription(0L, 5L, 0L, 5L); + message = "path computated !"; + rpcStatusEx = RpcStatusEx.Successful; + LOG.error(message); + responseCode = ResponseCodes.RESPONSE_OK; + } + notification = new ServicePathRpcResultBuilder() + .setNotificationType(ServicePathNotificationTypes.PathComputationRequest) + .setPathDescription(value) + .setStatus(rpcStatusEx).setStatusMessage(message) + .setServiceName(serviceName).build(); + sendNotifications(notification); + configurationResponseCommon = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message).build(); + output = new PathComputationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + return output; + } + }); + } + + private static PathDescription createPathDescription(long azRate, long azWaveLength, long zaRate, + long zaWaveLength) { + AToZDirection atozDirection = + new AToZDirectionBuilder().setRate(azRate).setAToZWavelengthNumber(azWaveLength).setAToZ(null).build(); + ZToADirection ztoaDirection = + new ZToADirectionBuilder().setRate(zaRate).setZToAWavelengthNumber(zaWaveLength).setZToA(null).build(); + PathDescription pathDescription = + new PathDescriptionBuilder().setAToZDirection(atozDirection).setZToADirection(ztoaDirection).build(); + return pathDescription; + } + + public void setPceFailed(Boolean pceFailed) { + this.pceFailed = pceFailed; + } +} diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java index 504d4e941..c18f1aaa8 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java @@ -7,6 +7,7 @@ */ package org.opendaylight.transportpce.servicehandler.stub; +import com.google.common.base.Optional; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; @@ -14,46 +15,138 @@ import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.transportpce.common.ResponseCodes; +import org.opendaylight.transportpce.common.Timeouts; import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutputBuilder; 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.yangtools.yang.common.RpcResult; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSp; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSpBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.rpc.result.sp.PathTopology; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.rpc.result.sp.PathTopologyBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.path.PathDescription; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.Notification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class StubRendererServiceOperations implements RendererServiceOperations { private static final Logger LOG = LoggerFactory.getLogger(StubRendererServiceOperations.class); - private StubrendererImpl stubrendererImpl; private final ListeningExecutorService executor; + private final NotificationPublishService notificationPublishService; + private final NetworkModelWavelengthService networkModelWavelengthService; + private final DataBroker dataBroker; + private Boolean rendererFailed; + private Boolean isnetworkModelWlService; public StubRendererServiceOperations(NetworkModelWavelengthService networkModelWavelengthService, DataBroker dataBroker, NotificationPublishService notificationPublishService) { - this.stubrendererImpl = - new StubrendererImpl(networkModelWavelengthService, dataBroker, notificationPublishService); + this.notificationPublishService = notificationPublishService; + this.networkModelWavelengthService = networkModelWavelengthService; + this.dataBroker = dataBroker; + this.rendererFailed = false; + this.isnetworkModelWlService = true; executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2)); } + private void sendNotifications(Notification notif) { + try { + LOG.info("putting notification : {}", notif); + notificationPublishService.putNotification(notif); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : ", e.getMessage()); + } + } + @Override public ListenableFuture serviceImplementation(ServiceImplementationRequestInput input) { return executor.submit(new Callable() { - @Override public ServiceImplementationRequestOutput call() { - ListenableFuture> rpcResultFuture = - stubrendererImpl.serviceImplementation(input); + LOG.info("serviceImplementation request ..."); + String serviceName = input.getServiceName(); + RpcStatusEx rpcStatusEx = RpcStatusEx.Pending; + ServiceRpcResultSp notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage("Service compliant, submitting serviceImplementation Request ...").build(); + sendNotifications(notification); + String message = ""; + String responseCode = null; + ConfigurationResponseCommonBuilder configurationResponseCommon = null; + ServiceImplementationRequestOutput output = null; try { - return rpcResultFuture.get().getResult(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("RPC serviceImplementation failed !", e); + LOG.info("Wait for 5s til beginning the Renderer serviceImplementation request"); + Thread.sleep(5000); // sleep for 1s + } catch (InterruptedException e) { + message = "renderer failed !"; + rpcStatusEx = RpcStatusEx.Failed; + responseCode = ResponseCodes.RESPONSE_FAILED; + LOG.error(message); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName(serviceName).setStatus(rpcStatusEx).setStatusMessage(message).build(); + sendNotifications(notification); + configurationResponseCommon = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode).setResponseMessage(message); + output = new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()).build(); + return output; } - return null; + if (rendererFailed) { + LOG.info("forcing renderer to fail"); + message = "renderer failed !"; + rpcStatusEx = RpcStatusEx.Failed; + LOG.error(message); + responseCode = ResponseCodes.RESPONSE_FAILED; + } else { + if (isnetworkModelWlService) { + networkModelWavelengthService.useWavelengths(input.getPathDescription()); + } else { + LOG.warn("No need to execute networkModelWavelengthService..."); + } + message = "service implemented !"; + rpcStatusEx = RpcStatusEx.Successful; + LOG.info(message); + responseCode = ResponseCodes.RESPONSE_OK; + } + PathTopology pathTopology = new PathTopologyBuilder().build(); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage(message).setPathTopology(pathTopology).build(); + sendNotifications(notification); + responseCode = ResponseCodes.RESPONSE_OK; + configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message); + output = new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); + return output; } }); } @@ -61,18 +154,103 @@ public class StubRendererServiceOperations implements RendererServiceOperations @Override public ListenableFuture serviceDelete(ServiceDeleteInput input) { return executor.submit(new Callable() { - @Override public ServiceDeleteOutput call() { - ListenableFuture> rpcResultFuture = - stubrendererImpl.serviceDelete(input); + LOG.info("ServiceDelete request ..."); + String serviceName = input.getServiceName(); + RpcStatusEx rpcStatusEx = RpcStatusEx.Pending; + ServiceRpcResultSp notification = + new ServiceRpcResultSpBuilder().setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage("Service compliant, submitting serviceDelete Request ...").build(); + sendNotifications(notification); + String message = ""; + String responseCode = null; + ConfigurationResponseCommonBuilder configurationResponseCommon = null; + ServiceDeleteOutput output = null; try { - return rpcResultFuture.get().getResult(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("RPC serviceDelete failed !", e); + LOG.info("Wait for 5s til beginning the Renderer serviceDelete request"); + Thread.sleep(5000); // sleep for 1s + } catch (InterruptedException e) { + message = "deleting service failed !"; + LOG.error("deleting service failed !", e); + responseCode = ResponseCodes.RESPONSE_FAILED; + rpcStatusEx = RpcStatusEx.Failed; + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete).setServiceName(serviceName) + .setStatus(rpcStatusEx).setStatusMessage(message).build(); + sendNotifications(notification); + configurationResponseCommon = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode).setResponseMessage(message); + output = new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()).build(); + } + if (rendererFailed) { + LOG.info("forcing renderer to fail"); + message = "renderer failed !"; + rpcStatusEx = RpcStatusEx.Failed; + LOG.error(message); + responseCode = ResponseCodes.RESPONSE_FAILED; + } else { + if (isnetworkModelWlService) { + // Obtain path description + Optional pathDescriptionOpt = getPathDescriptionFromDatastore(serviceName); + PathDescription pathDescription; + if (pathDescriptionOpt.isPresent()) { + pathDescription = pathDescriptionOpt.get(); + networkModelWavelengthService.freeWavelengths(pathDescription); + } else { + LOG.warn("failed to get pathDescription for service : {}", serviceName); + } + } else { + LOG.warn("No need to execute networkModelWavelengthService..."); + } + message = "service deleted !"; + rpcStatusEx = RpcStatusEx.Successful; + LOG.info(message); + responseCode = ResponseCodes.RESPONSE_OK; } - return null; + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage(message).build(); + sendNotifications(notification); + responseCode = ResponseCodes.RESPONSE_OK; + configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message); + output = new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); + return output; } }); } + + private Optional getPathDescriptionFromDatastore(String serviceName) { + InstanceIdentifier pathDescriptionIID = InstanceIdentifier.create(ServicePathList.class) + .child(ServicePaths.class, new ServicePathsKey(serviceName)).child(PathDescription.class); + ReadOnlyTransaction pathDescReadTx = this.dataBroker.newReadOnlyTransaction(); + try { + LOG.debug("Getting path description for service {}", serviceName); + return pathDescReadTx.read(LogicalDatastoreType.OPERATIONAL, pathDescriptionIID) + .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + LOG.warn("Exception while getting path description from datastore {} for service {}!", pathDescriptionIID, + serviceName, e); + return Optional.absent(); + } + } + + public void setRendererFailed(Boolean rendererFailed) { + this.rendererFailed = rendererFailed; + } + + public void setIsnetworkModelWlService(Boolean isnetworkModelWlService) { + this.isnetworkModelWlService = isnetworkModelWlService; + } } diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java deleted file mode 100644 index 91aefe82f..000000000 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright © 2017 Orange, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - - -package org.opendaylight.transportpce.servicehandler.stub; - -import com.google.common.base.Optional; -import com.google.common.util.concurrent.ListenableFuture; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.transportpce.common.ResponseCodes; -import org.opendaylight.transportpce.common.Timeouts; -import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutputBuilder; -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.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutputBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSp; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSpBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.rpc.result.sp.PathTopology; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.rpc.result.sp.PathTopologyBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.path.PathDescription; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.Notification; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - - -/** - * Class to implement StubrendererService. - * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange - * - */ -public class StubrendererImpl { - /** Logging. */ - private static final Logger LOG = LoggerFactory.getLogger(StubrendererImpl.class); - /** check service sdnc-request-header compliancy. */ - private final NotificationPublishService notificationPublishService; - private final NetworkModelWavelengthService networkModelWavelengthService; - private final DataBroker dataBroker; - private ServiceRpcResultSp notification = null; - - public StubrendererImpl(NetworkModelWavelengthService networkModelWavelengthService, DataBroker dataBroker, - NotificationPublishService notificationPublishService) { - this.notificationPublishService = notificationPublishService; - this.networkModelWavelengthService = networkModelWavelengthService; - this.dataBroker = dataBroker; - } - - private void sendNotifications(Notification notif) { - try { - notificationPublishService.putNotification(notif); - } catch (InterruptedException e) { - LOG.info("notification offer rejected : ", e.getMessage()); - } - } - - public ListenableFuture> serviceDelete(ServiceDeleteInput input) { - LOG.info("ServiceDelete request ..."); - String serviceName = input.getServiceName(); - String message = ""; - String responseCode = null; - notification = new ServiceRpcResultSpBuilder().setNotificationType(ServicePathNotificationTypes.ServiceDelete) - .setServiceName(serviceName).setStatus(RpcStatusEx.Pending) - .setStatusMessage("Service compliant, submitting serviceDelete Request ...").build(); - sendNotifications(notification); - try { - LOG.info("Wait for 10s til beginning the Renderer serviceDelete request"); - Thread.sleep(10000); // sleep for 1s - } catch (InterruptedException e) { - message = "deleting service failed !"; - LOG.error("deleting service failed !", e); - responseCode = ResponseCodes.RESPONSE_FAILED; - } - // Obtain path description - Optional pathDescriptionOpt = getPathDescriptionFromDatastore(serviceName); - PathDescription pathDescription; - if (pathDescriptionOpt.isPresent()) { - pathDescription = pathDescriptionOpt.get(); - this.networkModelWavelengthService.freeWavelengths(pathDescription); - responseCode = ResponseCodes.RESPONSE_OK; - message = "service deleted !"; - } else { - LOG.error("failed to get pathDescription for service : {}", serviceName); - responseCode = ResponseCodes.RESPONSE_FAILED; - message = "failed to get pathDescription for service : " + serviceName; - } - notification = new ServiceRpcResultSpBuilder().setNotificationType(ServicePathNotificationTypes.ServiceDelete) - .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Successful) - .setStatusMessage("Service deleted").build(); - sendNotifications(notification); - responseCode = ResponseCodes.RESPONSE_OK; - ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) - .setRequestId(input.getServiceHandlerHeader().getRequestId()) - .setResponseCode(responseCode) - .setResponseMessage(message); - ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon.build()) - .build(); - return RpcResultBuilder.success(output).buildFuture(); - } - - public ListenableFuture> - serviceImplementation(ServiceImplementationRequestInput input) { - LOG.info("serviceImplementation request ..."); - String message = ""; - String responseCode = null; - notification = new ServiceRpcResultSpBuilder() - .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) - .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending) - .setStatusMessage("Service compliant, submitting serviceImplementation Request ...").build(); - sendNotifications(notification); - try { - LOG.info("Wait for 10s til beginning the Renderer serviceImplementation request"); - Thread.sleep(10000); // sleep for 1s - } catch (InterruptedException e) { - message = "implementing service failed !"; - LOG.error(message); - responseCode = ResponseCodes.RESPONSE_FAILED; - } - this.networkModelWavelengthService.useWavelengths(input.getPathDescription()); - message = "service implemented !"; - PathTopology pathTopology = new PathTopologyBuilder().build(); - notification = new ServiceRpcResultSpBuilder() - .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) - .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Successful) - .setStatusMessage("Service implemented").setPathTopology(pathTopology).build(); - sendNotifications(notification); - responseCode = ResponseCodes.RESPONSE_OK; - ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) - .setRequestId(input.getServiceHandlerHeader().getRequestId()) - .setResponseCode(responseCode) - .setResponseMessage(message); - ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon.build()) - .build(); - return RpcResultBuilder.success(output).buildFuture(); - } - - private Optional getPathDescriptionFromDatastore(String serviceName) { - InstanceIdentifier pathDescriptionIID = InstanceIdentifier.create(ServicePathList.class) - .child(ServicePaths.class, new ServicePathsKey(serviceName)).child(PathDescription.class); - ReadOnlyTransaction pathDescReadTx = this.dataBroker.newReadOnlyTransaction(); - try { - LOG.debug("Getting path description for service {}", serviceName); - return pathDescReadTx.read(LogicalDatastoreType.OPERATIONAL, pathDescriptionIID) - .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException e) { - LOG.warn("Exception while getting path description from datastore {} for service {}!", pathDescriptionIID, - serviceName, e); - return Optional.absent(); - } - } -} diff --git a/servicehandler/src/main/resources/org/opendaylight/blueprint/servicehandler-blueprint.xml b/servicehandler/src/main/resources/org/opendaylight/blueprint/servicehandler-blueprint.xml index be736445e..d1d73e87a 100644 --- a/servicehandler/src/main/resources/org/opendaylight/blueprint/servicehandler-blueprint.xml +++ b/servicehandler/src/main/resources/org/opendaylight/blueprint/servicehandler-blueprint.xml @@ -24,6 +24,10 @@ Author: Martial Coulibaly on behalf of Orange interface="org.opendaylight.controller.md.sal.binding.api.NotificationService" odl:type="default" /> + + @@ -39,6 +43,7 @@ Author: Martial Coulibaly on behalf of Orange + diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtilsTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtilsTest.java index ebc7294ce..d7e373137 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtilsTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtilsTest.java @@ -44,7 +44,7 @@ public class ModelMappingUtilsTest extends AbstractTest { NotificationPublishService notificationPublishService = new NotificationPublishServiceMock(); PathComputationService pathComputationService = new PathComputationServiceImpl(getDataBroker(), notificationPublishService); - pceServiceWrapper = new PCEServiceWrapper(pathComputationService); + pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService); this.pathComputationRequestOutput = pceServiceWrapper.performPCE(ServiceDataUtils.buildServiceCreateInput(), true); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java index f17513e4d..24ab643d1 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java @@ -8,9 +8,7 @@ package org.opendaylight.transportpce.servicehandler.impl; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; @@ -20,7 +18,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Optional; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -33,11 +30,9 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.transportpce.common.OperationResult; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.pce.service.PathComputationService; -import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl; -import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock; import org.opendaylight.transportpce.pce.utils.PceTestData; import org.opendaylight.transportpce.pce.utils.PceTestUtils; import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService; @@ -45,18 +40,24 @@ import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOpe import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; import org.opendaylight.transportpce.servicehandler.ServiceEndpointType; 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.stub.StubPceServiceOperations; import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.utils.MockedNotificationServiceWrapper; import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult; import org.opendaylight.transportpce.test.AbstractTest; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.TransportpcePceListener; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutputBuilder; -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.ServiceImplementationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.TransportpceRendererListener; 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.ServiceNotificationTypes; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder; @@ -67,7 +68,6 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev1 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder; 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.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; @@ -78,13 +78,13 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.Service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInputBuilder; -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.TempServiceDeleteInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteOutput; 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.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder; +import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,124 +96,93 @@ public class ServiceHandlerImplTest extends AbstractTest { private PathComputationService pathComputationService; private RendererServiceOperations rendererServiceOperations; - private NetworkModelWavelengthService networkModelWavelengthService; private ServicehandlerImpl serviceHandler; + private PceListenerImpl pceListenerImpl; + private RendererListenerImpl rendererListenerImpl; private ListeningExecutorService executor; + private NotificationPublishService notificationPublishService; + private NotificationService notificationService; + private ListenerRegistration pcelistenerRegistration; + private ListenerRegistration rendererlistenerRegistration; + private MockedNotificationServiceWrapper mockedNotificationServiceWrapper; @Mock private ServiceDataStoreOperations serviceDataStoreOperationsMock; - @Mock private PCEServiceWrapper pceServiceWrapperMock; - + @Mock + private RendererServiceWrapper rendererServiceWrapperMock; + @Mock + private PathComputationService pathComputationServiceMock; @Mock private RendererServiceOperations rendererServiceOperationsMock; - @Mock private ComplianceCheckResult complianceCheckResultMock; - @Mock private Optional servicesOptionalMock; - + @Mock + private PceListenerImpl pceListenerImplMock; + @Mock + private RendererListenerImpl rendererListenerImplMock; + @Mock + private NotificationPublishService notificationPublishServiceMock; + @Mock + private NetworkModelWavelengthService networkModelWavelengthServiceMock; @InjectMocks private ServicehandlerImpl serviceHandlerImplMock; @Before public void setUp() { this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, - this.rendererServiceOperations, this.networkModelWavelengthService); - this.serviceHandlerImplMock = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null); + this.rendererServiceOperations, this.notificationPublishService, this.pceListenerImpl, + this.rendererListenerImpl, this.networkModelWavelengthServiceMock); + this.serviceHandlerImplMock = + new ServicehandlerImpl(getDataBroker(), this.pathComputationService, this.rendererServiceOperations, + notificationPublishService, pceListenerImpl, rendererListenerImpl, null); MockitoAnnotations.initMocks(this); } public ServiceHandlerImplTest() throws Exception { - NotificationPublishService notificationPublishService = new NotificationPublishServiceMock(); - this.pathComputationService = new PathComputationServiceImpl(getDataBroker(), notificationPublishService); + this.mockedNotificationServiceWrapper = new MockedNotificationServiceWrapper(getNotificationPublishService()); + this.notificationPublishService = this.mockedNotificationServiceWrapper.getMockedNotificationService(); + this.notificationService = getNotificationService(); + this.pathComputationService = new StubPceServiceOperations(notificationPublishService); + this.rendererServiceOperations = new StubRendererServiceOperations(this.networkModelWavelengthServiceMock, + getDataBroker(), notificationPublishService); PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(), "topologyData/NW-simple-topology.xml"); - this.rendererServiceOperations = - new StubRendererServiceOperations(this.networkModelWavelengthService, getDataBroker(), - notificationPublishService); + this.pceListenerImpl = + new PceListenerImpl(rendererServiceOperations, pathComputationService, notificationPublishService, + null); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperationsMock); + this.pceListenerImpl.setServiceReconfigure(false); + this.rendererListenerImpl = + new RendererListenerImpl(pathComputationServiceMock, notificationPublishService); + this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperationsMock); this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS)); + pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl); + rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl); } + + @Test public void testCreateServiceValid() throws ExecutionException, InterruptedException { - ServiceCreateInput serviceInput = ServiceDataUtils.buildServiceCreateInput(); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( PceTestData.getPCE_simpletopology_test1_result((long) 5)) .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.pceServiceWrapperMock.performPCE(serviceInput, true)) .thenReturn(pathComputationRequestOutput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); - Mockito.when( - this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build())); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceInput.getServiceName(), - State.InService, State.InService)).thenReturn(OperationResult.ok("successful")); - Future> output0 = this.serviceHandlerImplMock.serviceCreate(serviceInput); Assert.assertNotNull(output0); Assert.assertTrue(output0.get().isSuccessful()); - Assert.assertEquals(output0.get().getResult(), - ModelMappingUtils.createCreateServiceReply(serviceInput, ResponseCodes.FINAL_ACK_YES, - "Service rendered successfully !", ResponseCodes.RESPONSE_OK).get().getResult()); - Assert.assertEquals(0, output0.get().getErrors().size()); - } - - private ListenableFuture returnFuture(T output) { - return executor.submit(new Callable() { - - @Override - public T call() throws Exception { - return output; - } - }); - } - - @Test - public void createTempServiceHandlerServiceCreateValid() throws ExecutionException, InterruptedException { - TempServiceCreateInput serviceInput = ServiceDataUtils.buildTempServiceCreateInput(); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); - PathComputationRequestOutput pathComputationRequestOutput = - new PathComputationRequestOutputBuilder(PceTestData.getPCE_simpletopology_test1_result((long) 5)) - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.pceServiceWrapperMock.performPCE(serviceInput, true)) - .thenReturn(pathComputationRequestOutput); - Mockito.when(this.serviceDataStoreOperationsMock.createTempService(any(TempServiceCreateInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); - Mockito.when( - this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build())); - Mockito.when(this.serviceDataStoreOperationsMock.modifyTempService(serviceInput.getCommonId(), State.InService, - State.InService)).thenReturn(OperationResult.ok("successful")); - Future> output0 = - this.serviceHandlerImplMock.tempServiceCreate(serviceInput); - Assert.assertNotNull(output0); - Assert.assertTrue(output0.get().isSuccessful()); Assert.assertEquals(output0.get().getResult(), ModelMappingUtils.createCreateServiceReply(serviceInput, - ResponseCodes.FINAL_ACK_YES, "Service rendered successfully !", ResponseCodes.RESPONSE_OK).get() - .getResult()); + ResponseCodes.FINAL_ACK_NO,"PCE calculation in progress", ResponseCodes.RESPONSE_OK) + .get().getResult()); Assert.assertEquals(0, output0.get().getErrors().size()); } @@ -365,7 +334,7 @@ public class ServiceHandlerImplTest extends AbstractTest { @Test public void createServiceHandlerNotValidServiceAEndRateIsNull() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandler = - new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null); + new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null, null, null, null); ServiceCreateInput notValidServiceAEnd = ServiceDataUtils.buildServiceCreateInput(); ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceAEnd); notValidServiceAEnd = buildInput.setServiceAEnd(ServiceDataUtils.getServiceAEndBuild().setServiceRate(null) @@ -379,7 +348,7 @@ public class ServiceHandlerImplTest extends AbstractTest { @Test public void createServiceHandlerNotValidServiceZEndRateIsNull() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandler = - new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null); + new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null, null, null, null); ServiceCreateInput notValidServiceZEnd = ServiceDataUtils.buildServiceCreateInput(); ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(notValidServiceZEnd); notValidServiceZEnd = buildInput.setServiceZEnd(ServiceDataUtils.getServiceZEndBuild().setServiceRate(null) @@ -543,7 +512,8 @@ public class ServiceHandlerImplTest extends AbstractTest { txDirectionBuilder.setLgx(lgx); serviceAEndBuilder.setTxDirection(txDirectionBuilder.build()); ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput); - this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null); + this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null, null, + null, null); return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get() .getResult(); } @@ -614,201 +584,16 @@ public class ServiceHandlerImplTest extends AbstractTest { @Test public void createServiceHandlerResponseCodesNotPassed() throws ExecutionException, InterruptedException { ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failed").build(); - PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( - PceTestData.getPCE_simpletopology_test1_result((long) 5)) - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) - .thenReturn(pathComputationRequestOutput); - ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); - verify(this.pceServiceWrapperMock).performPCE(serviceCreateInput, true); - } - - @Test - public void createServiceHandlerOperationResultNotPassed() throws ExecutionException, InterruptedException { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); - PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( - PceTestData.getPCE_simpletopology_test1_result((long) 5)) - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) - .thenReturn(pathComputationRequestOutput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), - any(PathComputationRequestOutput.class))) - .thenReturn(OperationResult.failed( - "Failed to create service " + serviceCreateInput.getServiceName() + " to Service List")); - ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); - verify(this.serviceDataStoreOperationsMock).createService(any(ServiceCreateInput.class), - any(PathComputationRequestOutput.class)); - } - - @Test - public void createServiceHandlerOperationServicePathSaveResultNotPassed() - throws ExecutionException, InterruptedException { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("PCE calculation failed").build(); PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( PceTestData.getPCE_simpletopology_test1_result((long) 5)) .setConfigurationResponseCommon(configurationResponseCommon).build(); Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) .thenReturn(pathComputationRequestOutput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))) - .thenReturn(OperationResult.failed("Failed to create servicePath " + serviceCreateInput.getServiceName() - + " to ServicePath List")); ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); - verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class)); - } - - @Test - public void createServiceHandlerModifyServicePassed() throws ExecutionException, InterruptedException { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); - PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( - PceTestData.getPCE_simpletopology_test1_result((long) 5)) - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) - .thenReturn(pathComputationRequestOutput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); - Mockito.when( - this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build())); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(), - State.InService, State.InService)).thenReturn(OperationResult.ok("successful")); - ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); - verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService, - State.InService); - } - - @Test - public void createServiceHandlerModifyServiceNotPassed() throws ExecutionException, InterruptedException { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); - PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( - PceTestData.getPCE_simpletopology_test1_result((long) 5)) - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) - .thenReturn(pathComputationRequestOutput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); - Mockito.when( - this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build())); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceCreateInput.getServiceName(), - State.InService, State.InService)).thenReturn(OperationResult.failed("failure")); - ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); - verify(this.serviceDataStoreOperationsMock).modifyService(serviceCreateInput.getServiceName(), State.InService, - State.InService); - } - - @Test - public void createServiceHandlerServiceImplementationNotPassed() throws ExecutionException, InterruptedException { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); - PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( - PceTestData.getPCE_simpletopology_test1_result((long) 5)) - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) - .thenReturn(pathComputationRequestOutput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build(); - Mockito.when( - this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build())); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName())) - .thenReturn(OperationResult.ok("successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName())) - .thenReturn(OperationResult.ok("successful")); - ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); - verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName()); - verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName()); - } - - @Test - public void createServiceHandlerServiceImplementationNotPassed2() throws ExecutionException, InterruptedException { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); - PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( - PceTestData.getPCE_simpletopology_test1_result((long) 5)) - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.pceServiceWrapperMock.performPCE(serviceCreateInput, true)) - .thenReturn(pathComputationRequestOutput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("failure").build(); - Mockito.when( - this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build())); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(serviceCreateInput.getServiceName())) - .thenReturn(OperationResult.failed("successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(serviceCreateInput.getServiceName())) - .thenReturn(OperationResult.failed("successful")); - ServiceCreateOutput result = this.serviceHandlerImplMock.serviceCreate(serviceCreateInput).get().getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); - verify(this.serviceDataStoreOperationsMock).deleteService(serviceCreateInput.getServiceName()); - verify(this.serviceDataStoreOperationsMock).deleteServicePath(serviceCreateInput.getServiceName()); } private ServiceCreateOutput getRxDirectionPortServiceCreateOutput(Port port, Lgx lgx) @@ -822,7 +607,8 @@ public class ServiceHandlerImplTest extends AbstractTest { rxDirectionBuilder.setLgx(lgx); serviceAEndBuilder.setRxDirection(rxDirectionBuilder.build()); ServiceCreateInputBuilder buildInput = new ServiceCreateInputBuilder(serviceCreateInput); - this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null); + this.serviceHandler = new ServicehandlerImpl(getDataBroker(), this.pathComputationService, null, null, null, + null, null); return serviceHandler.serviceCreate(buildInput.setServiceAEnd(serviceAEndBuilder.build()).build()).get() .getResult(); } @@ -998,57 +784,6 @@ public class ServiceHandlerImplTest extends AbstractTest { @Test public void deleteServiceNotPassed() throws ExecutionException, InterruptedException { - - ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput(); - Optional service = Optional.of(new ServicesBuilder().setServiceName("service 1").build()); - Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput( - new ServiceInput(serviceDeleteInput)); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("success").build(); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); - ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_FAILED); - } - - @Test - public void deleteServicePathNotPassed() throws ExecutionException, InterruptedException { - - ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput(); - Optional service = Optional.of(new ServicesBuilder().setServiceName("service 1").build()); - Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput( - new ServiceInput(serviceDeleteInput)); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) - .thenReturn(OperationResult.failed("failed")); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) - .thenReturn(OperationResult.failed("failed")); - ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); - } - - @Test - public void deleteServiceOperationNotPassed() throws ExecutionException, InterruptedException { - ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput(); Optional service = Optional.of(new ServicesBuilder().setServiceName("service 1").build()); Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service); @@ -1057,26 +792,21 @@ public class ServiceHandlerImplTest extends AbstractTest { new ServiceInput(serviceDeleteInput)); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("Renderer service delete failed !") + .build(); org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 .ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) - .thenReturn(OperationResult.ok("success")); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) - .thenReturn(OperationResult.ok("success")); + Mockito.when(this.rendererServiceWrapperMock.performRenderer(input, + ServiceNotificationTypes.ServiceDeleteResult)).thenReturn(output); ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); + Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode()); } @Test public void deleteServiceIfServicePresentAndValid() throws ExecutionException, InterruptedException { - ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput(); Optional service = Optional.of(new ServicesBuilder().setServiceName("service 1").build()); Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service); @@ -1084,60 +814,24 @@ public class ServiceHandlerImplTest extends AbstractTest { .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput( new ServiceInput(serviceDeleteInput)); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress") + .build(); org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer .rev171017.ServiceDeleteOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) - .thenReturn(OperationResult.ok("success")); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) - .thenReturn(OperationResult.ok("success")); + Mockito.when( + this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult)) + .thenReturn(output); ServiceDeleteOutput result = this.serviceHandlerImplMock.serviceDelete(serviceDeleteInput).get().getResult(); Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); - Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); - } - - @Test - public void deleteTempServiceIfServicePresentAndValid() throws ExecutionException, InterruptedException { - - TempServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildTempServiceDeleteInput(); - Optional service = Optional.of(new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014 - .temp.service.list.ServicesBuilder().setCommonId("service 1").build()); - Mockito.when(this.serviceDataStoreOperationsMock.getTempService("service 1")).thenReturn(service); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput( - new ServiceInput(serviceDeleteInput)); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer - .rev171017.ServiceDeleteOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteServicePath(serviceDeleteInput.getCommonId())) - .thenReturn(OperationResult.ok("success")); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteTempService(serviceDeleteInput.getCommonId())) - .thenReturn(OperationResult.ok("success")); - TempServiceDeleteOutput result = this.serviceHandlerImplMock.tempServiceDelete(serviceDeleteInput).get() - .getResult(); - Assert.assertEquals(result.getConfigurationResponseCommon().getAckFinalIndicator(), - ResponseCodes.FINAL_ACK_YES); + ResponseCodes.FINAL_ACK_NO); Assert.assertEquals(result.getConfigurationResponseCommon().getResponseCode(), ResponseCodes.RESPONSE_OK); } @Test public void rerouteServiceIsNotPresent() throws ExecutionException, InterruptedException { - ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput(); ServiceRerouteOutput result = this.serviceHandler.serviceReroute(input).get().getResult(); Assert.assertEquals(result.getStatus(), RpcStatus.Failed); @@ -1147,12 +841,8 @@ public class ServiceHandlerImplTest extends AbstractTest { @Test public void rerouteServiceIfserviceIsPresent() throws ExecutionException, InterruptedException { - ServiceRerouteInput serviceRerouteinput = ServiceDataUtils.buildServiceRerouteInput(); - ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput(); ServiceCreateInput serviceInput = ServiceDataUtils.buildServiceCreateInput(); - - /** Mock RPC service-delete. */ Services serviceMock = ModelMappingUtils.mappingServices(serviceInput, null); Optional service = Optional.of(serviceMock); Mockito.when(this.serviceDataStoreOperationsMock.getService(any(String.class))).thenReturn(service); @@ -1160,43 +850,15 @@ public class ServiceHandlerImplTest extends AbstractTest { .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, service.get()); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Service reroute successfully !") + .build(); org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer .rev171017.ServiceDeleteOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); - Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) - .thenReturn(OperationResult.ok("success")); - Mockito.when(this.serviceDataStoreOperationsMock - .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) - .thenReturn(OperationResult.ok("success")); - - ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); - PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( - PceTestData.getPCE_simpletopology_test1_result((long) 5)) - .setConfigurationResponseCommon(configurationResponseCommon2).build(); - - /** Mock RPC service-create. */ - Mockito.when(this.pceServiceWrapperMock.performPCE(any(ServiceCreateInput.class), any(Boolean.class))) - .thenReturn(pathComputationRequestOutput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - ConfigurationResponseCommon configurationResponseCommon3 = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); Mockito.when( - this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon3).build())); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(any(String.class), any(State.class), - any(State.class))).thenReturn(OperationResult.ok("successful")); - + this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult)) + .thenReturn(output); ServiceRerouteOutput result = this.serviceHandlerImplMock.serviceReroute(serviceRerouteinput).get().getResult(); Assert.assertEquals(org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful, result.getStatus()); diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImplTest.java new file mode 100644 index 000000000..f2850990e --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImplTest.java @@ -0,0 +1,314 @@ +/* + * Copyright © 2018 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.listeners; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.verifyZeroInteractions; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.opendaylight.transportpce.common.OperationResult; +import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.ServiceInput; +import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; +import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; +import org.opendaylight.transportpce.servicehandler.utils.InjectField; +import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; +import org.opendaylight.transportpce.test.AbstractTest; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResult; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResultBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; + + +public class PceListenerImplTest extends AbstractTest { + + @Mock + private ServiceDataStoreOperations serviceDataStoreOperationsMock; + @Mock + private RendererServiceOperations rendererServiceOperationsMock; + @Mock + private PCEServiceWrapper pceServiceWrapperMock; + @Mock + private ServiceInput serviceInputMock; + @InjectMocks + private PceListenerImpl pceListenerImplMock; + + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void onServicePathRpcResultServiceInputIsNull() { + InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); + InjectField.inject(this.pceListenerImplMock, "tempService", false); + InjectField.inject(this.pceListenerImplMock, "input", null); + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( + ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true); + this.pceListenerImplMock.onServicePathRpcResult(notification); + verifyNoMoreInteractions(this.serviceDataStoreOperationsMock); + verifyNoMoreInteractions(this.rendererServiceOperationsMock); + } + + @Test + public void onServicePathRpcResultPathDescriptionIsNull() { + InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); + InjectField.inject(this.pceListenerImplMock, "tempService", false); + InjectField.inject(this.pceListenerImplMock, "input", null); + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( + ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", false); + this.pceListenerImplMock.onServicePathRpcResult(notification); + verifyNoMoreInteractions(this.serviceDataStoreOperationsMock); + verifyNoMoreInteractions(this.rendererServiceOperationsMock); + } + + @Test + public void onServicePathRpcResultPCRSuccess() { + ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); + Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); + Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); + Mockito.when(this.serviceInputMock.getSdncRequestHeader()) + .thenReturn(serviceCreateInput.getSdncRequestHeader()); + InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); + InjectField.inject(this.pceListenerImplMock, "tempService", false); + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( + ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true); + this.pceListenerImplMock.onServicePathRpcResult(notification); + verify(this.serviceDataStoreOperationsMock).createService(any(ServiceCreateInput.class)); + verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceInput.class), + any(PathComputationRequestOutput.class)); + verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class)); + } + + @Test + public void onServicePathRpcResultTempPCRSuccess() { + TempServiceCreateInput tempServiceCreateInput = ServiceDataUtils.buildTempServiceCreateInput(); + Mockito.when(this.serviceInputMock.getTempServiceCreateInput()).thenReturn(tempServiceCreateInput); + Mockito.when(this.serviceDataStoreOperationsMock.createTempService(any(TempServiceCreateInput.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(tempServiceCreateInput.getServiceAEnd()); + Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(tempServiceCreateInput.getServiceZEnd()); + Mockito.when(this.serviceInputMock.getSdncRequestHeader()) + .thenReturn(tempServiceCreateInput.getSdncRequestHeader()); + InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); + InjectField.inject(this.pceListenerImplMock, "tempService", true); + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( + ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true); + this.pceListenerImplMock.onServicePathRpcResult(notification); + verify(this.serviceDataStoreOperationsMock).createTempService(any(TempServiceCreateInput.class)); + verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceInput.class), + any(PathComputationRequestOutput.class)); + verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class)); + } + + @Test + public void onServicePathRpcResultCRRSuccessWithNoReconfigure() { + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( + ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Successful, "", false); + Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); + InjectField.inject(this.pceListenerImplMock, "tempService", false); + this.pceListenerImplMock.onServicePathRpcResult(notification); + verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); + verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); + } + + @Test + public void onServicePathRpcResultCRRSuccessWithReconfigure() { + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( + ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Successful, "", false); + Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", true); + InjectField.inject(this.pceListenerImplMock, "tempService", false); + ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); + Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); + this.pceListenerImplMock.onServicePathRpcResult(notification); + verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); + verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); + verify(this.pceServiceWrapperMock).performPCE(serviceCreateInput, true); + } + + @Test + public void onServicePathRpcResultCRRTempSuccess() { + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( + ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Successful, "", false); + Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteTempService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); + InjectField.inject(this.pceListenerImplMock, "tempService", true); + this.pceListenerImplMock.onServicePathRpcResult(notification); + verify(this.serviceDataStoreOperationsMock).deleteTempService(any(String.class)); + verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); + } + + @Test + public void onServicePathRpcResultCRRFailed() { + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( + ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Failed, "", false); + InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); + InjectField.inject(this.pceListenerImplMock, "tempService", false); + this.pceListenerImplMock.onServicePathRpcResult(notification); + verifyZeroInteractions(this.serviceDataStoreOperationsMock); + verifyZeroInteractions(this.pceServiceWrapperMock); + } + + @Test + public void onServicePathRpcResultCRRTempFailed() { + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( + ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Failed, "", false); + InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); + InjectField.inject(this.pceListenerImplMock, "tempService", true); + this.pceListenerImplMock.onServicePathRpcResult(notification); + verifyZeroInteractions(this.serviceDataStoreOperationsMock); + verifyZeroInteractions(this.pceServiceWrapperMock); + } + + @Test + public void onServicePathRpcResultRepeat() { + ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); + Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); + Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); + Mockito.when(this.serviceInputMock.getSdncRequestHeader()) + .thenReturn(serviceCreateInput.getSdncRequestHeader()); + this.pceListenerImplMock.onServicePathRpcResult(ServiceDataUtils.buildServicePathRpcResult()); + verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class)); + this.pceListenerImplMock.onServicePathRpcResult(ServiceDataUtils.buildServicePathRpcResult()); + verifyNoMoreInteractions(this.rendererServiceOperationsMock); + } + + @Test + public void onServicePathRpcResultFailed() { + this.pceListenerImplMock.onServicePathRpcResult(ServiceDataUtils.buildFailedPceServicePathRpcResult()); + verifyZeroInteractions(this.rendererServiceOperationsMock); + } + + @Test + public void onServicePathRpcResultRepeatFailedCompareCase1() { + ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); + Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); + Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); + Mockito.when(this.serviceInputMock.getSdncRequestHeader()) + .thenReturn(serviceCreateInput.getSdncRequestHeader()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(); + this.pceListenerImplMock.onServicePathRpcResult(notification); + Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(serviceCreateInput.getServiceName()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + ServicePathRpcResult notification2 = new ServicePathRpcResultBuilder(notification) + .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve).build(); + this.pceListenerImplMock.onServicePathRpcResult(notification2); + verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class)); + } + + @Test + public void onServicePathRpcResultRepeatFailedCompareCase2() { + ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); + Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); + Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); + Mockito.when(this.serviceInputMock.getSdncRequestHeader()) + .thenReturn(serviceCreateInput.getSdncRequestHeader()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(); + this.pceListenerImplMock.onServicePathRpcResult(notification); + Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(serviceCreateInput.getServiceName()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + ServicePathRpcResult notification2 = + new ServicePathRpcResultBuilder(notification).setServiceName("service 2").build(); + this.pceListenerImplMock.onServicePathRpcResult(notification2); + verify(this.rendererServiceOperationsMock, times(2)) + .serviceImplementation(any(ServiceImplementationRequestInput.class)); + } + + @Test + public void onServicePathRpcResultRepeatFailedCompareCase3() { + ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); + Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); + Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); + Mockito.when(this.serviceInputMock.getSdncRequestHeader()) + .thenReturn(serviceCreateInput.getSdncRequestHeader()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(); + this.pceListenerImplMock.onServicePathRpcResult(notification); + Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(serviceCreateInput.getServiceName()); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + ServicePathRpcResult notification2 = + new ServicePathRpcResultBuilder(notification).setStatus(RpcStatusEx.Failed).build(); + this.pceListenerImplMock.onServicePathRpcResult(notification2); + verify(this.rendererServiceOperationsMock, times(1)) + .serviceImplementation(any(ServiceImplementationRequestInput.class)); + } +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImplTest.java new file mode 100644 index 000000000..0059551f2 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImplTest.java @@ -0,0 +1,242 @@ +/* + * Copyright © 2017 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.listeners; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.verifyZeroInteractions; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.common.OperationResult; +import org.opendaylight.transportpce.pce.service.PathComputationService; +import org.opendaylight.transportpce.servicehandler.ServiceInput; +import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; +import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; +import org.opendaylight.transportpce.servicehandler.utils.InjectField; +import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; +import org.opendaylight.transportpce.test.AbstractTest; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSp; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSpBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; + +public class RendererListenerImplTest extends AbstractTest { + + @InjectMocks + private RendererListenerImpl rendererListenerImplMock; + @Mock + private PathComputationService pathComputationService; + @Mock + private NotificationPublishService notificationPublishService; + @Mock + private ServiceInput serviceInputMock; + @Mock + private ServiceDataStoreOperations serviceDataStoreOperationsMock; + @Mock + private PCEServiceWrapper pceServiceWrapperMock; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void onServiceRpcResultServiceInputIsNull() { + InjectField.inject(this.rendererListenerImplMock, "tempService", false); + InjectField.inject(this.rendererListenerImplMock, "input", null); + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( + ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Successful, ""); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(notification.getServiceName())) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(notification.getServiceName())) + .thenReturn(OperationResult.ok("Successful")); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verifyNoMoreInteractions(this.pceServiceWrapperMock); + } + + @Test + public void onServiceRpcResultSIRSuccess() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( + ServicePathNotificationTypes.ServiceImplementationRequest, "service 1", RpcStatusEx.Successful, ""); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, + State.InService)) + .thenReturn(OperationResult.ok("Successful")); + InjectField.inject(this.rendererListenerImplMock, "tempService", false); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.serviceDataStoreOperationsMock).modifyService(any(String.class), any(State.class), + any(State.class)); + } + + @Test + public void onServiceRpcResultSIRTempSuccess() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( + ServicePathNotificationTypes.ServiceImplementationRequest, "service 1", RpcStatusEx.Successful, ""); + Mockito.when(this.serviceDataStoreOperationsMock.modifyTempService(notification.getServiceName(), + State.InService, State.InService)).thenReturn(OperationResult.ok("Successful")); + InjectField.inject(this.rendererListenerImplMock, "tempService", true); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.serviceDataStoreOperationsMock).modifyTempService(any(String.class), any(State.class), + any(State.class)); + } + + @Test + public void onServiceRpcResultSIRFailed() { + InjectField.inject(this.rendererListenerImplMock, "tempService", false); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( + ServicePathNotificationTypes.ServiceImplementationRequest, "service 1", RpcStatusEx.Failed, ""); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); + verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); + } + + @Test + public void onServiceRpcResultSIRTempFailed() { + InjectField.inject(this.rendererListenerImplMock, "tempService", true); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteTempService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( + ServicePathNotificationTypes.ServiceImplementationRequest, "service 1", RpcStatusEx.Failed, ""); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); + verify(this.serviceDataStoreOperationsMock).deleteTempService(any(String.class)); + } + + @Test + public void onServiceRpcResultSDSuccess() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( + ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Successful, ""); + Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); + Mockito.when(this.pceServiceWrapperMock.cancelPCEResource(notification.getServiceName(), + ServiceNotificationTypes.ServiceDeleteResult)).thenReturn(null); + InjectField.inject(this.rendererListenerImplMock, "tempService", false); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.pceServiceWrapperMock).cancelPCEResource(any(String.class), any(ServiceNotificationTypes.class)); + } + + @Test + public void onServiceRpcResultSDTempSuccess() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( + ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Successful, ""); + Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); + Mockito.when(this.pceServiceWrapperMock.cancelPCEResource(notification.getServiceName(), + ServiceNotificationTypes.ServiceDeleteResult)).thenReturn(null); + InjectField.inject(this.rendererListenerImplMock, "tempService", true); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.pceServiceWrapperMock).cancelPCEResource(any(String.class), any(ServiceNotificationTypes.class)); + } + + @Test + public void onServiceRpcResultSDFailed() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( + ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Failed, ""); + InjectField.inject(this.rendererListenerImplMock, "tempService", true); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verifyZeroInteractions(this.pceServiceWrapperMock); + } + + @Test + public void onServiceRpcResultSDTempFailed() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( + ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Failed, ""); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verifyZeroInteractions(this.pceServiceWrapperMock); + } + + @Test + public void onServiceRpcResultSpRepeat() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp(); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, + State.InService)) + .thenReturn(OperationResult.ok("Successful")); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.serviceDataStoreOperationsMock).modifyService(any(String.class), any(State.class), + any(State.class)); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verifyZeroInteractions(this.serviceDataStoreOperationsMock); + } + + @Test + public void onServiceRpcResultSpFailed() { + ServiceRpcResultSp notification = ServiceDataUtils.buildFailedServiceRpcResultSp(); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); + verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); + } + + @Test + public void onServiceRpcResultSpRepeatFailedCompareCase1() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp(); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, + State.InService)).thenReturn(OperationResult.ok("Successful")); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.serviceDataStoreOperationsMock).modifyService(any(String.class), any(State.class), + any(State.class)); + ServiceRpcResultSp notification2 = new ServiceRpcResultSpBuilder(notification) + .setNotificationType(ServicePathNotificationTypes.ServiceDelete).build(); + Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); + Mockito.when(this.pceServiceWrapperMock.cancelPCEResource(notification.getServiceName(), + ServiceNotificationTypes.ServiceDeleteResult)).thenReturn(null); + this.rendererListenerImplMock.onServiceRpcResultSp(notification2); + verify(this.pceServiceWrapperMock).cancelPCEResource(any(String.class), any(ServiceNotificationTypes.class)); + } + + @Test + public void onServiceRpcResultSpRepeatFailedCompareCase2() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp(); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, + State.InService)).thenReturn(OperationResult.ok("Successful")); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + ServiceRpcResultSp notification2 = + new ServiceRpcResultSpBuilder(notification).setServiceName("service 2").build(); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification2.getServiceName(), State.InService, + State.InService)).thenReturn(OperationResult.ok("Successful")); + this.rendererListenerImplMock.onServiceRpcResultSp(notification2); + verify(this.serviceDataStoreOperationsMock, times(2)).modifyService(any(String.class), any(State.class), + any(State.class)); + } + + @Test + public void onServiceRpcResultSpRepeatFailedCompareCase3() { + ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp(); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, + State.InService)).thenReturn(OperationResult.ok("Successful")); + this.rendererListenerImplMock.onServiceRpcResultSp(notification); + verify(this.serviceDataStoreOperationsMock).modifyService(any(String.class), any(State.class), + any(State.class)); + ServiceRpcResultSp notification2 = + new ServiceRpcResultSpBuilder(notification).setStatus(RpcStatusEx.Failed).build(); + Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) + .thenReturn(OperationResult.ok("Successful")); + this.rendererListenerImplMock.onServiceRpcResultSp(notification2); + verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); + verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); + } + +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listensers/PceListenserImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listensers/PceListenserImplTest.java deleted file mode 100644 index 80c4bc1e3..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listensers/PceListenserImplTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright © 2018 Orange, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.servicehandler.listensers; - -import org.junit.Test; -import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl; -import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResult; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResultBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; - - -public class PceListenserImplTest { - - private PceListenerImpl pceListener; - private ServicePathRpcResult servicePathRpcResult = null; - - public PceListenserImplTest() { - this.pceListener = new PceListenerImpl(); - this.servicePathRpcResult = ServiceDataUtils.buildServicePathRpcResult(); - } - - @Test - public void onServicePathRpcResultInitial() { - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - } - - @Test - public void onServicePathRpcResultRepeat() { - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - } - - @Test - public void onServicePathRpcResultRepeatFailed() { - this.servicePathRpcResult = ServiceDataUtils.buildFailedServicePathRpcResult(); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - } - - @Test - public void onServicePathRpcResultRepeatFailedCompareCase1() { - this.servicePathRpcResult = ServiceDataUtils.buildServicePathRpcResult(); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - this.servicePathRpcResult = new ServicePathRpcResultBuilder(this.servicePathRpcResult) - .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve).build(); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - } - - @Test - public void onServicePathRpcResultRepeatFailedCompareCase2() { - this.servicePathRpcResult = ServiceDataUtils.buildServicePathRpcResult(); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - this.servicePathRpcResult = new ServicePathRpcResultBuilder(this.servicePathRpcResult) - .setServiceName("service 2").build(); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - } - - @Test - public void onServicePathRpcResultRepeatFailedCompareCase3() { - this.servicePathRpcResult = ServiceDataUtils.buildServicePathRpcResult(); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - this.servicePathRpcResult = new ServicePathRpcResultBuilder(this.servicePathRpcResult) - .setStatus(RpcStatusEx.Failed).build(); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - } - - @Test - public void onServicePathRpcResultRepeatFailedCompareCase4() { - this.servicePathRpcResult = ServiceDataUtils.buildServicePathRpcResult(); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - this.servicePathRpcResult = new ServicePathRpcResultBuilder(this.servicePathRpcResult) - .setStatusMessage("failed").build(); - this.pceListener.onServicePathRpcResult(this.servicePathRpcResult); - } -} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapperTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapperTest.java index eec103d69..5daf5affd 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapperTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapperTest.java @@ -7,81 +7,159 @@ */ package org.opendaylight.transportpce.servicehandler.service; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; + +import com.google.common.util.concurrent.ListenableFuture; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.pce.service.PathComputationService; -import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl; -import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock; import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; import org.opendaylight.transportpce.test.AbstractTest; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; -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.SdncRequestHeader; -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.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; 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.TempServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInputBuilder; public class PCEServiceWrapperTest extends AbstractTest { - private PathComputationService pathComputationService; - private PCEServiceWrapper pceServiceWrapper; - private Method method; - private static String METHOD_NAME = "mappingCancelResourceReserve"; - private Class[] parameterTypes; - private Object[] parameters; - - - - public PCEServiceWrapperTest() { - NotificationPublishService notificationPublishService = new NotificationPublishServiceMock(); - this.pathComputationService = new PathComputationServiceImpl(getDataBroker(), notificationPublishService); - } + @Mock + private PathComputationService pathComputationServiceMock; + @Mock + private NotificationPublishService notificationPublishServiceMock; + @InjectMocks + private PCEServiceWrapper pceServiceWrapperMock; @Before public void init() throws NoSuchMethodException { - this.pceServiceWrapper = new PCEServiceWrapper(this.pathComputationService); - this.parameterTypes = new Class[2]; - this.parameterTypes[0] = java.lang.String.class; - this.parameterTypes[1] = SdncRequestHeader.class; - this.method = this.pceServiceWrapper.getClass().getDeclaredMethod(METHOD_NAME, this.parameterTypes); - this.method.setAccessible(true); - this.parameters = new Object[2]; + MockitoAnnotations.initMocks(this); } @Test public void performPCENullSdncRequestHeader() { ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput(); input = new ServiceCreateInputBuilder(input).setSdncRequestHeader(null).build(); - PathComputationRequestOutput pceResponse = this.pceServiceWrapper.performPCE(input, true); - Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon() - .getAckFinalIndicator()); + PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); + Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, + pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, + pceResponse.getConfigurationResponseCommon().getResponseCode()); + verifyZeroInteractions(this.pathComputationServiceMock); + } + + @Test + public void performPCENullServiceName() { + ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput(); + input = new ServiceCreateInputBuilder(input).setServiceName(null).build(); + PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); + Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, + pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, + pceResponse.getConfigurationResponseCommon().getResponseCode()); + verifyZeroInteractions(this.pathComputationServiceMock); + } + + @Test + public void performPCENullCommonId() { + TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput(); + input = new TempServiceCreateInputBuilder(input).setCommonId(null).build(); + PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); + Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, + pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, + pceResponse.getConfigurationResponseCommon().getResponseCode()); + verifyZeroInteractions(this.pathComputationServiceMock); + } + + + @Test + public void cancelPCEResourceNullServiceName() { + CancelResourceReserveOutput pceResponse = + this.pceServiceWrapperMock.cancelPCEResource(null, ServiceNotificationTypes.ServiceDeleteResult); + Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, + pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, + pceResponse.getConfigurationResponseCommon().getResponseCode()); + verifyZeroInteractions(this.pathComputationServiceMock); } @Test - public void mappingCancelResourceReserveNullSdncRequestHeader() - throws InvocationTargetException, IllegalAccessException { - this.parameters[0] = "service 1"; - this.parameters[1] = null; - CancelResourceReserveInput result = (CancelResourceReserveInput)this.method.invoke(this.pceServiceWrapper, - this.parameters); - Assert.assertEquals("service 1", result.getServiceName()); + public void cancelPCEResourceValid() { + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); + CancelResourceReserveOutput output = new CancelResourceReserveOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + ListenableFuture response = ServiceDataUtils.returnFuture(output); + Mockito.when(this.pathComputationServiceMock.cancelResourceReserve(any(CancelResourceReserveInput.class))) + .thenReturn(response); + CancelResourceReserveOutput pceResponse = + this.pceServiceWrapperMock.cancelPCEResource("service 1", ServiceNotificationTypes.ServiceDeleteResult); + Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, + pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_OK, + pceResponse.getConfigurationResponseCommon().getResponseCode()); + Assert.assertEquals("PCE calculation in progress", + pceResponse.getConfigurationResponseCommon().getResponseMessage()); + verify(this.pathComputationServiceMock).cancelResourceReserve(any(CancelResourceReserveInput.class)); + } + + @Test + public void performPCEValid() { + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); + PathComputationRequestOutput output = new PathComputationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + ListenableFuture response = ServiceDataUtils.returnFuture(output); + Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class))) + .thenReturn(response); + ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput(); + PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); + Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, + pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_OK, + pceResponse.getConfigurationResponseCommon().getResponseCode()); + Assert.assertEquals("PCE calculation in progress", + pceResponse.getConfigurationResponseCommon().getResponseMessage()); + verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class))); } @Test - public void mappingCancelResourceReserveValidSdncRequestHeader() - throws InvocationTargetException, IllegalAccessException { - this.parameters[0] = "service 1"; - this.parameters[1] = new SdncRequestHeaderBuilder().setRequestId("request 1") - .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url").build(); - CancelResourceReserveInput result = (CancelResourceReserveInput)this.method.invoke(this.pceServiceWrapper, - this.parameters); - Assert.assertEquals("service 1", result.getServiceName()); - Assert.assertEquals("request 1", result.getServiceHandlerHeader().getRequestId()); + public void performPCETempValid() { + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); + PathComputationRequestOutput output = new PathComputationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + ListenableFuture response = ServiceDataUtils.returnFuture(output); + Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class))) + .thenReturn(response); + TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput(); + PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); + Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, + pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode()); + Assert.assertEquals("PCE calculation in progress", + pceResponse.getConfigurationResponseCommon().getResponseMessage()); + verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class))); } } diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java new file mode 100644 index 000000000..4d495055f --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java @@ -0,0 +1,159 @@ +/* + * Copyright © 2017 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.service; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; + +import com.google.common.util.concurrent.ListenableFuture; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.common.ResponseCodes; +import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; +import org.opendaylight.transportpce.servicehandler.ServiceInput; +import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; +import org.opendaylight.transportpce.test.AbstractTest; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInputBuilder; + +/** + * Test RendererServiceWrapper class. + * + * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange + * + */ +public class RendererServiceWrapperTest extends AbstractTest { + @Mock + private RendererServiceOperations rendererServiceOperationsMock; + @Mock + private NotificationPublishService notificationPublishService; + @InjectMocks + private RendererServiceWrapper rendererServiceWrapperMock; + + @Before + public void init() throws NoSuchMethodException { + MockitoAnnotations.initMocks(this); + } + + @Test + public void performRendererNullServiceHandlerHeader() { + ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer + .rev171017.ServiceDeleteInput serviceDeleteInput = + ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); + serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceHandlerHeader(null).build(); + ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput, + ServiceNotificationTypes.ServiceDeleteResult); + Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, + response.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, + response.getConfigurationResponseCommon().getResponseCode()); + verifyZeroInteractions(this.rendererServiceOperationsMock); + } + + @Test + public void performRendererNullServiceName() { + ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer + .rev171017.ServiceDeleteInput serviceDeleteInput = + ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); + serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceName(null).build(); + ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput, + ServiceNotificationTypes.ServiceDeleteResult); + Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, + response.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, + response.getConfigurationResponseCommon().getResponseCode()); + verifyZeroInteractions(this.rendererServiceOperationsMock); + } + + @Test + public void performRendererNullCommonId() { + TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(); + input = new TempServiceDeleteInputBuilder(input).setCommonId(null).build(); + ServiceDeleteOutput response = + this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult); + Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, + response.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, + response.getConfigurationResponseCommon().getResponseCode()); + verifyZeroInteractions(this.rendererServiceOperationsMock); + } + + + @Test + public void performRendererValid() { + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress") + .build(); + ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + ListenableFuture response = ServiceDataUtils.returnFuture(output); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any( + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 + .ServiceDeleteInput.class))).thenReturn(response); + ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer + .rev171017.ServiceDeleteInput serviceDeleteInput = + ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); + ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput, + ServiceNotificationTypes.ServiceDeleteResult); + Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, + rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_OK, + rendereResponse.getConfigurationResponseCommon().getResponseCode()); + Assert.assertEquals("Renderer service delete in progress", + rendereResponse.getConfigurationResponseCommon().getResponseMessage()); + verify(this.rendererServiceOperationsMock).serviceDelete(any( + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 + .ServiceDeleteInput.class)); + } + + @Test + public void performRendererTempValid() { + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress") + .build(); + ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + ListenableFuture response = ServiceDataUtils.returnFuture(output); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any( + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 + .ServiceDeleteInput.class))).thenReturn(response); + TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(); + ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(input, + ServiceNotificationTypes.ServiceDeleteResult); + Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, + rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + Assert.assertEquals(ResponseCodes.RESPONSE_OK, + rendereResponse.getConfigurationResponseCommon().getResponseCode()); + Assert.assertEquals("Renderer service delete in progress", + rendereResponse.getConfigurationResponseCommon().getResponseMessage()); + verify(this.rendererServiceOperationsMock).serviceDelete(any( + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer + .rev171017.ServiceDeleteInput.class)); + } +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java index d58ae187c..e2e62986b 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java @@ -19,6 +19,8 @@ import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock; import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl; +import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl; +import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl; import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations; import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; import org.opendaylight.transportpce.test.AbstractTest; @@ -39,12 +41,16 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { NotificationPublishService notificationPublishService = new NotificationPublishServiceMock(); PathComputationService pathComputationService = new PathComputationServiceImpl(getDataBroker(), notificationPublishService); - this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService); - this.rendererServiceOperations = - new StubRendererServiceOperations(this.networkModelWavelengthService, getDataBroker(), - notificationPublishService); + PceListenerImpl pceListenerImpl = new PceListenerImpl(rendererServiceOperations, pathComputationService, + notificationPublishService, null); + RendererListenerImpl rendererListenerImpl = + new RendererListenerImpl(pathComputationService, notificationPublishService); + this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService); + this.rendererServiceOperations = new StubRendererServiceOperations(this.networkModelWavelengthService, + null, notificationPublishService); this.serviceHandler = new ServicehandlerImpl(getDataBroker(), pathComputationService, - this.rendererServiceOperations, this.networkModelWavelengthService); + this.rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, + this.networkModelWavelengthService); } @@ -56,8 +62,8 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { @Test public void modifyIfServiceNotPresent() { - OperationResult result = this.serviceDataStoreOperations.modifyService("service 1", - State.InService, State.InService); + OperationResult result = + this.serviceDataStoreOperations.modifyService("service 1", State.InService, State.InService); Assert.assertEquals("Service " + "service 1" + " is not present!", result.getResultMessage()); } @@ -92,8 +98,7 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput, true); - OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput, - pathComputationRequestOutput); + OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput); String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 0); Assert.assertEquals(null, result); @@ -105,8 +110,7 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput, true); - OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput, - pathComputationRequestOutput); + OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput); String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 1); Assert.assertEquals(null, result); @@ -118,8 +122,7 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); PathComputationRequestOutput pathComputationRequestOutput = this.pceServiceWrapper.performPCE(createInput, true); - OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput, - pathComputationRequestOutput); + OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput); String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 2); Assert.assertEquals(null, result); diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/InjectField.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/InjectField.java new file mode 100644 index 000000000..8baad8f61 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/InjectField.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2017 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.utils; + + +/** + * Field Injection When Mocking Frameworks Fail. + * + * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange + * + */ +public final class InjectField { + + private InjectField() { + } + + public static void inject(final Object injectable, final String fieldname, final Object value) { + try { + final java.lang.reflect.Field field = injectable.getClass().getDeclaredField(fieldname); + final boolean origionalValue = field.isAccessible(); + field.setAccessible(true); + field.set(injectable, value); + field.setAccessible(origionalValue); + } catch (final NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e.getMessage(), e); + } + } +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/MockedNotificationServiceWrapper.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/MockedNotificationServiceWrapper.java new file mode 100644 index 000000000..e77bff71b --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/MockedNotificationServiceWrapper.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.utils; + +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; + +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSp; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSpBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.rpc.result.sp.PathTopologyBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class MockedNotificationServiceWrapper { + + private static final Logger LOG = LoggerFactory.getLogger(MockedNotificationServiceWrapper.class); + private final Notification publishedNotification; + private final NotificationPublishService notificationPublishService; + private Boolean rendererFailed = false; + + public MockedNotificationServiceWrapper(NotificationPublishService notificationPublishService) { + this.publishedNotification = null; + this.notificationPublishService = notificationPublishService; + } + + public NotificationPublishService getMockedNotificationService() throws InterruptedException { + final NotificationPublishService mockedNotificationService = mock(NotificationPublishService.class); + doAnswer(invocation -> { + final Object notif = invocation.getArguments()[0]; + LOG.info("notif received : {}", notif); + assertTrue(Notification.class.isAssignableFrom(notif.getClass())); + if (this.rendererFailed) { + LOG.info("putting failed renderer notification"); + ServiceRpcResultSp serviceRpcResultSp = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName("service 1").setStatus(RpcStatusEx.Failed).setStatusMessage("Renderer Failed") + .setPathTopology(new PathTopologyBuilder().build()).build(); + MockedNotificationServiceWrapper.this.notificationPublishService.putNotification(serviceRpcResultSp); + this.rendererFailed = false; + } else { + MockedNotificationServiceWrapper.this.notificationPublishService.putNotification((Notification) notif); + } + return null; + }).when(mockedNotificationService).putNotification(any(Notification.class)); + return mockedNotificationService; + } + + public void setRendererFailed() { + this.rendererFailed = true; + } +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ModelMappingUtils.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ModelMappingUtils.java new file mode 100644 index 000000000..367882f26 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ModelMappingUtils.java @@ -0,0 +1,353 @@ +/* + * Copyright © 2017 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler.utils; + +import com.google.common.util.concurrent.ListenableFuture; + +import org.opendaylight.transportpce.servicehandler.MappingConstraints; +import org.opendaylight.transportpce.servicehandler.ServiceInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.path.computation.request.input.ServiceAEnd; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.path.computation.request.input.ServiceAEndBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.path.computation.request.input.ServiceZEnd; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.path.computation.request.input.ServiceZEndBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescription; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInputBuilder; +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.ServiceImplementationRequestInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.response.parameters.ResponseParametersBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.LifecycleState; +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.ServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput; +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.TempServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutputBuilder; +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.TempServiceDeleteOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraintsBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.SoftConstraintsBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.endpoint.sp.RxDirection; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.endpoint.sp.RxDirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.endpoint.sp.TxDirection; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.endpoint.sp.TxDirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.handler.header.ServiceHandlerHeaderBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.path.PathDescriptionBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths; +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(ModelMappingUtils.class); + + private ModelMappingUtils() { + } + + public static ServiceImplementationRequestInput createServiceImplementationRequest(ServiceInput input, + PathDescription pathDescription) { + ServiceImplementationRequestInputBuilder serviceImplementationRequestInputBuilder = + new ServiceImplementationRequestInputBuilder(); + serviceImplementationRequestInputBuilder.setServiceName(input.getServiceName()); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.implementation + .request.input.ServiceAEndBuilder serviceAEnd = new org.opendaylight.yang.gen.v1.http.org.opendaylight + .transportpce.renderer.rev171017.service.implementation.request.input.ServiceAEndBuilder(); + serviceAEnd.setServiceFormat(input.getServiceAEnd().getServiceFormat()) + .setServiceRate(input.getServiceAEnd().getServiceRate()).setClli(input.getServiceAEnd().getClli()) + .setNodeId(input.getServiceAEnd().getNodeId()) + .setTxDirection(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types + .rev171016.service.endpoint.sp.TxDirectionBuilder() + .setPort(input.getServiceAEnd().getTxDirection().getPort()).build()) + .setRxDirection(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types + .rev171016.service.endpoint.sp.RxDirectionBuilder() + .setPort(input.getServiceAEnd().getRxDirection().getPort()).build()); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.implementation + .request.input.ServiceZEndBuilder serviceZEnd = new org.opendaylight.yang.gen.v1.http.org.opendaylight + .transportpce.renderer.rev171017.service.implementation.request.input.ServiceZEndBuilder(); + serviceZEnd.setServiceFormat(input.getServiceZEnd().getServiceFormat()) + .setServiceRate(input.getServiceZEnd().getServiceRate()).setClli(input.getServiceZEnd().getClli()) + .setNodeId(input.getServiceZEnd().getNodeId()) + .setTxDirection(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types + .rev171016.service.endpoint.sp.TxDirectionBuilder() + .setPort(input.getServiceZEnd().getTxDirection().getPort()).build()) + .setRxDirection(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types + .rev171016.service.endpoint.sp.RxDirectionBuilder() + .setPort(input.getServiceZEnd().getRxDirection().getPort()).build()); + serviceImplementationRequestInputBuilder.setServiceAEnd(serviceAEnd.build()); + serviceImplementationRequestInputBuilder.setServiceZEnd(serviceZEnd.build()); + serviceImplementationRequestInputBuilder.setServiceHandlerHeader( + new ServiceHandlerHeaderBuilder().setRequestId(input.getSdncRequestHeader().getRequestId()).build()); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.implementation + .request.input.PathDescriptionBuilder pathDescBuilder = new org.opendaylight.yang.gen.v1.http.org + .opendaylight.transportpce.renderer.rev171017.service.implementation.request.input + .PathDescriptionBuilder(); + pathDescBuilder.setAToZDirection(pathDescription.getAToZDirection()); + pathDescBuilder.setZToADirection(pathDescription.getZToADirection()); + serviceImplementationRequestInputBuilder.setPathDescription(pathDescBuilder.build()); + return serviceImplementationRequestInputBuilder.build(); + } + + public static org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 + .ServiceDeleteInput createServiceDeleteInput(ServiceInput serviceInput) { + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(); + builder.setServiceName(serviceInput.getServiceName()); + builder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder() + .setRequestId(serviceInput.getSdncRequestHeader().getRequestId()).build()); + return builder.build(); + } + + public static org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 + .ServiceDeleteInput createServiceDeleteInput(ServiceRerouteInput serviceRerouteinput, Services services) { + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(); + builder.setServiceName(serviceRerouteinput.getServiceName()); + builder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId( + services.getSdncRequestHeader().getRequestId()).build()); + return builder.build(); + } + + public static ServiceAEnd createServiceAEnd(org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types + .rev161014.ServiceEndpoint serviceAEnd) { + ServiceAEndBuilder serviceAEndBuilder = new ServiceAEndBuilder(); + serviceAEndBuilder.setClli(serviceAEnd.getClli()); + serviceAEndBuilder.setNodeId(serviceAEnd.getNodeId()); + serviceAEndBuilder.setRxDirection(createRxDirection(serviceAEnd.getRxDirection())); + serviceAEndBuilder.setServiceFormat(serviceAEnd.getServiceFormat()); + serviceAEndBuilder.setServiceRate(serviceAEnd.getServiceRate()); + serviceAEndBuilder.setTxDirection(createTxDirection(serviceAEnd.getTxDirection())); + return serviceAEndBuilder.build(); + } + + public static ServiceZEnd createServiceZEnd(org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types + .rev161014.ServiceEndpoint serviceZEnd) { + ServiceZEndBuilder serviceZEndBuilder = new ServiceZEndBuilder(); + serviceZEndBuilder.setClli(serviceZEnd.getClli()); + serviceZEndBuilder.setNodeId(serviceZEnd.getNodeId()); + serviceZEndBuilder.setRxDirection(createRxDirection(serviceZEnd.getRxDirection())); + serviceZEndBuilder.setServiceFormat(serviceZEnd.getServiceFormat()); + serviceZEndBuilder.setServiceRate(serviceZEnd.getServiceRate()); + serviceZEndBuilder.setTxDirection(createTxDirection(serviceZEnd.getTxDirection())); + return serviceZEndBuilder.build(); + } + + public static RxDirection createRxDirection(org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types + .rev161014.service.endpoint.RxDirection rxDirection) { + RxDirectionBuilder rxDirectionBuilder = new RxDirectionBuilder(); + rxDirectionBuilder.setPort(rxDirection.getPort()); + return rxDirectionBuilder.build(); + } + + public static TxDirection createTxDirection(org.opendaylight.yang.gen.v1.http.org.openroadm.common.service + .types.rev161014.service.endpoint.TxDirection txDirection) { + TxDirectionBuilder txDirectionBuilder = new TxDirectionBuilder(); + txDirectionBuilder.setPort(txDirection.getPort()); + return txDirectionBuilder.build(); + } + + public static ListenableFuture> createDeleteServiceReply(ServiceDeleteInput input, + String finalAck, String message, String responseCode) { + ConfigurationResponseCommonBuilder builder = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(finalAck).setResponseMessage(message).setResponseCode(responseCode); + if (input.getSdncRequestHeader() != null) { + builder.setRequestId(input.getSdncRequestHeader().getRequestId()); + } else { + builder.setRequestId(null); + } + ConfigurationResponseCommon configurationResponseCommon = builder.build(); + ServiceDeleteOutput output = + new ServiceDeleteOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon).build(); + return RpcResultBuilder.success(output).buildFuture(); + } + + public static ListenableFuture> createDeleteServiceReply( + TempServiceDeleteInput input, String finalAck, String message, String responseCode) { + ConfigurationResponseCommonBuilder builder = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(finalAck).setResponseMessage(message).setResponseCode(responseCode); + builder.setRequestId(null); + ConfigurationResponseCommon configurationResponseCommon = builder.build(); + TempServiceDeleteOutput output = new TempServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + return RpcResultBuilder.success(output).buildFuture(); + } + + public static ListenableFuture> createCreateServiceReply(ServiceCreateInput input, + String finalAck, String message, String responseCode) { + ResponseParametersBuilder responseParameters = new ResponseParametersBuilder(); + ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(finalAck).setResponseMessage(message).setResponseCode(responseCode); + if (input.getSdncRequestHeader() != null) { + configurationResponseCommon.setRequestId(input.getSdncRequestHeader().getRequestId()); + } else { + configurationResponseCommon.setRequestId(null); + } + ServiceCreateOutputBuilder output = + new ServiceCreateOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon.build()) + .setResponseParameters(responseParameters.build()); + return RpcResultBuilder.success(output.build()).buildFuture(); + } + + public static ListenableFuture> createCreateServiceReply( + TempServiceCreateInput input, String finalAck, String message, String responseCode) { + ResponseParametersBuilder responseParameters = new ResponseParametersBuilder(); + ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(finalAck).setResponseMessage(message).setResponseCode(responseCode); + if (input.getSdncRequestHeader() != null) { + configurationResponseCommon.setRequestId(input.getSdncRequestHeader().getRequestId()); + } else { + configurationResponseCommon.setRequestId(null); + } + TempServiceCreateOutputBuilder output = + new TempServiceCreateOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon.build()) + .setResponseParameters(responseParameters.build()); + return RpcResultBuilder.success(output.build()).buildFuture(); + } + + public static ListenableFuture> createRerouteServiceReply(ServiceRerouteInput input, + String finalAckYes, String message, RpcStatus status) { + ServiceRerouteOutputBuilder output = new ServiceRerouteOutputBuilder() + .setHardConstraints(null) + .setSoftConstraints(null) + .setStatus(status) + .setStatusMessage(message); + return RpcResultBuilder.success(output.build()).buildFuture(); + } + + public static Services mappingServices(ServiceCreateInput serviceCreateInput, + ServiceReconfigureInput serviceReconfigureInput) { + org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEnd aend = null; + org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceZEnd zend = null; + ServicesBuilder service = new ServicesBuilder(); + if (serviceCreateInput != null) { + aend = new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .ServiceAEndBuilder(serviceCreateInput.getServiceAEnd()).build(); + zend = new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .ServiceZEndBuilder(serviceCreateInput.getServiceZEnd()).build(); + service.setServiceName(serviceCreateInput.getServiceName()).setAdministrativeState(State.OutOfService) + .setOperationalState(State.OutOfService).setCommonId(serviceCreateInput.getCommonId()) + .setConnectionType(serviceCreateInput.getConnectionType()) + .setCustomer(serviceCreateInput.getCustomer()) + .setCustomerContact(serviceCreateInput.getCustomerContact()) + .setHardConstraints(serviceCreateInput.getHardConstraints()) + .setSoftConstraints(serviceCreateInput.getSoftConstraints()) + .setSdncRequestHeader(serviceCreateInput.getSdncRequestHeader()) + .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend); + } else if (serviceReconfigureInput != null) { + aend = new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .ServiceAEndBuilder(serviceReconfigureInput.getServiceAEnd()).build(); + zend = new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .ServiceZEndBuilder(serviceReconfigureInput.getServiceZEnd()).build(); + service.setServiceName(serviceReconfigureInput.getServiceName()).setAdministrativeState(State.OutOfService) + .setOperationalState(State.OutOfService).setCommonId(serviceReconfigureInput.getCommonId()) + .setConnectionType(serviceReconfigureInput.getConnectionType()) + .setCustomer(serviceReconfigureInput.getCustomer()) + .setCustomerContact(serviceReconfigureInput.getCustomerContact()) + .setHardConstraints(serviceReconfigureInput.getHardConstraints()) + .setSoftConstraints(serviceReconfigureInput.getSoftConstraints()) + .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend); + } + return service.build(); + } + + public static org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service.list + .Services mappingServices(TempServiceCreateInput tempServiceCreateInput) { + org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEnd aend = null; + org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceZEnd zend = null; + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service.list + .ServicesBuilder service = new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp + .service.list.ServicesBuilder(); + aend = new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .ServiceAEndBuilder(tempServiceCreateInput.getServiceAEnd()).build(); + zend = new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service + .ServiceZEndBuilder(tempServiceCreateInput.getServiceZEnd()).build(); + service.setServiceName(tempServiceCreateInput.getCommonId()).setAdministrativeState(State.OutOfService) + .setOperationalState(State.OutOfService).setCommonId(tempServiceCreateInput.getCommonId()) + .setConnectionType(tempServiceCreateInput.getConnectionType()) + .setCustomer(tempServiceCreateInput.getCustomer()) + .setCustomerContact(tempServiceCreateInput.getCustomerContact()) + .setHardConstraints(tempServiceCreateInput.getHardConstraints()) + .setSoftConstraints(tempServiceCreateInput.getSoftConstraints()) + .setSdncRequestHeader(tempServiceCreateInput.getSdncRequestHeader()) + .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend); + return service.build(); + } + + public static ServicePaths mappingServicePaths(ServiceInput serviceInput, PathComputationRequestOutput output) { + ServicePathsBuilder servicePathBuilder = new ServicePathsBuilder(); + if (serviceInput != null) { + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .service.types.rev171016.service.path.ServiceAEndBuilder serviceAEnd = + new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .service.types.rev171016.service.path.ServiceAEndBuilder(); + serviceAEnd.setServiceFormat(serviceInput.getServiceAEnd().getServiceFormat()) + .setServiceRate(serviceInput.getServiceAEnd().getServiceRate()) + .setClli(serviceInput.getServiceAEnd().getClli()) + .setNodeId(serviceInput.getServiceAEnd().getNodeId()) + .setTxDirection(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types + .rev171016.service.endpoint.sp.TxDirectionBuilder() + .setPort(serviceInput.getServiceAEnd().getTxDirection().getPort()).build()) + .setRxDirection(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types + .rev171016.service.endpoint.sp.RxDirectionBuilder() + .setPort(serviceInput.getServiceAEnd().getRxDirection().getPort()).build()); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .service.types.rev171016.service.path.ServiceZEndBuilder serviceZEnd = + new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .service.types.rev171016.service.path.ServiceZEndBuilder(); + serviceZEnd.setServiceFormat(serviceInput.getServiceZEnd().getServiceFormat()) + .setServiceRate(serviceInput.getServiceZEnd().getServiceRate()) + .setClli(serviceInput.getServiceZEnd().getClli()) + .setNodeId(serviceInput.getServiceZEnd().getNodeId()) + .setTxDirection(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types + .rev171016.service.endpoint.sp.TxDirectionBuilder() + .setPort(serviceInput.getServiceZEnd().getTxDirection().getPort()).build()) + .setRxDirection(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types + .rev171016.service.endpoint.sp.RxDirectionBuilder() + .setPort(serviceInput.getServiceZEnd().getRxDirection().getPort()).build()); + servicePathBuilder.setServiceAEnd(serviceAEnd.build()); + servicePathBuilder.setServiceZEnd(serviceZEnd.build()); + MappingConstraints mapConstraints = new MappingConstraints(serviceInput.getHardConstraints(), + serviceInput.getSoftConstraints()); + mapConstraints.serviceToServicePathConstarints(); + if (mapConstraints.getServicePathHardConstraints() != null) { + HardConstraintsBuilder hardConstraintBuilder = new HardConstraintsBuilder(); + hardConstraintBuilder.setCustomerCode(serviceInput.getHardConstraints().getCustomerCode()); + hardConstraintBuilder + .setCoRoutingOrGeneral(mapConstraints.getServicePathHardConstraints().getCoRoutingOrGeneral()); + servicePathBuilder.setHardConstraints(hardConstraintBuilder.build()); + } + if (mapConstraints.getServicePathSoftConstraints() != null) { + SoftConstraintsBuilder softConstraintBuilder = new SoftConstraintsBuilder(); + softConstraintBuilder.setCustomerCode(mapConstraints.getServicePathSoftConstraints().getCustomerCode()); + softConstraintBuilder + .setCoRoutingOrGeneral(mapConstraints.getServicePathSoftConstraints().getCoRoutingOrGeneral()); + servicePathBuilder.setSoftConstraints(softConstraintBuilder.build()); + } + servicePathBuilder.setServicePathName(serviceInput.getServiceName()); + servicePathBuilder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder() + .setRequestId(serviceInput.getSdncRequestHeader().getRequestId()).build()); + PathDescriptionBuilder pathDescBuilder = + new PathDescriptionBuilder(output.getResponseParameters().getPathDescription()); + servicePathBuilder.setPathDescription(pathDescBuilder.build()); + } + return servicePathBuilder.build(); + } +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ServiceDataUtils.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ServiceDataUtils.java index f6cc22b19..99c0390fa 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ServiceDataUtils.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ServiceDataUtils.java @@ -7,17 +7,33 @@ */ package org.opendaylight.transportpce.servicehandler.utils; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; + import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; +import java.util.concurrent.Callable; +import java.util.concurrent.Executors; +import org.opendaylight.transportpce.servicehandler.MappingConstraints; +import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInputBuilder; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResult; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResultBuilder; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescription; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescriptionBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSp; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSpBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultSh; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultShBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType; 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.ServiceFormat; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader; 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.service.types.rev161014.service.endpoint.RxDirection; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirection; @@ -39,8 +55,10 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdes import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirection; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.RoutingConstraintsSp.PceMetric; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.handler.header.ServiceHandlerHeaderBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; public final class ServiceDataUtils { @@ -71,6 +89,27 @@ public final class ServiceDataUtils { return builtInput.build(); } + public static PathComputationRequestInput createPceRequestInput(ServiceCreateInput input) { + MappingConstraints mappingConstraints = + new MappingConstraints(input.getHardConstraints(), input.getSoftConstraints()); + mappingConstraints.serviceToServicePathConstarints(); + ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder(); + SdncRequestHeader serviceHandler = input.getSdncRequestHeader(); + if (serviceHandler != null) { + serviceHandlerHeader.setRequestId(serviceHandler.getRequestId()); + } + return new PathComputationRequestInputBuilder() + .setServiceName(input.getServiceName()) + .setResourceReserve(true) + .setServiceHandlerHeader(serviceHandlerHeader.build()) + .setHardConstraints(mappingConstraints.getServicePathHardConstraints()) + .setSoftConstraints(mappingConstraints.getServicePathSoftConstraints()) + .setPceMetric(PceMetric.TEMetric) + .setServiceAEnd(ModelMappingUtils.createServiceAEnd(input.getServiceAEnd())) + .setServiceZEnd(ModelMappingUtils.createServiceZEnd(input.getServiceZEnd())) + .build(); + } + public static TempServiceCreateInput buildTempServiceCreateInput() { TempServiceCreateInputBuilder builtInput = new TempServiceCreateInputBuilder(); @@ -180,6 +219,33 @@ public final class ServiceDataUtils { return builder.build(); } + public static ServicePathRpcResult buildServicePathRpcResult( + ServicePathNotificationTypes servicePathNotificationTypes, String serviceName, RpcStatusEx rpcStatusEx, + String message, Boolean pathDescription) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + ServicePathRpcResultBuilder builder = new ServicePathRpcResultBuilder(); + builder.setNotificationType(servicePathNotificationTypes) + .setServiceName(serviceName) + .setStatus(rpcStatusEx).setStatusMessage(message); + if (pathDescription) { + builder.setPathDescription(createPathDescription(0L, 5L, 0L, 5L)); + } + return builder.build(); + } + + public static ServicePathRpcResult buildFailedPceServicePathRpcResult() { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + ServicePathRpcResultBuilder builder = new ServicePathRpcResultBuilder(); + builder.setActualDate(datetime).setNotificationType(ServicePathNotificationTypes.PathComputationRequest) + .setPathDescription(createPathDescription(0, 1, 0, 1)).setServiceName("service 1") + .setStatus(RpcStatusEx.Failed).setStatusMessage("failed"); + return builder.build(); + } + public static ServicePathRpcResult buildFailedServicePathRpcResult() { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); @@ -188,11 +254,54 @@ public final class ServiceDataUtils { builder.setActualDate(datetime).setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) .setPathDescription(createPathDescription(0,1, 0, 1)) .setServiceName("service 1") - .setStatus(RpcStatusEx.Failed).setStatusMessage("success"); + .setStatus(RpcStatusEx.Failed).setStatusMessage("failed"); return builder.build(); } - private static PathDescription createPathDescription(long azRate, long azWaveLength, long zaRate, + public static ServiceRpcResultSp buildServiceRpcResultSp() { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + ServiceRpcResultSpBuilder builder = new ServiceRpcResultSpBuilder(); + builder.setActualDate(datetime).setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName("service 1").setStatus(RpcStatusEx.Successful).setStatusMessage("success"); + return builder.build(); + } + + public static ServiceRpcResultSp buildServiceRpcResultSp(ServicePathNotificationTypes servicePathNotificationTypes, + String serviceName, RpcStatusEx rpcStatusEx, String message) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + ServiceRpcResultSpBuilder builder = new ServiceRpcResultSpBuilder(); + builder.setNotificationType(servicePathNotificationTypes).setServiceName(serviceName) + .setStatus(rpcStatusEx).setStatusMessage(message); + return builder.build(); + } + + public static ServiceRpcResultSh buildServiceRpcResultSh(ServiceNotificationTypes serviceNotificationTypes, + String serviceName, org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types + .rev170426.RpcStatusEx rpcStatusEx, String message) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + ServiceRpcResultShBuilder builder = new ServiceRpcResultShBuilder(); + builder.setNotificationType(serviceNotificationTypes).setServiceName(serviceName) + .setStatus(rpcStatusEx).setStatusMessage(message); + return builder.build(); + } + + public static ServiceRpcResultSp buildFailedServiceRpcResultSp() { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + ServiceRpcResultSpBuilder builder = new ServiceRpcResultSpBuilder(); + builder.setActualDate(datetime).setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName("service 1").setStatus(RpcStatusEx.Failed).setStatusMessage("failed"); + return builder.build(); + } + + public static PathDescription createPathDescription(long azRate, long azWaveLength, long zaRate, long zaWaveLength) { AToZDirection atozDirection = new AToZDirectionBuilder() .setRate(azRate) @@ -229,6 +338,17 @@ public final class ServiceDataUtils { .setRxDirection(getRxDirection()); } + public static ListenableFuture returnFuture(T output) { + final ListeningExecutorService executor = + MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)); + return executor.submit(new Callable() { + @Override + public T call() throws Exception { + return output; + } + }); + } + private ServiceDataUtils() { } diff --git a/test-common/src/main/java/org/opendaylight/transportpce/test/AbstractTest.java b/test-common/src/main/java/org/opendaylight/transportpce/test/AbstractTest.java index 571e7063e..8d503a169 100644 --- a/test-common/src/main/java/org/opendaylight/transportpce/test/AbstractTest.java +++ b/test-common/src/main/java/org/opendaylight/transportpce/test/AbstractTest.java @@ -8,6 +8,8 @@ package org.opendaylight.transportpce.test; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.transportpce.test.common.DataStoreContext; import org.opendaylight.transportpce.test.common.DataStoreContextImpl; @@ -32,4 +34,12 @@ public abstract class AbstractTest { return dataStoreContextUtil; } + public NotificationPublishService getNotificationPublishService() { + return dataStoreContextUtil.getNotificationPublishService(); + } + + public NotificationService getNotificationService() { + return dataStoreContextUtil.getNotificationService(); + } + } diff --git a/tests/SH_stubs.diff b/tests/SH_stubs.diff index ca863a3c2..9d423a20c 100644 --- a/tests/SH_stubs.diff +++ b/tests/SH_stubs.diff @@ -1,30 +1,22 @@ -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 3a07abb..f79862d 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 -@@ -26,6 +26,7 @@ import org.opendaylight.transportpce.servicehandler.ServiceInput; - import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; - import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; - import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl; +diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProvider.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProvider.java +index 1c8ddfe..b83b8cc 100644 +--- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProvider.java ++++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProvider.java +@@ -18,6 +18,7 @@ import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService; + import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; + import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl; + import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl; +import org.opendaylight.transportpce.servicehandler.stub.StubRendererServiceOperations; - import org.opendaylight.transportpce.servicehandler.validation.ServiceCreateValidation; - import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult; - import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerCompliancyCheck; -@@ -87,7 +88,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { - - private DataBroker db; - private ServiceDataStoreOperations serviceDataStoreOperations; -- private RendererServiceOperations rendererServiceOperations; -+ private StubRendererServiceOperations rendererServiceOperations; - private PCEServiceWrapper pceServiceWrapper; - - //TODO: remove private request fields as they are in global scope -@@ -96,7 +97,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { - RendererServiceOperations rendererServiceOperations, - NetworkModelWavelengthService networkModelWavelengthService) { - this.db = databroker; + import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.TransportpcePceListener; + import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.TransportpceRendererListener; + import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.OrgOpenroadmServiceService; +@@ -55,7 +56,8 @@ public class ServicehandlerProvider { + this.rpcRegistry = rpcProviderRegistry; + this.notificationService = notificationService; + this.pathComputationService = pathComputationService; - this.rendererServiceOperations = rendererServiceOperations; -+ this.rendererServiceOperations = new StubRendererServiceOperations(networkModelWavelengthService, db); - this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.db); - this.serviceDataStoreOperations.initialize(); - this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService); ++ this.rendererServiceOperations = new StubRendererServiceOperations(networkModelWavelengthService, dataBroker, ++ notificationPublishService); + this.networkModelWavelengthService = networkModelWavelengthService; + this.notificationPublishService = notificationPublishService; + } diff --git a/tests/transportpce_tests/test_servicehandler.py b/tests/transportpce_tests/test_servicehandler.py index 44c46a1c8..1b40e2f53 100644 --- a/tests/transportpce_tests/test_servicehandler.py +++ b/tests/transportpce_tests/test_servicehandler.py @@ -216,9 +216,9 @@ class TransportPCEtesting(unittest.TestCase): auth=('admin', 'admin')) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() - self.assertIn('Service rendered successfully !', + self.assertIn('PCE calculation in progress', res['output']['configuration-response-common']['response-message']) - time.sleep(10) + time.sleep(20) # Create Service 'test' with not compliant parameter : no 'sdnc-request-header' parameter def test_08_create_service(self): @@ -651,9 +651,9 @@ class TransportPCEtesting(unittest.TestCase): auth=('admin', 'admin')) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() - self.assertIn('Service delete was successful!', + self.assertIn('Renderer service delete in progress', res['output']['configuration-response-common']['response-message']) - time.sleep(1) + time.sleep(20) # Verify 'test' service deleted def test_13_get_service(self): @@ -765,9 +765,9 @@ class TransportPCEtesting(unittest.TestCase): auth=('admin', 'admin')) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() - self.assertIn('Service rendered successfully !', + self.assertIn('PCE calculation in progress', res['output']['configuration-response-common']['response-message']) - time.sleep(10) + time.sleep(20) # Create Temp Service not compliant with no common-id @@ -912,12 +912,12 @@ class TransportPCEtesting(unittest.TestCase): auth=('admin', 'admin')) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() - self.assertIn('Service delete was successful!', + self.assertIn('Renderer service delete in progress', res['output']['configuration-response-common']['response-message']) - time.sleep(1) + time.sleep(20) # Verify 'test' service deleted - def test_13_verify_temp_service_deleted(self): + def test_19_verify_temp_service_deleted(self): url = ("{}/operational/org-openroadm-service:service-list/services/ASATT1234567" .format(self.restconf_baseurl)) headers = {'content-type': 'application/json', -- 2.36.6