Search in sources :

Example 41 with DataTreeModification

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

the class AbstractEntityOwnershipTest method deleteNode.

static void deleteNode(final YangInstanceIdentifier path, final ShardDataTree shardDataTree) throws DataValidationFailedException {
    DataTreeModification modification = shardDataTree.newModification();
    modification.delete(path);
    commit(shardDataTree, modification);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)

Example 42 with DataTreeModification

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

the class AbstractEntityOwnershipTest method writeNode.

static void writeNode(final YangInstanceIdentifier path, final NormalizedNode<?, ?> node, final ShardDataTree shardDataTree) throws DataValidationFailedException {
    DataTreeModification modification = shardDataTree.newModification();
    modification.merge(path, node);
    commit(shardDataTree, modification);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)

Example 43 with DataTreeModification

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

the class LocalReadWriteProxyTransactionTest method testForwardToLocalCommit.

@Test
public void testForwardToLocalCommit() throws Exception {
    final TestProbe probe = createProbe();
    final DataTreeModification mod = mock(DataTreeModification.class);
    final TransactionRequest<?> request = new CommitLocalTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), mod, null, false);
    testForwardToLocal(request, CommitLocalTransactionRequest.class);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification) TestProbe(akka.testkit.TestProbe) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest) Test(org.junit.Test)

Example 44 with DataTreeModification

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

the class LocalProxyTransaction method forwardToRemote.

@Override
final void forwardToRemote(final RemoteProxyTransaction successor, final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
    if (request instanceof CommitLocalTransactionRequest) {
        final CommitLocalTransactionRequest req = (CommitLocalTransactionRequest) request;
        final DataTreeModification mod = req.getModification();
        LOG.debug("Applying modification {} to successor {}", mod, successor);
        mod.applyToCursor(new AbstractDataTreeModificationCursor() {

            @Override
            public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
                successor.write(current().node(child), data);
            }

            @Override
            public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
                successor.merge(current().node(child), data);
            }

            @Override
            public void delete(final PathArgument child) {
                successor.delete(current().node(child));
            }
        });
        successor.sealOnly();
        final ModifyTransactionRequest successorReq = successor.commitRequest(req.isCoordinated());
        successor.sendRequest(successorReq, callback);
    } else if (request instanceof AbortLocalTransactionRequest) {
        LOG.debug("Forwarding abort {} to successor {}", request, successor);
        successor.abort();
    } else if (request instanceof TransactionPurgeRequest) {
        LOG.debug("Forwarding purge {} to successor {}", request, successor);
        successor.enqueuePurge(callback);
    } else if (request instanceof ModifyTransactionRequest) {
        successor.handleForwardedRequest(request, callback);
    } else {
        throwUnhandledRequest(request);
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)

Example 45 with DataTreeModification

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

the class InMemoryDataStoreTest method testReadWithReadWriteTransactionFailure.

@Test(expected = ReadFailedException.class)
public void testReadWithReadWriteTransactionFailure() throws Exception {
    DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
    DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
    Mockito.doThrow(new RuntimeException("mock ex")).when(mockModification).readNode(Mockito.any(YangInstanceIdentifier.class));
    Mockito.doReturn(mockModification).when(mockSnapshot).newModification();
    @SuppressWarnings("unchecked") TransactionReadyPrototype<String> mockReady = Mockito.mock(TransactionReadyPrototype.class);
    DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadWriteTransaction("1", false, mockSnapshot, mockReady);
    doReadAndThrowEx(readTx);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DOMStoreReadTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)45 Test (org.junit.Test)17 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)13 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)8 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)8 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)6 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)6 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)6 ActorRef (akka.actor.ActorRef)5 PruningDataTreeModification (org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)4 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)4 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)3 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 ActorSelection (akka.actor.ActorSelection)2 TestActorRef (akka.testkit.TestActorRef)2