Apache atlas 的入门教程

27 篇文章 0 订阅
2 篇文章 2 订阅

笔者最近参加了2场大数据技术开放活动,在技术分享的时候,发现,2场分享活动,有人不约而同的推荐了Apache atlas 组件,所以,就像介绍一下这个组件。Apache atlas 是个什么样的工具?它有哪些功能和作用?

其实,在本人之前的文章中有介绍,它是一个用在hadoop上的数据治理和元数据框架工具。它是基于hadoop平台上,能无缝对接hadoop平台的组件。前端UI默认使用solr5,有丰富的rest API ,后端数据库可以是hive,hbase等。能导入不同格式的数据源,包括hive,hbase等(传统数据库,暂不清楚)。

1.Apache atlas 安装

安装步骤,官网上面有,链接:

https://atlas.apache.org/InstallationSteps.html

为方便操作,简单翻译一下步骤:
环境:
JDK8
MAVEN3.X
GIT
PYTHON2.7以上

(1)building atlas(构建atlas)

git clone https://git-wip-us.apache.org/repos/asf/atlas.git atlas
cd atlas
export MAVEN_OPTS="-Xms2g -Xmx4g"
mvn clean -DskipTests install

注意:

  • 服务器内存至少要4G。笔者升级了几次配置。这是笔者的截图:
    这里写图片描述

    文件很多,要下比较1-2个小时,中间可能也有fail。

(2)打包atlas

(机器上已经装有hbase和solr)

mvn clean -DskipTests package -Pdist

(机器上没有装hbase和solr,atlas自带hbase和solr)

mvn clean -DskipTests package -Pdist,embedded-hbase-solr

本文这里选了后一种。

(3)打包完,会在根目录下生成以下的包:

(4)安装atlas

tar -xzvf apache-atlas-${project.version}-bin.tar.gz

cd atlas-${project.version}

目前它会自动解压,这一步可以不要。

下载完成后,目录结构:
distro目录

其中,atlas_home/distro/target 下面,
apache-atlas-1.0.0-SNAPSHOT-bin 是其解压后的目录:
atlas1.0目录

注意:接下来是配置步骤。先看完黑体字,再接着看下文。

如果只是atlas默认配置启动,命令

cd /apache_atlas/atlas/distro/target/apache-atlas-1.0.0-SNAPSHOT-bin/apache-atlas-1.0.0-SNAPSHOT
bin/atlas_start.py

测试

curl -v http://localhost:21000/api/atlas/admin/version

报错
Error 401 Full authentication is required to access this resource
HTTP ERROR 401
Problem accessing /api/atlas/admin/version. Reason:
Full authentication is required to access this resource
报错

原因

没有权限,正确命令:

curl -v -u username:password http://localhost:21000/api/atlas/admin/version

username:默认admin
password:默认admin
curl -v -u admin:admin http://localhost:21000/api/atlas/admin/version

这样就成功了。

上面的启动,solr,hbase 是内嵌式的,solr端口是9838,跟独立安装的默认端口8983不一样。如果需要自定义配置,尤其是使用hbase做图库的存储后端(HBase as the Storage Backend for the Graph Repository),solr做图表库的索引后端(SOLR as the Indexing Backend for the Graph Repository),请看下文

(5)配置项。

conf/atlas-env.sh

# The java implementation to use. If JAVA_HOME is not found we expect java and jar to be in path
#export JAVA_HOME=

# any additional java opts you want to set. This will apply to both client and server operations
#export ATLAS_OPTS=

# any additional java opts that you want to set for client only
#export ATLAS_CLIENT_OPTS=

# java heap size we want to set for the client. Default is 1024MB
#export ATLAS_CLIENT_HEAP=

# any additional opts you want to set for atlas service.
#export ATLAS_SERVER_OPTS=

# java heap size we want to set for the atlas server. Default is 1024MB
#export ATLAS_SERVER_HEAP=

# What is is considered as atlas home dir. Default is the base location of the installed software
#export ATLAS_HOME_DIR=

# Where log files are stored. Defatult is logs directory under the base install location
#export ATLAS_LOG_DIR=

# Where pid files are stored. Defatult is logs directory under the base install location
#export ATLAS_PID_DIR=

# Where do you want to expand the war file. By Default it is in /server/webapp dir under the base install dir.
#export ATLAS_EXPANDED_WEBAPP_DIR=

如果/etc/profile没有配JAVA_HOME,需要配JAVA_HOME

配置conf/atlas-application.properties:

#使用hbase tables
atlas.graph.storage.hbase.table=atlas
atlas.audit.hbase.tablename=apache_atlas_entity_audit

这一步,需要安装独立的solr集群,使用zookeeper是solr集群高可用。参考链接:
https://cwiki.apache.org/confluence/display/solr/SolrCloud

启动solr集群

cd solr/bin

./solr create -c vertex_index -d SOLR_CONF -shards #numShards -replicationFactor #replicationFactor
./solr create -c edge_index -d SOLR_CONF -shards #numShards -replicationFactor #replicationFactor
./solr create -c fulltext_index -d SOLR_CONF -shards #numShards -replicationFactor #replicationFactor

SOLR_CONF : solrconfig.xml所在的目录,其实笔者之前也一直没有搞清楚。笔者这里是:
/usr/local/solr-5.5.1

如果不知道要创建多少numShards ,可忽略,默认是1。笔者的配置如下:

cd /apache_atlas/atlas/distro/target/solr/bin
export SOLR_CONF=/usr/local/solr-5.5.1
./solr start -c -z localhost:2181 -p 8983
./solr create -c vertex_index -d $SOLR_CONF
./solr create -c edge_index -d $SOLR_CONF
./solr create -c fulltext_index -d $SOLR_CONF

启动solr集群后,在atlas-application.properties中配置:

#
atlas.kafka.zookeeper.connect=localhost:2181
atlas.graph.index.search.backend=solr5
atlas.graph.index.search.solr.mode=cloud
atlas.graph.index.search.solr.zookeeper-url=10.1.6.4:2181,10.1.6.5:2181
atlas.graph.index.search.solr.zookeeper-connect-timeout=60000 ms
atlas.graph.index.search.solr.zookeeper-session-timeout=60000 ms

启动hbase

cd hbase/bin

./start-hbase.sh

启动atlas:

bin/atlas_start.py

atlas UI界面:

http://localhost:21000/

错误1

java.io.FileNotFoundException: /apache_atlas/atlas/distro/target/server/webapp/atlas.war (No such file or directory)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at java.io.FileInputStream.<init>(FileInputStream.java:93)
    at sun.tools.jar.Main.run(Main.java:307)
    at sun.tools.jar.Main.main(Main.java:1288)
The Server is no longer running with pid 6353
configured for local hbase.
hbase started.
configured for local solr.
solr started.
setting up solr collections...
starting atlas on host localhost
starting atlas on port 21000

这是atlas启动的路径不对导致。网上没有该解决方法。后来发现启动的路径不对,笔者这里,之前启动路径是:
/apache_atlas/atlas/distro/target/
正确的启动路径是:
/apache_atlas/atlas/distro/target/apache-atlas-1.0.0-SNAPSHOT-bin/apache-atlas-1.0.0-SNAPSHOT/

错误2
/apache_atlas/atlas/distro/target/logs 错误日志会有:

ERROR: 
Collection 'vertex_index' already exists!
Checked collection existence using Collections API command:
http://localhost:9838/solr/admin/collections?action=list

这是重名collection冲突。命令:
jps
看看是否有多个jar进程。该进程是solr进程。

希望别人不要犯跟我一样的错误。

错误3

2018-05-05 11:10:18,545 WARN  - [main:] ~ Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'services': Invocation of init method failed; nested exception is java.lang.RuntimeException: org.apache.atlas.AtlasException: Failed to start embedded kafka (AbstractApplicationContext:550)
2018-05-05 11:10:18,699 ERROR - [main:] ~ Context initialization failed (ContextLoader:350)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'services': Invocation of init method failed; nested exception is java.lang.RuntimeException: org.apache.atlas.AtlasException: Failed to start embedded kafka
Caused by: org.apache.atlas.AtlasException: Failed to start embedded kafka
    at org.apache.atlas.kafka.EmbeddedKafkaServer.start(EmbeddedKafkaServer.java:83)
    at org.apache.atlas.service.Services.start(Services.java:67)
    ... 40 more
Caused by: java.net.BindException: Address already in use

原因
端口占用。查看conf/atlas-application.properties
atlas.kafka.zookeeper.connect=localhost:*
端口是否占用。


简单说了下atlas安装,接下来说下使用方式。

2.Apache atlas 使用方式

再说下rest api的使用方式

需要关注的地方:
api部分

Apache atlas Api主要是对Type,Entity,Attribute这3个构件的增删改查操作。这听起来有点意外,实际上,其它的很多东西被封装了,还有包含在配置文件里,留下Api和Admin UI供外部调用。

简单介绍一下这几个构件。

Type

Atlas 中的 “类型” 是一个定义, 说明如何存储并访问特定类型的元数据对象,。类型表示一个特征或一个特性集合, 这些属性定义了元数据对象。具有开发背景的用户将识别类型的相似性, 以面向对象编程语言的 “Class” 定义或关系的 “table schema”数据库。

Entity

Atlas 中的一个 “实体” 是类 “type” 的特定值或实例, 因此表示特定的

现实世界中的元数据对象。回指我们的面向对象的类比

编程语言, “instance” 是某个 “Class” 的 “Object”。

Attribute

属性定义在复合 metatypes 中, 如Class和Struct。

可以简单将属性称为具有名称和 metatype 值。然而

Atlas 中的属性有更多的属性来定义与type system相关的更多概念。


上面的定义难以理解。笔者心理也比较抗拒。所以,先看几个例子。

例子(1)

使用Type定义一个Hive table,而且有一些Attribute

Name: hive_table
MetaType: Class
SuperTypes: DataSet
Attributes:
    name: String (name of the table)
    db: Database object of type hive_db
    owner: String
    createTime: Date
    lastAccessTime: Date
    comment: String
    retention: int
    sd: Storage Description object of type hive_storagedesc
    partitionKeys: Array of objects of type hive_column
    aliases: Array of strings
    columns: Array of objects of type hive_column
    parameters: Map of String keys to String values
    viewOriginalText: String
    viewExpandedText: String
    tableType: String
    temporary: Boolean

这跟java类的定义很相似,也跟json数据定义类似。需要注意的几点:

  1. Atlas 中的类型由 “name” 唯一标识
  2. 每个type 具有 一个metatype。metatype 表示该模型在 Atlas 中的类型。
  3. Atlas 有以下 metatypes:

    • 基本 metatypes: 如 Int、字符串、布尔值等。
    • 枚举 metatypes: TODO
    • 集合 metatypes: 例如阵列、地图
    • 复合 metatypes: 如类、结构、特性

    4.类型可以从名为 “supertype” 的父类型 “extend” 。凭借这一点, 它将得到还包括在超类型中定义的属性。这使模型设计家以在一组相关类型中定义公共属性等。这再次类似于面向对象语言如何定类的超级类的概念。在本示例中, 每个配置单元表都从预定义的超类型称为”DataSet”。有关此预定义的更多详细信息类型将在以后提供。在 Atlas 中的类型也可以从多个超级类型扩展。
    5.具有 “Class”、”Struct” 或 “Trait” metatype 的类型可以有一个集合
    属性。每个属性都有一个名称 (例如 “name”) 和其他一些关联的
    性能。属性可以引用为使用表达式。

从上面的说明看,atlas type似乎具有和java中class类似的性质,比如继承。如果我们按照java中对象关系的角度理解,会更容易理解一些。

例子(2)

一个Entity的定义

id: "9ba387ddfa76429cb791ffc338d3c91f"
typeName: “hive_table”
values:
    name: “customers”
    db: "b42c6cfcc1e742fda9e6890e0adf33bc"
    owner: “admin”
    createTime: "20160620T06:
    13:28.000Z"
    lastAccessTime: "20160620T06:
    13:28.000Z"
    comment: null
    retention: 0
    sd: "ff58025f685441959f753a3058dd8dcf"
    partitionKeys: null
    aliases: null
    columns: ["65e2204f6a234130934a9679af6a211f",
    "d726de70faca46fb9c99cf04f6b579a6",
    ...]
    parameters: {"transient_lastDdlTime": "1466403208"}
    viewOriginalText: null
    viewExpandedText: null
    tableType: “MANAGED_TABLE”
    temporary: false

上面的id就是Entity的id。顺着java 对象的思路,Entity结构也是比较容易理解的。

例子(3)

常用api:

(1)获取所有的types

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

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

Response

{
"results": [
    "Asset",
    "hive_column",
    "Process",
    "storm_node",
    "storm_bolt",
    "falcon_process",
    "falcon_feed_replication",
    "hive_serde",
    "kafka_topic",
    "hive_table",
    "hive_storagedesc",
    "sqoop_dbdatastore",
    "hive_principal_type",
    "fs_permissions",
    "jms_topic",
    "hive_process",
    "falcon_cluster",
    "storm_spout",
    "Referenceable","falcon_feed_creation",
    "falcon_feed",
    "hdfs_path",
    "sqoop_process",
    "Infrastructure",
    "storm_topology",
    "hive_order",
    "DataSet",
    "fs_path",
    "hive_db",
    "file_action"
],
"count": 34,
"requestId": "qtp180396531315
b17554dcf93d4d7fa6ede124388a5759"
}

(2)获取某一个type

GET http://atlas­server­host:port/api/atlas/types / {type_name}

E.g. GET http://atlas­server­host:port/api/atlas/types /hive_column

(3)创建新type

POST http://atlas­server­host:port/api/atlas/type

(4)创建新entity

http://atlas­server­host:port/api/atlas/ entities

entities:是一个数组

(5)获取一个entity:

GET http://atlas­server­host:port/api/atlas/ entities / {guid}

guid:entity的id

(6)获取一个包含某个attribute(属性)的entity

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

(7)更新entity的一个attribute属性

POST http://atlas­server­host:port/api/atlas/ entities/{GUID}

response 都是一个json结构,跟solr api是类似的。


上面是Atlas Api的基本查询等。下面说下在Api中创建血缘关系。

未完待续。

  • 17
    点赞
  • 74
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值