use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project netvirt by opendaylight.
the class L2GwValidateCli method readNodes.
private void readNodes() throws ReadFailedException {
try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
InstanceIdentifier<Topology> topoId = HwvtepSouthboundUtils.createHwvtepTopologyInstanceIdentifier();
Optional<Topology> operationalTopoOptional = tx.read(LogicalDatastoreType.OPERATIONAL, topoId).checkedGet();
Optional<Topology> configTopoOptional = tx.read(LogicalDatastoreType.CONFIGURATION, topoId).checkedGet();
if (operationalTopoOptional.isPresent()) {
for (Node node : operationalTopoOptional.get().getNode()) {
InstanceIdentifier<Node> nodeIid = topoId.child(Node.class, node.getKey());
operationalNodes.put(nodeIid, node);
}
}
if (configTopoOptional.isPresent()) {
for (Node node : configTopoOptional.get().getNode()) {
InstanceIdentifier<Node> nodeIid = topoId.child(Node.class, node.getKey());
configNodes.put(nodeIid, node);
}
}
fillNodesData(operationalNodes, operationalNodesData);
fillNodesData(configNodes, configNodesData);
Optional<ElanInstances> elanInstancesOptional = tx.read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(ElanInstances.class).build()).checkedGet();
if (elanInstancesOptional.isPresent() && elanInstancesOptional.get().getElanInstance() != null) {
for (ElanInstance elanInstance : elanInstancesOptional.get().getElanInstance()) {
elanInstanceMap.put(elanInstance.getElanInstanceName(), elanInstance);
}
}
l2gatewayConnections = L2GatewayConnectionUtils.getAllL2gatewayConnections(dataBroker);
l2gateways = L2GatewayConnectionUtils.getL2gatewayList(dataBroker);
for (L2gateway l2gateway : l2gateways) {
uuidToL2Gateway.put(l2gateway.getUuid(), l2gateway);
}
}
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project netvirt by opendaylight.
the class EvpnMacVrfUtils method getElanNameByMacvrfiid.
public String getElanNameByMacvrfiid(InstanceIdentifier<MacVrfEntry> instanceIdentifier) {
try (ReadOnlyTransaction 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).checkedGet();
if (evpnRdToNetwork.isPresent()) {
elanName = evpnRdToNetwork.get().getNetworkId();
}
} catch (ReadFailedException e) {
LOG.error("getElanName: unable to read elanName, exception ", e);
}
return elanName;
}
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction 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 (ReadOnlyTransaction 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);
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project netvirt by opendaylight.
the class TransactionUtil method read.
public static <T extends DataObject> Optional<T> read(DataBroker dataBroker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
Optional<T> result;
try {
result = tx.read(datastoreType, path).get();
} catch (InterruptedException | ExecutionException e) {
LOG.debug("read: Error while reading data from path {}", path);
throw new RuntimeException(e);
}
return result;
}
use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project netvirt by opendaylight.
the class StatisticsImpl method cleanAllElementCounterRequests.
@Override
public Future<RpcResult<CleanAllElementCounterRequestsOutput>> cleanAllElementCounterRequests(CleanAllElementCounterRequestsInput input) {
ReadOnlyTransaction tx = db.newReadOnlyTransaction();
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.<CleanAllElementCounterRequestsOutput>failed().withError(ErrorType.APPLICATION, "Couldn't read element counters config data from DB").buildFuture();
}
Set<String> idsToRelease = new HashSet<>();
if (input.getPortId() != null && !input.getPortId().isEmpty()) {
idsToRelease.addAll(getAllPortRequestsUniqueIds(input.getPortId(), iecrcOpt.get().getCounterRequests()));
idsToRelease.addAll(getAllPortRequestsUniqueIds(input.getPortId(), eecrcOpt.get().getCounterRequests()));
removeAllElementCounterRequestsOnPort(input.getPortId(), iecrcOpt.get().getCounterRequests());
removeAllElementCounterRequestsOnPort(input.getPortId(), eecrcOpt.get().getCounterRequests());
} else {
idsToRelease.addAll(getAllRquestsUniqueIds(iecrcOpt.get().getCounterRequests()));
idsToRelease.addAll(getAllRquestsUniqueIds(eecrcOpt.get().getCounterRequests()));
removeAllElementCounterRequests(iecrcOpt.get().getCounterRequests());
removeAllElementCounterRequests(eecrcOpt.get().getCounterRequests());
}
releaseIds(idsToRelease);
} catch (InterruptedException | ExecutionException e) {
LOG.warn("failed to get counter request data from DB");
return RpcResultBuilder.<CleanAllElementCounterRequestsOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
}
return RpcResultBuilder.<CleanAllElementCounterRequestsOutput>success().buildFuture();
}
Aggregations