/** * 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; }
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; }
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 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 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 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; } }
typesDef.getRelationshipDefs().add(relationshipType.getRelationshipDef());
private AtlasBaseTypeDef getTypeDefFromType(AtlasType type) throws AtlasBaseException { AtlasBaseTypeDef ret; switch (type.getTypeCategory()) { case ENUM: ret = ((AtlasEnumType) type).getEnumDef(); break; case STRUCT: ret = ((AtlasStructType) type).getStructDef(); break; case CLASSIFICATION: ret = ((AtlasClassificationType) type).getClassificationDef(); break; case ENTITY: ret = ((AtlasEntityType) type).getEntityDef(); break; case RELATIONSHIP: ret = ((AtlasRelationshipType) type).getRelationshipDef(); break; case PRIMITIVE: case OBJECT_ID_TYPE: case ARRAY: case MAP: default: throw new AtlasBaseException(AtlasErrorCode.SYSTEM_TYPE, type.getTypeCategory().name()); } 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; } }