mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-23 18:21:42 +08:00
Move ridad into an importable location and validate module state strings.
This commit is contained in:
@@ -24,11 +24,32 @@
|
||||
|
||||
"""Database handler functions."""
|
||||
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
|
||||
from sqlalchemy.orm import sessionmaker, relationship
|
||||
from sqlalchemy import (
|
||||
Column,
|
||||
Integer,
|
||||
String,
|
||||
ForeignKey,
|
||||
create_engine,
|
||||
)
|
||||
from sqlalchemy.orm import (
|
||||
sessionmaker,
|
||||
relationship,
|
||||
validates,
|
||||
)
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
|
||||
# Just like koji.BUILD_STATES, except our own codes for modules.
|
||||
BUILD_STATES = {
|
||||
"init": 0,
|
||||
"wait": 1,
|
||||
"build": 2,
|
||||
"done": 3,
|
||||
"failed": 4,
|
||||
"ready": 5,
|
||||
}
|
||||
|
||||
|
||||
class RidaBase(object):
|
||||
# TODO -- we can implement functionality here common to all our model
|
||||
# classes.
|
||||
@@ -77,10 +98,17 @@ class Module(Base):
|
||||
name = Column(String, nullable=False)
|
||||
version = Column(String, nullable=False)
|
||||
release = Column(String, nullable=False)
|
||||
# XXX: Consider making this a proper ENUM
|
||||
state = Column(String, nullable=False)
|
||||
state = Column(Integer, nullable=False)
|
||||
modulemd = Column(String, nullable=False)
|
||||
|
||||
@validates('state')
|
||||
def validate_state(self, key, field):
|
||||
if field in BUILD_STATES.values():
|
||||
return field
|
||||
if field in BUILD_STATES:
|
||||
return BUILD_STATES[field]
|
||||
raise ValueError("%s: %s, not in %r" % (key, field, BUILD_STATES))
|
||||
|
||||
def json(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
|
||||
89
rida/scheduler/main.py
Executable file
89
rida/scheduler/main.py
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2016 Red Hat, Inc.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
# Written by Petr Šabata <contyk@redhat.com>
|
||||
# Ralph Bean <rbean@redhat.com>
|
||||
|
||||
"""The module build orchestrator for Modularity, the builder.
|
||||
|
||||
This is the main component of the orchestrator and is responsible for
|
||||
proper scheduling component builds in the supported build systems.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import threading
|
||||
|
||||
import rida.config
|
||||
import rida.messaging
|
||||
|
||||
log = logging.getLogger()
|
||||
|
||||
# TODO: Load the config file from environment
|
||||
config = rida.config.from_file("rida.conf")
|
||||
|
||||
# TODO: Utilized rida.builder to prepare the buildroots and build components.
|
||||
# TODO: Set the build state to build once the module build is started.
|
||||
# TODO: Set the build state to done once the module build is done.
|
||||
# TODO: Set the build state to failed if the module build fails.
|
||||
|
||||
class Messaging(threading.Thread):
|
||||
def run(self):
|
||||
# TODO: Listen for bus messages from rida about module builds
|
||||
# entering the wait state
|
||||
# TODO: Listen for bus messages from the buildsystem about
|
||||
# component builds changing state
|
||||
# TODO: Check for modules that can be set to done/failed
|
||||
# TODO: Act on these things somehow
|
||||
# TODO: Emit messages about doing so
|
||||
for msg in rida.messaging.listen(backend=config.messaging):
|
||||
log.debug("Saw %r, %r" % (msg['msg_id'], msg['topic']))
|
||||
if '.buildsys.build.state.change' in msg['topic']:
|
||||
self.handle_build_change(msg)
|
||||
elif '.rida.module.state.change' in msg['topic']:
|
||||
self.handle_module_change(msg)
|
||||
else:
|
||||
pass
|
||||
|
||||
class Polling(threading.Thread):
|
||||
def run(self):
|
||||
while True:
|
||||
# TODO: Check for module builds in the wait state
|
||||
# TODO: Check component builds in the open state
|
||||
# TODO: Check for modules that can be set to done/failed
|
||||
# TODO: Act on these things somehow
|
||||
# TODO: Emit messages about doing so
|
||||
# TODO: Sleep for a configuration-determined interval
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(level=logging.DEBUG) # For now
|
||||
logging.info("Starting ridad.")
|
||||
try:
|
||||
messaging_thread = Messaging()
|
||||
polling_thread = Polling()
|
||||
messaging_thread.start()
|
||||
polling_thread.start()
|
||||
except KeyboardInterrupt:
|
||||
# FIXME: Make this less brutal
|
||||
os._exit()
|
||||
Reference in New Issue
Block a user