use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project controller by opendaylight.
the class WriteParentListenAugmentTest method writeNodeListenAugment.
@Test
public void writeNodeListenAugment() throws Exception {
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
DataBroker dataBroker = testContext.getDataBroker();
ListenerRegistration<org.opendaylight.controller.md.sal.binding.api.DataChangeListener> dclRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, AUGMENT_WILDCARDED_PATH, change -> event.set(change), DataChangeScope.SUBTREE);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
TopLevelList tll = new TopLevelListBuilder().setKey(TLL_KEY).addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment("one")).build();
transaction.put(LogicalDatastoreType.OPERATIONAL, TLL_INSTANCE_ID_BA, tll, true);
transaction.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get(1000, TimeUnit.MILLISECONDS);
assertTrue(receivedEvent.getCreatedData().containsKey(AUGMENT_TLL_PATH));
dclRegistration.close();
final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
transaction2.put(LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH, treeComplexUsesAugment("two"));
transaction2.submit().get(5, TimeUnit.SECONDS);
TreeComplexUsesAugment readedAug = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH).get(5, TimeUnit.SECONDS).get();
assertEquals("two", readedAug.getContainerWithUses().getLeafFromGrouping());
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project controller by opendaylight.
the class WriteParentReadChildTest method writeParentReadChild.
/**
* The scenario tests writing parent node, which also contains child items
* and then reading child directly, by specifying path to the child.
* Expected behaviour is child is returned.
*/
@Test
public void writeParentReadChild() throws Exception {
DataBroker dataBroker = testContext.getDataBroker();
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
List11 list11 = //
new List11Builder().setKey(//
LIST11_KEY).setAttrStr("primary").build();
List1 list1 = new List1Builder().setKey(LIST1_KEY).setList11(ImmutableList.of(list11)).build();
transaction.put(LogicalDatastoreType.OPERATIONAL, LIST1_INSTANCE_ID_BA, list1, true);
transaction.submit().get(5, TimeUnit.SECONDS);
Optional<List1> readList1 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, LIST1_INSTANCE_ID_BA).get(1000, TimeUnit.MILLISECONDS);
assertTrue(readList1.isPresent());
Optional<? extends DataObject> readList11 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, LIST11_INSTANCE_ID_BA).get(5, TimeUnit.SECONDS);
assertNotNull("Readed flow should not be null.", readList11);
assertTrue(readList11.isPresent());
assertEquals(list11, readList11.get());
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project netvirt by opendaylight.
the class VpnInterfaceManager method removeVpnInterfaceFromVpn.
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
private void removeVpnInterfaceFromVpn(final InstanceIdentifier<VpnInterface> identifier, final VpnInterface vpnInterface, final String vpnName, final String interfaceName, final Interface interfaceState) {
LOG.info("remove: VPN Interface remove event - intfName {} vpn {} dpn {}", vpnInterface.getName(), vpnName, vpnInterface.getDpnId());
removeInterfaceFromUnprocessedList(identifier, vpnInterface);
jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName, () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>(3);
ListenableFuture<Void> configFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
LOG.info("remove: - intfName {} onto vpnName {} running config-driven", interfaceName, vpnName);
BigInteger dpId = BigInteger.ZERO;
int ifIndex = 0;
String gwMacAddress = null;
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
final Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, interfaceId);
if (interfaceState != null) {
try {
dpId = InterfaceUtils.getDpIdFromInterface(interfaceState);
} catch (NumberFormatException | IllegalStateException e) {
LOG.error("remove: Unable to retrieve dpnId from interface operational" + " data store for interface {} on dpn {} for vpn {} Fetching" + " from vpn interface op data store. ", interfaceName, vpnInterface.getDpnId(), vpnName, e);
dpId = BigInteger.ZERO;
}
ifIndex = interfaceState.getIfIndex();
gwMacAddress = interfaceState.getPhysAddress().getValue();
} else {
LOG.info("remove: Interface state not available for {}. Trying to fetch data" + " from vpn interface op.", interfaceName);
if (optVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
dpId = vpnOpInterface.getDpnId();
ifIndex = vpnOpInterface.getLportTag().intValue();
gwMacAddress = vpnOpInterface.getGatewayMacAddress();
} else {
LOG.error("remove: Handling removal of VPN interface {} for vpn {} skipped" + " as interfaceState and vpn interface op is not" + " available", interfaceName, vpnName);
return;
}
}
processVpnInterfaceDown(dpId, interfaceName, ifIndex, gwMacAddress, optVpnInterface.isPresent() ? optVpnInterface.get() : null, false, writeConfigTxn, writeOperTxn, writeInvTxn);
LOG.info("remove: Removal of vpn interface {} on dpn {} for vpn {} processed " + "successfully", interfaceName, vpnInterface.getDpnId(), vpnName);
}));
}));
});
futures.add(configFuture);
Futures.addCallback(configFuture, new PostVpnInterfaceWorker(interfaceName, false, "Config"));
return futures;
}, DJC_MAX_RETRIES);
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project netvirt by opendaylight.
the class VpnInterfaceManager method updateVpnInterfacesForUnProcessAdjancencies.
public void updateVpnInterfacesForUnProcessAdjancencies(String vpnName) {
String primaryRd = VpnUtil.getVpnRd(dataBroker, vpnName);
VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
if (vpnInstanceOpData == null) {
return;
}
List<VpnToDpnList> vpnToDpnLists = vpnInstanceOpData.getVpnToDpnList();
if (vpnToDpnLists == null || vpnToDpnLists.isEmpty()) {
return;
}
LOG.debug("Update the VpnInterfaces for Unprocessed Adjancencies for vpnName:{}", vpnName);
vpnToDpnLists.forEach(vpnToDpnList -> vpnToDpnList.getVpnInterfaces().forEach(vpnInterface -> {
InstanceIdentifier<VpnInterfaceOpDataEntry> existingVpnInterfaceId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getInterfaceName(), vpnName);
Optional<VpnInterfaceOpDataEntry> vpnInterfaceOptional = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, existingVpnInterfaceId);
if (!vpnInterfaceOptional.isPresent()) {
return;
}
List<Adjacency> configVpnAdjacencies = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker, vpnInterface.getInterfaceName());
if (configVpnAdjacencies == null) {
LOG.debug("There is no adjacency available for vpnInterface:{}", vpnInterface);
return;
}
List<Adjacency> operationVpnAdjacencies = vpnInterfaceOptional.get().getAugmentation(AdjacenciesOp.class).getAdjacency();
// Due to insufficient rds, some of the extra route wont get processed when it is added.
// The unprocessed adjacencies will be present in config vpn interface DS but will be missing
// in operational DS. These unprocessed adjacencies will be handled below.
// To obtain unprocessed adjacencies, filtering is done by which the missing adjacencies in operational
// DS are retrieved which is used to call addNewAdjToVpnInterface method.
configVpnAdjacencies.stream().filter(adjacency -> operationVpnAdjacencies.stream().noneMatch(operationalAdjacency -> operationalAdjacency.getIpAddress().equals(adjacency.getIpAddress()))).forEach(adjacency -> {
LOG.debug("Processing the vpnInterface{} for the Ajacency:{}", vpnInterface, adjacency);
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getInterfaceName(), () -> {
WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
if (VpnUtil.isAdjacencyEligibleToVpn(dataBroker, adjacency, vpnName)) {
addNewAdjToVpnInterface(existingVpnInterfaceId, primaryRd, adjacency, vpnInterfaceOptional.get().getDpnId(), writeConfigTxn, writeOperTxn);
ListenableFuture<Void> operFuture = writeOperTxn.submit();
try {
operFuture.get();
} catch (ExecutionException | InterruptedException e) {
LOG.error("Exception encountered while submitting operational" + " future for vpnInterface {}", vpnInterface, e);
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(writeConfigTxn.submit());
return futures;
} else {
return Collections.emptyList();
}
});
});
}));
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project netvirt by opendaylight.
the class VpnManagerImpl method setupRouterGwMacFlow.
private void setupRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId, WriteTransaction writeTx, RouterGwMacFlowSetupMethod consumer, String operation) {
if (routerGwMac == null) {
LOG.warn("Failed to handle router GW flow in GW-MAC table. MAC address is missing for router-id {}", routerName);
return;
}
if (dpnId == null || BigInteger.ZERO.equals(dpnId)) {
LOG.info("setupRouterGwMacFlow: DPN id is missing for router-id {}", routerName);
return;
}
Uuid vpnId = VpnUtil.getExternalNetworkVpnId(dataBroker, extNetworkId);
if (vpnId == null) {
LOG.warn("Network {} is not associated with VPN", extNetworkId.getValue());
return;
}
LOG.info("{} router GW MAC flow for router-id {} on switch {}", operation, routerName, dpnId);
if (writeTx == null) {
ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> consumer.process(vpnId.getValue(), tx)), LOG, "Commit transaction");
} else {
consumer.process(vpnId.getValue(), writeTx);
}
}
Aggregations