Bug 6665 Clean code 11/45411/3
authorJozef Bacigal <jozef.bacigal@pantheon.tech>
Thu, 8 Sep 2016 14:56:30 +0000 (16:56 +0200)
committerJozef Bacigal <jozef.bacigal@pantheon.tech>
Fri, 9 Sep 2016 12:58:32 +0000 (12:58 +0000)
Change-Id: Ia87a66c37f906a3351f3a982209f6778f7c8a311
Signed-off-by: Jozef Bacigal <jozef.bacigal@pantheon.tech>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtils.java

index 41bee01d5975d497f3a25b445eba4b9b47c9645f..dc71ef042068305d6703222d5037ef07087885a1 100644 (file)
@@ -67,7 +67,8 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     private static final Logger LOG = LoggerFactory.getLogger(OpenFlowPluginProviderImpl.class);
     private static final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
     private static final int TICKS_PER_WHEEL = 500;
-    private static final long TICK_DURATION = 10; // 0.5 sec.
+    // 0.5 sec.
+    private static final long TICK_DURATION = 10;
 
     private final HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(TICK_DURATION, TimeUnit.MILLISECONDS, TICKS_PER_WHEEL);
 
index e0ff00efe0424d2feb40d49fb8a5de559688e098..f68ec73839122308202f38fe7268b3b1834dea15 100644 (file)
@@ -12,12 +12,6 @@ import com.google.common.base.Preconditions;
 import java.math.BigInteger;
 import java.net.InetSocketAddress;
 import java.util.Objects;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
index 2465c84efd69b5acfd85004876d7a30fb7fa8663..93fba6039e6d3fe1a8abe0991b1f5426450fc126 100644 (file)
@@ -230,7 +230,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     }
 
     @Override
-    public <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path) throws TransactionChainClosedException {
+    public <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path) {
         if (Objects.nonNull(transactionChainManager)) {
             transactionChainManager.addDeleteOperationTotTxChain(store, path);
         }
index 39696efd7b8aa5d730d0899f7c11b308026b77cd..4ada870f2dbca5b17de3a4271645813720232570 100644 (file)
@@ -129,45 +129,8 @@ public class LifecycleServiceImpl implements LifecycleService {
     }
 
     private void fillDeviceFlowRegistry() {
-        // Fill device flow registry with flows from datastore
         final ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill = deviceContext.getDeviceFlowRegistry().fill();
-
-        // Start statistics scheduling only after we finished initializing device flow registry
-        Futures.addCallback(deviceFlowRegistryFill, new FutureCallback<List<Optional<FlowCapableNode>>>() {
-            @Override
-            public void onSuccess(@Nullable List<Optional<FlowCapableNode>> result) {
-                if (LOG.isDebugEnabled()) {
-                    // Count all flows we read from datastore for debugging purposes.
-                    // This number do not always represent how many flows were actually added
-                    // 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, deviceContext.getDeviceInfo().getLOGValue());
-                }
-            }
-
-            @Override
-            public void onFailure(Throwable t) {
-                if (deviceFlowRegistryFill.isCancelled()) {
-                    if (LOG.isDebugEnabled()) {
-                        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: {}", deviceContext.getDeviceInfo().getLOGValue(), t);
-                }
-            }
-        });
+        Futures.addCallback(deviceFlowRegistryFill, new DeviceFlowRegistryCallback(deviceFlowRegistryFill));
     }
 
     @Override
@@ -188,4 +151,46 @@ public class LifecycleServiceImpl implements LifecycleService {
         fillDeviceFlowRegistry();
         return true;
     }
+
+    private class DeviceFlowRegistryCallback implements FutureCallback<List<Optional<FlowCapableNode>>> {
+        private final ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill;
+
+        public DeviceFlowRegistryCallback(ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill) {
+            this.deviceFlowRegistryFill = deviceFlowRegistryFill;
+        }
+
+        @Override
+        public void onSuccess(@Nullable List<Optional<FlowCapableNode>> result) {
+            if (LOG.isDebugEnabled()) {
+                // Count all flows we read from datastore for debugging purposes.
+                // This number do not always represent how many flows were actually added
+                // 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, deviceContext.getDeviceInfo().getLOGValue());
+            }
+        }
+
+        @Override
+        public void onFailure(Throwable t) {
+            if (deviceFlowRegistryFill.isCancelled()) {
+                if (LOG.isDebugEnabled()) {
+                    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: {}", deviceContext.getDeviceInfo().getLOGValue(), t);
+            }
+        }
+    }
 }
index 8d5061cd13e697e076ce9ddfc4e7ae574e82eb5a..0ffdbab0f47dd27b981d3ade5885f03e953390fd 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
@@ -416,7 +417,9 @@ public class DeviceInitializationUtils {
     // FIXME : remove after ovs tableFeatures fix
     private static void makeEmptyTables(final DeviceContext dContext, final InstanceIdentifier<Node> nodeII,
                                         final Short nrOfTables) {
-        LOG.debug("About to create {} empty tables.", nrOfTables);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("About to create {} empty tables.", nrOfTables);
+        }
         for (int i = 0; i < nrOfTables; i++) {
             final short tId = (short) i;
             final InstanceIdentifier<Table> tableII = nodeII.augmentation(FlowCapableNode.class).child(Table.class,
@@ -447,7 +450,7 @@ public class DeviceInitializationUtils {
                 } else {
                     for (RpcError rpcError : rpcResult.getErrors()) {
                         LOG.info("Failed to retrieve static node {} info: {}", type, rpcError.getMessage());
-                        if (null != rpcError.getCause()) {
+                        if (LOG.isTraceEnabled() && Objects.nonNull(rpcError.getCause())) {
                             LOG.trace("Detailed error:", rpcError.getCause());
                         }
                     }
@@ -466,7 +469,9 @@ public class DeviceInitializationUtils {
     }
 
     private static ListenableFuture<RpcResult<List<MultipartReply>>> getNodeStaticInfo(final MultipartType type,
-                                                                                       final DeviceContext deviceContext, final InstanceIdentifier<Node> nodeII, final short version) {
+                                                                                       final DeviceContext deviceContext,
+                                                                                       final InstanceIdentifier<Node> nodeII,
+                                                                                       final short version) {
 
         final OutboundQueue queue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider();
 
@@ -521,21 +526,30 @@ public class DeviceInitializationUtils {
                                          final ListenableFuture<List<RpcResult<List<MultipartReply>>>> deviceFeaturesFuture) {
 
         try {
-            LOG.trace("Waiting for protocol version 1.0");
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Waiting for protocol version 1.0");
+            }
             List<RpcResult<List<MultipartReply>>> results = deviceFeaturesFuture.get();
             boolean allSucceeded = true;
             for (final RpcResult<List<MultipartReply>> rpcResult : results) {
                 allSucceeded &= rpcResult.isSuccessful();
             }
             if (allSucceeded) {
-                LOG.debug("Creating emtpy flow capable node: {}", deviceContext.getDeviceInfo().getNodeId().getValue());
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Creating empty flow capable node: {}", deviceContext.getDeviceInfo().getLOGValue());
+                }
                 createEmptyFlowCapableNodeInDs(deviceContext);
-                LOG.debug("Creating emtpy tables for {}", deviceContext.getDeviceInfo().getNodeId().getValue());
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Creating empty tables for {}", deviceContext.getDeviceInfo().getLOGValue());
+                }
                 makeEmptyTables(deviceContext, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(),
                         deviceContext.getPrimaryConnectionContext().getFeatures().getTables());
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.warn("Error occurred in preparation node {} for protocol 1.0", deviceContext.getDeviceInfo().getNodeId().getValue());
+            LOG.warn("Error occurred in preparation node {} for protocol 1.0", deviceContext.getDeviceInfo().getLOGValue());
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Error for node {} : ", deviceContext.getDeviceInfo().getLOGValue(), e);
+            }
         }
     }
 }