BeeswaxService-remote 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/usr/bin/env python
  2. #
  3. # Autogenerated by Thrift Compiler (0.13.0)
  4. #
  5. # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  6. #
  7. # options string: py:new_style
  8. #
  9. import sys
  10. import pprint
  11. if sys.version_info[0] > 2:
  12. from urllib.parse import urlparse
  13. else:
  14. from urlparse import urlparse
  15. from thrift.transport import TTransport, TSocket, TSSLSocket, THttpClient
  16. from thrift.protocol.TBinaryProtocol import TBinaryProtocol
  17. from beeswaxd import BeeswaxService
  18. from beeswaxd.ttypes import *
  19. if len(sys.argv) <= 1 or sys.argv[1] == '--help':
  20. print('')
  21. print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] [-novalidate] [-ca_certs certs] [-keyfile keyfile] [-certfile certfile] function [arg1 [arg2...]]')
  22. print('')
  23. print('Functions:')
  24. print(' QueryHandle query(Query query)')
  25. print(' QueryHandle executeAndWait(Query query, LogContextId clientCtx)')
  26. print(' QueryExplanation explain(Query query)')
  27. print(' Results fetch(QueryHandle query_id, bool start_over, i32 fetch_size)')
  28. print(' QueryState get_state(QueryHandle handle)')
  29. print(' ResultsMetadata get_results_metadata(QueryHandle handle)')
  30. print(' string echo(string s)')
  31. print(' string dump_config()')
  32. print(' string get_log(LogContextId context)')
  33. print(' get_default_configuration(bool include_hadoop)')
  34. print(' void close(QueryHandle handle)')
  35. print(' void clean(LogContextId log_context)')
  36. print('')
  37. sys.exit(0)
  38. pp = pprint.PrettyPrinter(indent=2)
  39. host = 'localhost'
  40. port = 9090
  41. uri = ''
  42. framed = False
  43. ssl = False
  44. validate = True
  45. ca_certs = None
  46. keyfile = None
  47. certfile = None
  48. http = False
  49. argi = 1
  50. if sys.argv[argi] == '-h':
  51. parts = sys.argv[argi + 1].split(':')
  52. host = parts[0]
  53. if len(parts) > 1:
  54. port = int(parts[1])
  55. argi += 2
  56. if sys.argv[argi] == '-u':
  57. url = urlparse(sys.argv[argi + 1])
  58. parts = url[1].split(':')
  59. host = parts[0]
  60. if len(parts) > 1:
  61. port = int(parts[1])
  62. else:
  63. port = 80
  64. uri = url[2]
  65. if url[4]:
  66. uri += '?%s' % url[4]
  67. http = True
  68. argi += 2
  69. if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  70. framed = True
  71. argi += 1
  72. if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
  73. ssl = True
  74. argi += 1
  75. if sys.argv[argi] == '-novalidate':
  76. validate = False
  77. argi += 1
  78. if sys.argv[argi] == '-ca_certs':
  79. ca_certs = sys.argv[argi+1]
  80. argi += 2
  81. if sys.argv[argi] == '-keyfile':
  82. keyfile = sys.argv[argi+1]
  83. argi += 2
  84. if sys.argv[argi] == '-certfile':
  85. certfile = sys.argv[argi+1]
  86. argi += 2
  87. cmd = sys.argv[argi]
  88. args = sys.argv[argi + 1:]
  89. if http:
  90. transport = THttpClient.THttpClient(host, port, uri)
  91. else:
  92. if ssl:
  93. socket = TSSLSocket.TSSLSocket(host, port, validate=validate, ca_certs=ca_certs, keyfile=keyfile, certfile=certfile)
  94. else:
  95. socket = TSocket.TSocket(host, port)
  96. if framed:
  97. transport = TTransport.TFramedTransport(socket)
  98. else:
  99. transport = TTransport.TBufferedTransport(socket)
  100. protocol = TBinaryProtocol(transport)
  101. client = BeeswaxService.Client(protocol)
  102. transport.open()
  103. if cmd == 'query':
  104. if len(args) != 1:
  105. print('query requires 1 args')
  106. sys.exit(1)
  107. pp.pprint(client.query(eval(args[0]),))
  108. elif cmd == 'executeAndWait':
  109. if len(args) != 2:
  110. print('executeAndWait requires 2 args')
  111. sys.exit(1)
  112. pp.pprint(client.executeAndWait(eval(args[0]), eval(args[1]),))
  113. elif cmd == 'explain':
  114. if len(args) != 1:
  115. print('explain requires 1 args')
  116. sys.exit(1)
  117. pp.pprint(client.explain(eval(args[0]),))
  118. elif cmd == 'fetch':
  119. if len(args) != 3:
  120. print('fetch requires 3 args')
  121. sys.exit(1)
  122. pp.pprint(client.fetch(eval(args[0]), eval(args[1]), eval(args[2]),))
  123. elif cmd == 'get_state':
  124. if len(args) != 1:
  125. print('get_state requires 1 args')
  126. sys.exit(1)
  127. pp.pprint(client.get_state(eval(args[0]),))
  128. elif cmd == 'get_results_metadata':
  129. if len(args) != 1:
  130. print('get_results_metadata requires 1 args')
  131. sys.exit(1)
  132. pp.pprint(client.get_results_metadata(eval(args[0]),))
  133. elif cmd == 'echo':
  134. if len(args) != 1:
  135. print('echo requires 1 args')
  136. sys.exit(1)
  137. pp.pprint(client.echo(args[0],))
  138. elif cmd == 'dump_config':
  139. if len(args) != 0:
  140. print('dump_config requires 0 args')
  141. sys.exit(1)
  142. pp.pprint(client.dump_config())
  143. elif cmd == 'get_log':
  144. if len(args) != 1:
  145. print('get_log requires 1 args')
  146. sys.exit(1)
  147. pp.pprint(client.get_log(eval(args[0]),))
  148. elif cmd == 'get_default_configuration':
  149. if len(args) != 1:
  150. print('get_default_configuration requires 1 args')
  151. sys.exit(1)
  152. pp.pprint(client.get_default_configuration(eval(args[0]),))
  153. elif cmd == 'close':
  154. if len(args) != 1:
  155. print('close requires 1 args')
  156. sys.exit(1)
  157. pp.pprint(client.close(eval(args[0]),))
  158. elif cmd == 'clean':
  159. if len(args) != 1:
  160. print('clean requires 1 args')
  161. sys.exit(1)
  162. pp.pprint(client.clean(eval(args[0]),))
  163. else:
  164. print('Unrecognized method %s' % cmd)
  165. sys.exit(1)
  166. transport.close()