Commit b0470f50 by Sarath Subramanian Committed by Madhan Neethiraj

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

parent 40d909ef
...@@ -46,6 +46,13 @@ public interface AtlasRelationshipStore { ...@@ -46,6 +46,13 @@ public interface AtlasRelationshipStore {
AtlasRelationship getById(String guid) throws AtlasBaseException; 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. * Delete a relationship instance using guid.
* @param guid relationship instance guid * @param guid relationship instance guid
*/ */
......
...@@ -117,6 +117,31 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore { ...@@ -117,6 +117,31 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
@Override @Override
@GraphTransaction @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 { public AtlasRelationship update(AtlasRelationship relationship) throws AtlasBaseException {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> update({})", relationship); LOG.debug("==> update({})", relationship);
......
...@@ -422,7 +422,9 @@ public class EntityGraphMapper { ...@@ -422,7 +422,9 @@ public class EntityGraphMapper {
AtlasEntityType entityType = (AtlasEntityType) inverseAttributeType; AtlasEntityType entityType = (AtlasEntityType) inverseAttributeType;
if (entityType.hasRelationshipAttribute(inverseAttributeName)) { if (entityType.hasRelationshipAttribute(inverseAttributeName)) {
ret = createRelationship(inverseVertex, vertex, inverseAttribute.getRelationshipEdgeLabel()); String relationshipName = graphHelper.getRelationshipDefName(inverseVertex, entityType, inverseAttributeName);
ret = getOrCreateRelationship(inverseVertex, vertex, relationshipName);
} else { } else {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
...@@ -584,7 +586,7 @@ public class EntityGraphMapper { ...@@ -584,7 +586,7 @@ public class EntityGraphMapper {
} else { } else {
String relationshipName = graphHelper.getRelationshipDefName(entityVertex, entityType, attributeName); String relationshipName = graphHelper.getRelationshipDefName(entityVertex, entityType, attributeName);
ret = createRelationship(entityVertex, attributeVertex, relationshipName); ret = getOrCreateRelationship(entityVertex, attributeVertex, relationshipName);
} }
} else { } else {
...@@ -951,7 +953,7 @@ public class EntityGraphMapper { ...@@ -951,7 +953,7 @@ public class EntityGraphMapper {
relationshipName = currentEdge.getLabel(); relationshipName = currentEdge.getLabel();
} }
ret = createRelationship(currentEdge.getOutVertex(), entityVertex, relationshipName); ret = getOrCreateRelationship(currentEdge.getOutVertex(), entityVertex, relationshipName);
} }
return ret; return ret;
...@@ -1180,11 +1182,11 @@ public class EntityGraphMapper { ...@@ -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; AtlasEdge ret = null;
AtlasObjectId end1 = new AtlasObjectId(AtlasGraphUtilsV1.getIdFromVertex(end1Vertex), AtlasGraphUtilsV1.getTypeName(end1Vertex)); AtlasObjectId end1 = new AtlasObjectId(AtlasGraphUtilsV1.getIdFromVertex(end1Vertex), AtlasGraphUtilsV1.getTypeName(end1Vertex));
AtlasObjectId end2 = new AtlasObjectId(AtlasGraphUtilsV1.getIdFromVertex(end2Vertex), AtlasGraphUtilsV1.getTypeName(end2Vertex)); 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 // return newly created AtlasEdge
// if multiple edges are returned, compare using id to pick the right one // if multiple edges are returned, compare using id to pick the right one
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment