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;
}
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;
}
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();
}
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;
}
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);
}
}
Aggregations