Reply
Highlighted
Explorer
Posts: 10
Registered: ‎05-08-2017
Accepted Solution

CM Python API

Hi,

 

I am trying to use cm python api, but it keeps failing out. Not sure, what is causing the issue. I get 404 error ! which I think represents object not found.

 

Below is the code snippet

 

 

import datetime
import getpass
import re

from cm_api.api_client import ApiResource

# Connection information.
host = 'XXXXXXXXXXXXXXXXXXXXXXX'
port = 7180
user = 'admin'
password = 'admin'

api = ApiResource(host, 7180, user, password)

# Finds the first YARN service in the first cluster.
cluster = api.get_all_clusters()[0]

 

 

Its failing with Message

 

Traceback (most recent call last):
  File "scan-work-items.py", line 23, in <module>
    cluster = api.get_all_clusters()[0]
  File "/usr/lib/python2.6/site-packages/cm_api/api_client.py", line 131, in get_all_clusters
    return clusters.get_all_clusters(self, view)
  File "/usr/lib/python2.6/site-packages/cm_api/endpoints/clusters.py", line 66, in get_all_clusters
    params=view and dict(view=view) or None)
  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 110, in get
    return self.invoke("GET", relpath, params)
  File "/usr/lib/python2.6/site-packages/cm_api/resource.py", line 73, in invoke
    headers=headers)
  File "/usr/lib/python2.6/site-packages/cm_api/http_client.py", line 183, in execute
    raise self._exc_class(ex)
cm_api.api_client.ApiException:  (error 404)

Is it because of running python 2.6 ? I am running this on NameNode in my lab cluster(6 Node) that is running outside the production CM cluster. I am trying to use the API to connect to production cluster to fetch some metrics, but it keeps erroring out.

 

Also, We have RM HA. Is there a way to find which node is my active Resource Manager ? and the URL for it ? without logging into CM ?

 

 

Explorer
Posts: 10
Registered: ‎05-08-2017

Re: CM Python API

Any thoughts or direction is appreciated 

Posts: 454
Topics: 1
Kudos: 106
Solutions: 59
Registered: ‎04-22-2014

Re: CM Python API

Hi @code0404,

 

The 404 message that you describe usually occurs when you are using the latest Python API but your Cloudera Manager does not support that latest API version.

 

Use the REST API to verify the maximum supported API version in your Cloudera Manager:

 

http://host:port/api/version

 

The output will be the supported version. For example, "v14".

Take that value and then use it in your ApiResource() like this:

 

api = ApiResource(host, 7180, user, password,version=14

   See the following for more information on ApiResource:

https://cloudera.github.io/cm_api/epydoc/5.12.0/cm_api.api_client.ApiResource-class.html

 

Regards,

 

Ben

Explorer
Posts: 10
Registered: ‎05-08-2017

Re: CM Python API

Wow, Thanks... worked perfect after I plugged in the version. 

Announcements