Update MRI projects for Aluminium
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / SyncReactorImpl.java
index 6f64b8d4b1d053d827aff9dc1658fd48ffabb6df..ca965e9669f4fcac53879bfe97be7a675a302843 100644 (file)
@@ -1,20 +1,20 @@
-/**
+/*
  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.applications.frsync.impl;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +39,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -74,11 +76,14 @@ public class SyncReactorImpl implements SyncReactor {
          *  - flows - meters - groups (reordered)
          **/
 
-        final List<ItemSyncBox<Group>> groupsToAddOrUpdate = extractGroupsToAddOrUpdate(nodeId, configTree, operationalTree);
+        final List<ItemSyncBox<Group>> groupsToAddOrUpdate =
+                extractGroupsToAddOrUpdate(nodeId, configTree, operationalTree);
         final ItemSyncBox<Meter> metersToAddOrUpdate = extractMetersToAddOrUpdate(nodeId, configTree, operationalTree);
-        final Map<TableKey, ItemSyncBox<Flow>> flowsToAddOrUpdate = extractFlowsToAddOrUpdate(nodeId, configTree, operationalTree);
+        final Map<TableKey, ItemSyncBox<Flow>> flowsToAddOrUpdate =
+                extractFlowsToAddOrUpdate(nodeId, configTree, operationalTree);
 
-        final Map<TableKey, ItemSyncBox<Flow>> flowsToRemove = extractFlowsToRemove(nodeId, configTree, operationalTree);
+        final Map<TableKey, ItemSyncBox<Flow>> flowsToRemove =
+                extractFlowsToRemove(nodeId, configTree, operationalTree);
         final ItemSyncBox<Meter> metersToRemove = extractMetersToRemove(nodeId, configTree, operationalTree);
         final List<ItemSyncBox<Group>> groupsToRemove = extractGroupsToRemove(nodeId, configTree, operationalTree);
 
@@ -90,35 +95,32 @@ public class SyncReactorImpl implements SyncReactor {
         final ListenableFuture<RpcResult<Void>> resultVehicle = syncPlanPushStrategy.executeSyncStrategy(
                 bootstrapResultFuture, input, counters);
 
-        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("syncup outcome[{}] (added/updated/removed): flow={}/{}/{}, group={}/{}/{}, " +
-                                    "meter={}/{}/{}, errors={}",
-                            nodeId.getValue(),
-                            flowCrudCounts.getAdded(), flowCrudCounts.getUpdated(), flowCrudCounts.getRemoved(),
-                            groupCrudCounts.getAdded(), groupCrudCounts.getUpdated(), groupCrudCounts.getRemoved(),
-                            meterCrudCounts.getAdded(), meterCrudCounts.getUpdated(), meterCrudCounts.getRemoved(),
-                            Arrays.toString(input.getErrors().toArray()));
-                }
-                return input.isSuccessful();
-            }});
+        return Futures.transform(resultVehicle, input1 -> {
+            if (input1 == 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={}/{}/{}, group={}/{}/{}, "
+                                + "meter={}/{}/{}, errors={}",
+                        nodeId.getValue(),
+                        flowCrudCounts.getAdded(), flowCrudCounts.getUpdated(), flowCrudCounts.getRemoved(),
+                        groupCrudCounts.getAdded(), groupCrudCounts.getUpdated(), groupCrudCounts.getRemoved(),
+                        meterCrudCounts.getAdded(), meterCrudCounts.getUpdated(), meterCrudCounts.getRemoved(),
+                        Arrays.toString(input1.getErrors().toArray()));
+            }
+            return input1.isSuccessful();
+        }, MoreExecutors.directExecutor());
     }
 
     @VisibleForTesting
     private static List<ItemSyncBox<Group>> extractGroupsToAddOrUpdate(final NodeId nodeId,
-                                                                       final FlowCapableNode flowCapableNodeConfigured,
-                                                                       final FlowCapableNode flowCapableNodeOperational) {
-        final List<Group> groupsConfigured = ReconcileUtil.safeGroups(flowCapableNodeConfigured);
-        final List<Group> groupsOperational = ReconcileUtil.safeGroups(flowCapableNodeOperational);
-        final Map<Long, Group> groupOperationalMap = FlowCapableNodeLookups.wrapGroupsToMap(groupsOperational);
+            final FlowCapableNode flowCapableNodeConfigured, final FlowCapableNode flowCapableNodeOperational) {
+        final Collection<Group> groupsConfigured = ReconcileUtil.safeGroups(flowCapableNodeConfigured);
+        final Collection<Group> groupsOperational = ReconcileUtil.safeGroups(flowCapableNodeOperational);
+        final Map<Uint32, Group> groupOperationalMap = FlowCapableNodeLookups.wrapGroupsToMap(groupsOperational);
 
         final List<Group> pendingGroups = new ArrayList<>();
         pendingGroups.addAll(groupsConfigured);
@@ -130,8 +132,8 @@ public class SyncReactorImpl implements SyncReactor {
     private static ItemSyncBox<Meter> extractMetersToAddOrUpdate(final NodeId nodeId,
                                                                  final FlowCapableNode flowCapableNodeConfigured,
                                                                  final FlowCapableNode flowCapableNodeOperational) {
-        final List<Meter> metersConfigured = ReconcileUtil.safeMeters(flowCapableNodeConfigured);
-        final List<Meter> metersOperational = ReconcileUtil.safeMeters(flowCapableNodeOperational);
+        final Collection<Meter> metersConfigured = ReconcileUtil.safeMeters(flowCapableNodeConfigured);
+        final Collection<Meter> metersOperational = ReconcileUtil.safeMeters(flowCapableNodeOperational);
         final Map<MeterId, Meter> meterOperationalMap = FlowCapableNodeLookups.wrapMetersToMap(metersOperational);
 
         return ReconcileUtil.resolveMeterDiffs(nodeId, meterOperationalMap, metersConfigured, true);
@@ -139,30 +141,28 @@ public class SyncReactorImpl implements SyncReactor {
 
     @VisibleForTesting
     private static Map<TableKey, ItemSyncBox<Flow>> extractFlowsToAddOrUpdate(final NodeId nodeId,
-                                                                              final FlowCapableNode flowCapableNodeConfigured,
-                                                                              final FlowCapableNode flowCapableNodeOperational) {
-        final List<Table> tablesConfigured = ReconcileUtil.safeTables(flowCapableNodeConfigured);
+            final FlowCapableNode flowCapableNodeConfigured, final FlowCapableNode flowCapableNodeOperational) {
+        final Collection<Table> tablesConfigured = ReconcileUtil.safeTables(flowCapableNodeConfigured);
         if (tablesConfigured.isEmpty()) {
             return Collections.emptyMap();
         }
 
-        final List<Table> tablesOperational = ReconcileUtil.safeTables(flowCapableNodeOperational);
-        final Map<Short, Table> tableOperationalMap = FlowCapableNodeLookups.wrapTablesToMap(tablesOperational);
+        final Collection<Table> tablesOperational = ReconcileUtil.safeTables(flowCapableNodeOperational);
+        final Map<Uint8, Table> tableOperationalMap = FlowCapableNodeLookups.wrapTablesToMap(tablesOperational);
 
         return ReconcileUtil.resolveFlowDiffsInAllTables(nodeId, tableOperationalMap, tablesConfigured, true);
     }
 
     @VisibleForTesting
     private static Map<TableKey, ItemSyncBox<Flow>> extractFlowsToRemove(final NodeId nodeId,
-                                                                         final FlowCapableNode flowCapableNodeConfigured,
-                                                                         final FlowCapableNode flowCapableNodeOperational) {
-        final List<Table> tablesOperational = ReconcileUtil.safeTables(flowCapableNodeOperational);
+            final FlowCapableNode flowCapableNodeConfigured, final FlowCapableNode flowCapableNodeOperational) {
+        final Collection<Table> tablesOperational = ReconcileUtil.safeTables(flowCapableNodeOperational);
         if (tablesOperational.isEmpty()) {
             return Collections.emptyMap();
         }
 
-        final List<Table> tablesConfigured = ReconcileUtil.safeTables(flowCapableNodeConfigured);
-        final Map<Short, Table> tableConfiguredMap = FlowCapableNodeLookups.wrapTablesToMap(tablesConfigured);
+        final Collection<Table> tablesConfigured = ReconcileUtil.safeTables(flowCapableNodeConfigured);
+        final Map<Uint8, Table> tableConfiguredMap = FlowCapableNodeLookups.wrapTablesToMap(tablesConfigured);
 
         return ReconcileUtil.resolveFlowDiffsInAllTables(nodeId, tableConfiguredMap, tablesOperational, false);
     }
@@ -171,8 +171,8 @@ public class SyncReactorImpl implements SyncReactor {
     private static ItemSyncBox<Meter> extractMetersToRemove(final NodeId nodeId,
                                                             final FlowCapableNode flowCapableNodeConfigured,
                                                             final FlowCapableNode flowCapableNodeOperational) {
-        final List<Meter> metersConfigured = ReconcileUtil.safeMeters(flowCapableNodeConfigured);
-        final List<Meter> metersOperational = ReconcileUtil.safeMeters(flowCapableNodeOperational);
+        final Collection<Meter> metersConfigured = ReconcileUtil.safeMeters(flowCapableNodeConfigured);
+        final Collection<Meter> metersOperational = ReconcileUtil.safeMeters(flowCapableNodeOperational);
         final Map<MeterId, Meter> meterConfiguredMap = FlowCapableNodeLookups.wrapMetersToMap(metersConfigured);
 
         return ReconcileUtil.resolveMeterDiffs(nodeId, meterConfiguredMap, metersOperational, false);
@@ -182,9 +182,9 @@ public class SyncReactorImpl implements SyncReactor {
     private static List<ItemSyncBox<Group>> extractGroupsToRemove(final NodeId nodeId,
                                                                   final FlowCapableNode flowCapableNodeConfigured,
                                                                   final FlowCapableNode flowCapableNodeOperational) {
-        final List<Group> groupsConfigured = ReconcileUtil.safeGroups(flowCapableNodeConfigured);
-        final List<Group> groupsOperational = ReconcileUtil.safeGroups(flowCapableNodeOperational);
-        final Map<Long, Group> groupConfiguredMap = FlowCapableNodeLookups.wrapGroupsToMap(groupsConfigured);
+        final Collection<Group> groupsConfigured = ReconcileUtil.safeGroups(flowCapableNodeConfigured);
+        final Collection<Group> groupsOperational = ReconcileUtil.safeGroups(flowCapableNodeOperational);
+        final Map<Uint32, Group> groupConfiguredMap = FlowCapableNodeLookups.wrapGroupsToMap(groupsConfigured);
 
         final List<Group> pendingGroups = new ArrayList<>();
         pendingGroups.addAll(groupsOperational);