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; }
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; }
/** * Validate the fields in the the RelationshipType are consistent with respect to themselves. * @param type * @throws AtlasBaseException */ private boolean validateAtlasRelationshipType(AtlasRelationshipType type) { boolean isValid = false; try { validateAtlasRelationshipDef(type.getRelationshipDef()); isValid = true; } catch (AtlasBaseException abe) { LOG.error("Validation error for AtlasRelationshipType", abe); } return isValid; }
private void addRelationshipType(AtlasRelationshipType relationshipType, ExportService.ExportContext context) { if (!context.relationshipTypes.contains(relationshipType.getTypeName())) { context.relationshipTypes.add(relationshipType.getTypeName()); addAttributeTypes(relationshipType, context); addEntityType(relationshipType.getEnd1Type(), context); addEntityType(relationshipType.getEnd2Type(), context); } }
@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(); }
public AtlasRelationshipDef getRelationshipDef(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) { List<AtlasRelationshipType> relationshipTypes = entityType.getRelationshipAttributeType(attributeName); AtlasRelationshipDef ret = null; if (relationshipTypes.size() > 1) { Iterator<AtlasEdge> iter = entityVertex.getEdges(AtlasEdgeDirection.IN).iterator(); while (iter.hasNext() && ret == null) { String edgeTypeName = AtlasGraphUtilsV2.getTypeName(iter.next()); for (AtlasRelationshipType relationType : relationshipTypes) { AtlasRelationshipDef relationshipDef = relationType.getRelationshipDef(); if (StringUtils.equals(edgeTypeName, relationshipDef.getName())) { ret = relationshipDef; break; } } } if (ret == null) { ret = relationshipTypes.get(0).getRelationshipDef(); } } else { //relationshipTypes will have at least one relationshipDef ret = relationshipTypes.get(0).getRelationshipDef(); } return ret; }
@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 AtlasRelationship defineTermAssignment(String termGuid, AtlasRelatedObjectId relatedObjectId) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(TERM_ASSIGNMENT); AtlasStruct defaultAttrs = relationshipType.createDefaultValue(); AtlasObjectId end1 = new AtlasObjectId(termGuid); AtlasRelationship relationship = new AtlasRelationship(TERM_ASSIGNMENT, end1, relatedObjectId, defaultAttrs.getAttributes()); updateRelationshipAttributes(relationship, relatedObjectId); return relationship; }
AtlasRelationshipDef relationshipDef1 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_SET); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef1); AtlasRelationshipDef relationshipDef2 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_single); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef2); AtlasRelationshipDef relationshipDef3 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_single); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef3); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef); fail("This call is expected to fail"); } catch (AtlasBaseException abe) { AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_single_container); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef); fail("This call is expected to fail"); } catch (AtlasBaseException abe) { AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_single_container); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef); fail("This call is expected to fail"); } catch (AtlasBaseException abe) { AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_SET); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
AtlasRelationshipDef relationshipDef = (AtlasRelationshipDef) typeDef; registryData.relationshipDefs.addType(relationshipDef, new AtlasRelationshipType(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; }
@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 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(); }
private AtlasRelationship defineTermAssignment(String termGuid, AtlasRelatedObjectId relatedObjectId) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(TERM_ASSIGNMENT); AtlasStruct defaultAttrs = relationshipType.createDefaultValue(); AtlasObjectId end1 = new AtlasObjectId(termGuid); AtlasRelationship relationship = new AtlasRelationship(TERM_ASSIGNMENT, end1, relatedObjectId, defaultAttrs.getAttributes()); updateRelationshipAttributes(relationship, relatedObjectId); return relationship; }
AtlasRelationshipDef relationshipDef1 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_SET); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef1); AtlasRelationshipDef relationshipDef2 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_single); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef2); AtlasRelationshipDef relationshipDef3 = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_single); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef3); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef); fail("This call is expected to fail"); } catch (AtlasBaseException abe) { AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_single_container); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef); fail("This call is expected to fail"); } catch (AtlasBaseException abe) { AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_single, ep_single_container); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef); fail("This call is expected to fail"); } catch (AtlasBaseException abe) { AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1", AtlasRelationshipDef.RelationshipCategory.COMPOSITION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep_SET_container, ep_SET); AtlasRelationshipType.validateAtlasRelationshipDef(relationshipDef);
AtlasRelationshipDef relationshipDef = (AtlasRelationshipDef) typeDef; registryData.relationshipDefs.addType(relationshipDef, new AtlasRelationshipType(relationshipDef));
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 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 AtlasRelationship defineCategoryAnchorRelation(String glossaryGuid, String categoryGuid) { AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(CATEGORY_ANCHOR); AtlasStruct defaultAttrs = relationshipType.createDefaultValue(); return new AtlasRelationship(CATEGORY_ANCHOR, new AtlasObjectId(glossaryGuid), new AtlasObjectId(categoryGuid), defaultAttrs.getAttributes()); }
registryData.relationshipDefs.addType(relationshipDef, new AtlasRelationshipType(relationshipDef));