use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch in project bgpcep by opendaylight.
the class AppPeerBenchmark method processRoutes.
private long processRoutes(final Ipv4Prefix ipv4Prefix, final long count, final long batch, final Attributes attributes) {
WriteTransaction wt = this.txChain.newWriteOnlyTransaction();
String address = getAdddressFromPrefix(ipv4Prefix);
final Stopwatch stopwatch = Stopwatch.createStarted();
for (int i = 1; i <= count; i++) {
final Ipv4RouteKey routeKey = new Ipv4RouteKey(NON_PATH_ID, createPrefix(address));
final KeyedInstanceIdentifier<Ipv4Route, Ipv4RouteKey> routeIId = this.routesIId.child(Ipv4Route.class, routeKey);
if (attributes != null) {
final Ipv4RouteBuilder ipv4RouteBuilder = new Ipv4RouteBuilder();
ipv4RouteBuilder.setPrefix(routeKey.getPrefix());
ipv4RouteBuilder.setKey(routeKey);
ipv4RouteBuilder.setAttributes(attributes);
final Ipv4Route ipv4Route = ipv4RouteBuilder.build();
wt.put(LogicalDatastoreType.CONFIGURATION, routeIId, ipv4Route);
} else {
wt.delete(LogicalDatastoreType.CONFIGURATION, routeIId);
}
if (i % batch == 0) {
wt.submit();
wt = this.txChain.newWriteOnlyTransaction();
}
address = increasePrefix(address);
}
wt.submit();
return stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
}
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 testMarkBarriersWhereNeeded_noBarrier.
@Test
public void testMarkBarriersWhereNeeded_noBarrier() throws Exception {
final List<Batch> batches = Lists.newArrayList(// general part - no flush required
createBatch(BatchStepType.GROUP_REMOVE), createBatch(BatchStepType.METER_REMOVE), createBatch(BatchStepType.FLOW_ADD), createBatch(BatchStepType.FLOW_REMOVE, 2), createBatch(BatchStepType.FLOW_ADD), createBatch(BatchStepType.FLOW_UPDATE), createBatch(BatchStepType.GROUP_ADD), createBatch(BatchStepType.GROUP_UPDATE), createBatch(BatchStepType.METER_ADD), createBatch(BatchStepType.METER_UPDATE));
final List<BatchPlanStep> batchPlan = FlatBatchUtil.assembleBatchPlan(batches);
FlatBatchUtil.markBarriersWhereNeeded(batchPlan);
Assert.assertEquals(10, batchPlan.size());
for (int i = 0; i < batchPlan.size(); i++) {
final BatchPlanStep planStep = batchPlan.get(i);
final boolean barrierBefore = planStep.isBarrierAfter();
LOG.debug("checking barrier mark @ {} {} -> {}", i, planStep.getStepType(), barrierBefore);
Assert.assertFalse(barrierBefore);
}
}
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 assembleAddOrUpdateMeters.
@VisibleForTesting
static int assembleAddOrUpdateMeters(final List<Batch> batchBag, int batchOrder, final ItemSyncBox<Meter> meterItemSyncBox) {
// process meter add+update
int order = batchOrder;
if (meterItemSyncBox != null) {
if (!meterItemSyncBox.getItemsToPush().isEmpty()) {
final List<FlatBatchAddMeter> flatBatchAddMeterBag = new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
int itemOrder = 0;
for (Meter meter : meterItemSyncBox.getItemsToPush()) {
flatBatchAddMeterBag.add(new FlatBatchAddMeterBuilder(meter).setBatchOrder(itemOrder++).build());
}
final Batch batch = new BatchBuilder().setBatchChoice(new FlatBatchAddMeterCaseBuilder().setFlatBatchAddMeter(flatBatchAddMeterBag).build()).setBatchOrder(order).build();
order += itemOrder;
batchBag.add(batch);
}
if (!meterItemSyncBox.getItemsToUpdate().isEmpty()) {
final List<FlatBatchUpdateMeter> flatBatchUpdateMeterBag = new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
int itemOrder = 0;
for (ItemSyncBox.ItemUpdateTuple<Meter> meterUpdate : meterItemSyncBox.getItemsToUpdate()) {
flatBatchUpdateMeterBag.add(new FlatBatchUpdateMeterBuilder().setBatchOrder(itemOrder++).setOriginalBatchedMeter(new OriginalBatchedMeterBuilder(meterUpdate.getOriginal()).build()).setUpdatedBatchedMeter(new UpdatedBatchedMeterBuilder(meterUpdate.getUpdated()).build()).build());
}
final Batch batch = new BatchBuilder().setBatchChoice(new FlatBatchUpdateMeterCaseBuilder().setFlatBatchUpdateMeter(flatBatchUpdateMeterBag).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 SyncPlanPushStrategyFlatBatchImpl method assembleRemoveFlows.
@VisibleForTesting
static int assembleRemoveFlows(final List<Batch> batchBag, int batchOrder, final Map<TableKey, ItemSyncBox<Flow>> flowItemSyncTableMap) {
// process flow remove
int order = batchOrder;
if (flowItemSyncTableMap != null) {
for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
if (!flowItemSyncBox.getItemsToPush().isEmpty()) {
final List<FlatBatchRemoveFlow> flatBatchRemoveFlowBag = new ArrayList<>(flowItemSyncBox.getItemsToUpdate().size());
int itemOrder = 0;
for (Flow flow : flowItemSyncBox.getItemsToPush()) {
flatBatchRemoveFlowBag.add(new FlatBatchRemoveFlowBuilder(flow).setBatchOrder(itemOrder++).setFlowId(flow.getId()).build());
}
final Batch batch = new BatchBuilder().setBatchChoice(new FlatBatchRemoveFlowCaseBuilder().setFlatBatchRemoveFlow(flatBatchRemoveFlowBag).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 SalFlatBatchServiceImpl method prepareBatchChain.
@VisibleForTesting
List<BatchStepJob> prepareBatchChain(final List<BatchPlanStep> batchPlan, final NodeRef node, final boolean exitOnFirstError) {
// create batch API calls based on plan steps
final List<BatchStepJob> chainJobs = new ArrayList<>();
int stepOffset = 0;
for (final BatchPlanStep planStep : batchPlan) {
final int currentOffset = stepOffset;
chainJobs.add(new BatchStepJob(planStep, chainInput -> {
if (exitOnFirstError && !chainInput.isSuccessful()) {
LOG.debug("error on flat batch chain occurred -> skipping step {}", planStep.getStepType());
return FlatBatchUtil.createEmptyRpcBatchResultFuture(false);
}
LOG.trace("batch progressing on step type {}, previous steps result: {}", planStep.getStepType(), chainInput.isSuccessful());
return getChainOutput(node, planStep, currentOffset);
}));
stepOffset += planStep.getTaskBag().size();
}
return chainJobs;
}
Aggregations