Search in sources :

Example 11 with DataTreeSnapshot

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

the class ShardDataTreeTransactionChain method newReadWriteTransaction.

ReadWriteShardDataTreeTransaction newReadWriteTransaction(final TransactionIdentifier txId) {
    final DataTreeSnapshot snapshot = getSnapshot();
    LOG.debug("Allocated read-write transaction {} snapshot {}", txId, snapshot);
    openTransaction = new ReadWriteShardDataTreeTransaction(this, txId, snapshot.newModification());
    return openTransaction;
}
Also used : DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)

Example 12 with DataTreeSnapshot

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

the class ShardDataTreeTransactionChain method newReadOnlyTransaction.

ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final TransactionIdentifier txId) {
    final DataTreeSnapshot snapshot = getSnapshot();
    LOG.debug("Allocated read-only transaction {} snapshot {}", txId, snapshot);
    return new ReadOnlyShardDataTreeTransaction(this, txId, snapshot);
}
Also used : DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)

Example 13 with DataTreeSnapshot

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

the class AbstractDataStoreClientBehaviorTest method testGetConnection.

@Test
public void testGetConnection() throws Exception {
    // set up data tree mock
    final CursorAwareDataTreeModification modification = mock(CursorAwareDataTreeModification.class);
    when(modification.readNode(YangInstanceIdentifier.EMPTY)).thenReturn(Optional.empty());
    final DataTreeSnapshot snapshot = mock(DataTreeSnapshot.class);
    when(snapshot.newModification()).thenReturn(modification);
    final DataTree dataTree = mock(DataTree.class);
    when(dataTree.takeSnapshot()).thenReturn(snapshot);
    final TestProbe backendProbe = new TestProbe(system, "backend");
    final long shard = 0L;
    behavior.createTransaction().read(YangInstanceIdentifier.EMPTY);
    final AbstractClientConnection<ShardBackendInfo> connection = behavior.getConnection(shard);
    // check cached connection for same shard
    Assert.assertSame(connection, behavior.getConnection(shard));
    final ConnectClientRequest connectClientRequest = actorContextProbe.expectMsgClass(ConnectClientRequest.class);
    Assert.assertEquals(CLIENT_ID, connectClientRequest.getTarget());
    final long sequence = 0L;
    Assert.assertEquals(sequence, connectClientRequest.getSequence());
    actorContextProbe.reply(new ConnectClientSuccess(CLIENT_ID, sequence, backendProbe.ref(), Collections.emptyList(), dataTree, 3));
    Assert.assertEquals(clientActorProbe.ref(), connection.localActor());
    // capture and execute command passed to client context
    final InternalCommand<ShardBackendInfo> command = clientActorProbe.expectMsgClass(InternalCommand.class);
    command.execute(behavior);
    // check, whether command was reaplayed
    verify(modification).readNode(YangInstanceIdentifier.EMPTY);
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) ConnectClientRequest(org.opendaylight.controller.cluster.access.commands.ConnectClientRequest) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TestProbe(akka.testkit.TestProbe) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification) Test(org.junit.Test)

Example 14 with DataTreeSnapshot

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

the class SnapshotBackedReadTransaction method read.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
    LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
    checkNotNull(path, "Path must not be null.");
    final DataTreeSnapshot snapshot = stableSnapshot;
    if (snapshot == null) {
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed"));
    }
    try {
        return Futures.immediateCheckedFuture(Optional.fromJavaUtil(snapshot.readNode(path)));
    } catch (RuntimeException e) {
        LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed", e));
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)

Example 15 with DataTreeSnapshot

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

the class ShardDataTreeTest method getCars.

private static NormalizedNode<?, ?> getCars(final ShardDataTree shardDataTree) {
    final ReadOnlyShardDataTreeTransaction readOnlyShardDataTreeTransaction = shardDataTree.newReadOnlyTransaction(nextTransactionId());
    final DataTreeSnapshot snapshot1 = readOnlyShardDataTreeTransaction.getSnapshot();
    final Optional<NormalizedNode<?, ?>> optional = snapshot1.readNode(CarsModel.BASE_PATH);
    assertEquals(true, optional.isPresent());
    return optional.get();
}
Also used : DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Aggregations

DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)18 Test (org.junit.Test)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)7 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)6 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)5 BigInteger (java.math.BigInteger)4 InOrder (org.mockito.InOrder)4 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 UnsignedLong (com.google.common.primitives.UnsignedLong)3 CommitTransactionPayload (org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload)3 TestProbe (akka.testkit.TestProbe)2 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)2 DOMStoreReadTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction)2 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification)2 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)2 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)2 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)1 ConnectClientRequest (org.opendaylight.controller.cluster.access.commands.ConnectClientRequest)1 ConnectClientSuccess (org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess)1