@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; //AttributeDefs are checked in the super if (!super.equals(o)) return false; AtlasRelationshipDef that = (AtlasRelationshipDef) o; if (!Objects.equals(relationshipCategory, that.getRelationshipCategory())) return false; if (!Objects.equals(propagateTags, that.getPropagateTags())) return false; if (!Objects.equals(endDef1, that.getEndDef1())) return false; return (Objects.equals(endDef2, that.getEndDef2())); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; //AttributeDefs are checked in the super if (!super.equals(o)) return false; AtlasRelationshipDef that = (AtlasRelationshipDef) o; if (!Objects.equals(relationshipCategory, that.getRelationshipCategory())) return false; if (!Objects.equals(propagateTags, that.getPropagateTags())) return false; if (!Objects.equals(endDef1, that.getEndDef1())) return false; return (Objects.equals(endDef2, that.getEndDef2())); }
public AtlasRelationshipType(AtlasRelationshipDef relationshipDef) { super(relationshipDef); AtlasRelationshipEndDef end1Def = relationshipDef != null ? relationshipDef.getEndDef1() : null; AtlasRelationshipEndDef end2Def = relationshipDef != null ? relationshipDef.getEndDef2() : null; this.relationshipDef = relationshipDef; this.hasLegacyAttributeEnd = (end1Def != null && end1Def.getIsLegacyAttribute()) || (end2Def != null && end2Def.getIsLegacyAttribute()); }
public AtlasRelationshipDef(AtlasRelationshipDef other) throws AtlasBaseException { super(other); if (other != null) { setRelationshipCategory(other.getRelationshipCategory()); setPropagateTags(other.getPropagateTags()); setEndDef1(other.getEndDef1()); setEndDef2(other.getEndDef2()); } } @Override
public AtlasRelationshipDef(AtlasRelationshipDef other) throws AtlasBaseException { super(other); if (other != null) { setRelationshipCategory(other.getRelationshipCategory()); setPropagateTags(other.getPropagateTags()); setEndDef1(other.getEndDef1()); setEndDef2(other.getEndDef2()); } } @Override
public static Map<String, TypeInfo> get(AtlasTypeRegistry typeRegistry) { Map<String, TypeInfo> ret = new HashMap<>(); for (AtlasRelationshipType relType : typeRegistry.getAllRelationshipTypes()) { AtlasRelationshipDef relDef = relType.getRelationshipDef(); String relTypeName = relType.getTypeName(); add(ret, getKey(relDef.getEndDef1()), relTypeName, relDef.getPropagateTags()); add(ret, getKey(relDef.getEndDef2()), relTypeName, getEnd2PropagateTag(relDef.getPropagateTags())); } return ret; }
private String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef(); AtlasEntityType end1Type = relationshipType.getEnd1Type(); AtlasEntityType end2Type = relationshipType.getEnd2Type(); Set<String> vertexTypes = getTypeAndAllSuperTypes(typeName); AtlasAttribute attribute = null; if (vertexTypes.contains(end1Type.getTypeName())) { String attributeName = relationshipDef.getEndDef1().getName(); attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null; } else if (vertexTypes.contains(end2Type.getTypeName())) { String attributeName = relationshipDef.getEndDef2().getName(); attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null; } return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null; }
private String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef(); AtlasEntityType end1Type = relationshipType.getEnd1Type(); AtlasEntityType end2Type = relationshipType.getEnd2Type(); Set<String> vertexTypes = getTypeAndAllSuperTypes(typeName); AtlasAttribute attribute = null; if (vertexTypes.contains(end1Type.getTypeName())) { String attributeName = relationshipDef.getEndDef1().getName(); attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null; } else if (vertexTypes.contains(end2Type.getTypeName())) { String attributeName = relationshipDef.getEndDef2().getName(); attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null; } return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null; } }
@Override public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferences(typeRegistry); if (relationshipDef == null) { throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "relationshipDef is null"); } String end1TypeName = relationshipDef.getEndDef1() != null ? relationshipDef.getEndDef1().getType() : null; String end2TypeName = relationshipDef.getEndDef2() != null ? relationshipDef.getEndDef2().getType() : null; AtlasType type1 = typeRegistry.getType(end1TypeName); AtlasType type2 = typeRegistry.getType(end2TypeName); if (type1 instanceof AtlasEntityType) { end1Type = (AtlasEntityType) type1; } else { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END_TYPE, getTypeName(), end1TypeName); } if (type2 instanceof AtlasEntityType) { end2Type = (AtlasEntityType) type2; } else { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END_TYPE, getTypeName(), end2TypeName); } validateAtlasRelationshipDef(this.relationshipDef); }
@Override void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferences(typeRegistry); if (relationshipDef == null) { throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "relationshipDef is null"); } String end1TypeName = relationshipDef.getEndDef1() != null ? relationshipDef.getEndDef1().getType() : null; String end2TypeName = relationshipDef.getEndDef2() != null ? relationshipDef.getEndDef2().getType() : null; AtlasType type1 = typeRegistry.getType(end1TypeName); AtlasType type2 = typeRegistry.getType(end2TypeName); if (type1 instanceof AtlasEntityType) { end1Type = (AtlasEntityType) type1; } else { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END_TYPE, getTypeName(), end1TypeName); } if (type2 instanceof AtlasEntityType) { end2Type = (AtlasEntityType) type2; } else { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END_TYPE, getTypeName(), end2TypeName); } validateAtlasRelationshipDef(relationshipDef); }
private PropagateTags getRelationshipTagPropagation(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName()); AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2(); Set<String> fromVertexTypes = getTypeAndAllSuperTypes(getTypeName(fromVertex)); Set<String> toVertexTypes = getTypeAndAllSuperTypes(getTypeName(toVertex)); PropagateTags ret = relationshipType.getRelationshipDef().getPropagateTags(); // relationshipDef is defined as end1 (hive_db) and end2 (hive_table) and tagPropagation = ONE_TO_TWO // relationship edge exists from [hive_table --> hive_db] // swap the tagPropagation property for such cases. if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) { if (ret == ONE_TO_TWO) { ret = TWO_TO_ONE; } else if (ret == TWO_TO_ONE) { ret = ONE_TO_TWO; } } return ret; }
private PropagateTags getRelationshipTagPropagation(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName()); AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2(); Set<String> fromVertexTypes = getTypeAndAllSuperTypes(getTypeName(fromVertex)); Set<String> toVertexTypes = getTypeAndAllSuperTypes(getTypeName(toVertex)); PropagateTags ret = relationshipType.getRelationshipDef().getPropagateTags(); // relationshipDef is defined as end1 (hive_db) and end2 (hive_table) and tagPropagation = ONE_TO_TWO // relationship edge exists from [hive_table --> hive_db] // swap the tagPropagation property for such cases. if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) { if (ret == ONE_TO_TWO) { ret = TWO_TO_ONE; } else if (ret == TWO_TO_ONE) { ret = ONE_TO_TWO; } } return ret; }
private int getLegacyAttributeCount() { int count = 0; for (AtlasRelationshipType rt : typeRegistry.getAllRelationshipTypes()) { AtlasRelationshipDef rd = rt.getRelationshipDef(); if(rd.getEndDef1().getIsLegacyAttribute()) { count++; } if(rd.getEndDef2().getIsLegacyAttribute()) { count++; } } return count; } }
private int getLegacyAttributeCount() { int count = 0; for (AtlasRelationshipType rt : typeRegistry.getAllRelationshipTypes()) { AtlasRelationshipDef rd = rt.getRelationshipDef(); if(rd.getEndDef1().getIsLegacyAttribute()) { count++; } if(rd.getEndDef2().getIsLegacyAttribute()) { count++; } } return count; } }
private void addRelationshipEdgeDirection() { AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); if (StringUtils.equals(endDef1.getType(), endDef2.getType()) && StringUtils.equals(endDef1.getName(), endDef2.getName())) { AtlasAttribute endAttribute = end1Type.getRelationshipAttribute(endDef1.getName()); endAttribute.setRelationshipEdgeDirection(BOTH); } else { AtlasAttribute end1Attribute = end1Type.getRelationshipAttribute(endDef1.getName()); AtlasAttribute end2Attribute = end2Type.getRelationshipAttribute(endDef2.getName()); //default relationship edge direction is end1 (out) -> end2 (in) AtlasRelationshipEdgeDirection end1Direction = OUT; AtlasRelationshipEdgeDirection end2Direction = IN; if (endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { end2Direction = OUT; } else if (!endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { end1Direction = IN; end2Direction = OUT; } end1Attribute.setRelationshipEdgeDirection(end1Direction); end2Attribute.setRelationshipEdgeDirection(end2Direction); } }
private void addRelationshipEdgeDirection() { AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); AtlasAttribute end1Attribute = end1Type.getRelationshipAttribute(endDef1.getName()); AtlasAttribute end2Attribute = end2Type.getRelationshipAttribute(endDef2.getName()); //default relationship edge direction is end1 (out) -> end2 (in) AtlasRelationshipEdgeDirection end1Direction = OUT; AtlasRelationshipEdgeDirection end2Direction = IN; if (endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { end2Direction = OUT; } else if (!endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { end1Direction = IN; end2Direction = OUT; } end1Attribute.setRelationshipEdgeDirection(end1Direction); end2Attribute.setRelationshipEdgeDirection(end2Direction); }
public static void setVertexPropertiesFromRelationshipDef(AtlasRelationshipDef relationshipDef, AtlasVertex vertex) { vertex.setProperty(Constants.RELATIONSHIPTYPE_END1_KEY, AtlasType.toJson(relationshipDef.getEndDef1())); vertex.setProperty(Constants.RELATIONSHIPTYPE_END2_KEY, AtlasType.toJson(relationshipDef.getEndDef2())); // default the relationship category to association if it has not been specified. String relationshipCategory = RelationshipCategory.ASSOCIATION.name(); if (relationshipDef.getRelationshipCategory()!=null) { relationshipCategory =relationshipDef.getRelationshipCategory().name(); } // Update RelationshipCategory vertex.setProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, relationshipCategory); if (relationshipDef.getPropagateTags() == null) { vertex.setProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, AtlasRelationshipDef.PropagateTags.NONE.name()); } else { vertex.setProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, relationshipDef.getPropagateTags().name()); } }
public static void setVertexPropertiesFromRelationshipDef(AtlasRelationshipDef relationshipDef, AtlasVertex vertex) { vertex.setProperty(Constants.RELATIONSHIPTYPE_END1_KEY, AtlasType.toJson(relationshipDef.getEndDef1())); vertex.setProperty(Constants.RELATIONSHIPTYPE_END2_KEY, AtlasType.toJson(relationshipDef.getEndDef2())); // default the relationship category to association if it has not been specified. String relationshipCategory = RelationshipCategory.ASSOCIATION.name(); if (relationshipDef.getRelationshipCategory()!=null) { relationshipCategory =relationshipDef.getRelationshipCategory().name(); } // Update RelationshipCategory vertex.setProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, relationshipCategory); if (relationshipDef.getPropagateTags() == null) { vertex.setProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, AtlasRelationshipDef.PropagateTags.NONE.name()); } else { vertex.setProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, relationshipDef.getPropagateTags().name()); } }
@Override void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferencesPhase2(typeRegistry); AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); String relationshipLabel = null; // if legacyLabel is not specified at both ends, use relationshipDef name as relationship label. // if legacyLabel is specified in any one end, use it as the relationship label for both ends (legacy case). // if legacyLabel is specified at both ends use the respective end's legacyLabel as relationship label (legacy case). if (!endDef1.getIsLegacyAttribute() && !endDef2.getIsLegacyAttribute()) { relationshipLabel = relationshipDef.getRelationshipLabel(); } else if (endDef1.getIsLegacyAttribute() && !endDef2.getIsLegacyAttribute()) { relationshipLabel = getLegacyEdgeLabel(end1Type, endDef1.getName()); } else if (!endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { relationshipLabel = getLegacyEdgeLabel(end2Type, endDef2.getName()); } addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel); addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel); // add relationship edge direction information addRelationshipEdgeDirection(); }
@Override public void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferencesPhase2(typeRegistry); AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); String relationshipLabel = null; // if legacyLabel is not specified at both ends, use relationshipDef name as relationship label. // if legacyLabel is specified in any one end, use it as the relationship label for both ends (legacy case). // if legacyLabel is specified at both ends use the respective end's legacyLabel as relationship label (legacy case). if (!endDef1.getIsLegacyAttribute() && !endDef2.getIsLegacyAttribute()) { relationshipLabel = relationshipDef.getRelationshipLabel(); } else if (endDef1.getIsLegacyAttribute() && !endDef2.getIsLegacyAttribute()) { relationshipLabel = getLegacyEdgeLabel(end1Type, endDef1.getName()); } else if (!endDef1.getIsLegacyAttribute() && endDef2.getIsLegacyAttribute()) { relationshipLabel = getLegacyEdgeLabel(end2Type, endDef2.getName()); } addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel); addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel); // add relationship edge direction information addRelationshipEdgeDirection(); }