use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput in project openflowplugin by opendaylight.
the class FlatBatchMeterAdaptersTest method testAdaptFlatBatchRemoveMeter.
@Test
public void testAdaptFlatBatchRemoveMeter() throws Exception {
final BatchPlanStep planStep = new BatchPlanStep(BatchStepType.FLOW_REMOVE);
planStep.setBarrierAfter(true);
planStep.getTaskBag().addAll(Lists.newArrayList(createRemoveMeterBatch(1L), createRemoveMeterBatch(2L)));
final RemoveMetersBatchInput removeMetersBatchInput = FlatBatchMeterAdapters.adaptFlatBatchRemoveMeter(planStep, NODE_REF);
Assert.assertTrue(removeMetersBatchInput.isBarrierAfter());
Assert.assertEquals(2, removeMetersBatchInput.getBatchRemoveMeters().size());
Assert.assertEquals(1L, removeMetersBatchInput.getBatchRemoveMeters().get(0).getMeterId().getValue().longValue());
Assert.assertEquals(2L, removeMetersBatchInput.getBatchRemoveMeters().get(1).getMeterId().getValue().longValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput in project openflowplugin by opendaylight.
the class SalMetersBatchServiceImplTest method testRemoveMetersBatch_success.
@Test
public void testRemoveMetersBatch_success() throws Exception {
Mockito.when(salMeterService.removeMeter(Mockito.<RemoveMeterInput>any())).thenReturn(RpcResultBuilder.success(new RemoveMeterOutputBuilder().build()).buildFuture());
final RemoveMetersBatchInput input = new RemoveMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchRemoveMeters(Lists.newArrayList(createEmptyBatchRemoveMeter(42L), createEmptyBatchRemoveMeter(43L))).build();
final Future<RpcResult<RemoveMetersBatchOutput>> resultFuture = salMetersBatchService.removeMetersBatch(input);
Assert.assertTrue(resultFuture.isDone());
Assert.assertTrue(resultFuture.get().isSuccessful());
final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
inOrder.verify(salMeterService, Mockito.times(2)).removeMeter(removeMeterInputCpt.capture());
final List<RemoveMeterInput> allValues = removeMeterInputCpt.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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput in project openflowplugin by opendaylight.
the class SalMetersBatchServiceImpl method removeMetersBatch.
@Override
public Future<RpcResult<RemoveMetersBatchOutput>> removeMetersBatch(final RemoveMetersBatchInput input) {
LOG.trace("Removing meters @ {} : {}", PathUtil.extractNodeId(input.getNode()), input.getBatchRemoveMeters().size());
final ArrayList<ListenableFuture<RpcResult<RemoveMeterOutput>>> resultsLot = new ArrayList<>();
for (BatchRemoveMeters addMeter : input.getBatchRemoveMeters()) {
final RemoveMeterInput removeMeterInput = new RemoveMeterInputBuilder(addMeter).setMeterRef(createMeterRef(input.getNode(), addMeter)).setNode(input.getNode()).build();
resultsLot.add(JdkFutureAdapters.listenInPoolThread(salMeterService.removeMeter(removeMeterInput)));
}
final ListenableFuture<RpcResult<List<BatchFailedMetersOutput>>> commonResult = Futures.transform(Futures.allAsList(resultsLot), MeterUtil.<RemoveMeterOutput>createCumulativeFunction(input.getBatchRemoveMeters()), MoreExecutors.directExecutor());
ListenableFuture<RpcResult<RemoveMetersBatchOutput>> removeMetersBulkFuture = Futures.transform(commonResult, MeterUtil.METER_REMOVE_TRANSFORM, MoreExecutors.directExecutor());
if (input.isBarrierAfter()) {
removeMetersBulkFuture = BarrierUtil.chainBarrier(removeMetersBulkFuture, input.getNode(), transactionService, MeterUtil.METER_REMOVE_COMPOSING_TRANSFORM);
}
return removeMetersBulkFuture;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput in project openflowplugin by opendaylight.
the class FlatBatchMeterAdapters method adaptFlatBatchRemoveMeter.
/**
* Adapt flat batch remove meter.
* @param planStep batch step containing changes of the same type
* @param node pointer for RPC routing
* @return input suitable for {@link org.opendaylight.yang.gen.v1.urn
* .opendaylight.meters.service.rev160316.SalMetersBatchService#removeMetersBatch(RemoveMetersBatchInput)}
*/
public static RemoveMetersBatchInput adaptFlatBatchRemoveMeter(final BatchPlanStep planStep, final NodeRef node) {
final List<BatchRemoveMeters> batchMeters = new ArrayList<>();
for (FlatBatchRemoveMeter batchRemoveMeter : planStep.<FlatBatchRemoveMeter>getTaskBag()) {
final BatchRemoveMeters removeMeters = new BatchRemoveMetersBuilder(batchRemoveMeter).setMeterId(batchRemoveMeter.getMeterId()).build();
batchMeters.add(removeMeters);
}
return new RemoveMetersBatchInputBuilder().setBarrierAfter(planStep.isBarrierAfter()).setNode(node).setBatchRemoveMeters(batchMeters).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput in project openflowplugin by opendaylight.
the class SalFlatBatchServiceImplTest method prepareFirstFailingMockService.
private void prepareFirstFailingMockService() {
Mockito.when(salFlowsBatchService.addFlowsBatch(Matchers.<AddFlowsBatchInput>any())).thenReturn(RpcResultBuilder.success(new AddFlowsBatchOutputBuilder().build()).buildFuture());
Mockito.when(salFlowsBatchService.removeFlowsBatch(Matchers.<RemoveFlowsBatchInput>any())).thenReturn(RpcResultBuilder.<RemoveFlowsBatchOutput>failed().withResult(new RemoveFlowsBatchOutputBuilder().setBatchFailedFlowsOutput(Lists.newArrayList(new BatchFailedFlowsOutputBuilder().setBatchOrder(1).setFlowId(new FlowId("123")).build())).build()).withError(RpcError.ErrorType.APPLICATION, "ut-firstFlowAddError").buildFuture());
Mockito.when(salFlowsBatchService.updateFlowsBatch(Matchers.<UpdateFlowsBatchInput>any())).thenReturn(RpcResultBuilder.success(new UpdateFlowsBatchOutputBuilder().build()).buildFuture());
Mockito.when(salGroupsBatchService.addGroupsBatch(Matchers.<AddGroupsBatchInput>any())).thenReturn(RpcResultBuilder.success(new AddGroupsBatchOutputBuilder().build()).buildFuture());
Mockito.when(salGroupsBatchService.removeGroupsBatch(Matchers.<RemoveGroupsBatchInput>any())).thenReturn(RpcResultBuilder.success(new RemoveGroupsBatchOutputBuilder().build()).buildFuture());
Mockito.when(salGroupsBatchService.updateGroupsBatch(Matchers.<UpdateGroupsBatchInput>any())).thenReturn(RpcResultBuilder.success(new UpdateGroupsBatchOutputBuilder().build()).buildFuture());
Mockito.when(salMetersBatchService.addMetersBatch(Matchers.<AddMetersBatchInput>any())).thenReturn(RpcResultBuilder.success(new AddMetersBatchOutputBuilder().build()).buildFuture());
Mockito.when(salMetersBatchService.removeMetersBatch(Matchers.<RemoveMetersBatchInput>any())).thenReturn(RpcResultBuilder.success(new RemoveMetersBatchOutputBuilder().build()).buildFuture());
Mockito.when(salMetersBatchService.updateMetersBatch(Matchers.<UpdateMetersBatchInput>any())).thenReturn(RpcResultBuilder.success(new UpdateMetersBatchOutputBuilder().build()).buildFuture());
}
Aggregations