From fdfb1ed830d8f089a40bb3855215860d5eb7ddc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0abata?= Date: Tue, 28 Jun 2016 18:31:58 +0200 Subject: [PATCH] Implement the query bits of the API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr Ĺ abata --- rida.py | 32 ++++++++++++++++++++++---------- rida/{db.py => database.py} | 0 2 files changed, 22 insertions(+), 10 deletions(-) rename rida/{db.py => database.py} (100%) diff --git a/rida.py b/rida.py index c94427e1..f3923974 100755 --- a/rida.py +++ b/rida.py @@ -28,7 +28,6 @@ This is the implementation of the orchestrator's public RESTful API. """ -# TODO: Load configuration. # TODO: Handle GET and POST requests. # TODO; Validate the input modulemd & spec inputs. # TODO: Update the PDC dependency graph. @@ -37,16 +36,15 @@ This is the implementation of the orchestrator's public RESTful API. # TODO: Set the build state to wait once we're done. from flask import Flask -from rida import config +from rida import config, database +import json 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.""" +# TODO: Load the config file from environment +conf = config.from_file("rida.conf") +db = database.Session() @app.route("/rida/module-builds/", methods=["POST"]) def submit_build(): @@ -56,12 +54,26 @@ def submit_build(): @app.route("/rida/module-builds/", methods=["GET"]) def query_builds(): """Lists all tracked module builds.""" - return "query_builds()", 501 + return json.dumps([{"id": x.id, "state": x.state} + for x in db.session.query(database.Module).all()]), 200 -@app.route("/rida/module-builds/") +@app.route("/rida/module-builds/", methods=["GET"]) def query_build(id): """Lists details for the specified module builds.""" - return "query_build(id)", 501 + module = db.session.query(database.Module).filter_by(id=id).first() + if module: + tasks = dict() + if module.state != "init": + for build in db.session.query(database.Build).filter_by(module_id=id).all(): + tasks[build.format + "/" + build.package] = \ + str(build.task) + "/" + build.state + return json.dumps({ + "id": module.id, + "state": module.state, + "tasks": tasks + }), 200 + else: + return "", 404 if __name__ == "__main__": app.run() diff --git a/rida/db.py b/rida/database.py similarity index 100% rename from rida/db.py rename to rida/database.py