Search in sources :

Example 21 with DOMDataTreeIdentifier

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();
}
Also used : ChildShardContext(org.opendaylight.mdsal.dom.spi.shard.ChildShardContext) SubshardProducerSpecification(org.opendaylight.mdsal.dom.spi.shard.SubshardProducerSpecification) HashMap(java.util.HashMap) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ForeignShardModificationContext(org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext)

Example 22 with DOMDataTreeIdentifier

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;
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)

Example 23 with DOMDataTreeIdentifier

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());
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) SimpleEntry(java.util.AbstractMap.SimpleEntry) PrefixShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.PrefixShardStrategy)

Example 24 with DOMDataTreeIdentifier

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());
}
Also used : DOMDataTreeProducerException(org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CDSShardAccess(org.opendaylight.controller.cluster.dom.api.CDSShardAccess) CDSDataTreeProducer(org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer) TimeoutException(org.opendaylight.controller.cluster.datastore.exceptions.TimeoutException)

Aggregations

DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)24 Test (org.junit.Test)9 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 DOMDataTreeProducer (org.opendaylight.mdsal.dom.api.DOMDataTreeProducer)6 ActorRef (akka.actor.ActorRef)5 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)5 DistributedShardRegistration (org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration)5 DOMDataTreeCursorAwareTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction)5 DOMDataTreeWriteCursor (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor)5 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)4 ArrayList (java.util.ArrayList)3 DOMDataTreeProducerException (org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 Status (akka.actor.Status)2 Success (akka.actor.Status.Success)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 Collection (java.util.Collection)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2