Search in sources :

Example 6 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class StatisticsImpl method getNodeConnectorCounters.

@Override
@SuppressWarnings("checkstyle:illegalCatch")
public ListenableFuture<RpcResult<GetNodeConnectorCountersOutput>> getNodeConnectorCounters(GetNodeConnectorCountersInput input) {
    String portId = input.getPortId();
    LOG.trace("getting port counters of port {}", portId);
    Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(db, portId);
    if (interfaceState == null) {
        LOG.warn("trying to get counters for non exist port {}", portId);
        return RpcResultBuilder.<GetNodeConnectorCountersOutput>failed().buildFuture();
    }
    BigInteger dpId = InterfaceUtils.getDpIdFromInterface(interfaceState);
    if (interfaceState.getLowerLayerIf() == null || interfaceState.getLowerLayerIf().isEmpty()) {
        LOG.warn("Lower layer if wasn't found for port {}", portId);
        return RpcResultBuilder.<GetNodeConnectorCountersOutput>failed().buildFuture();
    }
    String portNumber = interfaceState.getLowerLayerIf().get(0);
    portNumber = portNumber.split(":")[2];
    List<CounterResult> counterResults = new ArrayList<>();
    try {
        if (!getNodeConnectorResult(counterResults, dpId, portNumber)) {
            statisticsCounters.failedGettingNodeConnectorCounters();
            return RpcResultBuilder.<GetNodeConnectorCountersOutput>failed().withError(ErrorType.APPLICATION, "failed to get port counters").buildFuture();
        }
    } catch (RuntimeException e) {
        LOG.warn("failed to get counter result for port {}", portId, e);
    }
    GetNodeConnectorCountersOutputBuilder gpcob = new GetNodeConnectorCountersOutputBuilder();
    gpcob.setCounterResult(counterResults);
    return RpcResultBuilder.success(gpcob.build()).buildFuture();
}
Also used : ArrayList(java.util.ArrayList) GetNodeConnectorCountersOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeConnectorCountersOutput) BigInteger(java.math.BigInteger) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) CounterResult(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult) GetNodeConnectorCountersOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeConnectorCountersOutputBuilder)

Example 7 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class StatisticsImpl method getNodeCounters.

@Override
@SuppressWarnings("checkstyle:illegalCatch")
public ListenableFuture<RpcResult<GetNodeCountersOutput>> getNodeCounters(GetNodeCountersInput input) {
    BigInteger dpId = input.getNodeId();
    LOG.trace("getting node counters for node {}", dpId);
    GetNodeCountersOutputBuilder gncob = new GetNodeCountersOutputBuilder();
    List<CounterResult> counterResults = new ArrayList<>();
    try {
        if (!getNodeResult(counterResults, dpId)) {
            statisticsCounters.failedGettingNodeCounters();
            return RpcResultBuilder.<GetNodeCountersOutput>failed().withError(ErrorType.APPLICATION, "failed to get node counters for node: " + dpId).buildFuture();
        }
    } catch (RuntimeException e) {
        LOG.warn("failed to get counter result for node {}", dpId, e);
        return RpcResultBuilder.<GetNodeCountersOutput>failed().withError(ErrorType.APPLICATION, "failed to get node counters for node: " + dpId).buildFuture();
    }
    gncob.setCounterResult(counterResults);
    return RpcResultBuilder.success(gncob.build()).buildFuture();
}
Also used : GetNodeCountersOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeCountersOutput) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) GetNodeCountersOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeCountersOutputBuilder) CounterResult(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult)

Example 8 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class StatisticsImpl method createGroupsResult.

private Groups createGroupsResult(String groupName, Map<String, BigInteger> countersMap) {
    GroupsBuilder gb = new GroupsBuilder();
    gb.setName(groupName);
    Map<String, Counters> counters = new HashMap<>();
    List<Counters> countersList = new ArrayList<>();
    for (String counterName : countersMap.keySet()) {
        addCountersToMap(countersMap, counters, counterName);
    }
    for (Counters counter : counters.values()) {
        countersList.add(counter);
    }
    gb.setCounters(countersList);
    return gb.build();
}
Also used : HashMap(java.util.HashMap) GroupsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.GroupsBuilder) ArrayList(java.util.ArrayList) Counters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters)

Example 9 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class StatisticsImpl method cleanAllElementCounterRequests.

@Override
public ListenableFuture<RpcResult<CleanAllElementCounterRequestsOutput>> cleanAllElementCounterRequests(CleanAllElementCounterRequestsInput input) {
    ReadTransaction tx = db.newReadOnlyTransaction();
    CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
    CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
    try {
        Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
        Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
        if (!iecrcOpt.isPresent() || !eecrcOpt.isPresent()) {
            LOG.warn("Couldn't read element counters config data from DB");
            statisticsCounters.failedReadingCounterDataFromConfig();
            return RpcResultBuilder.<CleanAllElementCounterRequestsOutput>failed().withError(ErrorType.APPLICATION, "Couldn't read element counters config data from DB").buildFuture();
        }
        Set<String> idsToRelease = new HashSet<>();
        if (input.getPortId() != null && !input.getPortId().isEmpty()) {
            idsToRelease.addAll(getAllPortRequestsUniqueIds(input.getPortId(), iecrcOpt.get().getCounterRequests()));
            idsToRelease.addAll(getAllPortRequestsUniqueIds(input.getPortId(), eecrcOpt.get().getCounterRequests()));
            removeAllElementCounterRequestsOnPort(input.getPortId(), iecrcOpt.get().getCounterRequests());
            removeAllElementCounterRequestsOnPort(input.getPortId(), eecrcOpt.get().getCounterRequests());
        } else {
            idsToRelease.addAll(getAllRquestsUniqueIds(iecrcOpt.get().getCounterRequests()));
            idsToRelease.addAll(getAllRquestsUniqueIds(eecrcOpt.get().getCounterRequests()));
            removeAllElementCounterRequests(iecrcOpt.get().getCounterRequests());
            removeAllElementCounterRequests(eecrcOpt.get().getCounterRequests());
        }
        releaseIds(idsToRelease);
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("failed to get counter request data from DB");
        return RpcResultBuilder.<CleanAllElementCounterRequestsOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
    } finally {
        tx.close();
    }
    return RpcResultBuilder.<CleanAllElementCounterRequestsOutput>success().buildFuture();
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) EgressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig) Optional(java.util.Optional) IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) CleanAllElementCounterRequestsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.CleanAllElementCounterRequestsOutput) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 10 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class StatisticsImpl method handleInterfaceRemoval.

@Override
public void handleInterfaceRemoval(String interfaceId) {
    CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc;
    CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc;
    try (ReadTransaction tx = db.newReadOnlyTransaction()) {
        iecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
        eecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
    }
    try {
        Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
        Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
        if (!iecrcOpt.isPresent() || !eecrcOpt.isPresent()) {
            LOG.warn("Couldn't read element counters config data from DB");
            statisticsCounters.failedReadingCounterDataFromConfig();
            return;
        }
        removeAllElementCounterRequestsOnPort(interfaceId, iecrcOpt.get().getCounterRequests());
        removeAllElementCounterRequestsOnPort(interfaceId, eecrcOpt.get().getCounterRequests());
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("failed to get counter request data from DB");
        statisticsCounters.failedGettingCounterResultsPortRemoval();
        return;
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) EgressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig) Optional(java.util.Optional) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Test (org.junit.Test)19 ExecutionException (java.util.concurrent.ExecutionException)13 Counter (org.opendaylight.infrautils.metrics.Counter)12 ArrayList (java.util.ArrayList)11 BigInteger (java.math.BigInteger)9 MapRegister (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)9 List (java.util.List)7 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Optional (java.util.Optional)5 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)5 CounterResult (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Future (java.util.concurrent.Future)4 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)4 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 Optional (com.google.common.base.Optional)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)3