use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.
the class EntityOwnershipShard method getCandidateNames.
private static Collection<String> getCandidateNames(final MapEntryNode entity) {
Collection<MapEntryNode> candidates = ((MapNode) entity.getChild(CANDIDATE_NODE_ID).get()).getValue();
Collection<String> candidateNames = new ArrayList<>(candidates.size());
for (MapEntryNode candidate : candidates) {
candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
}
return candidateNames;
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.
the class ShardTest method testReadyLocalTransactionWithThreePhaseCommit.
@Test
public void testReadyLocalTransactionWithThreePhaseCommit() throws Exception {
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testReadyLocalTransactionWithThreePhaseCommit");
waitUntilLeader(shard);
final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
final DataTreeModification modification = dataStore.newModification();
final ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
final TransactionIdentifier txId = nextTransactionId();
modification.ready();
final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, false);
shard.tell(readyMessage, getRef());
expectMsgClass(ReadyTransactionReply.class);
// Send the CanCommitTransaction message.
shard.tell(new CanCommitTransaction(txId, CURRENT_VERSION).toSerializable(), getRef());
final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(expectMsgClass(CanCommitTransactionReply.class));
assertEquals("Can commit", true, canCommitReply.getCanCommit());
// Send the CanCommitTransaction message.
shard.tell(new CommitTransaction(txId, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(CommitTransactionReply.class);
final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode);
}
};
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.
the class ShardTest method testReadyLocalTransactionWithImmediateCommit.
@Test
public void testReadyLocalTransactionWithImmediateCommit() throws Exception {
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testReadyLocalTransactionWithImmediateCommit");
waitUntilLeader(shard);
final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
final DataTreeModification modification = dataStore.newModification();
final ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
final TransactionIdentifier txId = nextTransactionId();
modification.ready();
final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
shard.tell(readyMessage, getRef());
expectMsgClass(CommitTransactionReply.class);
final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode);
}
};
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testTransactionChainWithSingleShard.
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionChainWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testTransactionChainWithSingleShard", "test-1")) {
// 1. Create a Tx chain and write-only Tx
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
// 2. Write some data
final NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
writeTx.write(TestModel.TEST_PATH, testNode);
// 3. Ready the Tx for commit
final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
// 4. Commit the Tx on another thread that first waits for
// the second read Tx.
final CountDownLatch continueCommit1 = new CountDownLatch(1);
final CountDownLatch commit1Done = new CountDownLatch(1);
final AtomicReference<Exception> commit1Error = new AtomicReference<>();
new Thread(() -> {
try {
continueCommit1.await();
doCommit(cohort1);
} catch (Exception e) {
commit1Error.set(e);
} finally {
commit1Done.countDown();
}
}).start();
// 5. Create a new read Tx from the chain to read and verify
// the data from the first
// Tx is visible after being readied.
DOMStoreReadTransaction readTx = txChain.newReadOnlyTransaction();
Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", testNode, optional.get());
// 6. Create a new RW Tx from the chain, write more data,
// and ready it
final DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
final MapNode outerNode = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
rwTx.write(TestModel.OUTER_LIST_PATH, outerNode);
final DOMStoreThreePhaseCommitCohort cohort2 = rwTx.ready();
// 7. Create a new read Tx from the chain to read the data
// from the last RW Tx to
// verify it is visible.
readTx = txChain.newReadWriteTransaction();
optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", outerNode, optional.get());
// 8. Wait for the 2 commits to complete and close the
// chain.
continueCommit1.countDown();
Uninterruptibles.awaitUninterruptibly(commit1Done, 5, TimeUnit.SECONDS);
if (commit1Error.get() != null) {
throw commit1Error.get();
}
doCommit(cohort2);
txChain.close();
// 9. Create a new read Tx from the data store and verify
// committed data.
readTx = dataStore.newReadOnlyTransaction();
optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", outerNode, optional.get());
}
}
};
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.
the class NormalizedNodePrunerTest method testInnerListNodeWithFullPathPrunedWhenSchemaMissing.
@Test
public void testInnerListNodeWithFullPathPrunedWhenSchemaMissing() throws IOException {
YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME).node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).node(TestModel.INVALID_QNAME).build();
NormalizedNodePruner pruner = prunerFullSchema(path);
MapNode input = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder(TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild(ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build();
NormalizedNodeWriter.forStreamWriter(pruner).write(input);
NormalizedNode<?, ?> actual = pruner.normalizedNode();
assertNull(actual);
}
Aggregations