Bug 6745 Improve compression queue locking and handle InterruptedException
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / SyncReactorImpl.java
index 504d583d032f8a02dc029067e20e4cc593265a9f..272e97dcceceea7849f8c6902183931dd75da734 100644 (file)
@@ -14,21 +14,20 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.applications.frsync.SyncPlanPushStrategy;
 import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
 import org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SynchronizationDiffInput;
 import org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts;
 import org.opendaylight.openflowplugin.applications.frsync.util.FlowCapableNodeLookups;
-import org.opendaylight.openflowplugin.applications.frsync.util.FxChainUtil;
 import org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox;
 import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;
 import org.opendaylight.openflowplugin.applications.frsync.util.ReconcileUtil;
 import org.opendaylight.openflowplugin.applications.frsync.util.SyncCrudCounters;
+import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
@@ -51,17 +50,16 @@ public class SyncReactorImpl implements SyncReactor {
     private static final Logger LOG = LoggerFactory.getLogger(SyncReactorImpl.class);
     private final SyncPlanPushStrategy syncPlanPushStrategy;
 
-    public SyncReactorImpl(SyncPlanPushStrategy syncPlanPushStrategy) {
+    public SyncReactorImpl(final SyncPlanPushStrategy syncPlanPushStrategy) {
         this.syncPlanPushStrategy = Preconditions.checkNotNull(syncPlanPushStrategy, "execution strategy is mandatory");
     }
 
     @Override
     public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> nodeIdent,
-                                            final FlowCapableNode configTree, final FlowCapableNode operationalTree,
-                                            final LogicalDatastoreType dsType) {
-
+                                            final SyncupEntry syncupEntry) {
         final NodeId nodeId = PathUtil.digNodeId(nodeIdent);
-        LOG.trace("syncup impl {} cfg:{} oper:{}", nodeId.getValue(), configTree == null ? "is null" : "non null", operationalTree == null ? "is null" : "non null");
+        FlowCapableNode configTree = syncupEntry.getAfter();
+        FlowCapableNode operationalTree = syncupEntry.getBefore();
         final SyncCrudCounters counters = new SyncCrudCounters();
 
         /**
@@ -72,7 +70,6 @@ public class SyncReactorImpl implements SyncReactor {
          *  - recommended order follows:
          * reconciliation strategy - phase 1: - add/update missing objects in following order:
          *  - table features - groups (reordered) - meters - flows
-         *
          * reconciliation strategy - phase 2: - remove redundant objects in following order:
          *  - flows - meters - groups (reordered)
          **/
@@ -89,44 +86,30 @@ public class SyncReactorImpl implements SyncReactor {
                 groupsToAddOrUpdate, metersToAddOrUpdate, flowsToAddOrUpdate,
                 flowsToRemove, metersToRemove, groupsToRemove);
 
-        counters.setStartNano(System.nanoTime());
         final ListenableFuture<RpcResult<Void>> bootstrapResultFuture = RpcResultBuilder.<Void>success().buildFuture();
         final ListenableFuture<RpcResult<Void>> resultVehicle = syncPlanPushStrategy.executeSyncStrategy(
                 bootstrapResultFuture, input, counters);
 
-        // log final result
-        Futures.addCallback(resultVehicle, FxChainUtil.logResultCallback(nodeId, "final result"));
-
         return Futures.transform(resultVehicle, new Function<RpcResult<Void>, Boolean>() {
             @Override
             public Boolean apply(RpcResult<Void> input) {
                 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("sync-outcome[{}] (added/updated/removed): flow={}/{}/{}, meter={}/{}/{}, group={}/{}/{}, took={} ms",
+                    LOG.debug("Syncup outcome[{}] (added/updated/removed): flow={}/{}/{}, group={}/{}/{}, " +
+                                    "meter={}/{}/{}, errors={}",
                             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(),
+                            Arrays.toString(input.getErrors().toArray()));
                 }
-
-                LOG.trace("syncup errors: {}", input.getErrors());
                 return input.isSuccessful();
-            }
-        });
+            }});
     }
 
     @VisibleForTesting
@@ -208,5 +191,4 @@ public class SyncReactorImpl implements SyncReactor {
 
         return ReconcileUtil.resolveAndDivideGroupDiffs(nodeId, groupConfiguredMap, pendingGroups, false);
     }
-
 }