use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput in project openflowplugin by opendaylight.
the class MeterForwarderTest method testUpdate.
@Test
public void testUpdate() throws Exception {
Mockito.when(salMeterService.updateMeter(updateMeterInputCpt.capture())).thenReturn(RpcResultBuilder.success(new UpdateMeterOutputBuilder().setTransactionId(txId).build()).buildFuture());
Meter meterOriginal = new MeterBuilder(meter).build();
Meter meterUpdate = new MeterBuilder(meter).setMeterName("another-test").build();
final Future<RpcResult<UpdateMeterOutput>> updateResult = meterForwarder.update(meterPath, meterOriginal, meterUpdate, flowCapableNodePath);
Mockito.verify(salMeterService).updateMeter(Matchers.<UpdateMeterInput>any());
Assert.assertTrue(updateResult.isDone());
final RpcResult<UpdateMeterOutput> meterResult = updateResult.get(2, TimeUnit.SECONDS);
Assert.assertTrue(meterResult.isSuccessful());
Assert.assertEquals(1, meterResult.getResult().getTransactionId().getValue().intValue());
final UpdateMeterInput updateMeterInput = updateMeterInputCpt.getValue();
Assert.assertEquals(meterPath, updateMeterInput.getMeterRef().getValue());
Assert.assertEquals(nodePath, updateMeterInput.getNode().getValue());
Assert.assertEquals("test-meter", updateMeterInput.getOriginalMeter().getMeterName());
Assert.assertEquals("another-test", updateMeterInput.getUpdatedMeter().getMeterName());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput in project openflowplugin by opendaylight.
the class MeterForwarder method update.
@Override
public void update(final InstanceIdentifier<Meter> identifier, final Meter original, final Meter update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
final UpdateMeterInputBuilder builder = new UpdateMeterInputBuilder();
builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
builder.setMeterRef(new MeterRef(identifier));
builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
builder.setUpdatedMeter(new UpdatedMeterBuilder(update).build());
builder.setOriginalMeter(new OriginalMeterBuilder(original).build());
final Future<RpcResult<UpdateMeterOutput>> resultFuture = this.provider.getSalMeterService().updateMeter(builder.build());
JdkFutures.addErrorLogging(resultFuture, LOG, "updateMeter");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput in project openflowplugin by opendaylight.
the class MeterForwarder method update.
@Override
public Future<RpcResult<UpdateMeterOutput>> update(final InstanceIdentifier<Meter> identifier, final Meter original, final Meter update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
LOG.trace("Received the Meter UPDATE request [Tbl id, node Id {} {} {}", identifier, nodeIdent, update);
final UpdateMeterInputBuilder builder = new UpdateMeterInputBuilder();
builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
builder.setMeterRef(new MeterRef(identifier));
builder.setUpdatedMeter(new UpdatedMeterBuilder(update).build());
builder.setOriginalMeter(new OriginalMeterBuilder(original).build());
return salMeterService.updateMeter(builder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput in project openflowplugin by opendaylight.
the class SalMetersBatchServiceImplTest method testUpdateMetersBatch_failure.
@Test
public void testUpdateMetersBatch_failure() throws Exception {
Mockito.when(salMeterService.updateMeter(Mockito.<UpdateMeterInput>any())).thenReturn(RpcResultBuilder.<UpdateMeterOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ur-groupUpdateError").buildFuture());
final UpdateMetersBatchInput input = new UpdateMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchUpdateMeters(Lists.newArrayList(createEmptyBatchUpdateMeter(42L), createEmptyBatchUpdateMeter(44L))).build();
final Future<RpcResult<UpdateMetersBatchOutput>> resultFuture = salMetersBatchService.updateMetersBatch(input);
Assert.assertTrue(resultFuture.isDone());
Assert.assertFalse(resultFuture.get().isSuccessful());
Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedMetersOutput().size());
Assert.assertEquals(43L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(0).getMeterId().getValue().longValue());
Assert.assertEquals(45L, 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)).updateMeter(updateMeterInputCpt.capture());
final List<UpdateMeterInput> allValues = updateMeterInputCpt.getAllValues();
Assert.assertEquals(2, allValues.size());
Assert.assertEquals(42, allValues.get(0).getOriginalMeter().getMeterId().getValue().longValue());
Assert.assertEquals(43, allValues.get(0).getUpdatedMeter().getMeterId().getValue().longValue());
Assert.assertEquals(44, allValues.get(1).getOriginalMeter().getMeterId().getValue().longValue());
Assert.assertEquals(45, allValues.get(1).getUpdatedMeter().getMeterId().getValue().longValue());
inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Aggregations