Search in sources :

Example 1 with BatchStepJob

use of org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob 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 2 with BatchStepJob

use of org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob in project openflowplugin by opendaylight.

the class SalFlatBatchServiceImpl method executeBatchPlan.

@VisibleForTesting
Future<RpcResult<ProcessFlatBatchOutput>> executeBatchPlan(final List<BatchStepJob> batchJobsChain) {
    BatchStepJob batchJob;
    final List<ListenableFuture<RpcResult<ProcessFlatBatchOutput>>> firedJobs = new ArrayList<>();
    ListenableFuture<RpcResult<ProcessFlatBatchOutput>> chainSummaryResult = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
    for (int i = 0; i < batchJobsChain.size(); i++) {
        batchJob = batchJobsChain.get(i);
        // wire actual job with chain
        firedJobs.add(Futures.transformAsync(chainSummaryResult, batchJob.getStepFunction(), MoreExecutors.directExecutor()));
        // if barrier after actual job is needed or it is the last job -> merge fired job results with chain result
        if ((batchJob.getPlanStep().isBarrierAfter()) || (i == batchJobsChain.size() - 1)) {
            firedJobs.add(0, chainSummaryResult);
            chainSummaryResult = FlatBatchUtil.mergeJobsResultsFutures(firedJobs);
            firedJobs.clear();
        }
    }
    return chainSummaryResult;
}
Also used : BatchStepJob(org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with BatchStepJob

use of org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob 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 BatchStepJob

use of org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob 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)

Example 5 with BatchStepJob

use of org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob in project openflowplugin by opendaylight.

the class SalFlatBatchServiceImplTest method testPrepareBatchPlan_success.

@Test
public void testPrepareBatchPlan_success() 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);
    final List<BatchStepJob> batchChain = salFlatBatchService.prepareBatchChain(batchPlan, NODE_REF, true);
    Assert.assertEquals(1, batchChain.size());
    Mockito.when(salFlowsBatchService.addFlowsBatch(Matchers.<AddFlowsBatchInput>any())).thenReturn(RpcResultBuilder.success(new AddFlowsBatchOutputBuilder().build()).buildFuture());
    final Future<RpcResult<ProcessFlatBatchOutput>> rpcResultFuture = salFlatBatchService.executeBatchPlan(batchChain);
    Assert.assertTrue(rpcResultFuture.isDone());
    final RpcResult<ProcessFlatBatchOutput> rpcResult = rpcResultFuture.get();
    Assert.assertTrue(rpcResult.isSuccessful());
    Assert.assertEquals(0, rpcResult.getErrors().size());
    Assert.assertEquals(0, rpcResult.getResult().getBatchFailure().size());
    Mockito.verify(salFlowsBatchService).addFlowsBatch(Matchers.<AddFlowsBatchInput>any());
}
Also used : 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) 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) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) Test(org.junit.Test)

Aggregations

BatchStepJob (org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob)5 ProcessFlatBatchOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput)5 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)5 BatchPlanStep (org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep)4 Test (org.junit.Test)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)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 Preconditions (com.google.common.base.Preconditions)1 Futures (com.google.common.util.concurrent.Futures)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 FlatBatchFlowAdapters (org.opendaylight.openflowplugin.impl.services.batch.FlatBatchFlowAdapters)1 FlatBatchGroupAdapters (org.opendaylight.openflowplugin.impl.services.batch.FlatBatchGroupAdapters)1