Search in sources :

Example 86 with WriteTransaction

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());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction)

Example 87 with WriteTransaction

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();
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) TopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder) TreeComplexUsesAugment(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment) ContainerWithUsesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder) TreeComplexUsesAugmentBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder)

Example 88 with WriteTransaction

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);
            }
        }
    });
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 89 with WriteTransaction

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());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AbstractDataServiceTest(org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest) Test(org.junit.Test)

Example 90 with WriteTransaction

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));
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) TreeComplexUsesAugment(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment) TreeComplexUsesAugmentBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) AbstractDataServiceTest(org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest) Test(org.junit.Test)

Aggregations

WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)320 ArrayList (java.util.ArrayList)74 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)60 BigInteger (java.math.BigInteger)43 Test (org.junit.Test)38 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)37 ExecutionException (java.util.concurrent.ExecutionException)33 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)28 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)25 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)23 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)23 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)22 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)19 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)17 List (java.util.List)16 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)16 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)16 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)15 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)14 VpnToDpnList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList)14