Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created on 10-23-2015 07:18 PM
Traits are Atlas types that act like decorators to provide a mechanism for classification. Traits can be applied to any Atlas entities (instances of classes). An entity can have any number of traits.
For example, a SECURITY_CLEARANCE trait could be defined with an attribute ‘security_level’. An Atlas entity (e.g. an instance of Person class) could be tagged with the SECURITY_CLEARANCE trait by providing a value for the trait’s ‘security_level’ attribute.
In order to use a trait, you first need to define the trait type. You can do that by posting to the Types resource of the Atlas REST APIs.
A type is the description of any representable item. In this case we are creating a trait type but the same resource is used to represent enums, structs and classes as well.
Submits a types definition containing a type definition representing a trait.
Request Body
Types Definition application/json
Response Body
Types Response application/json
Properties
enumTypes : Array of Type Definition for ENUM types
structTypes : Array of Type Definition for STRUCT types
traitTypes : Array of Type Definition for TRAIT types
classTypes : Array of Type Definition for CLASS types
Properties
superTypes : Array of super type names.
hierarchicalMetaTypeName : String : The trait class name.
typeName : String : The type name.
attributeDefinitions : Array of Attribute Definition.
Properties
name : String : The attribute name.
dataTypeName : String : The owning data type name.
multiplicity : String : OPTIONAL, REQUIRED, COLLECTION, SET
isComposite : Boolean : True if the attribute’s lifecycle is dependent on the enclosing type and is not just a reference.
isUnique : Boolean : True if the attribute must be unique.
isIndexable : Boolean : True if the attribute can be indexed.
reverseAttributeName : String : If this is a reference attribute, then the name of the attribute on the Class that this refers to.
Properties
requestId : String : The unique id for the request.
types : Array of Type Name Definition.
Properties
name : String : The type name.
The following example creates an Atlas trait type called EXPIRES_ON that has a single attribute called ‘expiry_date’.
POST
http://c6401.ambari.apache.org:21000/api/atlas/types
{
"enumTypes": [],
"structTypes": [],
"traitTypes": [
{
"superTypes":[],
"hierarchicalMetaTypeName":
"org.apache.atlas.typesystem.types.TraitType",
"typeName": "EXPIRES_ON",
"attributeDefinitions": [
{
"name": "expiry_date",
"dataTypeName": "date",
"multiplicity": "required",
"isComposite": false,
"isUnique": false,
"isIndexable": true,
"reverseAttributeName": null
}
]
}
],
"classTypes": []
}{
requestId:"qtp1796488937-14 - 1a194816-1c6f-451a-b706-6dc2f53139e5"
types:{
name:"EXPIRES_ON"
}
}
Created on 06-14-2016 05:31 PM
Hello,
Can you tell me which version of HDP and Atlas that you tested this with? I tried today with HDP 2.4, which comes with Atlas 0.5.0.2.4, and I'm getting an error regarding "Unable to deserialize json"
I'm using the following curl command to test:
curl -iv -d @./atlas_payload.json -H "Content-Type: application/json" -X POST http://sandbox.hortonworks.com:21000/api/atlas/types
Thanks!
Created on 06-14-2016 07:09 PM
I figured this out. I had left out dataTypeName as part of the attributeDefinitions.
Created on 08-23-2016 03:17 AM
@bhagan I am getting same error. did you flatten the json?
Created on 08-23-2016 01:16 PM
Yes, I did flatten the json. Here is what I used (all one line):
{"enumTypes":[],"structTypes":[],"traitTypes": [{"superTypes":[],"hierarchicalMetaTypeName":"org.apache.atlas.typesystem.types.TraitType","typeName":"EXPIRES_ON","attributeDefinitions":[{"name":"expiry_date","dataTypeName":"string","multiplicity":"required","isComposite":false,"isUnique":false,"isIndexable":true,"reverseAttributeName": null}]}],"classTypes":[]}
But for me, I had left out an attribute.