use of org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.
the class ProduceTransactionsHandler method start.
public static ListenableFuture<RpcResult<ProduceTransactionsOutput>> start(final DOMDataTreeService domDataTreeService, final ProduceTransactionsInput input) {
final String id = input.getId();
LOG.debug("Filling the item list {} with initial values.", id);
final YangInstanceIdentifier idListWithKey = ID_INT_YID.node(new NodeIdentifierWithPredicates(ID_INT, ID, id));
final DOMDataTreeProducer itemProducer = domDataTreeService.createProducer(Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, idListWithKey)));
final DOMDataTreeCursorAwareTransaction tx = itemProducer.createTransaction(false);
final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, idListWithKey));
final MapNode list = ImmutableNodes.mapNodeBuilder(ITEM).build();
cursor.write(list.getIdentifier(), list);
cursor.close();
try {
tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOG.warn("Unable to fill the initial item list.", e);
closeProducer(itemProducer);
return Futures.immediateFuture(RpcResultBuilder.<ProduceTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
}
final ProduceTransactionsHandler handler = new ProduceTransactionsHandler(itemProducer, new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, idListWithKey.node(list.getIdentifier()).toOptimized()), input);
// It is handler's responsibility to close itemProducer when the work is finished.
handler.doStart();
return handler.future;
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier 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.mdsal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.
the class DistributedShardedDOMDataTreeTest method testCDSDataTreeProducer.
@Test
public void testCDSDataTreeProducer() throws Exception {
initEmptyDatastores();
final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
final DOMDataTreeIdentifier configRoot = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
assertTrue(producer instanceof CDSDataTreeProducer);
final CDSDataTreeProducer cdsProducer = (CDSDataTreeProducer) producer;
CDSShardAccess shardAccess = cdsProducer.getShardAccess(TEST_ID);
assertEquals(shardAccess.getShardIdentifier(), TEST_ID);
shardAccess = cdsProducer.getShardAccess(INNER_LIST_ID);
assertEquals(TEST_ID, shardAccess.getShardIdentifier());
shardAccess = cdsProducer.getShardAccess(configRoot);
assertEquals(configRoot, shardAccess.getShardIdentifier());
waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.
the class DistributedShardedDOMDataTree method initDefaultShard.
@SuppressWarnings("checkstyle:IllegalCatch")
private void initDefaultShard(final LogicalDatastoreType logicalDatastoreType) throws ExecutionException, InterruptedException {
final PrefixedShardConfigWriter writer = writerMap.get(logicalDatastoreType);
if (writer.checkDefaultIsPresent()) {
LOG.debug("{}: Default shard for {} is already present in the config. Possibly saved in snapshot.", memberName, logicalDatastoreType);
} else {
try {
// Currently the default shard configuration is present in the out-of-box modules.conf and is
// expected to be present. So look up the local default shard here and create the frontend.
// TODO we don't have to do it for config and operational default shard separately. Just one of them
// should be enough
final ActorContext actorContext = logicalDatastoreType == LogicalDatastoreType.CONFIGURATION ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext();
final Optional<ActorRef> defaultLocalShardOptional = actorContext.findLocalShard(ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY));
if (defaultLocalShardOptional.isPresent()) {
LOG.debug("{}: Default shard for {} is already started, creating just frontend", memberName, logicalDatastoreType);
createShardFrontend(new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.EMPTY));
}
// The local shard isn't present - we assume that means the local member isn't in the replica list
// and will be dynamically created later via an explicit add-shard-replica request. This is the
// bootstrapping mechanism to add a new node into an existing cluster. The following code to create
// the default shard as a prefix shard is problematic in this scenario so it is commented out. Since
// the default shard is a module-based shard by default, it makes sense to always treat it as such,
// ie bootstrap it in the same manner as the special prefix-configuration and EOS shards.
// final Collection<MemberName> names = distributedConfigDatastore.getActorContext().getConfiguration()
// .getUniqueMemberNamesForAllShards();
// Await.result(FutureConverters.toScala(createDistributedShard(
// new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.EMPTY), names)),
// SHARD_FUTURE_TIMEOUT_DURATION);
// } catch (DOMDataTreeShardingConflictException e) {
// LOG.debug("{}: Default shard for {} already registered, possibly due to other node doing it faster",
// memberName, logicalDatastoreType);
} catch (Exception e) {
LOG.error("{}: Default shard initialization for {} failed", memberName, logicalDatastoreType, e);
throw new RuntimeException(e);
}
}
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.
the class ShardedDataTreeActor method onLookupPrefixShard.
@SuppressWarnings("checkstyle:IllegalCatch")
private void onLookupPrefixShard(final LookupPrefixShard message) {
LOG.debug("Member: {}, Received LookupPrefixShard: {}", clusterWrapper.getCurrentMemberName(), message);
final DOMDataTreeIdentifier prefix = message.getPrefix();
final ActorContext context = prefix.getDatastoreType() == LogicalDatastoreType.CONFIGURATION ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext();
// schedule a notification task for the reply
actorSystem.scheduler().scheduleOnce(SHARD_LOOKUP_TASK_INTERVAL, new ShardCreationLookupTask(actorSystem, getSender(), clusterWrapper, context, shardingService, prefix, lookupTaskMaxRetries), actorSystem.dispatcher());
}
Aggregations