Search in sources :

Example 11 with DataTreeModification

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

the class AbstractShardTest method writeToStore.

public static void writeToStore(final DataTree store, final YangInstanceIdentifier id, final NormalizedNode<?, ?> node) throws DataValidationFailedException {
    final DataTreeModification transaction = store.takeSnapshot().newModification();
    transaction.write(id, node);
    transaction.ready();
    store.validate(transaction);
    final DataTreeCandidate candidate = store.prepare(transaction);
    store.commit(candidate);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)

Example 12 with DataTreeModification

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

the class AbstractShardTest method writeToStore.

public static void writeToStore(final ShardDataTree store, final YangInstanceIdentifier id, final NormalizedNode<?, ?> node) throws DataValidationFailedException {
    BatchedModifications batched = newBatchedModifications(nextTransactionId(), id, node, true, true, 1);
    DataTreeModification modification = store.getDataTree().takeSnapshot().newModification();
    batched.apply(modification);
    store.notifyListeners(commitTransaction(store.getDataTree(), modification));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Example 13 with DataTreeModification

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

the class AbstractShardTest method mergeToStore.

public void mergeToStore(final ShardDataTree store, final YangInstanceIdentifier id, final NormalizedNode<?, ?> node) throws DataValidationFailedException {
    final BatchedModifications batched = new BatchedModifications(nextTransactionId(), CURRENT_VERSION);
    batched.addModification(new MergeModification(id, node));
    batched.setReady(true);
    batched.setDoCommitOnReady(true);
    batched.setTotalMessagesSent(1);
    DataTreeModification modification = store.getDataTree().takeSnapshot().newModification();
    batched.apply(modification);
    store.notifyListeners(commitTransaction(store.getDataTree(), modification));
}
Also used : MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Example 14 with DataTreeModification

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

the class TransactionProxyTest method createDataTree.

private static DataTree createDataTree(final NormalizedNode<?, ?> readResponse) {
    DataTree dataTree = mock(DataTree.class);
    DataTreeSnapshot dataTreeSnapshot = mock(DataTreeSnapshot.class);
    DataTreeModification dataTreeModification = mock(DataTreeModification.class);
    doReturn(dataTreeSnapshot).when(dataTree).takeSnapshot();
    doReturn(dataTreeModification).when(dataTreeSnapshot).newModification();
    doReturn(java.util.Optional.of(readResponse)).when(dataTreeModification).readNode(any(YangInstanceIdentifier.class));
    return dataTree;
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 15 with DataTreeModification

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

the class SnapshotBackedWriteTransaction method write.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
    checkNotReady();
    final DataTreeModification tree = mutableTree;
    LOG.debug("Tx: {} Write: {}:{}", getIdentifier(), path, data);
    try {
        tree.write(path, data);
    // FIXME: Add checked exception
    } catch (RuntimeException e) {
        LOG.error("Tx: {}, failed to write {}:{} in {}", getIdentifier(), path, data, tree, e);
        // Rethrow original ones if they are subclasses of RuntimeException
        // or Error
        Throwables.propagateIfPossible(e);
        // FIXME: Introduce proper checked exception
        throw new IllegalArgumentException("Illegal input data.", e);
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)

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