use of org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.
the class DistributedShardFrontend method createModificationFactory.
DistributedShardModificationFactory createModificationFactory(final Collection<DOMDataTreeIdentifier> prefixes) {
// TODO this could be abstract
final Map<DOMDataTreeIdentifier, SubshardProducerSpecification> affectedSubshards = new HashMap<>();
for (final DOMDataTreeIdentifier producerPrefix : prefixes) {
for (final ChildShardContext maybeAffected : childShards.values()) {
final DOMDataTreeIdentifier bindPath;
if (producerPrefix.contains(maybeAffected.getPrefix())) {
bindPath = maybeAffected.getPrefix();
} else if (maybeAffected.getPrefix().contains(producerPrefix)) {
// Bound path is inside subshard
bindPath = producerPrefix;
} else {
continue;
}
SubshardProducerSpecification spec = affectedSubshards.computeIfAbsent(maybeAffected.getPrefix(), k -> new SubshardProducerSpecification(maybeAffected));
spec.addPrefix(bindPath);
}
}
final DistributedShardModificationFactoryBuilder builder = new DistributedShardModificationFactoryBuilder(shardRoot);
for (final SubshardProducerSpecification spec : affectedSubshards.values()) {
final ForeignShardModificationContext foreignContext = new ForeignShardModificationContext(spec.getPrefix(), spec.createProducer());
builder.addSubshard(foreignContext);
builder.addSubshard(spec.getPrefix(), foreignContext);
}
return builder.build();
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.
the class ShardStrategyFactory method getStrategy.
public ShardStrategy getStrategy(final YangInstanceIdentifier path) {
Preconditions.checkNotNull(path, "path should not be null");
// try with the legacy module based shard mapping
final String moduleName = getModuleName(path);
final ShardStrategy shardStrategy = configuration.getStrategyForModule(moduleName);
if (shardStrategy == null) {
// retry with prefix based sharding
final ShardStrategy strategyForPrefix = configuration.getStrategyForPrefix(new DOMDataTreeIdentifier(logicalStoreType, path));
if (strategyForPrefix == null) {
return DefaultShardStrategy.getInstance();
}
return strategyForPrefix;
}
return shardStrategy;
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.
the class ConfigurationImpl method getStrategyForPrefix.
@Override
public ShardStrategy getStrategyForPrefix(@Nonnull final DOMDataTreeIdentifier prefix) {
Preconditions.checkNotNull(prefix, "Prefix cannot be null");
// FIXME using prefix tables like in mdsal will be better
Entry<DOMDataTreeIdentifier, PrefixShardConfiguration> bestMatchEntry = new SimpleEntry<>(new DOMDataTreeIdentifier(prefix.getDatastoreType(), YangInstanceIdentifier.EMPTY), null);
for (Entry<DOMDataTreeIdentifier, PrefixShardConfiguration> entry : prefixConfigMap.entrySet()) {
if (entry.getKey().contains(prefix) && entry.getKey().getRootIdentifier().getPathArguments().size() > bestMatchEntry.getKey().getRootIdentifier().getPathArguments().size()) {
bestMatchEntry = entry;
}
}
if (bestMatchEntry.getValue() == null) {
return null;
}
return new PrefixShardStrategy(ClusterUtils.getCleanShardName(bestMatchEntry.getKey().getRootIdentifier()), bestMatchEntry.getKey().getRootIdentifier());
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier 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