From: Tom Pantelis Date: Wed, 12 Aug 2015 04:57:45 +0000 (-0400) Subject: Bug 4105: Add general-entities yang model X-Git-Tag: release/beryllium~302 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=965b1f2fd427539206619a5df80520d217118170 Bug 4105: Add general-entities yang model Added a general-entities yang model tha can be used to represent an entity ID when no existing yang schema exists. Change-Id: Iec815966fe21ec15cb78ff47c68cda0aa7ae8504 Signed-off-by: Tom Pantelis --- diff --git a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/clustering/Entity.java b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/clustering/Entity.java index 93d001216a..35f23a490b 100644 --- a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/clustering/Entity.java +++ b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/clustering/Entity.java @@ -11,6 +11,7 @@ package org.opendaylight.controller.md.sal.common.api.clustering; import com.google.common.base.Preconditions; import java.io.Serializable; import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; /** @@ -29,17 +30,25 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; *

* The identifier is a YangInstanceIdentifier. The reason for the choice of YangInstanceIdentifier is because it * can easily be used to represent a data node. For example an inventory node represents a shared entity and it is best - * referenced by the YangInstanceIdentifier if the inventory node stored in the data store. + * referenced by the YangInstanceIdentifier if the inventory node is stored in the data store. + *

+ * Note that an entity identifier must conform to a valid yang schema. If there is no existing yang schema to + * represent an entity, the general-entity yang model can be used. + *

*

*/ public final class Entity implements Serializable { private static final long serialVersionUID = 1L; + private static final QName ENTITY_QNAME = + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.core.general.entity.rev150820.Entity.QNAME; + private static final QName ENTITY_NAME = QName.create(ENTITY_QNAME, "name"); + private final String type; private final YangInstanceIdentifier id; /** - * Construct a new Entity + * Construct an Entity with a YangInstanceIdentifier. * * @param type the type of the entity * @param id the identifier of the entity @@ -49,6 +58,19 @@ public final class Entity implements Serializable { this.id = Preconditions.checkNotNull(id, "id should not be null"); } + /** + * Construct an Entity with an with a name. The general-entity schema is used to construct the + * YangInstanceIdentifier. + * + * @param type the type of the entity + * @param entityName the name of the entity used to construct a general-entity YangInstanceIdentifier + */ + public Entity(@Nonnull String type, @Nonnull String entityName) { + this.type = Preconditions.checkNotNull(type, "type should not be null"); + this.id = YangInstanceIdentifier.builder().node(ENTITY_QNAME).nodeWithKey(ENTITY_QNAME, ENTITY_NAME, + Preconditions.checkNotNull(entityName, "entityName should not be null")).build(); + } + /** * * @return id of entity diff --git a/opendaylight/md-sal/sal-common-api/src/main/yang/general-entity.yang b/opendaylight/md-sal/sal-common-api/src/main/yang/general-entity.yang new file mode 100644 index 0000000000..ce21e25b88 --- /dev/null +++ b/opendaylight/md-sal/sal-common-api/src/main/yang/general-entity.yang @@ -0,0 +1,17 @@ +module general-entity { + namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:general-entity"; + prefix "general-entity"; + + description "Defines a model to describe a general entity whose path can be used as an ID for an entity that isn't otherwise modelled"; + + revision 2015-08-20 { + description "Initial revision"; + } + + list entity { + key name; + leaf name { + type string; + } + } +} \ No newline at end of file