BeeswaxService-remote 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/usr/bin/env python
  2. #
  3. # Autogenerated by Thrift Compiler (0.9.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. from urlparse import urlparse
  12. from thrift.transport import TTransport
  13. from thrift.transport import TSocket
  14. from thrift.transport import THttpClient
  15. from thrift.protocol import TBinaryProtocol
  16. import BeeswaxService
  17. from ttypes import *
  18. if len(sys.argv) <= 1 or sys.argv[1] == '--help':
  19. print ''
  20. print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
  21. print ''
  22. print 'Functions:'
  23. print ' QueryHandle query(Query query)'
  24. print ' QueryHandle executeAndWait(Query query, LogContextId clientCtx)'
  25. print ' QueryExplanation explain(Query query)'
  26. print ' Results fetch(QueryHandle query_id, bool start_over, i32 fetch_size)'
  27. print ' QueryState get_state(QueryHandle handle)'
  28. print ' ResultsMetadata get_results_metadata(QueryHandle handle)'
  29. print ' string echo(string s)'
  30. print ' string dump_config()'
  31. print ' string get_log(LogContextId context)'
  32. print ' get_default_configuration(bool include_hadoop)'
  33. print ' void close(QueryHandle handle)'
  34. print ' void clean(LogContextId log_context)'
  35. print ''
  36. sys.exit(0)
  37. pp = pprint.PrettyPrinter(indent = 2)
  38. host = 'localhost'
  39. port = 9090
  40. uri = ''
  41. framed = False
  42. http = False
  43. argi = 1
  44. if sys.argv[argi] == '-h':
  45. parts = sys.argv[argi+1].split(':')
  46. host = parts[0]
  47. if len(parts) > 1:
  48. port = int(parts[1])
  49. argi += 2
  50. if sys.argv[argi] == '-u':
  51. url = urlparse(sys.argv[argi+1])
  52. parts = url[1].split(':')
  53. host = parts[0]
  54. if len(parts) > 1:
  55. port = int(parts[1])
  56. else:
  57. port = 80
  58. uri = url[2]
  59. if url[4]:
  60. uri += '?%s' % url[4]
  61. http = True
  62. argi += 2
  63. if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  64. framed = True
  65. argi += 1
  66. cmd = sys.argv[argi]
  67. args = sys.argv[argi+1:]
  68. if http:
  69. transport = THttpClient.THttpClient(host, port, uri)
  70. else:
  71. socket = TSocket.TSocket(host, port)
  72. if framed:
  73. transport = TTransport.TFramedTransport(socket)
  74. else:
  75. transport = TTransport.TBufferedTransport(socket)
  76. protocol = TBinaryProtocol.TBinaryProtocol(transport)
  77. client = BeeswaxService.Client(protocol)
  78. transport.open()
  79. if cmd == 'query':
  80. if len(args) != 1:
  81. print 'query requires 1 args'
  82. sys.exit(1)
  83. pp.pprint(client.query(eval(args[0]),))
  84. elif cmd == 'executeAndWait':
  85. if len(args) != 2:
  86. print 'executeAndWait requires 2 args'
  87. sys.exit(1)
  88. pp.pprint(client.executeAndWait(eval(args[0]),eval(args[1]),))
  89. elif cmd == 'explain':
  90. if len(args) != 1:
  91. print 'explain requires 1 args'
  92. sys.exit(1)
  93. pp.pprint(client.explain(eval(args[0]),))
  94. elif cmd == 'fetch':
  95. if len(args) != 3:
  96. print 'fetch requires 3 args'
  97. sys.exit(1)
  98. pp.pprint(client.fetch(eval(args[0]),eval(args[1]),eval(args[2]),))
  99. elif cmd == 'get_state':
  100. if len(args) != 1:
  101. print 'get_state requires 1 args'
  102. sys.exit(1)
  103. pp.pprint(client.get_state(eval(args[0]),))
  104. elif cmd == 'get_results_metadata':
  105. if len(args) != 1:
  106. print 'get_results_metadata requires 1 args'
  107. sys.exit(1)
  108. pp.pprint(client.get_results_metadata(eval(args[0]),))
  109. elif cmd == 'echo':
  110. if len(args) != 1:
  111. print 'echo requires 1 args'
  112. sys.exit(1)
  113. pp.pprint(client.echo(args[0],))
  114. elif cmd == 'dump_config':
  115. if len(args) != 0:
  116. print 'dump_config requires 0 args'
  117. sys.exit(1)
  118. pp.pprint(client.dump_config())
  119. elif cmd == 'get_log':
  120. if len(args) != 1:
  121. print 'get_log requires 1 args'
  122. sys.exit(1)
  123. pp.pprint(client.get_log(eval(args[0]),))
  124. elif cmd == 'get_default_configuration':
  125. if len(args) != 1:
  126. print 'get_default_configuration requires 1 args'
  127. sys.exit(1)
  128. pp.pprint(client.get_default_configuration(eval(args[0]),))
  129. elif cmd == 'close':
  130. if len(args) != 1:
  131. print 'close requires 1 args'
  132. sys.exit(1)
  133. pp.pprint(client.close(eval(args[0]),))
  134. elif cmd == 'clean':
  135. if len(args) != 1:
  136. print 'clean requires 1 args'
  137. sys.exit(1)
  138. pp.pprint(client.clean(eval(args[0]),))
  139. else:
  140. print 'Unrecognized method %s' % cmd
  141. sys.exit(1)
  142. transport.close()