Declare SuppressFBWarnings in imports
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / RendererServiceOperationsImpl.java
index c8c620d4c58ac01f75dd456bb165fb1d017d80c7..4108679e7be55f0ca65fd259ba2e903a76dcf268 100644 (file)
@@ -11,6 +11,7 @@ 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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -63,7 +64,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.No
 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.Services;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.PathDescription;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.PathDescription;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.RpcStatusEx;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.ServicePathNotificationTypes;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
@@ -76,10 +77,14 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.common.Uint32;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
+@Component(immediate = true)
 public class RendererServiceOperationsImpl implements RendererServiceOperations {
 
     private static final Logger LOG = LoggerFactory.getLogger(RendererServiceOperationsImpl.class);
@@ -103,9 +108,13 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
     private final PortMapping portMapping;
     private ListeningExecutorService executor;
 
-    public RendererServiceOperationsImpl(DeviceRendererService deviceRenderer,
-            OtnDeviceRendererService otnDeviceRenderer, TransportpceOlmService olmService,
-            DataBroker dataBroker, NotificationPublishService notificationPublishService, PortMapping portMapping) {
+    @Activate
+    public RendererServiceOperationsImpl(@Reference DeviceRendererService deviceRenderer,
+            @Reference OtnDeviceRendererService otnDeviceRenderer,
+            @Reference TransportpceOlmService olmService,
+            @Reference DataBroker dataBroker,
+            @Reference NotificationPublishService notificationPublishService,
+            @Reference PortMapping portMapping) {
         this.deviceRenderer = deviceRenderer;
         this.otnDeviceRenderer = otnDeviceRenderer;
         this.olmService = olmService;
@@ -113,12 +122,14 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         this.notificationPublishService = notificationPublishService;
         this.portMapping = portMapping;
         this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
+        LOG.debug("RendererServiceOperationsImpl instantiated");
     }
 
     @Override
     public ListenableFuture<ServiceImplementationRequestOutput>
-            serviceImplementation(ServiceImplementationRequestInput input) {
+            serviceImplementation(ServiceImplementationRequestInput input, boolean isTempService) {
         LOG.info("Calling service impl request {}", input.getServiceName());
+        LOG.debug("Check if it is temp-service {}", isTempService);
         return executor.submit(new Callable<ServiceImplementationRequestOutput>() {
 
             @Override
@@ -154,7 +165,8 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
                     case StringConstants.SERVICE_TYPE_OTUC2:
                     case StringConstants.SERVICE_TYPE_OTUC3:
                     case StringConstants.SERVICE_TYPE_OTUC4:
-                        if (!manageServicePathCreation(input, serviceType)) {
+                        LOG.debug("Check temp service {}", isTempService);
+                        if (!manageServicePathCreation(input, serviceType, isTempService)) {
                             return ModelMappingUtils
                                 .createServiceImplResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED);
                         }
@@ -211,21 +223,21 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
                     return ModelMappingUtils
                         .createServiceDeleteResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED);
                 }
-                PathDescription pathDescription = pathDescriptionOpt.get();
+                PathDescription pathDescription = pathDescriptionOpt.orElseThrow();
                 String serviceType =
                     ServiceTypes.getServiceType(
                         service.getServiceAEnd().getServiceFormat().getName(),
                         service.getServiceAEnd().getServiceRate(),
                         service.getServiceAEnd().getTxDirection() == null
-                                || service.getServiceAEnd().getTxDirection().values().stream().findFirst().get()
+                                || service.getServiceAEnd().getTxDirection().values().stream().findFirst().orElseThrow()
                                     .getPort() == null
-                                || service.getServiceAEnd().getTxDirection().values().stream().findFirst().get()
+                                || service.getServiceAEnd().getTxDirection().values().stream().findFirst().orElseThrow()
                                     .getPort().getPortName() == null
                             ? null
                             : portMapping.getMapping(
                                     service.getServiceAEnd().getNodeId().getValue(),
-                                    service.getServiceAEnd().getTxDirection().values().stream().findFirst().get()
-                                        .getPort().getPortName()));
+                                    service.getServiceAEnd().getTxDirection().values().stream().findFirst()
+                                        .orElseThrow().getPort().getPortName()));
                 switch (serviceType) {
                     case StringConstants.SERVICE_TYPE_100GE_T:
                     case StringConstants.SERVICE_TYPE_400GE:
@@ -262,7 +274,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         });
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
         value = "UPM_UNCALLED_PRIVATE_METHOD",
         justification = "call in call() method")
     private Uint32 getServiceRate(ServiceImplementationRequestInput input) {
@@ -306,7 +318,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             .get(serviceName);
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
             value = "UPM_UNCALLED_PRIVATE_METHOD",
             justification = "call in call() method")
     private ServicePowerTurndownOutput olmPowerTurndown(ServicePathInputData servicePathInputData)
@@ -319,7 +331,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             .getResult();
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
             value = "UPM_UNCALLED_PRIVATE_METHOD",
             justification = "call in call() method")
     private Optional<org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118
@@ -342,7 +354,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         }
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
             value = "UPM_UNCALLED_PRIVATE_METHOD",
             justification = "call in call() method")
     private List<DeviceRenderingResult> deviceRendering(
@@ -404,7 +416,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         return renderingResults;
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
         value = "UPM_UNCALLED_PRIVATE_METHOD",
         justification = "call in call() method")
     private List<OtnDeviceRenderingResult> otnDeviceRendering(
@@ -462,37 +474,41 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         return otnRenderingResults;
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
             value = "UPM_UNCALLED_PRIVATE_METHOD",
             justification = "call in call() method")
     private void olmPowerSetup(
             RollbackProcessor rollbackProcessor,
             ServicePowerSetupInput powerSetupInputAtoZ,
-            ServicePowerSetupInput powerSetupInputZtoA) {
+            ServicePowerSetupInput powerSetupInputZtoA, boolean isTempService) {
 
         //TODO olmPowerSetupFutureAtoZ & olmPowerSetupFutureZtoA & olmFutures used only once
         //     Do notifications & LOG.info deserve this ?
         //TODO use constants for LOG.info & notifications common messages
+        // if the service create is a temp-service, OLM will be skipped
+        if (isTempService) {
+            LOG.info("For temp-service create OLM is not computed and skipped");
+            return;
+        }
         LOG.info("Olm power setup A-Z");
         sendNotifications(
-            ServicePathNotificationTypes.ServiceImplementationRequest,
-            powerSetupInputAtoZ.getServiceName(),
-            RpcStatusEx.Pending,
-            "Olm power setup A-Z");
+                ServicePathNotificationTypes.ServiceImplementationRequest,
+                powerSetupInputAtoZ.getServiceName(),
+                RpcStatusEx.Pending,
+                "Olm power setup A-Z");
         ListenableFuture<OLMRenderingResult> olmPowerSetupFutureAtoZ =
-            this.executor.submit(new OlmPowerSetupTask(this.olmService, powerSetupInputAtoZ));
+                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");
+                ServicePathNotificationTypes.ServiceImplementationRequest,
+                powerSetupInputAtoZ.getServiceName(),
+                RpcStatusEx.Pending,
+                "Olm power setup Z-A");
         ListenableFuture<OLMRenderingResult> olmPowerSetupFutureZtoA =
-            this.executor.submit(new OlmPowerSetupTask(this.olmService, powerSetupInputZtoA));
-
+                this.executor.submit(new OlmPowerSetupTask(this.olmService, powerSetupInputZtoA));
         ListenableFuture<List<OLMRenderingResult>> olmFutures =
-            Futures.allAsList(olmPowerSetupFutureAtoZ, olmPowerSetupFutureZtoA);
+                Futures.allAsList(olmPowerSetupFutureAtoZ, olmPowerSetupFutureZtoA);
 
         List<OLMRenderingResult> olmResults;
         try {
@@ -501,32 +517,31 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             LOG.warn(OLM_ROLL_BACK_MSG, e);
             sendNotifications(
-                ServicePathNotificationTypes.ServiceImplementationRequest,
-                powerSetupInputAtoZ.getServiceName(),
-                RpcStatusEx.Pending,
-                OLM_ROLL_BACK_MSG);
+                    ServicePathNotificationTypes.ServiceImplementationRequest,
+                    powerSetupInputAtoZ.getServiceName(),
+                    RpcStatusEx.Pending,
+                    OLM_ROLL_BACK_MSG);
             rollbackProcessor.addTask(
-                new OlmPowerSetupRollbackTask("AtoZOLMTask", true, this.olmService, powerSetupInputAtoZ));
+                    new OlmPowerSetupRollbackTask("AtoZOLMTask", true, this.olmService, powerSetupInputAtoZ));
             rollbackProcessor.addTask(
-                new OlmPowerSetupRollbackTask("ZtoAOLMTask", true, this.olmService, powerSetupInputZtoA));
+                    new OlmPowerSetupRollbackTask("ZtoAOLMTask", true, this.olmService, powerSetupInputZtoA));
             return;
         }
-
         rollbackProcessor.addTask(
-            new OlmPowerSetupRollbackTask(
-                "AtoZOLMTask",
-                olmResults.get(0).isSuccess(),
-                this.olmService,
-                powerSetupInputAtoZ));
+                new OlmPowerSetupRollbackTask(
+                        "AtoZOLMTask",
+                        !olmResults.get(0).isSuccess(),
+                        this.olmService,
+                        powerSetupInputAtoZ));
         rollbackProcessor.addTask(
-            new OlmPowerSetupRollbackTask(
-                "ZtoAOLMTask",
-                olmResults.get(1).isSuccess(),
-                this.olmService,
-                powerSetupInputZtoA));
+                new OlmPowerSetupRollbackTask(
+                        "ZtoAOLMTask",
+                        !olmResults.get(1).isSuccess(),
+                        this.olmService,
+                        powerSetupInputZtoA));
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
             value = "UPM_UNCALLED_PRIVATE_METHOD",
             justification = "call in call() method")
     private boolean isServiceActivated(String nodeId, String tpId) {
@@ -609,10 +624,11 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         return result <= threshold;
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
         value = "UPM_UNCALLED_PRIVATE_METHOD",
         justification = "call in call() method")
-    private boolean manageServicePathCreation(ServiceImplementationRequestInput input, String serviceType) {
+    private boolean manageServicePathCreation(ServiceImplementationRequestInput input, String serviceType,
+                                              boolean isTempService) {
         ServicePathInputData servicePathInputDataAtoZ =
             ModelMappingUtils
                 .rendererCreateServiceInputAToZ(input.getServiceName(), input.getPathDescription(), Action.Create);
@@ -636,7 +652,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             //olmPowerSetupInputAtoZ,
             ModelMappingUtils.createServicePowerSetupInput(renderingResults.get(0).getOlmList(), input),
             //olmPowerSetupInputZtoA
-            ModelMappingUtils.createServicePowerSetupInput(renderingResults.get(1).getOlmList(), input));
+            ModelMappingUtils.createServicePowerSetupInput(renderingResults.get(1).getOlmList(), input), isTempService);
         if (rollbackProcessor.rollbackAllIfNecessary() > 0) {
             sendNotifications(
                 ServicePathNotificationTypes.ServiceImplementationRequest,
@@ -688,7 +704,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         return true;
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
         value = "UPM_UNCALLED_PRIVATE_METHOD",
         justification = "call in call() method")
     private boolean manageServicePathDeletion(String serviceName, PathDescription pathDescription, String serviceType)
@@ -765,7 +781,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         return true;
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
         value = "UPM_UNCALLED_PRIVATE_METHOD",
         justification = "call in call() method")
     private boolean manageOtnServicePathCreation(
@@ -821,7 +837,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         return true;
     }
 
-    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    @SuppressFBWarnings(
         value = "UPM_UNCALLED_PRIVATE_METHOD",
         justification = "call in call() method")
     private boolean manageOtnServicePathDeletion(