use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.
the class DistributedShardedDOMDataTree method createShardFrontend.
private void createShardFrontend(final DOMDataTreeIdentifier prefix) {
LOG.debug("{}: Creating CDS shard for prefix: {}", memberName, prefix);
final String shardName = ClusterUtils.getCleanShardName(prefix.getRootIdentifier());
final AbstractDataStore distributedDataStore = prefix.getDatastoreType().equals(org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION) ? distributedConfigDatastore : distributedOperDatastore;
try (DOMDataTreeProducer producer = localCreateProducer(Collections.singletonList(prefix))) {
final Entry<DataStoreClient, ActorRef> entry = createDatastoreClient(shardName, distributedDataStore.getActorContext());
final DistributedShardFrontend shard = new DistributedShardFrontend(distributedDataStore, entry.getKey(), prefix);
final DOMDataTreeShardRegistration<DOMDataTreeShard> reg = shardedDOMDataTree.registerDataTreeShard(prefix, shard, producer);
synchronized (shards) {
shards.store(prefix, reg);
}
} catch (final DOMDataTreeShardingConflictException e) {
LOG.error("{}: Prefix {} is already occupied by another shard", distributedConfigDatastore.getActorContext().getClusterWrapper().getCurrentMemberName(), prefix, e);
} catch (DOMDataTreeProducerException e) {
LOG.error("Unable to close producer", e);
} catch (DOMDataTreeShardCreationFailedException e) {
LOG.error("Unable to create datastore client for shard {}", prefix, e);
}
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.
the class DistributedShardedDOMDataTree method createProducer.
@Nonnull
@Override
public DOMDataTreeProducer createProducer(@Nonnull final Collection<DOMDataTreeIdentifier> subtrees) {
LOG.debug("{} - Creating producer for {}", memberName, subtrees);
final DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(subtrees);
final Object response = distributedConfigDatastore.getActorContext().executeOperation(shardedDataTreeActor, new ProducerCreated(subtrees));
if (response == null) {
LOG.debug("{} - Received success from remote nodes, creating producer:{}", memberName, subtrees);
return new ProxyProducer(producer, subtrees, shardedDataTreeActor, distributedConfigDatastore.getActorContext(), shards);
}
closeProducer(producer);
if (response instanceof Throwable) {
Throwables.throwIfUnchecked((Throwable) response);
throw new RuntimeException((Throwable) response);
}
throw new RuntimeException("Unexpected response to create producer received." + response);
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.
the class DistributedShardedDOMDataTreeRemotingTest method testProducerRegistrations.
@Test
public void testProducerRegistrations() throws Exception {
LOG.info("testProducerRegistrations starting");
initEmptyDatastores();
leaderTestKit.waitForMembersUp("member-2");
// TODO refactor shard creation and verification to own method
final DistributedShardRegistration shardRegistration = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
leaderTestKit.waitUntilLeader(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
final ActorRef leaderShardManager = leaderConfigDatastore.getActorContext().getShardManager();
assertNotNull(findLocalShard(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier())));
assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier())));
final Set<String> peers = new HashSet<>();
IntegrationTestKit.verifyShardState(leaderConfigDatastore, ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()), onDemandShardState -> peers.addAll(onDemandShardState.getPeerAddresses().values()));
assertEquals(peers.size(), 1);
final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
try {
followerShardFactory.createProducer(Collections.singleton(TEST_ID));
fail("Producer should be already registered on the other node");
} catch (final IllegalArgumentException e) {
assertTrue(e.getMessage().contains("is attached to producer"));
}
producer.close();
final DOMDataTreeProducer followerProducer = followerShardFactory.createProducer(Collections.singleton(TEST_ID));
try {
leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
fail("Producer should be already registered on the other node");
} catch (final IllegalArgumentException e) {
assertTrue(e.getMessage().contains("is attached to producer"));
}
followerProducer.close();
// try to create a shard on an already registered prefix on follower
try {
waitOnAsyncTask(followerShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
fail("This prefix already should have a shard registration that was forwarded from the other node");
} catch (final DOMDataTreeShardingConflictException e) {
assertTrue(e.getMessage().contains("is already occupied by another shard"));
}
shardRegistration.close().toCompletableFuture().get();
LOG.info("testProducerRegistrations ending");
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.
the class DistributedShardedDOMDataTreeTest method testMultipleShardLevels.
// top level shard at TEST element, with subshards on each outer-list map entry
@Test
@Ignore
public void testMultipleShardLevels() throws Exception {
initEmptyDatastores();
final DistributedShardRegistration testShardReg = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, SINGLE_MEMBER), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
final ArrayList<DistributedShardRegistration> registrations = new ArrayList<>();
final int listSize = 5;
for (int i = 0; i < listSize; i++) {
final YangInstanceIdentifier entryYID = getOuterListIdFor(i);
final CompletionStage<DistributedShardRegistration> future = leaderShardFactory.createDistributedShard(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, entryYID), SINGLE_MEMBER);
registrations.add(waitOnAsyncTask(future, DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION));
}
final DOMDataTreeIdentifier rootId = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singletonList(rootId));
DOMDataTreeCursorAwareTransaction transaction = producer.createTransaction(false);
DOMDataTreeWriteCursor cursor = transaction.createCursor(rootId);
assertNotNull(cursor);
final MapNode outerList = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
final ContainerNode testNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(outerList).build();
cursor.write(testNode.getIdentifier(), testNode);
cursor.close();
transaction.submit().checkedGet();
final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
final MapNode wholeList = ImmutableMapNodeBuilder.create(outerList).withValue(createOuterEntries(listSize, "testing-values")).build();
transaction = producer.createTransaction(false);
cursor = transaction.createCursor(TEST_ID);
assertNotNull(cursor);
cursor.write(wholeList.getIdentifier(), wholeList);
cursor.close();
transaction.submit().checkedGet();
leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID), true, Collections.emptyList());
verify(mockedDataTreeListener, timeout(35000).atLeast(2)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
verifyNoMoreInteractions(mockedDataTreeListener);
final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> allSubtrees = captorForSubtrees.getAllValues();
final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> lastSubtree = allSubtrees.get(allSubtrees.size() - 1);
final NormalizedNode<?, ?> actual = lastSubtree.get(TEST_ID);
assertNotNull(actual);
final NormalizedNode<?, ?> expected = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableMapNodeBuilder.create(outerList).withValue(createOuterEntries(listSize, "testing-values")).build()).build();
for (final DistributedShardRegistration registration : registrations) {
waitOnAsyncTask(registration.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
}
waitOnAsyncTask(testShardReg.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
assertEquals(expected, actual);
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.
the class DistributedShardedDOMDataTreeTest method testWritesIntoDefaultShard.
@Test
public void testWritesIntoDefaultShard() throws Exception {
initEmptyDatastores();
final DOMDataTreeIdentifier configRoot = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(true);
final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY));
Assert.assertNotNull(cursor);
final ContainerNode test = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build();
cursor.write(test.getIdentifier(), test);
cursor.close();
tx.submit().checkedGet();
}
Aggregations