From 403072390b3a70a3bc6cd0071adc574ee97a3f66 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Mon, 28 Sep 2015 07:29:51 -0400 Subject: [PATCH] Add general-entity yang to common Change-Id: Iebf021d92a475174ceadb76895b5553b37df06ed Signed-off-by: Tom Pantelis --- binding/mdsal-binding-api/pom.xml | 4 ++ .../mdsal/binding/api/clustering/Entity.java | 13 ++-- .../binding/api/clustering/EntityTest.java | 28 ++++++--- common/artifacts/pom.xml | 6 +- common/features/pom.xml | 4 ++ .../features/src/main/features/features.xml | 1 + common/parent/pom.xml | 13 ++-- .../mdsal/dom/api/clustering/DOMEntity.java | 18 +++--- .../dom/api/clustering/DOMEntityTest.java | 61 +++++++++++++++++++ model/general-entity/pom.xml | 24 ++++++++ .../src/main/yang/odl-general-entity.yang | 17 ++++++ model/pom.xml | 1 + 12 files changed, 162 insertions(+), 28 deletions(-) create mode 100644 dom/mdsal-dom-api/src/test/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntityTest.java create mode 100644 model/general-entity/pom.xml create mode 100644 model/general-entity/src/main/yang/odl-general-entity.yang diff --git a/binding/mdsal-binding-api/pom.xml b/binding/mdsal-binding-api/pom.xml index 6dc2e329c5..405926d127 100644 --- a/binding/mdsal-binding-api/pom.xml +++ b/binding/mdsal-binding-api/pom.xml @@ -19,6 +19,10 @@ org.opendaylight.mdsal mdsal-common-api + + org.opendaylight.mdsal.model + general-entity + org.opendaylight.yangtools concepts diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/Entity.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/Entity.java index b6bb79d4d2..aaa2a7cd1d 100644 --- a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/Entity.java +++ b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/Entity.java @@ -8,8 +8,10 @@ package org.opendaylight.mdsal.binding.api.clustering; import com.google.common.annotations.Beta; +import com.google.common.base.Preconditions; import javax.annotation.Nonnull; import org.opendaylight.mdsal.common.api.clustering.GenericEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.EntityKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** @@ -37,10 +39,9 @@ public class Entity extends GenericEntity> { * @param type the type of the entity * @param entityName the name of the entity used to construct a general-entity InstanceIdentifier */ - // FIXME: needs to be enabled in a follow-up -// public Entity(@Nonnull String type, @Nonnull String entityName) { -// super(type, InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml. -// ns.yang.controller.md.sal.core.general.entity.rev150820.Entity.class, -// new EntityKey(Preconditions.checkNotNull(entityName, "entityName should not be null"))).build()); -// } + public Entity(@Nonnull String type, @Nonnull String entityName) { + super(type, InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang. + mdsal.core.general.entity.rev150930.Entity.class, + new EntityKey(Preconditions.checkNotNull(entityName, "entityName should not be null"))).build()); + } } diff --git a/binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/clustering/EntityTest.java b/binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/clustering/EntityTest.java index 96efb40245..2a5acfd209 100644 --- a/binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/clustering/EntityTest.java +++ b/binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/clustering/EntityTest.java @@ -8,11 +8,13 @@ package org.opendaylight.mdsal.binding.api.clustering; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotEquals; import org.apache.commons.lang3.SerializationUtils; import org.junit.Test; import org.opendaylight.yangtools.yang.binding.DataContainer; import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.Identifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** @@ -34,13 +36,6 @@ public class EntityTest { assertNotEquals("hashCode", entity1.hashCode(), new Entity(ENTITY_TYPE2, ID2).hashCode()); } - static class TestDataObject1 implements DataObject { - @Override - public Class getImplementedInterface() { - return null; - } - } - @Test public void testEquals() { Entity entity1 = new Entity(ENTITY_TYPE1, ID1); @@ -48,7 +43,7 @@ public class EntityTest { assertEquals("Same", true, entity1.equals(entity1)); assertEquals("Same", true, entity1.equals(new Entity(ENTITY_TYPE1, ID1))); assertEquals("Different entity type", false, entity1.equals(new Entity(ENTITY_TYPE2, ID1))); - assertEquals("Different yang ID", false, entity1.equals(new Entity(ENTITY_TYPE1, ID2))); + assertEquals("Different entity ID", false, entity1.equals(new Entity(ENTITY_TYPE1, ID2))); assertEquals("Different Object", false, entity1.equals(new Object())); assertEquals("Equals null", false, entity1.equals(null)); } @@ -63,6 +58,23 @@ public class EntityTest { assertEquals("getId", entity.getIdentifier(), clone.getIdentifier()); } + @Test + public void testEntityNameConstructor() { + Entity entity = new Entity(ENTITY_TYPE1, "foo"); + + Identifier keyID = entity.getIdentifier().firstKeyOf( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.Entity.class); + assertNotNull("List key not found", keyID); + } + + static class TestDataObject1 implements DataObject { + @Override + public Class getImplementedInterface() { + return null; + } + } + static class TestDataObject2 implements DataObject { @Override public Class getImplementedInterface() { diff --git a/common/artifacts/pom.xml b/common/artifacts/pom.xml index e716496e1e..46e0c6cded 100644 --- a/common/artifacts/pom.xml +++ b/common/artifacts/pom.xml @@ -120,7 +120,11 @@ yang-ext 2013.09.07.8-SNAPSHOT - + + org.opendaylight.mdsal.model + general-entity + 0.8.0-SNAPSHOT + org.opendaylight.mdsal mdsal-binding-test-model diff --git a/common/features/pom.xml b/common/features/pom.xml index 2750ef55c3..9b6a15b3a9 100644 --- a/common/features/pom.xml +++ b/common/features/pom.xml @@ -121,5 +121,9 @@ ${project.groupId}.model yang-ext + + ${project.groupId}.model + general-entity + diff --git a/common/features/src/main/features/features.xml b/common/features/src/main/features/features.xml index 3c037489c9..f45cf1ef2f 100644 --- a/common/features/src/main/features/features.xml +++ b/common/features/src/main/features/features.xml @@ -64,6 +64,7 @@ odl-mdsal-common odl-mdsal-binding-base + mvn:org.opendaylight.mdsal.model/general-entity/{{VERSION}} mvn:org.opendaylight.mdsal/mdsal-binding-api/{{VERSION}} mvn:org.opendaylight.mdsal/mdsal-binding-util/{{VERSION}} diff --git a/common/parent/pom.xml b/common/parent/pom.xml index 07a4fbbb38..f40144db86 100644 --- a/common/parent/pom.xml +++ b/common/parent/pom.xml @@ -25,6 +25,7 @@ 0.8.0-SNAPSHOT + target/generated-sources/sal 1.2 @@ -268,16 +269,16 @@ org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl - target/generated-sources/sal + ${salGeneratorPath} org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl - target/site/restconf + target/site/models org.opendaylight.yangtools.yang.wadl.generator.maven.WadlGenerator - target/site/restconf + target/site/models true @@ -341,7 +342,7 @@ target/generated-sources/parser - target/generated-sources/sal + ${salGeneratorPath} ${basedir}/src/main/xtend-gen @@ -425,6 +426,10 @@ org.apache.maven.plugins maven-javadoc-plugin + + org.codehaus.mojo + build-helper-maven-plugin + diff --git a/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntity.java b/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntity.java index b9180e5c82..4b567a55ee 100644 --- a/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntity.java +++ b/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntity.java @@ -8,8 +8,10 @@ package org.opendaylight.mdsal.dom.api.clustering; import com.google.common.annotations.Beta; +import com.google.common.base.Preconditions; import javax.annotation.Nonnull; import org.opendaylight.mdsal.common.api.clustering.GenericEntity; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; /** @@ -21,10 +23,9 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; public class DOMEntity extends GenericEntity { private static final long serialVersionUID = 1L; - // FIXME: needs update once the model is in -// 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"); + static final QName ENTITY = QName.create( + "urn:opendaylight:params:xml:ns:yang:mdsal:core:general-entity", "2015-09-30", "entity").intern(); + static final QName ENTITY_NAME = QName.create(ENTITY, "name").intern(); /** Constructs an instance. @@ -43,9 +44,8 @@ public class DOMEntity extends GenericEntity { * @param type the type of the entity * @param entityName the name of the entity used to construct a general-entity YangInstanceIdentifier */ - // FIXME: needs update once the model is in -// public DOMEntity(@Nonnull String type, @Nonnull String entityName) { -// super(type, YangInstanceIdentifier.builder().node(ENTITY_QNAME).nodeWithKey(ENTITY_QNAME, ENTITY_NAME, -// Preconditions.checkNotNull(entityName, "entityName should not be null")).build()); -// } + public DOMEntity(@Nonnull String type, @Nonnull String entityName) { + super(type, YangInstanceIdentifier.builder().node(ENTITY).nodeWithKey(ENTITY, ENTITY_NAME, + Preconditions.checkNotNull(entityName, "entityName should not be null")).build()); + } } diff --git a/dom/mdsal-dom-api/src/test/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntityTest.java b/dom/mdsal-dom-api/src/test/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntityTest.java new file mode 100644 index 0000000000..cfe15586cf --- /dev/null +++ b/dom/mdsal-dom-api/src/test/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntityTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.mdsal.dom.api.clustering; + +import static org.opendaylight.mdsal.dom.api.clustering.DOMEntity.ENTITY; +import static org.junit.Assert.*; +import java.util.List; +import java.util.Map.Entry; +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; + +/** + * @author Thomas Pantelis + */ +public class DOMEntityTest { + static String ENTITY_TYPE1 = "type1"; + static String ENTITY_TYPE2 = "type2"; + static final YangInstanceIdentifier ID1 = YangInstanceIdentifier.of(QName.create("test", "2015-11-24", "one")); + static final YangInstanceIdentifier ID2 = YangInstanceIdentifier.of(QName.create("test", "2015-11-24", "two")); + + @Test + public void testHashCode() { + DOMEntity entity1 = new DOMEntity(ENTITY_TYPE1, ID1); + + assertEquals("hashCode", entity1.hashCode(), new DOMEntity(ENTITY_TYPE1, ID1).hashCode()); + assertNotEquals("hashCode", entity1.hashCode(), new DOMEntity(ENTITY_TYPE2, ID2).hashCode()); + } + + @Test + public void testEquals() { + DOMEntity entity1 = new DOMEntity(ENTITY_TYPE1, ID1); + + assertEquals("Same", true, entity1.equals(entity1)); + assertEquals("Same", true, entity1.equals(new DOMEntity(ENTITY_TYPE1, ID1))); + assertEquals("Different entity type", false, entity1.equals(new DOMEntity(ENTITY_TYPE2, ID1))); + assertEquals("Different entity ID", false, entity1.equals(new DOMEntity(ENTITY_TYPE1, ID2))); + assertEquals("Different Object", false, entity1.equals(new Object())); + assertEquals("Equals null", false, entity1.equals(null)); + } + + @Test + public void testEntityNameConstructor() { + DOMEntity entity = new DOMEntity(ENTITY_TYPE1, "foo"); + + List pathArgs = entity.getIdentifier().getPathArguments(); + assertEquals("pathArgs size", 2, pathArgs.size()); + assertEquals("First PathArgument node type", ENTITY, pathArgs.get(0).getNodeType()); + assertEquals("Second PathArgument node type", ENTITY, pathArgs.get(1).getNodeType()); + Entry key = ((NodeIdentifierWithPredicates) pathArgs.get(1)).getKeyValues().entrySet().iterator().next(); + assertEquals("Key node type", QName.create(ENTITY, "name"), key.getKey()); + assertEquals("Key value", "foo", key.getValue()); + } +} diff --git a/model/general-entity/pom.xml b/model/general-entity/pom.xml new file mode 100644 index 0000000000..9427560d6f --- /dev/null +++ b/model/general-entity/pom.xml @@ -0,0 +1,24 @@ + + + + + + + model-parent + org.opendaylight.mdsal.model + 0.8.0-SNAPSHOT + + + 4.0.0 + general-entity + ${project.artifactId} + ${project.artifactId} + bundle + + diff --git a/model/general-entity/src/main/yang/odl-general-entity.yang b/model/general-entity/src/main/yang/odl-general-entity.yang new file mode 100644 index 0000000000..9a68ebf29b --- /dev/null +++ b/model/general-entity/src/main/yang/odl-general-entity.yang @@ -0,0 +1,17 @@ +module odl-general-entity { + namespace "urn:opendaylight:params:xml:ns:yang:mdsal:core:general-entity"; + prefix "odl-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-09-30 { + description "Initial revision"; + } + + list entity { + key name; + leaf name { + type string; + } + } +} \ No newline at end of file diff --git a/model/pom.xml b/model/pom.xml index cd66297edc..4d06d8ac2f 100644 --- a/model/pom.xml +++ b/model/pom.xml @@ -34,6 +34,7 @@ iana ietf l2-types + general-entity -- 2.36.6