Merge "Sonar - technical debt of FRS app"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / lifecycle / LifecycleServiceImpl.java
index dbac44a2705b2c62020e6d812c847d5561feffe4..729a3d8718defb60a2a01985ed0e8c3da2766b9a 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collection;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import javax.annotation.Nullable;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
@@ -44,8 +45,7 @@ public class LifecycleServiceImpl implements LifecycleService {
         try {
 
             if (LOG.isDebugEnabled()) {
-                LOG.debug("Starting clustering MASTER services for node {}", this.deviceContext.getDeviceInfo().getNodeId().getValue());
-                LOG.debug("===============================================");
+                LOG.debug("========== Starting clustering MASTER services for node {} ==========", this.deviceContext.getDeviceInfo().getLOGValue());
             }
 
             if (connectionInterrupted()) {
@@ -98,7 +98,7 @@ public class LifecycleServiceImpl implements LifecycleService {
 
     private boolean connectionInterrupted() {
         if (this.deviceContext.getPrimaryConnectionContext().getConnectionState().equals(ConnectionContext.CONNECTION_STATE.RIP)) {
-            LOG.warn("Node {} was disconnected, will stop starting MASTER services.", this.deviceContext.getDeviceInfo().getNodeId().getValue());
+            LOG.warn("Node {} was disconnected, will stop starting MASTER services.", this.deviceContext.getDeviceInfo().getLOGValue());
             return true;
         }
         return false;
@@ -106,10 +106,27 @@ public class LifecycleServiceImpl implements LifecycleService {
 
     @Override
     public ListenableFuture<Void> closeServiceInstance() {
-        roleContext.stopClusterServices();
-        statContext.stopClusterServices();
-        rpcContext.stopClusterServices();
-        return deviceContext.stopClusterServices();
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("========== Stopping clustering MASTER services for node {} ==========", this.deviceContext.getDeviceInfo().getLOGValue());
+        }
+
+        final boolean connectionInterrupted =
+                this.deviceContext
+                        .getPrimaryConnectionContext()
+                        .getConnectionState()
+                        .equals(ConnectionContext.CONNECTION_STATE.RIP);
+
+        LOG.info("Stopping role context cluster services for node {}", getIdentifier());
+        roleContext.stopClusterServices(connectionInterrupted);
+
+        LOG.info("Stopping statistics context cluster services for node {}", getIdentifier());
+        statContext.stopClusterServices(connectionInterrupted);
+
+        LOG.info("Stopping rpc context cluster services for node {}", getIdentifier());
+        rpcContext.stopClusterServices(connectionInterrupted);
+
+        LOG.info("Stopping device context cluster services for node {}", getIdentifier());
+        return deviceContext.stopClusterServices(connectionInterrupted);
     }
 
     @Override
@@ -175,21 +192,27 @@ public class LifecycleServiceImpl implements LifecycleService {
                     // to DeviceFlowRegistry, because of possible duplicates.
                     long flowCount = Optional.fromNullable(result).asSet().stream()
                             .flatMap(Collection::stream)
+                            .filter(Objects::nonNull)
                             .flatMap(flowCapableNodeOptional -> flowCapableNodeOptional.asSet().stream())
+                            .filter(Objects::nonNull)
+                            .filter(flowCapableNode -> Objects.nonNull(flowCapableNode.getTable()))
                             .flatMap(flowCapableNode -> flowCapableNode.getTable().stream())
+                            .filter(Objects::nonNull)
+                            .filter(table -> Objects.nonNull(table.getFlow()))
                             .flatMap(table -> table.getFlow().stream())
+                            .filter(Objects::nonNull)
                             .count();
 
-                    LOG.debug("Finished filling flow registry with {} flows for node: {}", flowCount, getIdentifier());
+                    LOG.debug("Finished filling flow registry with {} flows for node: {}", flowCount, deviceContext.getDeviceInfo().getLOGValue());
                 }
             }
 
             @Override
             public void onFailure(Throwable t) {
                 if (deviceFlowRegistryFill.isCancelled()) {
-                    LOG.debug("Cancelled filling flow registry with flows for node: {}", getIdentifier());
+                    LOG.debug("Cancelled filling flow registry with flows for node: {}", deviceContext.getDeviceInfo().getLOGValue());
                 } else {
-                    LOG.warn("Failed filling flow registry with flows for node: {} with exception: {}", getIdentifier(), t);
+                    LOG.warn("Failed filling flow registry with flows for node: {} with exception: {}", deviceContext.getDeviceInfo().getLOGValue(), t);
                 }
             }
         });