Merge lp:~rvb/maas/refactor-celerysettings into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1110
Proposed branch: lp:~rvb/maas/refactor-celerysettings
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 485 lines (+241/-122)
11 files modified
Makefile (+5/-3)
etc/celeryconfig.py (+6/-72)
etc/celeryconfig_cluster.py (+43/-0)
etc/celeryconfig_common.py (+65/-0)
etc/democeleryconfig.py (+9/-24)
etc/democeleryconfig_cluster.py (+35/-0)
etc/democeleryconfig_common.py (+33/-0)
services/celeryd/run (+0/-22)
services/cluster-worker/run (+20/-0)
services/region-worker/run (+22/-0)
setup.py (+3/-1)
To merge this branch: bzr merge lp:~rvb/maas/refactor-celerysettings
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+126816@code.launchpad.net

Commit message

Split the celeryconfig file into 2 files: one for the region controller and one for the cluster controller, both importing from a common config file. Split the celeryd service (on a dev instance) into a region worker (in charge of DNS-related tasks, etc.) and a cluster controller in charge of the cluster-specific tasks (like powering up nodes, uploading DHCP, etc.)

Description of the change

Split the celeryconfig file into 2 files: one for the region controller and one for the cluster controller, both importing from a common config file. Split the celeryd service (on a dev instance) into a region worker (in charge of DNS-related tasks, etc.) and a cluster controller in charge of the cluster-specific tasks (powering up nodes, uploading DHCP, etc.)

= Notes =

- Turns out PXE_TEMPLATES_DIR is not used anywhere so I simply got rid of it.

- I've created two new services: cluster-worker and region-worker, they remplace the old celeryd service.

- All the common settings have been moved into a celeryconfig_common file. Right now, the code relies on the fact that all the settings are available (because some of the settings are used "declaratively", like "@task(queue=celery_config.WORKER_QUEUE_DNS)") so even if strictly speaking, WORKER_QUEUE_DNS isn't used by the cluster code (this is a task only used by the region controller), it still needs to be there.

= Pre-imp =

This was discussed with Julian.

= Demo =

Run:
'make run-cluster'
'make run-region'
(Or all in one: 'make run')
And then watch logs/cluster-worker/current: you'll see the cluster tasks go through
You can also have a look at logs/webapp/current to see the initial API call used to exchange the RabbitMQ credentials.

= Next =

The packaging needs to be changed a bit in order for that change to be landed:
- the new file celeryconfig_common.py should be copied over by the region and the cluster packaging scripts.
- the cluster controller should:
    - copy celeryconfig_cluster.py instead of celeryconfig.py (which is now the region-specific config file.)
I'm working on it.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

I like the nomenclature of "region worker" vs. "cluster worker."

PXE_TEMPLATES_DIR was used once upon a time, but somebody realized that we only had one template and so dropped the directory meant for PXE templates... juuuussst before we had to create multiple PXE templates. And then we unified them again.

Revision history for this message
Gavin Panella (allenap) wrote :

> PXE_TEMPLATES_DIR was used once upon a time, but somebody realized that we
> only had one template and so dropped the directory meant for PXE templates...
> juuuussst before we had to create multiple PXE templates. And then we unified
> them again.

Erm, I suspect that was me. Still, I'm not sure that the celery stuff actually needs to know where those templates are anyway, only the TFTP server.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Wonderful. This makes all kind of sense.

Apart maybe from having CLUSTER_UUID in the common settings. :)

review: Approve
Revision history for this message
Raphaël Badin (rvb) wrote :

> Wonderful. This makes all kind of sense.
>
> Apart maybe from having CLUSTER_UUID in the common settings. :)

Right, I've moved it into etc/celeryconfig_cluster.py.

Thanks for the review!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2012-09-27 02:51:21 +0000
3+++ Makefile 2012-09-28 23:10:28 +0000
4@@ -192,8 +192,8 @@
5 # Development services.
6 #
7
8-service_names_region := database dns reloader txlongpoll web webapp
9-service_names_cluster := celeryd pserv reloader
10+service_names_region := database dns region-worker reloader txlongpoll web webapp
11+service_names_cluster := cluster-worker pserv reloader
12 service_names_all := $(service_names_region) $(service_names_cluster)
13
14 # The following template is intended to be used with `call`, and it
15@@ -277,7 +277,9 @@
16
17 services/dns/@deps: bin/py
18
19-services/celeryd/@deps: bin/celeryd
20+services/cluster-worker/@deps: bin/celeryd
21+
22+services/region-worker/@deps: bin/celeryd
23
24 services/database/@deps: bin/database
25
26
27=== modified file 'etc/celeryconfig.py'
28--- etc/celeryconfig.py 2012-09-28 10:16:59 +0000
29+++ etc/celeryconfig.py 2012-09-28 23:10:28 +0000
30@@ -1,7 +1,7 @@
31 # Copyright 2012 Canonical Ltd. This software is licensed under the
32 # GNU Affero General Public License version 3 (see the file LICENSE).
33
34-"""Celery settings for the maas project.
35+"""Celery settings for the region controller.
36
37 Do not edit this file. Instead, put custom settings in a module named
38 maas_local_celeryconfig.py somewhere on the PYTHONPATH.
39@@ -17,51 +17,13 @@
40
41 from datetime import timedelta
42
43+import celeryconfig_common
44 from maas import import_settings
45
46-# Location of power action templates. Use an absolute path, or leave as
47-# None to use the templates installed with the running version of MAAS.
48-POWER_TEMPLATES_DIR = None
49-
50-# Location of PXE config templates. Use an absolute path, or leave as
51-# None to use the templates installed with the running version of MAAS.
52-PXE_TEMPLATES_DIR = None
53-
54-# Location of MAAS' bind configuration files.
55-DNS_CONFIG_DIR = '/etc/bind/maas'
56-
57-# RNDC port to be configured by MAAS to communicate with the BIND
58-# server.
59-DNS_RNDC_PORT = 954
60-
61-# DHCP leases file, as maintained by ISC dhcpd.
62-DHCP_LEASES_FILE = '/var/lib/maas/dhcp/dhcpd.leases'
63-
64-# ISC dhcpd configuration file.
65-DHCP_CONFIG_FILE = '/etc/maas/dhcpd.conf'
66-
67-# List of interfaces that the dhcpd should service (if managed by MAAS).
68-DHCP_INTERFACES_FILE = '/var/lib/maas/dhcpd-interfaces'
69-
70-# Broker connection information. This is read by the region controller
71-# and sent to connecting cluster controllers.
72-# The cluster controllers currently read this same configuration file,
73-# but the broker URL they receive from the region controller overrides
74-# this setting.
75-BROKER_URL = 'amqp://guest:guest@localhost:5672//'
76-
77-# Cluster UUID. Will be overridden by the customized setting in the
78-# local MAAS Celery config.
79-CLUSTER_UUID = None
80-
81-# Location for log file.
82-MAAS_CELERY_LOG = '/var/log/maas/celery.log'
83-
84-WORKER_QUEUE_DNS = 'celery'
85-WORKER_QUEUE_BOOT_IMAGES = 'celery'
86-# XXX rvb 2012-09-25, bug=1056250: the WORKER_QUEUE_CLUSTER should be
87-# the uuid of the cluster controller.
88-WORKER_QUEUE_CLUSTER = 'celery'
89+# Silence lint, this will be defined by celeryconfig_common.
90+WORKER_QUEUE_BOOT_IMAGES = None
91+
92+import_settings(celeryconfig_common)
93
94 try:
95 import maas_local_celeryconfig
96@@ -71,35 +33,7 @@
97 import_settings(maas_local_celeryconfig)
98
99
100-# Each cluster should have its own queue created automatically by Celery.
101-CELERY_CREATE_MISSING_QUEUES = True
102-
103-
104-CELERY_IMPORTS = (
105- # Tasks.
106- "provisioningserver.tasks",
107-
108- # This import is needed for its side effect: it initializes the
109- # cache that allows workers to share data.
110- "provisioningserver.initialize_cache",
111- )
112-
113-CELERY_ACKS_LATE = True
114-
115-# Do not store the tasks' return values (aka tombstones);
116-# This improves performance.
117-CELERY_IGNORE_RESULT = True
118-
119-
120 CELERYBEAT_SCHEDULE = {
121- 'unconditional-dhcp-lease-upload': {
122- 'task': 'provisioningserver.tasks.upload_dhcp_leases',
123- 'schedule': timedelta(minutes=1),
124- 'options': {'queue': WORKER_QUEUE_CLUSTER},
125- },
126-
127- # XXX rvb 2012-09-25, bug=1056250: this task should
128- # only on the master worker.
129 'report-boot-images': {
130 'task': 'provisioningserver.tasks.report_boot_images',
131 'schedule': timedelta(minutes=5),
132
133=== added file 'etc/celeryconfig_cluster.py'
134--- etc/celeryconfig_cluster.py 1970-01-01 00:00:00 +0000
135+++ etc/celeryconfig_cluster.py 2012-09-28 23:10:28 +0000
136@@ -0,0 +1,43 @@
137+# Copyright 2012 Canonical Ltd. This software is licensed under the
138+# GNU Affero General Public License version 3 (see the file LICENSE).
139+
140+"""Celery settings for the cluster controller.
141+
142+Do not edit this file. Instead, put custom settings in a module named
143+maas_local_celeryconfig.py somewhere on the PYTHONPATH.
144+"""
145+
146+from __future__ import (
147+ absolute_import,
148+ print_function,
149+ unicode_literals,
150+)
151+
152+__metaclass__ = type
153+
154+from datetime import timedelta
155+
156+import celeryconfig_common
157+from maas import import_settings
158+
159+# Cluster UUID. Will be overridden by the customized setting in the
160+# local MAAS Celery config.
161+CLUSTER_UUID = None
162+
163+import_settings(celeryconfig_common)
164+
165+try:
166+ import maas_local_celeryconfig
167+except ImportError:
168+ pass
169+else:
170+ import_settings(maas_local_celeryconfig)
171+
172+
173+CELERYBEAT_SCHEDULE = {
174+ 'unconditional-dhcp-lease-upload': {
175+ 'task': 'provisioningserver.tasks.upload_dhcp_leases',
176+ 'schedule': timedelta(minutes=1),
177+ 'options': {'queue': CLUSTER_UUID},
178+ },
179+}
180
181=== added file 'etc/celeryconfig_common.py'
182--- etc/celeryconfig_common.py 1970-01-01 00:00:00 +0000
183+++ etc/celeryconfig_common.py 2012-09-28 23:10:28 +0000
184@@ -0,0 +1,65 @@
185+# Copyright 2012 Canonical Ltd. This software is licensed under the
186+# GNU Affero General Public License version 3 (see the file LICENSE).
187+
188+"""Celery settings common to the region and the cluster controllers."""
189+
190+from __future__ import (
191+ absolute_import,
192+ print_function,
193+ unicode_literals,
194+)
195+
196+__metaclass__ = type
197+
198+
199+# Location of power action templates. Use an absolute path, or leave as
200+# None to use the templates installed with the running version of MAAS.
201+POWER_TEMPLATES_DIR = None
202+
203+# Location of MAAS' bind configuration files.
204+DNS_CONFIG_DIR = '/etc/bind/maas'
205+
206+# RNDC port to be configured by MAAS to communicate with the BIND
207+# server.
208+DNS_RNDC_PORT = 954
209+
210+# DHCP leases file, as maintained by ISC dhcpd.
211+DHCP_LEASES_FILE = '/var/lib/maas/dhcp/dhcpd.leases'
212+
213+# ISC dhcpd configuration file.
214+DHCP_CONFIG_FILE = '/etc/maas/dhcpd.conf'
215+
216+# List of interfaces that the dhcpd should service (if managed by MAAS).
217+DHCP_INTERFACES_FILE = '/var/lib/maas/dhcpd-interfaces'
218+
219+# Broker connection information. This is read by the region controller
220+# and sent to connecting cluster controllers.
221+# The cluster controllers currently read this same configuration file,
222+# but the broker URL they receive from the region controller overrides
223+# this setting.
224+BROKER_URL = 'amqp://guest:guest@localhost:5672//'
225+
226+# Location for log file.
227+MAAS_CELERY_LOG = '/var/log/maas/celery.log'
228+
229+
230+WORKER_QUEUE_DNS = 'celery'
231+WORKER_QUEUE_BOOT_IMAGES = 'celery'
232+
233+# Each cluster should have its own queue created automatically by Celery.
234+CELERY_CREATE_MISSING_QUEUES = True
235+
236+CELERY_IMPORTS = (
237+ # Tasks.
238+ "provisioningserver.tasks",
239+
240+ # This import is needed for its side effect: it initializes the
241+ # cache that allows workers to share data.
242+ "provisioningserver.initialize_cache",
243+ )
244+
245+CELERY_ACKS_LATE = True
246+
247+# Do not store the tasks' return values (aka tombstones);
248+# This improves performance.
249+CELERY_IGNORE_RESULT = True
250
251=== modified file 'etc/democeleryconfig.py'
252--- etc/democeleryconfig.py 2012-09-28 10:16:59 +0000
253+++ etc/democeleryconfig.py 2012-09-28 23:10:28 +0000
254@@ -1,7 +1,7 @@
255 # Copyright 2012 Canonical Ltd. This software is licensed under the
256 # GNU Affero General Public License version 3 (see the file LICENSE).
257
258-"""Celery demo settings for the maas project."""
259+"""Celery demo settings for the maas project: region settings."""
260
261 from __future__ import (
262 absolute_import,
263@@ -11,36 +11,21 @@
264
265 __metaclass__ = type
266
267+
268 import os
269
270 import celeryconfig
271+import democeleryconfig_common
272 from maas import import_settings
273
274+# Silence lint, this will be defined by democeleryconfig_common.
275+DEV_ROOT_DIRECTORY = None
276+
277 # Extend base settings.
278 import_settings(celeryconfig)
279
280-
281-DEV_ROOT_DIRECTORY = os.path.join(
282- os.path.dirname(__file__), os.pardir)
283-
284-
285-DNS_CONFIG_DIR = os.path.join(
286- DEV_ROOT_DIRECTORY, 'run/named/')
287-
288-
289-DNS_RNDC_PORT = 9154
290-
291-
292-DHCP_CONFIG_FILE = os.path.join(
293- DEV_ROOT_DIRECTORY, 'run/dhcpd.conf')
294-
295-
296-DHCP_LEASES_FILE = os.path.join(
297- DEV_ROOT_DIRECTORY, 'run/dhcpd.leases')
298-
299-
300-CLUSTER_UUID = "adfd3977-f251-4f2c-8d61-745dbd690bfc"
301-
302+import_settings(democeleryconfig_common)
303
304 MAAS_CELERY_LOG = os.path.join(
305- DEV_ROOT_DIRECTORY, 'logs/celeryd/current')
306+ DEV_ROOT_DIRECTORY, 'logs/region-worker/current')
307+
308
309=== added file 'etc/democeleryconfig_cluster.py'
310--- etc/democeleryconfig_cluster.py 1970-01-01 00:00:00 +0000
311+++ etc/democeleryconfig_cluster.py 2012-09-28 23:10:28 +0000
312@@ -0,0 +1,35 @@
313+# Copyright 2012 Canonical Ltd. This software is licensed under the
314+# GNU Affero General Public License version 3 (see the file LICENSE).
315+
316+"""Celery demo settings for the maas project: cluster settings."""
317+
318+from __future__ import (
319+ absolute_import,
320+ print_function,
321+ unicode_literals,
322+)
323+
324+__metaclass__ = type
325+
326+
327+import os
328+
329+import celeryconfig_cluster
330+import democeleryconfig_common
331+from maas import import_settings
332+
333+# Silence lint, this will be defined by democeleryconfig_common.
334+DEV_ROOT_DIRECTORY = None
335+
336+# Extend base settings.
337+import_settings(celeryconfig_cluster)
338+
339+import_settings(democeleryconfig_common)
340+
341+# Set a fixed CLUSTER_UUID. In production, this is taken from
342+# maas_local_celeryconfig.
343+CLUSTER_UUID = "adfd3977-f251-4f2c-8d61-745dbd690bfc"
344+
345+MAAS_CELERY_LOG = os.path.join(
346+ DEV_ROOT_DIRECTORY, 'logs/cluster-worker/current')
347+
348
349=== added file 'etc/democeleryconfig_common.py'
350--- etc/democeleryconfig_common.py 1970-01-01 00:00:00 +0000
351+++ etc/democeleryconfig_common.py 2012-09-28 23:10:28 +0000
352@@ -0,0 +1,33 @@
353+# Copyright 2012 Canonical Ltd. This software is licensed under the
354+# GNU Affero General Public License version 3 (see the file LICENSE).
355+
356+"""Celery demo settings for the maas project: common settings."""
357+
358+from __future__ import (
359+ absolute_import,
360+ print_function,
361+ unicode_literals,
362+)
363+
364+__metaclass__ = type
365+
366+import os
367+
368+
369+DEV_ROOT_DIRECTORY = os.path.join(
370+ os.path.dirname(__file__), os.pardir)
371+
372+
373+DNS_CONFIG_DIR = os.path.join(
374+ DEV_ROOT_DIRECTORY, 'run/named/')
375+
376+
377+DNS_RNDC_PORT = 9154
378+
379+
380+DHCP_CONFIG_FILE = os.path.join(
381+ DEV_ROOT_DIRECTORY, 'run/dhcpd.conf')
382+
383+
384+DHCP_LEASES_FILE = os.path.join(
385+ DEV_ROOT_DIRECTORY, 'run/dhcpd.leases')
386
387=== removed directory 'services/celeryd'
388=== removed file 'services/celeryd/down'
389=== removed file 'services/celeryd/run'
390--- services/celeryd/run 2012-09-27 02:51:21 +0000
391+++ services/celeryd/run 1970-01-01 00:00:00 +0000
392@@ -1,22 +0,0 @@
393-#!/usr/bin/env bash
394-# Copyright 2012 Canonical Ltd. This software is licensed under the
395-# GNU Affero General Public License version 3 (see the file LICENSE).
396-
397-# Exit immediately if a command exits with a non-zero status.
398-set -o errexit
399-# Treat unset variables as an error when substituting.
400-set -o nounset
401-
402-# Move to the project root.
403-cd "$(dirname "$0")/../.."
404-
405-# Start logging, if requested. Not using multilog here right now
406-# because there are race issues when restarting.
407-[ -z "${logdir:-}" ] || exec &>> "${logdir}/current"
408-
409-# XXX JeroenVermeulen 2012-08-23, bug=1040529: Use fghack to kludge around
410-# hanging celery shutdown.
411-script="$(readlink -f bin/celeryd)"
412-exec fghack "${script}" \
413- --loglevel INFO --beat --queues celery \
414- --config democeleryconfig
415
416=== added directory 'services/cluster-worker'
417=== added file 'services/cluster-worker/down'
418=== added file 'services/cluster-worker/run'
419--- services/cluster-worker/run 1970-01-01 00:00:00 +0000
420+++ services/cluster-worker/run 2012-09-28 23:10:28 +0000
421@@ -0,0 +1,20 @@
422+#!/usr/bin/env bash
423+# Copyright 2012 Canonical Ltd. This software is licensed under the
424+# GNU Affero General Public License version 3 (see the file LICENSE).
425+
426+# Exit immediately if a command exits with a non-zero status.
427+set -o errexit
428+# Treat unset variables as an error when substituting.
429+set -o nounset
430+
431+# Move to the project root.
432+cd "$(dirname "$0")/../.."
433+
434+# Start logging, if requested. Not using multilog here right now
435+# because there are race issues when restarting.
436+[ -z "${logdir:-}" ] || exec &>> "${logdir}/current"
437+
438+export PYTHONPATH=etc/:src/
439+export CELERY_CONFIG_MODULE=democeleryconfig_cluster
440+script="$(readlink -f bin/maas-provision)"
441+exec fghack "${script}" start-cluster-controller http://0.0.0.0:5240/
442
443=== added directory 'services/region-worker'
444=== added file 'services/region-worker/down'
445=== added file 'services/region-worker/run'
446--- services/region-worker/run 1970-01-01 00:00:00 +0000
447+++ services/region-worker/run 2012-09-28 23:10:28 +0000
448@@ -0,0 +1,22 @@
449+#!/usr/bin/env bash
450+# Copyright 2012 Canonical Ltd. This software is licensed under the
451+# GNU Affero General Public License version 3 (see the file LICENSE).
452+
453+# Exit immediately if a command exits with a non-zero status.
454+set -o errexit
455+# Treat unset variables as an error when substituting.
456+set -o nounset
457+
458+# Move to the project root.
459+cd "$(dirname "$0")/../.."
460+
461+# Start logging, if requested. Not using multilog here right now
462+# because there are race issues when restarting.
463+[ -z "${logdir:-}" ] || exec &>> "${logdir}/current"
464+
465+# XXX JeroenVermeulen 2012-08-23, bug=1040529: Use fghack to kludge around
466+# hanging celery shutdown.
467+script="$(readlink -f bin/celeryd)"
468+exec fghack "${script}" \
469+ --loglevel INFO --beat --queues celery,master \
470+ --config democeleryconfig
471
472=== modified file 'setup.py'
473--- setup.py 2012-09-28 20:32:53 +0000
474+++ setup.py 2012-09-28 23:10:28 +0000
475@@ -67,7 +67,9 @@
476 ['etc/cron.d/maas-gc']),
477 ('/usr/share/maas',
478 ['contrib/wsgi.py',
479- 'etc/celeryconfig.py']),
480+ 'etc/celeryconfig.py',
481+ 'etc/celeryconfig_cluster.py',
482+ 'etc/celeryconfig_common.py']),
483 ('/usr/share/maas/preseeds',
484 ['contrib/preseeds_v2/commissioning',
485 'contrib/preseeds_v2/enlist',