Search in sources :

Example 6 with AddMeterOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput in project openflowplugin by opendaylight.

the class SyncPlanPushStrategyIncrementalImpl method addMissingMeters.

ListenableFuture<RpcResult<Void>> addMissingMeters(final NodeId nodeId, final InstanceIdentifier<FlowCapableNode> nodeIdent, final ItemSyncBox<Meter> syncBox, final SyncCrudCounters counters) {
    if (syncBox.isEmpty()) {
        LOG.trace("no meters configured for node: {} -> SKIPPING", nodeId.getValue());
        return RpcResultBuilder.<Void>success().buildFuture();
    }
    final CrudCounts meterCrudCounts = counters.getMeterCrudCounts();
    final List<ListenableFuture<RpcResult<AddMeterOutput>>> allResults = new ArrayList<>();
    final List<ListenableFuture<RpcResult<UpdateMeterOutput>>> allUpdateResults = new ArrayList<>();
    for (Meter meter : syncBox.getItemsToPush()) {
        final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent = nodeIdent.child(Meter.class, meter.getKey());
        LOG.debug("adding meter {} - absent on device {}", meter.getMeterId(), nodeId);
        allResults.add(JdkFutureAdapters.listenInPoolThread(meterForwarder.add(meterIdent, meter, nodeIdent)));
        meterCrudCounts.incAdded();
    }
    for (ItemSyncBox.ItemUpdateTuple<Meter> meterTuple : syncBox.getItemsToUpdate()) {
        final Meter existingMeter = meterTuple.getOriginal();
        final Meter updated = meterTuple.getUpdated();
        final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent = nodeIdent.child(Meter.class, updated.getKey());
        LOG.trace("meter {} - needs update on device {}", updated.getMeterId(), nodeId);
        allUpdateResults.add(JdkFutureAdapters.listenInPoolThread(meterForwarder.update(meterIdent, existingMeter, updated, nodeIdent)));
        meterCrudCounts.incUpdated();
    }
    final ListenableFuture<RpcResult<Void>> singleVoidAddResult = Futures.transform(Futures.allAsList(allResults), ReconcileUtil.<AddMeterOutput>createRpcResultCondenser("meter add"), MoreExecutors.directExecutor());
    final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(Futures.allAsList(allUpdateResults), ReconcileUtil.<UpdateMeterOutput>createRpcResultCondenser("meter update"), MoreExecutors.directExecutor());
    return Futures.transform(Futures.allAsList(singleVoidUpdateResult, singleVoidAddResult), ReconcileUtil.<Void>createRpcResultCondenser("meter add/update"), MoreExecutors.directExecutor());
}
Also used : ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) UpdateMeterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput) Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) CrudCounts(org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts) MeterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey) AddMeterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 7 with AddMeterOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput 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 8 with AddMeterOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput 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)

Aggregations

AddMeterOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput)5 AddMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput)4 AddMeterInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)2 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)2 MeterRef (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef)2 InOrder (org.mockito.InOrder)1 CrudCounts (org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts)1 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)1 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)1 Meter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)1 MeterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey)1 AddMeterOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder)1 UpdateMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput)1 UpdateMeterInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder)1 UpdateMeterOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput)1