- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
CM Python API
- Labels:
-
Apache YARN
-
Cloudera Manager
Created on ‎09-26-2017 11:57 AM - edited ‎09-16-2022 05:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
Created ‎09-27-2017 09:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created ‎09-27-2017 04:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any thoughts or direction is appreciated
Created ‎09-27-2017 09:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created ‎09-28-2017 10:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wow, Thanks... worked perfect after I plugged in the version.
