atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [09/14] incubator-atlas git commit: ATLAS-1904: Relationship def validation(s)
Date Sun, 09 Jul 2017 15:07:47 GMT
ATLAS-1904: Relationship def validation(s)

Signed-off-by: apoorvnaik <apoorvnaik@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/45d0930b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/45d0930b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/45d0930b

Branch: refs/heads/feature-odf
Commit: 45d0930b270caa10434f3d97dbea0224bc68740c
Parents: d22fa7e
Author: David Radley <david_radley@uk.ibm.com>
Authored: Mon Jul 3 13:51:27 2017 -0700
Committer: apoorvnaik <apoorvnaik@apache.org>
Committed: Mon Jul 3 13:51:27 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/atlas/AtlasErrorCode.java   |  2 +-
 .../atlas/type/AtlasRelationshipType.java       | 22 ++++++------
 .../atlas/type/TestAtlasRelationshipType.java   | 36 +++++++++++---------
 3 files changed, 32 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/45d0930b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
index 49ead6e..73dd33a 100644
--- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
+++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
@@ -77,7 +77,7 @@ public enum AtlasErrorCode {
     RELATIONSHIPDEF_ASSOCIATION_AND_CONTAINER(400,  "ATLAS-400-00-030", "ASSOCIATION relationshipDef
{0} creation attempted with an end specifying isContainer"),
     RELATIONSHIPDEF_COMPOSITION_NO_CONTAINER(400,  "ATLAS-400-00-031", "COMPOSITION relationshipDef
{0} creation attempted without an end specifying isContainer"),
     RELATIONSHIPDEF_AGGREGATION_NO_CONTAINER(400,  "ATLAS-400-00-032", "AGGREGATION relationshipDef
{0} creation attempted without an end specifying isContainer"),
-    RELATIONSHIPDEF_COMPOSITION_SET_CONTAINER(400,  "ATLAS-400-00-033", "COMPOSITION relationshipDef
{0} cannot have a SET cardinality and be a container"),
+    RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS(400,  "ATLAS-400-00-033", "COMPOSITION relationshipDef
{0} can only have one parent; so cannot have SET cardinality on children"),
     RELATIONSHIPDEF_LIST_ON_END(400,  "ATLAS-400-00-034", "relationshipDef {0} cannot have
a LIST cardinality on an end"),
     RELATIONSHIPDEF_INVALID_END_TYPE(400,  "ATLAS-400-00-035", "relationshipDef {0} has invalid
end type {1}"),
     INVALID_RELATIONSHIP_END_TYPE(400, "ATLAS-400-00-036", "invalid update for relationshipDef
{0}: new end type {1}, existing end type {2}"),

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/45d0930b/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java b/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
index f85cf35..49a9493 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
@@ -161,6 +161,10 @@ public class AtlasRelationshipType extends AtlasStructType {
         boolean                 isContainer1         = endDef1.getIsContainer();
         boolean                 isContainer2         = endDef2.getIsContainer();
 
+        if ((endDef1.getCardinality() == AtlasAttributeDef.Cardinality.LIST) ||
+                (endDef2.getCardinality() == AtlasAttributeDef.Cardinality.LIST)) {
+            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_LIST_ON_END, name);
+        }
         if (isContainer1 && isContainer2) {
             // we support 0 or 1 of these flags.
             throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_DOUBLE_CONTAINERS,
name);
@@ -168,11 +172,11 @@ public class AtlasRelationshipType extends AtlasStructType {
         if ((isContainer1 || isContainer2)) {
             // we have an isContainer defined in an end
             if (relationshipCategory == RelationshipCategory.ASSOCIATION) {
-                // associations are not containment relaitonships - so do not allow an endpoiint
with isContainer
+                // associations are not containment relationships - so do not allow an endpoint
with isContainer
                 throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_ASSOCIATION_AND_CONTAINER,
name);
             }
         } else {
-            // we do not have an isContainer defined in an end
+            // we do not have an isContainer defined on an end
             if (relationshipCategory == RelationshipCategory.COMPOSITION) {
                 // COMPOSITION needs one end to be the container.
                 throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_NO_CONTAINER,
name);
@@ -182,18 +186,14 @@ public class AtlasRelationshipType extends AtlasStructType {
             }
         }
         if (relationshipCategory == RelationshipCategory.COMPOSITION) {
-            // composition containers should not be multiple cardinality
+            // composition children should not be multiple cardinality
             if (endDef1.getCardinality() == AtlasAttributeDef.Cardinality.SET &&
-                    endDef1.getIsContainer()) {
-                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_SET_CONTAINER,
name);
+                    !endDef1.getIsContainer()) {
+                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS,
name);
             }
             if ((endDef2.getCardinality() == AtlasAttributeDef.Cardinality.SET) &&
-                    endDef2.getIsContainer()) {
-                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_SET_CONTAINER,
name);
-            }
-            if ((endDef1.getCardinality() == AtlasAttributeDef.Cardinality.LIST) ||
-                    (endDef2.getCardinality() == AtlasAttributeDef.Cardinality.LIST)) {
-                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_LIST_ON_END,
name);
+                    !endDef2.getIsContainer()) {
+                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS,
name);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/45d0930b/intg/src/test/java/org/apache/atlas/type/TestAtlasRelationshipType.java
----------------------------------------------------------------------
diff --git a/intg/src/test/java/org/apache/atlas/type/TestAtlasRelationshipType.java b/intg/src/test/java/org/apache/atlas/type/TestAtlasRelationshipType.java
index 41aac8f..8f3ac5b 100644
--- a/intg/src/test/java/org/apache/atlas/type/TestAtlasRelationshipType.java
+++ b/intg/src/test/java/org/apache/atlas/type/TestAtlasRelationshipType.java
@@ -61,22 +61,26 @@ public class TestAtlasRelationshipType {
 
     @Test
     public void testvalidateAtlasRelationshipDef() throws AtlasBaseException {
-        AtlasRelationshipEndDef ep1 = new AtlasRelationshipEndDef("typeA", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
-        AtlasRelationshipEndDef ep2 = new AtlasRelationshipEndDef("typeB", "attr2", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
-        AtlasRelationshipEndDef ep3 = new AtlasRelationshipEndDef("typeC", "attr2", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE,
true);
-        AtlasRelationshipEndDef ep4 = new AtlasRelationshipEndDef("typeD", "attr2", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE,
true);
-        AtlasRelationshipEndDef ep5 = new AtlasRelationshipEndDef("typeA", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SET,true);
-        AtlasRelationshipEndDef ep6 = new AtlasRelationshipEndDef("typeA", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.LIST,true);
+        AtlasRelationshipEndDef ep_single = new AtlasRelationshipEndDef("typeA", "attr1",
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
+        AtlasRelationshipEndDef ep_single_container = new AtlasRelationshipEndDef("typeB",
"attr2", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
+        AtlasRelationshipEndDef ep_single_container_2 = new AtlasRelationshipEndDef("typeC",
"attr3", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, true);
+        AtlasRelationshipEndDef ep_single_container_3 = new AtlasRelationshipEndDef("typeD",
"attr4", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, true);
+        AtlasRelationshipEndDef ep_SET = new AtlasRelationshipEndDef("typeD", "attr4", AtlasStructDef.AtlasAttributeDef.Cardinality.SET,false);
+        AtlasRelationshipEndDef ep_LIST = new AtlasRelationshipEndDef("typeE", "attr5", AtlasStructDef.AtlasAttributeDef.Cardinality.LIST,true);
+        AtlasRelationshipEndDef ep_SET_container = new AtlasRelationshipEndDef("typeF", "attr6",
AtlasStructDef.AtlasAttributeDef.Cardinality.SET,true);
         AtlasRelationshipDef relationshipDef1 = new AtlasRelationshipDef("emptyRelationshipDef",
"desc 1", "version1",
-                AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep1, ep2);
+                AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep_single, ep_SET);
+        AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef1);
         AtlasRelationshipDef relationshipDef2 = new AtlasRelationshipDef("emptyRelationshipDef",
"desc 1", "version1",
-                AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep1, ep3);
+                AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep_SET_container, ep_single);
+        AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef2);
         AtlasRelationshipDef relationshipDef3 = new AtlasRelationshipDef("emptyRelationshipDef",
"desc 1", "version1",
-                AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep1, ep3);
+                AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep_SET_container, ep_single);
+        AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef3);
 
         try {
             AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef",
"desc 1", "version1",
-                    AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep3, ep2);
+                    AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep_single_container_2, ep_single_container);
             AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
             fail("This call is expected to fail");
         } catch (AtlasBaseException abe) {
@@ -86,7 +90,7 @@ public class TestAtlasRelationshipType {
         }
         try {
             AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef",
"desc 1", "version1",
-                    AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep1, ep2);
+                    AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep_single, ep_single_container);
             AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
             fail("This call is expected to fail");
         } catch (AtlasBaseException abe) {
@@ -96,7 +100,7 @@ public class TestAtlasRelationshipType {
         }
         try {
             AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef",
"desc 1", "version1",
-                    AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep1, ep2);
+                    AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep_single, ep_single_container);
             AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
             fail("This call is expected to fail");
         } catch (AtlasBaseException abe) {
@@ -107,17 +111,17 @@ public class TestAtlasRelationshipType {
 
         try {
             AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef",
"desc 1", "version1",
-                    AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep1, ep5);
+                    AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep_SET_container, ep_SET);
             AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
             fail("This call is expected to fail");
         } catch (AtlasBaseException abe) {
-            if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_SET_CONTAINER))
{
+            if (!abe.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS))
{
                 fail("This call expected a different error");
             }
         }
         try {
             AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef",
"desc 1", "version1",
-                    AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep1, ep6);
+                    AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep_single, ep_LIST);
             AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
             fail("This call is expected to fail");
         } catch (AtlasBaseException abe) {
@@ -127,7 +131,7 @@ public class TestAtlasRelationshipType {
         }
         try {
             AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef",
"desc 1", "version1",
-                    AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep6, ep1);
+                    AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO,
ep_LIST, ep_single);
             AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
             fail("This call is expected to fail");
         } catch (AtlasBaseException abe) {


Mime
View raw message