Search in sources :

Example 1 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project mdsal by opendaylight.

the class SnapshotBackedReadTransaction method read.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public FluentFuture<Optional<NormalizedNode>> read(final YangInstanceIdentifier path) {
    LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
    requireNonNull(path, "Path must not be null.");
    final DataTreeSnapshot snapshot = stableSnapshot;
    if (snapshot == null) {
        return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Transaction is closed"));
    }
    try {
        return FluentFutures.immediateFluentFuture(snapshot.readNode(path));
    } catch (Exception e) {
        LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
        return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Read failed", e));
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException)

Example 2 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project mdsal by opendaylight.

the class SnapshotBackedReadTransaction method close.

@Override
public void close() {
    final DataTreeSnapshot prev = SNAPSHOT_UPDATER.getAndSet(this, null);
    if (prev == null) {
        LOG.debug("Store transaction: {} : previously closed", getIdentifier());
        return;
    }
    LOG.debug("Store transaction: {} : Closed", getIdentifier());
    if (closeImpl != null) {
        closeImpl.transactionClosed(this);
        closeImpl = null;
    }
}
Also used : DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)

Example 3 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project mdsal by opendaylight.

the class SnapshotBackedReadTransactionTest method basicTest.

@Test
public void basicTest() throws Exception {
    final NormalizedNode testNode = mock(NormalizedNode.class);
    final Optional<NormalizedNode> optional = Optional.of(testNode);
    doReturn("testNode").when(testNode).toString();
    doReturn(Optional.of(testNode)).when(DATA_TREE_SNAPSHOT).readNode(YangInstanceIdentifier.empty());
    assertTrue(snapshotBackedReadTransaction.exists(YangInstanceIdentifier.empty()).get());
    assertEquals(optional, snapshotBackedReadTransaction.read(YangInstanceIdentifier.empty()).get());
    final Field stableSnapshotField = SnapshotBackedReadTransaction.class.getDeclaredField("stableSnapshot");
    stableSnapshotField.setAccessible(true);
    DataTreeSnapshot stableSnapshot = (DataTreeSnapshot) stableSnapshotField.get(snapshotBackedReadTransaction);
    assertNotNull(stableSnapshot);
    snapshotBackedReadTransaction.close();
    stableSnapshot = (DataTreeSnapshot) stableSnapshotField.get(snapshotBackedReadTransaction);
    assertNull(stableSnapshot);
}
Also used : Field(java.lang.reflect.Field) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 4 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project mdsal by opendaylight.

the class InMemoryDataStoreTest method testReadWithReadOnlyTransactionFailure.

@SuppressWarnings("checkstyle:IllegalThrows")
@Test(expected = ReadFailedException.class)
public void testReadWithReadOnlyTransactionFailure() throws Throwable {
    DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
    Mockito.doThrow(new RuntimeException("mock ex")).when(mockSnapshot).readNode(Mockito.any(YangInstanceIdentifier.class));
    DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadTransaction("1", true, mockSnapshot);
    doReadAndThrowEx(readTx);
}
Also used : DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 5 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot in project yangtools by opendaylight.

the class Bug4454Test method minMaxLeafListPass.

@Test
public void minMaxLeafListPass() throws DataValidationFailedException {
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final NodeWithValue<?> barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
    final NodeWithValue<?> gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
    final LeafSetEntryNode<Object> barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(barPath).withValue("bar").build();
    final LeafSetEntryNode<Object> gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(gooPath).withValue("goo").build();
    final LeafSetNode<Object> fooLeafSetNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)).withChildValue("foo").build();
    modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
    modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare1);
    DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
    DataTreeModification tempMod1 = test1.newModification();
    tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
    tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
    tempMod1.ready();
    inMemoryDataTree.validate(tempMod1);
    final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
    inMemoryDataTree.commit(prepare2);
    final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
    final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
    assertTrue(masterContainer.isPresent());
    final Optional<NormalizedNodeContainer<?>> leafList = ((DistinctNodeContainer) masterContainer.get()).findChildByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
    assertTrue(leafList.isPresent());
    assertEquals(3, leafList.get().size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DistinctNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NormalizedNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)41 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)36 Test (org.junit.Test)30 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)25 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)18 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)11 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException)9 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)4 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)2 QName (org.opendaylight.yangtools.yang.common.QName)2 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)2 NodeWithValue (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue)2 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)2 NormalizedNodeContainer (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer)2 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)2