MetadataWebUtil.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import json
  2. from MyUtils.HttpUtil import *
  3. class MetadataWebUtil(object):
  4. def __init__(self, url):
  5. self.url = url
  6. def get_hbase(self, params):
  7. params = json.dumps(params)
  8. word = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.persagy.com/" xmlns:ent="http://entity.persagy.com">' \
  9. '<soapenv:Header/>' \
  10. '<soapenv:Body><ser:Query>' \
  11. '<arg0>%s</arg0>' \
  12. '</ser:Query></soapenv:Body></soapenv:Envelope>' % (params)
  13. res = HttpUtil.post(self.url, word)
  14. res = res.split("<return>")[1].split("</return>")[0]
  15. res = json.loads(res.replace("&#xd;", ""))
  16. return res
  17. def database_list(self):
  18. params = {
  19. "QueryType": "database_list"
  20. }
  21. res = self.get_hbase(params)
  22. return res["Content"]
  23. def table_list(self, database):
  24. params = {
  25. "QueryType": "table_list_strict",
  26. "Database": database
  27. }
  28. table_list_strict = self.get_hbase(params)["Content"]
  29. params = {
  30. "QueryType": "table_list",
  31. "Database": database
  32. }
  33. table_list = self.get_hbase(params)["Content"]
  34. table_list = [i for i in table_list if i not in table_list_strict]
  35. tables = {}
  36. for table in table_list_strict:
  37. childs = []
  38. for i in table_list:
  39. if i.startswith(table + "_"):
  40. try:
  41. word = i[len(table + "_"):]
  42. if len(word) == 4 or len(word) == 6:
  43. word = int(word)
  44. childs.append(i)
  45. except:
  46. pass
  47. tables[table] = childs
  48. return tables