Commit Graph

2717 Commits

Author SHA1 Message Date
mprahl
63baaf9213 Move models.py to common/models.py and views.py to web/views.py 2020-01-16 14:39:46 -05:00
mprahl
c3dcaa6571 Move views.py to web/views.py 2020-01-16 14:39:46 -05:00
mprahl
5f27e4359f Move errors.py to common/errors.py 2020-01-16 14:39:46 -05:00
mprahl
3091d6cfda Move monitor.py to common/monitor.py 2020-01-16 14:39:46 -05:00
mprahl
15b04a888e Move mmd_resolver.py to web/mmd_resolver.py 2020-01-16 14:39:46 -05:00
mprahl
c2a3b059e9 Move messaging.py to common/messaging.py 2020-01-16 14:39:46 -05:00
mprahl
46dcb2c236 Move db_session.py to scheduler/db_session.py 2020-01-16 14:39:46 -05:00
mprahl
e0fa2371eb Move config.py to common/config.py 2020-01-16 14:39:46 -05:00
mprahl
b9762b804e Move backports.py to web/backports.py 2020-01-16 14:39:46 -05:00
mprahl
cfac201b1c Move auth.py to web/auth.py 2020-01-16 14:39:46 -05:00
mprahl
ee3ca47c69 Split utils/submit.py
This moves the code used by the backend and API to common/submit.py,
the code used just by the API to web/submit.py, and the code used
just by the backend to scheduler/submit.py.
2020-01-16 14:39:46 -05:00
mprahl
b03bc41e76 Move utils/reuse.py to scheduler/reuse.py 2020-01-16 14:39:46 -05:00
mprahl
b853ca2bb3 Move utils/views.py to web/views.py
In the next commit, this will be merged into web/utils.py.
2020-01-16 14:39:46 -05:00
mprahl
92be7b3b0b Move utils/ursine.py to scheduler/ursine.py 2020-01-16 14:39:46 -05:00
mprahl
707f1313f5 Move utils/request_utils.py to common/request_utils.py 2020-01-16 14:39:46 -05:00
mprahl
78d5a9e482 Split utils/mse.py
This moves the code used by the backend and API to common/resolve.py
and moves the code used just by the API to web/mse.py.
2020-01-16 14:39:46 -05:00
mprahl
5e401bd598 Split utils/general.py
This puts backend specific code in either the builder or scheduler
subpackage. This puts API specific code in the new web subpackage.
Lastly, any code shared between the API and backend is placed in the
common subpackage.
2020-01-16 14:39:46 -05:00
mprahl
19e3abe84c Remove outdated TODO comments in builder/base.py 2020-01-16 14:39:46 -05:00
mprahl
a8b90c083b Move utils/greenwave.py to scheduler/greenwave.py 2020-01-16 14:39:45 -05:00
mprahl
9f1e3ddee0 Rename test_greenwave.py to test_greenwave_handler.py 2020-01-16 14:39:45 -05:00
mprahl
4590419d22 Move utils/batches.py to scheduler/batches.py 2020-01-16 14:39:45 -05:00
Qixiang Wan
ba22e1f686 Ignore koji_build_change event without task_id 2020-01-16 14:39:45 -05:00
mprahl
4340dea1e5 Move get_session and retry to separate modules to reduce circular imports 2020-01-16 14:39:45 -05:00
mprahl
3dd239dca7 Simplify how MBS is configured
This merges the configuration from conf/config.py to
module_build_service/config.py. This also greatly simplifies the logic
in `init_config`. Additionally, `init_config` is no longer aware of
Flask. This will allow us to eventually break up the configuration
between the API and the backend.
2020-01-16 14:39:45 -05:00
mprahl
5b6d16542c Move some of the defaults from conf/config.py to module_build_service/config.py
This removes the need to duplicate these configuration values.
2020-01-16 14:39:45 -05:00
Qixiang Wan
0e0033fb02 Return immediately when message parser returns None 2020-01-16 14:39:45 -05:00
Qixiang Wan
00cf650e15 Remove build_id from build_task_finalize call 2020-01-16 14:39:45 -05:00
Qixiang Wan
c790eb4810 Remove mbspoller for fedmsg-hub 2020-01-16 14:39:45 -05:00
Qixiang Wan
6e3432c0e4 Setup periodic tasks after app is finalized 2020-01-16 14:39:45 -05:00
Qixiang Wan
8800134411 Remove unused handler arguments
The following handler arguments are not used at all:

1. `build_id` in handlers/components.py:build_task_finalize
2. `build_name` in handlers/tags.py:tagged
2020-01-16 14:39:45 -05:00
Qixiang Wan
c21a0e8621 Enable task_always_eager for local builds 2020-01-16 14:39:45 -05:00
Qixiang Wan
ca9d3a2af8 Add celery task router
Add route_task function to route celery tasks to different queues.
If we can figure out what the module build is a task ran for by
checking the task arguments, then we route this task to a queue
named:

    "mbs-{}".format(module_build_id % num_workers)

"num_workers" has default value of 1, and can be changed in
backend_config.py. If module build id can't be figured out, task will
be routed to the default queue which is named "mbs-default".

While setting up the workers, the number of workers should match with
"num_workers" in config, and each worker will listen on two queues:

    1. mbs-default
    2. mbs-{number} # for example, the first worker listens on "mbs-0"

By this design, all tasks for a particular module build will be routed
to the same queue and run on the same worker serially.
2020-01-16 14:39:45 -05:00
Qixiang Wan
d01f911bd1 Rename handler.repos.done argument name "repo_tag" to "tag_name"
This to make it same as the `tag_name` argument in
`handlers.tags.tagged`, so we can handle it easily while inspecting the
function signatures.
2020-01-16 14:39:45 -05:00
mprahl
6febdeb04d Force the Celery workers to run only one task at a time
This forces the tasks to be run serially.
2020-01-16 14:39:45 -05:00
mprahl
d95f41fa9b Use double quotes to match the coding standard 2020-01-16 14:39:45 -05:00
Chenxiong Qi
17ba29a9cb Schedule event handler to queue from internal
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00
Qixiang Wan
1a250aed14 Remove some default values from settings
Some of the config vars have default values, it is unncessary to keep
them in settings.

Note: Some vars are still in conf/config.py even they have the default
values, like the '*_url' vars, they're kept there just as placeholder
and reminder for changing while deploying the service.
2020-01-16 14:39:45 -05:00
Qixiang Wan
bc68b3b08c Revert the config split change
Revert the changes in a207d97 and 9a2efb3, at this moment, some code
relies on both settings from frontend and backend, and it's inconvenient
to run unittests with config split up to frontend only and backend
only.
2020-01-16 14:39:45 -05:00
Chenxiong Qi
7cc2296ae0 Remove unused import from MockModuleBuilder.py
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00
Qixiang Wan
aa58d02928 Remove MBSProducer from entry points 2020-01-16 14:39:45 -05:00
Chenxiong Qi
6154cf5eb7 Convert the Poller to be Celery periodic tasks
Poller methods within original class MBSProducer become module level
functions and are registered as Celery periodic tasks.

Code logging the size of fedmsg-hub queue are removed from log_summary.

process_open_component_builds is still kept there and not converted to a
periodic task.

There are some small refactor:

* do not format string in logging method call.
* reformat some lines of code doing SQLAlchemy database query to make
  them more readable.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00
Chenxiong Qi
d8c33bfefd Add python3-celery to Vagrantfile
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00
Jan Kaluza
e79740a748 Allow building modules locally without fedmsg-hub.
We started using `events.scheduler` to plan fake events instead of internal
queue implemented by fedmsg-hub. Thanks to that, we can stop using fedmsg-hub
completely for local builds.

In this commit, the `scheduler.local.main` is rewritten to not use fedmsg-hub.
The original `scheduler.local.main` is still needed by test_build tests and
therefore it is moved there.
2020-01-16 14:39:45 -05:00
Qixiang Wan
062350031a Partially revert the change of split config (a207d97)
It turns out we still have some backend code relies on the flask app,
so revert the change to init_config, and make minor change to create
config object for frontend and backend with the same function.
2020-01-16 14:39:45 -05:00
Qixiang Wan
e07b82e2f9 Register handlers as Celery tasks 2020-01-16 14:39:45 -05:00
Qixiang Wan
d6c5f8c13b Create config for frontend or backend seperately
1. init_web_config: create Config object for frontend, load
   configuration from `web_config.py`.
2. init_backend_config: create Config for backend, load configuration
   from `backend_config.py`.

And two new classes inherit from `Config` in config.py:

1. WebConfig: representing the orchestrator frontend web configuration
2. BackendConfig: representing the orchestrator backend workers
                  configuration

Before calling init_{web,backend}_config, check sys.argv, if
"fedmsg-hub*", "celery" or "build_module_locally" is present, it's
running as backend.
2020-01-16 14:39:45 -05:00
Jan Kaluza
473f7e5e5b Replace further work by Scheduler class based on the "sched" module.
To support multiple backend, we need to get rid of `further_work` concept
which is used in multiple places in the MBS code. Before this commit, if
one handler wanted to execute another handler, it planned this work by
constructing fake message and returning it. MBSConsumer then planned
its execution by adding it into the event loop.

In this commit, the new `events.scheduler` instance of new Scheduler
class is used to acomplish this. If handler wants to execute another
handler, it simply schedules it using `events.scheduler.add` method.

In the end of each handler, the `events.scheduler.run` method is
executed which calls all the scheduled handlers.

The idea is that when Celery is enabled, we can change the
`Scheduler.run` method to execute the handlers using the Celery, while
during the local builds, we could execute them directly without Celery.

Use of Scheduler also fixes the issue with ordering of such calls. If
we would call the handlers directly, they could have been executed
in the middle of another handler leading to behavior incompatible
with the current `further_work` concept. Using the Scheduler, these
calls are executed always in the end of the handler no matter when
they have been scheduled.
2020-01-16 14:39:45 -05:00
Chenxiong Qi
fa697a950d Add celery app instance with base config
This patch allows to schedule tasks and launch workers with basic
config. To launch a worker:

    celery -A module_build_service.celery_app -l info

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00
Chenxiong Qi
5f4ef94103 Pass event info arguments to event handler directly
This patch drops message objects, defined by class BaseMessage and its
subclasses, and pass event info arguments to event handler directly.
Different event handler requires different arguments to handle a kind of
specific event. The event info is parsed from the raw message received
from message bus.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00
Chenxiong Qi
e1581ac831 Remove config argument from event handlers
For the purpose of migrating to Celery to run event handler inside a
worker, Config object is not serializable. And from the usage of config
argument, every event handler can just access module_build_service.conf
directly. This removal would make the migration easier.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00