背景
- 可以从
/ambari-server/src/main/resources/stacks
源码中查找Stack
的相关定义;- 当安装完ambari-server后,可以在
/var/lib/ambari-server/resources/stacks
目录下查找stack相关定义;
Stack配置
stack必须包含或者集成以下两个配置: stack_features.json and stack_tools.json,配置目录必须在stack根目录下;
stack_features.json
: 该配置包含了在ambari中定义的一些的特征,并包含该特征的版本、描述信息。比如,配置如下:
{
"stack_features": [
{
"name": "rolling_upgrade",
"description": "Rolling upgrade support",
"min_version": "0.1.0.0"
},
{
"name": "config_versioning",
"description": "Configurable versions support",
"min_version": "0.1.0.0"
},
{
"name": "snappy",
"description": "Snappy compressor/decompressor support",
"min_version": "0.1.0.0"
},
{
"name": "ranger_kerberos_support",
"description": "Ranger Kerberos support",
"min_version": "0.1.0.0"
},
{
"name": "ranger_audit_db_support",
"description": "Ranger Audit to DB support",
"min_version": "0.1.0.0"
}
]
}
stack_tools.json
: 该配置包含了stack_selector
和conf_selector
安装路径;比如:
{
"stack_selector": ["hdp-select", "/usr/bin/hdp-select", "hdp-select"],
"conf_selector": ["conf-select", "/usr/bin/conf-select", "conf-select"]
}
定义一个stack和component
一个Service中metainfo.xml
文件定义了该Service所依赖的组件及该组件的管理脚本等;Service组件的状态可以为: MASTER, SLAVE 或者 CLIENT状态,在metainfo.xml
文件中是通过 指定的;
Component Catergory | Default LifeCycle |
---|---|
Master | install, start, stop, configure, status |
Slave | install, start, stop, configure, status |
Clinet | install, configure, status |
Ambari支持基于Python的各种命令, 你也可以通过定义customCommands
实现不在lifecycle之内的其他生命周期执行命令;
比如说YARN的metainfo.xml
配置如下:
<component>
<name>RESOURCEMANAGER</name>
<category>MASTER</category>
<commandScript>
<script>scripts/resourcemanager.py</script>
<scriptType>PYTHON</scriptType>
<timeout>600</timeout>
</commandScript>
<customCommands>
<customCommand>
<name>DECOMMISSION</name>
<commandScript>
<script>scripts/resourcemanager.py</script>
<scriptType>PYTHON</scriptType>
<timeout>600</timeout>
</commandScript>
</customCommand>
</customCommands>
</component>
其中, RESOURCEMANAGER
是一个master组件,执行脚本为scripts/resourcemanager.py
,该目录位置为services/YARN/package
, 该脚本基于Python实现并实现默认生命周期的执行动作。比如说install动作实现如下:
class Resourcemanager(Script):
def install(self, env):
self.install_packages(env)
self.configure(env)
在上述配置中还实现了一个默认生命周期以外的一个DECOMMISSION
动作,其实现如下:
def decommission(self, env):
import params
...
Execute(yarn_refresh_cmd,
user=yarn_user
)
pass
Stack继承
Stack可以继承其他的Stack,以便于共享脚本和配置,可以通过以下几种方式来避免代码的重复:
* 定义Stack的子仓库;
* 定义Stack的自仓库的新Service;
* 重载父Stack的Service;
* 重载父Stack的Service配置;
比如说HDP2.1 Stack继承HDP 2.06 Stack,只需要在metainfo.xml
配置中添加以下配置既可:
<metainfo>
<versions>
<active>true</active>
</versions>
<extends>2.0.6</extends>
</metainfo>
参考:
* 源文档: https://cwiki.apache.org/confluence/display/AMBARI/Defining+a+Custom+Stack+and+Services