import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeSnapshotDao;
import org.opendaylight.openflowplugin.applications.frsync.impl.clustering.DeviceMastershipManager;
import org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SyncPlanPushStrategyFlatBatchImpl;
+import org.opendaylight.openflowplugin.applications.frsync.impl.strategy.TableForwarder;
import org.opendaylight.openflowplugin.applications.frsync.util.ReconciliationRegistry;
import org.opendaylight.openflowplugin.applications.frsync.util.SemaphoreKeeperGuavaImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService;
final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
LOG.trace("syncup future decorator: {}", nodeId.getValue());
- final ListenableFuture<Boolean> syncup = executorService.submit(() -> {
+ return executorService.submit(() -> {
final String oldThreadName = updateThreadName(nodeId);
try {
updateThreadName(oldThreadName);
}
});
-
- return syncup;
}
protected ListenableFuture<Boolean> doSyncupInFuture(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,
}
public boolean isDeviceMastered(final NodeId nodeId) {
- if (deviceMasterships.get(nodeId) == null) {
- return false;
- } else {
- return deviceMasterships.get(nodeId).isDeviceMastered();
- }
+ return deviceMasterships.get(nodeId) != null && deviceMasterships.get(nodeId).isDeviceMastered();
}
@VisibleForTesting
-/**
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+/*
+ * 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;
+package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
import com.google.common.base.Preconditions;
import java.util.concurrent.Future;
-/**
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+/*
+ * 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;
+package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
import java.util.concurrent.Future;
import org.opendaylight.openflowplugin.applications.frsync.ForwardingRulesCommitter;
-/**
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+/*
+ * 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;
+package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
import java.util.concurrent.Future;
import org.opendaylight.openflowplugin.applications.frsync.ForwardingRulesCommitter;
import java.util.concurrent.Future;
import javax.annotation.Nullable;
import org.opendaylight.openflowplugin.applications.frsync.SyncPlanPushStrategy;
-import org.opendaylight.openflowplugin.applications.frsync.impl.TableForwarder;
import org.opendaylight.openflowplugin.applications.frsync.util.FxChainUtil;
import org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox;
import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;
final ProcessFlatBatchInput flatBatchInput = new ProcessFlatBatchInputBuilder()
.setNode(new NodeRef(PathUtil.digNodePath(diffInput.getNodeIdent())))
- .setExitOnFirstError(false) // TODO: propagate from input
+ // TODO: propagate from input
+ .setExitOnFirstError(false)
.setBatch(batchBag)
.build();
@VisibleForTesting
static int assembleRemoveMeters(final List<Batch> batchBag, int batchOrder, final ItemSyncBox<Meter> meterItemSyncBox) {
// process meter remove
- if (meterItemSyncBox != null) {
- if (!meterItemSyncBox.getItemsToPush().isEmpty()) {
- final List<FlatBatchRemoveMeter> flatBatchRemoveMeterBag =
- new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
- int itemOrder = 0;
- for (Meter meter : meterItemSyncBox.getItemsToPush()) {
- flatBatchRemoveMeterBag.add(new FlatBatchRemoveMeterBuilder(meter).setBatchOrder(itemOrder++).build());
- }
- final Batch batch = new BatchBuilder()
- .setBatchChoice(new FlatBatchRemoveMeterCaseBuilder()
- .setFlatBatchRemoveMeter(flatBatchRemoveMeterBag)
- .build())
- .setBatchOrder(batchOrder)
- .build();
- batchOrder += itemOrder;
- batchBag.add(batch);
+ if (meterItemSyncBox != null && !meterItemSyncBox.getItemsToPush().isEmpty()) {
+ final List<FlatBatchRemoveMeter> flatBatchRemoveMeterBag =
+ new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
+ int itemOrder = 0;
+ for (Meter meter : meterItemSyncBox.getItemsToPush()) {
+ flatBatchRemoveMeterBag.add(new FlatBatchRemoveMeterBuilder(meter).setBatchOrder(itemOrder++).build());
}
+ final Batch batch = new BatchBuilder()
+ .setBatchChoice(new FlatBatchRemoveMeterCaseBuilder()
+ .setFlatBatchRemoveMeter(flatBatchRemoveMeterBag)
+ .build())
+ .setBatchOrder(batchOrder)
+ .build();
+ batchOrder += itemOrder;
+ batchBag.add(batch);
}
return batchOrder;
}
import java.util.List;
import java.util.Map;
import org.opendaylight.openflowplugin.applications.frsync.SyncPlanPushStrategy;
-import org.opendaylight.openflowplugin.applications.frsync.impl.FlowForwarder;
-import org.opendaylight.openflowplugin.applications.frsync.impl.GroupForwarder;
-import org.opendaylight.openflowplugin.applications.frsync.impl.MeterForwarder;
-import org.opendaylight.openflowplugin.applications.frsync.impl.TableForwarder;
import org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts;
import org.opendaylight.openflowplugin.applications.frsync.util.FxChainUtil;
import org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox;
private static final Logger LOG = LoggerFactory.getLogger(SyncPlanPushStrategyIncrementalImpl.class);
private FlowForwarder flowForwarder;
- private TableForwarder tableForwarder;
private MeterForwarder meterForwarder;
private GroupForwarder groupForwarder;
+ private TableForwarder tableForwarder;
private FlowCapableTransactionService transactionService;
@Override
ListenableFuture<RpcResult<Void>> addMissingFlows(final NodeId nodeId,
- final InstanceIdentifier<FlowCapableNode> nodeIdent,
- final Map<TableKey, ItemSyncBox<Flow>> flowsInTablesSyncBox,
- final SyncCrudCounters counters) {
+ final InstanceIdentifier<FlowCapableNode> nodeIdent,
+ final Map<TableKey, ItemSyncBox<Flow>> flowsInTablesSyncBox,
+ final SyncCrudCounters counters) {
if (flowsInTablesSyncBox.isEmpty()) {
LOG.trace("no tables in config for node: {} -> SKIPPING", nodeId.getValue());
return RpcResultBuilder.<Void>success().buildFuture();
Futures.allAsList(allUpdateResults),
ReconcileUtil.<UpdateFlowOutput>createRpcResultCondenser("flow updating"));
- final ListenableFuture<RpcResult<Void>> summaryResult = Futures.transform(
- Futures.allAsList(singleVoidAddResult, singleVoidUpdateResult),
+ return Futures.transform(Futures.allAsList(singleVoidAddResult, singleVoidUpdateResult),
ReconcileUtil.<Void>createRpcResultCondenser("flow add/update"));
-
- return summaryResult;
-
- /*
- return Futures.transform(summaryResult,
- ReconcileUtil.chainBarrierFlush(PathUtil.digNodePath(nodeIdent), transactionService));
- */
}
ListenableFuture<RpcResult<Void>> removeRedundantFlows(final NodeId nodeId,
- final InstanceIdentifier<FlowCapableNode> nodeIdent,
- final Map<TableKey, ItemSyncBox<Flow>> removalPlan,
- final SyncCrudCounters counters) {
+ final InstanceIdentifier<FlowCapableNode> nodeIdent,
+ final Map<TableKey, ItemSyncBox<Flow>> removalPlan,
+ final SyncCrudCounters counters) {
if (removalPlan.isEmpty()) {
LOG.trace("no tables in operational for node: {} -> SKIPPING", nodeId.getValue());
return RpcResultBuilder.<Void>success().buildFuture();
}
ListenableFuture<RpcResult<Void>> removeRedundantMeters(final NodeId nodeId,
- final InstanceIdentifier<FlowCapableNode> nodeIdent,
- final ItemSyncBox<Meter> meterRemovalPlan,
- final SyncCrudCounters counters) {
+ final InstanceIdentifier<FlowCapableNode> nodeIdent,
+ final ItemSyncBox<Meter> meterRemovalPlan,
+ final SyncCrudCounters counters) {
if (meterRemovalPlan.isEmpty()) {
LOG.trace("no meters on device for node: {} -> SKIPPING", nodeId.getValue());
return RpcResultBuilder.<Void>success().buildFuture();
meterCrudCounts.incRemoved();
}
- final ListenableFuture<RpcResult<Void>> singleVoidResult = Futures.transform(
- Futures.allAsList(allResults),
+ return Futures.transform(Futures.allAsList(allResults),
ReconcileUtil.<RemoveMeterOutput>createRpcResultCondenser("meter remove"));
- return singleVoidResult;
- /*
- return Futures.transform(singleVoidResult,
- ReconcileUtil.chainBarrierFlush(PathUtil.digNodePath(nodeIdent), transactionService));
- */
}
ListenableFuture<RpcResult<Void>> removeRedundantGroups(final NodeId nodeId,
ReconcileUtil.<Void>createRpcResultCondenser("group add/update"));
- return Futures.transform(summaryResult,
- ReconcileUtil.chainBarrierFlush(
- PathUtil.digNodePath(nodeIdent), transactionService));
+ return Futures.transform(summaryResult, ReconcileUtil.chainBarrierFlush(
+ PathUtil.digNodePath(nodeIdent), transactionService));
}
ListenableFuture<RpcResult<Void>> addMissingMeters(final NodeId nodeId,
- final InstanceIdentifier<FlowCapableNode> nodeIdent,
- final ItemSyncBox<Meter> syncBox,
- final SyncCrudCounters counters) {
+ final InstanceIdentifier<FlowCapableNode> nodeIdent,
+ final ItemSyncBox<Meter> syncBox,
+ final SyncCrudCounters counters) {
if (syncBox.isEmpty()) {
LOG.trace("no meters configured for node: {} -> SKIPPING", nodeId.getValue());
return RpcResultBuilder.<Void>success().buildFuture();
Futures.allAsList(allUpdateResults),
ReconcileUtil.<UpdateMeterOutput>createRpcResultCondenser("meter update"));
- final ListenableFuture<RpcResult<Void>> summaryResults = Futures.transform(
- Futures.allAsList(singleVoidUpdateResult, singleVoidAddResult),
+ return Futures.transform(Futures.allAsList(singleVoidUpdateResult, singleVoidAddResult),
ReconcileUtil.<Void>createRpcResultCondenser("meter add/update"));
-
- return summaryResults;
-
- /*
- return Futures.transform(summaryResults,
- ReconcileUtil.chainBarrierFlush(PathUtil.digNodePath(nodeIdent), transactionService));
- */
}
ListenableFuture<RpcResult<Void>> addMissingGroups(final NodeId nodeId,
- final InstanceIdentifier<FlowCapableNode> nodeIdent,
- final List<ItemSyncBox<Group>> groupsAddPlan,
- final SyncCrudCounters counters) {
+ final InstanceIdentifier<FlowCapableNode> nodeIdent,
+ final List<ItemSyncBox<Group>> groupsAddPlan,
+ final SyncCrudCounters counters) {
if (groupsAddPlan.isEmpty()) {
LOG.trace("no groups configured for node: {} -> SKIPPING", nodeId.getValue());
return RpcResultBuilder.<Void>success().buildFuture();
-/**
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+/*
+ * 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;
+package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
import java.util.Collections;
import java.util.concurrent.Future;
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;
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));
};
}
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
SyncupEntry that = (SyncupEntry) o;
- if (after != null ? !after.equals(that.after) : that.after != null) return false;
- if (dsTypeAfter != that.dsTypeAfter) return false;
- if (before != null ? !before.equals(that.before) : that.before != null) return false;
+ if (after != null ? !after.equals(that.after) : that.after != null) {
+ return false;
+ }
+ if (dsTypeAfter != that.dsTypeAfter) {
+ return false;
+ }
+ if (before != null ? !before.equals(that.before) : that.before != null) {
+ return false;
+ }
return dsTypeBefore == that.dsTypeBefore;
}
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
import org.opendaylight.openflowplugin.applications.frsync.impl.clustering.DeviceMastershipManager;
import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
private InstanceIdentifier<FlowCapableNode> fcNodePath;
@Mock
- private SyncReactorFutureZipDecorator delegate;
+ private SyncReactor delegate;
@Mock
private DeviceMastershipManager deviceMastershipManager;
@Mock
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
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.inventory.rev130819.NodeId;
private final LogicalDatastoreType operationalDS = LogicalDatastoreType.OPERATIONAL;
@Mock
- private SyncReactorGuardDecorator delegate;
+ private SyncReactor delegate;
@Mock
private SyncupEntry syncupEntry;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
import org.opendaylight.openflowplugin.applications.frsync.util.SemaphoreKeeperGuavaImpl;
import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
private static final NodeId NODE_ID = new NodeId("test-node");
private SyncReactorGuardDecorator reactor;
private InstanceIdentifier<FlowCapableNode> fcNodePath;
- private final LogicalDatastoreType dsType = LogicalDatastoreType.CONFIGURATION;
@Mock
- private SyncReactorRetryDecorator delegate;
+ private SyncReactor delegate;
@Mock
private FlowCapableNode fcConfigNode;
@Mock
Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Matchers.<SyncupEntry>any()))
.thenReturn(Futures.immediateFuture(Boolean.TRUE));
-// reactor.syncup(fcNodePath, fcConfigNode, fcOperationalNode, dsType);
reactor.syncup(fcNodePath, syncupEntry);
-// Mockito.verify(delegate).syncup(fcNodePath, fcConfigNode, fcOperationalNode, dsType);
Mockito.verify(delegate).syncup(fcNodePath, syncupEntry);
Mockito.verifyNoMoreInteractions(delegate);
}
Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Matchers.<SyncupEntry>any()))
.thenReturn(Futures.immediateFailedFuture(new Exception()));
-// reactor.syncup(fcNodePath, fcConfigNode, fcOperationalNode, dsType);
reactor.syncup(fcNodePath, syncupEntry);
-// Mockito.verify(delegate).syncup(fcNodePath, fcConfigNode, fcOperationalNode, dsType);
Mockito.verify(delegate).syncup(fcNodePath, syncupEntry);
Mockito.verifyNoMoreInteractions(delegate);
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
import org.opendaylight.openflowplugin.applications.frsync.util.ReconciliationRegistry;
import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
private InstanceIdentifier<FlowCapableNode> fcNodePath;
@Mock
- private SyncReactorImpl delegate;
+ private SyncReactor delegate;
@Mock
private ReconciliationRegistry reconciliationRegistry;
@Mock
-/**
+/*
* Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.openflowplugin.applications.frsync.impl;
+package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
import java.math.BigInteger;
import java.util.Collections;
-/**
+/*
* Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.openflowplugin.applications.frsync.impl;
+package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
import java.math.BigInteger;
import java.util.concurrent.Future;
-/**
+/*
* Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.openflowplugin.applications.frsync.impl;
+package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
import java.math.BigInteger;
import java.util.concurrent.Future;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.openflowplugin.applications.frsync.impl.TableForwarder;
import org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox;
import org.opendaylight.openflowplugin.applications.frsync.util.SyncCrudCounters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.openflowplugin.applications.frsync.impl.DSInputFactory;
-import org.opendaylight.openflowplugin.applications.frsync.impl.FlowForwarder;
-import org.opendaylight.openflowplugin.applications.frsync.impl.GroupForwarder;
-import org.opendaylight.openflowplugin.applications.frsync.impl.MeterForwarder;
-import org.opendaylight.openflowplugin.applications.frsync.impl.TableForwarder;
import org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox;
import org.opendaylight.openflowplugin.applications.frsync.util.SyncCrudCounters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
}
private <O> Answer<Future<RpcResult<O>>> createSalServiceFutureAnswer() {
- return new Answer<Future<RpcResult<O>>>() {
- @Override
- public Future<RpcResult<O>> answer(final InvocationOnMock invocation) throws Throwable {
- return RpcResultBuilder.<O>success().buildFuture();
- }
- };
+ return invocation -> RpcResultBuilder.<O>success().buildFuture();
}
@Test
-/**
+/*
* Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.openflowplugin.applications.frsync.impl;
+package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
import java.math.BigInteger;
import java.util.concurrent.Future;