Search in sources :

Example 31 with DataTreeModification

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

the class SnapshotBackedWriteTransaction method ready.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public DOMStoreThreePhaseCommitCohort ready() {
    @SuppressWarnings("unchecked") final TransactionReadyPrototype<T> wasReady = READY_UPDATER.getAndSet(this, null);
    checkState(wasReady != null, "Transaction %s is no longer open", getIdentifier());
    LOG.debug("Store transaction: {} : Ready", getIdentifier());
    final DataTreeModification tree = mutableTree;
    TREE_UPDATER.lazySet(this, null);
    try {
        tree.ready();
        return wasReady.transactionReady(this, tree, null);
    } catch (RuntimeException e) {
        LOG.debug("Store transaction: {}: unexpected failure when readying", getIdentifier(), e);
        return wasReady.transactionReady(this, tree, e);
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)

Example 32 with DataTreeModification

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

the class ShardDataTreeTest method applyCandidates.

private static DataTreeCandidate applyCandidates(final ShardDataTree shardDataTree, final List<DataTreeCandidate> candidates) throws ExecutionException, InterruptedException {
    final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId());
    final DataTreeModification snapshot = transaction.getSnapshot();
    for (final DataTreeCandidate candidateTip : candidates) {
        DataTreeCandidates.applyToModification(snapshot, candidateTip);
    }
    final ShardDataTreeCohort cohort = shardDataTree.finishTransaction(transaction);
    immediateCanCommit(cohort);
    immediatePreCommit(cohort);
    final DataTreeCandidate candidate = cohort.getCandidate();
    immediateCommit(cohort);
    return candidate;
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)

Example 33 with DataTreeModification

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

the class ShardDataTreeTest method doTransaction.

private static DataTreeCandidate doTransaction(final ShardDataTree shardDataTree, final DataTreeOperation operation) throws ExecutionException, InterruptedException {
    final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId());
    final DataTreeModification snapshot = transaction.getSnapshot();
    operation.execute(snapshot);
    final ShardDataTreeCohort cohort = shardDataTree.finishTransaction(transaction);
    immediateCanCommit(cohort);
    immediatePreCommit(cohort);
    final DataTreeCandidate candidate = cohort.getCandidate();
    immediateCommit(cohort);
    return candidate;
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)

Example 34 with DataTreeModification

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

the class ShardRecoveryCoordinatorTest method createCar.

private DataTreeCandidate createCar() {
    final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, carsSchemaContext);
    final DataTreeSnapshot snapshot = dataTree.takeSnapshot();
    final DataTreeModification modification = snapshot.newModification();
    modification.merge(CarsModel.BASE_PATH, CarsModel.create());
    modification.ready();
    return dataTree.prepare(modification);
}
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) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Example 35 with DataTreeModification

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

the class ShardTest method testTransactionCommitWithSubsequentExpiredCohortEntry.

@Test
public void testTransactionCommitWithSubsequentExpiredCohortEntry() throws Exception {
    dataStoreContextBuilder.shardTransactionCommitTimeoutInSeconds(1);
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testTransactionCommitWithSubsequentExpiredCohortEntry");
            waitUntilLeader(shard);
            final FiniteDuration duration = duration("5 seconds");
            final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
            final TransactionIdentifier transactionID1 = nextTransactionId();
            shard.tell(prepareBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            // CanCommit the first Tx so it's the current in-progress Tx.
            shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, CanCommitTransactionReply.class);
            // Ready the second Tx.
            final TransactionIdentifier transactionID2 = nextTransactionId();
            shard.tell(prepareBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            // Ready the third Tx.
            final TransactionIdentifier transactionID3 = nextTransactionId();
            final DataTreeModification modification3 = dataStore.newModification();
            new WriteModification(TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME)).apply(modification3);
            modification3.ready();
            final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(transactionID3, modification3, true);
            shard.tell(readyMessage, getRef());
            // Commit the first Tx. After completing, the second should
            // expire from the queue and the third
            // Tx committed.
            shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, CommitTransactionReply.class);
            // Expect commit reply from the third Tx.
            expectMsgClass(duration, CommitTransactionReply.class);
            final NormalizedNode<?, ?> node = readStore(shard, TestModel.TEST2_PATH);
            assertNotNull(TestModel.TEST2_PATH + " not found", node);
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) ReadyLocalTransaction(org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) FiniteDuration(scala.concurrent.duration.FiniteDuration) 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