use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project netvirt by opendaylight.
the class StatisticsImpl method buildCounter.
private Counters buildCounter(String counterName, BigInteger value, Counters prevCounter) {
BigInteger prevValue = BigInteger.ZERO;
if (prevCounter != null) {
prevValue = prevCounter.getValue();
}
CountersBuilder cb = new CountersBuilder();
cb.setName(counterName);
cb.setValue(value.add(prevValue));
return cb.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project netvirt by opendaylight.
the class StatisticsImpl method getElementCountersByHandler.
@Override
public ListenableFuture<RpcResult<GetElementCountersByHandlerOutput>> getElementCountersByHandler(GetElementCountersByHandlerInput input) {
InstanceIdentifier<CounterRequests> ingressPath = InstanceIdentifier.builder(IngressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
InstanceIdentifier<CounterRequests> egressPath = InstanceIdentifier.builder(EgressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
ReadTransaction tx = db.newReadOnlyTransaction();
CheckedFuture<Optional<CounterRequests>, ReadFailedException> ingressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, ingressPath);
CheckedFuture<Optional<CounterRequests>, ReadFailedException> egressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, egressPath);
List<CounterResult> counters = new ArrayList<>();
try {
if (!ingressRequestData.get().isPresent() && !egressRequestData.get().isPresent()) {
LOG.warn("Handler does not exists");
return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "Handler does not exists").buildFuture();
}
if (ingressRequestData.get().isPresent()) {
CounterRequests ingressCounterRequest = ingressRequestData.get().get();
CounterResultDataStructure ingressCounterResultDS = createElementCountersResult(ingressCounterRequest);
if (ingressCounterResultDS == null) {
LOG.warn("Unable to get counter results");
statisticsCounters.failedGettingCounterResults();
return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "Unable to get counter results").buildFuture();
}
createCounterResults(counters, ingressCounterResultDS, CountersServiceUtils.INGRESS_COUNTER_RESULT_ID);
}
if (egressRequestData.get().isPresent()) {
CounterRequests egressCounterRequest = egressRequestData.get().get();
CounterResultDataStructure egressCounterResultDS = createElementCountersResult(egressCounterRequest);
if (egressCounterResultDS == null) {
LOG.warn("Unable to get counter results");
statisticsCounters.failedGettingCounterResults();
return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "Unable to get counter results").buildFuture();
}
createCounterResults(counters, egressCounterResultDS, CountersServiceUtils.EGRESS_COUNTER_RESULT_ID);
}
} catch (InterruptedException | ExecutionException e) {
LOG.warn("failed to get counter request data from DB");
return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
} finally {
tx.close();
}
GetElementCountersByHandlerOutputBuilder gecbhob = new GetElementCountersByHandlerOutputBuilder();
gecbhob.setCounterResult(counters);
return RpcResultBuilder.success(gecbhob.build()).buildFuture();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project netvirt by opendaylight.
the class NaptManager method removeExternalIpCounter.
protected void removeExternalIpCounter(Uint32 routerId, String externalIp) {
// Remove from external-counters model
InstanceIdentifier<ExternalIpCounter> id = InstanceIdentifier.builder(ExternalIpsCounter.class).child(ExternalCounters.class, new ExternalCountersKey(routerId)).child(ExternalIpCounter.class, new ExternalIpCounterKey(externalIp)).build();
LOG.debug("removeExternalIpCounter : Removing ExternalIpsCounter from datastore");
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project netvirt by opendaylight.
the class ExternalRoutersListener method isExternalIpAllocated.
private boolean isExternalIpAllocated(String externalIp) {
InstanceIdentifier<ExternalIpsCounter> id = InstanceIdentifier.builder(ExternalIpsCounter.class).build();
Optional<ExternalIpsCounter> externalCountersData;
try {
externalCountersData = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
} catch (InterruptedException | ExecutionException e) {
LOG.error("Failed to read external counters data for ExternalIp {}", externalIp, e);
externalCountersData = Optional.empty();
}
if (externalCountersData.isPresent()) {
ExternalIpsCounter externalIpsCounters = externalCountersData.get();
for (ExternalCounters ext : externalIpsCounters.nonnullExternalCounters().values()) {
for (ExternalIpCounter externalIpCount : ext.nonnullExternalIpCounter().values()) {
if (externalIpCount.getExternalIp().equals(externalIp)) {
if (externalIpCount.getCounter().toJava() != 0) {
return true;
}
break;
}
}
}
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project controller by opendaylight.
the class CarProvider method stressTest.
@Override
public ListenableFuture<RpcResult<StressTestOutput>> stressTest(final StressTestInput input) {
final int inputRate;
final long inputCount;
// If rate is not provided, or given as zero, then just return.
if (input.getRate() == null || input.getRate().toJava() == 0) {
LOG_PURCHASE_CAR.info("Exiting stress test as no rate is given.");
return Futures.immediateFuture(RpcResultBuilder.<StressTestOutput>failed().withError(ErrorType.PROTOCOL, "invalid rate").build());
}
inputRate = input.getRate().toJava();
if (input.getCount() != null) {
inputCount = input.getCount().toJava();
} else {
inputCount = 0;
}
LOG_PURCHASE_CAR.info("Stress test starting : rate: {} count: {}", inputRate, inputCount);
stopThread();
// clear counters
succcessCounter.set(0);
failureCounter.set(0);
WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
InstanceIdentifier<Cars> carsId = InstanceIdentifier.create(Cars.class);
tx.merge(LogicalDatastoreType.CONFIGURATION, carsId, new CarsBuilder().build());
try {
tx.commit().get(5, TimeUnit.SECONDS);
} catch (TimeoutException | InterruptedException | ExecutionException e) {
LOG_PURCHASE_CAR.error("Put Cars failed", e);
return Futures.immediateFuture(RpcResultBuilder.success(new StressTestOutputBuilder().build()).build());
}
stopThread = false;
final long sleep = TimeUnit.NANOSECONDS.convert(1000, TimeUnit.MILLISECONDS) / inputRate;
final Stopwatch sw = Stopwatch.createUnstarted();
testThread = new Thread(() -> {
sw.start();
AtomicLong count = new AtomicLong();
while (!stopThread) {
long id = count.incrementAndGet();
WriteTransaction tx1 = dataProvider.newWriteOnlyTransaction();
CarEntry car = new CarEntryBuilder().setId(new CarId("car" + id)).build();
tx1.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.<Cars>builder(Cars.class).child(CarEntry.class, car.key()).build(), car);
tx1.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
// Transaction succeeded
succcessCounter.getAndIncrement();
}
@Override
public void onFailure(final Throwable ex) {
// Transaction failed
failureCounter.getAndIncrement();
LOG_CAR_PROVIDER.error("Put Cars failed", ex);
}
}, MoreExecutors.directExecutor());
try {
TimeUnit.NANOSECONDS.sleep(sleep);
} catch (InterruptedException e) {
break;
}
if (count.get() % 1000 == 0) {
LOG_PURCHASE_CAR.info("Cars created {}, time: {}", count.get(), sw.elapsed(TimeUnit.SECONDS));
}
// Check if a count is specified in input and we have created that many cars.
if (inputCount != 0 && count.get() >= inputCount) {
stopThread = true;
}
}
LOG_PURCHASE_CAR.info("Stress test thread stopping after creating {} cars.", count.get());
});
testThread.start();
return Futures.immediateFuture(RpcResultBuilder.success(new StressTestOutputBuilder().build()).build());
}
Aggregations