use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project controller by opendaylight.
the class WildcardedDataChangeListenerTest method testNoChangeOnReplaceWithSameValue.
@Test
public void testNoChangeOnReplaceWithSameValue() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
// We wrote initial state NODE_0_FLOW
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
transaction.submit().get(5, TimeUnit.SECONDS);
// We registered DataChangeListener
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
assertFalse(eventFuture.isDone());
final WriteTransaction secondTx = dataBroker.newWriteOnlyTransaction();
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
secondTx.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
assertNotNull(event);
// Data change should contains NODE_1 Flow - which was added
assertTrue(event.getCreatedData().containsKey(NODE_1_LVU_PATH));
// Data change must not containe NODE_0 Flow which was replaced with same value.
assertFalse(event.getUpdatedData().containsKey(NODE_0_LVU_PATH));
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project bgpcep by opendaylight.
the class BgpDeployerImplTest method deleteNeighbors.
private void deleteNeighbors() throws ExecutionException, InterruptedException {
final WriteTransaction wr = getDataBroker().newWriteOnlyTransaction();
wr.delete(LogicalDatastoreType.CONFIGURATION, NEIGHBORS_II);
wr.submit().get();
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project bgpcep by opendaylight.
the class LocRibWriter method onDataTreeChanged.
/**
* We use two-stage processing here in hopes that we avoid duplicate
* calculations when multiple peers have changed a particular entry.
*
* @param changes on supported table
*/
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Tables>> changes) {
LOG.trace("Received data change {} to LocRib {}", changes, this);
final WriteTransaction tx = this.chain.newWriteOnlyTransaction();
try {
final Map<RouteUpdateKey, RouteEntry> toUpdate = update(tx, changes);
if (!toUpdate.isEmpty()) {
walkThrough(tx, toUpdate.entrySet());
}
} catch (final Exception e) {
LOG.error("Failed to completely propagate updates {}, state is undefined", changes, e);
} finally {
tx.submit();
}
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project bgpcep by opendaylight.
the class NodeChangedListenerTest method removeNode.
private void removeNode(final NodeId nodeId) throws TransactionCommitFailedException {
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
wTx.delete(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build());
wTx.submit().checkedGet();
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project bgpcep by opendaylight.
the class NodeChangedListenerTest method createNode.
private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId, final String dstIpv4Address) throws TransactionCommitFailedException {
final NodeBuilder nodeBuilder = new NodeBuilder();
nodeBuilder.setKey(new NodeKey(nodeId));
nodeBuilder.setNodeId(nodeId);
final PathBuilder pathBuilder = new PathBuilder();
pathBuilder.setKey(new PathKey(new LspId(lspId)));
pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(new Bandwidth(new byte[] { 0x00, 0x00, (byte) 0xff, (byte) 0xff })).build());
pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address)).build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(Collections.singletonList(pathBuilder.build())).build();
final Node1Builder node1Builder = new Node1Builder();
node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address))).build());
nodeBuilder.addAugmentation(Node1.class, node1Builder.build());
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build(), nodeBuilder.build());
wTx.submit().checkedGet();
}
Aggregations