Sonar - technical debt of FRS app
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / util / ReconcileUtil.java
index e339ccdd4a7f181077a8e25bdf8dde17e7d9c753..a910c01957e0dc8ec57d817d3f9a7a7da105dbcb 100644 (file)
@@ -8,14 +8,12 @@
 
 package org.opendaylight.openflowplugin.applications.frsync.util;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.AsyncFunction;
 import com.google.common.util.concurrent.JdkFutureAdapters;
-import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -25,8 +23,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
-import javax.annotation.Nullable;
-import org.opendaylight.openflowplugin.applications.frsync.markandsweep.SwitchFlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
@@ -53,41 +49,39 @@ import org.slf4j.LoggerFactory;
 /**
  * Util methods for group reconcil task (future chaining, transforms).
  */
-public class ReconcileUtil {
+public final class ReconcileUtil {
 
     private static final Logger LOG = LoggerFactory.getLogger(ReconcileUtil.class);
 
+    private ReconcileUtil() {
+        throw new IllegalStateException("This class should not be instantiated.");
+    }
+
     /**
      * @param previousItemAction description for case when the triggering future contains failure
      * @param <D>                type of rpc output (gathered in list)
      * @return single rpc result of type Void honoring all partial rpc results
      */
     public static <D> Function<List<RpcResult<D>>, RpcResult<Void>> createRpcResultCondenser(final String previousItemAction) {
-        return new Function<List<RpcResult<D>>, RpcResult<Void>>() {
-            @Nullable
-            @Override
-            public RpcResult<Void> apply(@Nullable final List<RpcResult<D>> input) {
-                final RpcResultBuilder<Void> resultSink;
-                if (input != null) {
-                    List<RpcError> errors = new ArrayList<>();
-                    for (RpcResult<D> rpcResult : input) {
-                        if (!rpcResult.isSuccessful()) {
-                            errors.addAll(rpcResult.getErrors());
-                        }
-                    }
-                    if (errors.isEmpty()) {
-                        resultSink = RpcResultBuilder.success();
-                    } else {
-                        resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
+        return input -> {
+            final RpcResultBuilder<Void> resultSink;
+            if (input != null) {
+                List<RpcError> errors = new ArrayList<>();
+                for (RpcResult<D> rpcResult : input) {
+                    if (!rpcResult.isSuccessful()) {
+                        errors.addAll(rpcResult.getErrors());
                     }
+                }
+                if (errors.isEmpty()) {
+                    resultSink = RpcResultBuilder.success();
                 } else {
-                    resultSink = RpcResultBuilder.<Void>failed()
-                            .withError(RpcError.ErrorType.APPLICATION, "previous " + previousItemAction + " failed");
-
+                    resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
                 }
-
-                return resultSink.build();
+            } else {
+                resultSink = RpcResultBuilder.<Void>failed()
+                        .withError(RpcError.ErrorType.APPLICATION, "previous " + previousItemAction + " failed");
             }
+            return resultSink.build();
         };
     }
 
@@ -97,27 +91,21 @@ public class ReconcileUtil {
      * @return single rpc result of type Void honoring all partial rpc results
      */
     public static <D> Function<RpcResult<D>, RpcResult<Void>> createRpcResultToVoidFunction(final String actionDescription) {
-        return new Function<RpcResult<D>, RpcResult<Void>>() {
-            @Nullable
-            @Override
-            public RpcResult<Void> apply(@Nullable final RpcResult<D> input) {
-                final RpcResultBuilder<Void> resultSink;
-                if (input != null) {
-                    List<RpcError> errors = new ArrayList<>();
-                    if (!input.isSuccessful()) {
-                        errors.addAll(input.getErrors());
-                        resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
-                    } else {
-                        resultSink = RpcResultBuilder.success();
-                    }
+        return input -> {
+            final RpcResultBuilder<Void> resultSink;
+            if (input != null) {
+                List<RpcError> errors = new ArrayList<>();
+                if (!input.isSuccessful()) {
+                    errors.addAll(input.getErrors());
+                    resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
                 } else {
-                    resultSink = RpcResultBuilder.<Void>failed()
-                            .withError(RpcError.ErrorType.APPLICATION, "action of " + actionDescription + " failed");
-
+                    resultSink = RpcResultBuilder.success();
                 }
-
-                return resultSink.build();
+            } else {
+                resultSink = RpcResultBuilder.<Void>failed()
+                        .withError(RpcError.ErrorType.APPLICATION, "action of " + actionDescription + " failed");
             }
+            return resultSink.build();
         };
     }
 
@@ -129,14 +117,11 @@ public class ReconcileUtil {
     public static AsyncFunction<RpcResult<Void>, RpcResult<Void>> chainBarrierFlush(
             final InstanceIdentifier<Node> nodeIdent,
             final FlowCapableTransactionService flowCapableTransactionService) {
-        return new AsyncFunction<RpcResult<Void>, RpcResult<Void>>() {
-            @Override
-            public ListenableFuture<RpcResult<Void>> apply(final RpcResult<Void> input) throws Exception {
-                final SendBarrierInput barrierInput = new SendBarrierInputBuilder()
-                        .setNode(new NodeRef(nodeIdent))
-                        .build();
-                return JdkFutureAdapters.listenInPoolThread(flowCapableTransactionService.sendBarrier(barrierInput));
-            }
+        return input -> {
+            final SendBarrierInput barrierInput = new SendBarrierInputBuilder()
+                    .setNode(new NodeRef(nodeIdent))
+                    .build();
+            return JdkFutureAdapters.listenInPoolThread(flowCapableTransactionService.sendBarrier(barrierInput));
         };
     }
 
@@ -163,7 +148,6 @@ public class ReconcileUtil {
                                                                       final Map<Long, Group> installedGroupsArg,
                                                                       final Collection<Group> pendingGroups,
                                                                       final boolean gatherUpdates) {
-
         final Map<Long, Group> installedGroups = new HashMap<>(installedGroupsArg);
         final List<ItemSyncBox<Group>> plan = new ArrayList<>();
 
@@ -262,7 +246,7 @@ public class ReconcileUtil {
                                                        final Map<MeterId, Meter> meterOperationalMap,
                                                        final List<Meter> metersConfigured,
                                                        final boolean gatherUpdates) {
-        LOG.trace("resolving meters for {}", nodeId);
+        LOG.trace("resolving meters for {}", nodeId.getValue());
         final ItemSyncBox<Meter> syncBox = new ItemSyncBox<>();
         for (Meter meter : metersConfigured) {
             final Meter existingMeter = meterOperationalMap.get(meter.getMeterId());
@@ -284,8 +268,7 @@ public class ReconcileUtil {
      * @param gatherUpdates      check content of pending item if present on device (and create update task eventually)
      * @return list of safe synchronization steps
      */
-    @VisibleForTesting
-    static ItemSyncBox<Flow> resolveFlowDiffsInTable(final List<Flow> flowsConfigured,
+    public static ItemSyncBox<Flow> resolveFlowDiffsInTable(final List<Flow> flowsConfigured,
                                                      final Map<SwitchFlowId, Flow> flowOperationalMap,
                                                      final boolean gatherUpdates) {
         final ItemSyncBox<Flow> flowsSyncBox = new ItemSyncBox<>();
@@ -316,7 +299,7 @@ public class ReconcileUtil {
                                                                                final Map<Short, Table> tableOperationalMap,
                                                                                final List<Table> tablesConfigured,
                                                                                final boolean gatherUpdates) {
-        LOG.trace("resolving flows in tables for {}", nodeId);
+        LOG.trace("resolving flows in tables for {}", nodeId.getValue());
         final Map<TableKey, ItemSyncBox<Flow>> tableFlowSyncBoxes = new HashMap<>();
         for (final Table tableConfigured : tablesConfigured) {
             final List<Flow> flowsConfigured = tableConfigured.getFlow();