Add general-entity yang to common 84/27684/9
authorTom Pantelis <tpanteli@brocade.com>
Mon, 28 Sep 2015 11:29:51 +0000 (07:29 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Sun, 6 Dec 2015 10:26:58 +0000 (10:26 +0000)
Change-Id: Iebf021d92a475174ceadb76895b5553b37df06ed
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
12 files changed:
binding/mdsal-binding-api/pom.xml
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/Entity.java
binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/clustering/EntityTest.java
common/artifacts/pom.xml
common/features/pom.xml
common/features/src/main/features/features.xml
common/parent/pom.xml
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntity.java
dom/mdsal-dom-api/src/test/java/org/opendaylight/mdsal/dom/api/clustering/DOMEntityTest.java [new file with mode: 0644]
model/general-entity/pom.xml [new file with mode: 0644]
model/general-entity/src/main/yang/odl-general-entity.yang [new file with mode: 0644]
model/pom.xml

index 6dc2e329c5984314cf634b9863093956fa38291e..405926d12712b0e2e7cfcd07fdbccdb1f1a5faef 100644 (file)
       <groupId>org.opendaylight.mdsal</groupId>
       <artifactId>mdsal-common-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.mdsal.model</groupId>
+      <artifactId>general-entity</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>concepts</artifactId>
index b6bb79d4d20688dd1567fb3e319d9bbc4e5b1645..aaa2a7cd1dee055adb7d14c618c20ece9aae9b4b 100644 (file)
@@ -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<InstanceIdentifier<?>> {
      * @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());
+    }
 }
index 96efb402452e9d4885770f1898c41ecc815a3be8..2a5acfd209593dbeff2099787e9d22a13e241b4a 100644 (file)
@@ -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<? extends DataContainer> 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<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.
+        mdsal.core.general.entity.rev150930.Entity> 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<? extends DataContainer> getImplementedInterface() {
+            return null;
+        }
+    }
+
     static class TestDataObject2 implements DataObject {
         @Override
         public Class<? extends DataContainer> getImplementedInterface() {
index e716496e1e442bd5eb1e1f209e353f3e9f43ae81..46e0c6cded47a070d9268625a2ec7c4aec294f43 100644 (file)
                 <artifactId>yang-ext</artifactId>
                 <version>2013.09.07.8-SNAPSHOT</version>
             </dependency>
-
+            <dependency>
+                <groupId>org.opendaylight.mdsal.model</groupId>
+                <artifactId>general-entity</artifactId>
+                <version>0.8.0-SNAPSHOT</version>
+            </dependency>
             <dependency>
                 <groupId>org.opendaylight.mdsal</groupId>
                 <artifactId>mdsal-binding-test-model</artifactId>
index 2750ef55c33ad3e3e0e2c7188162b268ffdc93af..9b6a15b3a974d260548d38c66a72aa2c341ad8ee 100644 (file)
                 <groupId>${project.groupId}.model</groupId>
                 <artifactId>yang-ext</artifactId>
             </dependency>
+            <dependency>
+                <groupId>${project.groupId}.model</groupId>
+                <artifactId>general-entity</artifactId>
+            </dependency>
     </dependencies>
 </project>
index 3c037489c9a41eaaf23b430759c69390859d3dc2..f45cf1ef2f0f3a5d8b53d269b3fe61fa650b6026 100644 (file)
@@ -64,6 +64,7 @@
     <feature name='odl-mdsal-binding-api' version='${project.version}' description='OpenDaylight :: MD-SAL :: Binding Base Concepts'>
         <feature version='${project.version}'>odl-mdsal-common</feature>
         <feature version='${project.version}'>odl-mdsal-binding-base</feature>
+        <bundle>mvn:org.opendaylight.mdsal.model/general-entity/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.mdsal/mdsal-binding-api/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.mdsal/mdsal-binding-util/{{VERSION}}</bundle>
     </feature>
index 07a4fbbb38023caf0738af1bd151d126cf35e36d..f40144db867b96f66c270988c1543cf44958d476 100644 (file)
@@ -25,6 +25,7 @@
 
     <properties>
         <yangtools.version>0.8.0-SNAPSHOT</yangtools.version>
+        <salGeneratorPath>target/generated-sources/sal</salGeneratorPath>
 
         <!-- FIXME: these will be upstreamed -->
         <maven.depends.version>1.2</maven.depends.version>
                                             org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
                                         </codeGeneratorClass>
                                         <outputBaseDir>
-                                            target/generated-sources/sal
+                                            ${salGeneratorPath}
                                         </outputBaseDir>
                                     </generator>
                                     <generator>
                                         <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                        <outputBaseDir>target/site/restconf</outputBaseDir>
+                                        <outputBaseDir>target/site/models</outputBaseDir>
                                     </generator>
                                     <generator>
                                         <codeGeneratorClass>org.opendaylight.yangtools.yang.wadl.generator.maven.WadlGenerator</codeGeneratorClass>
-                                        <outputBaseDir>target/site/restconf</outputBaseDir>
+                                        <outputBaseDir>target/site/models</outputBaseDir>
                                     </generator>
                                 </codeGenerators>
                                 <inspectDependencies>true</inspectDependencies>
                             <configuration>
                                 <sources>
                                     <source>target/generated-sources/parser</source>
-                                    <source>target/generated-sources/sal</source>
+                                    <source>${salGeneratorPath}</source>
                                     <source>${basedir}/src/main/xtend-gen</source>
                                 </sources>
                             </configuration>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-javadoc-plugin</artifactId>
             </plugin>
+            <plugin>
+              <groupId>org.codehaus.mojo</groupId>
+              <artifactId>build-helper-maven-plugin</artifactId>
+            </plugin>
         </plugins>
     </build>
 </project>
index b9180e5c82c2ca995037cd2139d4f863f2e9a97a..4b567a55eec7426e84105042a34855f257a23408 100644 (file)
@@ -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<YangInstanceIdentifier> {
     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<YangInstanceIdentifier> {
      * @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 (file)
index 0000000..cfe1558
--- /dev/null
@@ -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<PathArgument> 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<QName, Object> 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 (file)
index 0000000..9427560
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ Copyright (c) 2013 Cisco 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
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <parent>
+        <artifactId>model-parent</artifactId>
+        <groupId>org.opendaylight.mdsal.model</groupId>
+        <version>0.8.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>general-entity</artifactId>
+    <name>${project.artifactId}</name>
+    <description>${project.artifactId}</description>
+    <packaging>bundle</packaging>
+
+</project>
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 (file)
index 0000000..9a68ebf
--- /dev/null
@@ -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
index cd66297edc15b00c3fe69ebe7a6c5a6b33184dcb..4d06d8ac2febe343fcae8a9741c71760c4f0700a 100644 (file)
@@ -34,6 +34,7 @@
         <module>iana</module>
         <module>ietf</module>
         <module>l2-types</module>
+        <module>general-entity</module>
     </modules>
 
     <dependencyManagement>