0

python-ambariclient库有一个用于检索 host_components 的 api :

ambari.services(service_name).components(component_name).host_components

如何提取 IBM Analytics Engine 集群的 name_node?

我想我需要打个电话:

GET https://xxxx.bi.services.us-south.bluemix.net:9443/api/v1/clusters/AnalyticsEngine/services/HDFS/components/NAMENODE?fields=host_components

其中检索以下信息:

{
  "href" : "https://xxxx.bi.services.us-south.bluemix.net:9443/api/v1/clusters/AnalyticsEngine/services/HDFS/components/NAMENODE?fields=host_components",
  "ServiceComponentInfo" : {
    "cluster_name" : "AnalyticsEngine",
    "component_name" : "NAMENODE",
    "service_name" : "HDFS"
  },
  "host_components" : [
    {
      "href" : "https://xxxx.bi.services.us-south.bluemix.net:9443/api/v1/clusters/AnalyticsEngine/hosts/xxxx.bi.services.us-south.bluemix.net/host_components/NAMENODE",
      "HostRoles" : {
        "cluster_name" : "AnalyticsEngine",
        "component_name" : "NAMENODE",
        "host_name" : "xxxx.bi.services.us-south.bluemix.net"
      }
    }
  ]
}
4

2 回答 2

0

首先,安装python-ambariclient库:

! pip install --quiet python-ambariclient

接下来,您可以使用以下内容检索名称节点主机名:

from future.standard_library import install_aliases
install_aliases()
from urllib.parse import urlparse

import json
vcap = json.load(open('./vcap.json'))

USER         = vcap['cluster']['user']
PASSWORD     = vcap['cluster']['password']
AMBARI_URL   = vcap['cluster']['service_endpoints']['ambari_console']
CLUSTER_ID   = vcap['cluster']['cluster_id']

url = urlparse(AMBARI_URL)

HOST = url.hostname
PORT = url.port
PROTOCOL = url.scheme

from ambariclient.client import Ambari
ambari = Ambari(HOST, port=PORT, username=USER, password=PASSWORD, protocol=PROTOCOL)

CLUSTER_NAME = ambari.clusters.next().cluster_name # gets first cluster - there will only be one

namenode_hc = ambari.clusters(CLUSTER_NAME).services('HDFS').components('NAMENODE').host_components

namenode_host_name = [hc.host_name for hc in namenode_hc if hc.host_name][0]

print(namenode_host_name)
于 2017-12-16T08:53:29.953 回答
0

我创建了一个库来提取这些信息。安装:

pip install --quiet --upgrade git+https://github.com/snowch/ibm-analytics-engine-python@master

然后运行:

from ibm_analytics_engine import AmbariOperations
ambari_ops = AmbariOperations(vcap_filename='./vcap.json')
ambari_ops.get_namenode_hostname()
于 2017-12-20T10:23:15.313 回答