This is an automated email from the ASF dual-hosted git repository. madhan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push: new a910609 ATLAS-3136: assigning a term to an invalid entity guid throws 500, instead of 400 a910609 is described below commit a910609d43b252526cf15337f891fc04c6dc4154 Author: Madhan Neethiraj <mad...@apache.org> AuthorDate: Sun Apr 14 16:05:39 2019 -0700 ATLAS-3136: assigning a term to an invalid entity guid throws 500, instead of 400 --- .../store/graph/AtlasRelationshipStore.java | 2 +- .../store/graph/v2/AtlasRelationshipStoreV2.java | 31 +++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) 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 53e29e1..b7463dd 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 @@ -59,7 +59,7 @@ public interface AtlasRelationshipStore { AtlasEdge getOrCreate(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException; - AtlasEdge getRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship); + AtlasEdge getRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException; AtlasEdge createRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException; diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasRelationshipStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasRelationshipStoreV2.java index 0279c2c..54059e8 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasRelationshipStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasRelationshipStoreV2.java @@ -294,7 +294,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { } @Override - public AtlasEdge getRelationship(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) { + public AtlasEdge getRelationship(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) throws AtlasBaseException { String relationshipLabel = getRelationshipEdgeLabel(fromVertex, toVertex, relationship.getTypeName()); return getRelationshipEdge(fromVertex, toVertex, relationshipLabel); @@ -802,18 +802,31 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { return ret; } - private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipTypeName) { + private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipTypeName) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("getRelationshipEdgeLabel({})", relationshipTypeName); } - AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); - String ret = relationshipType.getRelationshipLabel(); - AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1(); - AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2(); - Set<String> fromVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(fromVertex)); - Set<String> toVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(toVertex)); - AtlasAttribute attribute = null; + AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); + + if (relationshipType == null) { + throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipTypeName + "'"); + } + + if (fromVertex == null) { + throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_END_IS_NULL, relationshipType.getEnd1Type().getTypeName()); + } + + if (toVertex == null) { + throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_END_IS_NULL, relationshipType.getEnd2Type().getTypeName()); + } + + String ret = relationshipType.getRelationshipLabel(); + AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1(); + AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2(); + Set<String> fromVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(fromVertex)); + Set<String> toVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV2.getTypeName(toVertex)); + AtlasAttribute attribute = null; // validate entity type and all its supertypes contains relationshipDefs end type // e.g. [hive_process -> hive_table] -> [Process -> DataSet]