From: hyokeun Date: Mon, 12 Feb 2018 07:38:07 +0000 (+0900) Subject: Api for gbs dashboard update X-Git-Tag: submit/trunk/20190927.012743~139^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F169937%2F2;p=services%2Fjenkins-scripts.git Api for gbs dashboard update Change-Id: I2dca7b792a39ae3f4c007ce6478dc976fb5ad84f --- diff --git a/common/buildmonitor_extention.py b/common/buildmonitor_extention.py index 2410ae6..6cc2b55 100644 --- a/common/buildmonitor_extention.py +++ b/common/buildmonitor_extention.py @@ -15,11 +15,15 @@ import os import sys +import base64 +import json from datetime import datetime +from urllib import quote_plus +from common.buildtrigger import trigger_next, remote_jenkins_build_job from buildmonitor_db import connect_db, disconnect_db, do_query, do_many_query, \ get_multi_values_from_query_data, get_value_from_query_data - + class BuildMonitorExtention(object): """ Interface to BuildMonitor(Database) """ def __init__(self): @@ -544,16 +548,19 @@ class GbsDashboard(BuildMonitorExtention): query_data = (tag, main_project, source_snapshot, gbs_type, submitter, tag) do_query(query, query_data) - def set_stage(self, tag, stage, reason=None): + def set_stage(self, tag, stage, reason=None, timestamp=None): if reason is None or reason == "": reason = "" - query = "INSERT INTO gbs_stage (gbs_status_id, gbs_stage_id, stage_status) \ + assert timestamp is not None + + query = "INSERT INTO gbs_stage (gbs_status_id, gbs_stage_id, stage_status, record_date) \ SELECT * FROM ( \ (SELECT id FROM gbs_status WHERE tag=%s) AS tmp1, \ (SELECT id FROM gbs_stage_lookup WHERE stage=%s) AS tmp2, \ - (SELECT (%s)) AS tmp3) \ + (SELECT (%s)) AS tmp3, \ + (SELECT (%s)) AS tmp4) \ WHERE NOT EXISTS ( \ SELECT * FROM (SELECT gsl.stage AS stage_name FROM gbs_stage gs, \ gbs_status gst, gbs_stage_lookup gsl \ @@ -561,7 +568,7 @@ class GbsDashboard(BuildMonitorExtention): ORDER BY gs.id DESC LIMIT 1) AS tmp \ WHERE stage_name=%s) \ LIMIT 1" - query_data = (tag, stage, reason, tag, stage) + query_data = (tag, stage, reason, timestamp, tag, stage) do_query(query, query_data) def set_packages(self, tag, packages): @@ -619,10 +626,12 @@ def put_snapshot_manifest(bm_ext, snapshot_name, manifest_items, start_datetime) build_project_id = bm_ext.get_build_project_id_for_buildsnapshot(snapshot_name) if build_project_id == 0: return False + #Delete data after check bm_ext.purge_snapshot_manifest_exist(build_project_id) manifest_data = [] + # getid from git_repository for git_repo, git_commit, obs_name in manifest_items: @@ -654,3 +663,23 @@ def get_snapshot_manifest(bm_ext, project): return manifest_list +def find_my_ip(): + try: + return os.getenv('SSH_CONNECTION').split(' ')[2] + except Exception as err: + return '0.0.0.0' + +def gbs_update_dashboard(raw_data): + raw_data["_timestamp"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + raw_data["_worker"] = {"node_name": os.getenv('NODE_NAME'), + "ip": find_my_ip()} + try: + encoded_data = base64.b64encode(json.dumps(raw_data)) + remote_jenkins_build_job(os.getenv('JENKINS_URL_INTERNAL'), \ + os.getenv('JENKINS_USER'), \ + os.getenv('JENKINS_PW'), \ + jobname=os.getenv('DASHBOARD_UPDATE_JOB_NAME'), \ + data='TRIGGER_INFO="%s"' % (quote_plus(encoded_data))) + except Exception as err: + trigger_next("DASHBOARD_UPDATE_%s" % raw_data.get("tag").replace('/', '_'), raw_data) + diff --git a/debian/jenkins-scripts.install b/debian/jenkins-scripts.install index 99c392d..3c2ab5b 100644 --- a/debian/jenkins-scripts.install +++ b/debian/jenkins-scripts.install @@ -50,3 +50,4 @@ debian/tmp/job_notify_buildstatus.py /var/lib/jenkins/jenkins-scripts/ debian/tmp/job_obs_project_manager.py /var/lib/jenkins/jenkins-scripts/ debian/tmp/job_gbs_dashboard_build.py /var/lib/jenkins/jenkins-scripts/ debian/tmp/job_gbsdbbuild_create_snapshot.py /var/lib/jenkins/jenkins-scripts/ +debian/tmp/job_gbs_build_dispatcher.py /var/lib/jenkins/jenkins-scripts/ diff --git a/job_buildmonitor_gbs.py b/job_buildmonitor_gbs.py index 5bab373..499aee2 100644 --- a/job_buildmonitor_gbs.py +++ b/job_buildmonitor_gbs.py @@ -45,6 +45,14 @@ class LocalError(Exception): """Local error exception.""" pass +def _set_stage(gbs_inst, stage, content): + gbs_inst.set_stage( + content.get('tag'), + stage, + content.get('reason'), + content.get('_timestamp') + ) + def fn_queued(gbs_inst, content): tag = content.get('tag') main_project = content.get('main_project') @@ -52,64 +60,48 @@ def fn_queued(gbs_inst, content): gbs_type = content.get('gbs_type') submitter = content.get('submitter') packages = content.get('packages') - reason = content.get('reason') + # set_queue() should be done by Dashboard itself when user initiate it. + # Call one more time here for confirmation. gbs_inst.set_queue(tag, main_project, source_snapshot, gbs_type, submitter) - gbs_inst.set_stage(tag, "queued", reason) + + _set_stage(gbs_inst, "queued", content) gbs_inst.set_packages(tag, packages) def fn_build_started(gbs_inst, content): - tag = content.get('tag') - reason = content.get('reason') - gbs_inst.set_stage(tag, "build_0", reason) + _set_stage(gbs_inst, "build_0", content) return def fn_build_finished(gbs_inst, content): - tag = content.get('tag') - reason = content.get('reason') - gbs_inst.set_stage(tag, "build_1", reason) + _set_stage(gbs_inst, "build_1", content) return def fn_snapshot_started(gbs_inst, content): - tag = content.get('tag') - reason = content.get('reason') - gbs_inst.set_stage(tag, "repo_0", reason) + _set_stage(gbs_inst, "repo_0", content) return def fn_snapshot_finished(gbs_inst, content): - tag = content.get('tag') - reason = content.get('reason') - gbs_inst.set_stage(tag, "repo_1", reason) + _set_stage(gbs_inst, "repo_1", content) return def fn_image_started(gbs_inst, content): - tag = content.get('tag') - reason = content.get('reason') - gbs_inst.set_stage(tag, "image_0", reason) + _set_stage(gbs_inst, "image_0", content) return def fn_image_finished(gbs_inst, content): - tag = content.get('tag') - reason = content.get('reason') - gbs_inst.set_stage(tag, "image_1", reason) + _set_stage(gbs_inst, "image_1", content) return def fn_test_started(gbs_inst, content): - tag = content.get('tag') - reason = content.get('reason') - gbs_inst.set_stage(tag, "test_0", reason) + _set_stage(gbs_inst, "test_0", content) return def fn_test_finished(gbs_inst, content): - tag = content.get('tag') - reason = content.get('reason') - gbs_inst.set_stage(tag, "test_1", reason) + _set_stage(gbs_inst, "test_1", content) return def fn_completed(gbs_inst, content): - tag = content.get('tag') - reason = content.get('reason') - gbs_inst.set_stage(tag, "completed", reason) + _set_stage(gbs_inst, "completed", content) return def fn_default(gbs_inst, content): diff --git a/job_gbs_build_dispatcher.py b/job_gbs_build_dispatcher.py new file mode 100755 index 0000000..eb86788 --- /dev/null +++ b/job_gbs_build_dispatcher.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import sys +import os + +from common.buildtrigger import trigger_info, trigger_next +from common.buildmonitor_extention import gbs_update_dashboard + +def menu_options(menu): + return ["", "Deps/Full Build", "Remove Packages", "New project gbs fullbuild", "Link Project Upgrade"].index(menu) + +def main(): + """The main body""" + + contents = trigger_info(os.getenv("TRIGGER_INFO")) + + transform_packages = [] + for x in contents.get("repo_commit"): + transform_packages.append( + {x["git_path"]: { + "commit": x["commit_id"], + "build": "include" if x["include_build"] == 1 else "exclude", + "image": "include" if x["include_image"] == 1 else "exclude"} + }) + bypass_data = { + "gbs_type" : contents.get("menu"), + "tag" : contents.get("tag"), + "source_snapshot": contents.get("snapshot"), + "main_project" : contents.get("project"), + "mode" : "queued", + "submitter" : contents.get("user_email"), + "packages" : transform_packages + } + + gbs_update_dashboard(bypass_data) + #trigger_next("gbs-dashboard-build_%s" % contents.get("tag").replace('/', '_'), bypass_data) + + +if __name__ == '__main__': + sys.exit(main()) + diff --git a/job_update_local_git.py b/job_update_local_git.py index 134a245..b2d0c45 100755 --- a/job_update_local_git.py +++ b/job_update_local_git.py @@ -63,7 +63,7 @@ def update_dashboard(full_git_path): ret_data = mygit.get_commit_info_from_id(reference) commit_id = ret_data["commit_id"] committer = ret_data["committer"] - commit_date = ret_data["commit_date"] + commit_date = ret_data["commit_date"][:19] commit_message = ret_data["commit_message"] db_git_commit_id = bm_ext.update_git_commit_strict( \ full_git_path, commit_id, committer, commit_date, commit_message, branch) @@ -78,7 +78,7 @@ def update_dashboard(full_git_path): tag_name = ret_data["tag_name"] tag_rev = ret_data["tag_rev"] tagger = ret_data["tagger"] - tag_date = ret_data["tag_date"] + tag_date = ret_data["tag_date"][:19] tag_message = ret_data["tag_message"] bm_ext.update_git_tag_strict(db_git_commit_id, tag_name, tag_rev, \ tagger, tag_date, tag_message) diff --git a/packaging/jenkins-scripts.spec b/packaging/jenkins-scripts.spec index 3b5b481..f8dd2b2 100644 --- a/packaging/jenkins-scripts.spec +++ b/packaging/jenkins-scripts.spec @@ -240,6 +240,7 @@ fi %{destdir}/common/workflow.py %{destdir}/common/get_name_from_specfile.py %{destdir}/common/gbsutils.py +%{destdir}/job_gbs_build_dispatcher.py %files dependsgraph %defattr(-,jenkins,jenkins)