Search in sources :

Example 1 with ReleaseElementCountersRequestHandlerInput

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

the class StatisticsImpl method handleReleaseTransaction.

private void handleReleaseTransaction(ReleaseElementCountersRequestHandlerInput input, InstanceIdentifier<CounterRequests> path, CheckedFuture<Optional<CounterRequests>, ReadFailedException> requestData, List<CounterRequests> counterRequests) throws InterruptedException, ExecutionException {
    WriteTransaction wt = db.newWriteOnlyTransaction();
    wt.delete(LogicalDatastoreType.CONFIGURATION, path);
    wt.submit();
    CounterRequests counterRequest = requestData.get().get();
    if (shouldUnbindCountersService(counterRequest.getPortId(), counterRequest.getKey().getRequestId(), counterRequests)) {
        unbindCountersServiceIfBound(counterRequest.getPortId(), ElementCountersDirection.valueOf(counterRequest.getTrafficDirection()));
    }
    if (!isIdenticalCounterRequestExist(input.getHandler(), counterRequest.getPortId(), counterRequest.getTrafficDirection(), counterRequest.getFilters(), counterRequests)) {
        deleteCounterSpecificRules(counterRequest.getPortId(), counterRequest.getLportTag(), counterRequest.getDpn(), ElementCountersDirection.valueOf(counterRequest.getTrafficDirection()), counterRequest.getFilters());
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests)

Example 2 with ReleaseElementCountersRequestHandlerInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.ReleaseElementCountersRequestHandlerInput 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 3 with ReleaseElementCountersRequestHandlerInput

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

the class StatisticsImpl method handleReleaseTransaction.

private void handleReleaseTransaction(WriteTransaction transaction, ReleaseElementCountersRequestHandlerInput input, InstanceIdentifier<CounterRequests> path, Optional<CounterRequests> requestData, List<CounterRequests> counterRequests) {
    transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
    CounterRequests counterRequest = requestData.get();
    if (shouldUnbindCountersService(counterRequest.getPortId(), counterRequest.key().getRequestId(), counterRequests)) {
        unbindCountersServiceIfBound(counterRequest.getPortId(), ElementCountersDirection.valueOf(counterRequest.getTrafficDirection()));
    }
    if (!isIdenticalCounterRequestExist(input.getHandler(), counterRequest.getPortId(), counterRequest.getTrafficDirection(), counterRequest.getFilters(), counterRequests)) {
        deleteCounterSpecificRules(counterRequest.getPortId(), counterRequest.getLportTag(), counterRequest.getDpn(), ElementCountersDirection.valueOf(counterRequest.getTrafficDirection()), counterRequest.getFilters());
    }
}
Also used : 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)3 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)2 Optional (com.google.common.base.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 EgressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig)1 IngressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig)1 ReleaseElementCountersRequestHandlerOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.ReleaseElementCountersRequestHandlerOutput)1 CounterRequestsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey)1