use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.
the class NodeConnectedHandlerTest method readNodes.
public void readNodes() throws Exception {
ReadTransaction tx = getDataBroker().newReadOnlyTransaction();
d1GlobalOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d1NodePath, tx);
d2GlobalOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d2NodePath, tx);
haGlobalOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, haNodePath, tx);
d1PsOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d1PsNodePath, tx);
d2PsOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d2PsNodePath, tx);
haPsOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, haPsNodePath, tx);
haGlobalConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, haNodePath, tx);
d1GlobalConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d1NodePath, tx);
d2GlobalConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d2NodePath, tx);
haPsConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, haPsNodePath, tx);
d1PsConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d1PsNodePath, tx);
d2PsConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d2PsNodePath, tx);
tx.close();
}
use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.
the class StatisticsImpl method cleanAllElementCounterRequests.
@Override
public ListenableFuture<RpcResult<CleanAllElementCounterRequestsOutput>> cleanAllElementCounterRequests(CleanAllElementCounterRequestsInput input) {
ReadTransaction 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");
statisticsCounters.failedReadingCounterDataFromConfig();
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();
} finally {
tx.close();
}
return RpcResultBuilder.<CleanAllElementCounterRequestsOutput>success().buildFuture();
}
use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.
the class StatisticsImpl method handleInterfaceRemoval.
@Override
public void handleInterfaceRemoval(String interfaceId) {
CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc;
CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc;
try (ReadTransaction tx = db.newReadOnlyTransaction()) {
iecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
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");
statisticsCounters.failedReadingCounterDataFromConfig();
return;
}
removeAllElementCounterRequestsOnPort(interfaceId, iecrcOpt.get().getCounterRequests());
removeAllElementCounterRequestsOnPort(interfaceId, eecrcOpt.get().getCounterRequests());
} catch (InterruptedException | ExecutionException e) {
LOG.warn("failed to get counter request data from DB");
statisticsCounters.failedGettingCounterResultsPortRemoval();
return;
}
}
use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.
the class DhcpExternalTunnelManager method createRemoteMcastMac.
@Nullable
public RemoteMcastMacs createRemoteMcastMac(Node dstDevice, String logicalSwitchName, IpAddress internalTunnelIp) {
Set<LocatorSet> locators = new HashSet<>();
TerminationPointKey terminationPointKey = HwvtepSouthboundUtils.getTerminationPointKey(internalTunnelIp.getIpv4Address().getValue());
HwvtepPhysicalLocatorRef phyLocRef = new HwvtepPhysicalLocatorRef(HwvtepSouthboundUtils.createInstanceIdentifier(dstDevice.getNodeId()).child(TerminationPoint.class, terminationPointKey));
locators.add(new LocatorSetBuilder().setLocatorRef(phyLocRef).build());
HwvtepLogicalSwitchRef lsRef = new HwvtepLogicalSwitchRef(HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(dstDevice.getNodeId(), new HwvtepNodeName(logicalSwitchName)));
RemoteMcastMacs remoteMcastMacs = new RemoteMcastMacsBuilder().setMacEntryKey(new MacAddress(UNKNOWN_DMAC)).setLogicalSwitchRef(lsRef).build();
InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(dstDevice.getNodeId(), remoteMcastMacs.key());
ReadTransaction transaction = broker.newReadOnlyTransaction();
try {
// TODO do async mdsal read
remoteMcastMacs = transaction.read(LogicalDatastoreType.CONFIGURATION, iid).get().get();
locators.addAll(remoteMcastMacs.getLocatorSet());
return new RemoteMcastMacsBuilder(remoteMcastMacs).setLocatorSet(new ArrayList<>(locators)).build();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Failed to read the macs {}", iid);
} finally {
transaction.close();
}
return null;
}
use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.
the class DhcpSubnetListener method getSubnetMapBuilder.
private SubnetmapBuilder getSubnetMapBuilder(DataBroker broker, Uuid subnetId) {
SubnetmapBuilder builder = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
ReadTransaction tx = broker.newReadOnlyTransaction();
Optional<Subnetmap> sn;
try {
sn = tx.read(LogicalDatastoreType.CONFIGURATION, id).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
} finally {
tx.close();
}
if (sn.isPresent()) {
builder = new SubnetmapBuilder(sn.get());
} else {
builder = new SubnetmapBuilder().withKey(new SubnetmapKey(subnetId)).setId(subnetId);
}
return builder;
}
Aggregations