JobSubmissionService.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. #
  2. # Autogenerated by Thrift
  3. #
  4. # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  5. #
  6. # Licensed to Cloudera, Inc. under one
  7. # or more contributor license agreements. See the NOTICE file
  8. # distributed with this work for additional information
  9. # regarding copyright ownership. Cloudera, Inc. licenses this file
  10. # to you under the Apache License, Version 2.0 (the
  11. # "License"); you may not use this file except in compliance
  12. # with the License. You may obtain a copy of the License at
  13. #
  14. # http://www.apache.org/licenses/LICENSE-2.0
  15. #
  16. # Unless required by applicable law or agreed to in writing, software
  17. # distributed under the License is distributed on an "AS IS" BASIS,
  18. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. # See the License for the specific language governing permissions and
  20. # limitations under the License.
  21. from thrift.Thrift import *
  22. from ttypes import *
  23. from thrift.Thrift import TProcessor
  24. from thrift.transport import TTransport
  25. from thrift.protocol import TBinaryProtocol
  26. try:
  27. from thrift.protocol import fastbinary
  28. except:
  29. fastbinary = None
  30. class Iface:
  31. def submit(self, plan):
  32. """
  33. Parameters:
  34. - plan
  35. """
  36. pass
  37. def get_job_data(self, handle):
  38. """
  39. Parameters:
  40. - handle
  41. """
  42. pass
  43. class Client(Iface):
  44. def __init__(self, iprot, oprot=None):
  45. self._iprot = self._oprot = iprot
  46. if oprot != None:
  47. self._oprot = oprot
  48. self._seqid = 0
  49. def submit(self, plan):
  50. """
  51. Parameters:
  52. - plan
  53. """
  54. self.send_submit(plan)
  55. return self.recv_submit()
  56. def send_submit(self, plan):
  57. self._oprot.writeMessageBegin('submit', TMessageType.CALL, self._seqid)
  58. args = submit_args()
  59. args.plan = plan
  60. args.write(self._oprot)
  61. self._oprot.writeMessageEnd()
  62. self._oprot.trans.flush()
  63. def recv_submit(self, ):
  64. (fname, mtype, rseqid) = self._iprot.readMessageBegin()
  65. if mtype == TMessageType.EXCEPTION:
  66. x = TApplicationException()
  67. x.read(self._iprot)
  68. self._iprot.readMessageEnd()
  69. raise x
  70. result = submit_result()
  71. result.read(self._iprot)
  72. self._iprot.readMessageEnd()
  73. if result.success != None:
  74. return result.success
  75. if result.error != None:
  76. raise result.error
  77. raise TApplicationException(TApplicationException.MISSING_RESULT, "submit failed: unknown result");
  78. def get_job_data(self, handle):
  79. """
  80. Parameters:
  81. - handle
  82. """
  83. self.send_get_job_data(handle)
  84. return self.recv_get_job_data()
  85. def send_get_job_data(self, handle):
  86. self._oprot.writeMessageBegin('get_job_data', TMessageType.CALL, self._seqid)
  87. args = get_job_data_args()
  88. args.handle = handle
  89. args.write(self._oprot)
  90. self._oprot.writeMessageEnd()
  91. self._oprot.trans.flush()
  92. def recv_get_job_data(self, ):
  93. (fname, mtype, rseqid) = self._iprot.readMessageBegin()
  94. if mtype == TMessageType.EXCEPTION:
  95. x = TApplicationException()
  96. x.read(self._iprot)
  97. self._iprot.readMessageEnd()
  98. raise x
  99. result = get_job_data_result()
  100. result.read(self._iprot)
  101. self._iprot.readMessageEnd()
  102. if result.success != None:
  103. return result.success
  104. if result.error != None:
  105. raise result.error
  106. raise TApplicationException(TApplicationException.MISSING_RESULT, "get_job_data failed: unknown result");
  107. class Processor(Iface, TProcessor):
  108. def __init__(self, handler):
  109. self._handler = handler
  110. self._processMap = {}
  111. self._processMap["submit"] = Processor.process_submit
  112. self._processMap["get_job_data"] = Processor.process_get_job_data
  113. def process(self, iprot, oprot):
  114. (name, type, seqid) = iprot.readMessageBegin()
  115. if name not in self._processMap:
  116. iprot.skip(TType.STRUCT)
  117. iprot.readMessageEnd()
  118. x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
  119. oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
  120. x.write(oprot)
  121. oprot.writeMessageEnd()
  122. oprot.trans.flush()
  123. return
  124. else:
  125. self._processMap[name](self, seqid, iprot, oprot)
  126. return True
  127. def process_submit(self, seqid, iprot, oprot):
  128. args = submit_args()
  129. args.read(iprot)
  130. iprot.readMessageEnd()
  131. result = submit_result()
  132. try:
  133. result.success = self._handler.submit(args.plan)
  134. except SubmissionError, error:
  135. result.error = error
  136. oprot.writeMessageBegin("submit", TMessageType.REPLY, seqid)
  137. result.write(oprot)
  138. oprot.writeMessageEnd()
  139. oprot.trans.flush()
  140. def process_get_job_data(self, seqid, iprot, oprot):
  141. args = get_job_data_args()
  142. args.read(iprot)
  143. iprot.readMessageEnd()
  144. result = get_job_data_result()
  145. try:
  146. result.success = self._handler.get_job_data(args.handle)
  147. except SubmissionError, error:
  148. result.error = error
  149. oprot.writeMessageBegin("get_job_data", TMessageType.REPLY, seqid)
  150. result.write(oprot)
  151. oprot.writeMessageEnd()
  152. oprot.trans.flush()
  153. # HELPER FUNCTIONS AND STRUCTURES
  154. class submit_args(object):
  155. """
  156. Attributes:
  157. - plan
  158. """
  159. thrift_spec = (
  160. None, # 0
  161. (1, TType.STRUCT, 'plan', (SubmissionPlan, SubmissionPlan.thrift_spec), None, ), # 1
  162. )
  163. def __init__(self, plan=None,):
  164. self.plan = plan
  165. def read(self, iprot):
  166. if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
  167. fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
  168. return
  169. iprot.readStructBegin()
  170. while True:
  171. (fname, ftype, fid) = iprot.readFieldBegin()
  172. if ftype == TType.STOP:
  173. break
  174. if fid == 1:
  175. if ftype == TType.STRUCT:
  176. self.plan = SubmissionPlan()
  177. self.plan.read(iprot)
  178. else:
  179. iprot.skip(ftype)
  180. else:
  181. iprot.skip(ftype)
  182. iprot.readFieldEnd()
  183. iprot.readStructEnd()
  184. def write(self, oprot):
  185. if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
  186. oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
  187. return
  188. oprot.writeStructBegin('submit_args')
  189. if self.plan != None:
  190. oprot.writeFieldBegin('plan', TType.STRUCT, 1)
  191. self.plan.write(oprot)
  192. oprot.writeFieldEnd()
  193. oprot.writeFieldStop()
  194. oprot.writeStructEnd()
  195. def __repr__(self):
  196. L = ['%s=%r' % (key, value)
  197. for key, value in self.__dict__.iteritems()]
  198. return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  199. def __eq__(self, other):
  200. return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  201. def __ne__(self, other):
  202. return not (self == other)
  203. class submit_result(object):
  204. """
  205. Attributes:
  206. - success
  207. - error
  208. """
  209. thrift_spec = (
  210. (0, TType.STRUCT, 'success', (SubmissionHandle, SubmissionHandle.thrift_spec), None, ), # 0
  211. (1, TType.STRUCT, 'error', (SubmissionError, SubmissionError.thrift_spec), None, ), # 1
  212. )
  213. def __init__(self, success=None, error=None,):
  214. self.success = success
  215. self.error = error
  216. def read(self, iprot):
  217. if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
  218. fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
  219. return
  220. iprot.readStructBegin()
  221. while True:
  222. (fname, ftype, fid) = iprot.readFieldBegin()
  223. if ftype == TType.STOP:
  224. break
  225. if fid == 0:
  226. if ftype == TType.STRUCT:
  227. self.success = SubmissionHandle()
  228. self.success.read(iprot)
  229. else:
  230. iprot.skip(ftype)
  231. elif fid == 1:
  232. if ftype == TType.STRUCT:
  233. self.error = SubmissionError()
  234. self.error.read(iprot)
  235. else:
  236. iprot.skip(ftype)
  237. else:
  238. iprot.skip(ftype)
  239. iprot.readFieldEnd()
  240. iprot.readStructEnd()
  241. def write(self, oprot):
  242. if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
  243. oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
  244. return
  245. oprot.writeStructBegin('submit_result')
  246. if self.success != None:
  247. oprot.writeFieldBegin('success', TType.STRUCT, 0)
  248. self.success.write(oprot)
  249. oprot.writeFieldEnd()
  250. if self.error != None:
  251. oprot.writeFieldBegin('error', TType.STRUCT, 1)
  252. self.error.write(oprot)
  253. oprot.writeFieldEnd()
  254. oprot.writeFieldStop()
  255. oprot.writeStructEnd()
  256. def __repr__(self):
  257. L = ['%s=%r' % (key, value)
  258. for key, value in self.__dict__.iteritems()]
  259. return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  260. def __eq__(self, other):
  261. return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  262. def __ne__(self, other):
  263. return not (self == other)
  264. class get_job_data_args(object):
  265. """
  266. Attributes:
  267. - handle
  268. """
  269. thrift_spec = (
  270. None, # 0
  271. (1, TType.STRUCT, 'handle', (SubmissionHandle, SubmissionHandle.thrift_spec), None, ), # 1
  272. )
  273. def __init__(self, handle=None,):
  274. self.handle = handle
  275. def read(self, iprot):
  276. if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
  277. fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
  278. return
  279. iprot.readStructBegin()
  280. while True:
  281. (fname, ftype, fid) = iprot.readFieldBegin()
  282. if ftype == TType.STOP:
  283. break
  284. if fid == 1:
  285. if ftype == TType.STRUCT:
  286. self.handle = SubmissionHandle()
  287. self.handle.read(iprot)
  288. else:
  289. iprot.skip(ftype)
  290. else:
  291. iprot.skip(ftype)
  292. iprot.readFieldEnd()
  293. iprot.readStructEnd()
  294. def write(self, oprot):
  295. if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
  296. oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
  297. return
  298. oprot.writeStructBegin('get_job_data_args')
  299. if self.handle != None:
  300. oprot.writeFieldBegin('handle', TType.STRUCT, 1)
  301. self.handle.write(oprot)
  302. oprot.writeFieldEnd()
  303. oprot.writeFieldStop()
  304. oprot.writeStructEnd()
  305. def __repr__(self):
  306. L = ['%s=%r' % (key, value)
  307. for key, value in self.__dict__.iteritems()]
  308. return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  309. def __eq__(self, other):
  310. return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  311. def __ne__(self, other):
  312. return not (self == other)
  313. class get_job_data_result(object):
  314. """
  315. Attributes:
  316. - success
  317. - error
  318. """
  319. thrift_spec = (
  320. (0, TType.STRUCT, 'success', (JobData, JobData.thrift_spec), None, ), # 0
  321. (1, TType.STRUCT, 'error', (SubmissionError, SubmissionError.thrift_spec), None, ), # 1
  322. )
  323. def __init__(self, success=None, error=None,):
  324. self.success = success
  325. self.error = error
  326. def read(self, iprot):
  327. if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
  328. fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
  329. return
  330. iprot.readStructBegin()
  331. while True:
  332. (fname, ftype, fid) = iprot.readFieldBegin()
  333. if ftype == TType.STOP:
  334. break
  335. if fid == 0:
  336. if ftype == TType.STRUCT:
  337. self.success = JobData()
  338. self.success.read(iprot)
  339. else:
  340. iprot.skip(ftype)
  341. elif fid == 1:
  342. if ftype == TType.STRUCT:
  343. self.error = SubmissionError()
  344. self.error.read(iprot)
  345. else:
  346. iprot.skip(ftype)
  347. else:
  348. iprot.skip(ftype)
  349. iprot.readFieldEnd()
  350. iprot.readStructEnd()
  351. def write(self, oprot):
  352. if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
  353. oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
  354. return
  355. oprot.writeStructBegin('get_job_data_result')
  356. if self.success != None:
  357. oprot.writeFieldBegin('success', TType.STRUCT, 0)
  358. self.success.write(oprot)
  359. oprot.writeFieldEnd()
  360. if self.error != None:
  361. oprot.writeFieldBegin('error', TType.STRUCT, 1)
  362. self.error.write(oprot)
  363. oprot.writeFieldEnd()
  364. oprot.writeFieldStop()
  365. oprot.writeStructEnd()
  366. def __repr__(self):
  367. L = ['%s=%r' % (key, value)
  368. for key, value in self.__dict__.iteritems()]
  369. return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
  370. def __eq__(self, other):
  371. return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
  372. def __ne__(self, other):
  373. return not (self == other)