如何以编程方式获取 BIGSQL_HEAD 的主机名?

how can I programmatically get the hostname for the BIGSQL_HEAD?

我需要通过脚本以编程方式检索我的 BigInsihgts on Cloud 企业集群的 BIGSQL_HEAD 主机名,以便我可以自动连接到该主机。

BIGSQL_HEAD 主机名在 Ambari 中 - 如何使用 'standard' unix 工具检索此信息?

BI_HOST=your_biginsights_mastermanager_hostname
BI_USER=your_biginsights_username
BI_PASS=your_biginsights_password

BASE_URL=https://${BI_HOST}:9443

CLUSTER_NAME=$(curl -k -s -u ${BI_USER}:${BI_PASS} -H 'X-Requested-By:ambari' \
  ${BASE_URL}/api/v1/clusters |  python -c \
  'import json,sys;print json.load(sys.stdin)["items"][0]["Clusters"]["cluster_name"]')

BIGSQL_HOST=$(curl -k -s -u ${BI_USER}:${BI_PASS} -H 'X-Requested-By:ambari' \
   ${BASE_URL}/api/v1/clusters/${CLUSTER_NAME}/services/BIGSQL/components/BIGSQL_HEAD | \
   python -c \
   'import json,sys;print json.load(sys.stdin)["host_components"][0]["HostRoles"]["host_name"]')

echo ${BIGSQL_HOST}

这些命令可以在 BigInsight 集群或您的客户端计算机上 运行。

感谢 Pierre Regazzoni 提供的 ambari 代码。