Search in sources :

Example 26 with Batch

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch 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 27 with Batch

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch 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)

Example 28 with Batch

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

the class FlatBatchUtilTest method testDetectBatchStepType.

@Test
public void testDetectBatchStepType() throws Exception {
    for (BatchStepType stepType : BatchStepType.values()) {
        LOG.debug("checking detection of: {}", stepType);
        final Batch batch = createBatch(stepType);
        final BatchStepType actualType = FlatBatchUtil.detectBatchStepType(batch.getBatchChoice());
        Assert.assertEquals(stepType, actualType);
    }
}
Also used : Batch(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch) BatchStepType(org.opendaylight.openflowplugin.impl.services.batch.BatchStepType) Test(org.junit.Test)

Example 29 with Batch

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

the class FlatBatchMeterAdapters method convertBatchMeterResult.

/**
 * Convert meter batch result.
 * @param stepOffset offset of current batch plan step
 * @return converted {@link ProcessFlatBatchOutput} RPC result
 */
@VisibleForTesting
static <T extends BatchMeterOutputListGrouping> Function<RpcResult<T>, RpcResult<ProcessFlatBatchOutput>> convertBatchMeterResult(final int stepOffset) {
    return new Function<RpcResult<T>, RpcResult<ProcessFlatBatchOutput>>() {

        @Nullable
        @Override
        public RpcResult<ProcessFlatBatchOutput> apply(@Nonnull final RpcResult<T> input) {
            List<BatchFailure> batchFailures = wrapBatchMeterFailuresForFlat(input, stepOffset);
            ProcessFlatBatchOutputBuilder outputBuilder = new ProcessFlatBatchOutputBuilder().setBatchFailure(batchFailures);
            return RpcResultBuilder.<ProcessFlatBatchOutput>status(input.isSuccessful()).withRpcErrors(input.getErrors()).withResult(outputBuilder.build()).build();
        }
    };
}
Also used : Function(com.google.common.base.Function) BatchFailure(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailure) ProcessFlatBatchOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutputBuilder) Nonnull(javax.annotation.Nonnull) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 30 with Batch

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

the class FlatBatchUtil method assembleBatchPlan.

public static List<BatchPlanStep> assembleBatchPlan(List<Batch> batches) {
    final List<BatchPlanStep> plan = new ArrayList<>();
    BatchPlanStep planStep;
    for (Batch batch : batches) {
        final BatchStepType nextStepType = detectBatchStepType(batch.getBatchChoice());
        planStep = new BatchPlanStep(nextStepType);
        planStep.getTaskBag().addAll(extractBatchData(planStep.getStepType(), batch.getBatchChoice()));
        if (!planStep.isEmpty()) {
            plan.add(planStep);
        }
    }
    return plan;
}
Also used : Batch(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch) ArrayList(java.util.ArrayList) BatchPlanStep(org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep) BatchStepType(org.opendaylight.openflowplugin.impl.services.batch.BatchStepType)

Aggregations

ArrayList (java.util.ArrayList)18 Batch (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch)13 VisibleForTesting (com.google.common.annotations.VisibleForTesting)12 BatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder)8 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)5 ProcessFlatBatchOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput)5 BatchFailure (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailure)5 Range (com.google.common.collect.Range)4 Nonnull (javax.annotation.Nonnull)4 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)4 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)4 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)4 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)4 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)4 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)4 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)4 Test (org.junit.Test)3 BatchStepType (org.opendaylight.openflowplugin.impl.services.batch.BatchStepType)3