Skip to content

Commit

Permalink
[py] Add cm_shell to internal github
Browse files Browse the repository at this point in the history
This has been out in the open for a long time. I'd like to reduce the diff
between our public github and the internal one.
  • Loading branch information
bc Wong committed Jun 12, 2013
1 parent d1599c6 commit 950ac60
Show file tree
Hide file tree
Showing 6 changed files with 1,889 additions and 3 deletions.
19 changes: 19 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ Another example: getting all the services in a cluster:
hue1
>>>

Shell
-----
After installing the `cm_api` Python package, you can use the API shell `cmps`
(CM Python Shell):

$ cmps -H <host> --user admin --password admin
Welcome to the Cloudera Manager Console
Select a cluster using 'show clusters' and 'use'
cloudera> show clusters
+------------------+
| CLUSTER NAME |
+------------------+
| Cluster 1 - CDH4 |
| Cluster 2 - CDH3 |
+------------------+
cloudera>

Please see the `SHELL_README.md` file for more.

Example Scripts
---------------
You can find example scripts in the `python/examples` directory.
Expand Down
143 changes: 143 additions & 0 deletions python/SHELL_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
Cloudera Manager Python Shell
============================


Getting Started
---------------

### Installation ###

> Run as a privileged user, or in a virtualenv
$ python setup.py install

### Usage ###

$ cmps
usage: cmps [-h] -H HOSTNAME [-p PORT] [-u USERNAME] [-c CLUSTER]
[--password PASSWORD] [-e EXECUTE] [-s SEPERATOR]
cmps: error: argument -H/--host/--hostname is required

### Login ###

$ cmps -H <host>
Enter Username: admin
Enter Password:
Welcome to the Cloudera Manager Console
Select a cluster using 'show clusters' and 'use'
cloudera>

### Using Help ###

cloudera> help
Cloudera Manager Commands
=========================
log show status stop_role
restart_role start_cluster stderr stop_service
restart_service start_role stdout use
roles start_service stop_cluster version

Other Commands
==============
help

cloudera> help stop_cluster
Completely stop the cluster
Usage:
> stop_cluster <cluster>

### Connecting to a Cluster ###

> Autocomplete works
cloudera> use cdh4
Connected to cdh4
cdh4> status
+------------+-----------+---------+--------+------------+
| NAME | SERVICE | STATUS | HEALTH | CONFIG |
+------------+-----------+---------+--------+------------+
| hbase1 | HBASE | STARTED | GOOD | UP TO DATE |
| hdfs1 | HDFS | STARTED | GOOD | UP TO DATE |
| mapreduce1 | MAPREDUCE | STARTED | GOOD | UP TO DATE |
| zookeeper1 | ZOOKEEPER | STARTED | GOOD | UP TO DATE |
+------------+-----------+---------+--------+------------+

### View Roles ###

cdh4> roles hbase1
+--------------+---------------------+-----------------------+---------+--------+------------+
| ROLE TYPE | HOST | ROLE NAME | STATE | HEALTH | CONFIG |
+--------------+---------------------+-----------------------+---------+--------+------------+
| MASTER | hbase.localdomain | hbase1-MASTER-1 | STARTED | GOOD | UP TO DATE |
| REGIONSERVER | hbase-2.localdomain | hbase1-REGIONSERVER-2 | STARTED | GOOD | UP TO DATE |
| REGIONSERVER | hbase.localdomain | hbase1-REGIONSERVER-1 | STARTED | GOOD | UP TO DATE |
+--------------+---------------------+-----------------------+---------+--------+------------+

### Stopping / Starting Services and Roles ###

cdh4> restart_service hbase1
hbase1 is being restarted
cdh4> status hbase1
status hbase1
+--------+---------+----------+--------+------------+
| NAME | SERVICE | STATUS | HEALTH | CONFIG |
+--------+---------+----------+--------+------------+
| hbase1 | HBASE | STARTING | GOOD | UP TO DATE |
+--------+---------+----------+--------+------------+

cdh4> stop_role hbase1-REGIONSERVER-2
Stopping Role
cdh4> roles hbase1
roles hbase1
+--------------+---------------------+-----------------------+---------+--------+------------+
| ROLE TYPE | HOST | ROLE NAME | STATE | HEALTH | CONFIG |
+--------------+---------------------+-----------------------+---------+--------+------------+
| MASTER | hbase.localdomain | hbase1-MASTER-1 | STARTED | GOOD | UP TO DATE |
| REGIONSERVER | hbase-2.localdomain | hbase1-REGIONSERVER-2 | STOPPED | GOOD | UP TO DATE |
| REGIONSERVER | hbase.localdomain | hbase1-REGIONSERVER-1 | STARTED | GOOD | UP TO DATE |
+--------------+---------------------+-----------------------+---------+--------+------------+

### Viewing Logs ###

> Interactive shells will use less
> Non-interactive shells will send to stdout
cdh4> log hbase1-REGIONSERVER-2
cdh4> stdout hbase1-REGIONSERVER-2
cdh4> stderr hbase1-REGIONSERVER-2

### Non-Interactive ###

$ cmps -H 192.168.2.105 -u admin --password admin -e "show hosts; show clusters"
+---------------------+---------------+----------+
| HOSTNAME | IP ADDRESS | RACK |
+---------------------+---------------+----------+
| hbase.localdomain | 192.168.2.105 | /default |
| hbase-2.localdomain | 192.168.2.110 | /default |
+---------------------+---------------+----------+
+--------------+
| CLUSTER NAME |
+--------------+
| cdh4 |
+--------------+

### Custom Output Delimiter ###

$ cmps -H 192.168.2.105 -u admin --password admin -e "roles hbase1" -c cdh4 -s ,
ROLE TYPE,HOST,ROLE NAME,STATE,HEALTH,CONFIG
MASTER,hbase.localdomain,hbase1-MASTER-1,STARTED,GOOD,UP TO DATE
REGIONSERVER,hbase-2.localdomain,hbase1-REGIONSERVER-2,STARTED,GOOD,UP TO DATE
REGIONSERVER,hbase.localdomain,hbase1-REGIONSERVER-1,STARTED,GOOD,UP TO DATE

### Scripting Example ###

> Obtain log files for all the region servers
$ for i in $(cmps -H 192.168.2.105 -u admin --password admin -e "roles hbase1" -c cdh4 -s , | grep REGIONSERVER | awk -F, '{print $3}');
do
cmps -H 192.168.2.105 -u admin --password admin -c cdh4 -e "log $i" > $i.out;
done
$ du -h *.out
2.4M hbase1-REGIONSERVER-1.out
1.9M hbase1-REGIONSERVER-2.out
18 changes: 15 additions & 3 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@

from setuptools import setup, find_packages

from sys import version_info
from sys import version_info, platform

if version_info[:2] > (2, 5):
install_requires = []
else:
install_requires = ['simplejson >= 2.0.0']

# Python 2.6 and below requires argparse
if version_info[:2] < (2, 7):
install_requires += ['argparse']

# Mac does not come default with readline, this is needed for autocomplete
# in the cmps shell
if platform == 'darwin':
install_requires += ['readline']

setup(
name = 'cm_api',
version = '1.0.0', # Compatible with API v1
version = '5.0.0', # Compatible with API v5
packages = find_packages('src', exclude=['cm_api_tests']),
package_dir = {'cm_api': 'src/cm_api'},
package_dir = {'cm_api': 'src/cm_api',
'cm_shell': 'src/cm_shell'},

# Project uses simplejson, so ensure that it gets installed or upgraded
# on the target machine
Expand All @@ -37,4 +48,5 @@
description = 'Cloudera Manager API client',
license = 'Apache License 2.0',
url = 'https://github.com/cloudera/cm_api',
entry_points = { 'console_scripts': [ 'cmps = cm_shell.cmps:main', ]}
)
Empty file added python/src/cm_shell/__init__.py
Empty file.
Loading

0 comments on commit 950ac60

Please sign in to comment.