X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=applications%2Fforwardingrules-sync%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fapplications%2Ffrsync%2Fimpl%2FSyncReactorImpl.java;h=ca965e9669f4fcac53879bfe97be7a675a302843;hb=05f8db12159673d0e0a95642fe86e62c14b7dc7b;hp=0528470789958bd1b5c035bc00e60dcaf6161d10;hpb=7f63d9b25efe493bbafc8b6d5ec4a8ad0327fa79;p=openflowplugin.git diff --git a/applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorImpl.java b/applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorImpl.java index 0528470789..ca965e9669 100644 --- a/applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorImpl.java +++ b/applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/SyncReactorImpl.java @@ -1,34 +1,33 @@ -/** +/* * 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; -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; @@ -40,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; @@ -51,17 +52,18 @@ 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 syncup(final InstanceIdentifier nodeIdent, - final FlowCapableNode configTree, final FlowCapableNode operationalTree, - final LogicalDatastoreType dsType) { - - LOG.trace("syncup {} cfg:{} oper:{}", nodeIdent, configTree == null ? "is null" : "non null", operationalTree == null ? "is null" : "non null"); + final SyncupEntry syncupEntry) { + final NodeId nodeId = PathUtil.digNodeId(nodeIdent); + FlowCapableNode configTree = syncupEntry.getAfter(); + FlowCapableNode operationalTree = syncupEntry.getBefore(); final SyncCrudCounters counters = new SyncCrudCounters(); + /** * instructions: * - extract diff changes and prepare change steps in safe order @@ -70,18 +72,18 @@ 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) **/ - final NodeId nodeId = PathUtil.digNodeId(nodeIdent); - - final List> groupsToAddOrUpdate = extractGroupsToAddOrUpdate(nodeId, configTree, operationalTree); + final List> groupsToAddOrUpdate = + extractGroupsToAddOrUpdate(nodeId, configTree, operationalTree); final ItemSyncBox metersToAddOrUpdate = extractMetersToAddOrUpdate(nodeId, configTree, operationalTree); - final Map> flowsToAddOrUpdate = extractFlowsToAddOrUpdate(nodeId, configTree, operationalTree); + final Map> flowsToAddOrUpdate = + extractFlowsToAddOrUpdate(nodeId, configTree, operationalTree); - final Map> flowsToRemove = extractFlowsToRemove(nodeId, configTree, operationalTree); + final Map> flowsToRemove = + extractFlowsToRemove(nodeId, configTree, operationalTree); final ItemSyncBox metersToRemove = extractMetersToRemove(nodeId, configTree, operationalTree); final List> groupsToRemove = extractGroupsToRemove(nodeId, configTree, operationalTree); @@ -89,53 +91,36 @@ public class SyncReactorImpl implements SyncReactor { groupsToAddOrUpdate, metersToAddOrUpdate, flowsToAddOrUpdate, flowsToRemove, metersToRemove, groupsToRemove); - counters.setStartNano(System.nanoTime()); final ListenableFuture> bootstrapResultFuture = RpcResultBuilder.success().buildFuture(); final ListenableFuture> resultVehicle = syncPlanPushStrategy.executeSyncStrategy( bootstrapResultFuture, input, counters); - // log final result - Futures.addCallback(resultVehicle, FxChainUtil.logResultCallback(nodeId, "final result")); - - return Futures.transform(resultVehicle, new Function, Boolean>() { - @Override - public Boolean apply(RpcResult 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", - 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()) - ); - } - - LOG.trace("syncup errors: {}", input.getErrors()); - 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 - static List> extractGroupsToAddOrUpdate(final NodeId nodeId, - final FlowCapableNode flowCapableNodeConfigured, - final FlowCapableNode flowCapableNodeOperational) { - final List groupsConfigured = ReconcileUtil.safeGroups(flowCapableNodeConfigured); - final List groupsOperational = ReconcileUtil.safeGroups(flowCapableNodeOperational); - final Map groupOperationalMap = FlowCapableNodeLookups.wrapGroupsToMap(groupsOperational); + private static List> extractGroupsToAddOrUpdate(final NodeId nodeId, + final FlowCapableNode flowCapableNodeConfigured, final FlowCapableNode flowCapableNodeOperational) { + final Collection groupsConfigured = ReconcileUtil.safeGroups(flowCapableNodeConfigured); + final Collection groupsOperational = ReconcileUtil.safeGroups(flowCapableNodeOperational); + final Map groupOperationalMap = FlowCapableNodeLookups.wrapGroupsToMap(groupsOperational); final List pendingGroups = new ArrayList<>(); pendingGroups.addAll(groupsConfigured); @@ -144,69 +129,66 @@ public class SyncReactorImpl implements SyncReactor { } @VisibleForTesting - static ItemSyncBox extractMetersToAddOrUpdate(final NodeId nodeId, - final FlowCapableNode flowCapableNodeConfigured, - final FlowCapableNode flowCapableNodeOperational) { - final List metersConfigured = ReconcileUtil.safeMeters(flowCapableNodeConfigured); - final List metersOperational = ReconcileUtil.safeMeters(flowCapableNodeOperational); + private static ItemSyncBox extractMetersToAddOrUpdate(final NodeId nodeId, + final FlowCapableNode flowCapableNodeConfigured, + final FlowCapableNode flowCapableNodeOperational) { + final Collection metersConfigured = ReconcileUtil.safeMeters(flowCapableNodeConfigured); + final Collection metersOperational = ReconcileUtil.safeMeters(flowCapableNodeOperational); final Map meterOperationalMap = FlowCapableNodeLookups.wrapMetersToMap(metersOperational); return ReconcileUtil.resolveMeterDiffs(nodeId, meterOperationalMap, metersConfigured, true); } @VisibleForTesting - static Map> extractFlowsToAddOrUpdate(final NodeId nodeId, - final FlowCapableNode flowCapableNodeConfigured, - final FlowCapableNode flowCapableNodeOperational) { - final List tablesConfigured = ReconcileUtil.safeTables(flowCapableNodeConfigured); + private static Map> extractFlowsToAddOrUpdate(final NodeId nodeId, + final FlowCapableNode flowCapableNodeConfigured, final FlowCapableNode flowCapableNodeOperational) { + final Collection
tablesConfigured = ReconcileUtil.safeTables(flowCapableNodeConfigured); if (tablesConfigured.isEmpty()) { return Collections.emptyMap(); } - final List
tablesOperational = ReconcileUtil.safeTables(flowCapableNodeOperational); - final Map tableOperationalMap = FlowCapableNodeLookups.wrapTablesToMap(tablesOperational); + final Collection
tablesOperational = ReconcileUtil.safeTables(flowCapableNodeOperational); + final Map tableOperationalMap = FlowCapableNodeLookups.wrapTablesToMap(tablesOperational); return ReconcileUtil.resolveFlowDiffsInAllTables(nodeId, tableOperationalMap, tablesConfigured, true); } @VisibleForTesting - static Map> extractFlowsToRemove(final NodeId nodeId, - final FlowCapableNode flowCapableNodeConfigured, - final FlowCapableNode flowCapableNodeOperational) { - final List
tablesOperational = ReconcileUtil.safeTables(flowCapableNodeOperational); + private static Map> extractFlowsToRemove(final NodeId nodeId, + final FlowCapableNode flowCapableNodeConfigured, final FlowCapableNode flowCapableNodeOperational) { + final Collection
tablesOperational = ReconcileUtil.safeTables(flowCapableNodeOperational); if (tablesOperational.isEmpty()) { return Collections.emptyMap(); } - final List
tablesConfigured = ReconcileUtil.safeTables(flowCapableNodeConfigured); - final Map tableConfiguredMap = FlowCapableNodeLookups.wrapTablesToMap(tablesConfigured); + final Collection
tablesConfigured = ReconcileUtil.safeTables(flowCapableNodeConfigured); + final Map tableConfiguredMap = FlowCapableNodeLookups.wrapTablesToMap(tablesConfigured); return ReconcileUtil.resolveFlowDiffsInAllTables(nodeId, tableConfiguredMap, tablesOperational, false); } @VisibleForTesting - static ItemSyncBox extractMetersToRemove(final NodeId nodeId, - final FlowCapableNode flowCapableNodeConfigured, - final FlowCapableNode flowCapableNodeOperational) { - final List metersConfigured = ReconcileUtil.safeMeters(flowCapableNodeConfigured); - final List metersOperational = ReconcileUtil.safeMeters(flowCapableNodeOperational); + private static ItemSyncBox extractMetersToRemove(final NodeId nodeId, + final FlowCapableNode flowCapableNodeConfigured, + final FlowCapableNode flowCapableNodeOperational) { + final Collection metersConfigured = ReconcileUtil.safeMeters(flowCapableNodeConfigured); + final Collection metersOperational = ReconcileUtil.safeMeters(flowCapableNodeOperational); final Map meterConfiguredMap = FlowCapableNodeLookups.wrapMetersToMap(metersConfigured); return ReconcileUtil.resolveMeterDiffs(nodeId, meterConfiguredMap, metersOperational, false); } @VisibleForTesting - static List> extractGroupsToRemove(final NodeId nodeId, - final FlowCapableNode flowCapableNodeConfigured, - final FlowCapableNode flowCapableNodeOperational) { - final List groupsConfigured = ReconcileUtil.safeGroups(flowCapableNodeConfigured); - final List groupsOperational = ReconcileUtil.safeGroups(flowCapableNodeOperational); - final Map groupConfiguredMap = FlowCapableNodeLookups.wrapGroupsToMap(groupsConfigured); + private static List> extractGroupsToRemove(final NodeId nodeId, + final FlowCapableNode flowCapableNodeConfigured, + final FlowCapableNode flowCapableNodeOperational) { + final Collection groupsConfigured = ReconcileUtil.safeGroups(flowCapableNodeConfigured); + final Collection groupsOperational = ReconcileUtil.safeGroups(flowCapableNodeOperational); + final Map groupConfiguredMap = FlowCapableNodeLookups.wrapGroupsToMap(groupsConfigured); final List pendingGroups = new ArrayList<>(); pendingGroups.addAll(groupsOperational); return ReconcileUtil.resolveAndDivideGroupDiffs(nodeId, groupConfiguredMap, pendingGroups, false); } - }