Apache Atlas 架构图

Atlas 支持多数据源接入:Hive、HBase、Storm等

Type System

Type

Atlas 中定义了一些元数据类型

  1. ── AtlasBaseTypeDef
  2. ├── AtlasEnumDef
  3. └── AtlasStructDef
  4. ├── AtlasBusinessMetadataDef
  5. ├── AtlasClassificationDef
  6. ├── AtlasEntityDef
  7. └── AtlasRelationshipDef
  8. ├── AtlasStructType
  9. ├── AtlasBusinessMetadataType
  10. ├── AtlasClassificationType
  11. ├── AtlasRelationshipType
  12. └── AtlasEntityType
  13. └── AtlasRootEntityType
  14. ├── AtlasType
  15. ├── AtlasArrayType
  16. ├── AtlasBigDecimalType
  17. ├── AtlasBigIntegerType
  18. ├── AtlasByteType
  19. ├── AtlasDateType
  20. ├── AtlasDoubleType
  21. ├── AtlasEnumType
  22. ├── AtlasFloatType
  23. ├── AtlasIntType
  24. ├── AtlasLongType
  25. ├── AtlasMapType
  26. ├── AtlasObjectIdType
  27. ├── AtlasShortType
  28. ├── AtlasStringType
  29. └── AtlasStructType
  30. ├── AtlasBusinessMetadataType
  31. ├── AtlasClassificationType
  32. ├── AtlasEntityType
  33. └── AtlasRelationshipType
  34. ├── AtlasTypeDefStore
  35. └── AtlasTypeDefGraphStore
  36. └── AtlasTypeDefGraphStoreV2
  37. └── StructTypeDefinition
  38. └── HierarchicalTypeDefinition
  39. ├── ClassTypeDefinition
  40. └── TraitTypeDefinition

Entity

Entity 是基于类型的具体实现

  1. AtlasEntity
  2. ├── AtlasEntityExtInfo
  3. ├── AtlasEntitiesWithExtInfo
  4. └── AtlasEntityWithExtInfo
  5. ├── AtlasEntityStore
  6. └── AtlasEntityStoreV2
  7. ├── AtlasEntityStream
  8. └── AtlasEntityStreamForImport
  9. ├── AtlasEntityType
  10. └── AtlasRootEntityType
  11. └── IAtlasEntityChangeNotifier
  12. ├── AtlasEntityChangeNotifier
  13. └── EntityChangeNotifierNop

Attributes

针对模型定义属性

  1. AtlasAttributeDef
  2. └── AtlasRelationshipAttributeDef

AtlasAttributeDef 属性字段:

  1. private String name;
  2. private String typeName;
  3. private boolean isOptional;
  4. private Cardinality cardinality;
  5. private int valuesMinCount;
  6. private int valuesMaxCount;
  7. private boolean isUnique;
  8. private boolean isIndexable;
  9. private boolean includeInNotification;
  10. private String defaultValue;
  11. private String description;
  12. private int searchWeight = DEFAULT_SEARCHWEIGHT;
  13. private IndexType indexType = null;
  14. private List<AtlasConstraintDef> constraints;
  15. private Map<String, String> options;
  16. private String displayName;
  17. 具体实现:
  18. db:
  19. "name": "db",
  20. "typeName": "hive_db",
  21. "isOptional": false,
  22. "isIndexable": true,
  23. "isUnique": false,
  24. "cardinality": "SINGLE"
  25. columns:
  26. "name": "columns",
  27. "typeName": "array<hive_column>",
  28. "isOptional": optional,
  29. "isIndexable": true,
  30. isUnique": false,
  31. "constraints": [ { "type": "ownedRef" } ]
  • isComposite - 是否复合
  • isIndexable - 是否索引
  • isUnique - 是否唯一
  • multiplicity - 指示此属性是(必需的/可选的/还是可以是多值)的

System specific types and their significance

Referenceable

This type represents all entities that can be searched for using a unique attribute called qualifiedName.

  1. ├── Referenceable
  2. ├── ReferenceableDeserializer
  3. ├── ReferenceableSerializer
  4. └── V1SearchReferenceableSerializer

Hooks

以Hive元信息采集为例分析采集过程:

全量导入

import-hive.sh

  1. "${JAVA_BIN}" ${JAVA_PROPERTIES} -cp "${CP}"
  2. org.apache.atlas.hive.bridge.HiveMetaStoreBridge $IMPORT_ARGS
  1. importTables
  2. └── importDatabases [addons/hive-bridge/src/main/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridge.java +295]
  3. └── importHiveMetadata [addons/hive-bridge/src/main/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridge.java +289]

上面是调用过程:

importTables -> importTable --> registerInstances

  1. AtlasEntitiesWithExtInfo ret = null;
  2. EntityMutationResponse response = atlasClientV2.createEntities(entities);
  3. List<AtlasEntityHeader> createdEntities = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);
  4. if (CollectionUtils.isNotEmpty(createdEntities)) {
  5. ret = new AtlasEntitiesWithExtInfo();
  6. for (AtlasEntityHeader createdEntity : createdEntities) {
  7. AtlasEntityWithExtInfo entity = atlasClientV2.getEntityByGuid(createdEntity.getGuid());
  8. ret.addEntity(entity.getEntity());
  9. if (MapUtils.isNotEmpty(entity.getReferredEntities())) {
  10. for (Map.Entry<String, AtlasEntity> entry : entity.getReferredEntities().entrySet()) {
  11. ret.addReferredEntity(entry.getKey(), entry.getValue());
  12. }
  13. }
  14. LOG.info("Created {} entity: name={}, guid={}", entity.getEntity().getTypeName(), entity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME), entity.getEntity().getGuid());
  15. }
  16. }

通过Http Post 的请求将库表数据更新至Atlas

atlasClientV2有很多Http接口

Atlas HTTP 客户端API:

实时监听

HiveHook implements ExecuteWithHookContext

ExecuteWithHookContext is a new interface that the Pre/Post Execute Hook can run with the HookContext.

实现run()方法来对Hive 相关事件做处理

Hive相关事件:

  1. BaseHiveEvent
  2. ├── AlterTableRename
  3. ├── CreateHiveProcess
  4. ├── DropDatabase
  5. ├── DropTable
  6. ├── CreateDatabase
  7. └── AlterDatabase
  8. └── CreateTable
  9. └── AlterTable
  10. └── AlterTableRenameCol

以create database 为例分析流程:

  1. //处理Hook 上下文信息
  2. AtlasHiveHookContext context =
  3. new AtlasHiveHookContext(this, oper, hookContext, getKnownObjects(), isSkipTempTables());
  4. //建库事件处理,提取相关库信息
  5. event = new CreateDatabase(context);
  6. if (event != null) {
  7. final UserGroupInformation ugi = hookContext.getUgi() == null ? Utils.getUGI() : hookContext.getUgi();
  8. super.notifyEntities(ActiveEntityFilter.apply(event.getNotificationMessages()), ugi);
  9. }
  10. public enum HookNotificationType {
  11. TYPE_CREATE, TYPE_UPDATE, ENTITY_CREATE, ENTITY_PARTIAL_UPDATE, ENTITY_FULL_UPDATE, ENTITY_DELETE,
  12. ENTITY_CREATE_V2, ENTITY_PARTIAL_UPDATE_V2, ENTITY_FULL_UPDATE_V2, ENTITY_DELETE_V2
  13. }
  14. //操作用户获取
  15. if (context.isMetastoreHook()) {
  16. try {
  17. ugi = SecurityUtils.getUGI();
  18. } catch (Exception e) {
  19. //do nothing
  20. }
  21. } else {
  22. ret = getHiveUserName();
  23. if (StringUtils.isEmpty(ret)) {
  24. ugi = getUgi();
  25. }
  26. }
  27. if (ugi != null) {
  28. ret = ugi.getShortUserName();
  29. }
  30. if (StringUtils.isEmpty(ret)) {
  31. try {
  32. ret = UserGroupInformation.getCurrentUser().getShortUserName();
  33. } catch (IOException e) {
  34. LOG.warn("Failed for UserGroupInformation.getCurrentUser() ", e);
  35. ret = System.getProperty("user.name");
  36. }
  37. }

主要:

获取实体信息, 传递Hook message的类型、操作用户

notifyEntities 可以看出其他组件HBase、impala也会调用该方法进行消息的发送

  1. public static void notifyEntities(List<HookNotification> messages, UserGroupInformation ugi, int maxRetries) {
  2. if (executor == null) { // send synchronously
  3. notifyEntitiesInternal(messages, maxRetries, ugi, notificationInterface, logFailedMessages, failedMessagesLogger);
  4. } else {
  5. executor.submit(new Runnable() {
  6. @Override
  7. public void run() {
  8. notifyEntitiesInternal(messages, maxRetries, ugi, notificationInterface, logFailedMessages, failedMessagesLogger);
  9. }
  10. });
  11. }
  12. }

消息通知框架:

  1. NotificationInterface
  2. ├── AtlasFileSpool
  3. └── AbstractNotification
  4. ├── KafkaNotification
  5. └── Spooler

数据写入Kafka中:

  1. @Override
  2. public void sendInternal(NotificationType notificationType, List<String> messages) throws NotificationException {
  3. KafkaProducer producer = getOrCreateProducer(notificationType);
  4. sendInternalToProducer(producer, notificationType, messages);
  5. }

根据NotificationType写入指定topic 中:

  1. private static final Map<NotificationType, String> PRODUCER_TOPIC_MAP = new HashMap<NotificationType, String>() {
  2. {
  3. put(NotificationType.HOOK, ATLAS_HOOK_TOPIC);
  4. put(NotificationType.ENTITIES, ATLAS_ENTITIES_TOPIC);
  5. }
  6. };
  7. NOTIFICATION_HOOK_TOPIC_NAME("atlas.notification.hook.topic.name", "ATLAS_HOOK"),
  8. NOTIFICATION_ENTITIES_TOPIC_NAME("atlas.notification.entities.topic.name", "ATLAS_ENTITIES"),

数据主要写入两个Topic中: ATLAS_ENTITIES、ATLAS_HOOK

ATLAS_HOOK是写入Hook事件消息, 创建库的事件元数据信息会写入该Topic中

如何唯一确定一个库:

  1. public String getQualifiedName(Database db) {
  2. return getDatabaseName(db) + QNAME_SEP_METADATA_NAMESPACE + getMetadataNamespace();
  3. }

dbName@clusterName 确定唯一性

外延应用

一个基于Hive hook 实现Impala 元数据刷新的用例:

AutoRefreshImpala:https://github.com/Observe-secretly/AutoRefreshImpala

参考

[1] Apache Atlas – Data Governance and Metadata framework for Hadoop

[2] Apache Atlas 源码

[Apache Atlas] Atlas 架构设计及源代码简单分析的更多相关文章

  1. FFmpeg的HEVC解码器源代码简单分析:环路滤波(Loop Filter)

    ===================================================== HEVC源代码分析文章列表: [解码 -libavcodec HEVC 解码器] FFmpe ...

  2. FFmpeg的HEVC解码器源代码简单分析:CTU解码(CTU Decode)部分-TU

    ===================================================== HEVC源代码分析文章列表: [解码 -libavcodec HEVC 解码器] FFmpe ...

  3. FFmpeg的HEVC解码器源代码简单分析:CTU解码(CTU Decode)部分-PU

    ===================================================== HEVC源代码分析文章列表: [解码 -libavcodec HEVC 解码器] FFmpe ...

  4. FFmpeg源代码简单分析:libavdevice的gdigrab

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  5. FFmpeg源代码简单分析:libavdevice的avdevice_register_all()

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  6. FFmpeg源代码简单分析:configure

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  7. FFmpeg源代码简单分析:makefile

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  8. FFmpeg源代码简单分析:libswscale的sws_scale()

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  9. FFmpeg源代码简单分析:libswscale的sws_getContext()

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

随机推荐

  1. C# 为什么你应该更喜欢 is 关键字而不是 == 运算符

    前言 在C# 进行开发中,检查参数值是否为null大家都用什么?本文介绍除了传统的方式==运算符,还有一种可以商用is关键字. C# 7.0 中 is 关键字的使用 传统的方式是使用==运算符: if ...

  2. 关于const声明一些东西

    const int a;        int const a;        const int *a;     int *const a;    const int *const a;   前两个 ...

  3. LiteFlow 2.6.0版本发行注记,项目逻辑解耦的利器

    前言 自从LiteFlow 2.5.X版本发布依赖,陆续经历了10个小版本的迭代.社区群也稳固增长,每天都有很多小伙伴在问我问题. 但是我发现最多人问我的还是:什么时候能支持界面编排? 从LiteFL ...

  4. 【Vulnhub】 DC-4 靶机

    Vulnhub DC-4 一.环境搭建 下载链接:https://www.vulnhub.com/entry/dc-4,313/ 解压后用VMware打开,导入虚拟机 网卡配置看个人习惯,我喜欢NAT ...

  5. ☕【Java技术指南】「编译器专题」重塑认识Java编译器的执行过程(常量优化机制)!

    问题概括 静态常量可以再编译器确定字面量,但常量并不一定在编译期就确定了, 也可以在运行时确定,所以Java针对某些情况制定了常量优化机制. 常量优化机制 给一个变量赋值,如果等于号的右边是常量的表达 ...

  6. springboot整合多数据源解决分布式事务

    一.前言        springboot整合多数据源解决分布式事务.             1.多数据源采用分包策略              2.全局分布式事务管理:jta-atomikos. ...

  7. 彻底搞懂volatile关键字

    对于volatile这个关键字,相信很多朋友都听说过,甚至使用过,这个关键字虽然字面上理解起来比较简单,但是要用好起来却不是一件容易的事.这篇文章将从多个方面来讲解volatile,让你对它更加理解. ...

  8. WPF 勾选划线

    最近项目需要一个左右侧一对多的划线功能 我们先来看一下效果秃: 主要功能: 支持动态添加 支持复选 支持修改颜色 支持动态宽度 主要实现:事件的传递 应用场景:购物互选,食品搭配,角色互选 数据源 左 ...

  9. ubuntu黑屏无法进入系统【Recovery Mode急救】

    一.问题 前言:因为一次美化配置ubuntu导致系统启动黑屏,无法进入系统.之前并没有系统备份,后果严重还好修复了,记录下修复步骤备用.  事件:就是因为修改了 /usr/share/gnome-sh ...

  10. linux 常用命令(四)——(centos7-centos6.8)Vim安装

    centos是默认安装了vi编辑器的,vim编辑器是没安装或者未完全安装的,个人习惯用vim,所以记录一下vim编辑器的安装: 1.查看vim相关软件信息: yum search vim 2.在线安装 ...