jolt 0.9.123__py3-none-any.whl → 0.9.435__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. jolt/__init__.py +80 -7
  2. jolt/__main__.py +9 -1
  3. jolt/bin/fstree-darwin-x86_64 +0 -0
  4. jolt/bin/fstree-linux-x86_64 +0 -0
  5. jolt/cache.py +832 -362
  6. jolt/chroot.py +156 -0
  7. jolt/cli.py +281 -162
  8. jolt/common_pb2.py +63 -0
  9. jolt/common_pb2_grpc.py +4 -0
  10. jolt/config.py +98 -41
  11. jolt/error.py +19 -4
  12. jolt/filesystem.py +2 -6
  13. jolt/graph.py +705 -117
  14. jolt/hooks.py +43 -0
  15. jolt/influence.py +122 -3
  16. jolt/loader.py +369 -121
  17. jolt/log.py +225 -63
  18. jolt/manifest.py +28 -38
  19. jolt/options.py +35 -10
  20. jolt/pkgs/abseil.py +42 -0
  21. jolt/pkgs/asio.py +25 -0
  22. jolt/pkgs/autoconf.py +41 -0
  23. jolt/pkgs/automake.py +41 -0
  24. jolt/pkgs/b2.py +31 -0
  25. jolt/pkgs/boost.py +111 -0
  26. jolt/pkgs/boringssl.py +32 -0
  27. jolt/pkgs/busybox.py +39 -0
  28. jolt/pkgs/bzip2.py +43 -0
  29. jolt/pkgs/cares.py +29 -0
  30. jolt/pkgs/catch2.py +36 -0
  31. jolt/pkgs/cbindgen.py +17 -0
  32. jolt/pkgs/cista.py +19 -0
  33. jolt/pkgs/clang.py +44 -0
  34. jolt/pkgs/cli11.py +24 -0
  35. jolt/pkgs/cmake.py +48 -0
  36. jolt/pkgs/cpython.py +196 -0
  37. jolt/pkgs/crun.py +29 -0
  38. jolt/pkgs/curl.py +38 -0
  39. jolt/pkgs/dbus.py +18 -0
  40. jolt/pkgs/double_conversion.py +24 -0
  41. jolt/pkgs/fastfloat.py +21 -0
  42. jolt/pkgs/ffmpeg.py +28 -0
  43. jolt/pkgs/flatbuffers.py +29 -0
  44. jolt/pkgs/fmt.py +27 -0
  45. jolt/pkgs/fstree.py +20 -0
  46. jolt/pkgs/gflags.py +18 -0
  47. jolt/pkgs/glib.py +18 -0
  48. jolt/pkgs/glog.py +25 -0
  49. jolt/pkgs/glslang.py +21 -0
  50. jolt/pkgs/golang.py +16 -11
  51. jolt/pkgs/googlebenchmark.py +18 -0
  52. jolt/pkgs/googletest.py +46 -0
  53. jolt/pkgs/gperf.py +15 -0
  54. jolt/pkgs/grpc.py +73 -0
  55. jolt/pkgs/hdf5.py +19 -0
  56. jolt/pkgs/help2man.py +14 -0
  57. jolt/pkgs/inja.py +28 -0
  58. jolt/pkgs/jsoncpp.py +31 -0
  59. jolt/pkgs/libarchive.py +43 -0
  60. jolt/pkgs/libcap.py +44 -0
  61. jolt/pkgs/libdrm.py +44 -0
  62. jolt/pkgs/libedit.py +42 -0
  63. jolt/pkgs/libevent.py +31 -0
  64. jolt/pkgs/libexpat.py +27 -0
  65. jolt/pkgs/libfastjson.py +21 -0
  66. jolt/pkgs/libffi.py +16 -0
  67. jolt/pkgs/libglvnd.py +30 -0
  68. jolt/pkgs/libogg.py +28 -0
  69. jolt/pkgs/libpciaccess.py +18 -0
  70. jolt/pkgs/libseccomp.py +21 -0
  71. jolt/pkgs/libtirpc.py +24 -0
  72. jolt/pkgs/libtool.py +42 -0
  73. jolt/pkgs/libunwind.py +35 -0
  74. jolt/pkgs/libva.py +18 -0
  75. jolt/pkgs/libvorbis.py +33 -0
  76. jolt/pkgs/libxml2.py +35 -0
  77. jolt/pkgs/libxslt.py +17 -0
  78. jolt/pkgs/libyajl.py +16 -0
  79. jolt/pkgs/llvm.py +81 -0
  80. jolt/pkgs/lua.py +54 -0
  81. jolt/pkgs/lz4.py +26 -0
  82. jolt/pkgs/m4.py +14 -0
  83. jolt/pkgs/make.py +17 -0
  84. jolt/pkgs/mesa.py +81 -0
  85. jolt/pkgs/meson.py +17 -0
  86. jolt/pkgs/mstch.py +28 -0
  87. jolt/pkgs/mysql.py +60 -0
  88. jolt/pkgs/nasm.py +49 -0
  89. jolt/pkgs/ncurses.py +30 -0
  90. jolt/pkgs/ng_log.py +25 -0
  91. jolt/pkgs/ninja.py +45 -0
  92. jolt/pkgs/nlohmann_json.py +25 -0
  93. jolt/pkgs/nodejs.py +19 -11
  94. jolt/pkgs/opencv.py +24 -0
  95. jolt/pkgs/openjdk.py +26 -0
  96. jolt/pkgs/openssl.py +103 -0
  97. jolt/pkgs/paho.py +76 -0
  98. jolt/pkgs/patchelf.py +16 -0
  99. jolt/pkgs/perl.py +42 -0
  100. jolt/pkgs/pkgconfig.py +64 -0
  101. jolt/pkgs/poco.py +39 -0
  102. jolt/pkgs/protobuf.py +77 -0
  103. jolt/pkgs/pugixml.py +27 -0
  104. jolt/pkgs/python.py +19 -0
  105. jolt/pkgs/qt.py +35 -0
  106. jolt/pkgs/rapidjson.py +26 -0
  107. jolt/pkgs/rapidyaml.py +28 -0
  108. jolt/pkgs/re2.py +30 -0
  109. jolt/pkgs/re2c.py +17 -0
  110. jolt/pkgs/readline.py +15 -0
  111. jolt/pkgs/rust.py +41 -0
  112. jolt/pkgs/sdl.py +28 -0
  113. jolt/pkgs/simdjson.py +27 -0
  114. jolt/pkgs/soci.py +46 -0
  115. jolt/pkgs/spdlog.py +29 -0
  116. jolt/pkgs/spirv_llvm.py +21 -0
  117. jolt/pkgs/spirv_tools.py +24 -0
  118. jolt/pkgs/sqlite.py +83 -0
  119. jolt/pkgs/ssl.py +12 -0
  120. jolt/pkgs/texinfo.py +15 -0
  121. jolt/pkgs/tomlplusplus.py +22 -0
  122. jolt/pkgs/wayland.py +26 -0
  123. jolt/pkgs/x11.py +58 -0
  124. jolt/pkgs/xerces_c.py +20 -0
  125. jolt/pkgs/xorg.py +360 -0
  126. jolt/pkgs/xz.py +29 -0
  127. jolt/pkgs/yamlcpp.py +30 -0
  128. jolt/pkgs/zeromq.py +47 -0
  129. jolt/pkgs/zlib.py +87 -0
  130. jolt/pkgs/zstd.py +33 -0
  131. jolt/plugins/alias.py +3 -0
  132. jolt/plugins/allure.py +5 -2
  133. jolt/plugins/autotools.py +66 -0
  134. jolt/plugins/cache.py +133 -0
  135. jolt/plugins/cmake.py +74 -6
  136. jolt/plugins/conan.py +238 -0
  137. jolt/plugins/cxx.py +698 -0
  138. jolt/plugins/cxxinfo.py +7 -0
  139. jolt/plugins/dashboard.py +1 -1
  140. jolt/plugins/docker.py +80 -23
  141. jolt/plugins/email.py +2 -2
  142. jolt/plugins/email.xslt +144 -101
  143. jolt/plugins/environ.py +11 -0
  144. jolt/plugins/fetch.py +141 -0
  145. jolt/plugins/gdb.py +39 -19
  146. jolt/plugins/gerrit.py +1 -14
  147. jolt/plugins/git.py +283 -85
  148. jolt/plugins/googletest.py +2 -1
  149. jolt/plugins/http.py +36 -38
  150. jolt/plugins/libtool.py +63 -0
  151. jolt/plugins/linux.py +990 -0
  152. jolt/plugins/logstash.py +4 -4
  153. jolt/plugins/meson.py +61 -0
  154. jolt/plugins/ninja-compdb.py +99 -30
  155. jolt/plugins/ninja.py +468 -166
  156. jolt/plugins/paths.py +11 -1
  157. jolt/plugins/pkgconfig.py +219 -0
  158. jolt/plugins/podman.py +136 -92
  159. jolt/plugins/python.py +137 -0
  160. jolt/plugins/remote_execution/__init__.py +0 -0
  161. jolt/plugins/remote_execution/administration_pb2.py +46 -0
  162. jolt/plugins/remote_execution/administration_pb2_grpc.py +170 -0
  163. jolt/plugins/remote_execution/log_pb2.py +32 -0
  164. jolt/plugins/remote_execution/log_pb2_grpc.py +68 -0
  165. jolt/plugins/remote_execution/scheduler_pb2.py +41 -0
  166. jolt/plugins/remote_execution/scheduler_pb2_grpc.py +141 -0
  167. jolt/plugins/remote_execution/worker_pb2.py +38 -0
  168. jolt/plugins/remote_execution/worker_pb2_grpc.py +112 -0
  169. jolt/plugins/report.py +12 -2
  170. jolt/plugins/rust.py +25 -0
  171. jolt/plugins/scheduler.py +710 -0
  172. jolt/plugins/selfdeploy/setup.py +8 -4
  173. jolt/plugins/selfdeploy.py +138 -88
  174. jolt/plugins/strings.py +35 -22
  175. jolt/plugins/symlinks.py +26 -11
  176. jolt/plugins/telemetry.py +5 -2
  177. jolt/plugins/timeline.py +13 -3
  178. jolt/plugins/volume.py +46 -48
  179. jolt/scheduler.py +589 -192
  180. jolt/tasks.py +625 -121
  181. jolt/templates/timeline.html.template +44 -47
  182. jolt/timer.py +22 -0
  183. jolt/tools.py +638 -282
  184. jolt/utils.py +211 -7
  185. jolt/version.py +1 -1
  186. jolt/xmldom.py +12 -2
  187. {jolt-0.9.123.dist-info → jolt-0.9.435.dist-info}/METADATA +97 -38
  188. jolt-0.9.435.dist-info/RECORD +207 -0
  189. {jolt-0.9.123.dist-info → jolt-0.9.435.dist-info}/WHEEL +1 -1
  190. jolt/plugins/amqp.py +0 -834
  191. jolt/plugins/debian.py +0 -338
  192. jolt/plugins/ftp.py +0 -181
  193. jolt/plugins/repo.py +0 -253
  194. jolt-0.9.123.dist-info/RECORD +0 -77
  195. {jolt-0.9.123.dist-info → jolt-0.9.435.dist-info}/entry_points.txt +0 -0
  196. {jolt-0.9.123.dist-info → jolt-0.9.435.dist-info}/top_level.txt +0 -0
jolt/plugins/amqp.py DELETED
@@ -1,834 +0,0 @@
1
- import click
2
- import functools
3
- import getpass
4
- import keyring
5
- import os
6
- try:
7
- import pika
8
- from pika.exceptions import AMQPConnectionError
9
- from pika.adapters.utils.connection_workflow import AMQPConnectorStackTimeout
10
- except ImportError:
11
- from jolt import log
12
- log.error("AMQP plugin enabled but not installed. Install it with: pip install jolt[amqp]")
13
- os._exit(1)
14
-
15
- import threading
16
- import time
17
-
18
- from jolt.cli import cli
19
- from jolt import config
20
- from jolt import filesystem as fs
21
- from jolt import hooks
22
- from jolt import log
23
- from jolt import scheduler
24
- from jolt import utils
25
- from jolt.manifest import JoltManifest
26
- from jolt.tools import Tools
27
- from jolt.error import JoltCommandError
28
- from jolt.error import raise_error
29
- from jolt.error import raise_task_error_if
30
- from jolt.error import raise_task_error_on_exception
31
-
32
-
33
- NAME = "amqp"
34
-
35
-
36
- def _get_auth():
37
- service = config.get(NAME, "keyring.service", NAME)
38
-
39
- username = config.get(NAME, "keyring.username")
40
- if not username:
41
- return "guest", "guest"
42
-
43
- password = config.get(NAME, "keyring.password") or keyring.get_password(NAME, username)
44
- if not password:
45
- password = getpass.getpass(NAME + " password: ")
46
- assert password, "no password in keyring for " + NAME
47
- keyring.set_password(service, username, password)
48
- return username, password
49
-
50
-
51
- def _get_url():
52
- host = config.get("amqp", "host", "amqp-service")
53
- port = int(config.get("amqp", "port", 5672))
54
- username, password = _get_auth()
55
- return "amqp://{}:{}@{}:{}/%2F".format(username, password, host, port)
56
-
57
-
58
- TYPE = "Remote execution"
59
- TIMEOUT = (3.5, 27)
60
- POLL_INTERVAL = 1
61
-
62
-
63
- class WorkerTaskConsumer(object):
64
- """This is a task consumer that will handle unexpected interactions
65
- with RabbitMQ such as channel and connection closures.
66
-
67
- If RabbitMQ closes the connection, this class will stop and indicate
68
- that reconnection is necessary. You should look at the output, as
69
- there are limited reasons why the connection may be closed, which
70
- usually are tied to permission related issues or socket timeouts.
71
-
72
- If the channel is closed, it will indicate a problem with one of the
73
- commands that were issued and that should surface in the output as well.
74
-
75
- """
76
- EXCHANGE = 'jolt_exchange'
77
- EXCHANGE_TYPE = 'direct'
78
- QUEUE = 'jolt_tasks'
79
- RESULT_EXCHANGE = 'jolt_results'
80
- ROUTING_KEY_PREFIX = ''
81
- ROUTING_KEY_REQUEST = 'default'
82
- ROUTING_KEY_RESULT = 'default'
83
-
84
- def __init__(self, amqp_url):
85
- """Create a new instance of the consumer class, passing in the AMQP
86
- URL used to connect to RabbitMQ.
87
-
88
- :param str amqp_url: The AMQP url to connect with
89
-
90
- """
91
- self.should_reconnect = False
92
- self.was_consuming = False
93
-
94
- self._connection = None
95
- self._channel = None
96
- self._closing = False
97
- self._consumer_tag = None
98
- self._url = amqp_url
99
- self._consuming = False
100
- # In production, experiment with higher prefetch values
101
- # for higher consumer throughput
102
- self._prefetch_count = 1
103
- self._job = None
104
- self._routing_key = self.ROUTING_KEY_PREFIX + config.get(
105
- "amqp", "routing_key",
106
- os.getenv("RABBITMQ_ROUTING_KEY", self.ROUTING_KEY_REQUEST))
107
- self._queue = self.QUEUE + "_" + self._routing_key
108
- self._max_priority = config.getint("amqp", "max-priority", 1)
109
-
110
- def connect(self):
111
- """This method connects to RabbitMQ, returning the connection handle.
112
- When the connection is established, the on_connection_open method
113
- will be invoked by pika.
114
-
115
- :rtype: pika.SelectConnection
116
-
117
- """
118
- log.info('Connecting to {}', self._url)
119
- return pika.SelectConnection(
120
- parameters=pika.URLParameters(self._url),
121
- on_open_callback=self.on_connection_open,
122
- on_open_error_callback=self.on_connection_open_error,
123
- on_close_callback=self.on_connection_closed)
124
-
125
- def close_connection(self):
126
- self._consuming = False
127
- if self._connection.is_closing or self._connection.is_closed:
128
- log.info('Connection is closing or already closed')
129
- else:
130
- log.info('Closing connection')
131
- self._connection.close()
132
-
133
- def on_connection_open(self, _unused_connection):
134
- """This method is called by pika once the connection to RabbitMQ has
135
- been established. It passes the handle to the connection object in
136
- case we need it, but in this case, we'll just mark it unused.
137
-
138
- :param pika.SelectConnection _unused_connection: The connection
139
-
140
- """
141
- log.info('Connection opened')
142
- self.open_channel()
143
-
144
- def on_connection_open_error(self, _unused_connection, err):
145
- """This method is called by pika if the connection to RabbitMQ
146
- can't be established.
147
-
148
- :param pika.SelectConnection _unused_connection: The connection
149
- :param Exception err: The error
150
-
151
- """
152
- log.error('Connection open failed: {}', err)
153
- self.reconnect()
154
-
155
- def on_connection_closed(self, _unused_connection, reason):
156
- """This method is invoked by pika when the connection to RabbitMQ is
157
- closed unexpectedly. Since it is unexpected, we will reconnect to
158
- RabbitMQ if it disconnects.
159
-
160
- :param pika.connection.Connection connection: The closed connection obj
161
- :param Exception reason: exception representing reason for loss of
162
- connection.
163
-
164
- """
165
- self._channel = None
166
- if self._closing:
167
- self._connection.ioloop.stop()
168
- else:
169
- log.warning('Connection closed, reconnect necessary: {}', reason)
170
- self.reconnect()
171
-
172
- def reconnect(self):
173
- """Will be invoked if the connection can't be opened or is
174
- closed. Indicates that a reconnect is necessary then stops the
175
- ioloop.
176
-
177
- """
178
- self.should_reconnect = True
179
- self.stop()
180
-
181
- def open_channel(self):
182
- """Open a new channel with RabbitMQ by issuing the Channel.Open RPC
183
- command. When RabbitMQ responds that the channel is open, the
184
- on_channel_open callback will be invoked by pika.
185
-
186
- """
187
- log.info('Creating a new channel')
188
- self._connection.channel(on_open_callback=self.on_channel_open)
189
-
190
- def on_channel_open(self, channel):
191
- """This method is invoked by pika when the channel has been opened.
192
- The channel object is passed in so we can make use of it.
193
-
194
- Since the channel is now open, we'll declare the exchange to use.
195
-
196
- :param pika.channel.Channel channel: The channel object
197
-
198
- """
199
- log.info('Channel opened')
200
- self._channel = channel
201
- self.add_on_channel_close_callback()
202
- self.setup_exchange(self.EXCHANGE)
203
-
204
- def add_on_channel_close_callback(self):
205
- """This method tells pika to call the on_channel_closed method if
206
- RabbitMQ unexpectedly closes the channel.
207
-
208
- """
209
- log.info('Adding channel close callback')
210
- self._channel.add_on_close_callback(self.on_channel_closed)
211
-
212
- def on_channel_closed(self, channel, reason):
213
- """Invoked by pika when RabbitMQ unexpectedly closes the channel.
214
- Channels are usually closed if you attempt to do something that
215
- violates the protocol, such as re-declare an exchange or queue with
216
- different parameters. In this case, we'll close the connection
217
- to shutdown the object.
218
-
219
- :param pika.channel.Channel: The closed channel
220
- :param Exception reason: why the channel was closed
221
-
222
- """
223
- log.warning('Channel {} was closed: {}', channel, reason)
224
- self.close_connection()
225
-
226
- def setup_exchange(self, exchange_name):
227
- """Setup the exchange on RabbitMQ by invoking the Exchange.Declare RPC
228
- command. When it is complete, the on_exchange_declareok method will
229
- be invoked by pika.
230
-
231
- :param str|unicode exchange_name: The name of the exchange to declare
232
-
233
- """
234
- log.info('Declaring exchange: {}', exchange_name)
235
- # Note: using functools.partial is not required, it is demonstrating
236
- # how arbitrary data can be passed to the callback when it is called
237
- cb = functools.partial(
238
- self.on_exchange_declareok, userdata=exchange_name)
239
- self._channel.exchange_declare(
240
- exchange=exchange_name,
241
- exchange_type=self.EXCHANGE_TYPE,
242
- callback=cb)
243
-
244
- def on_exchange_declareok(self, _unused_frame, userdata):
245
- """Invoked by pika when RabbitMQ has finished the Exchange.Declare RPC
246
- command.
247
-
248
- :param pika.Frame.Method unused_frame: Exchange.DeclareOk response frame
249
- :param str|unicode userdata: Extra user data (exchange name)
250
-
251
- """
252
- log.info('Exchange declared: {}', userdata)
253
- self.setup_queue(self._queue)
254
-
255
- def setup_queue(self, queue_name):
256
- """Setup the queue on RabbitMQ by invoking the Queue.Declare RPC
257
- command. When it is complete, the on_queue_declareok method will
258
- be invoked by pika.
259
-
260
- :param str|unicode queue_name: The name of the queue to declare.
261
-
262
- """
263
- log.info('Declaring queue {}', queue_name)
264
- cb = functools.partial(self.on_queue_declareok, userdata=queue_name)
265
- self._channel.queue_declare(
266
- queue=queue_name, callback=cb,
267
- arguments={
268
- "x-message-deduplication": True,
269
- "x-max-priority": self._max_priority
270
- })
271
-
272
- def on_queue_declareok(self, _unused_frame, userdata):
273
- """Method invoked by pika when the Queue.Declare RPC call made in
274
- setup_queue has completed. In this method we will bind the queue
275
- and exchange together with the routing key by issuing the Queue.Bind
276
- RPC command. When this command is complete, the on_bindok method will
277
- be invoked by pika.
278
-
279
- :param pika.frame.Method _unused_frame: The Queue.DeclareOk frame
280
- :param str|unicode userdata: Extra user data (queue name)
281
-
282
- """
283
- queue_name = userdata
284
- log.info('Binding {} to {} with {}',
285
- self.EXCHANGE, queue_name, self._routing_key)
286
- cb = functools.partial(self.on_bindok, userdata=queue_name)
287
- self._channel.queue_bind(
288
- queue_name,
289
- self.EXCHANGE,
290
- routing_key=self._routing_key,
291
- callback=cb)
292
- log.info('Binding {} to {} with jolt_{}',
293
- self.EXCHANGE, queue_name, self._routing_key)
294
- self._channel.queue_bind(
295
- queue_name,
296
- self.EXCHANGE,
297
- routing_key="jolt_" + self._routing_key)
298
-
299
- def on_bindok(self, _unused_frame, userdata):
300
- """Invoked by pika when the Queue.Bind method has completed. At this
301
- point we will set the prefetch count for the channel.
302
-
303
- :param pika.frame.Method _unused_frame: The Queue.BindOk response frame
304
- :param str|unicode userdata: Extra user data (queue name)
305
-
306
- """
307
- log.info('Queue bound: {}', userdata)
308
- self.set_qos()
309
-
310
- def set_qos(self):
311
- """This method sets up the consumer prefetch to only be delivered
312
- one message at a time. The consumer must acknowledge this message
313
- before RabbitMQ will deliver another one. You should experiment
314
- with different prefetch values to achieve desired performance.
315
-
316
- """
317
- self._channel.basic_qos(
318
- prefetch_count=self._prefetch_count, callback=self.on_basic_qos_ok)
319
-
320
- def on_basic_qos_ok(self, _unused_frame):
321
- """Invoked by pika when the Basic.QoS method has completed. At this
322
- point we will start consuming messages by calling start_consuming
323
- which will invoke the needed RPC commands to start the process.
324
-
325
- :param pika.frame.Method _unused_frame: The Basic.QosOk response frame
326
-
327
- """
328
- log.info('QOS set to: {}', self._prefetch_count)
329
- self.start_consuming()
330
-
331
- def start_consuming(self):
332
- """This method sets up the consumer by first calling
333
- add_on_cancel_callback so that the object is notified if RabbitMQ
334
- cancels the consumer. It then issues the Basic.Consume RPC command
335
- which returns the consumer tag that is used to uniquely identify the
336
- consumer with RabbitMQ. We keep the value to use it when we want to
337
- cancel consuming. The on_message method is passed in as a callback pika
338
- will invoke when a message is fully received.
339
-
340
- """
341
- log.info('Issuing consumer related RPC commands')
342
- self.add_on_cancel_callback()
343
- self._consumer_tag = self._channel.basic_consume(
344
- self._queue, self.on_message)
345
- self.was_consuming = True
346
- self._consuming = True
347
-
348
- def add_on_cancel_callback(self):
349
- """Add a callback that will be invoked if RabbitMQ cancels the consumer
350
- for some reason. If RabbitMQ does cancel the consumer,
351
- on_consumer_cancelled will be invoked by pika.
352
-
353
- """
354
- log.info('Adding consumer cancellation callback')
355
- self._channel.add_on_cancel_callback(self.on_consumer_cancelled)
356
-
357
- def on_consumer_cancelled(self, method_frame):
358
- """Invoked by pika when RabbitMQ sends a Basic.Cancel for a consumer
359
- receiving messages.
360
-
361
- :param pika.frame.Method method_frame: The Basic.Cancel frame
362
-
363
- """
364
- log.info('Consumer was cancelled remotely, shutting down: {}',
365
- method_frame)
366
- if self._channel:
367
- self._channel.close()
368
-
369
- def on_message(self, channel, basic_deliver, properties, body):
370
- """Invoked by pika when a message is delivered from RabbitMQ. The
371
- channel is passed for your convenience. The basic_deliver object that
372
- is passed in carries the exchange, routing key, delivery tag and
373
- a redelivered flag for the message. The properties passed in is an
374
- instance of BasicProperties with the message properties and the body
375
- is the message that was sent.
376
-
377
- :param pika.channel.Channel _unused_channel: The channel object
378
- :param pika.Spec.Basic.Deliver: basic_deliver method
379
- :param pika.Spec.BasicProperties: properties
380
- :param bytes body: The message body
381
-
382
- """
383
- log.info('Received execution request # {} from {}',
384
- basic_deliver.delivery_tag, properties.app_id)
385
-
386
- class Job(threading.Thread):
387
- def __init__(self, consumer, channel, basic_deliver, properties, body):
388
- super(Job, self).__init__()
389
- self.consumer = consumer
390
- self.channel = channel
391
- self.basic_deliver = basic_deliver
392
- self.properties = properties
393
- self.body = body
394
-
395
- def selfdeploy(self):
396
- """ Installs the correct version of Jolt as specified in execution request. """
397
-
398
- tools = Tools()
399
- manifest = JoltManifest()
400
- try:
401
- manifest.parse()
402
- ident = manifest.get_parameter("jolt_identity")
403
- url = manifest.get_parameter("jolt_url")
404
- if not ident or not url:
405
- return "jolt"
406
-
407
- requires = manifest.get_parameter("jolt_requires")
408
-
409
- log.info("Jolt version: {}", ident)
410
-
411
- src = "build/selfdeploy/{}/src".format(ident)
412
- env = "build/selfdeploy/{}/env".format(ident)
413
-
414
- if not fs.path.exists(env):
415
- try:
416
- fs.makedirs(src)
417
- tools.run("curl {} | tar zx -C {}", url, src)
418
- tools.run("virtualenv {}", env)
419
- tools.run(". {}/bin/activate && pip install -e {}", env, src)
420
- if requires:
421
- tools.run(". {}/bin/activate && pip install {}", env, requires)
422
- if "autocompletion=" in tools.read_file(f"{src}/jolt/cli.py"):
423
- tools.run(". {}/bin/activate && pip install 'click<8.1'", env, src)
424
- except Exception as e:
425
- tools.rmtree("build/selfdeploy/{}", ident, ignore_errors=True)
426
- raise e
427
-
428
- return ". {}/bin/activate && jolt".format(env)
429
- except Exception as e:
430
- log.exception()
431
- raise e
432
-
433
- def run(self):
434
- with open("default.joltxmanifest", "wb") as f:
435
- f.write(self.body)
436
-
437
- log.info("Manifest written")
438
-
439
- tools = Tools()
440
- for recipe in tools.glob("*.jolt"):
441
- tools.unlink(recipe)
442
-
443
- try:
444
- jolt = self.selfdeploy()
445
- config_file = config.get("amqp", "config", "")
446
- if config_file:
447
- config_file = "-c " + config_file
448
-
449
- log.info("Running jolt")
450
- tools.run("{} -vv {} build --worker --result result.joltxmanifest",
451
- jolt, config_file, output_stdio=True)
452
- except JoltCommandError as e:
453
- self.response = ""
454
- try:
455
- manifest = JoltManifest()
456
- try:
457
- manifest.parse("result.joltxmanifest")
458
- except Exception:
459
- manifest.duration = "0"
460
- manifest.result = "FAILED"
461
- manifest.stdout = "\n".join(e.stdout)
462
- manifest.stderr = "\n".join(e.stderr)
463
- self.response = manifest.format()
464
- except Exception:
465
- log.exception()
466
- log.error("Task failed")
467
- except Exception:
468
- log.exception()
469
- self.response = ""
470
- try:
471
- manifest = JoltManifest()
472
- try:
473
- manifest.parse("result.joltxmanifest")
474
- except Exception:
475
- manifest.duration = "0"
476
- manifest.result = "FAILED"
477
- self.response = manifest.format()
478
- except Exception:
479
- log.exception()
480
- log.error("Task failed")
481
- else:
482
- self.response = ""
483
- try:
484
- manifest = JoltManifest()
485
- try:
486
- manifest.parse("result.joltxmanifest")
487
- except Exception:
488
- manifest.duration = "0"
489
- manifest.result = "SUCCESS"
490
- self.response = manifest.format()
491
- except Exception:
492
- log.exception()
493
- log.info("Task succeeded")
494
-
495
- utils.call_and_catch(tools.unlink, "result.joltxmanifest")
496
- self.consumer.add_on_job_completed_callback(self)
497
-
498
- self._job = Job(self, channel, basic_deliver, properties, body)
499
- self._job.start()
500
-
501
- def add_on_job_completed_callback(self, job):
502
- if self._connection:
503
- self._connection.ioloop.add_callback_threadsafe(
504
- functools.partial(self.on_job_completed, job))
505
- else:
506
- self._job = None
507
-
508
- def on_job_completed(self, job):
509
- job.join()
510
- if job.channel is self._channel:
511
- self._channel.basic_publish(
512
- exchange=self.RESULT_EXCHANGE,
513
- routing_key=job.properties.correlation_id,
514
- properties=pika.BasicProperties(
515
- correlation_id=job.properties.correlation_id,
516
- expiration="600000"),
517
- body=str(job.response))
518
-
519
- self.acknowledge_message(job.basic_deliver.delivery_tag)
520
- log.info("Result published")
521
- else:
522
- log.info("Result not published as connection was lost")
523
- self._job = None
524
-
525
- def acknowledge_message(self, delivery_tag):
526
- """Acknowledge the message delivery from RabbitMQ by sending a
527
- Basic.Ack RPC method for the delivery tag.
528
-
529
- :param int delivery_tag: The delivery tag from the Basic.Deliver frame
530
-
531
- """
532
- log.info('Acknowledging message {}', delivery_tag)
533
- self._channel.basic_ack(delivery_tag)
534
-
535
- def stop_consuming(self):
536
- """Tell RabbitMQ that you would like to stop consuming by sending the
537
- Basic.Cancel RPC command.
538
-
539
- """
540
- if self._channel:
541
- log.info('Sending a Basic.Cancel RPC command to RabbitMQ')
542
- cb = functools.partial(
543
- self.on_cancelok, userdata=self._consumer_tag)
544
- self._channel.basic_cancel(self._consumer_tag, cb)
545
-
546
- def on_cancelok(self, _unused_frame, userdata):
547
- """This method is invoked by pika when RabbitMQ acknowledges the
548
- cancellation of a consumer. At this point we will close the channel.
549
- This will invoke the on_channel_closed method once the channel has been
550
- closed, which will in-turn close the connection.
551
-
552
- :param pika.frame.Method _unused_frame: The Basic.CancelOk frame
553
- :param str|unicode userdata: Extra user data (consumer tag)
554
-
555
- """
556
- self._consuming = False
557
- log.info(
558
- 'RabbitMQ acknowledged the cancellation of the consumer: {}',
559
- userdata)
560
- self.close_channel()
561
-
562
- def close_channel(self):
563
- """Call to close the channel with RabbitMQ cleanly by issuing the
564
- Channel.Close RPC command.
565
-
566
- """
567
- log.info('Closing the channel')
568
- self._channel.close()
569
-
570
- def run(self):
571
- """Run the task consumer by connecting to RabbitMQ and then
572
- starting the IOLoop to block and allow the SelectConnection to operate.
573
-
574
- """
575
- self._connection = self.connect()
576
- self._connection.ioloop.start()
577
-
578
- def stop(self):
579
- """Cleanly shutdown the connection to RabbitMQ by stopping the consumer
580
- with RabbitMQ. When RabbitMQ confirms the cancellation, on_cancelok
581
- will be invoked by pika, which will then closing the channel and
582
- connection. The IOLoop is started again because this method is invoked
583
- when CTRL-C is pressed raising a KeyboardInterrupt exception. This
584
- exception stops the IOLoop which needs to be running for pika to
585
- communicate with RabbitMQ. All of the commands issued prior to starting
586
- the IOLoop will be buffered but not processed.
587
-
588
- """
589
- if not self._closing:
590
- self._closing = True
591
- log.info('Stopping')
592
- if self._consuming:
593
- self.stop_consuming()
594
- self._connection.ioloop.start()
595
- else:
596
- self._connection.ioloop.stop()
597
- log.info('Stopped')
598
- if self._job:
599
- self.on_job_completed(self._job)
600
-
601
-
602
- class ReconnectingWorkerTaskConsumer(object):
603
- """This is a task consumer that will reconnect if the nested
604
- WorkerTaskConsumer indicates that a reconnect is necessary.
605
-
606
- """
607
-
608
- def __init__(self, amqp_url):
609
- self._reconnect_delay = 0
610
- self._amqp_url = amqp_url
611
- self._consumer = WorkerTaskConsumer(self._amqp_url)
612
-
613
- def run(self):
614
- while True:
615
- try:
616
- self._consumer.run()
617
- except KeyboardInterrupt:
618
- self._consumer.stop()
619
- break
620
- self._maybe_reconnect()
621
-
622
- def _maybe_reconnect(self):
623
- if self._consumer.should_reconnect:
624
- self._consumer.stop()
625
- reconnect_delay = self._get_reconnect_delay()
626
- log.info('Reconnecting after {} seconds', reconnect_delay)
627
- time.sleep(reconnect_delay)
628
- self._consumer = WorkerTaskConsumer(self._amqp_url)
629
-
630
- def _get_reconnect_delay(self):
631
- if self._consumer.was_consuming:
632
- self._reconnect_delay = 0
633
- else:
634
- self._reconnect_delay += 1
635
- if self._reconnect_delay > 30:
636
- self._reconnect_delay = 30
637
- return self._reconnect_delay
638
-
639
-
640
- @cli.command(name="amqp-worker", hidden=True)
641
- @click.pass_context
642
- def amqp_worker(ctx):
643
- """ Run an AMQP worker """
644
-
645
- consumer = ReconnectingWorkerTaskConsumer(_get_url())
646
- log.info("Service started")
647
- consumer.run()
648
-
649
-
650
- class AmqpExecutor(scheduler.NetworkExecutor):
651
-
652
- def __init__(self, factory, task):
653
- super(AmqpExecutor, self).__init__(factory)
654
- self.factory = factory
655
- self.callback_queue = None
656
- self.connection = None
657
- self.priority = config.getint("amqp", "priority", 0)
658
- self.task = task
659
-
660
- def _create_manifest(self):
661
- manifest = JoltManifest.export(self.task)
662
- build = manifest.create_build()
663
-
664
- tasks = [self.task.qualified_name]
665
- tasks += [t.qualified_name for t in self.task.extensions]
666
-
667
- for task in tasks:
668
- mt = build.create_task()
669
- mt.name = task
670
-
671
- registry = scheduler.ExecutorRegistry.get()
672
- for key, value in registry.get_network_parameters(self.task).items():
673
- param = manifest.create_parameter()
674
- param.key = key
675
- param.value = value
676
-
677
- routing_key = WorkerTaskConsumer.ROUTING_KEY_PREFIX
678
- routing_key += getattr(self.task.task, "routing_key", WorkerTaskConsumer.ROUTING_KEY_REQUEST)
679
-
680
- return manifest.format(), routing_key
681
-
682
- def _run(self, env):
683
- timeout = int(config.getint("amqp", "timeout", 300))
684
- manifest, routing_key = self._create_manifest()
685
-
686
- self.connect()
687
- self.publish_request(manifest, routing_key)
688
-
689
- log.debug("[AMQP] Queued {0}", self.task.short_qualified_name)
690
-
691
- self.task.running()
692
- for extension in self.task.extensions:
693
- extension.running()
694
-
695
- while self.response is None:
696
- try:
697
- self.connection.process_data_events(time_limit=timeout)
698
- if self.response is None:
699
- self.task.info("Remote execution still in progress after {}",
700
- self.task.duration_queued)
701
- except (ConnectionError, AMQPConnectionError):
702
- log.warning("[AMQP] Lost server connection")
703
- self.connect()
704
-
705
- log.debug("[AMQP] Finished {0}", self.task.short_qualified_name)
706
-
707
- manifest = JoltManifest()
708
- with raise_task_error_on_exception(self.task, "failed to parse build result manifest"):
709
- manifest.parsestring(self.response)
710
-
711
- self.task.running(utils.duration() - float(manifest.duration))
712
-
713
- if manifest.result != "SUCCESS":
714
- output = []
715
- if manifest.stdout:
716
- output.extend(manifest.stdout.split("\n"))
717
- if manifest.stderr:
718
- output.extend(manifest.stderr.split("\n"))
719
- for line in output:
720
- log.transfer(line, self.task.identity[:8])
721
- for task in [self.task] + self.task.extensions:
722
- with task.task.report() as report:
723
- remote_report = manifest.find_task(task.qualified_name)
724
- if remote_report:
725
- for error in remote_report.errors:
726
- report.manifest.append(error)
727
- raise_error("[AMQP] remote build failed with status: {0}".format(manifest.result))
728
-
729
- raise_task_error_if(
730
- self.task.has_artifact() and not env.cache.is_available_remotely(self.task), self.task,
731
- "no task artifact available in any cache, check configuration")
732
-
733
- raise_task_error_if(
734
- self.task.has_artifact() and not env.cache.download(self.task) and env.cache.download_enabled(),
735
- self.task, "failed to download task artifact")
736
-
737
- for extension in self.task.extensions:
738
- raise_task_error_if(
739
- self.task.has_artifact() and not env.cache.download(extension) and env.cache.download_enabled(),
740
- self.task, "failed to download task artifact")
741
-
742
- return self.task
743
-
744
- @utils.retried.on_exception((ConnectionError, AMQPConnectionError, AMQPConnectorStackTimeout))
745
- def connect(self):
746
- self.connection = pika.BlockingConnection(
747
- parameters=pika.URLParameters(_get_url()))
748
- self.channel = self.connection.channel()
749
- if not self.callback_queue:
750
- self.corr_id = self.task.identity
751
- self.channel.exchange_declare(
752
- exchange=WorkerTaskConsumer.RESULT_EXCHANGE,
753
- exchange_type=WorkerTaskConsumer.EXCHANGE_TYPE)
754
- result = self.channel.queue_declare(
755
- '', arguments={"x-expires": 7200000})
756
- self.callback_queue = result.method.queue
757
- self.channel.queue_bind(
758
- self.callback_queue,
759
- WorkerTaskConsumer.RESULT_EXCHANGE,
760
- routing_key=self.corr_id)
761
- self.channel.basic_consume(
762
- queue=self.callback_queue,
763
- on_message_callback=self.on_response,
764
- auto_ack=False)
765
- log.debug("[AMQP] Established connection to server")
766
-
767
- def on_response(self, channel, basic_deliver, properties, body):
768
- # log.debug("[AMQP] Completion of {}, expecting {}", properties.correlation_id, self.corr_id)
769
- if self.corr_id == properties.correlation_id:
770
- self.response = body.decode()
771
- channel.basic_ack(basic_deliver.delivery_tag)
772
- else:
773
- channel.basic_ack(basic_deliver.delivery_tag)
774
-
775
- def publish_request(self, manifest, routing_key):
776
- props = pika.BasicProperties(
777
- correlation_id=self.corr_id,
778
- priority=self.priority,
779
- headers={"x-deduplication-header": self.task.identity})
780
- self.response = None
781
- self.channel.basic_publish(
782
- exchange=WorkerTaskConsumer.EXCHANGE,
783
- routing_key=routing_key,
784
- properties=props,
785
- body=manifest)
786
-
787
- def run(self, env):
788
- try:
789
- self.task.started(TYPE)
790
- hooks.task_started_execution(self.task)
791
- for extension in self.task.extensions:
792
- extension.started(TYPE)
793
- hooks.task_started_execution(extension)
794
- with hooks.task_run([self.task] + self.task.extensions):
795
- self._run(env)
796
- for extension in self.task.extensions:
797
- hooks.task_finished_execution(extension)
798
- extension.finished(TYPE)
799
- hooks.task_finished_execution(self.task)
800
- self.task.finished(TYPE)
801
- except (ConnectionError, AMQPConnectionError):
802
- log.exception()
803
- for extension in self.task.extensions:
804
- extension.failed(TYPE)
805
- self.task.failed(TYPE)
806
- raise_error("Lost connection to AMQP server")
807
- except Exception as e:
808
- log.exception()
809
- for extension in self.task.extensions:
810
- extension.failed(TYPE)
811
- self.task.failed(TYPE)
812
- raise e
813
- finally:
814
- if self.connection is not None:
815
- utils.call_and_catch(self.connection.close)
816
- return self.task
817
-
818
-
819
- @scheduler.ExecutorFactory.Register
820
- class AmqpExecutorFactory(scheduler.NetworkExecutorFactory):
821
- def __init__(self, options):
822
- workers = config.getint(NAME, "workers", 16)
823
- super(AmqpExecutorFactory, self).__init__(max_workers=workers)
824
- self._options = options
825
-
826
- @property
827
- def options(self):
828
- return self._options
829
-
830
- def create(self, task):
831
- return AmqpExecutor(self, task)
832
-
833
-
834
- log.verbose("[AMQP] Loaded")