X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Fstubrenderer%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fstubrenderer%2Fimpl%2FStubrendererImpl.java;h=23ae97628781b7df6f5f778733c618299f5395db;hb=f635c4d0e4252050154b89d53bd7e658eaf75be8;hp=16132378cea15cf2cbaab98c048d6badbd5b2e55;hpb=bfd3fdb1aee497c5628eb2aaffa3c336544f3a6f;p=transportpce.git diff --git a/tests/stubrenderer/src/main/java/org/opendaylight/transportpce/stubrenderer/impl/StubrendererImpl.java b/tests/stubrenderer/src/main/java/org/opendaylight/transportpce/stubrenderer/impl/StubrendererImpl.java index 16132378c..23ae97628 100644 --- a/tests/stubrenderer/src/main/java/org/opendaylight/transportpce/stubrenderer/impl/StubrendererImpl.java +++ b/tests/stubrenderer/src/main/java/org/opendaylight/transportpce/stubrenderer/impl/StubrendererImpl.java @@ -9,10 +9,18 @@ package org.opendaylight.transportpce.stubrenderer.impl; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; + +import java.util.concurrent.Executors; import java.util.concurrent.Future; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.stubrenderer.SendingRendererRPCs; +import org.opendaylight.transportpce.stubrenderer.StubrendererCompliancyCheck; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutputBuilder; @@ -34,17 +42,22 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** * Class to implement StubrendererService. * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange * */ public class StubrendererImpl implements StubrendererService { - /* Logging. */ + /** Logging. */ private static final Logger LOG = LoggerFactory.getLogger(StubrendererImpl.class); - /* send notification. */ + /** send notification. */ private NotificationPublishService notificationPublishService; private ServiceRpcResultSp notification; + private final ListeningExecutorService executor = MoreExecutors + .listeningDecorator(Executors.newFixedThreadPool(10)); + /** check service sdnc-request-header compliancy. */ + private StubrendererCompliancyCheck compliancyCheck; public StubrendererImpl(NotificationPublishService notificationPublishService) { this.notificationPublishService = notificationPublishService; @@ -53,58 +66,125 @@ public class StubrendererImpl implements StubrendererService { @Override public Future> serviceImplementationRequest( ServiceImplementationRequestInput input) { - String message = ""; LOG.info("RPC serviceImplementationRequest request received"); + String responseCode = ""; + String message = ""; + ConfigurationResponseCommonBuilder configurationResponseCommon = null; - notification = new ServiceRpcResultSpBuilder() - .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) - .setServiceName(input.getServiceName()) - .setStatus(RpcStatusEx.Pending) - .setStatusMessage("Service compliant, submitting serviceImplementation Request ...") - .build(); - try { - notificationPublishService.putNotification(notification); - } catch (InterruptedException e) { - LOG.info("notification offer rejected : " + e); - } + compliancyCheck = new StubrendererCompliancyCheck(input.getServiceName(), input.getServiceHandlerHeader()); + if (compliancyCheck.check(false, true)) { + LOG.info("Service compliant !"); + /** + * If compliant, service-request parameters are verified in order to + * check if there is no missing parameter that prevents calculating + * a path and implement a service. + */ - SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(); - sendingRenderer.serviceImplementation(); - if (sendingRenderer.getSuccess()) { - message = "Service implemented !"; - ServiceRpcResultSpBuilder tmp = new ServiceRpcResultSpBuilder() - .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) - .setServiceName(input.getServiceName()) - .setStatus(RpcStatusEx.Successful) - .setStatusMessage(message); - TopologyBuilder topo = sendingRenderer.getTopology(); - if (topo != null) { - PathTopology path = new PathTopologyBuilder() - .setAToZ(topo.getAToZ()) - .setZToA(topo.getZToA()) + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName(input.getServiceName()) + .setStatus(RpcStatusEx.Pending) + .setStatusMessage("Service compliant, submitting serviceImplementation Request ...") .build(); - tmp.setPathTopology(path); - } - notification = tmp.build(); try { notificationPublishService.putNotification(notification); } catch (InterruptedException e) { - LOG.info("notification offer rejected : " + e); + LOG.info("notification offer rejected : {}", e); } + SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(executor); + FutureCallback rendererCallback = + new FutureCallback() { + String message = ""; + ServiceRpcResultSp notification = null; + + @Override + public void onFailure(Throwable arg0) { + LOG.error("Failure message : {}", arg0.toString()); + LOG.error("Service implementation failed !"); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed) + .setStatusMessage("PCR Request failed : {}" + arg0.getMessage()).build(); + try { + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : {}", e); + } + } + + @Override + public void onSuccess(Boolean response) { + LOG.info("response : {}", response); + if (response) { + message = "Service implemented !"; + TopologyBuilder topo = sendingRenderer.getTopology(); + ServiceRpcResultSpBuilder tmp = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName(input.getServiceName()) + .setStatus(RpcStatusEx.Successful) + .setStatusMessage(message); + if (topo != null) { + PathTopology value = new PathTopologyBuilder() + .setAToZ(topo.getAToZ()) + .setZToA(topo.getZToA()) + .build(); + tmp.setPathTopology(value); + } + notification = tmp.build(); + } else { + message = "Service implementation failed : " + sendingRenderer.getError(); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest) + .setServiceName("") + .setStatus(RpcStatusEx.Failed).setStatusMessage(message) + .build(); + } + LOG.info(notification.toString()); + try { + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : {}", e); + } + LOG.info(message); + } + }; + ListenableFuture renderer = sendingRenderer.serviceImplementation(); + Futures.addCallback(renderer, rendererCallback, executor); + LOG.info("Service implmentation Request in progress "); + configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator("Yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode("200") + .setResponseMessage("Service implementation Request in progress "); + + ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); + return RpcResultBuilder.success(output).buildFuture(); } else { - message = "Service not implemented !"; + message = compliancyCheck.getMessage(); + responseCode = "500"; + LOG.info("Service not compliant caused by : {}", message); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed) + .setStatusMessage("Service not compliant caused by : " + message) + .build(); + try { + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : {}", e); + } } - LOG.info(message); - ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator("Yes") - .setRequestId(input.getServiceHandlerHeader().getRequestId()) - .setResponseCode("200") - .setResponseMessage(message); - + configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator("yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message); ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon.build()) - .build(); + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); return RpcResultBuilder.success(output).buildFuture(); } @@ -112,50 +192,111 @@ public class StubrendererImpl implements StubrendererService { @Override public Future> serviceDelete(ServiceDeleteInput input) { String message = ""; - LOG.info("RPC serviceDelete request received"); - - notification = new ServiceRpcResultSpBuilder() - .setNotificationType(ServicePathNotificationTypes.ServiceDelete) - .setServiceName(input.getServiceName()) - .setStatus(RpcStatusEx.Pending) - .setStatusMessage("Service compliant, submitting ServiceDelete Request ...") - .build(); - try { - notificationPublishService.putNotification(notification); - } catch (InterruptedException e) { - LOG.info("notification offer rejected : " + e); - } + LOG.info("RPC serviceDelete request received"); + String responseCode = ""; + ConfigurationResponseCommonBuilder configurationResponseCommon = null; + compliancyCheck = new StubrendererCompliancyCheck(input.getServiceName(), input.getServiceHandlerHeader()); + if (compliancyCheck.check(false, true)) { + LOG.info("Service compliant !"); + /** + * If compliant, service-request parameters are verified in order to + * check if there is no missing parameter that prevents calculating + * a path and implement a service. + */ - SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(); - sendingRenderer.serviceDelete(); - if (sendingRenderer.getSuccess()) { - message = "Service deleted ! "; - LOG.info(message); - ServiceRpcResultSpBuilder tmp = new ServiceRpcResultSpBuilder() - .setNotificationType(ServicePathNotificationTypes.ServiceDelete) - .setServiceName(input.getServiceName()) - .setStatus(RpcStatusEx.Successful) - .setStatusMessage(message); - notification = tmp.build(); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName(input.getServiceName()) + .setStatus(RpcStatusEx.Pending) + .setStatusMessage("Service compliant, submitting serviceDelete Request ...") + .build(); try { notificationPublishService.putNotification(notification); } catch (InterruptedException e) { - LOG.info("notification offer rejected : " + e); + LOG.info("notification offer rejected : {}", e); } + SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(executor); + FutureCallback rendererCallback = new FutureCallback() { + String message = ""; + ServiceRpcResultSp notification = null; + + @Override + public void onFailure(Throwable arg0) { + LOG.error("Failure message : {}", arg0.toString()); + LOG.error("Service delete failed !"); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed) + .setStatusMessage("PCR Request failed : " + arg0.getMessage()).build(); + try { + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : {}", e); + } + } + + @Override + public void onSuccess(Boolean response) { + LOG.info("response : {}", response); + if (response) { + message = "Service deleted !"; + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Successful) + .setStatusMessage(message).build(); + } else { + message = "Service delete failed : " + sendingRenderer.getError(); + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName("") + .setStatus(RpcStatusEx.Failed).setStatusMessage(message) + .build(); + } + LOG.info(notification.toString()); + try { + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : {}", e); + } + LOG.info(message); + } + }; + ListenableFuture renderer = sendingRenderer.serviceDelete(); + Futures.addCallback(renderer, rendererCallback, executor); + message = "Service delete Request in progress ..."; + LOG.info(message); + configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator("Yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode("200") + .setResponseMessage(message); + ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); + return RpcResultBuilder.success(output).buildFuture(); } else { - message = "Service not deleted !"; + message = compliancyCheck.getMessage(); + LOG.info("Service not compliant caused by : {}", message); + responseCode = "500"; + notification = new ServiceRpcResultSpBuilder() + .setNotificationType(ServicePathNotificationTypes.ServiceDelete) + .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed) + .setStatusMessage("Service not compliant caused by : " + message) + .build(); + try { + notificationPublishService.putNotification(notification); + } catch (InterruptedException e) { + LOG.info("notification offer rejected : {}", e); + } } - LOG.info(message); - ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setAckFinalIndicator("yes") - .setRequestId(input.getServiceHandlerHeader().getRequestId()) - .setResponseCode("200") - .setResponseMessage(message); + configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator("yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message); ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon.build()) - .build(); - + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); return RpcResultBuilder.success(output).buildFuture(); - } }