*/
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);
}
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;
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;
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)
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));
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));
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 =
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,
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;
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
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);
}
}
<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" />
<argument ref="olmService" />
<argument ref="dataBroker" />
<argument ref="networkModelWavelengthService" />
+ <argument ref="notificationPublishService" />
</bean>
<bean id="rendererProvider" class="org.opendaylight.transportpce.renderer.RendererProvider"
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;
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;
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);
}
.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());
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());
}
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());
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;
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;
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(),
}
@Test
- public void serviceImplementationTerminationPointAsResourceTtp() {
+ public void serviceImplementationTerminationPointAsResourceTtp() throws InterruptedException, ExecutionException {
ServiceImplementationRequestInput input = ServiceDataUtils
.buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.TTP_TOKEN);
.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);
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);
.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);
.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,
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());
}
}
@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());
}
}
@Test
- public void serviceImplementationServiceInActive() {
+ public void serviceImplementationServiceInActive() throws InterruptedException, ExecutionException {
ServiceImplementationRequestInput input = ServiceDataUtils
.buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
.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);
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);
.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);
.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);
.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);
.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);
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());
}
--- /dev/null
+/*
+ * 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");
+ }
+
+}
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 !";
.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())) {
.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())) {
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 !";
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;
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;
+ }
+ });
}
}
import java.util.concurrent.TimeoutException;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.transportpce.common.ResponseCodes;
import org.opendaylight.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;
/** 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);
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())
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);
}
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)
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;
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;
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
.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"));
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();
.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 =
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();
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();
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()))
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()))
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);
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"));
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"));
.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"));
.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"));
.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"));
.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"));
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);
}