use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class WriteTransactionsHandler method execWrite.
@Override
ListenableFuture<Void> execWrite(final long txId) {
final int i = nextInt(MAX_ITEM + 1);
final YangInstanceIdentifier entryId = idListItem.node(ITEM).node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(ITEM, NUMBER, i));
final DOMDataWriteTransaction tx = createTransaction();
if (usedValues.contains(i)) {
LOG.debug("Deleting item: {}", i);
deleteTx++;
tx.delete(LogicalDatastoreType.CONFIGURATION, entryId);
usedValues.remove(i);
} else {
LOG.debug("Inserting item: {}", i);
insertTx++;
final MapEntryNode entry = ImmutableNodes.mapEntry(ITEM, NUMBER, i);
tx.put(LogicalDatastoreType.CONFIGURATION, entryId, entry);
usedValues.add(i);
}
return tx.submit();
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class DistributedShardFrontendTest method createCrossShardContainer.
private static ContainerNode createCrossShardContainer() {
final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).withChild(createInnerMapNode(1)).build();
final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).withChild(createInnerMapNode(2)).build();
final MapNode outerList = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(outerListEntry1).withChild(outerListEntry2).build();
final ContainerNode testContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(outerList).build();
return testContainer;
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class DistributedShardedDOMDataTreeTest method testMultipleWritesIntoSingleMapEntry.
@Test
public void testMultipleWritesIntoSingleMapEntry() throws Exception {
initEmptyDatastores();
final DistributedShardRegistration shardRegistration = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
LOG.warn("Got after waiting for nonleader");
final ActorRef leaderShardManager = leaderDistributedDataStore.getActorContext().getShardManager();
leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
final YangInstanceIdentifier oid1 = getOuterListIdFor(0);
final DOMDataTreeIdentifier outerListPath = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1);
final DistributedShardRegistration outerListShardReg = waitOnAsyncTask(leaderShardFactory.createDistributedShard(outerListPath, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(outerListPath.getRootIdentifier()));
final DOMDataTreeProducer shardProducer = leaderShardFactory.createProducer(Collections.singletonList(outerListPath));
final DOMDataTreeCursorAwareTransaction tx = shardProducer.createTransaction(false);
final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1));
assertNotNull(cursor);
MapNode innerList = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME)).build();
cursor.write(new NodeIdentifier(TestModel.INNER_LIST_QNAME), innerList);
cursor.close();
tx.submit().checkedGet();
final ArrayList<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
final Collection<MapEntryNode> innerListMapEntries = createInnerListMapEntries(1000, "run-" + i);
for (final MapEntryNode innerListMapEntry : innerListMapEntries) {
final DOMDataTreeCursorAwareTransaction tx1 = shardProducer.createTransaction(false);
final DOMDataTreeWriteCursor cursor1 = tx1.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1.node(new NodeIdentifier(TestModel.INNER_LIST_QNAME))));
cursor1.write(innerListMapEntry.getIdentifier(), innerListMapEntry);
cursor1.close();
futures.add(tx1.submit());
}
}
futures.get(futures.size() - 1).checkedGet();
final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_LIST_ID), true, Collections.emptyList());
verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
verifyNoMoreInteractions(mockedDataTreeListener);
final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
final NormalizedNode<?, ?> expected = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME)).withValue(createInnerListMapEntries(1000, "run-999")).build();
assertEquals("List values dont match the expected values from the last run", expected, capturedValue.get(0).iterator().next().getRootNode().getDataAfter().get());
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class PrefixedShardConfigWriter method doWrite.
private DOMStoreThreePhaseCommitCohort doWrite(final YangInstanceIdentifier path, final Collection<MemberName> replicas) {
final ListNodeBuilder<Object, LeafSetEntryNode<Object>> replicaListBuilder = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_REPLICA_QNAME));
replicas.forEach(name -> replicaListBuilder.withChild(ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(ClusterUtils.SHARD_REPLICA_QNAME, name.getName())).withValue(name.getName()).build()));
final MapEntryNode newEntry = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(new NodeIdentifierWithPredicates(ClusterUtils.SHARD_LIST_QNAME, ClusterUtils.SHARD_PREFIX_QNAME, path)).withChild(ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_PREFIX_QNAME)).withValue(path).build()).withChild(ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_REPLICAS_QNAME)).withChild(replicaListBuilder.build()).build()).build();
final ClientTransaction tx = history.createTransaction();
final DOMDataTreeWriteCursor cursor = tx.openCursor();
ClusterUtils.SHARD_LIST_PATH.getPathArguments().forEach(cursor::enter);
cursor.write(newEntry.getIdentifier(), newEntry);
cursor.close();
return tx.ready();
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class DistributedEntityOwnershipService method getOwnershipState.
@Override
public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) {
Preconditions.checkNotNull(forEntity, "forEntity cannot be null");
DataTree dataTree = getLocalEntityOwnershipShardDataTree();
if (dataTree == null) {
return Optional.absent();
}
java.util.Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode(entityPath(forEntity.getType(), forEntity.getIdentifier()));
if (!entityNode.isPresent()) {
return Optional.absent();
}
// Check if there are any candidates, if there are none we do not really have ownership state
final MapEntryNode entity = (MapEntryNode) entityNode.get();
final java.util.Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID);
final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0;
if (!hasCandidates) {
return Optional.absent();
}
MemberName localMemberName = context.getCurrentMemberName();
java.util.Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID);
String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null;
boolean hasOwner = !Strings.isNullOrEmpty(owner);
boolean isOwner = hasOwner && localMemberName.getName().equals(owner);
return Optional.of(EntityOwnershipState.from(isOwner, hasOwner));
}
Aggregations