Skip to content

Instantly share code, notes, and snippets.

@mboeru
Created February 6, 2016 08:09
Show Gist options
  • Save mboeru/5120a1a9e1b3a124c1e3 to your computer and use it in GitHub Desktop.
Save mboeru/5120a1a9e1b3a124c1e3 to your computer and use it in GitHub Desktop.
a simple script to send start stop restart commands to hive using cm api
#!/usr/bin/env python
import urllib
import urllib2
import sys
import json
from json import JSONDecoder
def command_hive( ACTION ):
USER = "admin"
PASS = "admin"
URL = "http://ec2-52-19-119-223.eu-west-1.compute.amazonaws.com:7180/api/v11/clusters/mboeru/services/hive/commands/"+ACTION
VALUES = { }
DATA = urllib.urlencode(VALUES)
# simple wrapper function to encode the username & pass
def encodeUserData(user, password):
return "Basic " + (user + ":" + password).encode("base64").rstrip()
req = urllib2.Request(URL,DATA)
req.add_header('Accept', 'application/json')
req.add_header("Content-type", "application/x-www-form-urlencoded")
req.add_header('Authorization', encodeUserData(USER, PASS))
res = urllib2.urlopen(req)
print res.read()
if len(sys.argv) == 2:
print "Running command "+sys.argv[1]
command_hive(sys.argv[1])
else:
print "Need to add a command to run. EX: start, stop, restart"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment