Search in sources :

Example 6 with UpdateGroupsBatchInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput in project openflowplugin by opendaylight.

the class SalGroupsBatchServiceImplTest method testUpdateGroupsBatch_success.

@Test
public void testUpdateGroupsBatch_success() throws Exception {
    Mockito.when(salGroupService.updateGroup(Mockito.<UpdateGroupInput>any())).thenReturn(RpcResultBuilder.success(new UpdateGroupOutputBuilder().build()).buildFuture());
    final UpdateGroupsBatchInput input = new UpdateGroupsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchUpdateGroups(Lists.newArrayList(createEmptyBatchUpdateGroup(42L), createEmptyBatchUpdateGroup(44L))).build();
    final Future<RpcResult<UpdateGroupsBatchOutput>> resultFuture = salGroupsBatchService.updateGroupsBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertTrue(resultFuture.get().isSuccessful());
    final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService);
    inOrder.verify(salGroupService, Mockito.times(2)).updateGroup(updateGroupInputCpt.capture());
    final List<UpdateGroupInput> allValues = updateGroupInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42, allValues.get(0).getOriginalGroup().getGroupId().getValue().longValue());
    Assert.assertEquals(43, allValues.get(0).getUpdatedGroup().getGroupId().getValue().longValue());
    Assert.assertEquals(44, allValues.get(1).getOriginalGroup().getGroupId().getValue().longValue());
    Assert.assertEquals(45, allValues.get(1).getUpdatedGroup().getGroupId().getValue().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : UpdateGroupsBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInputBuilder) InOrder(org.mockito.InOrder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdateGroupOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder) UpdateGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput) UpdateGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput) Test(org.junit.Test)

Example 7 with UpdateGroupsBatchInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput in project openflowplugin by opendaylight.

the class SalGroupsBatchServiceImplTest method testUpdateGroupsBatch_failure.

@Test
public void testUpdateGroupsBatch_failure() throws Exception {
    Mockito.when(salGroupService.updateGroup(Mockito.<UpdateGroupInput>any())).thenReturn(RpcResultBuilder.<UpdateGroupOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ur-groupUpdateError").buildFuture());
    final UpdateGroupsBatchInput input = new UpdateGroupsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchUpdateGroups(Lists.newArrayList(createEmptyBatchUpdateGroup(42L), createEmptyBatchUpdateGroup(44L))).build();
    final Future<RpcResult<UpdateGroupsBatchOutput>> resultFuture = salGroupsBatchService.updateGroupsBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertFalse(resultFuture.get().isSuccessful());
    Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedGroupsOutput().size());
    Assert.assertEquals(43L, resultFuture.get().getResult().getBatchFailedGroupsOutput().get(0).getGroupId().getValue().longValue());
    Assert.assertEquals(45L, resultFuture.get().getResult().getBatchFailedGroupsOutput().get(1).getGroupId().getValue().longValue());
    Assert.assertEquals(2, resultFuture.get().getErrors().size());
    final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService);
    inOrder.verify(salGroupService, Mockito.times(2)).updateGroup(updateGroupInputCpt.capture());
    final List<UpdateGroupInput> allValues = updateGroupInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42, allValues.get(0).getOriginalGroup().getGroupId().getValue().longValue());
    Assert.assertEquals(43, allValues.get(0).getUpdatedGroup().getGroupId().getValue().longValue());
    Assert.assertEquals(44, allValues.get(1).getOriginalGroup().getGroupId().getValue().longValue());
    Assert.assertEquals(45, allValues.get(1).getUpdatedGroup().getGroupId().getValue().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : UpdateGroupsBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInputBuilder) InOrder(org.mockito.InOrder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdateGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput) UpdateGroupInput(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput) Test(org.junit.Test)

Example 8 with UpdateGroupsBatchInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput in project openflowplugin by opendaylight.

the class FlatBatchGroupAdaptersTest method testAdaptFlatBatchUpdateGroup.

@Test
public void testAdaptFlatBatchUpdateGroup() throws Exception {
    final BatchPlanStep planStep = new BatchPlanStep(BatchStepType.FLOW_UPDATE);
    planStep.setBarrierAfter(true);
    planStep.getTaskBag().addAll(Lists.newArrayList(createUpdateGroupBatch(1L), createUpdateGroupBatch(2L)));
    final UpdateGroupsBatchInput updateGroupsBatchInput = FlatBatchGroupAdapters.adaptFlatBatchUpdateGroup(planStep, NODE_REF);
    Assert.assertTrue(updateGroupsBatchInput.isBarrierAfter());
    Assert.assertEquals(2, updateGroupsBatchInput.getBatchUpdateGroups().size());
    Assert.assertEquals(1L, updateGroupsBatchInput.getBatchUpdateGroups().get(0).getUpdatedBatchedGroup().getGroupId().getValue().longValue());
    Assert.assertEquals(2L, updateGroupsBatchInput.getBatchUpdateGroups().get(1).getUpdatedBatchedGroup().getGroupId().getValue().longValue());
}
Also used : UpdateGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput) Test(org.junit.Test)

Example 9 with UpdateGroupsBatchInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput 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)6 Test (org.junit.Test)5 InOrder (org.mockito.InOrder)4 UpdateGroupsBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput)4 UpdateGroupInput (org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput)3 UpdateGroupsBatchInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInputBuilder)3 ArrayList (java.util.ArrayList)2 ProcessFlatBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput)2 ProcessFlatBatchInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInputBuilder)2 ProcessFlatBatchOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput)2 AddFlowsBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutputBuilder)2 RemoveFlowsBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutputBuilder)2 UpdateFlowsBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchOutputBuilder)2 AddGroupsBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutputBuilder)2 RemoveGroupsBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutputBuilder)2 UpdateGroupsBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchOutputBuilder)2 BatchUpdateGroups (org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.update.groups.batch.input.BatchUpdateGroups)2 AddMetersBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutputBuilder)2 RemoveMetersBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchOutputBuilder)2 UpdateMetersBatchOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchOutputBuilder)2