From 400e8bfde844d1a0c02a3dfa05c067aa1866663b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0abata?= Date: Fri, 24 Jun 2016 10:28:04 +0200 Subject: [PATCH] Sharing an early development version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr Šabata --- rida.py | 30 +++++++++++ rida/conf.py | 26 ---------- rida/config.py | 95 +++++++++++++++++++++++++++++++++++ rida/db.py | 56 +++++++++++++++++++++ rida/{log.py => logging.py} | 0 rida/{bus.py => messaging.py} | 0 6 files changed, 181 insertions(+), 26 deletions(-) delete mode 100644 rida/conf.py create mode 100644 rida/config.py rename rida/{log.py => logging.py} (100%) rename rida/{bus.py => messaging.py} (100%) diff --git a/rida.py b/rida.py index ad4dcc3c..c94427e1 100755 --- a/rida.py +++ b/rida.py @@ -35,3 +35,33 @@ This is the implementation of the orchestrator's public RESTful API. # TODO: Emit messages about module submission. # TODO: Set the build state to init once the module NVR is known. # TODO: Set the build state to wait once we're done. + +from flask import Flask +from rida import config + +app = Flask(__name__) +app.config.from_envvar("RIDA_SETTINGS", silent=True) + +conf = config.from_file() + +@app.teardown_appcontext +def close_db(error): + """Closes the database connection at the end of the request.""" + +@app.route("/rida/module-builds/", methods=["POST"]) +def submit_build(): + """Handles new module build submissions.""" + return "submit_build()", 501 + +@app.route("/rida/module-builds/", methods=["GET"]) +def query_builds(): + """Lists all tracked module builds.""" + return "query_builds()", 501 + +@app.route("/rida/module-builds/") +def query_build(id): + """Lists details for the specified module builds.""" + return "query_build(id)", 501 + +if __name__ == "__main__": + app.run() diff --git a/rida/conf.py b/rida/conf.py deleted file mode 100644 index 40c0d6d5..00000000 --- a/rida/conf.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 - -"""Configuration handler functions.""" diff --git a/rida/config.py b/rida/config.py new file mode 100644 index 00000000..ce9cf36f --- /dev/null +++ b/rida/config.py @@ -0,0 +1,95 @@ +# -*- 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 + +"""Configuration handler functions.""" + +# TODO: Pick the configuration format +# TODO: Add properties for all the required options. + +def from_file(filename=None): + """Create the configuration instance from a file. + + The file name is optional and defaults to /etc/rida/rida.conf. + + :param str filename: The configuration file to load, optional. + """ + if filename is None: + filename = "/etc/rida/rida.conf" + if not isinstance(filename, str): + raise TypeError("The configuration filename must be a string.") + conf = Config() + # TODO: Parse the file and set the properties + return conf + +class Config(object): + """Class representing the orchestrator configuration.""" + + def __init__(self): + """Initialize the Config object.""" + # Buildsystem to use; koji, copr, mock + self._system = "" + # SQLAlchemy RDB URL + self._db = "" + # PDC URL + self._pdc = "" + # Koji URL + self._koji = "" + + @property + def system(): + """Buildsystem to use by the orchestrator.""" + return self._system + + @system.setter + def system(s): + # XXX: Check if it's one of the supported values + self._system = str(s) + + @property + def db(): + """RDB URL for the orchestrator.""" + return self._db + + @db.setter + def db(s): + self._db = str(s) + + @property + def pdc(): + """PDC URL for the orchestrator.""" + return self._pdc + + @pdc.setter + def pdc(s): + self._pdc = str(s) + + @property + def koji(): + """Koji URL for the orchestrator.""" + return self._koji + + @koji.setter + def koji(s): + self._koji = str(s) diff --git a/rida/db.py b/rida/db.py index b75a2554..0ee3d3f3 100644 --- a/rida/db.py +++ b/rida/db.py @@ -24,3 +24,59 @@ # Written by Petr Šabata """Database handler functions.""" + +from sqlalchemy import Column, Integer, String +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() + +class Database(object): + """Class for handling database connections.""" + + def __init__(self, conf): + """...""" + if not isinstance(conf, rida.config.Config): + raise TypeError("Database requires a configuration object.") + self._conf = conf + + def connect_db(): + # TODO: implement this + + def disconnect_db(): + # TODO: implement this + + def get_db(): + # TODO: Implement this + + @property + def conf(): + """Database configuration.""" + return self._conf + + @conf.setter + def conf(o): + if not isinstance(conf, rida.config.Config): + raise TypeError("Invalid data passed for conf") + self._conf = o + +class Module(Base): + __tablename__ = "modules" + id = Column(Integer, primary_key=True) + name = Column(String) + version = Column(String) + release = Column(String) + # XXX: Consider making this a proper ENUM + state = Column(String) + modulemd = Column(String) + +class Build(Base): + __tablename__ = "builds" + id = Column(Integer, primary_key=True) + # XXX: Consider making this a proper foreign key + module_id = Column(Integer) + package = Column(String) + # XXX: Consider making this a proper ENUM + format = Column(String) + task = Column(Integer) + # XXX: Consider making this a proper ENUM + state = Column(String) diff --git a/rida/log.py b/rida/logging.py similarity index 100% rename from rida/log.py rename to rida/logging.py diff --git a/rida/bus.py b/rida/messaging.py similarity index 100% rename from rida/bus.py rename to rida/messaging.py