Search in sources :

Example 51 with Counters

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();
}
Also used : CountersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.CountersBuilder) BigInteger(java.math.BigInteger)

Example 52 with Counters

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();
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) GetElementCountersByHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutput) GetElementCountersByHandlerOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutputBuilder) Optional(java.util.Optional) CounterRequestsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey) ArrayList(java.util.ArrayList) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests) CounterResult(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) ExecutionException(java.util.concurrent.ExecutionException)

Example 53 with Counters

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);
}
Also used : ExternalCountersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey) ExternalIpCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter) ExternalIpCounterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterKey) ExternalIpsCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter)

Example 54 with Counters

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;
}
Also used : ExternalIpCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter) ExternalIpsCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter) ExecutionException(java.util.concurrent.ExecutionException) ExternalCounters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCounters)

Example 55 with Counters

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());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) Cars(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars) Stopwatch(com.google.common.base.Stopwatch) StopStressTestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StopStressTestOutputBuilder) StressTestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StressTestOutputBuilder) CarEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.cars.CarEntry) AtomicLong(java.util.concurrent.atomic.AtomicLong) CarId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarId) CarsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarsBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) ExecutionException(java.util.concurrent.ExecutionException) CarEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.cars.CarEntryBuilder) FutureCallback(com.google.common.util.concurrent.FutureCallback) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)23 ArrayList (java.util.ArrayList)17 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)17 ExecutionException (java.util.concurrent.ExecutionException)13 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)12 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)11 Test (org.junit.Test)11 Meter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)11 Map (java.util.Map)10 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)10 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)10 InOrder (org.mockito.InOrder)9 BigInteger (java.math.BigInteger)8 List (java.util.List)8 CrudCounts (org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts)8 SyncCrudCounters (org.opendaylight.openflowplugin.applications.frsync.util.SyncCrudCounters)8 Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)8 Futures (com.google.common.util.concurrent.Futures)7 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)7 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)6