Search in sources :

Example 1 with CounterRequestsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey in project netvirt by opendaylight.

the class StatisticsImpl method putEgressElementCounterRequestInConfig.

private void putEgressElementCounterRequestInConfig(AcquireElementCountersRequestHandlerInput input, ElementCountersDirection direcion, ReadWriteTransaction transaction, String requestKey, InstanceIdentifier<EgressElementCountersRequestConfig> ecrcIdentifier, Optional<EgressElementCountersRequestConfig> eecrcOpt, String generatedUniqueId) {
    EgressElementCountersRequestConfig requestConfig = eecrcOpt.get();
    CounterRequestsBuilder crb = new CounterRequestsBuilder();
    crb.setRequestId(requestKey);
    crb.setKey(new CounterRequestsKey(requestKey));
    crb.setFilters(input.getIncomingTraffic().getFilters());
    crb.setPortId(input.getPortId());
    crb.setLportTag(getLportTag(input.getPortId()));
    crb.setDpn(getDpn(input.getPortId()));
    crb.setTrafficDirection(direcion.toString());
    crb.setGeneratedUniqueId(generatedUniqueId);
    List<CounterRequests> counterRequests = requestConfig.getCounterRequests();
    counterRequests.add(crb.build());
    EgressElementCountersRequestConfigBuilder ecrcb = new EgressElementCountersRequestConfigBuilder();
    ecrcb.setCounterRequests(counterRequests);
    requestConfig = ecrcb.build();
    transaction.put(LogicalDatastoreType.CONFIGURATION, ecrcIdentifier, requestConfig, WriteTransaction.CREATE_MISSING_PARENTS);
}
Also used : EgressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig) EgressElementCountersRequestConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfigBuilder) CounterRequestsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey) CounterRequestsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsBuilder) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests)

Example 2 with CounterRequestsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey in project netvirt by opendaylight.

the class StatisticsImpl method deleteCounterRequest.

private void deleteCounterRequest(CounterRequests counterRequest, ElementCountersDirection direction) {
    WriteTransaction tx = db.newWriteOnlyTransaction();
    if (ElementCountersDirection.INGRESS.equals(direction)) {
        tx.delete(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(IngressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(counterRequest.getKey().getRequestId())).build());
    } else if (ElementCountersDirection.EGRESS.equals(direction)) {
        tx.delete(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(EgressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(counterRequest.getKey().getRequestId())).build());
    }
    tx.submit();
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) CounterRequestsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests)

Example 3 with CounterRequestsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey in project netvirt by opendaylight.

the class StatisticsImpl method getElementCountersByHandler.

@Override
public Future<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();
    ReadOnlyTransaction 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");
                StatisticsPluginImplCounters.failed_getting_counter_results.inc();
                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");
                StatisticsPluginImplCounters.failed_getting_counter_results.inc();
                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();
    }
    GetElementCountersByHandlerOutputBuilder gecbhob = new GetElementCountersByHandlerOutputBuilder();
    gecbhob.setCounterResult(counters);
    return RpcResultBuilder.success(gecbhob.build()).buildFuture();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.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(com.google.common.base.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) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with CounterRequestsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey in project netvirt by opendaylight.

the class StatisticsImpl method releaseElementCountersRequestHandler.

@Override
public Future<RpcResult<ReleaseElementCountersRequestHandlerOutput>> releaseElementCountersRequestHandler(ReleaseElementCountersRequestHandlerInput 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();
    ReadWriteTransaction tx = db.newReadWriteTransaction();
    CheckedFuture<Optional<CounterRequests>, ReadFailedException> ingressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, ingressPath);
    CheckedFuture<Optional<CounterRequests>, ReadFailedException> egressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, egressPath);
    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");
            StatisticsPluginImplCounters.failed_reading_counter_data_from_config.inc();
            return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "Couldn't read element counters config data from DB").buildFuture();
        }
        if (!ingressRequestData.get().isPresent() && !egressRequestData.get().isPresent()) {
            LOG.warn("Handler does not exists");
            StatisticsPluginImplCounters.unknown_request_handler.inc();
            return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "Handler does not exists").buildFuture();
        }
        String generatedKey = null;
        if (ingressRequestData.get().isPresent()) {
            handleReleaseTransaction(input, ingressPath, ingressRequestData, iecrcOpt.get().getCounterRequests());
            generatedKey = ingressRequestData.get().get().getGeneratedUniqueId();
        }
        if (egressRequestData.get().isPresent()) {
            handleReleaseTransaction(input, egressPath, egressRequestData, eecrcOpt.get().getCounterRequests());
            generatedKey = egressRequestData.get().get().getGeneratedUniqueId();
        }
        releaseId(generatedKey);
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("failed to get counter request data from DB");
        return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
    }
    return RpcResultBuilder.<ReleaseElementCountersRequestHandlerOutput>success().buildFuture();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) EgressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig) Optional(com.google.common.base.Optional) IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) CounterRequestsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ExecutionException(java.util.concurrent.ExecutionException) ReleaseElementCountersRequestHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.ReleaseElementCountersRequestHandlerOutput)

Example 5 with CounterRequestsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey in project netvirt by opendaylight.

the class StatisticsImpl method putIngressElementCounterRequestInConfig.

private void putIngressElementCounterRequestInConfig(AcquireElementCountersRequestHandlerInput input, ElementCountersDirection direcion, ReadWriteTransaction transaction, String requestKey, InstanceIdentifier<IngressElementCountersRequestConfig> ecrcIdentifier, Optional<IngressElementCountersRequestConfig> iecrcOpt, String generatedUniqueId) {
    IngressElementCountersRequestConfig requestConfig = iecrcOpt.get();
    CounterRequestsBuilder crb = new CounterRequestsBuilder();
    crb.setRequestId(requestKey);
    crb.setKey(new CounterRequestsKey(requestKey));
    crb.setFilters(input.getOutgoingTraffic().getFilters());
    crb.setPortId(input.getPortId());
    crb.setLportTag(getLportTag(input.getPortId()));
    crb.setDpn(getDpn(input.getPortId()));
    crb.setTrafficDirection(direcion.toString());
    crb.setGeneratedUniqueId(generatedUniqueId);
    List<CounterRequests> counterRequests = requestConfig.getCounterRequests();
    counterRequests.add(crb.build());
    IngressElementCountersRequestConfigBuilder ecrcb = new IngressElementCountersRequestConfigBuilder();
    ecrcb.setCounterRequests(counterRequests);
    requestConfig = ecrcb.build();
    transaction.put(LogicalDatastoreType.CONFIGURATION, ecrcIdentifier, requestConfig, WriteTransaction.CREATE_MISSING_PARENTS);
}
Also used : IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) IngressElementCountersRequestConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfigBuilder) CounterRequestsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey) CounterRequestsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsBuilder) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests)

Aggregations

CounterRequests (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests)5 CounterRequestsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey)5 IngressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig)3 Optional (com.google.common.base.Optional)2 ExecutionException (java.util.concurrent.ExecutionException)2 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 EgressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig)2 CounterRequestsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsBuilder)2 ArrayList (java.util.ArrayList)1 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1 EgressElementCountersRequestConfigBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfigBuilder)1 GetElementCountersByHandlerOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutput)1 GetElementCountersByHandlerOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutputBuilder)1 IngressElementCountersRequestConfigBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfigBuilder)1 ReleaseElementCountersRequestHandlerOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.ReleaseElementCountersRequestHandlerOutput)1 CounterResult (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult)1