[BuildMonitor] change the monitoring method 07/96507/3
authorSungHun Hwang <sh0924.hwang@samsung.com>
Wed, 9 Nov 2016 07:27:00 +0000 (16:27 +0900)
committerSungHun Hwang <sh0924.hwang@samsung.com>
Thu, 10 Nov 2016 05:11:00 +0000 (14:11 +0900)
1. structure
Before : module import & function call directly
After  : add new jenkins job named "BUILD-MONITOR" & trigger the job

2. change the buildmonitor file
Before : buildmonitor.py     in ~/jenkins-scripts/common folder
After  : job_buildmonitor.py in ~/jenkins-scripts        folder

3. modify the related jenkins job & spec files

Change-Id: I78afb496e10730acba84ca7d70825e319d419c2f
Signed-off-by: SungHun Hwang <sh0924.hwang@samsung.com>
job_buildmonitor.py [new file with mode: 0644]
job_create_snapshot.py
job_imager.py
job_post_image.py
job_pre_release_obs.py
job_request.py
job_submit.py
packaging/jenkins-scripts.spec

diff --git a/job_buildmonitor.py b/job_buildmonitor.py
new file mode 100644 (file)
index 0000000..039f7eb
--- /dev/null
@@ -0,0 +1,1146 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2016 Samsung Electronics.Co.Ltd.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+"""
+BuildMonitor APIs
+
+1. Related files
+  (1) gbs submit --------------- [job_submit.py]
+  (2) [pre] packae build ------- [on OBS]
+  (3) [pre] snapshot create ---- [job_pre_release_obs.py]
+  (4) [pre] image creation  ---- [job_imager.py][job_post_imager.py]
+  (5) SR accept or reject ------ [job_request.py]
+  (6) [post] package build ----- [on OBS]
+  (7) [post] snapshot creation - [job_create_snapshot.py]
+  (8) [post] image creation ---- [job_imager.py]
+  (9) Completed
+  * pre : pre build / post : post build
+
+2. function naming rules
+
+[ACTION]_for_[TABLE]
+
+ex) sr_submit_for_sr_status
+ACTION : Submit
+TABLE  : sr_status
+
+3. db table list
+
+[SR    parts] sr_stage | sr_status | sr_commit | sr_status_details
+[BUILD parts] build_snapshot | build_snapshot_package | build_image
+"""
+
+import os
+import sys
+import datetime
+from common import buildmonitor_db
+from common.buildtrigger import trigger_info, trigger_next
+
+class LocalError(Exception):
+    """Local error exception."""
+    pass
+
+#===============================================================================
+# for info_stage_id
+
+SR_SUBMIT = 1
+PRE_BUILD = 2
+PRE_SNAP = 3
+PRE_IMAGE = 4
+SR_ACCEPT = 5
+POST_BUILD = 6
+POST_SNAP = 7
+POST_IMAGE = 8
+COMPLETE = 9
+
+#===============================================================================
+# connect & disconnect db
+
+def bm_connect_db():
+    buildmonitor_db.connect_db()
+
+def bm_disconnect_db():
+    buildmonitor_db.disconnect_db()
+
+#===============================================================================
+# [job_submit.py]
+
+def sr_submit_for_sr_status(bm_git_tag):
+    print '[%s] enter sr_submit_for_sr_status\n' % (__file__)
+
+    # get curr_sr_status_id
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (bm_git_tag)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] curr_sr_status_id(%s)\n' % (__file__, curr_sr_status_id)
+
+    if curr_sr_status_id == 9876 or curr_sr_status_id == 0:
+        query = "INSERT INTO sr_status (sr, status) VALUES(%s, %s)"
+        query_data = (bm_git_tag, 'C')
+        buildmonitor_db.do_query(query, query_data)
+    else:
+        print '[%s] Already existing sr_status_id(%s) skip INSERT sr_stage\n' \
+                % (__file__, curr_sr_status_id)
+
+def sr_submit_for_sr_commit(commit_date, commit_msg, submit_date, submit_msg,
+                            submitter, git_tag, gerrit_project,
+                            gerrit_newrev, gerrit_account_name):
+    print '[%s] enter sr_submit_for_sr_commit\n' % (__file__)
+
+    # get current_sr_status_id (should be here, after sr_submit_for_sr_status)
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (git_tag)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] curr_sr_status_id(%s)\n' % (__file__, curr_sr_status_id)
+
+    obs_pkg_name = os.path.basename(gerrit_project)
+    bm_submitter = submitter.split('@')[0].strip('<')
+    #print '[%s] bm_submitter(%s)' % (__file__, bm_submitter)
+
+    query = "INSERT INTO sr_commit (sr_status_id, git_repository," \
+            "obs_package_name, git_commit_id, git_commit_date, "   \
+            "git_commit_message, git_committer, sr_submit_date, "  \
+            "sr_submit_message, sr_submitter) " \
+            "VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
+    query_data = (curr_sr_status_id, gerrit_project, obs_pkg_name,
+                    gerrit_newrev, commit_date, commit_msg,
+                    gerrit_account_name, submit_date, submit_msg,
+                    bm_submitter)
+    buildmonitor_db.do_query(query, query_data)
+
+def start_pre_build_for_sr_stage(git_tag, bm_start_datetime,
+                                 bm_end_datetime, pre_build_project_id):
+    print '[%s] enter start_pre_build_for_sr_stage\n' % (__file__)
+
+    # get current_sr_status_id (should be here after sr_submit_for_sr_status)
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (git_tag)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] curr_sr_status_id(%s)\n' % (__file__, curr_sr_status_id)
+
+    ### [1] end stage : SR submit
+    info_stage_id = 1
+    query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
+            "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+    query_data = (bm_end_datetime, 'S', curr_sr_status_id, info_stage_id, pre_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+    ### [2] start stage : [pre] package build
+    bm_start_datetime = bm_end_datetime
+    info_stage_id = 2
+    query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
+            "stage_status, build_project_id) VALUES(%s, %s, %s, %s, %s)"
+    query_data = (curr_sr_status_id, info_stage_id, bm_start_datetime, 'R', pre_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+def sr_submit_for_sr_stage(curr_sr_status_id, bm_start_datetime,
+                           bm_end_datetime, pre_build_project_id):
+    print '[%s] enter sr_submit_for_sr_stage\n' % (__file__)
+
+    ### [1] SR submit
+    info_stage_id = 1
+    query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
+            "stage_end_time, stage_status, build_project_id) VALUES(%s, %s, %s, %s, %s, %s)"
+    query_data = (curr_sr_status_id, info_stage_id, bm_start_datetime,
+                  bm_end_datetime, 'S', pre_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+def package_build_for_sr_detail_sr_stage(git_tag, bm_start_datetime,
+                                         bm_end_datetime, bm_src_project_lst):
+    print '[%s] enter package_build_for_sr_detail_sr_stage\n' % (__file__)
+
+    # get current_sr_status_id (should be here after sr_submit_for_sr_status)
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (git_tag)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] curr_sr_status_id(%s)\n' % (__file__, curr_sr_status_id)
+
+    ### for sr_status_detail & sr_stage
+    # bm_src_project_lst is needed for multi profile
+    print '[%s] bm_src_project_lst(%s)\n' % (__file__, bm_src_project_lst)
+    for bm_src_project in bm_src_project_lst:
+        #print '[%s] bm_src_project(%s)\n' % (__file__, bm_src_project)
+
+        # get info_project_id -> get pre_build_project_id
+        query = "SELECT id FROM info_project WHERE project_name = %s"
+        query_data = (bm_src_project)
+        info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        query = "SELECT id FROM build_project WHERE info_project_id = %s"
+        query_data = (info_project_id)
+        pre_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        print '[%s] info_project_id(%s), pre_build_project_id(%s)\n' \
+               % (__file__, info_project_id, pre_build_project_id)
+
+        # get sr_status_detail_id for checking group submit
+        query = "SELECT id FROM sr_status_detail WHERE sr_status_id = %s " \
+                "AND pre_build_project_id = %s"
+        query_data = (curr_sr_status_id, pre_build_project_id)
+        sr_status_detail_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        #print '[%s] sr_status_detail_id(%s)\n' % (__file__, sr_status_detail_id)
+
+        if sr_status_detail_id == 9876 or sr_status_detail_id == 0:
+            # get pre_build_project_id
+            query = "SELECT id FROM build_project WHERE info_project_id = %s"
+            query_data = (info_project_id)
+            pre_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+            ### for sr_status_detail
+            query = "INSERT INTO sr_status_detail (sr_status_id, pre_build_project_id) " \
+                    "VALUES(%s, %s)"
+            query_data = (curr_sr_status_id, pre_build_project_id)
+            buildmonitor_db.do_query(query, query_data)
+
+            ### for sr_stage for multi profile
+            # [1] start stage
+            sr_submit_for_sr_stage(curr_sr_status_id, bm_start_datetime,
+                                   bm_end_datetime, pre_build_project_id)
+            # [1] end stage / [2] start stage
+            start_pre_build_for_sr_stage(git_tag, bm_start_datetime,
+                                         bm_end_datetime, pre_build_project_id)
+        else:
+            # clear the existing tables (sr_stage & build_snapshot)
+            print '[%s] Already existing sr_status_id(%s)!! clear the related tables\n' \
+                  % (__file__, sr_status_detail_id)
+            query = "DELETE FROM sr_stage WHERE sr_status_id = %s AND build_project_id = %s"
+            query_data = (curr_sr_status_id, pre_build_project_id)
+            buildmonitor_db.do_query(query, query_data)
+
+            # get build_snapshot_id for deleting build_snapshot_package & build_image
+            query = "SELECT id FROM build_snapshot WHERE build_project_id = %s"
+            query_data = (pre_build_project_id)
+            build_snapshot_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+            # delete build_snapshot & build_snapshot_package & build_image
+            query = "DELETE FROM build_snapshot WHERE build_project_id = %s"
+            query_data = (pre_build_project_id)
+            buildmonitor_db.do_query(query, query_data)
+            query = "DELETE FROM build_snapshot_package WHERE build_snapshot_id = %s"
+            query_data = (build_snapshot_id)
+            buildmonitor_db.do_query(query, query_data)
+            query = "DELETE FROM build_image WHERE build_snapshot_id = %s"
+            query_data = (build_snapshot_id)
+            buildmonitor_db.do_query(query, query_data)
+
+            ### for sr_stage for multi profile
+            # [1] start stage
+            sr_submit_for_sr_stage(curr_sr_status_id, bm_start_datetime,
+                                   bm_end_datetime, pre_build_project_id)
+            # [1] end stage / [2] start stage
+            start_pre_build_for_sr_stage(git_tag, bm_start_datetime,
+                                         bm_end_datetime, pre_build_project_id)
+
+#===============================================================================
+# [job_pre_release_obs.py]
+
+def update_fail_status_for_sr_stage(project, bm_git_tag):
+    print '[%s] enter update_fail_status_for_sr_stage\n' % (__file__)
+
+    # get curr_sr_status_id
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (bm_git_tag)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] curr_sr_status_id (%s)\n' % (__file__, curr_sr_status_id)
+
+    # get curr_info_project_id -> get curr_build_project_id for multi profile
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project)
+    curr_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    query = "SELECT id FROM build_project WHERE info_project_id = %s"
+    query_data = (curr_info_project_id)
+    curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    ### [3] stage end : update fail status [pre] snapshot creation
+    info_stage_id = 3
+    query = "UPDATE sr_stage SET stage_status = %s WHERE sr_status_id = %s " \
+            "AND info_stage_id = %s AND build_project_id = %s"
+    query_data = ('F', curr_sr_status_id, info_stage_id, curr_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+def start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetime):
+    print '[%s] enter start_pre_create_snapshot_for_sr_stage\n' % (__file__)
+
+    # get curr_sr_status_id
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (bm_git_tag)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get curr_info_project_id -> get curr_build_project_id for multi profile
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project)
+    curr_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    query = "SELECT id FROM build_project WHERE info_project_id = %s"
+    query_data = (curr_info_project_id)
+    curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get multi_build_status from build_target
+    query = "SELECT status FROM build_target WHERE build_project_id = %s " \
+            "AND last_flag = %s"
+    query_data = (curr_build_project_id, 'Y')
+    multi_build_status = buildmonitor_db.get_multi_values_from_query_data(query, query_data)
+    print '[%s] multi_build_status(%s)\n' % (__file__, multi_build_status)
+
+    # default 'S'
+    info_stage_status = 'S'
+    for each_build_status in multi_build_status:
+        #print '[%s] each_build_status(%s)\n' % (__file__, each_build_status)
+        if each_build_status[0] == 'F':
+            info_stage_status = 'F'
+            print '[%s] failed!! info_stage_status(%s)\n' % (__file__, info_stage_status)
+
+    ### [2] stage end : [pre] package build
+    info_stage_id = 2
+    bm_end_datetime = bm_start_datetime
+    query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
+            "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+    query_data = (bm_end_datetime, info_stage_status, curr_sr_status_id,
+                  info_stage_id, curr_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+    ### [3] stage start : [pre] snapshot creation
+    info_stage_id = 3
+    query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
+            "stage_status, build_project_id) VALUES(%s, %s, %s, %s, %s)"
+    query_data = (curr_sr_status_id, info_stage_id,
+                  bm_start_datetime, 'R', curr_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+def start_pre_create_snapshot_for_build_snapshot(project, bm_start_datetime):
+    print '[%s] enter start_pre_create_snapshot_for_build_snapshot\n' % (__file__)
+
+    # get pre_info_project_id -> get pre_build_project_id
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project)
+    pre_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    query = "SELECT id FROM build_project WHERE info_project_id = %s"
+    query_data = (pre_info_project_id)
+    pre_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] pre_info_project_id(%s), pre_build_project_id(%s)\n' \
+    #      % (__file__, pre_info_project_id, pre_build_project_id)
+
+    ### for build_snapshot
+    query = "INSERT INTO build_snapshot (build_project_id, start_time, status) " \
+            "VALUES(%s, %s, %s)"
+    query_data = (pre_build_project_id, bm_start_datetime, 'R')
+    buildmonitor_db.do_query(query, query_data)
+
+def create_snapshot_packages_for_build_snapshot_package(project, bm_repo, bm_arch,
+                                                        bm_pkg_url,
+                                                        bm_pkg_name_lst,
+                                                        bm_pkg_mdate_lst,
+                                                        bm_pkg_size_lst):
+    print '[%s] enter create_snapshot_packages_for_build_snapshot_package\n' % (__file__)
+
+    # get pre_info_project_id -> get pre_build_project_id
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project)
+    pre_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    query = "SELECT id FROM build_project WHERE info_project_id = %s"
+    query_data = (pre_info_project_id)
+    pre_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] pre_info_project_id(%s), pre_build_project_id(%s)\n' \
+    #      % (__file__, pre_info_project_id, pre_build_project_id)
+
+    # get curr_build_snapshot_id
+    query = "SELECT id FROM build_snapshot WHERE build_project_id = %s"
+    query_data = (pre_build_project_id)
+    curr_build_snapshot_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] curr_build_snapshot_id(%s)\n' % (__file__, curr_build_snapshot_id)
+
+    for each_pkg_name, each_pkg_mdate, each_pkg_size in zip(bm_pkg_name_lst, bm_pkg_mdate_lst, bm_pkg_size_lst):
+        timestamp = datetime.datetime.fromtimestamp(each_pkg_mdate)
+        #print '[%s] each_pkg_name(%s), timestamp(%s), each_pkg_size(%s)\n' \
+        #      % (__file__, each_pkg_name, timestamp, each_pkg_size)
+        query = "INSERT INTO build_snapshot_package (build_snapshot_id, repository, " \
+                "arch, package_name, created_date, package_size, package_url) " \
+                "VALUES(%s, %s, %s, %s, %s, %s, %s)"
+        query_data = (curr_build_snapshot_id, bm_repo, bm_arch, each_pkg_name,
+                      timestamp, each_pkg_size, bm_pkg_url)
+        buildmonitor_db.do_query(query, query_data)
+
+def end_pre_create_snapshot_for_sr_stage(project, bm_git_tag,
+                                         bm_start_datetime, bm_end_datetime):
+    print '[%s] enter end_pre_create_snapshot_for_sr_stage\n' % (__file__)
+
+    # get curr_sr_status_id
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (bm_git_tag)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get curr_info_project_id -> get curr_build_project_id for multi profile
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project)
+    curr_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    query = "SELECT id FROM build_project WHERE info_project_id = %s"
+    query_data = (curr_info_project_id)
+    curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    ### [3] stage end : [pre] snapshot creation
+    info_stage_id = 3
+    query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
+            "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+    query_data = (bm_end_datetime, 'S', curr_sr_status_id,
+                  info_stage_id, curr_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+    ### [4] stage start : [pre] image creation
+    info_stage_id = 4
+    query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
+            "stage_status, build_project_id) VALUES(%s, %s, %s, %s, %s)"
+    query_data = (curr_sr_status_id, info_stage_id, bm_end_datetime,
+                  'R', curr_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+def end_pre_create_snapshot_for_build_snapshot(project, bm_snapshot_name,
+                                               bm_snapshot_url, bm_end_datetime):
+    print '[%s] enter end_pre_create_snapshot_for_build_snapshot\n' % (__file__)
+
+    # get pre_info_project_id -> get pre_build_project_id
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project)
+    pre_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    query = "SELECT id FROM build_project WHERE info_project_id = %s"
+    query_data = (pre_info_project_id)
+    pre_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] pre_info_project_id(%s), pre_build_project_id(%s)\n' \
+    #      % (__file__, pre_info_project_id, pre_build_project_id)
+
+    ### for build_snapshot
+    query = "UPDATE build_snapshot SET snapshot_name = %s, snapshot_url = %s, " \
+            "end_time = %s, status = %s WHERE build_project_id = %s"
+    query_data = (bm_snapshot_name, bm_snapshot_url, bm_end_datetime,
+                  'S', pre_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+#===============================================================================
+# [job_imager.py]
+
+def update_fail_create_image_for_sr_stage(fields, bm_start_datetime):
+    print '[%s] enter update_fail_create_image_for_sr_stage\n' % (__file__)
+
+    bm_prj_name = fields["project"]
+    bm_split_data = fields["project"].split(':')[-1]
+    bm_git_tag = 'submit/tizen/' + bm_split_data
+    bm_url = os.path.join(fields.get('url_pub_base', ''),
+                           fields['repo_path'], fields['images_path'])
+    #print '[%s] bm_prj_name(%s), bm_split_data(%s), bm_git_tag(%s), bm_url(%s)\n' \
+    #      % (__file__, bm_prj_name, bm_split_data, bm_git_tag, bm_url)
+
+    bm_end_datetime = datetime.datetime.now()
+
+    #if 'prerelease' in bm_url:
+    if not ((bm_url.find("prerelease")) == -1):
+
+        # [pre_build] get current_sr_status_id
+        query = "SELECT id FROM sr_status WHERE sr = %s"
+        query_data = (bm_git_tag)
+        curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        #print '[%s][pre_build] info_stage_id(%s), query_data(%s), curr_sr_status_id(%s)\n' \
+        #      % (__file__, info_stage_id, query_data, curr_sr_status_id)
+
+        # get curr_info_project_id -> get curr_build_project_id for multi profile
+        query = "SELECT id FROM info_project WHERE project_name = %s"
+        query_data = (bm_prj_name)
+        curr_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        query = "SELECT id FROM build_project WHERE info_project_id = %s"
+        query_data = (curr_info_project_id)
+        curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+        ### [4] stage : update fail status for [pre] image creation
+        info_stage_id = 4
+        query = "UPDATE sr_stage SET stage_start_time = %s, stage_end_time = %s, stage_status = %s " \
+                "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (bm_start_datetime, bm_end_datetime, 'F',
+                      curr_sr_status_id, info_stage_id, curr_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+    else:
+        # get post_info_project_id -> get post_build_project_id
+        query = "SELECT id FROM info_project WHERE project_name = %s"
+        query_data = (bm_prj_name)
+        post_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        query = "SELECT id FROM build_project " \
+                "WHERE info_project_id = %s ORDER BY id desc LIMIT 1"
+        query_data = (post_info_project_id)
+        post_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+        # get curr_sr_status_id
+        query = "SELECT sr_status_id FROM sr_status_detail WHERE post_build_project_id = %s"
+        query_data = (post_build_project_id)
+        curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        #print '[%s] curr_sr_status_id(%s)\n' % (__file__, curr_sr_status_id)
+
+        ### [8] stage : update fail status for [post] image creation
+        info_stage_id = 8
+        query = "UPDATE sr_stage SET stage_start_time = %s, stage_end_time = %s, stage_status = %s " \
+                "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (bm_start_datetime, bm_end_datetime, 'F',
+                      curr_sr_status_id, info_stage_id, post_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+def create_image_for_build_image(fields, bm_start_datetime,
+                                 bm_end_datetime, build_id):
+    print '[%s] enter create_image_for_build_image\n' % (__file__)
+
+    bm_repository = fields['repo']
+    bm_device_name = fields['name']
+    bm_status = fields['status']
+    bm_url = fields['url']
+    #print '[%s] bm_repository(%s), bm_device_name(%s), bm_status(%s), bm_url(%s)\n' \
+    #      % (__file__, bm_repository, bm_device_name, bm_status, bm_url)
+
+    bm_base_path = os.getenv('PATH_REPO_BASE')
+    bm_img_url = os.path.join(bm_base_path, fields['repo_path'], fields['images_path'])
+    bm_img_path = bm_img_url + '/' + build_id + '_' + bm_device_name + '.tar.gz'
+    bm_img_size = os.path.getsize(bm_img_path)
+    #print '[%s] bm_img_path(%s), bm_img_size(%s)\n' \
+    #      % (__file__, bm_img_path, bm_img_size)
+
+    # get curr_build_snapshot_id
+    query = "SELECT id FROM build_snapshot WHERE snapshot_name = %s"
+    query_data = (build_id)
+    curr_build_snapshot_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] curr_build_snapshot_id(%s)\n' % (__file__, curr_build_snapshot_id)
+
+    ### for build_image
+    query = "INSERT INTO build_image (build_snapshot_id, repository, device_name, " \
+            "start_time, end_time, status, image_size, image_url) " \
+            "VALUES(%s, %s, %s, %s, %s, %s, %s, %s)"
+    query_data = (curr_build_snapshot_id, bm_repository, bm_device_name,
+                  bm_start_datetime, bm_end_datetime,
+                  bm_status, bm_img_size, bm_url)
+    buildmonitor_db.do_query(query, query_data)
+
+#===============================================================================
+# [job_post_image.py]
+
+def end_create_image_for_sr_stage(bm_start_datetime, project):
+    print '[%s] enter end_create_image_for_sr_stage project(%s)\n' % (__file__, project)
+
+    if project.startswith("home:prerelease:"):
+        bm_end_datetime = datetime.datetime.now()
+        bm_git_tag = project.split(":")[-3] + '/' + project.split(":")[-2] + '/' + project.split(":")[-1]
+        #print '[%s] bm_git_tag(%s)\n' % (__file__, bm_git_tag)
+
+        # [pre_build] get current_sr_status_id
+        query = "SELECT id FROM sr_status WHERE sr = %s"
+        query_data = (bm_git_tag)
+        curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        #print '[%s][pre_build] query_data(%s), curr_sr_status_id(%s)\n' \
+        #      % (__file__, query_data, curr_sr_status_id)
+
+        # get curr_info_project_id -> get curr_build_project_id for multi profile
+        query = "SELECT id FROM info_project WHERE project_name = %s"
+        query_data = (project)
+        curr_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        query = "SELECT id FROM build_project WHERE info_project_id = %s"
+        query_data = (curr_info_project_id)
+        curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+        ### [4] stage : [pre] image creation
+        info_stage_id = 4
+        query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
+                "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (bm_end_datetime, 'S',
+                      curr_sr_status_id, info_stage_id, curr_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+#===============================================================================
+# [job_request.py]
+
+def sr_accept_for_sr_stage(bm_src_prj_name, bm_target_prj_name,
+                           bm_start_datetime, bm_end_datetime, bm_git_tag):
+    print '[%s] enter sr_accept_for_sr_stage\n' % (__file__)
+
+    # get current_sr_status_id
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (bm_git_tag)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] curr_sr_status_id(%s)\n' % (__file__, curr_sr_status_id)
+
+    # get curr_info_project_id -> get curr_build_project_id for multi profile
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (bm_src_prj_name)
+    curr_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    query = "SELECT id FROM build_project WHERE info_project_id = %s"
+    query_data = (curr_info_project_id)
+    curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    ### [5] stage : SR aceept
+    info_stage_id = 5
+    query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, " \
+            "stage_start_time, stage_end_time, stage_status, build_project_id) " \
+            "VALUES(%s, %s, %s, %s, %s, %s)"
+    query_data = (curr_sr_status_id, info_stage_id,
+                  bm_start_datetime, bm_end_datetime, 'S', curr_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+    # get curr_info_project_id -> get post_build_project_id for multi profile
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (bm_target_prj_name)
+    curr_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    query = "SELECT id FROM build_project " \
+            "WHERE info_project_id = %s ORDER BY id desc LIMIT 1"
+    query_data = (curr_info_project_id)
+    post_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    ### [6] stage start : [post] package build
+    info_stage_id = 6
+    query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, " \
+            "stage_start_time, stage_status, build_project_id) " \
+            "VALUES(%s, %s, %s, %s, %s)"
+    query_data = (curr_sr_status_id, info_stage_id, bm_start_datetime,
+                  'R', post_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+def sr_reject_for_sr_stage(bm_src_prj_name, bm_start_datetime,
+                           bm_end_datetime, bm_git_tag):
+    print '[%s] enter sr_reject_for_sr_stage\n' % (__file__)
+
+    # get curr_sr_status_id
+    query = "SELECT id FROM sr_status WHERE sr = %s"
+    query_data = (bm_git_tag)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] curr_sr_status_id(%s)\n' % (__file__, curr_sr_status_id)
+
+    # get curr_info_project_id -> get curr_build_project_id for multi profile
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (bm_src_prj_name)
+    curr_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    query = "SELECT id FROM build_project WHERE info_project_id = %s"
+    query_data = (curr_info_project_id)
+    curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    ### [5] stage : SR reject
+    info_stage_id = 5
+    query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
+            "stage_end_time, stage_status, build_project_id) " \
+            "VALUES(%s, %s, %s, %s, %s, %s)"
+    query_data = (curr_sr_status_id, info_stage_id, bm_start_datetime, bm_end_datetime,
+                  'F', curr_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+def sr_accept_reject_for_sr_status_detail(event_fields, bm_start_datetime,
+                                          bm_end_datetime, bm_git_tag):
+    print '[%s] enter sr_accept_reject_for_sr_status_detail\n' % (__file__)
+
+    obs_req_no = event_fields['id']
+    obs_req_comment = event_fields['comment']
+    obs_req_date = bm_end_datetime
+    obs_req_status = event_fields['state']
+    obs_req_status = obs_req_status.upper()
+    bm_src_prj_name = event_fields['sourceproject']
+    bm_target_prj_name = event_fields['targetproject']
+    #print '[%s] obs_req_no(%s), obs_req_comment(%s), obs_req_date(%s), obs_req_status(%s)\n' \
+    #      % (__file__, obs_req_no, obs_req_comment, obs_req_date, obs_req_status)
+    #print '[%s] bm_src_prj_name(%s), bm_target_prj_name(%s), bm_git_tag(%s)\n' \
+    #      % (__file__, bm_src_prj_name, bm_target_prj_name, bm_git_tag)
+
+    if obs_req_status == 'ACCEPTED':
+        print '[%s][ACCEPTED] obs_req_status(%s)\n' % (__file__, obs_req_status)
+
+        # get pre_info_project_id -> get pre_build_project_id
+        query = "SELECT id FROM info_project WHERE project_name = %s"
+        query_data = (bm_src_prj_name) # should use bm_src_prj_name
+        pre_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        query = "SELECT id FROM build_project WHERE info_project_id = %s"
+        query_data = (pre_info_project_id)
+        pre_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        #print '[%s] pre_info_project_id(%d), pre_build_project_id(%s)\n' \
+        #      % (__file__, pre_info_project_id, pre_build_project_id)
+
+        # get post_info_project_id -> get post_build_project_id
+        query = "SELECT id FROM info_project WHERE project_name = %s"
+        query_data = (bm_target_prj_name)
+        post_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        query = "SELECT id FROM build_project " \
+                "WHERE info_project_id = %s ORDER BY id desc LIMIT 1"
+        query_data = (post_info_project_id)
+        post_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        #print '[%s] post_info_project_id(%s), post_build_project_id(%s)\n' \
+        #      % (__file__, post_info_project_id, post_build_project_id)
+
+        ### for sr_status_detail
+        query = "UPDATE sr_status_detail SET post_build_project_id = %s, obs_request_no = %s, " \
+                "obs_request_comment = %s, obs_request_date = %s, obs_request_status = %s " \
+                "WHERE pre_build_project_id = %s"
+        query_data = (post_build_project_id, obs_req_no, obs_req_comment,
+                      obs_req_date, obs_req_status, pre_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+        ### for sr_stage (now can find the build_project_id of the target prj)
+        sr_accept_for_sr_stage(bm_src_prj_name, bm_target_prj_name,
+                               bm_start_datetime, bm_end_datetime, bm_git_tag)
+
+    elif obs_req_status == 'REVOKED' or obs_req_status == 'DECLINED':
+        print '[%s][REVOKED or DECLINED] obs_req_status(%s)\n' \
+              % (__file__, obs_req_status)
+
+        # get info_project_id -> get pre_build_project_id
+        query = "SELECT id FROM info_project WHERE project_name = %s"
+        query_data = (bm_src_prj_name)
+        info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+        query = "SELECT id FROM build_project WHERE info_project_id = %s"
+        query_data = (info_project_id)
+        pre_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+        ### for sr_status_detail
+        query = "UPDATE sr_status_detail SET obs_request_no = %s, " \
+                "obs_request_comment = %s, obs_request_date = %s, obs_request_status = %s " \
+                "WHERE pre_build_project_id = %s"
+        query_data = (obs_req_no, obs_req_comment, obs_req_date,
+                      obs_req_status, pre_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+        ### for sr_stage
+        sr_reject_for_sr_stage(bm_src_prj_name, bm_start_datetime,
+                               bm_end_datetime, bm_git_tag)
+
+#===============================================================================
+# [job_create_snapshot.py]
+
+def update_fail_create_snapshot_for_sr_stage(project):
+    print '[%s] enter update_fail_create_snapshot_for_sr_stage\n' % (__file__)
+
+    # get post_info_project_id
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project) # Tizen:Mobile
+    post_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get post_build_project_id
+    query = "SELECT id FROM build_project " \
+            "WHERE info_project_id = %s ORDER BY id desc LIMIT 1"
+    query_data = (post_info_project_id)
+    post_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get curr_sr_status_id
+    query = "SELECT sr_status_id FROM sr_status_detail WHERE post_build_project_id = %s"
+    query_data = (post_build_project_id)
+    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] post_info_project_id(%s), post_build_project_id(%d), curr_sr_status_id(%s)\n' \
+    #      % (__file__, post_info_project_id, post_build_project_id, curr_sr_status_id)
+
+    ### [7] stage : update fail status when failed
+    bm_start_datetime = bm_end_datetime = datetime.datetime.now()
+    query = "UPDATE sr_stage SET stage_start_time = %s, stage_end_time = %s, stage_status = %s " \
+            "WHERE sr_status_id = %s AND build_project_id = %s"
+    query_data = (bm_start_datetime, bm_end_datetime, 'F',
+                  curr_sr_status_id, post_build_project_id)
+    buildmonitor_db.do_query(query, query_data)
+
+def start_create_snapshot_for_sr_stage(project, bm_start_datetime):
+    print '[%s] enter start_create_snapshot_for_sr_stage\n' % (__file__)
+
+    # get post_info_project_id
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project) # Tizen:Mobile
+    post_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get post_build_project_id
+    query = "SELECT id FROM build_project " \
+            "WHERE info_project_id = %s ORDER BY id desc LIMIT 1"
+    query_data = (post_info_project_id)
+    post_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get multi_sr_status_id
+    query = "SELECT sr_status_id FROM sr_status_detail WHERE post_build_project_id = %s"
+    query_data = (post_build_project_id)
+    multi_sr_status_id = buildmonitor_db.get_multi_values_from_query_data(query, query_data)
+    #print '[%s] post_info_project_id(%s), post_build_project_id(%d), multi_sr_status_id(%s)\n' \
+    #      % (__file__, post_info_project_id, post_build_project_id, multi_sr_status_id)
+
+    ### [6] end / [7/8] start : [post] snapshot creation
+    for each_sr_status_id in multi_sr_status_id:
+        print '[%s] each_sr_status_id(%s)\n' % (__file__, each_sr_status_id)
+        info_stage_id = 6
+        bm_end_datetime = datetime.datetime.now()
+        query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
+                "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (bm_end_datetime, 'S',
+                      each_sr_status_id[0], info_stage_id, post_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+        info_stage_id = 7
+        query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, " \
+                "stage_start_time, stage_end_time, stage_status, build_project_id) " \
+                "VALUES(%s, %s, %s, %s, %s, %s)"
+        query_data = (each_sr_status_id[0], info_stage_id,
+                      bm_start_datetime, bm_end_datetime, 'R', post_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+        info_stage_id = 8
+        query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, " \
+                "stage_start_time, stage_end_time, stage_status, build_project_id) " \
+                "VALUES(%s, %s, %s, %s, %s, %s)"
+        query_data = (each_sr_status_id[0], info_stage_id,
+                      bm_start_datetime, bm_end_datetime, 'R', post_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+def start_create_snapshot_for_post_build_snapshot(project, bm_snapshot_name,
+                                                  bm_start_datetime):
+    print '[%s] enter start_create_snapshot_for_post_build_snapshot\n' % (__file__)
+
+    # get post_info_project_id
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project)
+    post_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get post_build_project_id
+    query = "SELECT id FROM build_project " \
+            "WHERE info_project_id = %s ORDER BY id desc LIMIT 1"
+    query_data = (post_info_project_id)
+    post_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] post_info_project_id(%s), post_build_project_id(%d)\n' \
+    #      % (__file__, post_info_project_id, post_build_project_id)
+
+    # insert new post_build_project_id
+    query = "INSERT INTO build_snapshot (build_project_id, snapshot_name, " \
+            "start_time, status) VALUES(%s, %s, %s, %s)"
+    query_data = (post_build_project_id, bm_snapshot_name, bm_start_datetime, 'R')
+    buildmonitor_db.do_query(query, query_data)
+
+def create_snapshot_packages_for_post_build_snapshot_package(project, bm_repo, bm_arch,
+                                                             bm_pkg_url,
+                                                             bm_pkg_name_lst,
+                                                             bm_pkg_mdate_lst,
+                                                             bm_pkg_size_lst):
+    print '[%s] enter create_snapshot_packages_for_post_build_snapshot_package\n' % (__file__)
+
+    # get post_info_project_id
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project)
+    post_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] post_info_project_id (%s)\n' % (__file__, post_info_project_id)
+
+    # get post_build_project_id
+    query = "SELECT id FROM build_project " \
+            "WHERE info_project_id = %s ORDER BY id desc LIMIT 1"
+    query_data = (post_info_project_id)
+    build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get curr_build_snapshot_id
+    query = "SELECT id FROM build_snapshot WHERE build_project_id = %s"
+    query_data = (build_project_id)
+    curr_build_snapshot_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    for each_pkg_name, each_pkg_mdate, each_pkg_size in zip(bm_pkg_name_lst, bm_pkg_mdate_lst, bm_pkg_size_lst):
+        timestamp = datetime.datetime.fromtimestamp(each_pkg_mdate)
+        # post build
+        #print '[%s] curr_build_snapshot_id(%s), each_pkg_name(%s), timestamp(%s), each_pkg_size(%s)\n' \
+        #      % (__file__, curr_build_snapshot_id, each_pkg_name, timestamp, each_pkg_size)
+        query = "INSERT INTO build_snapshot_package (build_snapshot_id, repository, arch, " \
+                "package_name, created_date, package_size, package_url) " \
+                "VALUES(%s, %s, %s, %s, %s, %s, %s)"
+        query_data = (curr_build_snapshot_id, bm_repo, bm_arch,
+                      each_pkg_name, timestamp, each_pkg_size, bm_pkg_url)
+        buildmonitor_db.do_query(query, query_data)
+
+def end_create_snapshot_create_images_for_sr_stage(project, bm_start_datetime,
+                                                   bm_end_datetime):
+    print '[%s] enter end_create_snapshot_create_images_for_sr_stage\n' % (__file__)
+
+    ### [7/8/9] end : [post] snapshot creation / [post] image creation / Completed
+    # get post_info_project_id
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project) # Tizen:Mobile
+    post_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get post_build_project_id
+    query = "SELECT id FROM build_project " \
+            "WHERE info_project_id = %s ORDER BY id desc LIMIT 1"
+    query_data = (post_info_project_id)
+    post_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get multi_sr_status_id
+    query = "SELECT sr_status_id FROM sr_status_detail WHERE post_build_project_id = %s"
+    query_data = (post_build_project_id)
+    multi_sr_status_id = buildmonitor_db.get_multi_values_from_query_data(query, query_data)
+    #print '[%s] post_info_project_id(%s), post_build_project_id(%d), multi_sr_status_id(%s)\n' \
+    #      % (__file__, post_info_project_id, post_build_project_id, multi_sr_status_id)
+
+    for each_sr_status_id in multi_sr_status_id:
+        print '[%s] each_sr_status_id(%s)\n' % (__file__, each_sr_status_id)
+
+        # change the state_status of previous stage from 'R' to 'S'
+        info_stage_id = 7
+        query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
+                "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (bm_end_datetime, 'S',
+                      each_sr_status_id[0], info_stage_id, post_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+        info_stage_id = 8
+        query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
+                "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (bm_end_datetime, 'S',
+                      each_sr_status_id[0], info_stage_id, post_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+        info_stage_id = 9
+        bm_start_datetime = datetime.datetime.now()
+        query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, " \
+                "stage_start_time, stage_end_time, stage_status, build_project_id) " \
+                "VALUES(%s, %s, %s, %s, %s, %s)"
+        query_data = (each_sr_status_id[0], info_stage_id,
+                      bm_start_datetime, bm_end_datetime, 'S', post_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+def end_create_snapshot_for_post_build_snapshot(project, bm_start_datetime,
+                                                bm_end_datetime, bm_snapshot_url,
+                                                bm_snapshot_name):
+    print '[%s] enter end_create_snapshot_for_post_build_snapshot\n' % (__file__)
+
+    # get post_info_project_id
+    query = "SELECT id FROM info_project WHERE project_name = %s"
+    query_data = (project)
+    post_info_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+    # get post_build_project_id
+    query = "SELECT id FROM build_project " \
+            "WHERE info_project_id = %s ORDER BY id desc LIMIT 1"
+    query_data = (post_info_project_id)
+    post_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+    #print '[%s] post_info_project_id(%s), post_build_project_id(%d)\n' \
+    #      % (__file__, post_info_project_id, post_build_project_id)
+
+    # insert new post_build_project_id
+    query = "UPDATE build_snapshot SET snapshot_url = %s, " \
+            "end_time = %s, status = %s WHERE snapshot_name = %s"
+    query_data = (bm_snapshot_url, bm_end_datetime, 'S', bm_snapshot_name)
+    buildmonitor_db.do_query(query, query_data)
+#==================================================================================
+
+def main():
+    """
+    Script entry point.
+    """
+    bm_connect_db()
+    content = trigger_info(os.getenv('TRIGGER_INFO'))
+    bm_stage = content.get("bm_stage")
+
+    #=======================================================
+    # Submit
+    if bm_stage == 'Submit':
+        print '[%s][Submit]\n' % (__file__)
+        # get vars
+        commit_date = content.get("commit_date")
+        commit_msg = content.get("commit_msg")
+        submit_date = content.get("submit_date")
+        submit_msg = content.get("submit_msg")
+        submitter = content.get("submitter")
+        git_tag = content.get("git_tag")
+        gerrit_project = content.get("gerrit_project")
+        gerrit_newrev = content.get("gerrit_newrev")
+        gerrit_account_name = content.get("gerrit_account_name")
+        bm_start_datetime = content.get("bm_start_datetime")
+        bm_end_datetime = content.get("bm_end_datetime")
+        bm_src_project_lst = content.get("bm_src_project_lst")
+
+        # func call
+        ### sr_status -> sr_commit -> sr_stage & sr_status_detail
+        sr_submit_for_sr_status(git_tag)
+        sr_submit_for_sr_commit(commit_date, commit_msg, submit_date, submit_msg,
+                                submitter, git_tag, gerrit_project,
+                                gerrit_newrev, gerrit_account_name)
+        package_build_for_sr_detail_sr_stage(git_tag, bm_start_datetime,
+                                             bm_end_datetime,
+                                             bm_src_project_lst)
+    #=======================================================
+    # [PRE] Build
+    #=======================================================
+    # [PRE] Snap
+    elif bm_stage == 'Pre_Snap_Start':
+        print '[%s][Pre_Snap_Start]\n' % (__file__)
+        # get vars
+        project = content.get("project")
+        bm_git_tag = content.get("bm_git_tag")
+        bm_start_datetime = content.get("bm_start_datetime")
+        # func call
+        start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetime) # move to job_dispacher
+        start_pre_create_snapshot_for_build_snapshot(project, bm_start_datetime)
+    elif bm_stage == 'Pre_Snap_End':
+        print '[%s][Pre_Snap_End]\n' % (__file__)
+        # get vars
+        project = content.get("project")
+        bm_git_tag = content.get("bm_git_tag")
+        bm_start_datetime = bm_end_datetime = datetime.datetime.now()
+        bm_snapshot_name = content.get("bm_snapshot_name")
+        bm_snapshot_url = content.get("bm_snapshot_url")
+
+        # func call
+        end_pre_create_snapshot_for_sr_stage(project, bm_git_tag,
+                                                      bm_start_datetime,
+                                                      bm_end_datetime)
+        end_pre_create_snapshot_for_build_snapshot(project,
+                                                   bm_snapshot_name,
+                                                   bm_snapshot_url,
+                                                   bm_end_datetime)
+
+    elif bm_stage == 'Pre_Snap_packages':
+        print '[%s][Pre_Snap_Fail]\n' % (__file__)
+        # get vars
+        project = content.get("project")
+        bm_repo = content.get("bm_repo")
+        bm_arch = content.get("bm_arch")
+        bm_pkg_url = content.get("bm_pkg_url")
+        bm_pkg_name_lst = content.get("bm_pkg_name_lst")
+        bm_pkg_mdate_lst = content.get("bm_pkg_mdate_lst")
+        bm_pkg_size_lst = content.get("bm_pkg_size_lst")
+        # func call
+        create_snapshot_packages_for_build_snapshot_package(project, bm_repo, bm_arch,
+                                                            bm_pkg_url,
+                                                            bm_pkg_name_lst,
+                                                            bm_pkg_mdate_lst,
+                                                            bm_pkg_size_lst)
+
+    elif bm_stage == 'Pre_Snap_Fail':
+        print '[%s][Pre_Snap_Fail]\n' % (__file__)
+        # get vars
+        project = content.get("project")
+        bm_git_tag = content.get("bm_git_tag")
+        # func call
+        update_fail_status_for_sr_stage(project, bm_git_tag)
+    #=======================================================
+    # [PRE] Image
+    #elif bm_stage == 'Pre_Image':
+    elif bm_stage == 'Image':
+        print '[%s][Image]\n' % (__file__)
+        # get vars
+        image_status = content.get("status")
+        fields = content.get("fields")
+        bm_start_datetime  = content.get("bm_start_datetime")
+        bm_end_datetime = content.get("bm_end_datetime")
+        build_id = content.get("build_id")
+        #print '[HSH][%s] fields(%s), bm_start_datetime(%s), build_id(%s)\n' \
+        #      % (__file__, fields, bm_start_datetime, build_id)
+
+        # func call
+        if image_status == 'success':
+            create_image_for_build_image(fields, bm_start_datetime,
+                                         bm_end_datetime, build_id)
+        elif image_status == 'failed':
+            update_fail_create_image_for_sr_stage(fields, bm_start_datetime)
+    elif bm_stage == 'Post_Image':
+        print '[%s][Post_Image]\n' % (__file__)
+        # get vars
+        bm_start_datetime = content.get("bm_start_datetime")
+        project = content.get("project")
+        # func call
+        end_create_image_for_sr_stage(bm_start_datetime, project)
+    # SR Accept or Reject
+    elif bm_stage == 'SR_Accept':
+        print '[%s][SR_Accept]\n' % (__file__)
+        # get vars
+        event_fields = content.get("event_fields")
+        bm_start_datetime = content.get("bm_start_datetime")
+        bm_end_datetime = content.get("bm_end_datetime")
+        bm_git_tag = content.get("bm_git_tag")
+        # func call
+        sr_accept_reject_for_sr_status_detail(event_fields, bm_start_datetime,
+                                              bm_end_datetime, bm_git_tag)
+    #=======================================================
+    # [POST] Build
+    #=======================================================
+    # [POST] Snap
+    elif bm_stage == 'Post_Snap_Start':
+        print '[%s][Post_Snap_Start]\n' % (__file__)
+        # get vars
+        project = content.get("project")
+        bm_start_datetime = content.get("bm_start_datetime")
+        # func call
+        start_create_snapshot_for_sr_stage(project, bm_start_datetime)
+    elif bm_stage == 'Post_Snap_snapshot':
+        print '[%s][Post_Snap_snapshot]\n' % (__file__)
+        project = content.get("project")
+        bm_snapshot_name = content.get("bm_snapshot_name")
+        bm_start_datetime = content.get("bm_start_datetime")
+        start_create_snapshot_for_post_build_snapshot(project,
+                                                      bm_snapshot_name,
+                                                      bm_start_datetime)
+    elif bm_stage == 'Post_Snap_packages':
+        print '[%s][Post_Snap_packages]\n' % (__file__)
+        # get vars
+        repo = content.get("repo")
+        project = content.get("project")
+        bm_repo = content.get("bm_repo")
+        bm_arch = content.get("bm_arch")
+        bm_pkg_url = content.get("bm_pkg_url")
+        bm_pkg_name_lst = content.get("bm_pkg_name_lst")
+        bm_pkg_mdate_lst = content.get("bm_pkg_mdate_lst")
+        bm_pkg_size_lst = content.get("bm_pkg_size_lst")
+        # func call
+        create_snapshot_packages_for_post_build_snapshot_package(repo,
+                                                                 project,
+                                                                 bm_repo,
+                                                                 bm_arch,
+                                                                 bm_pkg_url,
+                                                                 bm_pkg_name_lst,
+                                                                 bm_pkg_mdate_lst,
+                                                                 bm_pkg_size_lst)
+    elif bm_stage == 'Post_Snap_End':
+        print '[%s][Post_Snap_End]\n' % (__file__)
+        # get vars
+        project = content.get("project")
+        bm_start_datetime = content.get("bm_start_datetime")
+        bm_end_datetime = content.get("bm_end_datetime")
+        bm_snapshot_url = content.get("bm_snapshot_url")
+        repo_data_build_id = content.get("repo_data_build_id")
+
+        # func call
+        # for sr_stage & build_snapshot
+        end_create_snapshot_create_images_for_sr_stage(project,
+                                                       bm_start_datetime,
+                                                       bm_end_datetime)
+        end_create_snapshot_for_post_build_snapshot(project,
+                                                    bm_start_datetime,
+                                                    bm_end_datetime,
+                                                    bm_snapshot_url,
+                                                    repo_data_build_id)
+    elif bm_stage == 'Post_Snap_Fail':
+        print '[%s][Post_Snap_Fail]\n' % (__file__)
+        # get vars
+        bm_project = content.get("bm_project")
+        # func call
+        update_fail_create_snapshot_for_sr_stage(bm_project)
+    #=======================================================
+    # [POST] Image / Post_Image
+    #=======================================================
+    #else:
+    #    print 'no bm_stage\n'
+
+    #bm_disconnect_db()
+    '''
+    elif bm_stage == 'Post_Snap':
+        print 'Post_Snap\n'
+        bm_stage_func = content.get("bm_stage_func")
+        if bm_stage_func == 'update_fail_create_snapshot_for_sr_stage'
+            print 'update_fail_create_snapshot_for_sr_stage\n'
+        elif bm_stage_func == 'start_create_snapshot_for_post_build_snapshot'
+            print 'start_create_snapshot_for_post_build_snapshot\n'
+        elif bm_stage_func == 'create_snapshot_packages_for_post_build_snapshot_package'
+            print 'create_snapshot_packages_for_post_build_snapshot_package\n'
+        elif bm_stage_func == 'start_create_snapshot_for_sr_stage'
+            print 'start_create_snapshot_for_sr_stage\n'
+        elif bm_stage_func == 'end_create_snapshot_create_images_for_sr_stage'
+            print 'end_create_snapshot_create_images_for_sr_stage\n'
+        else
+            print 'else\n'
+    '''
+
+if __name__ == '__main__':
+    try:
+        #sys.exit(main(os.path.basename(sys.argv[1])))
+        sys.exit(main())
+    except LocalError, err:
+        print err
+        #print '[HSH] except!!\n'
+        #bm_disconnect_db()
+        sys.exit(1)
index 0d403f8..9ba2eb1 100755 (executable)
@@ -32,7 +32,6 @@ from common.repomaker import RepoMaker, RepoMakerError
 from common.backenddb import BackendDB
 from common.snapshot import Snapshot, SnapshotError, snapshot_project_enabled
 from common.utils import make_latest_link
-from common import buildmonitor
 
 class LocalError(Exception):
     """Local error exception."""
@@ -115,9 +114,17 @@ def make_repo(project, backenddb, base_path, live_repo_base):
 
     if buildmonitor_enabled:
         bm_snapshot_name = snapshot.build_id
-        buildmonitor.start_create_snapshot_for_post_build_snapshot(project,
-                                                                   bm_snapshot_name,
-                                                                   bm_start_datetime)
+        #buildmonitor.start_create_snapshot_for_post_build_snapshot(project,
+        #                                                           bm_snapshot_name,
+        #                                                           bm_start_datetime)
+        bm_data = {"bm_stage" : 'Post_Snap_snapshot',
+                   "bm_stage_func" : 'start_create_snapshot_for_post_build_snapshot',
+                   "project" : project,
+                   "bm_snapshot_name" : bm_snapshot_name,
+                   "bm_start_datetime" : str(bm_start_datetime)
+                  }
+        trigger_next("BUILD-MONITOR", bm_data)
+
     # Convert live repo to download structure
     for repo in targets:
         repomaker = RepoMaker(snapshot.build_id, snapshot.path)
@@ -139,7 +146,13 @@ def make_repo(project, backenddb, base_path, live_repo_base):
         if not repomaker.imagedata:
             if buildmonitor_enabled:
                 print '[%s][LocalError] bm_project(%s)\n' % (__file__, bm_project)
-                buildmonitor.update_fail_create_snapshot_for_sr_stage(bm_project)
+                #buildmonitor.update_fail_create_snapshot_for_sr_stage(bm_project)
+                bm_data = {"bm_stage" : 'Post_Snap_Fail',
+                           "bm_stage_func" : 'update_fail_create_snapshot_for_sr_stage',
+                           "bm_project" : bm_project
+                          }
+                trigger_next("BUILD-MONITOR", bm_data)
+
             raise LocalError("Image configuration not found in %s" %
                               snapshot.path)
 
@@ -147,12 +160,59 @@ def make_repo(project, backenddb, base_path, live_repo_base):
         imagedatas[repo['Name']] = repomaker.imagedata
 
         if buildmonitor_enabled:
-            buildmonitor.create_snapshot_packages_for_post_build_snapshot_package(repo,
-                                                                                  project,
-                                                                                  repo['Name'],
-                                                                                  repo['Architectures'][0],
-                                                                                  base_path,
-                                                                                  snapshot)
+            bm_repo = repo['Name']             # emul32-wayland / emul64-wayland / arm-wayland / arm64-wayland / target-TM1
+            bm_arch = repo['Architectures'][0] # ia32 / x86_64 / armv7l / aarch64 / armv7l
+            if bm_arch == 'ia32':
+                bm_arch = 'i686'
+
+            bm_repo_dir = os.path.join(snapshot.path, "repos", bm_repo, "packages")
+            #print '[%s] snapshot.path(%s), bm_repo(%s), bm_arch(%s)\n' \
+            #      % (__file__, snapshot.path, bm_repo, bm_arch)
+            #print '[%s] bm_repo_dir(%s), os.listdir(bm_repo_dir)(%s)\n' \
+            #      % (__file__, bm_repo_dir, os.listdir(bm_repo_dir))
+
+            bm_base_url = os.getenv("URL_PUBLIC_REPO_BASE")
+            bm_pkg_url = bm_repo_dir.replace(base_path, bm_base_url)
+            #print '[%s] bm_base_url(%s), base_path(%s), bm_pkg_url(%s)\n' \
+            #      % (__file__, bm_base_url, base_path, bm_pkg_url)
+
+            # get rpm files
+            bm_pkg_name_lst = []
+            bm_pkg_mdate_lst = []
+            bm_pkg_size_lst = []
+            for root, dirs, files in os.walk(bm_repo_dir):
+                #print '[%s] root(%s), dirs(%s), files(%s)\n' % (__file__, root, dirs, files)
+                for each_file in files:
+                    if each_file.endswith(".rpm"):
+                        rpm_file_path = os.path.join(root, each_file)
+                        rpm_file_mdate = os.path.getmtime(rpm_file_path)
+                        rpm_file_size = os.path.getsize(rpm_file_path)
+                        bm_pkg_name_lst.append(each_file)
+                        bm_pkg_mdate_lst.append(rpm_file_mdate)
+                        bm_pkg_size_lst.append(rpm_file_size)
+                        # too much log
+                        #print '[%s] rpm_file_path(%s), rpm_file_mdate(%s), rpm_file_size(%s)\n' \
+                        #      % (__file__, rpm_file_path, rpm_file_mdate, rpm_file_size)
+
+
+            #buildmonitor.create_snapshot_packages_for_post_build_snapshot_package(repo,
+            #                                                                      project,
+            #                                                                      repo['Name'],
+            #                                                                      repo['Architectures'][0],
+            #                                                                      base_path,
+            #                                                                      snapshot)
+            bm_data = {"bm_stage" : 'Post_Snap_packages',
+                       "bm_stage_func" : 'create_snapshot_packages_for_post_build_snapshot_package',
+                       "project" : project,
+                       "bm_repo" : bm_repo,
+                       "bm_arch" : bm_arch,
+                       "bm_pkg_url" : bm_pkg_url,
+                       "bm_pkg_name_lst" : bm_pkg_name_lst,
+                       "bm_pkg_mdate_lst" : bm_pkg_mdate_lst,
+                       "bm_pkg_size_lst" : bm_pkg_size_lst,
+                      }
+            trigger_next("BUILD-MONITOR", bm_data)
+
         # Generate image info to builddata/ dir
         repomaker.gen_image_info()
 
@@ -183,7 +243,6 @@ def main():
         buildmonitor_skip = 1 # for exception case
         global bm_start_datetime
         bm_start_datetime = datetime.datetime.now()
-        buildmonitor.bm_connect_db()
 
     obs_api = os.getenv("OBS_API_URL")
     obs_user = os.getenv("OBS_API_USERNAME")
@@ -199,7 +258,13 @@ def main():
     if buildmonitor_enabled:
         global bm_project # for update_fail_xxx
         bm_project = project
-        buildmonitor.start_create_snapshot_for_sr_stage(project, bm_start_datetime)
+        #buildmonitor.start_create_snapshot_for_sr_stage(project, bm_start_datetime)
+        bm_data = {"bm_stage" : 'Post_Snap_Start',
+                   "bm_stage_func" : 'start_create_snapshot_for_sr_stage',
+                   "project" : project,
+                   "bm_start_datetime" : str(bm_start_datetime)
+                  }
+        trigger_next("BUILD-MONITOR", bm_data)
 
     build = BuildService(obs_api, obs_user, obs_passwd)
 
@@ -248,15 +313,24 @@ def main():
         else:
             bm_end_datetime = datetime.datetime.now()
             # for sr_stage & build_snapshot
-            buildmonitor.end_create_snapshot_create_images_for_sr_stage(project,
-                                                                        bm_start_datetime,
-                                                                        bm_end_datetime)
+            #buildmonitor.end_create_snapshot_create_images_for_sr_stage(project,
+            #                                                            bm_start_datetime,
+            #                                                            bm_end_datetime)
             bm_snapshot_url = os.path.join(base_url, repo_data['repo_path'])
-            buildmonitor.end_create_snapshot_for_post_build_snapshot(project,
-                                                                     bm_start_datetime,
-                                                                     bm_end_datetime,
-                                                                     bm_snapshot_url,
-                                                                     repo_data['build_id'])
+            #buildmonitor.end_create_snapshot_for_post_build_snapshot(project,
+            #                                                         bm_start_datetime,
+            #                                                         bm_end_datetime,
+            #                                                         bm_snapshot_url,
+            #                                                         repo_data['build_id'])
+            bm_data = {"bm_stage" : 'Post_Snap_End',
+                       "bm_stage_func" : 'end_create_snapshot_create_images_for_sr_stage',
+                       "project" : project,
+                       "bm_start_datetime" : str(bm_start_datetime),
+                       "bm_end_datetime" : str(bm_end_datetime),
+                       "bm_snapshot_url" : bm_snapshot_url,
+                       "repo_data_build_id" : repo_data['build_id']
+                      }
+            trigger_next("BUILD-MONITOR", bm_data)
 
 if __name__ == '__main__':
     try:
index 986e4f3..a0705bc 100755 (executable)
@@ -38,7 +38,6 @@ from random import randint
 
 from common.buildtrigger import trigger_info, trigger_next
 from common.utils import sync, set_permissions, Workdir
-from common import buildmonitor
 
 
 # Returns the list of baseurls from kickstart configuration.
@@ -209,7 +208,6 @@ def main():
     print 'buildmonitor_enabled(%s)\n' % (buildmonitor_enabled)
     if buildmonitor_enabled:
         bm_start_datetime = datetime.datetime.now()
-        buildmonitor.bm_connect_db()
 
     # Check if environment variables are set
     for var in ('WORKSPACE', 'IMG_SYNC_DEST_BASE'):
@@ -290,8 +288,6 @@ def main():
     if ret:
         print 'Error: mic returned %d' % ret
         status = 'failed'
-        if buildmonitor_enabled:
-            buildmonitor.update_fail_create_image_for_sr_stage(fields, bm_start_datetime)
 
     # sync image, logs to SYNC_DEST
     sync_dest = os.path.join(os.getenv('IMG_SYNC_DEST_BASE'),
@@ -337,14 +333,30 @@ def main():
         fields["status"] = status
         fields["url"] = url
         trigger_next("IMAGE-TESTING", fields)
+
+        if buildmonitor_enabled:
+            bm_end_datetime = datetime.datetime.now()
+            bm_data = {"bm_stage": 'Image',
+                       "status" : status,
+                       "fields" : fields,
+                       "bm_start_datetime" : str(bm_start_datetime),
+                       "bm_end_datetime" : str(bm_end_datetime),
+                       "build_id": build_id
+                      }
+            trigger_next("BUILD-MONITOR", bm_data)
     else:
+        if buildmonitor_enabled:
+            bm_end_datetime = datetime.datetime.now()
+            bm_data = {"bm_stage": 'Image',
+                       "status" : status,
+                       "fields" : fields,
+                       "bm_start_datetime": str(bm_start_datetime),
+                       "bm_end_datetime" : str(bm_end_datetime),
+                       "build_id": build_id
+                      }
+            trigger_next("BUILD-MONITOR", bm_data)
         return -1
 
-    if buildmonitor_enabled:
-        bm_end_datetime = datetime.datetime.now()
-        # for build_image
-        buildmonitor.create_image_for_build_image(fields, bm_start_datetime,
-                                                  bm_end_datetime, build_id)
 
 if __name__ == "__main__":
     sys.exit(main())
index 4d2e3b6..a8b9e09 100755 (executable)
@@ -27,7 +27,6 @@ from common.buildtrigger import trigger_info
 from common.buildservice import BuildService
 from common.prerelease import is_prerelease_project
 from common.iris_rest_client import IrisRestClient
-from common import buildmonitor
 
 def main():
     """The main body"""
@@ -35,7 +34,6 @@ def main():
     print 'buildmonitor_enabled(%s)\n' % (buildmonitor_enabled)
     if buildmonitor_enabled:
         bm_start_datetime = datetime.datetime.now()
-        buildmonitor.bm_connect_db()
 
     obs_api = os.getenv("OBS_API_URL")
     obs_user = os.getenv("OBS_API_USERNAME")
@@ -77,8 +75,13 @@ def main():
                 if len(saveinfo['images']) == saveinfo['images_count']:
                     print '[%s] last image(%s)\n' \
                           % (__file__, len(saveinfo['images']))
-                    buildmonitor.end_create_image_for_sr_stage(bm_start_datetime,
-                                                               project)
+                    #buildmonitor.end_create_image_for_sr_stage(bm_start_datetime,
+                    #                                           project)
+                    bm_data = {"bm_stage" : 'post_image',
+                               "bm_start_datetime" : str(bm_start_datetime),
+                               "project" : project,
+                              }
+                    trigger_next("BUILD-MONITOR", bm_data)
 
 if __name__ == "__main__":
     sys.exit(main())
index 735e993..9c39182 100755 (executable)
@@ -27,7 +27,6 @@ import re
 import shutil
 import base64
 import datetime
-from common import buildmonitor
 
 from common.buildtrigger import trigger_info, trigger_next
 from common.buildservice import BuildService
@@ -190,7 +189,13 @@ def make_repo(project, repo, backenddb, base_url, base_path,
             if not img_conf_list:
                 if buildmonitor_enabled:
                     print '[%s][LocalError] bm_git_tag(%s)\n' % (__file__, bm_git_tag)
-                    buildmonitor.update_fail_status_for_sr_stage(project, bm_git_tag)
+                    #buildmonitor.update_fail_status_for_sr_stage(project, bm_git_tag)
+                    bm_stage = 'Pre_Snap_Fail'
+                    bm_data = {"bm_stage": bm_stage,
+                               "bm_git_tag" : bm_git_tag,
+                              }
+                    trigger_next("BUILD-MONITOR-%s" % bm_stage, bm_data)
+
                 raise LocalError("Image configuration not found in %s" %
                         snapshot.path)
             for rpm in img_conf_list:
@@ -209,9 +214,48 @@ def make_repo(project, repo, backenddb, base_url, base_path,
             bm_pkg_urls_dic = prerelease.pkg_urls(repo['Name'])
             print '[%s] prerelease.pkg_urls(%s), base_path(%s)\n' \
                   % (__file__, bm_pkg_urls_dic, base_path)
-            buildmonitor.create_snapshot_packages_for_build_snapshot_package(project, bm_snapshot_name,
-                                                                             repo['Name'], repo['Architectures'][0],
-                                                                             bm_pkg_urls_dic, base_url, base_path)
+            bm_repo = repo['Name']             # emul32-wayland / emul64-wayland / arm-wayland / arm64-wayland / target-TM1
+            bm_arch = repo['Architectures'][0] # ia32 / x86_64 / armv7l / aarch64 / armv7l
+            bm_pkg_url = bm_pkg_urls_dic[bm_arch]
+            bm_pkg_dir = bm_pkg_url.replace(base_url, base_path) #http -> /srv/obs
+            #print '[%s] bm_arch(%s), os.listdir(bm_pkg_dir)(%s)\n' \
+            #      % (__file__, bm_arch, os.listdir(bm_pkg_dir))
+
+            if bm_arch == 'ia32':
+                bm_arch = 'i686'
+
+            # get rpm files
+            bm_pkg_name_lst = []
+            bm_pkg_mdate_lst = []
+            bm_pkg_size_lst = []
+            for root, dirs, files in os.walk(bm_pkg_dir):
+                for each_file in files:
+                    if each_file.endswith(".rpm"):
+                        rpm_file_path = root + '/' + each_file
+                        rpm_file_mdate = os.path.getmtime(rpm_file_path)
+                        rpm_file_size = os.path.getsize(rpm_file_path)
+                        bm_pkg_name_lst.append(each_file)
+                        bm_pkg_mdate_lst.append(rpm_file_mdate)
+                        bm_pkg_size_lst.append(rpm_file_size)
+                        #print '[%s] rpm_file_path(%s), rpm_file_mdate(%s), rpm_file_size(%s)\n' \
+                        #      % (__file__, rpm_file_path, rpm_file_mdate, rpm_file_size)
+
+            #buildmonitor.create_snapshot_packages_for_build_snapshot_package(project, bm_snapshot_name,
+            #                                                                 repo['Name'], repo['Architectures'][0],
+            #                                                                 bm_pkg_urls_dic, base_url, base_path)
+            bm_stage = 'Pre_Snap_packages'
+            bm_data = {"bm_stage" : bm_stage,
+                       "project" : project,
+                       "bm_repo" : bm_repo,
+                       "bm_arch" : bm_arch,
+                       "bm_pkg_url" : bm_pkg_url,
+                       "bm_pkg_name_lst" : bm_pkg_name_lst,
+                       "bm_pkg_mdate_lst" : bm_pkg_mdate_lst,
+                       "bm_pkg_size_lst" : bm_pkg_size_lst
+                      }
+            #trigger_next("BUILD-MONITOR", bm_data)
+            trigger_next("BUILD-MONITOR-%s" % bm_stage, bm_data)
+
         # Generate image info to builddata/ dir
         repomaker.gen_image_info(images_ks)
 
@@ -319,7 +363,6 @@ def main(action):
         bm_start_datetime = datetime.datetime.now()
         global bm_git_tag # for execption handling
         bm_git_tag = None
-        buildmonitor.bm_connect_db()
 
     obs_api = os.getenv("OBS_API_URL")
     obs_user = os.getenv("OBS_API_USERNAME")
@@ -343,8 +386,16 @@ def main(action):
 
         if buildmonitor_enabled:
             bm_git_tag = info['git_tag']
-            buildmonitor.start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetime)
-            buildmonitor.start_pre_create_snapshot_for_build_snapshot(project, bm_start_datetime)
+            #buildmonitor.start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetime)
+            #buildmonitor.start_pre_create_snapshot_for_build_snapshot(project, bm_start_datetime)
+            bm_stage = 'Pre_Snap_Start'
+            bm_data = {"bm_stage" : bm_stage,
+                       "project" : project,
+                       "bm_git_tag" : bm_git_tag,
+                       "bm_start_datetime": str(bm_start_datetime)
+                        }
+            #trigger_next("BUILD-MONITOR", bm_data)
+            trigger_next("BUILD-MONITOR-%s" % bm_stage, bm_data)
 
         buildstatus = build.getbuildstatus(project)
         print 'buildstatus=%s' %(buildstatus)
@@ -376,13 +427,24 @@ def main(action):
         #      % (__file__, project, bm_git_tag, bm_start_datetime, bm_end_datetime)
         bm_end_datetime = datetime.datetime.now()
         # for sr_stage & build_snapshot
-        buildmonitor.end_pre_create_snapshot_for_sr_stage(project, bm_git_tag,
-                                                          bm_start_datetime,
-                                                          bm_end_datetime)
-        buildmonitor.end_pre_create_snapshot_for_build_snapshot(project,
-                                                                bm_snapshot_name,
-                                                                bm_snapshot_url,
-                                                                bm_end_datetime)
+        #buildmonitor.end_pre_create_snapshot_for_sr_stage(project, bm_git_tag,
+        #                                                  bm_start_datetime,
+        #                                                  bm_end_datetime)
+        #buildmonitor.end_pre_create_snapshot_for_build_snapshot(project,
+        #                                                        bm_snapshot_name,
+        #                                                        bm_snapshot_url,
+        #                                                        bm_end_datetime)
+        bm_stage = 'Pre_Snap_End'
+        bm_data = {"bm_stage": bm_stage,
+                   "project" : project,
+                   "bm_git_tag": bm_git_tag,
+                   "bm_start_datetime": str(bm_start_datetime),
+                   "bm_end_datetime": str(bm_end_datetime),
+                   "bm_snapshot_name" : bm_snapshot_name,
+                   "bm_snapshot_url" : bm_snapshot_url,
+                    }
+        #trigger_next("BUILD-MONITOR", bm_data)
+        trigger_next("BUILD-MONITOR-%s" % bm_stage, bm_data)
 
 if __name__ == '__main__':
     try:
index d4ac5ef..4feffbf 100755 (executable)
@@ -35,7 +35,6 @@ import os
 import datetime
 import base64
 from xml.sax.saxutils import unescape
-from common import buildmonitor
 
 # set default char-set endcoding to utf-8
 reload(sys)
@@ -341,7 +340,6 @@ def main():
     print 'buildmonitor_enabled(%s)\n' % (buildmonitor_enabled)
     if buildmonitor_enabled:
         bm_start_datetime = datetime.datetime.now()
-        buildmonitor.bm_connect_db()
 
     event_fields = trigger_info(os.getenv('TRIGGER_INFO'))
 
@@ -434,10 +432,17 @@ def main():
 
     if buildmonitor_enabled and event_type != 'OBS_SRCSRV_REQUEST_STATECHANGE':
         bm_end_datetime = datetime.datetime.now()
-        buildmonitor.sr_accept_reject_for_sr_status_detail(event_fields,
-                                                           bm_start_datetime,
-                                                           bm_end_datetime,
-                                                           data["GIT_TAG"])
+        #buildmonitor.sr_accept_reject_for_sr_status_detail(event_fields,
+        #                                                   bm_start_datetime,
+        #                                                   bm_end_datetime,
+        #                                                   data["GIT_TAG"])
+        bm_data = {"bm_stage" : 'SR_Accept',
+                   "event_fields" : event_fields,
+                   "bm_start_datetime" : str(bm_start_datetime),
+                   "bm_end_datetime" : str(bm_end_datetime),
+                   "bm_git_tag" : data["GIT_TAG"],
+                  }
+        trigger_next("BUILD-MONITOR", bm_data)
 
     return 0
 
index ba3155a..25ffcb6 100755 (executable)
@@ -30,7 +30,6 @@ import xml.etree.cElementTree as ElementTree
 from xml.sax.saxutils import escape
 from time import sleep
 import datetime
-from common import buildmonitor
 
 from osc import core
 from gitbuildsys.errors import ObsError
@@ -479,7 +478,6 @@ def main(build_type):
     print 'buildmonitor_enabled(%s)\n' % (buildmonitor_enabled)
     if buildmonitor_enabled:
         bm_start_datetime = datetime.datetime.now()
-        buildmonitor.bm_connect_db()
 
     obs_api = os.getenv("OBS_API_URL")
     obs_user = os.getenv("OBS_API_USERNAME")
@@ -675,13 +673,40 @@ def main(build_type):
 
     if buildmonitor_enabled:
         bm_end_datetime = datetime.datetime.now()
+        commit_date, cd_err, cd_ret = mygit._git_inout('show', ['-s', '--format=%ci'])
+        commit_msg, cm_err, cm_ret = mygit._git_inout('show', ['-s', '--format=%s'])
+        submit_date, sd_err, sd_ret = mygit._git_inout('for-each-ref', \
+                    ['--count=1', '--sort=-taggerdate', '--format=%(taggerdate:iso)'])
+        submit_msg, sm_err, sm_ret = mygit._git_inout('for-each-ref', \
+                    ['--count=1', '--sort=-taggerdate', '--format=%(subject)'])
+        submitter, st_err, st_ret = mygit._git_inout('for-each-ref',\
+                    ['--count=1', '--sort=-taggerdate', '--format=%(taggeremail)'])
+        #print '[%s] %s%s' % (__file__, commit_date, commit_msg)
+        #print '[%s] %s%s%s' % (__file__, submit_date, submit_msg, submitter)
+
+        ### sr_status -> sr_commit -> sr_stage & sr_status_detail
+        #buildmonitor.sr_submit_for_sr_status(git_tag)
+        #buildmonitor.sr_submit_for_sr_commit(mygit, git_tag, gerrit_project,
+        #                                     gerrit_newrev, gerrit_account_name)
+        #buildmonitor.package_build_for_sr_detail_sr_stage(git_tag, bm_start_datetime,
+        #                                                  bm_end_datetime,
+        #                                                  submit_info['pre_created'])
+        bm_data = {"bm_stage": 'Submit',
+                   "commit_date" : commit_date,
+                   "commit_msg" : commit_msg,
+                   "submit_date" : submit_date,
+                   "submit_msg" : submit_msg,
+                   "submitter" : submitter,
+                   "git_tag" : git_tag,
+                   "gerrit_project" : gerrit_project,
+                   "gerrit_newrev" : gerrit_newrev,
+                   "gerrit_account_name" : gerrit_account_name,
+                   "bm_start_datetime": str(bm_start_datetime),
+                   "bm_end_datetime": str(bm_end_datetime),
+                   "bm_src_project_lst": submit_info['pre_created']
+                    }
         ### sr_status -> sr_commit -> sr_stage & sr_status_detail
-        buildmonitor.sr_submit_for_sr_status(git_tag)
-        buildmonitor.sr_submit_for_sr_commit(mygit, git_tag, gerrit_project,
-                                             gerrit_newrev, gerrit_account_name)
-        buildmonitor.package_build_for_sr_detail_sr_stage(git_tag, bm_start_datetime,
-                                                          bm_end_datetime,
-                                                          submit_info['pre_created'])
+        trigger_next("BUILD-MONITOR", bm_data)
 
 if __name__ == '__main__':
     try:
index fe9f0f4..a973a95 100644 (file)
@@ -124,7 +124,6 @@ fi
 %{destdir}/common/apply_scm_meta_git.py
 %{destdir}/common/check_scm_meta_git.py
 %{destdir}/common/git_diff_parse.py
-%{destdir}/common/buildmonitor.py
 %{destdir}/common/buildmonitor_db.py
 %{destdir}/job_re.py
 %{destdir}/job_create_snapshot.py
@@ -136,6 +135,7 @@ fi
 %{destdir}/job_load_repos.yaml.py
 %{destdir}/job_sync_obs.py
 %{destdir}/job_sync_snapdiff.py
+%{destdir}/job_buildmonitor.py
 %dir %{destdir}/templates
 %{destdir}/templates/index.html
 %{destdir}/job_update_local_git.py