use of org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep 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.openflowplugin.impl.services.batch.BatchPlanStep in project openflowplugin by opendaylight.
the class SalFlatBatchServiceImplTest method testExecuteBatchPlan.
@Test
public void testExecuteBatchPlan() throws Exception {
BatchStepJob batchStepJob1 = Mockito.mock(BatchStepJob.class);
BatchStepJob batchStepJob2 = Mockito.mock(BatchStepJob.class);
AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>> function1 = Mockito.mock(AsyncFunction.class);
AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>> function2 = Mockito.mock(AsyncFunction.class);
Mockito.when(batchStepJob1.getStepFunction()).thenReturn(function1);
Mockito.when(batchStepJob2.getStepFunction()).thenReturn(function2);
BatchPlanStep batchPlanStep1 = new BatchPlanStep(BatchStepType.GROUP_ADD);
batchPlanStep1.setBarrierAfter(true);
BatchPlanStep batchPlanStep2 = new BatchPlanStep(BatchStepType.FLOW_ADD);
batchPlanStep1.setBarrierAfter(false);
Mockito.when(batchStepJob1.getPlanStep()).thenReturn(batchPlanStep1);
Mockito.when(batchStepJob2.getPlanStep()).thenReturn(batchPlanStep2);
final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> succeededChainOutput = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> failedChainOutput = RpcResultBuilder.<ProcessFlatBatchOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ut-chainError").withResult(createFlatBatchOutput(createFlowBatchFailure(0, "f1"), createFlowBatchFailure(1, "f2"))).buildFuture();
Mockito.when(batchStepJob1.getStepFunction().apply(Matchers.<RpcResult<ProcessFlatBatchOutput>>any())).thenReturn(succeededChainOutput);
Mockito.when(batchStepJob2.getStepFunction().apply(Matchers.<RpcResult<ProcessFlatBatchOutput>>any())).thenReturn(failedChainOutput);
final List<BatchStepJob> batchChainElements = Lists.newArrayList(batchStepJob1, batchStepJob2);
final Future<RpcResult<ProcessFlatBatchOutput>> rpcResultFuture = salFlatBatchService.executeBatchPlan(batchChainElements);
Assert.assertTrue(rpcResultFuture.isDone());
final RpcResult<ProcessFlatBatchOutput> rpcResult = rpcResultFuture.get();
Assert.assertFalse(rpcResult.isSuccessful());
Assert.assertEquals(1, rpcResult.getErrors().size());
Assert.assertEquals(2, rpcResult.getResult().getBatchFailure().size());
Assert.assertEquals("f2", ((FlatBatchFailureFlowIdCase) rpcResult.getResult().getBatchFailure().get(1).getBatchItemIdChoice()).getFlowId().getValue());
}
use of org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep 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;
}
use of org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep in project openflowplugin by opendaylight.
the class FlatBatchUtil method markBarriersWhereNeeded.
public static void markBarriersWhereNeeded(final List<BatchPlanStep> batchPlan) {
final EnumSet<BatchStepType> previousTypes = EnumSet.noneOf(BatchStepType.class);
BatchPlanStep previousPlanStep = null;
for (BatchPlanStep planStep : batchPlan) {
final BatchStepType type = planStep.getStepType();
if (!previousTypes.isEmpty() && decideBarrier(previousTypes, type)) {
previousPlanStep.setBarrierAfter(true);
previousTypes.clear();
}
previousTypes.add(type);
previousPlanStep = planStep;
}
}
use of org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep in project openflowplugin by opendaylight.
the class SalFlatBatchServiceImplTest method testPrepareBatchPlan_failure.
@Test
public void testPrepareBatchPlan_failure() throws Exception {
final FlatBatchAddFlow flatBatchAddFlow = new FlatBatchAddFlowBuilder().setFlowId(new FlowId("f1")).build();
final BatchPlanStep batchPlanStep = new BatchPlanStep(BatchStepType.FLOW_ADD);
batchPlanStep.getTaskBag().addAll(Lists.newArrayList(flatBatchAddFlow, flatBatchAddFlow));
final List<BatchPlanStep> batchPlan = Lists.newArrayList(batchPlanStep, batchPlanStep);
final List<BatchStepJob> batchChain = salFlatBatchService.prepareBatchChain(batchPlan, NODE_REF, true);
Assert.assertEquals(2, batchChain.size());
Mockito.when(salFlowsBatchService.addFlowsBatch(Matchers.<AddFlowsBatchInput>any())).thenReturn(RpcResultBuilder.<AddFlowsBatchOutput>failed().withResult(new AddFlowsBatchOutputBuilder().setBatchFailedFlowsOutput(Lists.newArrayList(new BatchFailedFlowsOutputBuilder().setBatchOrder(0).setFlowId(new FlowId("f1")).build(), new BatchFailedFlowsOutputBuilder().setBatchOrder(1).setFlowId(new FlowId("f2")).build())).build()).withError(RpcError.ErrorType.APPLICATION, "ut-addFlowBatchError").buildFuture());
final Future<RpcResult<ProcessFlatBatchOutput>> rpcResultFuture = salFlatBatchService.executeBatchPlan(batchChain);
Assert.assertTrue(rpcResultFuture.isDone());
final RpcResult<ProcessFlatBatchOutput> rpcResult = rpcResultFuture.get();
Assert.assertFalse(rpcResult.isSuccessful());
Assert.assertEquals(2, rpcResult.getErrors().size());
Assert.assertEquals(4, rpcResult.getResult().getBatchFailure().size());
Mockito.verify(salFlowsBatchService, Mockito.times(2)).addFlowsBatch(addFlowsBatchInputCpt.capture());
Assert.assertEquals(2, addFlowsBatchInputCpt.getValue().getBatchAddFlows().size());
}
Aggregations