如何使用 cm_api 得到 get_yarn_applications

how to use cm_api to get get_yarn_applications

我正在尝试使用 cm_api/ 获取 运行 YARN 应用程序列表 get_yarn_applications。我在 cm-api (9.0.0) & CM 5.3.2

我正在关注这个https://github.com/cloudera/cm_api/blob/master/python/src/cm_api/endpoints/services.py

lastHourDateTime = datetime.datetime.now() - datetime.timedelta(小时 = 1)

现在日期时间 = datetime.datetime.now()

yarn_applications = cm.get_service().get_yarn_applications(lastHourDateTime, nowDateTime)

但我遇到以下异常

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/cm_api/endpoints/services.py", line 418, in get_yarn_applications
params=params, api_version=6)
  File "/usr/lib/python2.6/site-packages/cm_api/endpoints/types.py", line 357, in _get
api_version)
  File "/usr/lib/python2.6/site-packages/cm_api/endpoints/types.py", line 380, in _call
api_version)
  File "/usr/lib/python2.6/site-packages/cm_api/endpoints/types.py", line 139, in call
ret = method(path, params=params)
  File "/usr/lib/python2.6/site-packages/cm_api/resource.py", line 100, in get
return self.invoke("GET", relpath, params)
  File "/usr/lib/python2.6/site-packages/cm_api/resource.py", line 63, in invoke
headers=headers)
  File "/usr/lib/python2.6/site-packages/cm_api/http_client.py", line 161, in execute
raise self._exc_class(ex)
cm_api.api_client.ApiException:  (error 404)

如何使用 filter_str

获取 运行 yarn 应用列表

您需要在调用 get_service() 时指定 YARN 服务,要仅获取 运行 个应用程序,您需要 filter_strstate=RUNNING

如果您的 YARN 服务名为 yarn,那么您的 get_yarn_applications() 调用将如下所示:

yarn_applications = cm.get_service("yarn").get_yarn_applications(lastHourDateTime, nowDateTime, filter_str = "state=RUNNING")