Service-notification handling for Renderer 92/78292/17
authorMartial COULIBALY <martial.coulibaly@gfi.fr>
Thu, 29 Nov 2018 08:20:23 +0000 (09:20 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Thu, 7 Feb 2019 13:53:47 +0000 (14:53 +0100)
- 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 <martial.coulibaly@gfi.fr>
12 files changed:
renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperations.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImpl.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/rpcs/TransportPCEServicePathRPCImpl.java
renderer/src/main/resources/org/opendaylight/blueprint/renderer-blueprint.xml
renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImplDeleteTest.java
renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImplTest.java
renderer/src/test/java/org/opendaylight/transportpce/renderer/utils/NotificationPublishServiceMock.java [new file with mode: 0644]
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java

index fcaf88c878b58a626d44cb7622da91ab33bd518c..2ba2583d807003de51e9e8f9b0827775ea895266 100644 (file)
@@ -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<ServiceImplementationRequestOutput> serviceImplementation(ServiceImplementationRequestInput input);
 
-    ServiceDeleteOutput serviceDelete(ServiceDeleteInput input);
+    ListenableFuture<ServiceDeleteOutput> serviceDelete(ServiceDeleteInput input);
 
 }
index 9aa073a99057bba54a889df4141419a8d1941e55..831efbcd8d44d0d8dc192757370be89ead08a5b0 100644 (file)
@@ -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<DeviceRenderingResult> 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> 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<ServiceImplementationRequestOutput>
+            serviceImplementation(ServiceImplementationRequestInput input) {
+        LOG.info("Calling service impl request {} {}", input.getServiceName());
+        return executor.submit(new Callable<ServiceImplementationRequestOutput>() {
+
+            @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<DeviceRenderingResult> 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> 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<ServiceDeleteOutput> serviceDelete(ServiceDeleteInput input) {
         String serviceName = input.getServiceName();
-
-        // Obtain path description
-        Optional<PathDescription> 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<ServiceDeleteOutput>() {
+
+            @Override
+            public ServiceDeleteOutput call() throws Exception {
+                sendNotifications(ServicePathNotificationTypes.ServiceDelete, input.getServiceName(),
+                        RpcStatusEx.Pending, "Service compliant, submitting service delete Request ...");
+                // Obtain path description
+                Optional<PathDescription> 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<DeviceRenderingResult> 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<DeviceRenderingResult> 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<DeviceRenderingResult> 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<OLMRenderingResult> 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<OLMRenderingResult> olmPowerSetupFutureZtoA
                 = this.executor.submit(new OlmPowerSetupTask(this.olmService, powerSetupInputZtoA));
         ListenableFuture<List<OLMRenderingResult>> 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,
index 3dd8c178c1d3eed8b61a4add4975286ad1c784db..dce7d7178e6a1c248456a4dcf8aa7c56962efd20 100644 (file)
@@ -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<RpcResult<ServiceDeleteOutput>> 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);
     }
 
 }
index 6ef15d1874651f9ea20fe086432a13804329c732..90747b71d83cca152a472bd3eddcb6193b7a06b6 100644 (file)
@@ -13,6 +13,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
   <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
         odl:type="default" />
+  <reference id="notificationPublishService"
+        interface="org.opendaylight.controller.md.sal.binding.api.NotificationPublishService"
+        odl:type="default" />
   <reference id="rpcProviderRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry" />
   <reference id="deviceTransactionManager" interface="org.opendaylight.transportpce.common.device.DeviceTransactionManager" />
   <reference id="openRoadmInterfaces" interface="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces" />
@@ -50,6 +53,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <argument ref="olmService" />
     <argument ref="dataBroker" />
     <argument ref="networkModelWavelengthService" />
+    <argument ref="notificationPublishService" />
   </bean>
 
   <bean id="rendererProvider" class="org.opendaylight.transportpce.renderer.RendererProvider"
index 9a89f3ed541ebcef35851dbd3ebff42999f6d7ea..32b6544ee2eeba6a55ae82cc3885f907f594b566 100644 (file)
@@ -8,16 +8,20 @@
 
 package org.opendaylight.transportpce.renderer.provisiondevice;
 
+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.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.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
@@ -34,6 +38,7 @@ import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterf
 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.NotificationPublishServiceMock;
 import org.opendaylight.transportpce.renderer.utils.ServiceDeleteDataUtils;
 import org.opendaylight.transportpce.renderer.utils.TransactionUtils;
 import org.opendaylight.transportpce.test.AbstractTest;
@@ -84,8 +89,9 @@ public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
         ListeningExecutorService executor =
                 MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
         this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
+        NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
         this.rendererServiceOperations =  new RendererServiceOperationsImpl(this.deviceRenderer, olmService,
-                getDataBroker(), this.networkModelWavelengthService);
+                getDataBroker(), this.networkModelWavelengthService, notificationPublishService);
 
     }
 
@@ -99,18 +105,18 @@ public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
                 .setRequestId("request1").build());
         Mockito.doReturn(true).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(), Mockito.anyString());
         ServiceDeleteOutput serviceDeleteOutput
-                = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build());
+                = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()).get();
         Assert.assertEquals(ResponseCodes.RESPONSE_OK,
                 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
         Mockito.verify(this.crossConnect, Mockito.times(2)).deleteCrossConnect(Mockito.any(), Mockito.any());
     }
 
     @Test
-    public void serviceDeleteOperationNoDescription() {
+    public void serviceDeleteOperationNoDescription() throws InterruptedException, ExecutionException {
         ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
         serviceDeleteInputBuilder.setServiceName("service 1");
         ServiceDeleteOutput serviceDeleteOutput
-                = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build());
+                = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()).get();
         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
                 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
         Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.any(), Mockito.any());
@@ -127,10 +133,11 @@ public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
         serviceDeleteInputBuilder.setServiceName("service 1");
         serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
                 .setRequestId("request1").build());
-        ServiceDeleteOutput serviceDeleteOutput
-                = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build());
+        ListenableFuture<ServiceDeleteOutput> 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());
index cc250c95667908ef9a893d71b59129e0a0a3fcb9..af3c0f71d69df027c495047f70d940e6312e57aa 100644 (file)
@@ -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 (file)
index 0000000..1b7a6bf
--- /dev/null
@@ -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");
+    }
+
+}
index 3a07abb10a6c35693ff30748c9253037e40284bb..435e809aba3729ffc0d82147ed8c66ae89d72614 100644 (file)
@@ -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 !";
index 95053ec407b021cf98c2145a690f7dcf23433655..504d4e941bcbaa0b97357c61c42c8c140cae8136 100644 (file)
@@ -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<RpcResult<ServiceImplementationRequestOutput>> 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<ServiceImplementationRequestOutput>
+            serviceImplementation(ServiceImplementationRequestInput input) {
+        return executor.submit(new Callable<ServiceImplementationRequestOutput>() {
+
+            @Override
+            public ServiceImplementationRequestOutput call() {
+                ListenableFuture<RpcResult<ServiceImplementationRequestOutput>> 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<RpcResult<ServiceDeleteOutput>> 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<ServiceDeleteOutput> serviceDelete(ServiceDeleteInput input) {
+        return executor.submit(new Callable<ServiceDeleteOutput>() {
+
+            @Override
+            public ServiceDeleteOutput call() {
+                ListenableFuture<RpcResult<ServiceDeleteOutput>> rpcResultFuture =
+                        stubrendererImpl.serviceDelete(input);
+                try {
+                    return rpcResultFuture.get().getResult();
+                } catch (InterruptedException | ExecutionException e) {
+                    LOG.error("RPC serviceDelete failed !", e);
+                }
+                return null;
+            }
+        });
     }
 }
index a964c97dd5dda3063b9cae1e6680edbab88d360c..91aefe82f19912927a85d1ddfcc275c964d1c090 100644 (file)
@@ -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<RpcResult<ServiceDeleteOutput>> 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)
index 685a4fcc6cab135448c4924877b90d7e27625ed0..f17513e4d503cace3aaf6279f35b27e74503d98d 100644 (file)
@@ -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 <T> ListenableFuture<T> returnFuture(T output) {
+        return executor.submit(new Callable<T>() {
+
+            @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<RpcResult<TempServiceCreateOutput>> 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"));
 
index 8a9ae22275bb1c35818b2e346b873b127cf2b65e..d58ae187c49c0c5eb5ec59739782688075819e7e 100644 (file)
@@ -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);
     }