1. 程式人生 > >元資料與資料治理|Apache Atlas API使用入門(第十一篇)

元資料與資料治理|Apache Atlas API使用入門(第十一篇)

一 概念講解

Apache atlas Api主要是對Type,Entity,Attribute這3個構件的增刪改查操作(Api和Admin UI供外部呼叫,其它的被封裝或在 配置檔案中)

Atlas Type System
     Atlas 型別系統,Atlas 允許使用者為他們想要管理的元資料物件定義一個模型。該模型由稱為 “型別” 的定義組成。被稱為 “實體” 的 “型別” 例項表示被管理的實際元資料物件。型別系統是一個元件,允許使用者定義和管理型別和實體。由 Atlas 管理的所有元資料物件(例如Hive表)都使用型別進行建模,並表示為實體。如果要在Atlas中儲存新型別的元資料,需要了解型別系統元件的概念。

參考連結:https://blog.csdn.net/qq_36096641/article/details/83502079

Type:(類:Persion)

Atlas中的 “型別” 定義瞭如何儲存和訪問特定型別的元資料物件。型別表示了所定義元資料物件的一個或多個屬性集合。具有開發背景的使用者可以將 “型別” 理解成面向物件的程式語言的 “類” (Class定義的或關係資料庫的 “表模式”(table schema

可以通過該API獲取Atlas的所有型別:http://127.0.0.1:21000/api/atlas/v2/types/typedefs

下面通過該API獲取hive_table型別的定義:http://atlas:21000/api/atlas/v2/types/typedef/name/hive_table
 

Entity:(實體:new Persion()  張三)

Atlas 中的一個 “實體” 是類 “type” 的特定值或例項, 因此表示特定的

現實世界中的元資料物件。回指我們的面向物件的類比

程式語言, “instance” 是某個 “Class” 的 “Object”。

Attribute:(ExtMap額外更多的屬性?暫且這麼理解 ?)

屬性定義在複合 metatypes 中, 如Class和Struct。

可以簡單將屬性稱為具有名稱和 metatype 值。然而

Atlas 中的屬性有更多的屬性來定義與type system相關的更多概念。

二  Demo應用

Type

1.  使用Type定義一個Hive table,而且有一些Attribute

這跟java類的定義很相似,也跟json資料定義類似。需要注意的幾點:

Atlas 中的型別由 “name” 唯一標識
每個type 具有 一個metatype。metatype 表示該模型在 Atlas 中的型別。
Atlas 有以下 metatypes:

  1. 基本 metatypes: 如 Int、字串、布林值等。
  2. 列舉 metatypes: TODO
  3. 集合 metatypes: 例如陣列、地圖
  4. 複合 metatypes: 如類、結構、特性

4.型別可以從名為 “supertype” 的父型別 “extend” 。憑藉這一點, 它將得到還包括在超型別中定義的屬性。這使模型設計家以在一組相關型別中定義公共屬性等。這再次類似於面嚮物件語言如何定類的超級類的概念。在本示例中, 每個配置單元表都從預定義的超型別稱為”DataSet”。有關此預定義的更多詳細資訊型別將在以後提供。在 Atlas 中的型別也可以從多個超級型別擴充套件。 
5.具有 “Class”、”Struct” 或 “Trait” metatype 的型別可以有一個集合 
屬性。每個屬性都有一個名稱 (例如 “name”) 和其他一些關聯的 
效能。屬性可以引用為使用表示式。

從上面的說明看,atlas type似乎具有和java中class類似的性質,比如繼承。如果我們按照java中物件關係的角度理解,會更容易理解一些。

 

Entity

2 .一個Entity的定義

上面的id就是Entity的id。順著java 物件的思路,Entity結構也是比較容易理解的。

三、常用Rest API

 

  Atlas REST API 參考地址:http://atlas.apache.org/api/v2/

 

1.獲取所有的types

GET http://ip:port/api/atlas/types

GET http://ip:port/api/atlas/types?type=STRUCT|CLASS|TRAIT

如下圖

{
	"requestId": "pool-1-thread-4 - 088d30a2-870a-4257-9c22-98885de21224",
	"count": 109,
	"results": ["hive_principal_type", "AtlasGlossaryTermRelationshipStatus", "file_action", "AtlasGlossaryTermAssignmentStatus", "aws_tag", "aws_cloud_watch_metric", "aws_s3_access_policy", "hive_order", "hive_serde", "aws_s3_bucket_lifeCycleRule", "fs_permissions", "DataSet", "Process", "hive_table", "avro_primitive", "storm_node", "Referenceable", "jms_topic", "falcon_feed", "rdbms_column", "Asset", "hbase_column_family", "avro_collection", "hive_column", "avro_schema", "__AtlasUserSavedSearch", "avro_record", "__internal", "storm_bolt", "avro_type", "falcon_cluster", "aws_s3_object", "aws_s3_bucket", "fs_path", "falcon_feed_replication", "falcon_process", "rdbms_foreign_key", "avro_fixed", "falcon_feed_creation", "AtlasGlossaryCategory", "__AtlasUserProfile", "aws_s3_pseudo_dir", "hive_db", "sqoop_dbdatastore", "hbase_namespace", "avro_field", "hive_process", "hbase_column", "rdbms_instance", "hbase_table", "rdbms_table", "storm_topology", "Infrastructure", "storm_spout", "rdbms_db", "kafka_topic", "AtlasGlossary", "hive_storagedesc", "hdfs_path", "AtlasGlossaryTerm", "sqoop_process", "hive_column_lineage", "rdbms_index", "avro_enum", "storm_topology_nodes", "AtlasGlossaryTranslation", "avro_schema_associatedEntities", "AtlasGlossaryCategoryHierarchyLink", "aws_s3_bucket_aws_s3_pseudo_dirs", "AtlasGlossaryTermAnchor", "AtlasGlossaryCategoryAnchor", "hbase_table_column_families", "AtlasGlossaryValidValue", "falcon_feed_cluster", "hive_process_column_lineage", "AtlasGlossaryAntonym", "AtlasGlossaryPreferredTerm", "AtlasGlossarySynonym", "avro_record_fields", "rdbms_table_foreign_key", "aws_s3_object_avro_schema", "hbase_column_family_columns", "kafka_topic_avroSchema", "rdbms_table_indexes", "AtlasGlossarySemanticAssignment", "AtlasGlossaryReplacementTerm", "rdbms_foreign_key_key_columns", "aws_s3_pseudo_dir_avro_schema", "AtlasGlossaryRelatedTerm", "process_dataset_outputs", "__AtlasUserProfile_savedsearches", "falcon_cluster_feed_creation", "dataset_process_inputs", "rdbms_foreign_key_table_references", "aws_s3_pseudo_dir_aws_objects", "rdbms_instance_databases", "rdbms_foreign_key_column_references", "hbase_table_namespace", "rdbms_db_tables", "avro_field_types", "falcon_cluster_process", "hive_table_storagedesc", "hive_table_columns", "AtlasGlossaryIsARelationship", "rdbms_index_columns", "hive_table_partitionkeys", "rdbms_table_columns", "AtlasGlossaryTermCategorization", "hive_table_db"]
}

(2)獲取某一個type:

GET http://ip:port/api/atlas/types / {type_name}

(3)建立新type:

POST http://ip:port/api/atlas/type

(4)建立新entity:

http://ip:port/api/atlas/entities

entities:是一個數組

(5)獲取一個entity:

GET http://ip:port/api/atlas/ entities / {guid}

guid:entity的id

(6)獲取一個包含某個attribute(屬性)的entity:

GET http://ip:port/api/atlas/ entities?type={type_name}&p roperty={unique_attribute_name}&value={unique_attribute_value

(7)更新entity的一個attribute屬性:

POST http://ip:port/api/atlas/ entities/{GUID}

response 都是一個json結構,跟solr api是類似的。
 

 四、關注  Rest API 介面

 

參考連結:https://blog.csdn.net/cafebar123/article/details/79944247