Search in sources :

Example 1 with ProcessFlatBatchOutput

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

the class FlatBatchFlowAdaptersTest method testCreateBatchFlowChainingFunction_successes.

@Test
public void testCreateBatchFlowChainingFunction_successes() throws Exception {
    final RpcResult<BatchFlowOutputListGrouping> input = RpcResultBuilder.<BatchFlowOutputListGrouping>success(new AddFlowsBatchOutputBuilder().build()).build();
    final RpcResult<ProcessFlatBatchOutput> rpcResult = FlatBatchFlowAdapters.convertBatchFlowResult(0).apply(input);
    Assert.assertTrue(rpcResult.isSuccessful());
    Assert.assertEquals(0, rpcResult.getErrors().size());
    Assert.assertEquals(0, rpcResult.getResult().getBatchFailure().size());
}
Also used : BatchFlowOutputListGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.BatchFlowOutputListGrouping) AddFlowsBatchOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutputBuilder) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) Test(org.junit.Test)

Example 2 with ProcessFlatBatchOutput

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

the class FlatBatchMeterAdaptersTest method testCreateBatchMeterChainingFunction_successes.

@Test
public void testCreateBatchMeterChainingFunction_successes() throws Exception {
    final RpcResult<BatchMeterOutputListGrouping> input = RpcResultBuilder.<BatchMeterOutputListGrouping>success(new AddMetersBatchOutputBuilder().build()).build();
    final RpcResult<ProcessFlatBatchOutput> rpcResult = FlatBatchMeterAdapters.convertBatchMeterResult(0).apply(input);
    Assert.assertTrue(rpcResult.isSuccessful());
    Assert.assertEquals(0, rpcResult.getErrors().size());
    Assert.assertEquals(0, rpcResult.getResult().getBatchFailure().size());
}
Also used : BatchMeterOutputListGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.BatchMeterOutputListGrouping) AddMetersBatchOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutputBuilder) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) Test(org.junit.Test)

Example 3 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 testProcessFlatBatch_firstFailedInterrupted.

@Test
public void testProcessFlatBatch_firstFailedInterrupted() throws Exception {
    prepareFirstFailingMockService();
    int idx = 0;
    ProcessFlatBatchInput batchInput = new ProcessFlatBatchInputBuilder().setNode(NODE_REF).setBatch(Lists.newArrayList(createFlowAddBatch(idx++, "f1", 2), createFlowRemoveBatch(idx++, "f2"), createFlowUpdateBatch(idx++, "f3"), createGroupAddBatch(idx++, 1L), createGroupRemoveBatch(idx++, 2L), createGroupUpdateBatch(idx++, 3L), createMeterAddBatch(idx++, 1L), createMeterRemoveBatch(idx++, 2L), createMeterUpdateBatch(idx++, 3L))).setExitOnFirstError(true).build();
    final Future<RpcResult<ProcessFlatBatchOutput>> rpcResultFuture = salFlatBatchService.processFlatBatch(batchInput);
    Assert.assertTrue(rpcResultFuture.isDone());
    final RpcResult<ProcessFlatBatchOutput> rpcResult = rpcResultFuture.get();
    Assert.assertFalse(rpcResult.isSuccessful());
    Assert.assertEquals(1, rpcResult.getErrors().size());
    Assert.assertEquals(1, rpcResult.getResult().getBatchFailure().size());
    Assert.assertEquals(3, rpcResult.getResult().getBatchFailure().get(0).getBatchOrder().intValue());
    final InOrder inOrder = Mockito.inOrder(salFlowsBatchService, salGroupsBatchService, salMetersBatchService);
    inOrder.verify(salFlowsBatchService).addFlowsBatch(Matchers.<AddFlowsBatchInput>any());
    inOrder.verify(salFlowsBatchService).removeFlowsBatch(Matchers.<RemoveFlowsBatchInput>any());
    inOrder.verify(salFlowsBatchService).updateFlowsBatch(Matchers.<UpdateFlowsBatchInput>any());
    inOrder.verify(salGroupsBatchService).addGroupsBatch(Matchers.<AddGroupsBatchInput>any());
}
Also used : InOrder(org.mockito.InOrder) ProcessFlatBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInputBuilder) ProcessFlatBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) Test(org.junit.Test)

Example 4 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 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 5 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 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)

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