use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException 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.DOMDataTreeProducerException in project controller by opendaylight.
the class PrefixShardHandler method ensureListExists.
private ListenableFuture<Void> ensureListExists() {
final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = ImmutableNodes.mapNodeBuilder(ID_INT);
// hardcoded initial list population for parallel produce-transactions testing on multiple nodes
for (int i = 1; i < MAX_PREFIX; i++) {
mapBuilder.withChild(ImmutableNodes.mapEntryBuilder(ID_INT, ID, PREFIX_TEMPLATE + i).withChild(ImmutableNodes.mapNodeBuilder(ITEM).build()).build());
}
final MapNode mapNode = mapBuilder.build();
final ContainerNode containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ID_INTS)).withChild(mapNode).build();
final DOMDataTreeProducer producer = domDataTreeService.createProducer(Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY)));
final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(false);
final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY));
cursor.merge(containerNode.getIdentifier(), containerNode);
cursor.close();
final ListenableFuture<Void> future = tx.submit();
Futures.addCallback(future, new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
try {
LOG.debug("Closing producer for initial list.");
producer.close();
} catch (DOMDataTreeProducerException e) {
LOG.warn("Error while closing producer.", e);
}
}
@Override
public void onFailure(final Throwable throwable) {
// NOOP handled by the caller of this method.
}
}, MoreExecutors.directExecutor());
return future;
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException in project controller by opendaylight.
the class ShardedDataTreeActor method onNotifyProducerRemoved.
private void onNotifyProducerRemoved(final NotifyProducerRemoved message) {
LOG.debug("Received NotifyProducerRemoved: {}", message);
final ActorProducerRegistration registration = idToProducer.remove(message.getSubtrees().iterator().next());
if (registration == null) {
LOG.warn("The notification contained a path on which no producer is registered, throwing away");
getSender().tell(new Status.Success(null), noSender());
return;
}
try {
registration.close();
getSender().tell(new Status.Success(null), noSender());
} catch (final DOMDataTreeProducerException e) {
LOG.error("Unable to close producer", e);
getSender().tell(new Status.Failure(e), noSender());
}
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException in project controller by opendaylight.
the class PrefixLeaderHandler method makeLeaderLocal.
public ListenableFuture<RpcResult<Void>> makeLeaderLocal(final BecomePrefixLeaderInput input) {
final YangInstanceIdentifier yid = serializer.toYangInstanceIdentifier(input.getPrefix());
final DOMDataTreeIdentifier prefix = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yid);
try (CDSDataTreeProducer producer = (CDSDataTreeProducer) domDataTreeService.createProducer(Collections.singleton(prefix))) {
final CDSShardAccess shardAccess = producer.getShardAccess(prefix);
final CompletionStage<Void> completionStage = shardAccess.makeLeaderLocal();
completionStage.exceptionally(throwable -> {
LOG.error("Leader movement failed.", throwable);
return null;
});
} catch (final DOMDataTreeProducerException e) {
LOG.warn("Error while closing producer", e);
} catch (final TimeoutException e) {
LOG.warn("Timeout while on producer operation", e);
Futures.immediateFuture(RpcResultBuilder.failed().withError(RpcError.ErrorType.RPC, "resource-denied-transport", "Timeout while opening producer please retry.", "clustering-it", "clustering-it", e));
}
return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
}
Aggregations