Search in sources :

Example 1 with DataTreeModification

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

the class NormalizedNodeAggregator method combine.

private NormalizedNodeAggregator combine() throws DataValidationFailedException {
    final DataTreeModification mod = dataTree.takeSnapshot().newModification();
    for (final Optional<NormalizedNode<?, ?>> node : nodes) {
        if (node.isPresent()) {
            mod.merge(rootIdentifier, node.get());
        }
    }
    mod.ready();
    dataTree.validate(mod);
    final DataTreeCandidate candidate = dataTree.prepare(mod);
    dataTree.commit(candidate);
    return this;
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 2 with DataTreeModification

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

the class ShardDataTreeTest method newShardDataTreeCohort.

private ShardDataTreeCohort newShardDataTreeCohort(final DataTreeOperation operation) {
    final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId());
    final DataTreeModification snapshot = transaction.getSnapshot();
    operation.execute(snapshot);
    return shardDataTree.finishTransaction(transaction);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)

Example 3 with DataTreeModification

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

the class ShardDataTreeTest method modify.

private void modify(final boolean merge, final boolean expectedCarsPresent, final boolean expectedPeoplePresent) throws ExecutionException, InterruptedException {
    immediatePayloadReplication(shardDataTree, mockShard);
    assertEquals(fullSchema, shardDataTree.getSchemaContext());
    final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId());
    final DataTreeModification snapshot = transaction.getSnapshot();
    assertNotNull(snapshot);
    if (merge) {
        snapshot.merge(CarsModel.BASE_PATH, CarsModel.create());
        snapshot.merge(PeopleModel.BASE_PATH, PeopleModel.create());
    } else {
        snapshot.write(CarsModel.BASE_PATH, CarsModel.create());
        snapshot.write(PeopleModel.BASE_PATH, PeopleModel.create());
    }
    final ShardDataTreeCohort cohort = shardDataTree.finishTransaction(transaction);
    immediateCanCommit(cohort);
    immediatePreCommit(cohort);
    immediateCommit(cohort);
    final ReadOnlyShardDataTreeTransaction readOnlyShardDataTreeTransaction = shardDataTree.newReadOnlyTransaction(nextTransactionId());
    final DataTreeSnapshot snapshot1 = readOnlyShardDataTreeTransaction.getSnapshot();
    final Optional<NormalizedNode<?, ?>> optional = snapshot1.readNode(CarsModel.BASE_PATH);
    assertEquals(expectedCarsPresent, optional.isPresent());
    final Optional<NormalizedNode<?, ?>> optional1 = snapshot1.readNode(PeopleModel.BASE_PATH);
    assertEquals(expectedPeoplePresent, optional1.isPresent());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 4 with DataTreeModification

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

the class ShardRecoveryCoordinatorTest method createSnapshot.

private static ShardSnapshotState createSnapshot() {
    final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, SchemaContextHelper.PEOPLE_YANG));
    DataTreeSnapshot snapshot = dataTree.takeSnapshot();
    DataTreeModification modification = snapshot.newModification();
    modification.merge(CarsModel.BASE_PATH, CarsModel.create());
    modification.merge(PeopleModel.BASE_PATH, PeopleModel.create());
    modification.ready();
    dataTree.commit(dataTree.prepare(modification));
    return new ShardSnapshotState(new MetadataShardDataTreeSnapshot(dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get()));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Example 5 with DataTreeModification

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

the class ShardTest method testApplyState.

@Test
public void testApplyState() throws Exception {
    final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testApplyState");
    ShardTestKit.waitUntilLeader(shard);
    final DataTree store = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
    final DataTreeModification writeMod = store.takeSnapshot().newModification();
    final ContainerNode node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    writeMod.write(TestModel.TEST_PATH, node);
    writeMod.ready();
    final TransactionIdentifier tx = nextTransactionId();
    shard.underlyingActor().applyState(null, null, payloadForModification(store, writeMod, tx));
    final Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
        Uninterruptibles.sleepUninterruptibly(75, TimeUnit.MILLISECONDS);
        final NormalizedNode<?, ?> actual = readStore(shard, TestModel.TEST_PATH);
        if (actual != null) {
            assertEquals("Applied state", node, actual);
            return;
        }
    }
    fail("State was not applied");
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Stopwatch(com.google.common.base.Stopwatch) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) 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