package org.opendaylight.controller.cluster.datastore.utils;
+import akka.cluster.ddata.Key;
+import akka.cluster.ddata.ORMap;
+import akka.cluster.ddata.ORMapKey;
+import java.util.Map;
import org.opendaylight.controller.cluster.access.concepts.MemberName;
+import org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration;
import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
/**
* Utils for encoding prefix shard name.
*/
public class ClusterUtils {
+ // key for replicated configuration key
+ public static final Key<ORMap<PrefixShardConfiguration>> CONFIGURATION_KEY =
+ ORMapKey.create("prefix-shard-configuration");
+
public static ShardIdentifier getShardIdentifier(final MemberName memberName, final DOMDataTreeIdentifier prefix) {
- return ShardIdentifier
- .create(getCleanShardName(prefix.getRootIdentifier()), memberName, prefix.getDatastoreType().name());
+ final String type;
+ switch (prefix.getDatastoreType()) {
+ case OPERATIONAL:
+ type = "operational";
+ break;
+ case CONFIGURATION:
+ type = "config";
+ break;
+ default:
+ type = prefix.getDatastoreType().name();
+ }
+
+ return ShardIdentifier.create(getCleanShardName(prefix.getRootIdentifier()), memberName, type);
}
/**
* @return encoded name that doesn't contain characters that cannot be in actor path.
*/
public static String getCleanShardName(final YangInstanceIdentifier path) {
+ if (path.isEmpty()) {
+ return "default";
+ }
+
final StringBuilder builder = new StringBuilder();
// TODO need a better mapping that includes namespace, but we'll need to cleanup the string beforehand
+ // we have to fight both javax and akka url path restrictions..
path.getPathArguments().forEach(p -> {
builder.append(p.getNodeType().getLocalName());
+ if (p instanceof NodeIdentifierWithPredicates) {
+ builder.append("-key_");
+ final Map<QName, Object> key = ((NodeIdentifierWithPredicates) p).getKeyValues();
+ key.entrySet().forEach(e -> {
+ builder.append(e.getKey().getLocalName());
+ builder.append(e.getValue());
+ builder.append("-");
+ });
+ builder.append("_");
+ }
builder.append("!");
});
return builder.toString();