From: Martial COULIBALY Date: Thu, 29 Nov 2018 08:20:23 +0000 (+0100) Subject: Service-notification handling for Renderer X-Git-Tag: v0.3.0~24 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F92%2F78292%2F17;p=transportpce.git Service-notification handling for Renderer - Modify Renderer to send notifications to SH - Modify Renderer service to implement RPCs ListenableFuture JIRA: TRNSPRTPCE-50 Change-Id: I4ed3cc24814ac8c6ddf303d5fa3746de6389b7a5 Signed-off-by: Martial COULIBALY --- diff --git a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperations.java b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperations.java index fcaf88c87..2ba2583d8 100644 --- a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperations.java +++ b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperations.java @@ -7,15 +7,18 @@ */ package org.opendaylight.transportpce.renderer.provisiondevice; +import com.google.common.util.concurrent.ListenableFuture; + 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.ServiceImplementationRequestInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput; + public interface RendererServiceOperations { - ServiceImplementationRequestOutput serviceImplementation(ServiceImplementationRequestInput input); + ListenableFuture serviceImplementation(ServiceImplementationRequestInput input); - ServiceDeleteOutput serviceDelete(ServiceDeleteInput input); + ListenableFuture serviceDelete(ServiceDeleteInput input); } diff --git a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImpl.java b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImpl.java index 9aa073a99..831efbcd8 100644 --- a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImpl.java +++ b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImpl.java @@ -12,14 +12,18 @@ 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.ArrayList; import java.util.List; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; 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; @@ -45,8 +49,12 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer. 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.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.ServiceRpcResultSp; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSpBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmGranularity; import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum; +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; @@ -70,124 +78,177 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations private final DeviceRendererService deviceRenderer; private final TransportpceOlmService olmService; private final DataBroker dataBroker; + private final NotificationPublishService notificationPublishService; private ListeningExecutorService executor; private NetworkModelWavelengthService networkModelWavelengthService; + private ServiceRpcResultSp notification = null; public RendererServiceOperationsImpl(DeviceRendererService deviceRenderer, TransportpceOlmService olmService, - DataBroker dataBroker, NetworkModelWavelengthService networkModelWavelengthService) { + DataBroker dataBroker, NetworkModelWavelengthService networkModelWavelengthService, + NotificationPublishService notificationPublishService) { this.deviceRenderer = deviceRenderer; this.olmService = olmService; this.dataBroker = dataBroker; this.networkModelWavelengthService = networkModelWavelengthService; + this.notificationPublishService = notificationPublishService; this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS)); } - @Override - public ServiceImplementationRequestOutput serviceImplementation(ServiceImplementationRequestInput input) { - LOG.info("Calling service impl request {} {}", input.getServiceName()); - RollbackProcessor rollbackProcessor = new RollbackProcessor(); - - ServicePathInputData servicePathInputDataAtoZ - = ModelMappingUtils.rendererCreateServiceInputAToZ(input.getServiceName(), - input.getPathDescription()); - ServicePathInputData servicePathInputDataZtoA - = ModelMappingUtils.rendererCreateServiceInputZToA(input.getServiceName(), - input.getPathDescription()); - List renderingResults = deviceRendering(rollbackProcessor, servicePathInputDataAtoZ, - servicePathInputDataZtoA); - if (rollbackProcessor.rollbackAllIfNecessary() > 0) { - return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); - } - - ServicePowerSetupInput olmPowerSetupInputAtoZ = ModelMappingUtils.createServicePowerSetupInput( - renderingResults.get(0).getOlmList(), input); - ServicePowerSetupInput olmPowerSetupInputZtoA = ModelMappingUtils.createServicePowerSetupInput( - renderingResults.get(1).getOlmList(), input); - olmPowerSetup(rollbackProcessor, olmPowerSetupInputAtoZ, olmPowerSetupInputZtoA); - if (rollbackProcessor.rollbackAllIfNecessary() > 0) { - return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); - } - - // run service activation test twice - once on source node and once on destination node - List nodes = servicePathInputDataAtoZ.getServicePathInput().getNodes(); - Nodes sourceNode = nodes.get(0); - Nodes destNode = nodes.get(nodes.size() - 1); - - String srcNetworkTp; - String dstNetowrkTp; - - if (sourceNode.getDestTp().contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) { - srcNetworkTp = sourceNode.getDestTp(); - } else { - srcNetworkTp = sourceNode.getSrcTp(); - } - if (destNode.getDestTp().contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) { - dstNetowrkTp = destNode.getDestTp(); - } else { - dstNetowrkTp = destNode.getSrcTp(); - } - - if (!isServiceActivated(sourceNode.getNodeId(), srcNetworkTp) - || !isServiceActivated(destNode.getNodeId(), dstNetowrkTp)) { - rollbackProcessor.rollbackAll(); - return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); + private void sendNotifications(ServicePathNotificationTypes servicePathNotificationTypes, String serviceName, + RpcStatusEx rpcStatusEx, String message) { + this.notification = new ServiceRpcResultSpBuilder() + .setNotificationType(servicePathNotificationTypes) + .setServiceName(serviceName) + .setStatus(rpcStatusEx) + .setStatusMessage(message) + .build(); + try { + notificationPublishService.putNotification(this.notification); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : ", e.getMessage()); } + } - //If Service activation is success update Network ModelMappingUtils - this.networkModelWavelengthService.useWavelengths(input.getPathDescription()); + @Override + public ListenableFuture + serviceImplementation(ServiceImplementationRequestInput input) { + LOG.info("Calling service impl request {} {}", input.getServiceName()); + return executor.submit(new Callable() { + + @Override + public ServiceImplementationRequestOutput call() throws Exception { + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, input.getServiceName(), + RpcStatusEx.Pending, "Service compliant, submitting service implementation Request ..."); + RollbackProcessor rollbackProcessor = new RollbackProcessor(); + ServicePathInputData servicePathInputDataAtoZ = ModelMappingUtils + .rendererCreateServiceInputAToZ(input.getServiceName(), input.getPathDescription()); + ServicePathInputData servicePathInputDataZtoA = ModelMappingUtils + .rendererCreateServiceInputZToA(input.getServiceName(), input.getPathDescription()); + List renderingResults = + deviceRendering(rollbackProcessor, servicePathInputDataAtoZ, servicePathInputDataZtoA); + if (rollbackProcessor.rollbackAllIfNecessary() > 0) { + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, input.getServiceName(), + RpcStatusEx.Failed, "Device rendering was not successful! Rendering will be rolled back."); + return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); + } + ServicePowerSetupInput olmPowerSetupInputAtoZ = + ModelMappingUtils.createServicePowerSetupInput(renderingResults.get(0).getOlmList(), input); + ServicePowerSetupInput olmPowerSetupInputZtoA = + ModelMappingUtils.createServicePowerSetupInput(renderingResults.get(1).getOlmList(), input); + olmPowerSetup(rollbackProcessor, olmPowerSetupInputAtoZ, olmPowerSetupInputZtoA); + if (rollbackProcessor.rollbackAllIfNecessary() > 0) { + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, input.getServiceName(), + RpcStatusEx.Failed, + "OLM power setup was not successful! Rendering and OLM will be rolled back."); + return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); + } + // run service activation test twice - once on source node and once on + // destination node + List nodes = servicePathInputDataAtoZ.getServicePathInput().getNodes(); + Nodes sourceNode = nodes.get(0); + Nodes destNode = nodes.get(nodes.size() - 1); + String srcNetworkTp; + String dstNetowrkTp; + if (sourceNode.getDestTp().contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) { + srcNetworkTp = sourceNode.getDestTp(); + } else { + srcNetworkTp = sourceNode.getSrcTp(); + } + if (destNode.getDestTp().contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) { + dstNetowrkTp = destNode.getDestTp(); + } else { + dstNetowrkTp = destNode.getSrcTp(); + } + if (!isServiceActivated(sourceNode.getNodeId(), srcNetworkTp) + || !isServiceActivated(destNode.getNodeId(), dstNetowrkTp)) { + rollbackProcessor.rollbackAll(); + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, input.getServiceName(), + RpcStatusEx.Failed, "Service activation test failed."); + return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); + } + // If Service activation is success update Network ModelMappingUtils + networkModelWavelengthService.useWavelengths(input.getPathDescription()); + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, input.getServiceName(), + RpcStatusEx.Successful, OPERATION_SUCCESSFUL); + return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_OK, OPERATION_SUCCESSFUL); + } + }); - return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_OK, OPERATION_SUCCESSFUL); } @Override - public ServiceDeleteOutput serviceDelete(ServiceDeleteInput input) { + public ListenableFuture serviceDelete(ServiceDeleteInput input) { String serviceName = input.getServiceName(); - - // Obtain path description - Optional pathDescriptionOpt = getPathDescriptionFromDatastore(serviceName); - PathDescription pathDescription; - if (pathDescriptionOpt.isPresent()) { - pathDescription = pathDescriptionOpt.get(); - } else { - LOG.error("Unable to get path description for service {}!", serviceName); - return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); - } - - ServicePathInputData servicePathInputDataAtoZ - = ModelMappingUtils.rendererCreateServiceInputAToZ(serviceName, pathDescription); - ServicePathInputData servicePathInputDataZtoA - = ModelMappingUtils.rendererCreateServiceInputZToA(serviceName, pathDescription); - - // OLM turn down power - try { - LOG.debug("Turning down power on A-to-Z path"); - ServicePowerTurndownOutput atozPowerTurndownOutput = olmPowerTurndown(servicePathInputDataAtoZ); - // TODO add some flag rather than string - if (FAILED.equals(atozPowerTurndownOutput.getResult())) { - LOG.error("Service power turndown failed on A-to-Z path for service {}!", serviceName); - return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); - } - - LOG.debug("Turning down power on Z-to-A path"); - ServicePowerTurndownOutput ztoaPowerTurndownOutput = olmPowerTurndown(servicePathInputDataZtoA); - // TODO add some flag rather than string - if (FAILED.equals(ztoaPowerTurndownOutput.getResult())) { - LOG.error("Service power turndown failed on Z-to-A path for service {}!", serviceName); - return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); + LOG.info("Calling service delete request {} {}", input.getServiceName()); + return executor.submit(new Callable() { + + @Override + public ServiceDeleteOutput call() throws Exception { + sendNotifications(ServicePathNotificationTypes.ServiceDelete, input.getServiceName(), + RpcStatusEx.Pending, "Service compliant, submitting service delete Request ..."); + // Obtain path description + Optional pathDescriptionOpt = getPathDescriptionFromDatastore(serviceName); + PathDescription pathDescription; + if (pathDescriptionOpt.isPresent()) { + pathDescription = pathDescriptionOpt.get(); + } else { + LOG.error("Unable to get path description for service {}!", serviceName); + sendNotifications(ServicePathNotificationTypes.ServiceDelete, input.getServiceName(), + RpcStatusEx.Failed, "Unable to get path description for service"); + return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_FAILED, + OPERATION_FAILED); + } + ServicePathInputData servicePathInputDataAtoZ = + ModelMappingUtils.rendererCreateServiceInputAToZ(serviceName, pathDescription); + ServicePathInputData servicePathInputDataZtoA = + ModelMappingUtils.rendererCreateServiceInputZToA(serviceName, pathDescription); + // OLM turn down power + try { + LOG.debug("Turning down power on A-to-Z path"); + sendNotifications(ServicePathNotificationTypes.ServiceDelete, + input.getServiceName(), RpcStatusEx.Pending, "Turning down power on A-to-Z path"); + ServicePowerTurndownOutput atozPowerTurndownOutput = olmPowerTurndown(servicePathInputDataAtoZ); + // TODO add some flag rather than string + if (FAILED.equals(atozPowerTurndownOutput.getResult())) { + LOG.error("Service power turndown failed on A-to-Z path for service {}!", serviceName); + sendNotifications(ServicePathNotificationTypes.ServiceDelete, + input.getServiceName(), RpcStatusEx.Failed, + "Service power turndown failed on A-to-Z path for service"); + return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_FAILED, + OPERATION_FAILED); + } + LOG.debug("Turning down power on Z-to-A path"); + sendNotifications(ServicePathNotificationTypes.ServiceDelete, input.getServiceName(), + RpcStatusEx.Pending, "Turning down power on Z-to-A path"); + ServicePowerTurndownOutput ztoaPowerTurndownOutput = olmPowerTurndown(servicePathInputDataZtoA); + // TODO add some flag rather than string + if (FAILED.equals(ztoaPowerTurndownOutput.getResult())) { + LOG.error("Service power turndown failed on Z-to-A path for service {}!", serviceName); + sendNotifications(ServicePathNotificationTypes.ServiceDelete, + input.getServiceName(), RpcStatusEx.Failed, + "Service power turndown failed on Z-to-A path for service"); + return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_FAILED, + OPERATION_FAILED); + } + } catch (InterruptedException | ExecutionException | TimeoutException e) { + LOG.error("Error while turning down power!", e); + return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_FAILED, + OPERATION_FAILED); + } + // delete service path with renderer + LOG.debug("Deleting service path via renderer"); + sendNotifications(ServicePathNotificationTypes.ServiceDelete, input.getServiceName(), + RpcStatusEx.Pending, "Deleting service path via renderer"); + deviceRenderer.deleteServicePath(servicePathInputDataAtoZ.getServicePathInput()); + deviceRenderer.deleteServicePath(servicePathInputDataZtoA.getServicePathInput()); + networkModelWavelengthService.freeWavelengths(pathDescription); + sendNotifications(ServicePathNotificationTypes.ServiceDelete, input.getServiceName(), + RpcStatusEx.Successful, OPERATION_SUCCESSFUL); + return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_OK, OPERATION_SUCCESSFUL); } - } catch (InterruptedException | ExecutionException | TimeoutException e) { - LOG.error("Error while turning down power!", e); - return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED); - } - - // delete service path with renderer - LOG.debug("Deleting service path via renderer"); - this.deviceRenderer.deleteServicePath(servicePathInputDataAtoZ.getServicePathInput()); - this.deviceRenderer.deleteServicePath(servicePathInputDataZtoA.getServicePathInput()); + }); - this.networkModelWavelengthService.freeWavelengths(pathDescription); - return ModelMappingUtils.createServiceDeleteResponse(ResponseCodes.RESPONSE_OK, OPERATION_SUCCESSFUL); } private ServicePowerTurndownOutput olmPowerTurndown(ServicePathInputData servicePathInputData) @@ -216,11 +277,17 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations private List deviceRendering(RollbackProcessor rollbackProcessor, ServicePathInputData servicePathDataAtoZ, ServicePathInputData servicePathDataZtoA) { LOG.info("Rendering devices A-Z"); + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, + servicePathDataAtoZ.getServicePathInput().getServiceName(), RpcStatusEx.Pending, + "Rendering devices A-Z"); ListenableFuture atozrenderingFuture = this.executor.submit(new DeviceRenderingTask(this.deviceRenderer, servicePathDataAtoZ, ServicePathDirection.A_TO_Z)); LOG.info("Rendering devices Z-A"); + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, + servicePathDataAtoZ.getServicePathInput().getServiceName(), RpcStatusEx.Pending, + "Rendering devices A-Z"); ListenableFuture ztoarenderingFuture = this.executor.submit(new DeviceRenderingTask(this.deviceRenderer, servicePathDataZtoA, ServicePathDirection.Z_TO_A)); @@ -233,6 +300,9 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations renderingResults = renderingCombinedFuture.get(Timeouts.RENDERING_TIMEOUT, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Device rendering was not successful! Rendering will be rolled back.", e); + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, + servicePathDataAtoZ.getServicePathInput().getServiceName(), RpcStatusEx.Pending, + "Device rendering was not successful! Rendering will be rolled back."); //FIXME we can't do rollback here, because we don't have rendering results. //rollbackProcessor.addTask(new DeviceRenderingRollbackTask("AtoZDeviceTask", true)); //rollbackProcessor.addTask(new DeviceRenderingRollbackTask("ZtoADeviceTask", true)); @@ -251,10 +321,14 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations private void olmPowerSetup(RollbackProcessor rollbackProcessor, ServicePowerSetupInput powerSetupInputAtoZ, ServicePowerSetupInput powerSetupInputZtoA) { LOG.info("Olm power setup A-Z"); + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, + powerSetupInputAtoZ.getServiceName(), RpcStatusEx.Pending, "Olm power setup A-Z"); ListenableFuture olmPowerSetupFutureAtoZ = this.executor.submit(new OlmPowerSetupTask(this.olmService, powerSetupInputAtoZ)); LOG.info("OLM power setup Z-A"); + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, + powerSetupInputAtoZ.getServiceName(), RpcStatusEx.Pending, "Olm power setup Z-A"); ListenableFuture olmPowerSetupFutureZtoA = this.executor.submit(new OlmPowerSetupTask(this.olmService, powerSetupInputZtoA)); ListenableFuture> olmFutures = @@ -266,6 +340,9 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations olmResults = olmFutures.get(Timeouts.OLM_TIMEOUT, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("OLM power setup was not successful! Rendering and OLM will be rolled back.", e); + sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, + powerSetupInputAtoZ.getServiceName(), RpcStatusEx.Pending, + "OLM power setup was not successful! Rendering and OLM will be rolled back."); rollbackProcessor.addTask(new OlmPowerSetupRollbackTask("AtoZOLMTask", true, this.olmService, powerSetupInputAtoZ)); rollbackProcessor.addTask(new OlmPowerSetupRollbackTask("ZtoAOLMTask", true, diff --git a/renderer/src/main/java/org/opendaylight/transportpce/renderer/rpcs/TransportPCEServicePathRPCImpl.java b/renderer/src/main/java/org/opendaylight/transportpce/renderer/rpcs/TransportPCEServicePathRPCImpl.java index 3dd8c178c..dce7d7178 100644 --- a/renderer/src/main/java/org/opendaylight/transportpce/renderer/rpcs/TransportPCEServicePathRPCImpl.java +++ b/renderer/src/main/java/org/opendaylight/transportpce/renderer/rpcs/TransportPCEServicePathRPCImpl.java @@ -8,6 +8,9 @@ package org.opendaylight.transportpce.renderer.rpcs; import com.google.common.util.concurrent.ListenableFuture; + +import java.util.concurrent.ExecutionException; + import org.opendaylight.transportpce.renderer.ModelMappingUtils; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput; @@ -33,8 +36,13 @@ public class TransportPCEServicePathRPCImpl implements TransportpceRendererServi public ListenableFuture> serviceDelete(ServiceDeleteInput input) { String serviceName = input.getServiceName(); LOG.info("Calling RPC service delete request {} {}", serviceName); - return ModelMappingUtils - .createServiceDeleteRpcResponse(this.rendererServiceOperations.serviceDelete(input)); + ServiceDeleteOutput output = null; + try { + output = this.rendererServiceOperations.serviceDelete(input).get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("RPC service delete failed !"); + } + return ModelMappingUtils.createServiceDeleteRpcResponse(output); } @Override @@ -42,8 +50,13 @@ public class TransportPCEServicePathRPCImpl implements TransportpceRendererServi ServiceImplementationRequestInput input) { String serviceName = input.getServiceName(); LOG.info("Calling RPC service impl request {} {}", serviceName); - return ModelMappingUtils - .createServiceImplementationRpcResponse(this.rendererServiceOperations.serviceImplementation(input)); + ServiceImplementationRequestOutput output = null; + try { + output = this.rendererServiceOperations.serviceImplementation(input).get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("RPC service implementation failed !"); + } + return ModelMappingUtils.createServiceImplementationRpcResponse(output); } } diff --git a/renderer/src/main/resources/org/opendaylight/blueprint/renderer-blueprint.xml b/renderer/src/main/resources/org/opendaylight/blueprint/renderer-blueprint.xml index 6ef15d187..90747b71d 100644 --- a/renderer/src/main/resources/org/opendaylight/blueprint/renderer-blueprint.xml +++ b/renderer/src/main/resources/org/opendaylight/blueprint/renderer-blueprint.xml @@ -13,6 +13,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html + @@ -50,6 +53,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html + serviceDeleteOutput = + this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()); + ServiceDeleteOutput output = serviceDeleteOutput.get(); Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode()); + output.getConfigurationResponseCommon().getResponseCode()); Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any()); Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any()); } @@ -150,7 +157,7 @@ public class RendererServiceOperationsImplDeleteTest extends AbstractTest { serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder()) .setRequestId("request1").build()); ServiceDeleteOutput serviceDeleteOutput = - this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()); + this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()).get(); Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode()); Mockito.verify(this.olmService, Mockito.times(2)).servicePowerTurndown(Mockito.any()); diff --git a/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImplTest.java b/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImplTest.java index cc250c956..af3c0f71d 100644 --- a/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImplTest.java +++ b/renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImplTest.java @@ -9,12 +9,15 @@ package org.opendaylight.transportpce.renderer.provisiondevice; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutionException; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.opendaylight.controller.md.sal.binding.api.MountPoint; import org.opendaylight.controller.md.sal.binding.api.MountPointService; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.common.crossconnect.CrossConnect; import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl; @@ -32,6 +35,7 @@ import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub; import org.opendaylight.transportpce.renderer.stub.MountPointStub; import org.opendaylight.transportpce.renderer.stub.OlmServiceStub; import org.opendaylight.transportpce.renderer.utils.MountPointUtils; +import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock; import org.opendaylight.transportpce.renderer.utils.ServiceDataUtils; import org.opendaylight.transportpce.test.AbstractTest; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInput; @@ -83,12 +87,11 @@ public class RendererServiceOperationsImplTest extends AbstractTest { this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect, portMapping); Mockito.doNothing().when(this.openRoadmInterfaces).postEquipmentState(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean()); - + NotificationPublishService notificationPublishService = new NotificationPublishServiceMock(); this.olmService = Mockito.spy(this.olmService); this.deviceRenderer = Mockito.spy(this.deviceRenderer); this.rendererServiceOperations = new RendererServiceOperationsImpl(this.deviceRenderer, this.olmService, - getDataBroker(), this.networkModelWavelengthService); - + getDataBroker(), this.networkModelWavelengthService, notificationPublishService); ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success") .setSuccess(true); Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(), @@ -96,7 +99,7 @@ public class RendererServiceOperationsImplTest extends AbstractTest { } @Test - public void serviceImplementationTerminationPointAsResourceTtp() { + public void serviceImplementationTerminationPointAsResourceTtp() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.TTP_TOKEN); @@ -105,13 +108,13 @@ public class RendererServiceOperationsImplTest extends AbstractTest { .setSuccess(true); Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(), Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationTerminationPointAsResourceTtp2() { + public void serviceImplementationTerminationPointAsResourceTtp2() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.TTP_TOKEN); @@ -122,13 +125,13 @@ public class RendererServiceOperationsImplTest extends AbstractTest { Mockito.any()); Mockito.doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService) .servicePowerSetup(Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationTerminationPointAsResourcePp() { + public void serviceImplementationTerminationPointAsResourcePp() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.PP_TOKEN); @@ -137,13 +140,14 @@ public class RendererServiceOperationsImplTest extends AbstractTest { .setSuccess(true); Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(), Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationTerminationPointAsResourceNetwork() { + public void serviceImplementationTerminationPointAsResourceNetwork() + throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN); @@ -152,23 +156,25 @@ public class RendererServiceOperationsImplTest extends AbstractTest { .setSuccess(true); Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(), Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationTerminationPointAsResourceClient() { + public void serviceImplementationTerminationPointAsResourceClient() + throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.CLIENT_TOKEN); writePortMapping(input, OpenRoadmInterfacesImpl.CLIENT_TOKEN); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationTerminationPointAsResourceNoMapping() { + public void serviceImplementationTerminationPointAsResourceNoMapping() + throws InterruptedException, ExecutionException { String[] interfaceTokens = { OpenRoadmInterfacesImpl.NETWORK_TOKEN, @@ -185,7 +191,8 @@ public class RendererServiceOperationsImplTest extends AbstractTest { for (String tpToken : interfaceTokens) { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(tpToken); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = + this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode()); } @@ -217,14 +224,14 @@ public class RendererServiceOperationsImplTest extends AbstractTest { } @Test - public void serviceImplementationRollbackAllNecessary() { + public void serviceImplementationRollbackAllNecessary() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN); writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN); Mockito.doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService) .servicePowerSetup(Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode()); } @@ -241,7 +248,7 @@ public class RendererServiceOperationsImplTest extends AbstractTest { } @Test - public void serviceImplementationServiceInActive() { + public void serviceImplementationServiceInActive() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN); @@ -254,13 +261,13 @@ public class RendererServiceOperationsImplTest extends AbstractTest { .setNodeId("node1").setMeasurements(measurementsList).build(); Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService) .getPm(Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationServiceInActive2() { + public void serviceImplementationServiceInActive2() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN); @@ -276,13 +283,13 @@ public class RendererServiceOperationsImplTest extends AbstractTest { Mockito.when(this.olmService.getPm(Mockito.any())) .thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationServiceInActive3() { + public void serviceImplementationServiceInActive3() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN); @@ -305,13 +312,13 @@ public class RendererServiceOperationsImplTest extends AbstractTest { .thenReturn(RpcResultBuilder.success(getPmOutput2).buildFuture()); Mockito.when(this.olmService.getPm(Mockito.eq(getPmInputA))) .thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationServiceActive() { + public void serviceImplementationServiceActive() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN); @@ -325,13 +332,13 @@ public class RendererServiceOperationsImplTest extends AbstractTest { .setSuccess(true); Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(), Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationServiceActive2() { + public void serviceImplementationServiceActive2() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN); @@ -343,13 +350,13 @@ public class RendererServiceOperationsImplTest extends AbstractTest { .setSuccess(true); Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(), Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationServiceInActive4() { + public void serviceImplementationServiceInActive4() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN); @@ -367,13 +374,13 @@ public class RendererServiceOperationsImplTest extends AbstractTest { .setSuccess(true); Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(), Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceImplementationServiceInActive5() { + public void serviceImplementationServiceInActive5() throws InterruptedException, ExecutionException { ServiceImplementationRequestInput input = ServiceDataUtils .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN); @@ -387,7 +394,7 @@ public class RendererServiceOperationsImplTest extends AbstractTest { Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService) .getPm(Mockito.any()); - ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input); + ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get(); Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode()); } diff --git a/renderer/src/test/java/org/opendaylight/transportpce/renderer/utils/NotificationPublishServiceMock.java b/renderer/src/test/java/org/opendaylight/transportpce/renderer/utils/NotificationPublishServiceMock.java new file mode 100644 index 000000000..1b7a6bf87 --- /dev/null +++ b/renderer/src/test/java/org/opendaylight/transportpce/renderer/utils/NotificationPublishServiceMock.java @@ -0,0 +1,41 @@ +/* + * Copyright © 2017 AT&T, 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.renderer.utils; + +import com.google.common.util.concurrent.ListenableFuture; + +import java.util.concurrent.TimeUnit; + +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NotificationPublishServiceMock implements NotificationPublishService { + + private static final Logger LOG = LoggerFactory.getLogger(NotificationPublishServiceMock.class); + + @Override + public void putNotification(Notification notification) throws InterruptedException { + LOG.info("putNotification"); + } + + @Override + public ListenableFuture offerNotification(Notification notification) { + LOG.info("offerNotification"); + throw new UnsupportedOperationException("offerNotification is not implemented"); + } + + @Override + public ListenableFuture offerNotification(Notification notification, int timeout, TimeUnit unit) + throws InterruptedException { + LOG.info("offerNotification"); + throw new UnsupportedOperationException("offerNotification is not implemented"); + } + +} 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 3a07abb10..435e809ab 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 @@ -147,8 +147,13 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { ServiceImplementationRequestInput serviceImplementationRequest = ModelMappingUtils.createServiceImplementationRequest(new ServiceInput(input), pceResponse); - ServiceImplementationRequestOutput serviceImplementationRequestOutput = this.rendererServiceOperations - .serviceImplementation(serviceImplementationRequest); + 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 !"; @@ -223,7 +228,12 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput( new ServiceInput(input)); org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteOutput output = this.rendererServiceOperations.serviceDelete(serviceDeleteInput); + .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())) { @@ -408,7 +418,12 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput( new ServiceInput(input)); org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 - .ServiceDeleteOutput output = this.rendererServiceOperations.serviceDelete(serviceDeleteInput); + .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())) { @@ -478,8 +493,13 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { ServiceImplementationRequestInput serviceImplementationRequest = ModelMappingUtils.createServiceImplementationRequest(new ServiceInput(input), pceResponse); - ServiceImplementationRequestOutput serviceImplementationRequestOutput = this.rendererServiceOperations - .serviceImplementation(serviceImplementationRequest); + 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 !"; 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 95053ec40..504d4e941 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 @@ -8,10 +8,15 @@ package org.opendaylight.transportpce.servicehandler.stub; 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.Callable; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; 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; @@ -25,36 +30,49 @@ 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; public StubRendererServiceOperations(NetworkModelWavelengthService networkModelWavelengthService, - DataBroker dataBroker) { - this.stubrendererImpl = new StubrendererImpl(networkModelWavelengthService, dataBroker); + DataBroker dataBroker, NotificationPublishService notificationPublishService) { + this.stubrendererImpl = + new StubrendererImpl(networkModelWavelengthService, dataBroker, notificationPublishService); + executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2)); } @Override - public ServiceImplementationRequestOutput serviceImplementation(ServiceImplementationRequestInput input) { - ListenableFuture> rpcResultFuture = - this.stubrendererImpl.serviceImplementation(input); - try { - return rpcResultFuture.get().getResult(); - } catch (InterruptedException e) { - LOG.error("RPC serviceImplementation failed !",e); - } catch (ExecutionException e) { - LOG.error("RPC serviceImplementation failed !",e); - } - return null; + public ListenableFuture + serviceImplementation(ServiceImplementationRequestInput input) { + return executor.submit(new Callable() { + + @Override + public ServiceImplementationRequestOutput call() { + ListenableFuture> rpcResultFuture = + stubrendererImpl.serviceImplementation(input); + try { + return rpcResultFuture.get().getResult(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("RPC serviceImplementation failed !", e); + } + return null; + } + }); } @Override - public ServiceDeleteOutput serviceDelete(ServiceDeleteInput input) { - ListenableFuture> rpcResultFuture = this.stubrendererImpl.serviceDelete(input); - try { - return rpcResultFuture.get().getResult(); - } catch (InterruptedException e) { - LOG.error("RPC serviceDelete failed !",e); - } catch (ExecutionException e) { - LOG.error("RPC serviceDelete failed !",e); - } - return null; + public ListenableFuture serviceDelete(ServiceDeleteInput input) { + return executor.submit(new Callable() { + + @Override + public ServiceDeleteOutput call() { + ListenableFuture> rpcResultFuture = + stubrendererImpl.serviceDelete(input); + try { + return rpcResultFuture.get().getResult(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("RPC serviceDelete failed !", e); + } + return null; + } + }); } } 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 index a964c97dd..91aefe82f 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java @@ -17,6 +17,7 @@ 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; @@ -28,12 +29,19 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer. 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; @@ -50,22 +58,38 @@ 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) { + 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 1s til beginning the Renderer serviceDelete request"); - Thread.sleep(1000); //sleep for 1s + 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); @@ -84,6 +108,11 @@ public class StubrendererImpl { 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()) @@ -100,9 +129,14 @@ public class StubrendererImpl { 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 1s til beginning the Renderer serviceDelete request"); - Thread.sleep(1000); //sleep for 1s + 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); @@ -110,6 +144,12 @@ public class StubrendererImpl { } 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) 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 685a4fcc6..f17513e4d 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 @@ -10,13 +10,19 @@ 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; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; 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; import org.junit.Assert; @@ -86,11 +92,13 @@ import org.slf4j.LoggerFactory; public class ServiceHandlerImplTest extends AbstractTest { private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerImplTest.class); + private static final int NUMBER_OF_THREADS = 4; private PathComputationService pathComputationService; private RendererServiceOperations rendererServiceOperations; private NetworkModelWavelengthService networkModelWavelengthService; private ServicehandlerImpl serviceHandler; + private ListeningExecutorService executor; @Mock private ServiceDataStoreOperations serviceDataStoreOperationsMock; @@ -124,7 +132,9 @@ public class ServiceHandlerImplTest extends AbstractTest { PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(), "topologyData/NW-simple-topology.xml"); this.rendererServiceOperations = - new StubRendererServiceOperations(this.networkModelWavelengthService, getDataBroker()); + new StubRendererServiceOperations(this.networkModelWavelengthService, getDataBroker(), + notificationPublishService); + this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS)); } @Test @@ -149,8 +159,8 @@ public class ServiceHandlerImplTest extends AbstractTest { .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); Mockito.when( this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build()); + .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon2).build())); Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceInput.getServiceName(), State.InService, State.InService)).thenReturn(OperationResult.ok("successful")); @@ -163,6 +173,16 @@ public class ServiceHandlerImplTest extends AbstractTest { 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(); @@ -183,8 +203,8 @@ public class ServiceHandlerImplTest extends AbstractTest { .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); Mockito.when( this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build()); + .thenReturn(returnFuture(new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon2).build())); Mockito.when(this.serviceDataStoreOperationsMock.modifyTempService(serviceInput.getCommonId(), State.InService, State.InService)).thenReturn(OperationResult.ok("successful")); Future> output0 = @@ -677,11 +697,10 @@ public class ServiceHandlerImplTest extends AbstractTest { 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(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build()); + .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(); @@ -710,11 +729,10 @@ public class ServiceHandlerImplTest extends AbstractTest { 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(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build()); + .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(); @@ -743,11 +761,10 @@ public class ServiceHandlerImplTest extends AbstractTest { 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(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build()); + .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())) @@ -778,11 +795,10 @@ public class ServiceHandlerImplTest extends AbstractTest { 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(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon2).build()); + .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())) @@ -995,7 +1011,7 @@ public class ServiceHandlerImplTest extends AbstractTest { 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(output); + 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); @@ -1017,7 +1033,7 @@ public class ServiceHandlerImplTest extends AbstractTest { 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(output); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); Mockito.when(this.serviceDataStoreOperationsMock .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) .thenReturn(OperationResult.failed("failed")); @@ -1045,7 +1061,7 @@ public class ServiceHandlerImplTest extends AbstractTest { 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(output); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); Mockito.when(this.serviceDataStoreOperationsMock .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) .thenReturn(OperationResult.ok("success")); @@ -1074,7 +1090,7 @@ public class ServiceHandlerImplTest extends AbstractTest { .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(output); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); Mockito.when(this.serviceDataStoreOperationsMock .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) .thenReturn(OperationResult.ok("success")); @@ -1105,7 +1121,7 @@ public class ServiceHandlerImplTest extends AbstractTest { .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(output); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); Mockito.when(this.serviceDataStoreOperationsMock .deleteServicePath(serviceDeleteInput.getCommonId())) .thenReturn(OperationResult.ok("success")); @@ -1149,7 +1165,7 @@ public class ServiceHandlerImplTest extends AbstractTest { .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(output); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(returnFuture(output)); Mockito.when(this.serviceDataStoreOperationsMock .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) .thenReturn(OperationResult.ok("success")); @@ -1176,8 +1192,8 @@ public class ServiceHandlerImplTest extends AbstractTest { .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); Mockito.when( this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) - .thenReturn(new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon3).build()); + .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")); 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 8a9ae2227..d58ae187c 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 @@ -41,7 +41,8 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { notificationPublishService); this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService); this.rendererServiceOperations = - new StubRendererServiceOperations(this.networkModelWavelengthService, getDataBroker()); + new StubRendererServiceOperations(this.networkModelWavelengthService, getDataBroker(), + notificationPublishService); this.serviceHandler = new ServicehandlerImpl(getDataBroker(), pathComputationService, this.rendererServiceOperations, this.networkModelWavelengthService); }