2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore.utils;
11 import org.opendaylight.controller.cluster.access.concepts.MemberName;
12 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
13 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 * Utils for encoding prefix shard name.
19 public class ClusterUtils {
21 public static ShardIdentifier getShardIdentifier(final MemberName memberName, final DOMDataTreeIdentifier prefix) {
22 return ShardIdentifier
23 .create(getCleanShardName(prefix.getRootIdentifier()), memberName, prefix.getDatastoreType().name());
27 * Returns an encoded shard name based on the provided path that should doesn't contain characters that cannot be
28 * present in akka actor paths.
30 * @param path Path on which to base the shard name
31 * @return encoded name that doesn't contain characters that cannot be in actor path.
33 public static String getCleanShardName(final YangInstanceIdentifier path) {
34 final StringBuilder builder = new StringBuilder();
35 // TODO need a better mapping that includes namespace, but we'll need to cleanup the string beforehand
36 path.getPathArguments().forEach(p -> {
37 builder.append(p.getNodeType().getLocalName());
40 return builder.toString();