use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project controller by opendaylight.
the class Bug1125RegressionTest method delete.
private void delete(final InstanceIdentifier<?> path) {
WriteTransaction tx = getDataBroker().newWriteOnlyTransaction();
tx.delete(LogicalDatastoreType.OPERATIONAL, path);
assertCommit(tx.submit());
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project controller by opendaylight.
the class AbstractDataBrokerTestTest method writeInitialState.
// copy/pasted from Bug1125RegressionTest.writeInitialState()
private void writeInitialState() throws TransactionCommitFailedException {
WriteTransaction initialTx = getDataBroker().newWriteOnlyTransaction();
initialTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
TreeComplexUsesAugment fooAugment = new TreeComplexUsesAugmentBuilder().setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build()).build();
initialTx.put(LogicalDatastoreType.OPERATIONAL, path(TOP_FOO_KEY), topLevelList(TOP_FOO_KEY, fooAugment));
initialTx.submit().checkedGet();
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project controller by opendaylight.
the class OpendaylightToaster method setToasterStatusUp.
private void setToasterStatusUp(final Function<Boolean, Void> resultCallback) {
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
tx.put(OPERATIONAL, TOASTER_IID, buildToaster(ToasterStatus.Up));
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
LOG.info("Successfully set ToasterStatus to Up");
notifyCallback(true);
}
@Override
public void onFailure(final Throwable failure) {
// We shouldn't get an OptimisticLockFailedException (or any ex) as no
// other component should be updating the operational state.
LOG.error("Failed to update toaster status", failure);
notifyCallback(false);
}
void notifyCallback(final boolean result) {
if (resultCallback != null) {
resultCallback.apply(result);
}
}
});
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project controller by opendaylight.
the class BrokerIntegrationTest method simpleModifyOperation.
@Test
public void simpleModifyOperation() throws Exception {
DataBroker dataBroker = testContext.getDataBroker();
Optional<TopLevelList> tllFoo = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, FOO_PATH).checkedGet(5, TimeUnit.SECONDS);
assertFalse(tllFoo.isPresent());
TopLevelList tllFooData = createTll(TLL_FOO_KEY);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION, FOO_PATH, tllFooData);
transaction.submit().get(5, TimeUnit.SECONDS);
Optional<TopLevelList> readedData = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, FOO_PATH).checkedGet(5, TimeUnit.SECONDS);
assertTrue(readedData.isPresent());
assertEquals(tllFooData.getKey(), readedData.get().getKey());
TopLevelList nodeBarData = createTll(TLL_BAR_KEY);
TopLevelList nodeBazData = createTll(TLL_BAZ_KEY);
final WriteTransaction insertMoreTr = dataBroker.newWriteOnlyTransaction();
insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAR_PATH, nodeBarData);
insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAZ_PATH, nodeBazData);
insertMoreTr.submit().get(5, TimeUnit.SECONDS);
Optional<Top> top = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, TOP_PATH).checkedGet(5, TimeUnit.SECONDS);
assertTrue(top.isPresent());
assertEquals(3, top.get().getTopLevelList().size());
// We create transaction no 2
final WriteTransaction removalTransaction = dataBroker.newWriteOnlyTransaction();
// We remove node 1
removalTransaction.delete(LogicalDatastoreType.CONFIGURATION, BAR_PATH);
// We commit transaction
removalTransaction.submit().get(5, TimeUnit.SECONDS);
Optional<TopLevelList> readedData2 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, BAR_PATH).checkedGet(5, TimeUnit.SECONDS);
assertFalse(readedData2.isPresent());
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project controller by opendaylight.
the class WildcardedDataChangeListenerTest method testWriteByReplace.
@Test
public void testWriteByReplace() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
final WriteTransaction cwuTx = dataBroker.newWriteOnlyTransaction();
cwuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
cwuTx.submit().get(5, TimeUnit.SECONDS);
assertFalse(eventFuture.isDone());
final WriteTransaction lvuTx = dataBroker.newWriteOnlyTransaction();
TreeComplexUsesAugment tcua = new TreeComplexUsesAugmentBuilder().setListViaUses(Collections.singletonList(LVU)).build();
lvuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_TCU_PATH, tcua, true);
lvuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
lvuTx.submit().get(5, TimeUnit.SECONDS);
validateEvent(eventFuture.get(1000, TimeUnit.MILLISECONDS));
}
Aggregations