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());
}
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();
}
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;
}
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());
}
}
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());
}
}
Aggregations