dba17611300e56898094fb0cf5a8b1342f907da5
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / ClusterUtils.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore.utils;
10
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;
15
16 /**
17  * Utils for encoding prefix shard name.
18  */
19 public class ClusterUtils {
20
21     public static ShardIdentifier getShardIdentifier(final MemberName memberName, final DOMDataTreeIdentifier prefix) {
22         return ShardIdentifier
23                 .create(getCleanShardName(prefix.getRootIdentifier()), memberName, prefix.getDatastoreType().name());
24     }
25
26     /**
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.
29      *
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.
32      */
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());
38             builder.append("!");
39         });
40         return builder.toString();
41     }
42 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.