atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject incubator-atlas git commit: ATLAS-1943: Fix IT failure due to incorrect inverse reference check using relationship
Date Wed, 12 Jul 2017 21:58:25 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master 40d909ef8 -> b0470f50e


ATLAS-1943: Fix IT failure due to incorrect inverse reference check using relationship

Signed-off-by: Madhan Neethiraj <madhan@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/b0470f50
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/b0470f50
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/b0470f50

Branch: refs/heads/master
Commit: b0470f50e10837d052db8e0fe74847b0559bfabf
Parents: 40d909e
Author: Sarath Subramanian <ssubramanian@hortonworks.com>
Authored: Tue Jul 11 13:12:36 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Wed Jul 12 14:35:18 2017 -0700

----------------------------------------------------------------------
 .../store/graph/AtlasRelationshipStore.java     |  7 ++++++
 .../graph/v1/AtlasRelationshipStoreV1.java      | 25 ++++++++++++++++++++
 .../store/graph/v1/EntityGraphMapper.java       | 12 ++++++----
 3 files changed, 39 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b0470f50/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasRelationshipStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasRelationshipStore.java
b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasRelationshipStore.java
index 341711a..8043760 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasRelationshipStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasRelationshipStore.java
@@ -46,6 +46,13 @@ public interface AtlasRelationshipStore {
     AtlasRelationship getById(String guid) throws AtlasBaseException;
 
     /**
+     * Retrieve a relationship if it exists or creates a new relationship instance.
+     * @param relationship relationship instance definition
+     * @return AtlasRelationship
+     */
+    AtlasRelationship getOrCreate(AtlasRelationship relationship) throws AtlasBaseException;
+
+    /**
      * Delete a relationship instance using guid.
      * @param guid relationship instance guid
      */

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b0470f50/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
index 8d9e4be..3ff6fbe 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
@@ -117,6 +117,31 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore
{
 
     @Override
     @GraphTransaction
+    public AtlasRelationship getOrCreate(AtlasRelationship relationship) throws AtlasBaseException
{
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("==> getOrCreate({})", relationship);
+        }
+
+        validateRelationship(relationship);
+
+        AtlasVertex       end1Vertex = getVertexFromEndPoint(relationship.getEnd1());
+        AtlasVertex       end2Vertex = getVertexFromEndPoint(relationship.getEnd2());
+        AtlasRelationship ret;
+
+        // check if relationship exists
+        AtlasEdge relationshipEdge = getRelationshipEdge(end1Vertex, end2Vertex, relationship);
+
+        ret = (relationshipEdge != null) ? mapEdgeToAtlasRelationship(relationshipEdge) :
create(relationship);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("<== getOrCreate({}): {}", relationship, ret);
+        }
+
+        return ret;
+    }
+
+    @Override
+    @GraphTransaction
     public AtlasRelationship update(AtlasRelationship relationship) throws AtlasBaseException
{
         if (LOG.isDebugEnabled()) {
             LOG.debug("==> update({})", relationship);

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b0470f50/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
index d5c1e86..68f8370 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
@@ -422,7 +422,9 @@ public class EntityGraphMapper {
             AtlasEntityType entityType = (AtlasEntityType) inverseAttributeType;
 
             if (entityType.hasRelationshipAttribute(inverseAttributeName)) {
-                ret = createRelationship(inverseVertex, vertex, inverseAttribute.getRelationshipEdgeLabel());
+                String relationshipName = graphHelper.getRelationshipDefName(inverseVertex,
entityType, inverseAttributeName);
+
+                ret = getOrCreateRelationship(inverseVertex, vertex, relationshipName);
 
             } else {
                 if (LOG.isDebugEnabled()) {
@@ -584,7 +586,7 @@ public class EntityGraphMapper {
 
                 } else {
                     String relationshipName = graphHelper.getRelationshipDefName(entityVertex,
entityType, attributeName);
-                    ret = createRelationship(entityVertex, attributeVertex, relationshipName);
+                    ret = getOrCreateRelationship(entityVertex, attributeVertex, relationshipName);
                 }
 
             } else {
@@ -951,7 +953,7 @@ public class EntityGraphMapper {
                 relationshipName = currentEdge.getLabel();
             }
 
-            ret = createRelationship(currentEdge.getOutVertex(), entityVertex, relationshipName);
+            ret = getOrCreateRelationship(currentEdge.getOutVertex(), entityVertex, relationshipName);
         }
 
         return ret;
@@ -1180,11 +1182,11 @@ public class EntityGraphMapper {
         }
     }
 
-    private AtlasEdge createRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex,
String relationshipName) throws AtlasBaseException {
+    private AtlasEdge getOrCreateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex,
String relationshipName) throws AtlasBaseException {
         AtlasEdge         ret          = null;
         AtlasObjectId     end1         = new AtlasObjectId(AtlasGraphUtilsV1.getIdFromVertex(end1Vertex),
AtlasGraphUtilsV1.getTypeName(end1Vertex));
         AtlasObjectId     end2         = new AtlasObjectId(AtlasGraphUtilsV1.getIdFromVertex(end2Vertex),
AtlasGraphUtilsV1.getTypeName(end2Vertex));
-        AtlasRelationship relationship = relationshipStore.create(new AtlasRelationship(relationshipName,
end1, end2));
+        AtlasRelationship relationship = relationshipStore.getOrCreate(new AtlasRelationship(relationshipName,
end1, end2));
 
         // return newly created AtlasEdge
         // if multiple edges are returned, compare using id to pick the right one


Mime
View raw message