Search in sources :

Example 11 with ProcessFlatBatchOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput 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 12 with ProcessFlatBatchOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput 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)

Example 13 with ProcessFlatBatchOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput in project openflowplugin by opendaylight.

the class FlatBatchGroupAdaptersTest method testCreateBatchGroupChainingFunction_successes.

@Test
public void testCreateBatchGroupChainingFunction_successes() throws Exception {
    final RpcResult<BatchGroupOutputListGrouping> input = RpcResultBuilder.<BatchGroupOutputListGrouping>success(new AddGroupsBatchOutputBuilder().build()).build();
    final RpcResult<ProcessFlatBatchOutput> rpcResult = FlatBatchGroupAdapters.convertBatchGroupResult(0).apply(input);
    Assert.assertTrue(rpcResult.isSuccessful());
    Assert.assertEquals(0, rpcResult.getErrors().size());
    Assert.assertEquals(0, rpcResult.getResult().getBatchFailure().size());
}
Also used : BatchGroupOutputListGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.BatchGroupOutputListGrouping) AddGroupsBatchOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutputBuilder) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) Test(org.junit.Test)

Example 14 with ProcessFlatBatchOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput in project openflowplugin by opendaylight.

the class FlatBatchUtilTest method testMergeJobsResultsFutures.

@Test
public void testMergeJobsResultsFutures() throws Exception {
    final BatchFailure batchFailure = new BatchFailureBuilder().setBatchOrder(9).setBatchItemIdChoice(new FlatBatchFailureFlowIdCaseBuilder().setFlowId(new FlowId("11")).build()).build();
    final ProcessFlatBatchOutput output = new ProcessFlatBatchOutputBuilder().setBatchFailure(Lists.newArrayList(batchFailure)).build();
    final RpcResult<ProcessFlatBatchOutput> rpcResultFailed = RpcResultBuilder.<ProcessFlatBatchOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ut-rpcError").withResult(output).build();
    final RpcResult<ProcessFlatBatchOutput> rpcResultSuccess = RpcResultBuilder.<ProcessFlatBatchOutput>success().withResult(new ProcessFlatBatchOutputBuilder().setBatchFailure(new ArrayList<>())).build();
    final RpcResult<ProcessFlatBatchOutput> rpcResult1 = FlatBatchUtil.mergeRpcResults().apply(Lists.newArrayList(rpcResultFailed, rpcResultSuccess));
    Assert.assertEquals(1, rpcResult1.getErrors().size());
    Assert.assertFalse(rpcResult1.isSuccessful());
    final RpcResult<ProcessFlatBatchOutput> rpcResult2 = FlatBatchUtil.mergeRpcResults().apply(Lists.newArrayList(rpcResultFailed, rpcResultFailed));
    Assert.assertEquals(2, rpcResult2.getErrors().size());
    Assert.assertFalse(rpcResult2.isSuccessful());
    final RpcResult<ProcessFlatBatchOutput> rpcResult3 = FlatBatchUtil.mergeRpcResults().apply(Lists.newArrayList(rpcResultSuccess, rpcResultSuccess));
    Assert.assertEquals(0, rpcResult3.getErrors().size());
    Assert.assertTrue(rpcResult3.isSuccessful());
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) BatchFailure(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailure) ProcessFlatBatchOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutputBuilder) BatchFailureBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailureBuilder) FlatBatchFailureFlowIdCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.batch.failure.batch.item.id.choice.FlatBatchFailureFlowIdCaseBuilder) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) Test(org.junit.Test)

Example 15 with ProcessFlatBatchOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput in project openflowplugin by opendaylight.

the class SalFlatBatchServiceImpl method getChainOutput.

private ListenableFuture<RpcResult<ProcessFlatBatchOutput>> getChainOutput(final NodeRef node, final BatchPlanStep planStep, final int currentOffset) {
    final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> chainOutput;
    switch(planStep.getStepType()) {
        case FLOW_ADD:
            final AddFlowsBatchInput addFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchAddFlow(planStep, node);
            final Future<RpcResult<AddFlowsBatchOutput>> resultAddFlowFuture = salFlowService.addFlowsBatch(addFlowsBatchInput);
            chainOutput = FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultAddFlowFuture, currentOffset);
            break;
        case FLOW_REMOVE:
            final RemoveFlowsBatchInput removeFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchRemoveFlow(planStep, node);
            final Future<RpcResult<RemoveFlowsBatchOutput>> resultRemoveFlowFuture = salFlowService.removeFlowsBatch(removeFlowsBatchInput);
            chainOutput = FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultRemoveFlowFuture, currentOffset);
            break;
        case FLOW_UPDATE:
            final UpdateFlowsBatchInput updateFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchUpdateFlow(planStep, node);
            final Future<RpcResult<UpdateFlowsBatchOutput>> resultUpdateFlowFuture = salFlowService.updateFlowsBatch(updateFlowsBatchInput);
            chainOutput = FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultUpdateFlowFuture, currentOffset);
            break;
        case GROUP_ADD:
            final AddGroupsBatchInput addGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchAddGroup(planStep, node);
            final Future<RpcResult<AddGroupsBatchOutput>> resultAddGroupFuture = salGroupService.addGroupsBatch(addGroupsBatchInput);
            chainOutput = FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultAddGroupFuture, currentOffset);
            break;
        case GROUP_REMOVE:
            final RemoveGroupsBatchInput removeGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchRemoveGroup(planStep, node);
            final Future<RpcResult<RemoveGroupsBatchOutput>> resultRemoveGroupFuture = salGroupService.removeGroupsBatch(removeGroupsBatchInput);
            chainOutput = FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultRemoveGroupFuture, currentOffset);
            break;
        case GROUP_UPDATE:
            final UpdateGroupsBatchInput updateGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchUpdateGroup(planStep, node);
            final Future<RpcResult<UpdateGroupsBatchOutput>> resultUpdateGroupFuture = salGroupService.updateGroupsBatch(updateGroupsBatchInput);
            chainOutput = FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultUpdateGroupFuture, currentOffset);
            break;
        case METER_ADD:
            final AddMetersBatchInput addMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchAddMeter(planStep, node);
            final Future<RpcResult<AddMetersBatchOutput>> resultAddMeterFuture = salMeterService.addMetersBatch(addMetersBatchInput);
            chainOutput = FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultAddMeterFuture, currentOffset);
            break;
        case METER_REMOVE:
            final RemoveMetersBatchInput removeMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchRemoveMeter(planStep, node);
            final Future<RpcResult<RemoveMetersBatchOutput>> resultRemoveMeterFuture = salMeterService.removeMetersBatch(removeMetersBatchInput);
            chainOutput = FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultRemoveMeterFuture, currentOffset);
            break;
        case METER_UPDATE:
            final UpdateMetersBatchInput updateMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchUpdateMeter(planStep, node);
            final Future<RpcResult<UpdateMetersBatchOutput>> resultUpdateMeterFuture = salMeterService.updateMetersBatch(updateMetersBatchInput);
            chainOutput = FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultUpdateMeterFuture, currentOffset);
            break;
        default:
            LOG.warn("Unsupported plan-step type occurred: {} -> OMITTING", planStep.getStepType());
            chainOutput = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
    }
    return chainOutput;
}
Also used : AddGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput) RemoveGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput) UpdateFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput) UpdateGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput) RemoveMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput) UpdateMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput) AddFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput) RemoveFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput)

Aggregations

ProcessFlatBatchOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput)15 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)12 Test (org.junit.Test)10 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 BatchFailure (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailure)5 Nonnull (javax.annotation.Nonnull)4 BatchStepJob (org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob)4 ProcessFlatBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput)4 ProcessFlatBatchInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInputBuilder)4 ProcessFlatBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutputBuilder)4 AddFlowsBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutputBuilder)4 Function (com.google.common.base.Function)3 InOrder (org.mockito.InOrder)3 BatchPlanStep (org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep)3 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)3 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)3 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)2 AddGroupsBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutputBuilder)2