Search in sources :

Example 6 with BatchBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder in project openflowplugin by opendaylight.

the class SyncPlanPushStrategyFlatBatchImpl method assembleAddOrUpdateGroups.

@VisibleForTesting
static int assembleAddOrUpdateGroups(final List<Batch> batchBag, int batchOrder, final List<ItemSyncBox<Group>> groupsToAddOrUpdate) {
    // process group add+update
    int order = batchOrder;
    if (groupsToAddOrUpdate != null) {
        for (ItemSyncBox<Group> groupItemSyncBox : groupsToAddOrUpdate) {
            if (!groupItemSyncBox.getItemsToPush().isEmpty()) {
                final List<FlatBatchAddGroup> flatBatchAddGroupBag = new ArrayList<>(groupItemSyncBox.getItemsToUpdate().size());
                int itemOrder = 0;
                for (Group group : groupItemSyncBox.getItemsToPush()) {
                    flatBatchAddGroupBag.add(new FlatBatchAddGroupBuilder(group).setBatchOrder(itemOrder++).build());
                }
                final Batch batch = new BatchBuilder().setBatchChoice(new FlatBatchAddGroupCaseBuilder().setFlatBatchAddGroup(flatBatchAddGroupBag).build()).setBatchOrder(order).build();
                order += itemOrder;
                batchBag.add(batch);
            }
            if (!groupItemSyncBox.getItemsToUpdate().isEmpty()) {
                final List<FlatBatchUpdateGroup> flatBatchUpdateGroupBag = new ArrayList<>(groupItemSyncBox.getItemsToUpdate().size());
                int itemOrder = 0;
                for (ItemSyncBox.ItemUpdateTuple<Group> groupUpdate : groupItemSyncBox.getItemsToUpdate()) {
                    flatBatchUpdateGroupBag.add(new FlatBatchUpdateGroupBuilder().setBatchOrder(itemOrder++).setOriginalBatchedGroup(new OriginalBatchedGroupBuilder(groupUpdate.getOriginal()).build()).setUpdatedBatchedGroup(new UpdatedBatchedGroupBuilder(groupUpdate.getUpdated()).build()).build());
                }
                final Batch batch = new BatchBuilder().setBatchChoice(new FlatBatchUpdateGroupCaseBuilder().setFlatBatchUpdateGroup(flatBatchUpdateGroupBag).build()).setBatchOrder(order).build();
                order += itemOrder;
                batchBag.add(batch);
            }
        }
    }
    return order;
}
Also used : FlatBatchUpdateGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.group._case.FlatBatchUpdateGroup) Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) FlatBatchRemoveGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.group._case.FlatBatchRemoveGroup) FlatBatchAddGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.group._case.FlatBatchAddGroup) FlatBatchAddGroupCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddGroupCaseBuilder) OriginalBatchedGroupBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.OriginalBatchedGroupBuilder) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) UpdatedBatchedGroupBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.UpdatedBatchedGroupBuilder) ArrayList(java.util.ArrayList) BatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder) FlatBatchUpdateGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.group._case.FlatBatchUpdateGroup) FlatBatchAddGroupBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.group._case.FlatBatchAddGroupBuilder) FlatBatchUpdateGroupCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateGroupCaseBuilder) Batch(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch) FlatBatchAddGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.group._case.FlatBatchAddGroup) FlatBatchUpdateGroupBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.group._case.FlatBatchUpdateGroupBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with BatchBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder in project openflowplugin by opendaylight.

the class SyncPlanPushStrategyFlatBatchImplTest method testMapBatchesToRanges.

@Test
public void testMapBatchesToRanges() throws Exception {
    final List<Batch> inputBatchBag = Lists.newArrayList(new BatchBuilder().setBatchOrder(0).build(), new BatchBuilder().setBatchOrder(5).build(), new BatchBuilder().setBatchOrder(9).build(), new BatchBuilder().setBatchOrder(15).build());
    final Map<Range<Integer>, Batch> rangeBatchMap = SyncPlanPushStrategyFlatBatchImpl.mapBatchesToRanges(inputBatchBag, 42);
    Assert.assertEquals(4, rangeBatchMap.size());
    int idx = 0;
    final int[] lower = new int[] { 0, 5, 9, 15 };
    final int[] upper = new int[] { 4, 8, 14, 41 };
    for (Map.Entry<Range<Integer>, Batch> rangeBatchEntry : rangeBatchMap.entrySet()) {
        Assert.assertEquals(lower[idx], rangeBatchEntry.getKey().lowerEndpoint().intValue());
        Assert.assertEquals(upper[idx], rangeBatchEntry.getKey().upperEndpoint().intValue());
        Assert.assertSame(inputBatchBag.get(idx), rangeBatchEntry.getValue());
        idx++;
    }
}
Also used : Batch(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch) BatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder) Range(com.google.common.collect.Range) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Batch (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch)7 BatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 ArrayList (java.util.ArrayList)6 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)4 Map (java.util.Map)3 LinkedHashMap (java.util.LinkedHashMap)2 FlatBatchAddFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.flow._case.FlatBatchAddFlow)2 FlatBatchAddGroup (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.group._case.FlatBatchAddGroup)2 FlatBatchAddMeter (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.meter._case.FlatBatchAddMeter)2 FlatBatchRemoveFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.flow._case.FlatBatchRemoveFlow)2 FlatBatchRemoveGroup (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.group._case.FlatBatchRemoveGroup)2 FlatBatchRemoveMeter (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.meter._case.FlatBatchRemoveMeter)2 FlatBatchUpdateFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.flow._case.FlatBatchUpdateFlow)2 FlatBatchUpdateGroup (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.group._case.FlatBatchUpdateGroup)2 FlatBatchUpdateMeter (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeter)2 Meter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)2 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)2 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)2 Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)2