Search in sources :

Example 1 with BatchPlanStep

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);
    }
}
Also used : Batch(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch) BatchPlanStep(org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep) Test(org.junit.Test)

Example 2 with BatchPlanStep

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());
}
Also used : BatchStepJob(org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob) FlatBatchFailureFlowIdCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.batch.failure.batch.item.id.choice.FlatBatchFailureFlowIdCase) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) BatchPlanStep(org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) Test(org.junit.Test)

Example 3 with BatchPlanStep

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;
}
Also used : BatchStepJob(org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput) ProcessFlatBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput) UpdateMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput) AddGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput) LoggerFactory(org.slf4j.LoggerFactory) SalFlatBatchService(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService) SalFlowsBatchService(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.SalFlowsBatchService) FlatBatchGroupAdapters(org.opendaylight.openflowplugin.impl.services.batch.FlatBatchGroupAdapters) AddMetersBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput) ArrayList(java.util.ArrayList) RemoveGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput) FlatBatchUtil(org.opendaylight.openflowplugin.impl.util.FlatBatchUtil) RemoveGroupsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutput) Future(java.util.concurrent.Future) BatchStepJob(org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob) AddGroupsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutput) SalMetersBatchService(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.SalMetersBatchService) SalFlowService(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService) UpdateGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput) UpdateMetersBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchOutput) AddFlowsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutput) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) RemoveFlowsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput) Logger(org.slf4j.Logger) UpdateFlowsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchOutput) AddMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput) RemoveFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput) SalGroupsBatchService(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.SalGroupsBatchService) FlatBatchMeterAdapters(org.opendaylight.openflowplugin.impl.services.batch.FlatBatchMeterAdapters) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) BatchPlanStep(org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) PathUtil(org.opendaylight.openflowplugin.impl.util.PathUtil) UpdateFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput) RemoveMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput) Preconditions(com.google.common.base.Preconditions) UpdateGroupsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchOutput) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RemoveMetersBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchOutput) FlatBatchFlowAdapters(org.opendaylight.openflowplugin.impl.services.batch.FlatBatchFlowAdapters) ArrayList(java.util.ArrayList) BatchPlanStep(org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with BatchPlanStep

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;
    }
}
Also used : BatchPlanStep(org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep) BatchStepType(org.opendaylight.openflowplugin.impl.services.batch.BatchStepType)

Example 5 with BatchPlanStep

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());
}
Also used : BatchFailedFlowsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.output.list.grouping.BatchFailedFlowsOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) BatchPlanStep(org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep) AddFlowsBatchOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutputBuilder) 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) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) BatchStepJob(org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob) FlatBatchAddFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.flow._case.FlatBatchAddFlowBuilder) AddFlowsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutput) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) Test(org.junit.Test)

Aggregations

BatchPlanStep (org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep)7 Test (org.junit.Test)4 BatchStepJob (org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob)4 ProcessFlatBatchOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 ArrayList (java.util.ArrayList)2 BatchStepType (org.opendaylight.openflowplugin.impl.services.batch.BatchStepType)2 Batch (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch)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 FlatBatchAddFlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.flow._case.FlatBatchAddFlowBuilder)2 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)2 AddFlowsBatchOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutput)2 AddFlowsBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutputBuilder)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 List (java.util.List)1 Future (java.util.concurrent.Future)1