use of org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SynchronizationDiffInput in project openflowplugin by opendaylight.
the class SyncReactorImpl method syncup.
@Override
public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> nodeIdent, 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
* - optimization: decide if updates needed
* - execute chosen implementation (e.g. conventional API, bulk API, flat bulk API)
* - 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 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>> flowsToRemove = extractFlowsToRemove(nodeId, configTree, operationalTree);
final ItemSyncBox<Meter> metersToRemove = extractMetersToRemove(nodeId, configTree, operationalTree);
final List<ItemSyncBox<Group>> groupsToRemove = extractGroupsToRemove(nodeId, configTree, operationalTree);
final SynchronizationDiffInput input = new SynchronizationDiffInput(nodeIdent, groupsToAddOrUpdate, metersToAddOrUpdate, flowsToAddOrUpdate, flowsToRemove, metersToRemove, groupsToRemove);
final ListenableFuture<RpcResult<Void>> bootstrapResultFuture = RpcResultBuilder.<Void>success().buildFuture();
final ListenableFuture<RpcResult<Void>> resultVehicle = syncPlanPushStrategy.executeSyncStrategy(bootstrapResultFuture, input, counters);
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());
}
use of org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SynchronizationDiffInput in project openflowplugin by opendaylight.
the class SyncReactorImplTest method testSyncup.
@Test
public void testSyncup() throws Exception {
final FlowCapableNode configFcn = new FlowCapableNodeBuilder().setGroup(Collections.singletonList(DSInputFactory.createGroup(1L))).setTable(Collections.singletonList(new TableBuilder().setFlow(Collections.singletonList(DSInputFactory.createFlow("f1", 1))).build())).setMeter(Collections.singletonList(DSInputFactory.createMeter(1L))).build();
final FlowCapableNode operationalFcn = new FlowCapableNodeBuilder().setGroup(Collections.singletonList(DSInputFactory.createGroup(2L))).setTable(Collections.singletonList(new TableBuilder().setFlow(Collections.singletonList(DSInputFactory.createFlow("f2", 2))).build())).setMeter(Collections.singletonList(DSInputFactory.createMeter(2L))).build();
final SyncupEntry syncupEntry = new SyncupEntry(configFcn, LogicalDatastoreType.CONFIGURATION, operationalFcn, LogicalDatastoreType.OPERATIONAL);
Mockito.when(syncPlanPushStrategy.executeSyncStrategy(Matchers.<ListenableFuture<RpcResult<Void>>>any(), Matchers.<SynchronizationDiffInput>any(), Matchers.<SyncCrudCounters>any())).thenReturn(RpcResultBuilder.<Void>success().buildFuture());
final ListenableFuture<Boolean> syncupResult = reactor.syncup(NODE_IDENT, syncupEntry);
Assert.assertTrue(syncupResult.isDone());
final Boolean voidRpcResult = syncupResult.get(2, TimeUnit.SECONDS);
Assert.assertTrue(voidRpcResult);
Mockito.verify(syncPlanPushStrategy).executeSyncStrategy(Matchers.<ListenableFuture<RpcResult<Void>>>any(), syncDiffInputCaptor.capture(), Matchers.<SyncCrudCounters>any());
final SynchronizationDiffInput diffInput = syncDiffInputCaptor.getValue();
Assert.assertEquals(1, ReconcileUtil.countTotalPushed(diffInput.getFlowsToAddOrUpdate().values()));
Assert.assertEquals(0, ReconcileUtil.countTotalUpdated(diffInput.getFlowsToAddOrUpdate().values()));
Assert.assertEquals(1, ReconcileUtil.countTotalPushed(diffInput.getFlowsToRemove().values()));
Assert.assertEquals(1, ReconcileUtil.countTotalPushed(diffInput.getGroupsToAddOrUpdate()));
Assert.assertEquals(0, ReconcileUtil.countTotalUpdated(diffInput.getGroupsToAddOrUpdate()));
Assert.assertEquals(1, ReconcileUtil.countTotalPushed(diffInput.getGroupsToRemove()));
Assert.assertEquals(1, diffInput.getMetersToAddOrUpdate().getItemsToPush().size());
Assert.assertEquals(0, diffInput.getMetersToAddOrUpdate().getItemsToUpdate().size());
Assert.assertEquals(1, diffInput.getMetersToRemove().getItemsToPush().size());
}
Aggregations