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 static AtlasRelationshipDef createRelationshipTypeDef(String name, String description, String version, RelationshipCategory relationshipCategory, PropagateTags propagateTags, AtlasRelationshipEndDef endDef1, AtlasRelationshipEndDef endDef2, AtlasAttributeDef... attrDefs) { return new AtlasRelationshipDef(name, description, version, relationshipCategory, propagateTags, endDef1, endDef2, Arrays.asList(attrDefs)); }
@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 AtlasRelationshipDef(AtlasRelationshipDef other) throws AtlasBaseException { super(other); if (other != null) { setRelationshipCategory(other.getRelationshipCategory()); setPropagateTags(other.getPropagateTags()); setEndDef1(other.getEndDef1()); setEndDef2(other.getEndDef2()); } } @Override
String existingName = existingRelationshipDef.getName(); String newName = newRelationshipDef.getName(); newRelationshipDef.getGuid(),existingName, newName); RelationshipCategory existingRelationshipCategory = existingRelationshipDef.getRelationshipCategory(); RelationshipCategory newRelationshipCategory = newRelationshipDef.getRelationshipCategory(); newRelationshipDef.getName(),newRelationshipCategory.name(), existingRelationshipCategory.name() ); AtlasRelationshipEndDef existingEnd1 = existingRelationshipDef.getEndDef1(); AtlasRelationshipEndDef newEnd1 = newRelationshipDef.getEndDef1(); newRelationshipDef.getName(), newEnd1.toString(), existingEnd1.toString()); AtlasRelationshipEndDef existingEnd2 = existingRelationshipDef.getEndDef2(); AtlasRelationshipEndDef newEnd2 = newRelationshipDef.getEndDef2(); newRelationshipDef.getName(), newEnd2.toString(), existingEnd2.toString());
private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipTypeName) { if (LOG.isDebugEnabled()) { LOG.debug("getRelationshipEdgeLabel({})", relationshipTypeName); } AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); String ret = relationshipType.getRelationshipDef().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] if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) { String attributeName = endDef1.getName(); attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName); } else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) { String attributeName = endDef2.getName(); attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName); } if (attribute != null) { ret = attribute.getRelationshipEdgeLabel(); } return ret; }
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 Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, AtlasEntityType entityType, AtlasAttribute attribute) throws AtlasBaseException { Object ret = null; AtlasRelationshipDef relationshipDef = graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName()); if (relationshipDef == null) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is null"); } AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); AtlasEntityType endDef1Type = typeRegistry.getEntityTypeByName(endDef1.getType()); AtlasEntityType endDef2Type = typeRegistry.getEntityTypeByName(endDef2.getType()); AtlasRelationshipEndDef attributeEndDef = null; if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef1.getName(), attribute.getName())) { attributeEndDef = endDef1; } else if (endDef2Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef2.getName(), attribute.getName())) { attributeEndDef = endDef2; } if (attributeEndDef == null) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, relationshipDef.toString()); } switch (attributeEndDef.getCardinality()) { case SINGLE: ret = mapRelatedVertexToObjectId(entityVertex, attribute); break; case LIST: case SET: ret = mapRelationshipArrayAttribute(entityVertex, attribute); break; } return ret; }
AtlasType type = typeRegistry.getType(relationshipDef.getName()); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); AtlasVertex relationshipDefVertex = typeDefStore.findTypeVertexByName(relationshipDef.getName()); throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, relationshipDef.getName()); final AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); final AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); final String type1 = endDef1.getType(); final String type2 = endDef2.getType(); throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type1); throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type2);
@Test public void testRelationshipEquals() throws AtlasBaseException { AtlasRelationshipEndDef ep1 = new AtlasRelationshipEndDef("typeA", "attr1", Cardinality.SINGLE); AtlasRelationshipEndDef ep2 = new AtlasRelationshipEndDef("typeB", "attr2", Cardinality.SINGLE); AtlasRelationshipDef relationshipDef1 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep1, ep2); List<AtlasStructDef.AtlasAttributeDef> attributeDefs = ModelTestUtil.newAttributeDefsWithAllBuiltInTypesForRelationship(PREFIX_ATTRIBUTE_NAME); relationshipDef1.setAttributeDefs(attributeDefs); AtlasRelationshipDef relationshipDef2 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep1, ep2); relationshipDef2.setAttributeDefs(attributeDefs); assertEquals(relationshipDef1,relationshipDef2); AtlasRelationshipDef relationshipDef3 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep1, ep2); assertNotEquals(relationshipDef1,relationshipDef3); } }
public AtlasRelationship(AtlasRelationshipDef relationshipDef) { this(relationshipDef != null ? relationshipDef.getName() : null); }
@Override public AtlasRelationshipDef update(AtlasRelationshipDef relationshipDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.update({})", relationshipDef); } validateType(relationshipDef); AtlasRelationshipDef ret = StringUtils.isNotBlank(relationshipDef.getGuid()) ? updateByGuid(relationshipDef.getGuid(), relationshipDef) : updateByName(relationshipDef.getName(), relationshipDef); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.update({}): {}", relationshipDef, ret); } return ret; }
@Override public String toString() { return toString(new StringBuilder()).toString(); } }
String existingName = existingRelationshipDef.getName(); String newName = newRelationshipDef.getName(); newRelationshipDef.getGuid(),existingName, newName); RelationshipCategory existingRelationshipCategory = existingRelationshipDef.getRelationshipCategory(); RelationshipCategory newRelationshipCategory = newRelationshipDef.getRelationshipCategory(); newRelationshipDef.getName(),newRelationshipCategory.name(), existingRelationshipCategory.name() ); AtlasRelationshipEndDef existingEnd1 = existingRelationshipDef.getEndDef1(); AtlasRelationshipEndDef newEnd1 = newRelationshipDef.getEndDef1(); newRelationshipDef.getName(), newEnd1.toString(), existingEnd1.toString()); AtlasRelationshipEndDef existingEnd2 = existingRelationshipDef.getEndDef2(); AtlasRelationshipEndDef newEnd2 = newRelationshipDef.getEndDef2(); newRelationshipDef.getName(), newEnd2.toString(), existingEnd2.toString());
public AtlasRelationshipDef(AtlasRelationshipDef other) throws AtlasBaseException { super(other); if (other != null) { setRelationshipCategory(other.getRelationshipCategory()); setPropagateTags(other.getPropagateTags()); setEndDef1(other.getEndDef1()); setEndDef2(other.getEndDef2()); } } @Override
private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipTypeName) { if (LOG.isDebugEnabled()) { LOG.debug("getRelationshipEdgeLabel({})", relationshipTypeName); } AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName); String ret = relationshipType.getRelationshipDef().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] if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) { String attributeName = endDef1.getName(); attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName); } else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) { String attributeName = endDef2.getName(); attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName); } if (attribute != null) { ret = attribute.getRelationshipEdgeLabel(); } 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 Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, AtlasEntityType entityType, AtlasAttribute attribute) throws AtlasBaseException { Object ret = null; AtlasRelationshipDef relationshipDef = graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName()); if (relationshipDef == null) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is null"); } AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); AtlasEntityType endDef1Type = typeRegistry.getEntityTypeByName(endDef1.getType()); AtlasEntityType endDef2Type = typeRegistry.getEntityTypeByName(endDef2.getType()); AtlasRelationshipEndDef attributeEndDef = null; if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef1.getName(), attribute.getName())) { attributeEndDef = endDef1; } else if (endDef2Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef2.getName(), attribute.getName())) { attributeEndDef = endDef2; } if (attributeEndDef == null) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, relationshipDef.toString()); } switch (attributeEndDef.getCardinality()) { case SINGLE: ret = mapRelatedVertexToObjectId(entityVertex, attribute); break; case LIST: case SET: ret = mapRelationshipArrayAttribute(entityVertex, attribute); break; } return ret; }
AtlasType type = typeRegistry.getType(relationshipDef.getName()); throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); AtlasVertex relationshipDefVertex = typeDefStore.findTypeVertexByName(relationshipDef.getName()); throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, relationshipDef.getName()); final AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); final AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); final String type1 = endDef1.getType(); final String type2 = endDef2.getType(); throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type1); throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type2);
@Test public void testRelationshipEquals() throws AtlasBaseException { AtlasRelationshipEndDef ep1 = new AtlasRelationshipEndDef("typeA", "attr1", Cardinality.SINGLE); AtlasRelationshipEndDef ep2 = new AtlasRelationshipEndDef("typeB", "attr2", Cardinality.SINGLE); AtlasRelationshipDef relationshipDef1 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep1, ep2); List<AtlasStructDef.AtlasAttributeDef> attributeDefs = ModelTestUtil.newAttributeDefsWithAllBuiltInTypesForRelationship(PREFIX_ATTRIBUTE_NAME); relationshipDef1.setAttributeDefs(attributeDefs); AtlasRelationshipDef relationshipDef2 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep1, ep2); relationshipDef2.setAttributeDefs(attributeDefs); assertEquals(relationshipDef1,relationshipDef2); AtlasRelationshipDef relationshipDef3 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep1, ep2); assertNotEquals(relationshipDef1,relationshipDef3); } }