Last active
August 29, 2015 14:06
-
-
Save onefoursix/2ef20bbc959ef45a6c74 to your computer and use it in GitHub Desktop.
Example of how to restart the HS2 role using the Cloudera Manager API (in python) CM4.6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
## ********************************************************************** | |
## restart-hs2-role.py | |
## | |
## Example of how to restart the HS2 role in the Hive Service using the Cloudera Manager API | |
## | |
## Make sure to set the CM Host, CM Port, login, password, Cluster Name and Hive Service name | |
## in the "Settings" section below | |
## | |
## Usage: restart-hs2-role.py | |
## | |
## ********************************************************************** | |
## ** imports ******************************* | |
import sys | |
from cm_api.api_client import ApiResource | |
## ** Settings ****************************** | |
## Cloudera Manager Host | |
cm_host = "localhost" | |
cm_port = "7180" | |
## Cloudera Manager login | |
cm_login = "admin" | |
## Cloudera Manager password | |
cm_password = <PASSWORD> | |
## Cluster Name | |
cluster_name = <CLUSTER-NAME> | |
## ****************************************** | |
if len(sys.argv) != 1: | |
print "Error: too many arguments; this script does not expect any arguments" | |
print "Usage: restart-hs2-role.py" | |
print "Example: restart-hs2-role.py" | |
quit(1) | |
print "Restarting HIVERSERVER2 Role in the Hive Service on cluster '" + cluster_name + "'..." | |
## Get the CM api | |
api = ApiResource(server_host=cm_host, server_port=cm_port, username=cm_login, password=cm_password) | |
## Get the cluster | |
cluster = api.get_cluster(cluster_name) | |
## Get the HIVE Service | |
hive_service = cluster.get_service("hive") | |
## Get the HS2 Role for the Hive Service | |
for role in hive_service.get_all_roles(): | |
if role.type == "HIVESERVER2": | |
hs2_role = role | |
break | |
## Restart the Role | |
hive_service.restart_roles(hs2_role.name) | |
print "Restart command initiated!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment