Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Clarification on Apache Atlas Relationships

avatar
New Contributor

Hello.

I am currently in the process of building a TypeDef and would like to include a relationship between this TypeDef and another. I have been researching relationships in Atlas but have become confused in the process of relationship creation. My question is what order of steps are required to build out a working relationship using the v2 API?

2 REPLIES 2

avatar
Contributor

 

If you are still looking for this, the below references might be of help for some insights with AtlasRelationship v2 APIs:

As with other typeDefs the AtlasRelationshipDef has a name. Once created the RelationshipDef has a guid. The name and the guid are the 2 ways that the RelationshipDef is identified.

Ref: https://stackoverflow.com/questions/57385463/simple-example-for-adding-relationships-between-atlas-e...

Additional Ref: https://atlas.apache.org/api/v2/json_AtlasRelationshipDef.html

 

https://atlas.apache.org/api/v2/resource_RelationshipREST.html

avatar
Cloudera Employee

Hopefully the OP is sorted out by now, but for anyone else who comes across this: one of the best step-by-step instructions on Atlas relationships I've found is this comment by Vinayak Marriaya on the Atlas Jira; re-producing here, in case that link dies:

 


Following are the json's to create relationships
1. Creating EntityDef json
2. Creating Entity json
3. Creating RelationshipDef json
4. Creating Relationship instance json

Step-1

Creating EntityDef

POST - http://localhost:21000/api/atlas/v2/types/typedefs

 

{
 "entityDefs": [
 {
 "category": "ENTITY",
 "name": "type_a"
 },
 {
 "category": "ENTITY",
 "name": "type_b"
 }
 ]
}

 

Step-2

Creating Entity

POST - http://localhost:21000/api/atlas/v2/entity/bulk

 

{
 "entities": [
 {
 "typeName": "type_a",
 "guid": "-72ddefefS2UY"
 },
 {
 "typeName": "type_b",
 "guid": "-JL1HddDOfdf"
 }
 ]
}

 

Step-3

Creating RelationshipDef

POST - http://localhost:21000/api/atlas/v2/types/typedefs

 

{
 "relationshipDefs": [
 {
 "propagateTags": "ONE_TO_TWO",
 "description": "description ASSOCIATION between type5 and type6",
 "relationshipCategory": "ASSOCIATION",
 "typeVersion": "1.0",
 "attributeDefs": [
 {
 "name": "LinkInformation",
 "typeName": "string",
 "isOptional": true,
 "cardinality": "SINGLE",
 "valuesMinCount": 0,
 "valuesMaxCount": 1,
 "isUnique": false,
 "isIndexable": false,
 "includeInNotification": false,
 "searchWeight": -1
 }
 ],
 "endDef2": {
 "name": "type_b_rel_attribute",
 "isLegacyAttribute": false,
 "isContainer": false,
 "cardinality": "SINGLE",
 "type": "type_b",
 "description": "description with name: type_2_rel_attribute"
 },
 "endDef1": {
 "name": "type_a_rel_attribute",
 "isLegacyAttribute": false,
 "isContainer": false,
 "cardinality": "SET",
 "type": "type_a",
 "description": "description with name: type_1_rel_attribute"
 },
 "guid": "-2fsdfjhsewl04",
 "name": "association_type_a_and_type_b"
 }
 ]
}
 

Step-4

Creating Relationship instance

POST- http://localhost:21000/api/atlas/v2/relationship

 

{
 "typeName": "association_type_a_and_type_b",
 "end1": {
 "typeName": "type_a",
 "guid": "b4dae5e8-a606-4e41-9ce3-8f35245f389e" (guid of type_a entity)
 },
 "propagateTags": "NONE",
 "provenanceType": 0,
 "propagatedClassifications": [],
 "end2": {
 "typeName": "type_b",
 "guid": "23c2f3c1-dd74-4190-a6d1-b012c44cbb6d" (guid of type_b entity)
 },
 "blockedPropagatedClassifications": [],
 "guid": "-bjbfdfddfeffef",
 "attributes": {
 "LinkInformation": "TestingInformation"
 }
}

 

 

Following is the output of the above API call.

Output of type_a entity

GET - http://localhost:21000/api/atlas/v2/entity/guid/\{guid of type_a entity}

 

{
 "referredEntities": {},
 "entity": {
 "typeName": "type_a",
 "guid": "b4dae5e8-a606-4e41-9ce3-8f35245f389e",
 "isIncomplete": false,
 "status": "ACTIVE",
 "createdBy": "admin",
 "updatedBy": "admin",
 "createTime": 1632121151626,
 "updateTime": 1632121151626,
 "version": 0,
 "relationshipAttributes": {
 "type_a_rel_attribute": [
 {
 "guid": "23c2f3c1-dd74-4190-a6d1-b012c44cbb6d",
 "typeName": "type_b",
 "entityStatus": "ACTIVE",
 "relationshipType": "association_type_a_and_type_b",
 "relationshipGuid": "ec64783a-58d7-4265-87d6-c1535ce2d9b7",
 "relationshipStatus": "ACTIVE",
 "relationshipAttributes": {
 "typeName": "association_type_a_and_type_b",
 "attributes": {
 "LinkInformation": "TestingInformation"
 }
 }
 }
 ]
 },
 "labels": []
 }
}
 

Output of type_b entity

GET - http://localhost:21000/api/atlas/v2/entity/guid/\{guid of type_b entity}

{
 "referredEntities": {},
 "entity": {
 "typeName": "type_b",
 "guid": "23c2f3c1-dd74-4190-a6d1-b012c44cbb6d",
 "isIncomplete": false,
 "status": "ACTIVE",
 "createdBy": "admin",
 "updatedBy": "admin",
 "createTime": 1632121151626,
 "updateTime": 1632121151626,
 "version": 0,
 "relationshipAttributes": {
 "type_b_rel_attribute": {
 "guid": "b4dae5e8-a606-4e41-9ce3-8f35245f389e",
 "typeName": "type_a",
 "entityStatus": "ACTIVE",
 "relationshipType": "association_type_a_and_type_b",
 "relationshipGuid": "ec64783a-58d7-4265-87d6-c1535ce2d9b7",
 "relationshipStatus": "ACTIVE",
 "relationshipAttributes": {
 "typeName": "association_type_a_and_type_b",
 "attributes": {
 "LinkInformation": "TestingInformation"
 }
 }
 }
 },
 "labels": []
 }
}

As you can see, LinkInformation is specified under "attributes" and when you search for the entity using GUID as you mentioned in jira, you will be able to see the value of "LinkInformation".