Search in sources :

Example 41 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.

the class AbstractCommunityHandler method loadCommunitySet.

private List<Communities> loadCommunitySet(final String key) throws ExecutionException, InterruptedException {
    final ReadOnlyTransaction tr = this.databroker.newReadOnlyTransaction();
    final Optional<CommunitySet> result = tr.read(LogicalDatastoreType.CONFIGURATION, COMMUNITY_SETS_IID.child(CommunitySet.class, new CommunitySetKey(key))).get();
    if (!result.isPresent()) {
        return Collections.emptyList();
    }
    return result.get().getCommunities().stream().map(ge -> new CommunitiesBuilder().setAsNumber(ge.getAsNumber()).setSemantics(ge.getSemantics()).build()).collect(Collectors.toList());
}
Also used : Communities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Communities) LoadingCache(com.google.common.cache.LoadingCache) CommunitySet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.community.sets.CommunitySet) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) CommunitySets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.CommunitySets) RoutingPolicy(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.RoutingPolicy) Collectors(java.util.stream.Collectors) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) CacheLoader(com.google.common.cache.CacheLoader) ExecutionException(java.util.concurrent.ExecutionException) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) CommunitySetKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.community.sets.CommunitySetKey) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Optional(com.google.common.base.Optional) Objects.requireNonNull(java.util.Objects.requireNonNull) DefinedSets1(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.DefinedSets1) CommunitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.CommunitiesBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) Collections(java.util.Collections) DefinedSets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.DefinedSets) BgpDefinedSets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.BgpDefinedSets) CommunitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.CommunitiesBuilder) CommunitySet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.community.sets.CommunitySet) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) CommunitySetKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.community.sets.CommunitySetKey)

Example 42 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.

the class GenericConditionPolicyHandler method loadPrefixSets.

private List<Prefix> loadPrefixSets(final String key) throws ExecutionException, InterruptedException {
    final ReadOnlyTransaction tr = this.databroker.newReadOnlyTransaction();
    final com.google.common.base.Optional<PrefixSet> result = tr.read(LogicalDatastoreType.CONFIGURATION, PREFIXES_SET_IID.child(PrefixSet.class, new PrefixSetKey(key))).get();
    if (!result.isPresent()) {
        return Collections.emptyList();
    }
    return result.get().getPrefix();
}
Also used : ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) PrefixSetKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.prefix.set.PrefixSetKey) MatchPrefixSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.generic.conditions.MatchPrefixSet) PrefixSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.prefix.set.PrefixSet)

Example 43 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.

the class CheckUtil method readData.

private static <R, T extends DataObject> R readData(final DataBroker dataBroker, final LogicalDatastoreType ldt, final InstanceIdentifier<T> iid, final Function<T, R> function, final int timeout) throws ReadFailedException {
    AssertionError lastError = null;
    final Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= timeout) {
        try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
            final Optional<T> data = tx.read(ldt, iid).checkedGet();
            if (data.isPresent()) {
                try {
                    return function.apply(data.get());
                } catch (final AssertionError e) {
                    lastError = e;
                    Uninterruptibles.sleepUninterruptibly(SLEEP_FOR, TimeUnit.MILLISECONDS);
                }
            }
        }
    }
    throw lastError;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)

Example 44 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.

the class UpdateTunnelInstructionExecutor method invokeOperation.

@Override
protected ListenableFuture<OperationResult> invokeOperation() {
    final InstanceIdentifier<Topology> tii = TopologyProgrammingUtil.topologyForInput(this.updateTunnelInput);
    final InstanceIdentifier<Link> lii = TunnelProgrammingUtil.linkIdentifier(tii, this.updateTunnelInput);
    try (ReadOnlyTransaction t = this.dataProvider.newReadOnlyTransaction()) {
        final Link link;
        final Node node;
        try {
            // The link has to exist
            link = t.read(LogicalDatastoreType.OPERATIONAL, lii).checkedGet().get();
            // The source node has to exist
            node = TunelProgrammingUtil.sourceNode(t, tii, link).get();
        } catch (IllegalStateException | ReadFailedException e) {
            LOG.debug("Link or node does not exist.", e);
            return TunelProgrammingUtil.RESULT;
        }
        return Futures.transform((ListenableFuture<RpcResult<UpdateLspOutput>>) this.topologyService.updateLsp(buildUpdateInput(link, node)), RpcResult::getResult, MoreExecutors.directExecutor());
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) Link(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)

Example 45 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project bgpcep by opendaylight.

the class DestroyTunnelInstructionExecutor method invokeOperation.

@Override
protected ListenableFuture<OperationResult> invokeOperation() {
    final InstanceIdentifier<Topology> tii = TopologyProgrammingUtil.topologyForInput(this.pcepDestroyTunnelInput);
    final InstanceIdentifier<Link> lii = TunnelProgrammingUtil.linkIdentifier(tii, this.pcepDestroyTunnelInput);
    try (ReadOnlyTransaction t = this.dataProvider.newReadOnlyTransaction()) {
        final Node node;
        final Link link;
        try {
            // The link has to exist
            link = t.read(LogicalDatastoreType.OPERATIONAL, lii).checkedGet().get();
            // The source node has to exist
            node = TunelProgrammingUtil.sourceNode(t, tii, link).get();
        } catch (IllegalStateException | ReadFailedException e) {
            LOG.debug("Link or node does not exist.", e);
            return TunelProgrammingUtil.RESULT;
        }
        final RemoveLspInputBuilder ab = new RemoveLspInputBuilder();
        ab.setName(link.getAugmentation(Link1.class).getSymbolicPathName());
        ab.setNode(node.getSupportingNode().get(0).getKey().getNodeRef());
        return Futures.transform((ListenableFuture<RpcResult<RemoveLspOutput>>) this.topologyService.removeLsp(ab.build()), RpcResult::getResult, MoreExecutors.directExecutor());
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RemoveLspInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.RemoveLspInputBuilder) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) Link(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)

Aggregations

ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)65 Optional (com.google.common.base.Optional)27 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)23 ExecutionException (java.util.concurrent.ExecutionException)17 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)16 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)16 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)13 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)12 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)8 ArrayList (java.util.ArrayList)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)7 List (java.util.List)6 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)6 Topology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)6 Test (org.junit.Test)5 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)5 Nonnull (javax.annotation.Nonnull)4 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)4 CacheBuilder (com.google.common.cache.CacheBuilder)3