2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
11 import com.google.common.annotations.VisibleForTesting;
12 import com.google.common.collect.Iterators;
13 import com.google.common.collect.PeekingIterator;
14 import com.google.common.collect.Range;
15 import com.google.common.util.concurrent.FutureCallback;
16 import com.google.common.util.concurrent.Futures;
17 import com.google.common.util.concurrent.JdkFutureAdapters;
18 import com.google.common.util.concurrent.ListenableFuture;
19 import com.google.common.util.concurrent.MoreExecutors;
20 import java.util.ArrayList;
21 import java.util.LinkedHashMap;
22 import java.util.List;
24 import java.util.concurrent.Future;
25 import org.opendaylight.openflowplugin.applications.frsync.SyncPlanPushStrategy;
26 import org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox;
27 import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;
28 import org.opendaylight.openflowplugin.applications.frsync.util.ReconcileUtil;
29 import org.opendaylight.openflowplugin.applications.frsync.util.SyncCrudCounters;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInputBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.BatchChoice;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddFlowCase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddFlowCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddGroupCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddGroupCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddMeterCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddMeterCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchRemoveFlowCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchRemoveFlowCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchRemoveGroupCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchRemoveGroupCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchRemoveMeterCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchRemoveMeterCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateFlowCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateFlowCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateGroupCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateGroupCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateMeterCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateMeterCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.flow._case.FlatBatchAddFlow;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.flow._case.FlatBatchAddFlowBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.group._case.FlatBatchAddGroup;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.group._case.FlatBatchAddGroupBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.meter._case.FlatBatchAddMeter;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.meter._case.FlatBatchAddMeterBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.flow._case.FlatBatchRemoveFlow;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.flow._case.FlatBatchRemoveFlowBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.group._case.FlatBatchRemoveGroup;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.group._case.FlatBatchRemoveGroupBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.meter._case.FlatBatchRemoveMeter;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.meter._case.FlatBatchRemoveMeterBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.flow._case.FlatBatchUpdateFlow;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.flow._case.FlatBatchUpdateFlowBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.group._case.FlatBatchUpdateGroup;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.group._case.FlatBatchUpdateGroupBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeter;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeterBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailure;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.input.update.grouping.OriginalBatchedFlowBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.input.update.grouping.UpdatedBatchedFlowBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.OriginalBatchedGroupBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.UpdatedBatchedGroupBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.input.update.grouping.OriginalBatchedMeterBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.input.update.grouping.UpdatedBatchedMeterBuilder;
85 import org.opendaylight.yangtools.yang.common.RpcResult;
86 import org.slf4j.Logger;
87 import org.slf4j.LoggerFactory;
90 * Execute CRUD API for flow + group + meter involving flat-batch strategy.
92 public class SyncPlanPushStrategyFlatBatchImpl implements SyncPlanPushStrategy {
94 private static final Logger LOG = LoggerFactory.getLogger(SyncPlanPushStrategyFlatBatchImpl.class);
96 private SalFlatBatchService flatBatchService;
97 private TableForwarder tableForwarder;
100 public ListenableFuture<RpcResult<Void>> executeSyncStrategy(ListenableFuture<RpcResult<Void>> resultVehicle,
101 final SynchronizationDiffInput diffInput,
102 final SyncCrudCounters counters) {
103 // prepare default (full) counts
104 counters.getGroupCrudCounts().setAdded(ReconcileUtil.countTotalPushed(diffInput.getGroupsToAddOrUpdate()));
105 counters.getGroupCrudCounts().setUpdated(ReconcileUtil.countTotalUpdated(diffInput.getGroupsToAddOrUpdate()));
106 counters.getGroupCrudCounts().setRemoved(ReconcileUtil.countTotalPushed(diffInput.getGroupsToRemove()));
108 counters.getFlowCrudCounts().setAdded(ReconcileUtil.countTotalPushed(
109 diffInput.getFlowsToAddOrUpdate().values()));
110 counters.getFlowCrudCounts().setUpdated(ReconcileUtil.countTotalUpdated(
111 diffInput.getFlowsToAddOrUpdate().values()));
112 counters.getFlowCrudCounts().setRemoved(ReconcileUtil.countTotalPushed(diffInput.getFlowsToRemove().values()));
114 counters.getMeterCrudCounts().setAdded(diffInput.getMetersToAddOrUpdate().getItemsToPush().size());
115 counters.getMeterCrudCounts().setUpdated(diffInput.getMetersToAddOrUpdate().getItemsToUpdate().size());
116 counters.getMeterCrudCounts().setRemoved(diffInput.getMetersToRemove().getItemsToPush().size());
118 /* Tables - have to be pushed before groups */
119 // TODO enable table-update when ready
120 //resultVehicle = updateTableFeatures(nodeIdent, configTree);
122 resultVehicle = Futures.transformAsync(resultVehicle, input -> {
123 final List<Batch> batchBag = new ArrayList<>();
126 batchOrder = assembleAddOrUpdateGroups(batchBag, batchOrder, diffInput.getGroupsToAddOrUpdate());
127 batchOrder = assembleAddOrUpdateMeters(batchBag, batchOrder, diffInput.getMetersToAddOrUpdate());
128 batchOrder = assembleAddOrUpdateFlows(batchBag, batchOrder, diffInput.getFlowsToAddOrUpdate());
130 batchOrder = assembleRemoveFlows(batchBag, batchOrder, diffInput.getFlowsToRemove());
131 batchOrder = assembleRemoveMeters(batchBag, batchOrder, diffInput.getMetersToRemove());
132 batchOrder = assembleRemoveGroups(batchBag, batchOrder, diffInput.getGroupsToRemove());
134 LOG.trace("Index of last batch step: {}", batchOrder);
136 final ProcessFlatBatchInput flatBatchInput = new ProcessFlatBatchInputBuilder()
137 .setNode(new NodeRef(PathUtil.digNodePath(diffInput.getNodeIdent())))
138 // TODO: propagate from input
139 .setExitOnFirstError(false)
143 final Future<RpcResult<ProcessFlatBatchOutput>> rpcResultFuture =
144 flatBatchService.processFlatBatch(flatBatchInput);
146 if (LOG.isDebugEnabled()) {
147 Futures.addCallback(JdkFutureAdapters.listenInPoolThread(rpcResultFuture),
148 createCounterCallback(batchBag, batchOrder, counters), MoreExecutors.directExecutor());
151 return Futures.transform(JdkFutureAdapters.listenInPoolThread(rpcResultFuture),
152 ReconcileUtil.createRpcResultToVoidFunction("flat-batch"),
153 MoreExecutors.directExecutor());
154 }, MoreExecutors.directExecutor());
155 return resultVehicle;
158 private FutureCallback<RpcResult<ProcessFlatBatchOutput>> createCounterCallback(final List<Batch> inputBatchBag,
159 final int failureIndexLimit,
160 final SyncCrudCounters counters) {
161 return new FutureCallback<RpcResult<ProcessFlatBatchOutput>>() {
163 public void onSuccess(final RpcResult<ProcessFlatBatchOutput> result) {
164 if (!result.isSuccessful() && result.getResult() != null
165 && !result.getResult().getBatchFailure().isEmpty()) {
166 Map<Range<Integer>, Batch> batchMap = mapBatchesToRanges(inputBatchBag, failureIndexLimit);
167 decrementBatchFailuresCounters(result.getResult().getBatchFailure(), batchMap, counters);
172 public void onFailure(final Throwable failure) {
178 private static void decrementBatchFailuresCounters(final List<BatchFailure> batchFailures,
179 final Map<Range<Integer>, Batch> batchMap,
180 final SyncCrudCounters counters) {
181 for (BatchFailure batchFailure : batchFailures) {
182 for (Map.Entry<Range<Integer>, Batch> rangeBatchEntry : batchMap.entrySet()) {
183 if (rangeBatchEntry.getKey().contains(batchFailure.getBatchOrder())) {
184 // get type and decrease
185 final BatchChoice batchChoice = rangeBatchEntry.getValue().getBatchChoice();
186 decrementCounters(batchChoice, counters);
193 static void decrementCounters(final BatchChoice batchChoice, final SyncCrudCounters counters) {
194 if (batchChoice instanceof FlatBatchAddFlowCase) {
195 counters.getFlowCrudCounts().decAdded();
196 } else if (batchChoice instanceof FlatBatchUpdateFlowCase) {
197 counters.getFlowCrudCounts().decUpdated();
198 } else if (batchChoice instanceof FlatBatchRemoveFlowCase) {
199 counters.getFlowCrudCounts().decRemoved();
200 } else if (batchChoice instanceof FlatBatchAddGroupCase) {
201 counters.getGroupCrudCounts().decAdded();
202 } else if (batchChoice instanceof FlatBatchUpdateGroupCase) {
203 counters.getGroupCrudCounts().decUpdated();
204 } else if (batchChoice instanceof FlatBatchRemoveGroupCase) {
205 counters.getGroupCrudCounts().decRemoved();
206 } else if (batchChoice instanceof FlatBatchAddMeterCase) {
207 counters.getMeterCrudCounts().decAdded();
208 } else if (batchChoice instanceof FlatBatchUpdateMeterCase) {
209 counters.getMeterCrudCounts().decUpdated();
210 } else if (batchChoice instanceof FlatBatchRemoveMeterCase) {
211 counters.getMeterCrudCounts().decRemoved();
215 static Map<Range<Integer>, Batch> mapBatchesToRanges(final List<Batch> inputBatchBag, final int failureIndexLimit) {
216 final Map<Range<Integer>, Batch> batchMap = new LinkedHashMap<>();
217 final PeekingIterator<Batch> batchPeekingIterator = Iterators.peekingIterator(inputBatchBag.iterator());
218 while (batchPeekingIterator.hasNext()) {
219 final Batch batch = batchPeekingIterator.next();
220 final int nextBatchOrder = batchPeekingIterator.hasNext()
221 ? batchPeekingIterator.peek().getBatchOrder()
223 batchMap.put(Range.closed(batch.getBatchOrder(), nextBatchOrder - 1), batch);
229 static int assembleRemoveFlows(final List<Batch> batchBag, int batchOrder,
230 final Map<TableKey, ItemSyncBox<Flow>> flowItemSyncTableMap) {
231 // process flow remove
232 int order = batchOrder;
233 if (flowItemSyncTableMap != null) {
234 for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
235 final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
237 if (!flowItemSyncBox.getItemsToPush().isEmpty()) {
238 final List<FlatBatchRemoveFlow> flatBatchRemoveFlowBag =
239 new ArrayList<>(flowItemSyncBox.getItemsToUpdate().size());
241 for (Flow flow : flowItemSyncBox.getItemsToPush()) {
242 flatBatchRemoveFlowBag.add(new FlatBatchRemoveFlowBuilder(flow)
243 .setBatchOrder(itemOrder++)
244 .setFlowId(flow.getId())
247 final Batch batch = new BatchBuilder()
248 .setBatchChoice(new FlatBatchRemoveFlowCaseBuilder()
249 .setFlatBatchRemoveFlow(flatBatchRemoveFlowBag)
251 .setBatchOrder(order)
262 static int assembleAddOrUpdateGroups(final List<Batch> batchBag, int batchOrder,
263 final List<ItemSyncBox<Group>> groupsToAddOrUpdate) {
264 // process group add+update
265 int order = batchOrder;
266 if (groupsToAddOrUpdate != null) {
267 for (ItemSyncBox<Group> groupItemSyncBox : groupsToAddOrUpdate) {
268 if (!groupItemSyncBox.getItemsToPush().isEmpty()) {
269 final List<FlatBatchAddGroup> flatBatchAddGroupBag =
270 new ArrayList<>(groupItemSyncBox.getItemsToUpdate().size());
272 for (Group group : groupItemSyncBox.getItemsToPush()) {
273 flatBatchAddGroupBag.add(new FlatBatchAddGroupBuilder(group)
274 .setBatchOrder(itemOrder++).build());
276 final Batch batch = new BatchBuilder()
277 .setBatchChoice(new FlatBatchAddGroupCaseBuilder()
278 .setFlatBatchAddGroup(flatBatchAddGroupBag)
280 .setBatchOrder(order)
286 if (!groupItemSyncBox.getItemsToUpdate().isEmpty()) {
287 final List<FlatBatchUpdateGroup> flatBatchUpdateGroupBag =
288 new ArrayList<>(groupItemSyncBox.getItemsToUpdate().size());
290 for (ItemSyncBox.ItemUpdateTuple<Group> groupUpdate : groupItemSyncBox.getItemsToUpdate()) {
291 flatBatchUpdateGroupBag.add(new FlatBatchUpdateGroupBuilder()
292 .setBatchOrder(itemOrder++)
293 .setOriginalBatchedGroup(new OriginalBatchedGroupBuilder(groupUpdate.getOriginal()).build())
294 .setUpdatedBatchedGroup(new UpdatedBatchedGroupBuilder(groupUpdate.getUpdated()).build())
297 final Batch batch = new BatchBuilder()
298 .setBatchChoice(new FlatBatchUpdateGroupCaseBuilder()
299 .setFlatBatchUpdateGroup(flatBatchUpdateGroupBag)
301 .setBatchOrder(order)
312 static int assembleRemoveGroups(final List<Batch> batchBag, int batchOrder,
313 final List<ItemSyncBox<Group>> groupsToRemoveOrUpdate) {
314 // process group add+update
315 int order = batchOrder;
316 if (groupsToRemoveOrUpdate != null) {
317 for (ItemSyncBox<Group> groupItemSyncBox : groupsToRemoveOrUpdate) {
318 if (!groupItemSyncBox.getItemsToPush().isEmpty()) {
319 final List<FlatBatchRemoveGroup> flatBatchRemoveGroupBag =
320 new ArrayList<>(groupItemSyncBox.getItemsToUpdate().size());
322 for (Group group : groupItemSyncBox.getItemsToPush()) {
323 flatBatchRemoveGroupBag.add(new FlatBatchRemoveGroupBuilder(group)
324 .setBatchOrder(itemOrder++).build());
326 final Batch batch = new BatchBuilder()
327 .setBatchChoice(new FlatBatchRemoveGroupCaseBuilder()
328 .setFlatBatchRemoveGroup(flatBatchRemoveGroupBag)
330 .setBatchOrder(order)
341 static int assembleAddOrUpdateMeters(final List<Batch> batchBag, int batchOrder,
342 final ItemSyncBox<Meter> meterItemSyncBox) {
343 // process meter add+update
344 int order = batchOrder;
345 if (meterItemSyncBox != null) {
346 if (!meterItemSyncBox.getItemsToPush().isEmpty()) {
347 final List<FlatBatchAddMeter> flatBatchAddMeterBag =
348 new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
350 for (Meter meter : meterItemSyncBox.getItemsToPush()) {
351 flatBatchAddMeterBag.add(new FlatBatchAddMeterBuilder(meter).setBatchOrder(itemOrder++).build());
353 final Batch batch = new BatchBuilder()
354 .setBatchChoice(new FlatBatchAddMeterCaseBuilder()
355 .setFlatBatchAddMeter(flatBatchAddMeterBag)
357 .setBatchOrder(order)
363 if (!meterItemSyncBox.getItemsToUpdate().isEmpty()) {
364 final List<FlatBatchUpdateMeter> flatBatchUpdateMeterBag =
365 new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
367 for (ItemSyncBox.ItemUpdateTuple<Meter> meterUpdate : meterItemSyncBox.getItemsToUpdate()) {
368 flatBatchUpdateMeterBag.add(new FlatBatchUpdateMeterBuilder()
369 .setBatchOrder(itemOrder++)
370 .setOriginalBatchedMeter(new OriginalBatchedMeterBuilder(meterUpdate.getOriginal()).build())
371 .setUpdatedBatchedMeter(new UpdatedBatchedMeterBuilder(meterUpdate.getUpdated()).build())
374 final Batch batch = new BatchBuilder()
375 .setBatchChoice(new FlatBatchUpdateMeterCaseBuilder()
376 .setFlatBatchUpdateMeter(flatBatchUpdateMeterBag)
378 .setBatchOrder(order)
388 static int assembleRemoveMeters(final List<Batch> batchBag, int batchOrder,
389 final ItemSyncBox<Meter> meterItemSyncBox) {
390 // process meter remove
391 int order = batchOrder;
392 if (meterItemSyncBox != null && !meterItemSyncBox.getItemsToPush().isEmpty()) {
393 final List<FlatBatchRemoveMeter> flatBatchRemoveMeterBag =
394 new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
396 for (Meter meter : meterItemSyncBox.getItemsToPush()) {
397 flatBatchRemoveMeterBag.add(new FlatBatchRemoveMeterBuilder(meter).setBatchOrder(itemOrder++).build());
399 final Batch batch = new BatchBuilder()
400 .setBatchChoice(new FlatBatchRemoveMeterCaseBuilder()
401 .setFlatBatchRemoveMeter(flatBatchRemoveMeterBag)
403 .setBatchOrder(order)
412 static int assembleAddOrUpdateFlows(final List<Batch> batchBag, int batchOrder,
413 final Map<TableKey, ItemSyncBox<Flow>> flowItemSyncTableMap) {
414 // process flow add+update
415 int order = batchOrder;
416 if (flowItemSyncTableMap != null) {
417 for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
418 final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
420 if (!flowItemSyncBox.getItemsToPush().isEmpty()) {
421 final List<FlatBatchAddFlow> flatBatchAddFlowBag =
422 new ArrayList<>(flowItemSyncBox.getItemsToUpdate().size());
424 for (Flow flow : flowItemSyncBox.getItemsToPush()) {
425 flatBatchAddFlowBag.add(new FlatBatchAddFlowBuilder(flow)
426 .setBatchOrder(itemOrder++)
427 .setFlowId(flow.getId())
430 final Batch batch = new BatchBuilder()
431 .setBatchChoice(new FlatBatchAddFlowCaseBuilder()
432 .setFlatBatchAddFlow(flatBatchAddFlowBag)
434 .setBatchOrder(order)
440 if (!flowItemSyncBox.getItemsToUpdate().isEmpty()) {
441 final List<FlatBatchUpdateFlow> flatBatchUpdateFlowBag =
442 new ArrayList<>(flowItemSyncBox.getItemsToUpdate().size());
444 for (ItemSyncBox.ItemUpdateTuple<Flow> flowUpdate : flowItemSyncBox.getItemsToUpdate()) {
445 flatBatchUpdateFlowBag.add(new FlatBatchUpdateFlowBuilder()
446 .setBatchOrder(itemOrder++)
447 .setFlowId(flowUpdate.getUpdated().getId())
448 .setOriginalBatchedFlow(new OriginalBatchedFlowBuilder(flowUpdate.getOriginal()).build())
449 .setUpdatedBatchedFlow(new UpdatedBatchedFlowBuilder(flowUpdate.getUpdated()).build())
452 final Batch batch = new BatchBuilder()
453 .setBatchChoice(new FlatBatchUpdateFlowCaseBuilder()
454 .setFlatBatchUpdateFlow(flatBatchUpdateFlowBag)
456 .setBatchOrder(order)
466 public SyncPlanPushStrategyFlatBatchImpl setFlatBatchService(final SalFlatBatchService flatBatchService) {
467 this.flatBatchService = flatBatchService;
471 public SyncPlanPushStrategyFlatBatchImpl setTableForwarder(final TableForwarder tableForwarder) {
472 this.tableForwarder = tableForwarder;