From 5f8f2b7d8e37e45042e327cbaeebadad43f2c8dd Mon Sep 17 00:00:00 2001 From: Lubos Kocman Date: Oct 17 2016 11:21:37 +0000 Subject: [PATCH 1/4] remove log.debus for unrelated messages (too spammy) Signed-off-by: Lubos Kocman --- diff --git a/rida/messaging.py b/rida/messaging.py index 44b2a85..51e1617 100644 --- a/rida/messaging.py +++ b/rida/messaging.py @@ -111,8 +111,6 @@ class BaseMessage(object): if msg_obj: return msg_obj - log.debug('Skipping unrecognized message with the topic "{0}"' - .format(topic)) return None From 66d00c26130f1e62fa95fb06ea14bbbcd5e08a1d Mon Sep 17 00:00:00 2001 From: Lubos Kocman Date: Oct 17 2016 11:21:55 +0000 Subject: [PATCH 2/4] Transition module build to failed in case that PDC was not updated - This allows resume ... otherwise we're stuck in building --- diff --git a/rida/scheduler/handlers/modules.py b/rida/scheduler/handlers/modules.py index f7917a2..41e073a 100644 --- a/rida/scheduler/handlers/modules.py +++ b/rida/scheduler/handlers/modules.py @@ -106,7 +106,7 @@ def wait(config, session, msg): dependencies, tag = _get_deps_and_tag() except ValueError: log.exception("Failed to get module info from PDC. Max retries reached.") - build.transition(config, state="build") # Wait for the buildroot to be ready.a + build.transition(config, state="failed") session.commit() raise From a146963ec0d01a6c68af737f41bc568574de2e5d Mon Sep 17 00:00:00 2001 From: Lubos Kocman Date: Oct 17 2016 11:25:42 +0000 Subject: [PATCH 3/4] Use correct rida.log for logging - improved logging for rida/views.py (helps to debug resubmit) Signed-off-by: Lubos Kocman --- diff --git a/rida/views.py b/rida/views.py index 076dae8..2ddd7e1 100644 --- a/rida/views.py +++ b/rida/views.py @@ -30,11 +30,9 @@ This is the implementation of the orchestrator's public RESTful API. from flask import request, jsonify from flask.views import MethodView import json -import logging import modulemd import os import rida.auth -import rida.logger import rida.scm import shutil import tempfile @@ -85,18 +83,22 @@ class ModuleBuildAPI(MethodView): try: r = json.loads(request.get_data().decode("utf-8")) except: + log.error('Invalid JSON submitted') raise ValidationError('Invalid JSON submitted') if "scmurl" not in r: + log.error('Missing scmurl') raise ValidationError('Missing scmurl') url = r["scmurl"] if not any(url.startswith(prefix) for prefix in conf.scmurls): + log.error('The submitted scmurl is not allowed') raise Unauthorized("The submitted scmurl is not allowed") yaml = "" td = None try: + log.debug('Verifying modulemd') td = tempfile.mkdtemp() scm = rida.scm.SCM(url, conf.scmurls) cod = scm.checkout(td) @@ -117,6 +119,7 @@ class ModuleBuildAPI(MethodView): try: mmd.loads(yaml) except: + log.error('Invalid modulemd') raise UnprocessableEntity('Invalid modulemd') if models.ModuleBuild.query.filter_by(name=mmd.name, @@ -166,6 +169,7 @@ class ModuleBuildAPI(MethodView): full_url = pkg["repository"] + "?#" + pkg["commit"] full_urls.append((pkgname, full_url)) + log.debug("Checking scm urls") # Checks the availability of SCM urls. pool = ThreadPool(10) err_msgs = pool.map(lambda data: "Cannot checkout {}".format(data[0]) @@ -190,7 +194,7 @@ class ModuleBuildAPI(MethodView): module.transition(conf, models.BUILD_STATES["wait"]) db.session.add(module) db.session.commit() - logging.info("%s submitted build of %s-%s-%s", username, mmd.name, + log.info("%s submitted build of %s-%s-%s", username, mmd.name, mmd.version, mmd.release) return jsonify(module.json()), 201 From fbbe3bdd9746d4236578a8efacf3f112633bf430 Mon Sep 17 00:00:00 2001 From: Lubos Kocman Date: Oct 17 2016 11:28:17 +0000 Subject: [PATCH 4/4] Add functionality to resume failed build - resume only failed module build tasks (this should be configurable in the future) Signed-off-by: Lubos Kocman --- diff --git a/rida/views.py b/rida/views.py index 2ddd7e1..1dc7b6e 100644 --- a/rida/views.py +++ b/rida/views.py @@ -122,21 +122,31 @@ class ModuleBuildAPI(MethodView): log.error('Invalid modulemd') raise UnprocessableEntity('Invalid modulemd') - if models.ModuleBuild.query.filter_by(name=mmd.name, + module = models.ModuleBuild.query.filter_by(name=mmd.name, version=mmd.version, - release=mmd.release).first(): - raise Conflict('Module already exists') - - module = models.ModuleBuild.create( - db.session, - conf, - name=mmd.name, - version=mmd.version, - release=mmd.release, - modulemd=yaml, - scmurl=url, - username=username - ) + release=mmd.release).first() + if module: + log.debug('Checking whether module build already exist.') + # TODO: make this configurable we might want to allow resubmit of any stucked build on DEV no matter the state + if module.state not in (models.BUILD_STATES['failed']): + log.error('Module (state=%s) already exists. Only new or failed builds are allowed.' % module.state) + raise Conflict('Module (state=%s) already exists. Only new or failed builds are allowed.' % module.state) + log.debug('Resuming existing module build %r' % module) + module.username = username + module.transition(conf, models.BUILD_STATES["init"]) + log.info("Resumed existing module build in previous state %s" % module.state) + else: + log.debug('Creating new module build') + module = models.ModuleBuild.create( + db.session, + conf, + name=mmd.name, + version=mmd.version, + release=mmd.release, + modulemd=yaml, + scmurl=url, + username=username + ) # List of (pkg_name, git_url) tuples to be used to check # the availability of git URLs paralelly later. @@ -182,13 +192,18 @@ class ModuleBuildAPI(MethodView): for pkgname, pkg in mmd.components.rpms.packages.items(): full_url = pkg["repository"] + "?#" + pkg["commit"] - build = models.ComponentBuild( - module_id=module.id, - package=pkgname, - format="rpms", - scmurl=full_url, - ) - db.session.add(build) + existing_build = models.ComponentBuild.query.filter_by(module_id=module.id, package=pkgname).first() + if existing_build and existing_build.state != models.BUILD_STATES['done']: + existing_build.state = models.BUILD_STATES['init'] + db.session.add(existing_build) + else: # XXX: what about components that were present in previous build but are gone now (component reduction) + build = models.ComponentBuild( + module_id=module.id, + package=pkgname, + format="rpms", + scmurl=full_url, + ) + db.session.add(build) module.modulemd = mmd.dumps() module.transition(conf, models.BUILD_STATES["wait"])