Sonar - technical debt of FRS app 41/43741/4
authorAndrej Leitner <andrej.leitner@pantheon.tech>
Mon, 8 Aug 2016 09:39:02 +0000 (11:39 +0200)
committerAndrej Leitner <andrej.leitner@pantheon.tech>
Mon, 15 Aug 2016 11:59:55 +0000 (13:59 +0200)
Change-Id: I2951c3e85f3599aec951844289de22e25b652a36
Signed-off-by: Andrej Leitner <andrej.leitner@pantheon.tech>
14 files changed:
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SimplifiedConfigListener.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SimplifiedOperationalListener.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorGuardDecorator.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorImpl.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/clustering/DeviceMastershipManager.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/strategy/FlowForwarder.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/strategy/SyncPlanPushStrategyFlatBatchImpl.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/FxChainUtil.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/ModificationUtil.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/PathUtil.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/ReconcileUtil.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/SwitchFlowId.java
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/util/SyncupEntry.java
applications/forwardingrules-sync/src/test/java/org/opendaylight/openflowplugin/applications/frsync/impl/ForwardingRulesSyncProviderTest.java

index f4188e2926aa8767ef6111b6849d1a5cf491011a..6f86def8a6a9ef71f5a7c00edac2e730759ae36d 100644 (file)
@@ -26,7 +26,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Listens to config changes and delegates add/remove/update/barrier to {@link SyncReactor}.
+ * Listens to config changes and delegates sync entry to {@link SyncReactor}.
  */
 public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapableNode> {
     private static final Logger LOG = LoggerFactory.getLogger(SimplifiedConfigListener.class);
@@ -49,8 +49,8 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     /**
-     * Compare cached operational with current config modification. If operational is not present
-     * skip calling Inventory RPCs.
+     * Update cache. If operational data are present, choose appropriate data and start syncup.
+     * Otherwise skip incoming change.
      * @throws InterruptedException from syncup
      */
     protected Optional<ListenableFuture<Boolean>> processNodeModification(
@@ -82,14 +82,9 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     /**
-     * Add only what is missing in operational store. Config. node could be added in two situations:
-     * <ul>
-     * <li>Note very first time after restart was handled by operational listener. Syncup should
-     * calculate no delta (we don want to reconfigure switch if not necessary).</li>
-     * <li>But later the config. node could be deleted, after that config node added again. Syncup
-     * should calculate that everything needs to be added. Operational store should be empty in
-     * optimal case (but the switch could be reprogrammed by another person/system.</li>
-     * </ul>
+     * Add only what is missing on device. If node was added to config DS and it is already present
+     * in operational DS (connected) diff between current new configuration and actual configuration
+     * (seen in operational) should be calculated and sent to device.
      */
     private ListenableFuture<Boolean> onNodeAdded(final InstanceIdentifier<FlowCapableNode> nodePath,
                                                   final FlowCapableNode dataAfter,
@@ -102,7 +97,7 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
 
     /**
      * Apply minimal changes very fast. For better performance needed just compare config
-     * after+before. Config listener should not be dependent on operational flows/groups while
+     * after+before. Config listener should not be dependent on operational flows/groups/meters while
      * updating config because operational store is highly async and it depends on another module in
      * system which is updating operational store (that components is also trying to solve
      * scale/performance issues on several layers).
@@ -117,9 +112,8 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     /**
-     * Remove values that are being deleted in the config from the switch. Note, this could be
-     * probably optimized using dedicated wipe-out RPC, but it has impact on switch if it is
-     * programmed by two person/system
+     * Remove values that are being deleted in the config from the switch.
+     * Note, this could be probably optimized using dedicated wipe-out RPC.
      */
     private ListenableFuture<Boolean> onNodeDeleted(final InstanceIdentifier<FlowCapableNode> nodePath,
                                                     final FlowCapableNode dataBefore) throws InterruptedException {
index eb70f5d4931a61acb897a1799ebabefd6b8063c1..2f0fc01257e9acd04881443bc554e4ffd9b9e218 100644 (file)
@@ -40,7 +40,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Listens to operational new nodes and delegates add/remove/update/barrier to {@link SyncReactor}.
+ * Listens to operational changes and starts reconciliation through {@link SyncReactor} when necessary.
  */
 public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node> {
     private static final Logger LOG = LoggerFactory.getLogger(SimplifiedOperationalListener.class);
@@ -71,13 +71,8 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
     }
 
     /**
-     * This method behaves like this:
-     * <ul>
-     * <li>If node is added to operational store then reconciliation.</li>
-     * <li>Node is deleted from operational cache is removed.</li>
-     * <li>Skip this event otherwise.</li>
-     * </ul>
-     *
+     * Update cache, register for device masterhip when device connected and start reconciliation if device
+     * is registered and actual modification is consistent.Skip the event otherwise.
      * @throws InterruptedException from syncup
      */
     protected Optional<ListenableFuture<Boolean>> processNodeModification(
@@ -89,7 +84,7 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
             deviceMastershipManager.onDeviceConnected(nodeId);
         }
 
-        if (isRegisteredAndConsistentForReconcile(modification)) {
+        if (reconciliationRegistry.isRegistered(nodeId) && isConsistentForReconcile(modification)) {
             return reconciliation(modification);
         } else {
             return skipModification(modification);
@@ -98,7 +93,7 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
 
     /**
      * Remove if delete. Update only if FlowCapableNode Augmentation modified.
-     *
+     * Unregister for device mastership.
      * @param modification Datastore modification
      */
     private void updateCache(DataTreeModification<Node> modification) {
@@ -169,6 +164,13 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
         return false;
     }
 
+    /**
+     * If node is present in config DS diff between wanted configuration (in config DS) and actual device
+     * configuration (coming from operational) should be calculated and sent to device.
+     * @param modification from DS
+     * @return optional syncup future
+     * @throws InterruptedException from syncup
+     */
     private Optional<ListenableFuture<Boolean>> reconciliation(DataTreeModification<Node> modification) throws InterruptedException {
         final NodeId nodeId = ModificationUtil.nodeId(modification);
         final Optional<FlowCapableNode> nodeConfiguration = configDao.loadByNodeId(nodeId);
@@ -188,13 +190,8 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
         }
     }
 
-    private boolean isRegisteredAndConsistentForReconcile(DataTreeModification<Node> modification) {
+    private boolean isConsistentForReconcile(DataTreeModification<Node> modification) {
         final NodeId nodeId = PathUtil.digNodeId(modification.getRootPath().getRootIdentifier());
-
-        if (!reconciliationRegistry.isRegistered(nodeId)) {
-            return false;
-        }
-
         final FlowCapableStatisticsGatheringStatus gatheringStatus = modification.getRootNode().getDataAfter()
                 .getAugmentation(FlowCapableStatisticsGatheringStatus.class);
 
@@ -234,9 +231,7 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
         if (node == null) {
             return true;
         }
-
         final List<NodeConnector> nodeConnectors = node.getNodeConnector();
-
         return nodeConnectors == null || nodeConnectors.isEmpty();
     }
 
@@ -244,5 +239,5 @@ public class SimplifiedOperationalListener extends AbstractFrmSyncListener<Node>
     public LogicalDatastoreType dsType() {
         return LogicalDatastoreType.OPERATIONAL;
     }
-    
+
 }
index c51f0bb6e0a6df346efe2024a49cb776cfeba5f2..3f1b2716a3f743ccadfa1cad969f5c295d906205 100644 (file)
@@ -63,35 +63,7 @@ public class SyncReactorGuardDecorator implements SyncReactor {
             final ListenableFuture<Boolean> endResult =
                     delegate.syncup(flowcapableNodePath, syncupEntry);
 
-            Futures.addCallback(endResult, new FutureCallback<Boolean>() {
-                @Override
-                public void onSuccess(@Nullable final Boolean result) {
-                    if (LOG.isDebugEnabled()) {
-                        final long stampFinished = System.nanoTime();
-                        LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
-                                formatNanos(stampFinished - stampBeforeGuard),
-                                formatNanos(stampFinished - stampAfterGuard),
-                                formatNanos(stampAfterGuard - stampBeforeGuard),
-                                guard.availablePermits(), threadName());
-                    }
-
-                    releaseGuardForNodeId(guard);
-                }
-
-                @Override
-                public void onFailure(final Throwable t) {
-                    if (LOG.isDebugEnabled()) {
-                        final long stampFinished = System.nanoTime();
-                        LOG.warn("syncup failed {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
-                                formatNanos(stampFinished - stampBeforeGuard),
-                                formatNanos(stampFinished - stampAfterGuard),
-                                formatNanos(stampAfterGuard - stampBeforeGuard),
-                                guard.availablePermits(), threadName());
-                    }
-
-                    releaseGuardForNodeId(guard);
-                }
-            });
+            Futures.addCallback(endResult, createSyncupCallback(guard, stampBeforeGuard, stampAfterGuard, nodeId));
             return endResult;
         } catch (InterruptedException e) {
             releaseGuardForNodeId(guard);
@@ -99,7 +71,32 @@ public class SyncReactorGuardDecorator implements SyncReactor {
         }
     }
 
-    private String formatNanos(long nanos) {
+    private static FutureCallback<Boolean> createSyncupCallback(final Semaphore guard,
+                                                                final long stampBeforeGuard,
+                                                                final long stampAfterGuard,
+                                                                final NodeId nodeId) {
+        return new FutureCallback<Boolean>() {
+            @Override
+            public void onSuccess(@Nullable final Boolean result) {
+                if (LOG.isDebugEnabled()) {
+                    final long stampFinished = System.nanoTime();
+                    LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
+                            formatNanos(stampFinished - stampBeforeGuard), formatNanos(stampFinished - stampAfterGuard),
+                            formatNanos(stampAfterGuard - stampBeforeGuard), guard.availablePermits(), threadName());
+                }
+                releaseGuardForNodeId(guard);
+            }
+            @Override
+            public void onFailure(final Throwable t) {
+                final long stampFinished = System.nanoTime();
+                LOG.error("syncup failed {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
+                        formatNanos(stampFinished - stampBeforeGuard), formatNanos(stampFinished - stampAfterGuard),
+                        formatNanos(stampAfterGuard - stampBeforeGuard), guard.availablePermits(), threadName());
+                releaseGuardForNodeId(guard);
+            }};
+    }
+
+    private static String formatNanos(long nanos) {
         return "'" + TimeUnit.NANOSECONDS.toMillis(nanos) + " ms'";
     }
 
@@ -126,7 +123,7 @@ public class SyncReactorGuardDecorator implements SyncReactor {
      * Unlock and release guard.
      * @param guard semaphore guard which should be unlocked
      */
-    private void releaseGuardForNodeId(final Semaphore guard) {
+    private static void releaseGuardForNodeId(final Semaphore guard) {
         if (guard != null) {
             guard.release();
             LOG.trace("syncup release guard:{} thread:{}", guard, threadName());
index 5eb8860f884ebb35dcb609f414f5e77898bb4d85..7f1be0b3fde15bdd1aa2ad52c279c7437e9b9efa 100644 (file)
@@ -107,30 +107,20 @@ public class SyncReactorImpl implements SyncReactor {
                 if (input == null) {
                     return false;
                 }
-
                 if (LOG.isDebugEnabled()) {
                     final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();
                     final CrudCounts meterCrudCounts = counters.getMeterCrudCounts();
                     final CrudCounts groupCrudCounts = counters.getGroupCrudCounts();
-                    LOG.debug("syncup outcome[{}] (added/updated/removed): flow={}/{}/{}, meter={}/{}/{}, group={}/{}/{}, took={} ms",
+                    LOG.debug("syncup outcome[{}] (added/updated/removed): flow={}/{}/{}, group={}/{}/{}, meter={}/{}/{}, took={} ms",
                             nodeId.getValue(),
-                            flowCrudCounts.getAdded(),
-                            flowCrudCounts.getUpdated(),
-                            flowCrudCounts.getRemoved(),
-                            meterCrudCounts.getAdded(),
-                            meterCrudCounts.getUpdated(),
-                            meterCrudCounts.getRemoved(),
-                            groupCrudCounts.getAdded(),
-                            groupCrudCounts.getUpdated(),
-                            groupCrudCounts.getRemoved(),
-                            TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - counters.getStartNano())
-                    );
+                            flowCrudCounts.getAdded(), flowCrudCounts.getUpdated(), flowCrudCounts.getRemoved(),
+                            groupCrudCounts.getAdded(), groupCrudCounts.getUpdated(), groupCrudCounts.getRemoved(),
+                            meterCrudCounts.getAdded(), meterCrudCounts.getUpdated(), meterCrudCounts.getRemoved(),
+                            TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - counters.getStartNano()));
                 }
-
                 LOG.trace("syncup errors: {}", input.getErrors());
                 return input.isSuccessful();
-            }
-        });
+            }});
     }
 
     @VisibleForTesting
index 41f736c05d8d2c199bd6192acfce006f406d7d64..06532ad3c2f821268a972c5a5d63b650dd8d41c8 100644 (file)
@@ -48,7 +48,7 @@ public class DeviceMastershipManager {
             try {
                 registration.close();
             } catch (Exception e) {
-                LOG.error("FRS cluster service close fail: {}", nodeId.getValue());
+                LOG.error("FRS cluster service close fail: {} {}", nodeId.getValue(), e);
             }
         }
         LOG.debug("FRS service unregistered for: {}", nodeId.getValue());
index ca752470fe978e4787ed0897d4a131b6ab853b88..2609d576f7c62b2ff0e72cdded3b5617307cbf9c 100644 (file)
@@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory;
 public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutput, RemoveFlowOutput, UpdateFlowOutput> {
 
     private static final Logger LOG = LoggerFactory.getLogger(FlowForwarder.class);
+    private static final String TABLE_ID_MISMATCH = "tableId mismatch";
     private final SalFlowService salFlowService;
 
     public FlowForwarder(final SalFlowService salFlowService) {
@@ -67,7 +68,7 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
             return salFlowService.removeFlow(builder.build());
         } else {
             return RpcResultBuilder.<RemoveFlowOutput>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, "tableId mismatch").buildFuture();
+                    .withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
         }
     }
 
@@ -94,7 +95,7 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
             output = salFlowService.updateFlow(builder.build());
         } else {
             output = RpcResultBuilder.<UpdateFlowOutput>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, "tableId mismatch").buildFuture();
+                    .withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
         }
 
         return output;
@@ -117,7 +118,7 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
             builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey)));
             output = salFlowService.addFlow(builder.build());
         } else {
-            output = RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, "tableId mismatch").buildFuture();
+            output = RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
         }
         return output;
     }
index 70ce219708a1480efdca8f214dd9e51898e689f9..68e0803723c532b7e7a9a6de1f9fe51cc3225165 100644 (file)
@@ -174,17 +174,7 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
             public void onSuccess(@Nullable final RpcResult<ProcessFlatBatchOutput> result) {
                 if (!result.isSuccessful() && result.getResult() != null && !result.getResult().getBatchFailure().isEmpty()) {
                     Map<Range<Integer>, Batch> batchMap = mapBatchesToRanges(inputBatchBag, failureIndexLimit);
-
-                    for (BatchFailure batchFailure : result.getResult().getBatchFailure()) {
-                        for (Map.Entry<Range<Integer>, Batch> rangeBatchEntry : batchMap.entrySet()) {
-                            if (rangeBatchEntry.getKey().contains(batchFailure.getBatchOrder())) {
-                                // get type and decrease
-                                final BatchChoice batchChoice = rangeBatchEntry.getValue().getBatchChoice();
-                                decrementCounters(batchChoice, counters);
-                                break;
-                            }
-                        }
-                    }
+                    decrementBatchFailuresCounters(result.getResult().getBatchFailure(), batchMap, counters);
                 }
             }
 
@@ -195,6 +185,21 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
         };
     }
 
+    private static void decrementBatchFailuresCounters(final List<BatchFailure> batchFailures,
+                                                final Map<Range<Integer>, Batch> batchMap,
+                                                final SyncCrudCounters counters) {
+        for (BatchFailure batchFailure : batchFailures) {
+            for (Map.Entry<Range<Integer>, Batch> rangeBatchEntry : batchMap.entrySet()) {
+                if (rangeBatchEntry.getKey().contains(batchFailure.getBatchOrder())) {
+                    // get type and decrease
+                    final BatchChoice batchChoice = rangeBatchEntry.getValue().getBatchChoice();
+                    decrementCounters(batchChoice, counters);
+                    break;
+                }
+            }
+        }
+    }
+
     static void decrementCounters(final BatchChoice batchChoice, final SyncCrudCounters counters) {
         if (batchChoice instanceof FlatBatchAddFlowCase) {
             counters.getFlowCrudCounts().decAdded();
@@ -233,6 +238,7 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
     @VisibleForTesting
     static int assembleRemoveFlows(final List<Batch> batchBag, int batchOrder, final Map<TableKey, ItemSyncBox<Flow>> flowItemSyncTableMap) {
         // process flow remove
+        int order = batchOrder;
         if (flowItemSyncTableMap != null) {
             for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
                 final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
@@ -251,19 +257,20 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchRemoveFlowCaseBuilder()
                                     .setFlatBatchRemoveFlow(flatBatchRemoveFlowBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
             }
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleAddOrUpdateGroups(final List<Batch> batchBag, int batchOrder, final List<ItemSyncBox<Group>> groupsToAddOrUpdate) {
         // process group add+update
+        int order = batchOrder;
         if (groupsToAddOrUpdate != null) {
             for (ItemSyncBox<Group> groupItemSyncBox : groupsToAddOrUpdate) {
                 if (!groupItemSyncBox.getItemsToPush().isEmpty()) {
@@ -277,9 +284,9 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchAddGroupCaseBuilder()
                                     .setFlatBatchAddGroup(flatBatchAddGroupBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
 
@@ -298,19 +305,20 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchUpdateGroupCaseBuilder()
                                     .setFlatBatchUpdateGroup(flatBatchUpdateGroupBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
             }
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleRemoveGroups(final List<Batch> batchBag, int batchOrder, final List<ItemSyncBox<Group>> groupsToRemoveOrUpdate) {
         // process group add+update
+        int order = batchOrder;
         if (groupsToRemoveOrUpdate != null) {
             for (ItemSyncBox<Group> groupItemSyncBox : groupsToRemoveOrUpdate) {
                 if (!groupItemSyncBox.getItemsToPush().isEmpty()) {
@@ -324,19 +332,20 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchRemoveGroupCaseBuilder()
                                     .setFlatBatchRemoveGroup(flatBatchRemoveGroupBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
             }
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleAddOrUpdateMeters(final List<Batch> batchBag, int batchOrder, final ItemSyncBox<Meter> meterItemSyncBox) {
         // process meter add+update
+        int order = batchOrder;
         if (meterItemSyncBox != null) {
             if (!meterItemSyncBox.getItemsToPush().isEmpty()) {
                 final List<FlatBatchAddMeter> flatBatchAddMeterBag =
@@ -349,9 +358,9 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                         .setBatchChoice(new FlatBatchAddMeterCaseBuilder()
                                 .setFlatBatchAddMeter(flatBatchAddMeterBag)
                                 .build())
-                        .setBatchOrder(batchOrder)
+                        .setBatchOrder(order)
                         .build();
-                batchOrder += itemOrder;
+                order += itemOrder;
                 batchBag.add(batch);
             }
 
@@ -370,18 +379,19 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                         .setBatchChoice(new FlatBatchUpdateMeterCaseBuilder()
                                 .setFlatBatchUpdateMeter(flatBatchUpdateMeterBag)
                                 .build())
-                        .setBatchOrder(batchOrder)
+                        .setBatchOrder(order)
                         .build();
-                batchOrder += itemOrder;
+                order += itemOrder;
                 batchBag.add(batch);
             }
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleRemoveMeters(final List<Batch> batchBag, int batchOrder, final ItemSyncBox<Meter> meterItemSyncBox) {
         // process meter remove
+        int order = batchOrder;
         if (meterItemSyncBox != null && !meterItemSyncBox.getItemsToPush().isEmpty()) {
             final List<FlatBatchRemoveMeter> flatBatchRemoveMeterBag =
                     new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
@@ -393,17 +403,18 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                     .setBatchChoice(new FlatBatchRemoveMeterCaseBuilder()
                             .setFlatBatchRemoveMeter(flatBatchRemoveMeterBag)
                             .build())
-                    .setBatchOrder(batchOrder)
+                    .setBatchOrder(order)
                     .build();
-            batchOrder += itemOrder;
+            order += itemOrder;
             batchBag.add(batch);
         }
-        return batchOrder;
+        return order;
     }
 
     @VisibleForTesting
     static int assembleAddOrUpdateFlows(final List<Batch> batchBag, int batchOrder, final Map<TableKey, ItemSyncBox<Flow>> flowItemSyncTableMap) {
         // process flow add+update
+        int order = batchOrder;
         if (flowItemSyncTableMap != null) {
             for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
                 final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
@@ -422,9 +433,9 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchAddFlowCaseBuilder()
                                     .setFlatBatchAddFlow(flatBatchAddFlowBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
 
@@ -444,14 +455,14 @@ public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
                             .setBatchChoice(new FlatBatchUpdateFlowCaseBuilder()
                                     .setFlatBatchUpdateFlow(flatBatchUpdateFlowBag)
                                     .build())
-                            .setBatchOrder(batchOrder)
+                            .setBatchOrder(order)
                             .build();
-                    batchOrder += itemOrder;
+                    order += itemOrder;
                     batchBag.add(batch);
                 }
             }
         }
-        return batchOrder;
+        return order;
     }
 
     public SyncPlanPushStrategyFlatBatchImpl setFlatBatchService(final SalFlatBatchService flatBatchService) {
index 903dd207f018b2de94fcf6e503d7927d7b464648..5e02d48a39d8aedbfe626282b07aea6dfc6f4d17 100644 (file)
@@ -27,6 +27,10 @@ public class FxChainUtil {
 
     private static final Logger LOG = LoggerFactory.getLogger(FxChainUtil.class);
 
+    private FxChainUtil() {
+        throw new IllegalStateException("This class should not be instantiated.");
+    }
+
 
     public static FutureCallback<RpcResult<Void>> logResultCallback(final NodeId nodeId, final String prefix) {
         return new FutureCallback<RpcResult<Void>>() {
index 1df1f7c6a43628a218d58ab5a623ea71641820d4..0eb7252725f233603d47c387285f51576f782406 100644 (file)
@@ -18,6 +18,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N
  * Basic {@link DataTreeModification} related tools.
  */
 public class ModificationUtil {
+
+    private ModificationUtil() {
+        throw new IllegalStateException("This class should not be instantiated.");
+    }
+
     public static String nodeIdValue(DataTreeModification<Node> modification) {
         final NodeId nodeId = nodeId(modification);
 
index f4a91c237b8c2961d4d0acc4e724fe158c254e76..9f84a63851c3090819acc938be983f335cf8a698 100644 (file)
@@ -18,6 +18,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  * Basic {@link InstanceIdentifier} related tools.
  */
 public class PathUtil {
+
+    private PathUtil() {
+        throw new IllegalStateException("This class should not be instantiated.");
+    }
     public static NodeId digNodeId(final InstanceIdentifier<?> nodeIdent) {
         return nodeIdent.firstKeyOf(Node.class, NodeKey.class).getId();
     }
index 79fd17a69774be0ca6c2587ab4009fcfd2fa83b7..a910c01957e0dc8ec57d817d3f9a7a7da105dbcb 100644 (file)
@@ -23,7 +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.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;
@@ -50,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();
         };
     }
 
@@ -94,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();
         };
     }
 
@@ -157,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<>();
 
index 5a9fbbaa2d5de8048c3c7dd3110205f08b31e3bf..8ccc9b203f42be188700e95ce964115c51828666 100644 (file)
@@ -29,6 +29,26 @@ public class SwitchFlowId {
         this.match = flow.getMatch();
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        SwitchFlowId that = (SwitchFlowId) o;
+
+        if (tableId != null ? !tableId.equals(that.tableId) : that.tableId != null) {
+            return false;
+        }
+        if (priority != null ? !priority.equals(that.priority) : that.priority != null) {
+            return false;
+        }
+        return match != null ? match.equals(that.match) : that.match == null;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -39,30 +59,4 @@ public class SwitchFlowId {
         return result;
     }
 
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        SwitchFlowId other = (SwitchFlowId) obj;
-        if (match == null) {
-            if (other.match != null)
-                return false;
-        } else if (!match.equals(other.match))
-            return false;
-        if (priority == null) {
-            if (other.priority != null)
-                return false;
-        } else if (!priority.equals(other.priority))
-            return false;
-        if (tableId == null) {
-            if (other.tableId != null)
-                return false;
-        } else if (!tableId.equals(other.tableId))
-            return false;
-        return true;
-    }
 }
index 151724c563181515c8159ff037c02231562d621f..290730e4cc42928c593b4e98890158369ccaf3af 100644 (file)
@@ -71,4 +71,14 @@ public class SyncupEntry {
         return dsTypeBefore == that.dsTypeBefore;
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = after != null ? after.hashCode() : 0;
+        result = prime * result + (dsTypeAfter != null ? dsTypeAfter.hashCode() : 0);
+        result = prime * result + (before != null ? before.hashCode() : 0);
+        result = prime * result + (dsTypeBefore != null ? dsTypeBefore.hashCode() : 0);
+        return result;
+    }
+
 }
index b795b2f728b73f8059ec48a185f2a90e14c6397a..a9a649462ae0654486717e4451eee885fc9e18e2 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.openflowplugin.applications.frsync.impl;
 
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -71,4 +72,10 @@ public class ForwardingRulesSyncProviderTest {
                 Matchers.<DataTreeIdentifier<FlowCapableNode>>any(),
                 Matchers.<DataTreeChangeListener<FlowCapableNode>>any());
     }
+
+    @After
+    public void tearDown() throws InterruptedException {
+        provider.close();
+    }
+
 }
\ No newline at end of file