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;
}
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++;
}
}
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);
}
}
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();
}
};
}
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;
}
Aggregations