public AtlasRelationship(AtlasRelationshipDef relationshipDef) { this(relationshipDef != null ? relationshipDef.getName() : null); }
public AtlasRelationship(AtlasRelationshipDef relationshipDef) { this(relationshipDef != null ? relationshipDef.getName() : null); }
/** * Get relationshipDef name from entityType using relationship attribute. * if more than one relationDefs are returned for an attribute. * e.g. hive_column.table * * hive_table.columns -> hive_column.table * hive_table.partitionKeys -> hive_column.table * * resolve by comparing all incoming edges typename with relationDefs name returned for an attribute * to pick the right relationshipDef name */ public String getRelationshipDefName(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) { AtlasRelationshipDef relationshipDef = getRelationshipDef(entityVertex, entityType, attributeName); return (relationshipDef != null) ? relationshipDef.getName() : null; }
@Override public AtlasRelationshipDef create(AtlasRelationshipDef relationshipDef, AtlasVertex preCreateResult) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.create({}, {})", relationshipDef, preCreateResult); } AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, relationshipDef), "create relationship-def ", relationshipDef.getName()); AtlasVertex vertex = (preCreateResult == null) ? preCreate(relationshipDef) : preCreateResult; AtlasRelationshipDef ret = toRelationshipDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.create({}, {}): {}", relationshipDef, preCreateResult, ret); } return ret; }
@Override public AtlasRelationshipDef create(AtlasRelationshipDef relationshipDef, AtlasVertex preCreateResult) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.create({}, {})", relationshipDef, preCreateResult); } AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, relationshipDef), "create relationship-def ", relationshipDef.getName()); AtlasVertex vertex = (preCreateResult == null) ? preCreate(relationshipDef) : preCreateResult; AtlasRelationshipDef ret = toRelationshipDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.create({}, {}): {}", relationshipDef, preCreateResult, ret); } return ret; }
@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 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; }
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; }
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()); 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);
@Override public AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.updateByName({}, {})", name, relationshipDef); } AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-def ", name); validateType(relationshipDef); AtlasType type = typeRegistry.getType(relationshipDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex); AtlasRelationshipDef ret = toRelationshipDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.updateByName({}, {}): {}", name, relationshipDef, ret); } return ret; }
@Override public AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.updateByName({}, {})", name, relationshipDef); } AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-def ", name); validateType(relationshipDef); AtlasType type = typeRegistry.getType(relationshipDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex); AtlasRelationshipDef ret = toRelationshipDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.updateByName({}, {}): {}", name, relationshipDef, ret); } return ret; }
@Override public AtlasRelationshipDef updateByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.updateByGuid({})", guid); } AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-Def ", (existingDef != null ? existingDef.getName() : guid)); validateType(relationshipDef); AtlasType type = typeRegistry.getTypeByGuid(guid); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex); // updates should not effect the edges between the types as we do not allow updates that change the endpoints. AtlasRelationshipDef ret = toRelationshipDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.updateByGuid({}): {}", guid, ret); } return ret; }
@Override public AtlasRelationshipDef updateByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.updateByGuid({})", guid); } AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-Def ", (existingDef != null ? existingDef.getName() : guid)); validateType(relationshipDef); AtlasType type = typeRegistry.getTypeByGuid(guid); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex); // updates should not effect the edges between the types as we do not allow updates that change the endpoints. AtlasRelationshipDef ret = toRelationshipDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.updateByGuid({}): {}", guid, ret); } return ret; }
@Override public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.preDeleteByGuid({})", guid); } AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete relationship-def ", (existingDef != null ? existingDef.getName() : guid)); AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP); if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } String typeName = AtlasGraphUtilsV2.getEncodedProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class); if (AtlasGraphUtilsV2.relationshipTypeHasInstanceEdges(typeName)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName); } typeDefStore.deleteTypeVertexOutEdges(ret); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.preDeleteByGuid({}): {}", guid, ret); } return ret; }
@Override public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.preDeleteByGuid({})", guid); } AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete relationship-def ", (existingDef != null ? existingDef.getName() : guid)); AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP); if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } String typeName = AtlasGraphUtilsV2.getEncodedProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class); if (AtlasGraphUtilsV2.relationshipTypeHasInstanceEdges(typeName)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName); } typeDefStore.deleteTypeVertexOutEdges(ret); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.preDeleteByGuid({}): {}", guid, ret); } return ret; }
String existingName = existingRelationshipDef.getName(); String newName = newRelationshipDef.getName(); newRelationshipDef.getName(),newRelationshipCategory.name(), existingRelationshipCategory.name() ); newRelationshipDef.getName(), newEnd1.toString(), existingEnd1.toString()); newRelationshipDef.getName(), newEnd2.toString(), existingEnd2.toString());
String existingName = existingRelationshipDef.getName(); String newName = newRelationshipDef.getName(); newRelationshipDef.getName(),newRelationshipCategory.name(), existingRelationshipCategory.name() ); newRelationshipDef.getName(), newEnd1.toString(), existingEnd1.toString()); newRelationshipDef.getName(), newEnd2.toString(), existingEnd2.toString());
if (!typeRegistry.isRegisteredType(relationshipDef.getName())) { typesToCreate.getRelationshipDefs().add(relationshipDef);
AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); RelationshipCategory relationshipCategory = relationshipDef.getRelationshipCategory(); String name = relationshipDef.getName(); boolean isContainer1 = endDef1.getIsContainer(); boolean isContainer2 = endDef2.getIsContainer();
AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); RelationshipCategory relationshipCategory = relationshipDef.getRelationshipCategory(); String name = relationshipDef.getName();