Search in sources :

Example 6 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.

the class EvpnMacVrfUtils method getElanNameByMacvrfiid.

public String getElanNameByMacvrfiid(InstanceIdentifier<MacVrfEntry> instanceIdentifier) {
    try (ReadTransaction tx = dataBroker.newReadOnlyTransaction()) {
        String rd = instanceIdentifier.firstKeyOf(VrfTables.class).getRouteDistinguisher();
        String elanName = null;
        InstanceIdentifier<EvpnRdToNetwork> iidEvpnRdToNet = InstanceIdentifier.builder(EvpnRdToNetworks.class).child(EvpnRdToNetwork.class, new EvpnRdToNetworkKey(rd)).build();
        try {
            Optional<EvpnRdToNetwork> evpnRdToNetwork = tx.read(LogicalDatastoreType.CONFIGURATION, iidEvpnRdToNet).get();
            if (evpnRdToNetwork.isPresent()) {
                elanName = evpnRdToNetwork.get().getNetworkId();
            }
        } catch (InterruptedException | ExecutionException e) {
            LOG.error("getElanName: unable to read elanName, exception ", e);
        }
        return elanName;
    }
}
Also used : VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) EvpnRdToNetworkKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.evpn.rd.to.networks.EvpnRdToNetworkKey) EvpnRdToNetwork(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.evpn.rd.to.networks.EvpnRdToNetwork) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.

the class EvpnUtils method asyncReadAndExecute.

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T extends DataObject> void asyncReadAndExecute(final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> iid, final String jobKey, final Function<Optional<T>, Void> function) {
    jobCoordinator.enqueueJob(jobKey, () -> {
        SettableFuture<Optional<T>> settableFuture = SettableFuture.create();
        List futures = Collections.singletonList(settableFuture);
        try (ReadTransaction tx = broker.newReadOnlyTransaction()) {
            Futures.addCallback(tx.read(datastoreType, iid), new SettableFutureCallback<Optional<T>>(settableFuture) {

                @Override
                public void onSuccess(Optional<T> data) {
                    function.apply(data);
                    super.onSuccess(data);
                }
            }, MoreExecutors.directExecutor());
            return futures;
        }
    }, ElanConstants.JOB_MAX_RETRIES);
}
Also used : Optional(java.util.Optional) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) DcGatewayIpList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList) List(java.util.List) ArrayList(java.util.ArrayList) ExternalTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList)

Example 8 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.

the class NeutronvpnUtils method asyncReadAndExecute.

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T extends DataObject> void asyncReadAndExecute(final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> iid, final String jobKey, final Function<Optional<T>, Void> function) {
    jobCoordinator.enqueueJob(jobKey, () -> {
        SettableFuture<Optional<T>> settableFuture = SettableFuture.create();
        List futures = Collections.singletonList(settableFuture);
        try (ReadTransaction tx = dataBroker.newReadOnlyTransaction()) {
            Futures.addCallback(tx.read(datastoreType, iid), new SettableFutureCallback<Optional<T>>(settableFuture) {

                @Override
                public void onSuccess(Optional<T> data) {
                    function.apply(data);
                    super.onSuccess(data);
                }
            }, MoreExecutors.directExecutor());
            return futures;
        }
    }, JOB_MAX_RETRIES);
}
Also used : Optional(java.util.Optional) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) ArrayList(java.util.ArrayList) RouterDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList) List(java.util.List)

Example 9 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.

the class StatisticsImpl method checkPoolExists.

private boolean checkPoolExists() {
    ReadTransaction roTransaction = db.newReadOnlyTransaction();
    InstanceIdentifier<IdPool> path = InstanceIdentifier.create(IdPools.class).child(IdPool.class, new IdPoolKey(CountersServiceUtils.COUNTERS_PULL_NAME));
    CheckedFuture<Optional<IdPool>, ReadFailedException> pool = roTransaction.read(LogicalDatastoreType.CONFIGURATION, path);
    try {
        Optional<IdPool> poolOpt = pool.get();
        if (poolOpt.isPresent()) {
            return true;
        }
    } catch (InterruptedException | ExecutionException e) {
        return false;
    } finally {
        roTransaction.close();
    }
    return false;
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Optional(java.util.Optional) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) IdPools(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools) IdPoolKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey) ExecutionException(java.util.concurrent.ExecutionException) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)

Example 10 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction 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)

Aggregations

ReadTransaction (org.opendaylight.mdsal.binding.api.ReadTransaction)11 ExecutionException (java.util.concurrent.ExecutionException)7 Optional (java.util.Optional)6 ArrayList (java.util.ArrayList)4 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)4 HashSet (java.util.HashSet)2 List (java.util.List)2 EgressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig)2 IngressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig)2 Nullable (org.eclipse.jdt.annotation.Nullable)1 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)1 IdPools (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools)1 IdPool (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)1 IdPoolKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey)1 ExternalTunnelList (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList)1 DcGatewayIpList (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList)1 Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)1 VrfTables (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables)1 EvpnRdToNetwork (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.evpn.rd.to.networks.EvpnRdToNetwork)1 EvpnRdToNetworkKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.evpn.rd.to.networks.EvpnRdToNetworkKey)1