Last active
October 7, 2016 22:58
-
-
Save abajwa-hw/0fd9772c916fac3fc5912f462168799a to your computer and use it in GitHub Desktop.
Sample python code to update zeppelin interpreter using REST
This file contains 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/local/bin/python | |
def post_request(url, body): | |
import json, urllib2 | |
encoded_body = json.dumps(body) | |
req = urllib2.Request(str(url), encoded_body) | |
req.get_method = lambda: 'PUT' | |
try: | |
response = urllib2.urlopen(req, encoded_body).read() | |
except urllib2.HTTPError, error: | |
print 'Exception: ' + error.read() | |
jsonresp = json.loads(response.decode('utf-8')) | |
print jsonresp['status'] | |
import json, urllib2 | |
zeppelin_int_url = 'http://localhost:9995/api/interpreter/setting/' | |
data = json.load(urllib2.urlopen(zeppelin_int_url)) | |
for body in data['body']: | |
if body['group'] == 'psql': | |
psqlbody = body | |
elif body['group'] == 'hive': | |
hivebody = body | |
hivebody['properties']['hive.hiveserver2.url'] = 'jdbc:hive2://localhost:10000' | |
post_request(zeppelin_int_url + hivebody['id'], hivebody) | |
psqlbody['properties']['postgresql.user'] = 'gpadmin' | |
psqlbody['properties']['postgresql.password'] = 'gpadmin' | |
psqlbody['properties']['postgresql.url'] = 'jdbc:postgresql://localhost:10432/postgres' | |
post_request(zeppelin_int_url + psqlbody['id'], psqlbody) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment