package org.opendaylight.controller.cluster.datastore.entityownership;
import java.util.Map.Entry;
-import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.EntityOwners;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.EntityType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.Entity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.entity.Candidate;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
*
* @author Thomas Pantelis
*/
-final class EntityOwnersModel {
- static final QName ENTITY_QNAME = org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.
- md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.Entity.QNAME;
+public final class EntityOwnersModel {
+ static final QName ENTITY_QNAME = Entity.QNAME;
static final QName CANDIDATE_NAME_QNAME = QName.create(Candidate.QNAME, "name");
static final QName ENTITY_ID_QNAME = QName.create(ENTITY_QNAME, "id");
static final QName ENTITY_OWNER_QNAME = QName.create(ENTITY_QNAME, "owner");
YangInstanceIdentifier.of(EntityOwners.QNAME).node(EntityType.QNAME);
static YangInstanceIdentifier entityPath(String entityType, YangInstanceIdentifier entityId) {
- return YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH).node(EntityType.QNAME).
- nodeWithKey(EntityType.QNAME, ENTITY_TYPE_QNAME, entityType).node(ENTITY_QNAME).
- nodeWithKey(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).build();
+ return YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH).node(EntityType.QNAME)
+ .nodeWithKey(EntityType.QNAME, ENTITY_TYPE_QNAME, entityType).node(ENTITY_QNAME)
+ .nodeWithKey(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).build();
}
static YangInstanceIdentifier candidatePath(String entityType, YangInstanceIdentifier entityId,
String candidateName) {
- return YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH).node(EntityType.QNAME).
- nodeWithKey(EntityType.QNAME, ENTITY_TYPE_QNAME, entityType).node(ENTITY_QNAME).
- nodeWithKey(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).node(Candidate.QNAME).
- nodeWithKey(Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName).build();
+ return YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH).node(EntityType.QNAME)
+ .nodeWithKey(EntityType.QNAME, ENTITY_TYPE_QNAME, entityType).node(ENTITY_QNAME)
+ .nodeWithKey(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).node(Candidate.QNAME)
+ .nodeWithKey(Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName).build();
}
static ContainerNode entityOwnersWithEntityTypeEntry(MapEntryNode entityTypeNode) {
return ImmutableContainerNodeBuilder.create().withNodeIdentifier(
- ENTITY_OWNERS_NODE_ID).addChild(ImmutableNodes.mapNodeBuilder(EntityType.QNAME).
- addChild(entityTypeNode).build()).build();
+ ENTITY_OWNERS_NODE_ID).addChild(ImmutableNodes.mapNodeBuilder(EntityType.QNAME)
+ .addChild(entityTypeNode).build()).build();
}
static MapEntryNode entityTypeEntryWithEntityEntry(String entityType, MapEntryNode entityNode) {
}
static MapNode candidateEntry(String candidateName) {
- return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(Candidate.QNAME)).
- addChild(candidateMapEntry(candidateName)).build();
+ return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(Candidate.QNAME))
+ .addChild(candidateMapEntry(candidateName)).build();
}
static MapEntryNode candidateMapEntry(String candidateName) {
ImmutableNodes.leafNode(ENTITY_OWNER_QNAME, owner)).build();
}
- static Entity createEntity(YangInstanceIdentifier entityPath) {
+ public static String entityTypeFromEntityPath(YangInstanceIdentifier entityPath) {
+ YangInstanceIdentifier parent = entityPath;
+ while (!parent.isEmpty()) {
+ if (EntityType.QNAME.equals(parent.getLastPathArgument().getNodeType())) {
+ YangInstanceIdentifier.NodeIdentifierWithPredicates entityTypeLastPathArgument =
+ (YangInstanceIdentifier.NodeIdentifierWithPredicates) parent.getLastPathArgument();
+ return (String) entityTypeLastPathArgument.getKeyValues().get(ENTITY_TYPE_QNAME);
+ }
+ parent = parent.getParent();
+ }
+ return null;
+ }
+
+ static DOMEntity createEntity(YangInstanceIdentifier entityPath) {
String entityType = null;
YangInstanceIdentifier entityId = null;
- for(PathArgument pathArg: entityPath.getPathArguments()) {
- if(pathArg instanceof NodeIdentifierWithPredicates) {
+ for (PathArgument pathArg: entityPath.getPathArguments()) {
+ if (pathArg instanceof NodeIdentifierWithPredicates) {
NodeIdentifierWithPredicates nodeKey = (NodeIdentifierWithPredicates) pathArg;
Entry<QName, Object> key = nodeKey.getKeyValues().entrySet().iterator().next();
- if(ENTITY_TYPE_QNAME.equals(key.getKey())) {
+ if (ENTITY_TYPE_QNAME.equals(key.getKey())) {
entityType = key.getValue().toString();
- } else if(ENTITY_ID_QNAME.equals(key.getKey())) {
+ } else if (ENTITY_ID_QNAME.equals(key.getKey())) {
entityId = (YangInstanceIdentifier) key.getValue();
}
}
}
- return new Entity(entityType, entityId);
+ return new DOMEntity(entityType, entityId);
}
}