1 Star 0 Fork 8

dabin/HadoopHACluster

forked from AOMEY/HadoopHACluster 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
start-cluster.py 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
from xml.etree.ElementTree import ElementTree,Element
import subprocess
def read_xml(in_path):
tree = ElementTree()
tree.parse(in_path)
return tree
def if_match(node, kv_map):
for key in kv_map:
if node.get(key) != kv_map.get(key):
return False
return True
def find_nodes(tree, path):
return tree.findall(path)
def get_node_by_keyvalue(nodelist, kv_map):
result_nodes = []
for node in nodelist:
if if_match(node, kv_map):
result_nodes.append(node)
return result_nodes
def start_zkserver(node):
start_cmd = []
start_cmd.append("docker")
start_cmd.append("exec")
start_cmd.append("-it")
start_cmd.append(node.attrib["host"])
start_cmd.append("zkServer.sh")
start_cmd.append("start")
print start_cmd
returncode = subprocess.call(start_cmd)
return returncode
def start_dfs(node):
start_cmd = []
start_cmd.append("docker")
start_cmd.append("exec")
start_cmd.append("-it")
start_cmd.append(node.attrib["host"])
start_cmd.append("start-dfs.sh")
print start_cmd
returncode = subprocess.call(start_cmd)
return returncode
def zkcluster_run(nodelist):
for node in nodelist:
start_zkserver(node)
def start_yarn(node):
start_cmd = []
start_cmd.append("docker")
start_cmd.append("exec")
start_cmd.append("-it")
start_cmd.append(node.attrib["host"])
start_cmd.append("start-yarn.sh")
print start_cmd
returncode = subprocess.call(start_cmd)
return returncode
def start_resourcemanager(node):
start_cmd = []
start_cmd.append("docker")
start_cmd.append("exec")
start_cmd.append("-it")
start_cmd.append(node.attrib["host"])
start_cmd.append("yarn-daemon.sh")
start_cmd.append("start")
start_cmd.append("resourcemanager")
print start_cmd
returncode = subprocess.call(start_cmd)
return returncode
def yarn_run(nodelist):
i = 0
for node in nodelist:
i = i + 1
if (i == 1):
start_yarn(node)
else:
start_resourcemanager(node)
if __name__ == "__main__":
cluster = read_xml("hacluster.xml")
clusterlist = find_nodes(cluster, "cluster")
# 1> zk cluster
zkcluster = get_node_by_keyvalue(clusterlist, {"type":"zk"})
zknodes = zkcluster[0].findall("node")
zkdockers = get_node_by_keyvalue(zknodes, {"platform":"docker"})
zkcluster_run(zkdockers)
# 2> hdfs cluster
hdfscluster = get_node_by_keyvalue(clusterlist, {"type":"hdfs"})
hdfsnodes = hdfscluster[0].findall("node")
hdfsdockers = get_node_by_keyvalue(hdfsnodes, {"platform":"docker"})
# 2.1> name node
namenodes = get_node_by_keyvalue(hdfsdockers, {"type":"namenode"})
start_dfs(namenodes[0])
# 3> yarn cluster
yarncluster = get_node_by_keyvalue(clusterlist, {"type":"yarn"})
yarnnodes = yarncluster[0].findall("node")
yarndockers = get_node_by_keyvalue(yarnnodes, {"platform":"docker"})
# 3.1> resource manager
resourcemanagers = get_node_by_keyvalue(yarndockers, {"type":"resourcemanager"})
yarn_run(resourcemanagers)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Docker
1
https://gitee.com/duanshubin/HadoopHACluster.git
git@gitee.com:duanshubin/HadoopHACluster.git
duanshubin
HadoopHACluster
HadoopHACluster
master

搜索帮助