FAQ
Hi,

I'm currently trying to get the Python API of Cloudera Manager to work, but
got stuck in both cmps and python client api.
Used resources:

    - https://github.com/cloudera/cm_api/blob/master/python/SHELL_README.md
    - https://github.com/cloudera/cm_api/tree/master/python


*a) cloudera manager shell*
*
*
Connecting to the cluster works fine and executing command inside a shell
session is fine, too. But the non-interactive calls are resulting in the
following exceptions:

$ cmps -H hadoop-pg-1 -u admin --password admin -c "Cluster 1 - CDH4" -e
"roles flume1"
Traceback (most recent call last):
   File "/usr/local/bin/cmps", line 9, in <module>
     load_entry_point('cm-api==4.0.0', 'console_scripts', 'cmps')()
   File
"/usr/local/lib/python2.7/dist-packages/cm_api-4.0.0-py2.7.egg/cm_shell/cmps.py",
line 634, in main
     shell.onecmd(command)
   File "/usr/lib/python2.7/cmd.py", line 221, in onecmd
     return func(arg)
   File
"/usr/local/lib/python2.7/dist-packages/cm_api-4.0.0-py2.7.egg/cm_shell/cmps.py",
line 391, in do_roles
     if not self.has_cluster():
   File
"/usr/local/lib/python2.7/dist-packages/cm_api-4.0.0-py2.7.egg/cm_shell/cmps.py",
line 131, in has_cluster
     if not self.cluster:
   File
"/usr/local/lib/python2.7/dist-packages/cm_api-4.0.0-py2.7.egg/cm_shell/cmps.py",
line 125, in cluster
     if self.cluster_object:
AttributeError: ClouderaShell instance has no attribute 'cluster_object'

The same as interactive session:

$ cmps -H hadoop-pg-1 -u admin --password admin -c "Cluster 1 - CDH4" -s ,
Connected to Cluster 1 - CDH4
Welcome to the Cloudera Manager Console
Select a cluster using 'show clusters' and 'use'
Cluster 1 - CDH4> roles flume1
ROLE TYPE,HOST,ROLE NAME,STATE,HEALTH,CONFIG
AGENT,hadoop-pg-2.cluster,flume1-AGENT-...,STARTED,GOOD,UP TO DATE
AGENT,hadoop-pg-5.cluster,flume1-AGENT-...,STARTED,GOOD,UP TO DATE
AGENT,hadoop-pg-3.cluster,flume1-AGENT-...,STARTED,CONCERNING,UP TO DATE
AGENT,hadoop-pg-4.cluster,flume1-AGENT-...,STARTED,GOOD,UP TO DATE


*b) Python api client*

almost same situation, inside python shell commands are working as
expected, but not within the following script:
#!/usr/bin/env python
import getopt
import inspect
import logging
import sys
import textwrap
from cm_api.api_client import ApiResource
CM_HOST = 'hadoopo-pg-1'
CM_USER = 'admin'
CM_PASSWD = 'admin'
def main(argv):
   api = ApiResource(CM_HOST, username=CM_USER, password=CM_PASSWD)
   print("api object created")
   for h in api.get_all_hosts():
     print ("%s\n") % h.hostname
   return 0
if __name__ == '__main__':
   sys.exit(main(sys.argv))

Calling this script (saved as cloudera-manager.py) results in:

$ python ./cloudera-manager.py
api object created
Traceback (most recent call last):
   File "./cloudera-manager.py", line 24, in <module>
     sys.exit(main(sys.argv))
   File "./cloudera-manager.py", line 18, in main
     for h in api.get_all_hosts():
   File
"/usr/local/lib/python2.7/dist-packages/cm_api-4.0.0-py2.7.egg/cm_api/api_client.py",
line 165, in get_all_hosts
     return hosts.get_all_hosts(self, view)
   File
"/usr/local/lib/python2.7/dist-packages/cm_api-4.0.0-py2.7.egg/cm_api/endpoints/hosts.py",
line 63, in get_all_hosts
     params=view and dict(view=view) or None)
   File
"/usr/local/lib/python2.7/dist-packages/cm_api-4.0.0-py2.7.egg/cm_api/resource.py",
line 91, in get
     return self.invoke("GET", relpath, params)
   File
"/usr/local/lib/python2.7/dist-packages/cm_api-4.0.0-py2.7.egg/cm_api/resource.py",
line 58, in invoke
     headers=headers)
   File
"/usr/local/lib/python2.7/dist-packages/cm_api-4.0.0-py2.7.egg/cm_api/http_client.py",
line 159, in execute
     return self._opener.open(request)
   File "/usr/lib/python2.7/urllib2.py", line 404, in open
     response = self._open(req, data)
   File "/usr/lib/python2.7/urllib2.py", line 422, in _open
     '_open', req)
   File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
     result = func(*args)
   File "/usr/lib/python2.7/urllib2.py", line 1214, in http_open
     return self.do_open(httplib.HTTPConnection, req)
   File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
     raise URLError(err)
urllib2.URLError: <urlopen error [Errno 2] No such file or directory>

I've no idea what the 'no such file or directory' error will tell me
Whereas inside the python shell, everything's fine:
$ python
Python 2.7.4 (default, Apr 19 2013, 18:32:33)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
from cm_api.api_client import ApiResource
api = ApiResource('hadoop-pg-1', 7180,'admin', 'admin')
for h in api.get_all_hosts():
... print h.hostname
...
hadoop-pg-1.cluster
hadoop-pg-2.cluster
hadoop-pg-3.cluster
hadoop-pg-4.cluster
hadoop-pg-5.cluster
>>>


Any help highly appreciated

kind regards...:: Gerd ::...

Search Discussions

  • bc Wong at Jul 22, 2013 at 9:28 pm
    I'd recommend using the Python API client for scripting because it's
    more complete that the shell. Inline comments below.
    On Mon, Jul 22, 2013 at 11:55 AM, Gerd Koenig wrote:
    b) Python api client

    almost same situation, inside python shell commands are working as expected,
    but not within the following script:
    #!/usr/bin/env python
    import getopt
    import inspect
    import logging
    import sys
    import textwrap
    from cm_api.api_client import ApiResource
    CM_HOST = 'hadoopo-pg-1'
    Is that a typo? hadoopo vs hadoop.

    Cheers,
    bc
  • Gerd Koenig at Jul 23, 2013 at 6:46 am
    Hi Bc,

    you're absolutely right ! I didn't see the wood for the trees, stupid me ;)

    Many thanks...: Gerd :....



    Am Montag, 22. Juli 2013 23:27:56 UTC+2 schrieb bc Wong:
    I'd recommend using the Python API client for scripting because it's
    more complete that the shell. Inline comments below.
    On Mon, Jul 22, 2013 at 11:55 AM, Gerd Koenig wrote:
    b) Python api client

    almost same situation, inside python shell commands are working as expected,
    but not within the following script:
    #!/usr/bin/env python
    import getopt
    import inspect
    import logging
    import sys
    import textwrap
    from cm_api.api_client import ApiResource
    CM_HOST = 'hadoopo-pg-1'
    Is that a typo? hadoopo vs hadoop.

    Cheers,
    bc
  • Sudhakar t at Jul 23, 2013 at 2:57 pm
    Hey all,

    Could you tell me step by step .....

    1) How to install Hive in Single node.
    2) How can i set Hive environment variables

    Regards,
    Sudhakar


    On Tue, Jul 23, 2013 at 12:16 PM, Gerd Koenig wrote:

    Hi Bc,

    you're absolutely right ! I didn't see the wood for the trees, stupid me ;)

    Many thanks...: Gerd :....



    Am Montag, 22. Juli 2013 23:27:56 UTC+2 schrieb bc Wong:
    I'd recommend using the Python API client for scripting because it's
    more complete that the shell. Inline comments below.

    On Mon, Jul 22, 2013 at 11:55 AM, Gerd Koenig <[email protected]>
    wrote:
    b) Python api client

    almost same situation, inside python shell commands are working as expected,
    but not within the following script:
    #!/usr/bin/env python
    import getopt
    import inspect
    import logging
    import sys
    import textwrap
    from cm_api.api_client import ApiResource
    CM_HOST = 'hadoopo-pg-1'
    Is that a typo? hadoopo vs hadoop.

    Cheers,
    bc

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupscm-users @
categorieshadoop
postedJul 22, '13 at 6:55p
activeJul 23, '13 at 2:57p
posts4
users3
websitecloudera.com
irc#hadoop

People

Translate

site design / logo © 2023 Grokbase