Search in sources :

Example 96 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class PrefixShardHandler method onRemovePrefixShard.

public ListenableFuture<RpcResult<Void>> onRemovePrefixShard(final RemovePrefixShardInput input) {
    final YangInstanceIdentifier identifier = serializer.toYangInstanceIdentifier(input.getPrefix());
    final DistributedShardRegistration registration = registrations.get(identifier);
    if (registration == null) {
        final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "registration-missing", "No shard registered at this prefix.");
        return Futures.immediateFuture(RpcResultBuilder.<Void>failed().withRpcError(error).build());
    }
    final SettableFuture<RpcResult<Void>> future = SettableFuture.create();
    final CompletionStage<Void> close = registration.close();
    close.thenRun(() -> future.set(RpcResultBuilder.<Void>success().build()));
    close.exceptionally(throwable -> {
        LOG.warn("Shard[{}] removal failed:", identifier, throwable);
        final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "remove-shard-failed", "Shard removal failed", "cluster-test-app", "", throwable);
        future.set(RpcResultBuilder.<Void>failed().withRpcError(error).build());
        return null;
    });
    return future;
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 97 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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;
}
Also used : DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ProduceTransactionsOutput(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.ProduceTransactionsOutput) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 98 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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();
}
Also used : MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 99 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class AbstractDataStore method registerCommitCohort.

@Override
public <C extends DOMDataTreeCommitCohort> DOMDataTreeCommitCohortRegistration<C> registerCommitCohort(final DOMDataTreeIdentifier subtree, final C cohort) {
    YangInstanceIdentifier treeId = Preconditions.checkNotNull(subtree, "subtree should not be null").getRootIdentifier();
    Preconditions.checkNotNull(cohort, "listener should not be null");
    final String shardName = actorContext.getShardStrategyFactory().getStrategy(treeId).findShard(treeId);
    LOG.debug("Registering cohort: {} for tree: {} shard: {}", cohort, treeId, shardName);
    DataTreeCohortRegistrationProxy<C> cohortProxy = new DataTreeCohortRegistrationProxy<>(actorContext, subtree, cohort);
    cohortProxy.init(shardName);
    return cohortProxy;
}
Also used : YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 100 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class DefaultShardDataChangeListenerPublisher method submitNotifications.

@Override
public void submitNotifications(final DataChangeListenerRegistration<?> listener, final Iterable<DOMImmutableDataChangeEvent> notifications) {
    final AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> instance = listener.getInstance();
    LOG.debug("{}: Notifying listener {} about {}", logContext, instance, notifications);
    for (DOMImmutableDataChangeEvent n : notifications) {
        instance.onDataChanged(n);
    }
}
Also used : DOMImmutableDataChangeEvent(org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)187 Test (org.junit.Test)111 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)34 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 ActorRef (akka.actor.ActorRef)19 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)19 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)15 TestActorRef (akka.testkit.TestActorRef)14 TestKit (akka.testkit.javadsl.TestKit)13 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)12 ArrayList (java.util.ArrayList)11 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)10 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)10 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)10 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)10 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)9 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)9 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9