X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=servicehandler%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fservicehandler%2Fstub%2FStubRendererServiceOperations.java;h=38c1d4c1e63669c6e88a9f815b8a7d1535e87155;hb=4378fca1d31d1f75c0480c752aa711fb885e6135;hp=504d4e941bcbaa0b97357c61c42c8c140cae8136;hpb=7a0c4c325803bb03a89c9e3ee3faddbab41bc7b8;p=transportpce.git diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java index 504d4e941..38c1d4c1e 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java @@ -10,50 +10,142 @@ 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.Optional; 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 java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.transportpce.common.OperationResult; +import org.opendaylight.transportpce.common.ResponseCodes; +import org.opendaylight.transportpce.common.Timeouts; import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutputBuilder; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput; -import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSp; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSpBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.rpc.result.sp.PathTopology; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.service.rpc.result.sp.PathTopologyBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.RpcStatusEx; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.ServicePathNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.service.path.PathDescription; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.Notification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class StubRendererServiceOperations implements RendererServiceOperations { private static final Logger LOG = LoggerFactory.getLogger(StubRendererServiceOperations.class); - private StubrendererImpl stubrendererImpl; private final ListeningExecutorService executor; + private final NotificationPublishService notificationPublishService; + private final NetworkModelWavelengthService networkModelWavelengthService; + private final DataBroker dataBroker; + private Boolean rendererFailed; + private Boolean isnetworkModelWlService; public StubRendererServiceOperations(NetworkModelWavelengthService networkModelWavelengthService, DataBroker dataBroker, NotificationPublishService notificationPublishService) { - this.stubrendererImpl = - new StubrendererImpl(networkModelWavelengthService, dataBroker, notificationPublishService); + this.notificationPublishService = notificationPublishService; + this.networkModelWavelengthService = networkModelWavelengthService; + this.dataBroker = dataBroker; + this.rendererFailed = false; + this.isnetworkModelWlService = true; executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2)); } + private void sendNotifications(Notification notif) { + try { + LOG.info("putting notification : {}", notif); + notificationPublishService.putNotification(notif); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : ", e.getMessage()); + } + } + @Override public ListenableFuture serviceImplementation(ServiceImplementationRequestInput input) { return executor.submit(new Callable() { - @Override public ServiceImplementationRequestOutput call() { - ListenableFuture> rpcResultFuture = - stubrendererImpl.serviceImplementation(input); + LOG.info("serviceImplementation request ..."); + String serviceName = input.getServiceName(); + RpcStatusEx rpcStatusEx = RpcStatusEx.Pending; + ServiceRpcResultSp notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage("Service compliant, submitting serviceImplementation Request ...").build(); + sendNotifications(notification); + String message = ""; + String responseCode = null; + ConfigurationResponseCommonBuilder configurationResponseCommon = null; + ServiceImplementationRequestOutput output = null; try { - return rpcResultFuture.get().getResult(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("RPC serviceImplementation failed !", e); + LOG.info("Wait for 5s til beginning the Renderer serviceImplementation request"); + Thread.sleep(5000); + } catch (InterruptedException e) { + message = "renderer failed !"; + rpcStatusEx = RpcStatusEx.Failed; + responseCode = ResponseCodes.RESPONSE_FAILED; + LOG.error(message); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName(serviceName).setStatus(rpcStatusEx).setStatusMessage(message).build(); + sendNotifications(notification); + configurationResponseCommon = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode).setResponseMessage(message); + output = new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()).build(); + return output; } - return null; + if (rendererFailed) { + LOG.info("forcing renderer to fail"); + message = "renderer failed !"; + rpcStatusEx = RpcStatusEx.Failed; + LOG.error(message); + responseCode = ResponseCodes.RESPONSE_FAILED; + } else { + if (isnetworkModelWlService) { + networkModelWavelengthService.useWavelengths(input.getPathDescription()); + } else { + LOG.warn("No need to execute networkModelWavelengthService..."); + } + message = "service implemented !"; + rpcStatusEx = RpcStatusEx.Successful; + LOG.info(message); + responseCode = ResponseCodes.RESPONSE_OK; + } + PathTopology pathTopology = new PathTopologyBuilder().build(); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage(message).setPathTopology(pathTopology).build(); + sendNotifications(notification); + responseCode = ResponseCodes.RESPONSE_OK; + configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message); + output = new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); + return output; } }); } @@ -61,18 +153,113 @@ public class StubRendererServiceOperations implements RendererServiceOperations @Override public ListenableFuture serviceDelete(ServiceDeleteInput input) { return executor.submit(new Callable() { - @Override public ServiceDeleteOutput call() { - ListenableFuture> rpcResultFuture = - stubrendererImpl.serviceDelete(input); + LOG.info("ServiceDelete request ..."); + String serviceName = input.getServiceName(); + RpcStatusEx rpcStatusEx = RpcStatusEx.Pending; + ServiceRpcResultSp notification = + new ServiceRpcResultSpBuilder().setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage("Service compliant, submitting serviceDelete Request ...").build(); + sendNotifications(notification); + String message = ""; + String responseCode = null; + ConfigurationResponseCommonBuilder configurationResponseCommon = null; + ServiceDeleteOutput output = null; try { - return rpcResultFuture.get().getResult(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("RPC serviceDelete failed !", e); + LOG.info("Wait for 5s til beginning the Renderer serviceDelete request"); + Thread.sleep(5000); + } catch (InterruptedException e) { + message = "deleting service failed !"; + LOG.error("deleting service failed !", e); + responseCode = ResponseCodes.RESPONSE_FAILED; + rpcStatusEx = RpcStatusEx.Failed; + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete).setServiceName(serviceName) + .setStatus(rpcStatusEx).setStatusMessage(message).build(); + sendNotifications(notification); + configurationResponseCommon = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode).setResponseMessage(message); + output = new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()).build(); + } + if (rendererFailed) { + LOG.info("forcing renderer to fail"); + message = "renderer failed !"; + rpcStatusEx = RpcStatusEx.Failed; + LOG.error(message); + responseCode = ResponseCodes.RESPONSE_FAILED; + } else { + if (isnetworkModelWlService) { + // Obtain path description + Optional pathDescriptionOpt = getPathDescriptionFromDatastore(serviceName); + PathDescription pathDescription; + if (pathDescriptionOpt.isPresent()) { + pathDescription = pathDescriptionOpt.get(); + networkModelWavelengthService.freeWavelengths(pathDescription); + } else { + LOG.warn("failed to get pathDescription for service : {}", serviceName); + } + } else { + LOG.warn("No need to execute networkModelWavelengthService..."); + } + message = "service deleted !"; + rpcStatusEx = RpcStatusEx.Successful; + LOG.info(message); + responseCode = ResponseCodes.RESPONSE_OK; } - return null; + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName(serviceName).setStatus(rpcStatusEx) + .setStatusMessage(message).build(); + sendNotifications(notification); + responseCode = ResponseCodes.RESPONSE_OK; + configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message); + output = new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); + return output; } }); } + + private Optional getPathDescriptionFromDatastore(String serviceName) { + InstanceIdentifier pathDescriptionIID = InstanceIdentifier.create(ServicePathList.class) + .child(ServicePaths.class, new ServicePathsKey(serviceName)).child(PathDescription.class); + ReadTransaction pathDescReadTx = this.dataBroker.newReadOnlyTransaction(); + try { + LOG.debug("Getting path description for service {}", serviceName); + return pathDescReadTx.read(LogicalDatastoreType.OPERATIONAL, pathDescriptionIID) + .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + LOG.warn("Exception while getting path description from datastore {} for service {}!", pathDescriptionIID, + serviceName, e); + return Optional.empty(); + } + } + + public void setRendererFailed(Boolean rendererFailed) { + this.rendererFailed = rendererFailed; + } + + public void setIsnetworkModelWlService(Boolean isnetworkModelWlService) { + this.isnetworkModelWlService = isnetworkModelWlService; + } + + @Override + public OperationResult reserveResource(PathDescription pathDescription) { + return null; + } + + @Override + public OperationResult freeResource(PathDescription pathDescription) { + return null; + } }