Search in sources :

Example 1 with AddMetersBatchOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput in project openflowplugin by opendaylight.

the class SalMetersBatchServiceImplTest method testAddMetersBatch_failure.

@Test
public void testAddMetersBatch_failure() throws Exception {
    Mockito.when(salMeterService.addMeter(Mockito.<AddMeterInput>any())).thenReturn(RpcResultBuilder.<AddMeterOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ut-groupAddError").buildFuture());
    final AddMetersBatchInput input = new AddMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchAddMeters(Lists.newArrayList(createEmptyBatchAddMeter(42L), createEmptyBatchAddMeter(43L))).build();
    final Future<RpcResult<AddMetersBatchOutput>> resultFuture = salMetersBatchService.addMetersBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertFalse(resultFuture.get().isSuccessful());
    Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedMetersOutput().size());
    Assert.assertEquals(42L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(0).getMeterId().getValue().longValue());
    Assert.assertEquals(43L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(1).getMeterId().getValue().longValue());
    Assert.assertEquals(2, resultFuture.get().getErrors().size());
    final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
    inOrder.verify(salMeterService, Mockito.times(2)).addMeter(addMeterInputCpt.capture());
    final List<AddMeterInput> allValues = addMeterInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue());
    Assert.assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : InOrder(org.mockito.InOrder) AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput) AddMetersBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInputBuilder) Test(org.junit.Test)

Example 2 with AddMetersBatchOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput in project openflowplugin by opendaylight.

the class SalMetersBatchServiceImpl method addMetersBatch.

@Override
public Future<RpcResult<AddMetersBatchOutput>> addMetersBatch(final AddMetersBatchInput input) {
    LOG.trace("Adding meters @ {} : {}", PathUtil.extractNodeId(input.getNode()), input.getBatchAddMeters().size());
    final ArrayList<ListenableFuture<RpcResult<AddMeterOutput>>> resultsLot = new ArrayList<>();
    for (BatchAddMeters addMeter : input.getBatchAddMeters()) {
        final AddMeterInput addMeterInput = new AddMeterInputBuilder(addMeter).setMeterRef(createMeterRef(input.getNode(), addMeter)).setNode(input.getNode()).build();
        resultsLot.add(JdkFutureAdapters.listenInPoolThread(salMeterService.addMeter(addMeterInput)));
    }
    final ListenableFuture<RpcResult<List<BatchFailedMetersOutput>>> commonResult = Futures.transform(Futures.allAsList(resultsLot), MeterUtil.<AddMeterOutput>createCumulativeFunction(input.getBatchAddMeters()), MoreExecutors.directExecutor());
    ListenableFuture<RpcResult<AddMetersBatchOutput>> addMetersBulkFuture = Futures.transform(commonResult, MeterUtil.METER_ADD_TRANSFORM, MoreExecutors.directExecutor());
    if (input.isBarrierAfter()) {
        addMetersBulkFuture = BarrierUtil.chainBarrier(addMetersBulkFuture, input.getNode(), transactionService, MeterUtil.METER_ADD_COMPOSING_TRANSFORM);
    }
    return addMetersBulkFuture;
}
Also used : AddMeterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput) AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) ArrayList(java.util.ArrayList) BatchAddMeters(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.add.meters.batch.input.BatchAddMeters) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AddMeterInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder) BatchFailedMetersOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.output.list.grouping.BatchFailedMetersOutput)

Example 3 with AddMetersBatchOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput in project openflowplugin by opendaylight.

the class SalMetersBatchServiceImplTest method testAddMetersBatch_success.

@Test
public void testAddMetersBatch_success() throws Exception {
    Mockito.when(salMeterService.addMeter(Mockito.<AddMeterInput>any())).thenReturn(RpcResultBuilder.success(new AddMeterOutputBuilder().build()).buildFuture());
    final AddMetersBatchInput input = new AddMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchAddMeters(Lists.newArrayList(createEmptyBatchAddMeter(42L), createEmptyBatchAddMeter(43L))).build();
    final Future<RpcResult<AddMetersBatchOutput>> resultFuture = salMetersBatchService.addMetersBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertTrue(resultFuture.get().isSuccessful());
    final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
    inOrder.verify(salMeterService, Mockito.times(2)).addMeter(addMeterInputCpt.capture());
    final List<AddMeterInput> allValues = addMeterInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue());
    Assert.assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : InOrder(org.mockito.InOrder) AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput) AddMetersBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInputBuilder) AddMeterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder) Test(org.junit.Test)

Example 4 with AddMetersBatchOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput 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

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 AddMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput)3 AddMetersBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput)3 Test (org.junit.Test)2 InOrder (org.mockito.InOrder)2 AddMetersBatchInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInputBuilder)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1 AddFlowsBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput)1 RemoveFlowsBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput)1 UpdateFlowsBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput)1 AddGroupsBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput)1 RemoveGroupsBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput)1 UpdateGroupsBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput)1 AddMeterInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder)1 AddMeterOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput)1 AddMeterOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder)1 RemoveMetersBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput)1 UpdateMetersBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput)1 BatchAddMeters (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.add.meters.batch.input.BatchAddMeters)1