Fix spotbugs issues of the renderer module
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / RendererServiceOperationsImpl.java
index cfcb2abc3fa0566dda8517b3a065c6c44cc7f526..3e34805ed6578e7ee40f8b65209621d3c9b58e3c 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 java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
@@ -20,6 +21,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 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;
@@ -68,6 +70,12 @@ import org.slf4j.LoggerFactory;
 
 public class RendererServiceOperationsImpl implements RendererServiceOperations {
 
+    private static final String DEVICE_RENDERING_ROLL_BACK_MSG =
+            "Device rendering was not successful! Rendering will be rolled back.";
+    private static final String OLM_ROLL_BACK_MSG =
+            "OLM power setup was not successful! Rendering and OLM will be rolled back.";
+    private static final String RENDERING_DEVICES_A_Z_MSG = "Rendering devices A-Z";
+    private static final String TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG = "Turning down power on A-to-Z path";
     private static final Logger LOG = LoggerFactory.getLogger(RendererServiceOperationsImpl.class);
     private static final String FAILED = "Failed";
     private static final String OPERATION_FAILED = "Operation Failed";
@@ -127,7 +135,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
                         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.");
+                            RpcStatusEx.Failed, DEVICE_RENDERING_ROLL_BACK_MSG);
                     return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED);
                 }
                 ServicePowerSetupInput olmPowerSetupInputAtoZ =
@@ -138,7 +146,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
                 if (rollbackProcessor.rollbackAllIfNecessary() > 0) {
                     sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest, input.getServiceName(),
                             RpcStatusEx.Failed,
-                            "OLM power setup was not successful! Rendering and OLM will be rolled back.");
+                            OLM_ROLL_BACK_MSG);
                     return ModelMappingUtils.createServiceImplResponse(ResponseCodes.RESPONSE_FAILED, OPERATION_FAILED);
                 }
                 // run service activation test twice - once on source node and once on
@@ -174,6 +182,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         });
     }
 
+    @Override
     @SuppressWarnings("checkstyle:IllegalCatch")
     public OperationResult reserveResource(PathDescription pathDescription) {
 
@@ -187,6 +196,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         return OperationResult.ok("Resources reserved successfully in network model");
     }
 
+    @Override
     @SuppressWarnings("checkstyle:IllegalCatch")
     public OperationResult freeResource(PathDescription pathDescription) {
 
@@ -226,9 +236,9 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
                         ModelMappingUtils.rendererCreateServiceInputZToA(serviceName, pathDescription);
                 // OLM turn down power
                 try {
-                    LOG.debug("Turning down power on A-to-Z path");
+                    LOG.debug(TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG);
                     sendNotifications(ServicePathNotificationTypes.ServiceDelete,
-                            input.getServiceName(), RpcStatusEx.Pending, "Turning down power on A-to-Z path");
+                            input.getServiceName(), RpcStatusEx.Pending, TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG);
                     ServicePowerTurndownOutput atozPowerTurndownOutput = olmPowerTurndown(servicePathInputDataAtoZ);
                     // TODO add some flag rather than string
                     if (FAILED.equals(atozPowerTurndownOutput.getResult())) {
@@ -273,14 +283,20 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
 
     }
 
+    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+            value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "call in call() method")
     private ServicePowerTurndownOutput olmPowerTurndown(ServicePathInputData servicePathInputData)
             throws InterruptedException, ExecutionException, TimeoutException {
-        LOG.debug("Turning down power on A-to-Z path");
+        LOG.debug(TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG);
         Future<RpcResult<ServicePowerTurndownOutput>> powerTurndownFuture = this.olmService.servicePowerTurndown(
                 new ServicePowerTurndownInputBuilder(servicePathInputData.getServicePathInput()).build());
         return powerTurndownFuture.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS).getResult();
     }
 
+    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+            value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "call in call() method")
     private Optional<PathDescription> getPathDescriptionFromDatastore(String serviceName) {
         InstanceIdentifier<PathDescription> pathDescriptionIID = InstanceIdentifier.create(ServicePathList.class)
                 .child(ServicePaths.class, new ServicePathsKey(serviceName)).child(PathDescription.class);
@@ -296,12 +312,15 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         }
     }
 
+    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+            value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "call in call() method")
     private List<DeviceRenderingResult> deviceRendering(RollbackProcessor rollbackProcessor,
             ServicePathInputData servicePathDataAtoZ, ServicePathInputData servicePathDataZtoA) {
-        LOG.info("Rendering devices A-Z");
+        LOG.info(RENDERING_DEVICES_A_Z_MSG);
         sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest,
                 servicePathDataAtoZ.getServicePathInput().getServiceName(), RpcStatusEx.Pending,
-                "Rendering devices A-Z");
+                RENDERING_DEVICES_A_Z_MSG);
         ListenableFuture<DeviceRenderingResult> atozrenderingFuture =
                 this.executor.submit(new DeviceRenderingTask(this.deviceRenderer, servicePathDataAtoZ,
                         ServicePathDirection.A_TO_Z));
@@ -309,7 +328,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         LOG.info("Rendering devices Z-A");
         sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest,
                 servicePathDataAtoZ.getServicePathInput().getServiceName(), RpcStatusEx.Pending,
-                "Rendering devices A-Z");
+                RENDERING_DEVICES_A_Z_MSG);
         ListenableFuture<DeviceRenderingResult> ztoarenderingFuture =
                 this.executor.submit(new DeviceRenderingTask(this.deviceRenderer, servicePathDataZtoA,
                         ServicePathDirection.Z_TO_A));
@@ -321,10 +340,10 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             LOG.info("Waiting for A-Z and Z-A device renderers ...");
             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);
+            LOG.warn(DEVICE_RENDERING_ROLL_BACK_MSG, e);
             sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest,
                     servicePathDataAtoZ.getServicePathInput().getServiceName(), RpcStatusEx.Pending,
-                    "Device rendering was not successful! Rendering will be rolled back.");
+                    DEVICE_RENDERING_ROLL_BACK_MSG);
             //FIXME we can't do rollback here, because we don't have rendering results.
             return renderingResults;
         }
@@ -338,6 +357,9 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
         return renderingResults;
     }
 
+    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+            value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "call in call() method")
     private void olmPowerSetup(RollbackProcessor rollbackProcessor, ServicePowerSetupInput powerSetupInputAtoZ,
             ServicePowerSetupInput powerSetupInputZtoA) {
         LOG.info("Olm power setup A-Z");
@@ -359,10 +381,10 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             LOG.info("Waiting for A-Z and Z-A OLM power setup ...");
             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);
+            LOG.warn(OLM_ROLL_BACK_MSG, e);
             sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest,
                     powerSetupInputAtoZ.getServiceName(), RpcStatusEx.Pending,
-                    "OLM power setup was not successful! Rendering and OLM will be rolled back.");
+                    OLM_ROLL_BACK_MSG);
             rollbackProcessor.addTask(new OlmPowerSetupRollbackTask("AtoZOLMTask", true,
                     this.olmService, powerSetupInputAtoZ));
             rollbackProcessor.addTask(new OlmPowerSetupRollbackTask("ZtoAOLMTask", true,
@@ -376,6 +398,9 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
                 this.olmService, powerSetupInputZtoA));
     }
 
+    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+            value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "call in call() method")
     private boolean isServiceActivated(String nodeId, String tpId) {
         LOG.info("Starting service activation test on node {} and tp {}", nodeId, tpId);
         for (int i = 0; i < 3; i++) {