Search code examples
pythonapiautomationclouderacloudera-manager

how to use cm_api to get get_yarn_applications


I am trying to get list of running YARN application using cm_api/ get_yarn_applications. I am on cm-api (9.0.0) & CM 5.3.2

I am following this https://github.com/cloudera/cm_api/blob/master/python/src/cm_api/endpoints/services.py

lastHourDateTime = datetime.datetime.now() - datetime.timedelta(hours = 1)

nowDateTime = datetime.datetime.now()

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

but i am getting following exception

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)

How do I get list of running yarn application using filter_str


Solution

  • You need to specify the YARN service when you call get_service(), and to get only the running applications you need a filter_str of state=RUNNING.

    If your YARN service is named yarn then your get_yarn_applications() call would look like:

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