use of org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput in project openflowplugin by opendaylight.
the class SalFlowsBatchServiceImplTest method testRemoveFlowsBatch_failed.
@Test
public void testRemoveFlowsBatch_failed() throws Exception {
Mockito.when(salFlowService.removeFlow(Matchers.<RemoveFlowInput>any())).thenReturn(RpcResultBuilder.<RemoveFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, "flow-remove-fail-1").buildFuture());
final BatchRemoveFlows batchFlow1 = createEmptyBatchRemoveFlow(FLOW_ID_VALUE_1, 42);
final BatchRemoveFlows batchFlow2 = createEmptyBatchRemoveFlow(FLOW_ID_VALUE_2, 43);
final RemoveFlowsBatchInput input = new RemoveFlowsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchRemoveFlows(Lists.newArrayList(batchFlow1, batchFlow2)).build();
final Future<RpcResult<RemoveFlowsBatchOutput>> resultFuture = salFlowsBatchService.removeFlowsBatch(input);
Assert.assertTrue(resultFuture.isDone());
final RpcResult<RemoveFlowsBatchOutput> rpcResult = resultFuture.get();
Assert.assertFalse(rpcResult.isSuccessful());
final RemoveFlowsBatchOutput result = rpcResult.getResult();
Assert.assertEquals(2, result.getBatchFailedFlowsOutput().size());
Assert.assertEquals(FLOW_ID_VALUE_1, result.getBatchFailedFlowsOutput().get(0).getFlowId().getValue());
Assert.assertEquals(FLOW_ID_VALUE_2, result.getBatchFailedFlowsOutput().get(1).getFlowId().getValue());
final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService);
inOrder.verify(salFlowService, Mockito.times(2)).removeFlow(removeFlowInputCpt.capture());
final List<RemoveFlowInput> allValues = removeFlowInputCpt.getAllValues();
Assert.assertEquals(2, allValues.size());
Assert.assertEquals(42, allValues.get(0).getPriority().longValue());
Assert.assertEquals(43, allValues.get(1).getPriority().longValue());
inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput in project openflowplugin by opendaylight.
the class SalFlowsBatchServiceImplTest method testRemoveFlowsBatch_success.
@Test
public void testRemoveFlowsBatch_success() throws Exception {
Mockito.when(salFlowService.removeFlow(Matchers.<RemoveFlowInput>any())).thenReturn(RpcResultBuilder.success(new RemoveFlowOutputBuilder().build()).buildFuture());
final String flow1IdValue = "ut-dummy-flow1";
final String flow2IdValue = "ut-dummy-flow2";
final BatchRemoveFlows batchFlow1 = createEmptyBatchRemoveFlow(flow1IdValue, 42);
final BatchRemoveFlows batchFlow2 = createEmptyBatchRemoveFlow(flow2IdValue, 43);
final RemoveFlowsBatchInput input = new RemoveFlowsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchRemoveFlows(Lists.newArrayList(batchFlow1, batchFlow2)).build();
final Future<RpcResult<RemoveFlowsBatchOutput>> resultFuture = salFlowsBatchService.removeFlowsBatch(input);
Assert.assertTrue(resultFuture.isDone());
final RpcResult<RemoveFlowsBatchOutput> rpcResult = resultFuture.get();
Assert.assertTrue(rpcResult.isSuccessful());
final RemoveFlowsBatchOutput result = rpcResult.getResult();
Assert.assertEquals(0, result.getBatchFailedFlowsOutput().size());
final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService);
inOrder.verify(salFlowService, Mockito.times(2)).removeFlow(removeFlowInputCpt.capture());
final List<RemoveFlowInput> allValues = removeFlowInputCpt.getAllValues();
Assert.assertEquals(2, allValues.size());
Assert.assertEquals(42, allValues.get(0).getPriority().longValue());
Assert.assertEquals(43, allValues.get(1).getPriority().longValue());
inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput in project openflowplugin by opendaylight.
the class SalFlowsBatchServiceImpl method removeFlowsBatch.
@Override
public Future<RpcResult<RemoveFlowsBatchOutput>> removeFlowsBatch(final RemoveFlowsBatchInput input) {
LOG.trace("Removing flows @ {} : {}", PathUtil.extractNodeId(input.getNode()), input.getBatchRemoveFlows().size());
final ArrayList<ListenableFuture<RpcResult<RemoveFlowOutput>>> resultsLot = new ArrayList<>();
for (BatchFlowInputGrouping batchFlow : input.getBatchRemoveFlows()) {
final RemoveFlowInput removeFlowInput = new RemoveFlowInputBuilder(batchFlow).setFlowRef(createFlowRef(input.getNode(), batchFlow)).setNode(input.getNode()).build();
resultsLot.add(JdkFutureAdapters.listenInPoolThread(salFlowService.removeFlow(removeFlowInput)));
}
final ListenableFuture<RpcResult<List<BatchFailedFlowsOutput>>> commonResult = Futures.transform(Futures.successfulAsList(resultsLot), FlowUtil.<RemoveFlowOutput>createCumulatingFunction(input.getBatchRemoveFlows()), MoreExecutors.directExecutor());
ListenableFuture<RpcResult<RemoveFlowsBatchOutput>> removeFlowsBulkFuture = Futures.transform(commonResult, FlowUtil.FLOW_REMOVE_TRANSFORM, MoreExecutors.directExecutor());
if (input.isBarrierAfter()) {
removeFlowsBulkFuture = BarrierUtil.chainBarrier(removeFlowsBulkFuture, input.getNode(), transactionService, FlowUtil.FLOW_REMOVE_COMPOSING_TRANSFORM);
}
return removeFlowsBulkFuture;
}
Aggregations