Search in sources :

Example 1 with PrefixShardStrategy

use of org.opendaylight.controller.cluster.datastore.shardstrategy.PrefixShardStrategy 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)

Aggregations

SimpleEntry (java.util.AbstractMap.SimpleEntry)1 PrefixShardStrategy (org.opendaylight.controller.cluster.datastore.shardstrategy.PrefixShardStrategy)1 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)1