NBI notification support for service-result-rpc
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / listeners / RendererNotificationHandler.java
index 4bf6d11dd5672da281c3d2534e6c93017f125a8f..2359412db3533f7db799f7613addc7930dcb37fc 100644 (file)
@@ -35,10 +35,10 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.rpc.result.PathComputationResultBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.rpc.result.path.computation.result.AToZBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.rpc.result.path.computation.result.ZToABuilder;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessServiceBuilder;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.process.service.ServiceAEndBuilder;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.process.service.ServiceZEndBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.PublishNotificationProcessService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.PublishNotificationProcessServiceBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service.ServiceAEndBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service.ServiceZEndBuilder;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
@@ -120,6 +120,7 @@ public class RendererNotificationHandler implements RendererListener {
                         .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
                         .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
                         .setCommonId(service.getCommonId())
+                        .setIsTempService(false)
                         .setConnectionType(service.getConnectionType())
                         .setResponseFailed("Renderer service delete failed !")
                         .setMessage("ServiceDelete request failed ...")
@@ -179,32 +180,56 @@ public class RendererNotificationHandler implements RendererListener {
         updateOtnTopology(notification, false);
         PublishNotificationProcessServiceBuilder nbiNotificationBuilder =
             new PublishNotificationProcessServiceBuilder()
-                .setServiceName(input.getServiceName())
                 .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build())
                 .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build())
-                .setCommonId(input.getCommonId()).setConnectionType(input.getConnectionType())
                 .setPublisherName(PUBLISHER);
         String serviceTemp = "";
         if (tempService) {
+            nbiNotificationBuilder.setCommonId(input.getCommonId()).setConnectionType(input.getConnectionType());
+            nbiNotificationBuilder.setIsTempService(true);
+            if (input.getServiceName() != null) {
+                nbiNotificationBuilder.setServiceName(input.getServiceName());
+            }
             OperationResult operationResult = this.serviceDataStoreOperations.modifyTempService(
                     serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
             serviceTemp = "Temp ";
             if (operationResult.isSuccess()) {
+                ServiceRpcResult serviceRpcResult =
+                    sendServiceRpcResultNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
                 sendNbiNotification(nbiNotificationBuilder
                     .setResponseFailed("")
-                    .setMessage("Temp Service implemented !")
+                    .setMessage("Temp Service implemented")
+                    .setAToZ(
+                        new org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service
+                                .AToZBuilder()
+                            .setFrequency(serviceRpcResult.getPathComputationResult().getAToZ().getFrequency())
+                            .setWidth(serviceRpcResult.getPathComputationResult().getAToZ().getWidth())
+                            .setOpticalOperationalMode(serviceRpcResult.getPathComputationResult()
+                                        .getAToZ().getOpticalOperationalMode())
+                            // TODO: add GNSR, OSNR, min/max output powers
+                            .build())
+                    .setZToA(
+                        new org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service
+                                .ZToABuilder()
+                            .setFrequency(serviceRpcResult.getPathComputationResult().getZToA().getFrequency())
+                            .setWidth(serviceRpcResult.getPathComputationResult().getZToA().getWidth())
+                            .setOpticalOperationalMode(serviceRpcResult.getPathComputationResult()
+                                        .getZToA().getOpticalOperationalMode())
+                            // TODO: add GNSR, OSNR, min/max output powers
+                            .build())
                     .setOperationalState(State.InService)
                     .build());
                 LOG.debug("For the Temp service, sending notification on service-result-rpc");
-                sendServiceRpcResultNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
                 return;
             }
         } else {
-            OperationResult operationResult = this.serviceDataStoreOperations.modifyService(
-                    serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
             // Here the service is implemented and the tempService has to be deleted if present
+            nbiNotificationBuilder.setServiceName(input.getServiceName()).setConnectionType(input.getConnectionType());
+            // Make sure temp-service is false
+            nbiNotificationBuilder.setIsTempService(false);
             String commonId = input.getCommonId();
             if (commonId != null) {
+                nbiNotificationBuilder.setCommonId(commonId);
                 if (this.serviceDataStoreOperations.getTempService(commonId).isPresent()) {
                     LOG.info("Temp-service exists with the common-Id {}", commonId);
                     // Delete the common-id from this temp-service-list here
@@ -214,7 +239,8 @@ public class RendererNotificationHandler implements RendererListener {
                     LOG.info("Result for temp-service-list with {} is {}", commonId, tempServiceListDelete);
                 }
             }
-
+            OperationResult operationResult = this.serviceDataStoreOperations.modifyService(
+                    serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
             if (operationResult.isSuccess()) {
                 sendNbiNotification(nbiNotificationBuilder
                     .setResponseFailed("")
@@ -249,8 +275,7 @@ public class RendererNotificationHandler implements RendererListener {
                     .setNotificationType(type)
                     .build();
             LOG.debug("Service update in datastore OK, sending notification {}", serviceHandlerNotification);
-            notificationPublishService.putNotification(
-                    serviceHandlerNotification);
+            notificationPublishService.putNotification(serviceHandlerNotification);
         } catch (InterruptedException e) {
             LOG.warn("Something went wrong while sending notification for service {}",
                     serviceRpcResultSp.getServiceName(), e);
@@ -258,7 +283,8 @@ public class RendererNotificationHandler implements RendererListener {
         }
     }
 
-    private void sendServiceRpcResultNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
+    private ServiceRpcResult sendServiceRpcResultNotification(
+            RendererRpcResultSp notification, ServiceNotificationTypes type) {
         try {
             ServiceRpcResult serviceRpcResult = new ServiceRpcResultBuilder()
                     .setServiceName(notification.getServiceName())
@@ -274,8 +300,9 @@ public class RendererNotificationHandler implements RendererListener {
                                                             .getAToZDirection()
                                                             .getWidth())
                                             // TODO: here the optical operational mode should be set
+                                            // A default value is set here
+                                            .setOpticalOperationalMode("OR-W-400G-oFEC-63.1Gbd")
                                             // TODO: also set the GNSR, OSNR, power values
-                                            .setOpticalOperationalMode("test")
                                             .build())
                             .setZToA(new ZToABuilder()
                                             .setFrequency(notification
@@ -285,19 +312,21 @@ public class RendererNotificationHandler implements RendererListener {
                                                             .getZToADirection()
                                                             .getWidth())
                                             // TODO: here the optical operational mode should be set
+                                            // A default value is set here
+                                            .setOpticalOperationalMode("OR-W-400G-oFEC-63.1Gbd")
                                             // TODO: also set the GNSR, OSNR, power values
-                                            .setOpticalOperationalMode("test")
                                             .build())
                             .build())
                     .build();
             LOG.info("Sending the notification for service-rpc-result {}", serviceRpcResult);
-            notificationPublishService.putNotification(
-                    serviceRpcResult);
+            notificationPublishService.putNotification(serviceRpcResult);
+            return serviceRpcResult;
         } catch (InterruptedException e) {
             LOG.warn("Something went wrong while sending notification for service {}",
                     serviceRpcResultSp.getServiceName(), e);
             Thread.currentThread().interrupt();
         }
+        return null;
     }
 
 
@@ -315,6 +344,7 @@ public class RendererNotificationHandler implements RendererListener {
                 .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
                 .setCommonId(service.getCommonId())
                 .setConnectionType(service.getConnectionType())
+                .setIsTempService(false)
                 .setResponseFailed("Renderer implementation failed !")
                 .setMessage("ServiceCreate request failed ...")
                 .setOperationalState(service.getOperationalState())