From: donghee yang Date: Mon, 24 Sep 2012 12:20:31 +0000 (+0900) Subject: [Title] Introduced "CommonJob" of parent of all job types X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=59077a7dfbf4a9a6b463c838c4b47bbc3013d4a1;p=sdk%2Ftools%2Fsdk-build.git [Title] Introduced "CommonJob" of parent of all job types --- diff --git a/src/build_server/BuildJob.rb b/src/build_server/BuildJob.rb index 223d752..a2b9f42 100644 --- a/src/build_server/BuildJob.rb +++ b/src/build_server/BuildJob.rb @@ -41,25 +41,24 @@ require "JobLog.rb" require "mail.rb" require "utils.rb" require "ReverseBuildChecker.rb" +require "CommonJob.rb" -class BuildJob +class BuildJob < CommonJob - attr_accessor :id, :server, :pre_jobs, :os, :type - attr_accessor :status, :pkginfo, :log, :source_path + attr_accessor :pre_jobs, :os, :type + attr_accessor :pkginfo, :source_path attr_accessor :pkgsvr_client, :thread attr_accessor :rev_fail_projects, :rev_success_jobs attr_accessor :pending_ancestor, :cancel_state attr_accessor :no_reverse # initialize - def initialize (id, project, os, server) - @id = id + def initialize (project, os, server) + super(server) @project = project @os = os - @server = server @type = "BUILD" - @status = "JUST_CREATED" @cancel_state = "NONE" @resolve = false @host_os = Utils::HOST_OS @@ -109,28 +108,6 @@ class BuildJob end - # set parent - def set_parent_job( parent ) - # if parent exists, share build-root - @parent = parent - end - - # get parent - def get_parent_job() - return @parent - end - - - def is_sub_job? - return (not @parent.nil?) - end - - - def get_sub_jobs - return [] - end - - def get_buildroot() return @buildroot_dir end @@ -182,40 +159,12 @@ class BuildJob end - # set logger - def set_logger( logger ) - @log = logger - end - - # add external packages to overwrite before build def add_external_package( file_name ) @external_pkgs.push "#{@job_root}/external_pkgs/#{file_name}" end - # execute - def execute(sync=false) - @log.info( "Invoking a thread for building Job #{@id}", Log::LV_USER) - if @status == "ERROR" then return end - @thread = Thread.new { - begin - thread_main() - if not is_sub_job? then terminate() end - rescue => e - @log.error e.message - @log.error e.backtrace.inspect - end - } - - if sync then - @thread.join - end - - return true - end - - #terminate def terminate() #do noting @@ -545,11 +494,13 @@ class BuildJob # # PROTECTED METHODS # - protected # main module - def thread_main + protected + def job_main() + @log.info( "Invoking a thread for building Job #{@id}", Log::LV_USER) + if @status == "ERROR" then return end @log.info( "New Job #{@id} is started", Log::LV_USER) # checking build dependency @@ -657,7 +608,7 @@ class BuildJob # if not found, check package server found = false if not @parent.nil? and @parent.type == "MULTIBUILD" then - @parent.sub_jobs.each { |j| + @parent.get_sub_jobs().each { |j| os = (dep.target_os_list.empty?) ? @os : dep.target_os_list[0] if j.pkginfo.pkg_exist?(dep.package_name, dep.base_version, os) then found = true; break @@ -1163,7 +1114,7 @@ class BuildJob chained_deps.each { |dep| dep_target_os = get_os_of_dependency(dep) - parent.sub_jobs.each { |j| + parent.get_sub_jobs().each { |j| new_deps += j.pkginfo.get_install_dependencies(dep_target_os, dep.package_name) } } diff --git a/src/build_server/CommonJob.rb b/src/build_server/CommonJob.rb new file mode 100644 index 0000000..520d2b0 --- /dev/null +++ b/src/build_server/CommonJob.rb @@ -0,0 +1,138 @@ +=begin + + CommonJob.rb + +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + +Contact: +Taejun Ha +Jiil Hyoun +Donghyuk Yang +DongHee Yang + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Contributors: +- S-Core Co., Ltd +=end + +require "fileutils" +$LOAD_PATH.unshift File.dirname(__FILE__) +$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common" +require "utils.rb" + +class CommonJob + + attr_accessor :id, :server, :log, :status + + # initialize + def initialize(server, id=nil) + @id = server.jobmgr.get_new_job_id() + @server = server + + @parent = nil + @sub_jobs = [] + + @status = "JUST_CREATED" + @log = nil + end + + # set parent + def set_parent_job( parent ) + @parent = parent + end + + # get parent + def get_parent_job() + return @parent + end + + + # check this job has a parent job + def is_sub_job? + return (not @parent.nil?) + end + + + # get all sub jobs + def get_sub_jobs + return @sub_jobs + end + + + # add sub job + def add_sub_job( job ) + @sub_jobs.push job + # this will make sub-job to share build-root of parent + job.set_parent_job( self ) + end + + + # set logger + def set_logger( logger ) + @log = logger + end + + + # execute + def execute(sync=false) + + # create a thread for job + @thread = Thread.new { + begin + job_main() + + # parent job will call sub job's terminate method + if not is_sub_job? then terminate() end + rescue => e + @log.error e.message + @log.error e.backtrace.inspect + end + } + + if sync then + @thread.join + end + + return true + end + + + #terminate + def terminate() + #do noting + end + + + #cancel + def cancel() + # do nothing + end + + + def progress + # do nothing + return "" + end + + + # + # PROTECTED METHODS + # + + # main module + protected + def job_main + # do nothing + end +end diff --git a/src/build_server/FullBuildJob.rb b/src/build_server/FullBuildJob.rb index 5c83fee..7bf1d59 100644 --- a/src/build_server/FullBuildJob.rb +++ b/src/build_server/FullBuildJob.rb @@ -39,22 +39,21 @@ require "RemoteBuilder.rb" require "BuildServer.rb" require "JobLog.rb" require "mail.rb" +require "CommonJob.rb" -class FullBuildJob +class FullBuildJob < CommonJob - attr_accessor :id, :server, :pre_jobs, :os, :type - attr_accessor :status, :log, :source_path + attr_accessor :pre_jobs, :os, :type + attr_accessor :source_path attr_accessor :pkgsvr_client, :thread attr_accessor :is_fullbuild_job # initialize def initialize (server) - @server = server - @id = server.jobmgr.get_new_job_id() + super(server) @log = nil @type = "FULLBUILD" - @status = "JUST_CREATED" @host_os = Utils::HOST_OS @pkgserver_url = @server.pkgserver_url @job_root = "#{@server.path}/jobs/#{@id}" @@ -67,28 +66,6 @@ class FullBuildJob end - # execute - def execute(sync=false) - @log.info( "Invoking a thread for FULL-BUILD Job #{@id}", Log::LV_USER) - if @status == "ERROR" then return end - @thread = Thread.new { - begin - thread_main() - terminate() - rescue => e - @log.error e.message - @log.error e.backtrace.inspect - end - } - - if sync then - @thread.join - end - - return true - end - - # def init # mkdir @@ -174,20 +151,17 @@ class FullBuildJob return false end - # set logger - def set_logger( logger ) - @log = logger - end - # # PROTECTED METHODS # - protected # main module - def thread_main + protected + def job_main() + @log.info( "Invoking a thread for FULL-BUILD Job #{@id}", Log::LV_USER) + if @status == "ERROR" then return end @log.info( "New Job #{@id} is started", Log::LV_USER) # check passwd diff --git a/src/build_server/GitBuildJob.rb b/src/build_server/GitBuildJob.rb index 5b1b696..7a46878 100644 --- a/src/build_server/GitBuildJob.rb +++ b/src/build_server/GitBuildJob.rb @@ -38,7 +38,7 @@ class GitBuildJob < BuildJob # initialize def initialize( project, os, server ) - super(server.jobmgr.get_new_job_id(), project, os, server) + super(project, os, server) @git_repos = project.repository @git_branch = project.branch @git_commit = nil diff --git a/src/build_server/MultiBuildJob.rb b/src/build_server/MultiBuildJob.rb index 9e28c9e..a832ec4 100644 --- a/src/build_server/MultiBuildJob.rb +++ b/src/build_server/MultiBuildJob.rb @@ -39,22 +39,21 @@ require "RemoteBuilder.rb" require "BuildServer.rb" require "JobLog.rb" require "mail.rb" +require "CommonJob.rb" -class MultiBuildJob +class MultiBuildJob < CommonJob - attr_accessor :id, :server, :pre_jobs, :os, :type - attr_accessor :status, :log, :source_path, :cancel_state - attr_accessor :pkgsvr_client, :thread, :sub_jobs + attr_accessor :pre_jobs, :os, :type + attr_accessor :source_path, :cancel_state + attr_accessor :pkgsvr_client, :thread # initialize def initialize (server) - @server = server - @id = server.jobmgr.get_new_job_id() + super(server) @log = nil @type = "MULTIBUILD" @os = "Unknown" - @status = "JUST_CREATED" @host_os = Utils::HOST_OS @pkgserver_url = @server.pkgserver_url @job_root = "#{@server.path}/jobs/#{@id}" @@ -64,8 +63,6 @@ class MultiBuildJob @pre_jobs = [] #pre-requisite jobs @cancel_state = "NONE" - # children - @sub_jobs = [] end @@ -74,39 +71,10 @@ class MultiBuildJob end - def get_parent_job() - return nil - end - - def is_rev_build_check_job() return false end - # execute - def execute(sync=false) - @log.info( "Invoking a thread for MULTI-BUILD Job #{@id}", Log::LV_USER) - if @status == "ERROR" then return end - @thread = Thread.new { - begin - # main - thread_main() - - # close - terminate() - rescue => e - @log.error e.message - @log.error e.backtrace.inspect - end - } - - if sync then - @thread.join - end - - return true - end - # cnacel def cancel() @sub_jobs.select{|x| x.cancel_state == "NONE"}.each do |sub| @@ -203,16 +171,6 @@ class MultiBuildJob end - def is_sub_job? - return false - end - - - def get_sub_jobs() - return @sub_jobs - end - - # check building is possible def can_be_built_on?(host_os) return true @@ -336,25 +294,6 @@ class MultiBuildJob return false end - # set logger - def set_logger( logger ) - @log = logger - end - - - # add sub job - def add_sub_job( job ) - @sub_jobs.push job - # this will make sub-job to share build-root of parent - job.set_parent_job( self ) - end - - - def progress - # do noting - return "" - end - def get_log_url() # only when server support log url @@ -366,13 +305,15 @@ class MultiBuildJob end # - # PROTECTED METHODS + # PROTECTED/PRIVATE METHODS # - protected # main module - def thread_main + protected + def job_main() + @log.info( "Invoking a thread for MULTI-BUILD Job #{@id}", Log::LV_USER) + if @status == "ERROR" then return end @log.info( "New Job #{@id} is started", Log::LV_USER) # initialize status map @@ -449,6 +390,7 @@ class MultiBuildJob end + private def upload() @log.info( "Uploading ...", Log::LV_USER) diff --git a/src/build_server/RegisterPackageJob.rb b/src/build_server/RegisterPackageJob.rb index 0655ef0..9fb069f 100644 --- a/src/build_server/RegisterPackageJob.rb +++ b/src/build_server/RegisterPackageJob.rb @@ -39,23 +39,22 @@ require "JobLog.rb" require "mail.rb" require "utils.rb" require "ReverseBuildChecker.rb" +require "CommonJob.rb" -class RegisterPackageJob +class RegisterPackageJob < CommonJob - attr_accessor :id, :server, :pre_jobs, :os, :type - attr_accessor :status, :log, :source_path + attr_accessor :pre_jobs, :os, :type + attr_accessor :source_path attr_accessor :pkgsvr_client, :thread, :pkg_type attr_accessor :pkg_name, :pkginfo, :cancel_state # initialize def initialize( local_path, project, server, ftpurl=nil ) - @server = server - @id = server.jobmgr.get_new_job_id() + super(server) @log = nil @type = "REGISTER" - @status = "JUST_CREATED" @host_os = Utils::HOST_OS @pkgserver_url = @server.pkgserver_url @job_root = "#{@server.path}/jobs/#{@id}" @@ -83,11 +82,6 @@ class RegisterPackageJob end - def is_sub_job? - return false - end - - def get_project() return @project end @@ -97,37 +91,11 @@ class RegisterPackageJob return @buildroot_dir end - def get_parent_job() - return nil - end - def is_rev_build_check_job() return false end - # execute - def execute(sync=false) - @log.info( "Invoking a thread for REGISTER Job #{@id}", Log::LV_USER) - if @status == "ERROR" then return end - @thread = Thread.new { - begin - thread_main() - terminate() - rescue => e - @log.error e.message - @log.error e.backtrace.inspect - end - } - - if sync then - @thread.join - end - - return true - end - - # def init # mkdir @@ -344,11 +312,6 @@ class RegisterPackageJob return false end - # set logger - def set_logger( logger ) - @log = logger - end - def progress if not @log.nil? then @@ -375,11 +338,13 @@ class RegisterPackageJob # # PROTECTED METHODS # - protected # main module - def thread_main + protected + def job_main() + @log.info( "Invoking a thread for REGISTER Job #{@id}", Log::LV_USER) + if @status == "ERROR" then return end @log.info( "New Job #{@id} is started", Log::LV_USER) # clean build diff --git a/src/build_server/RemoteBuildJob.rb b/src/build_server/RemoteBuildJob.rb index 845a0c8..4645786 100644 --- a/src/build_server/RemoteBuildJob.rb +++ b/src/build_server/RemoteBuildJob.rb @@ -31,12 +31,14 @@ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common" require "BuildJob.rb" require "utils.rb" + class RemoteBuildJob < BuildJob attr_accessor :id # initialize def initialize (id,server) - super(id,nil,nil,server) + super(nil,nil,server) + # overide id @id = id @type = nil end diff --git a/src/build_server/ReverseBuildChecker.rb b/src/build_server/ReverseBuildChecker.rb index 7ae943e..ed3e476 100644 --- a/src/build_server/ReverseBuildChecker.rb +++ b/src/build_server/ReverseBuildChecker.rb @@ -103,7 +103,7 @@ class ReverseBuildChecker # if this is sub job, all other sibling job must be excluded if job.is_sub_job? then - job.get_parent_job().get_sub_jobs.each do |sub_job| + job.get_parent_job().get_sub_jobs().each do |sub_job| sub_prj = sub_job.get_project() sub_os = sub_job.os if rev_prj == sub_prj and rev_os == sub_os then diff --git a/src/build_server/SocketJobRequestListener.rb b/src/build_server/SocketJobRequestListener.rb index ae438a9..05ea28e 100644 --- a/src/build_server/SocketJobRequestListener.rb +++ b/src/build_server/SocketJobRequestListener.rb @@ -418,7 +418,7 @@ class SocketJobRequestListener BuildCommServer.send(req,"#{status},#{job.id},#{job.pkg_name}") end when "MULTIBUILD" - BuildCommServer.send(req,"#{status},#{job.id},MULTI-BUILD : #{job.sub_jobs.map{|x| x.id}.join(" ")}") + BuildCommServer.send(req,"#{status},#{job.id},MULTI-BUILD : #{job.get_sub_jobs().map{|x| x.id}.join(" ")}") end end @@ -504,14 +504,14 @@ class SocketJobRequestListener if cancel_job.cancel_state == "NONE" then # check passwd if cancel_job.type == "MULTIBUILD" then - cancel_job.sub_jobs.select{|x| x.cancel_state == "NONE" }.each do |sub| + cancel_job.get_sub_jobs().select{|x| x.cancel_state == "NONE" }.each do |sub| if not check_project_password( sub.get_project, tok[2], req) then BuildCommServer.send(req, "Project's password is not matched!!") raise "Project's password is not matched!!" end end - BuildCommServer.send(req, "\"#{cancel_job.id}, #{cancel_job.sub_jobs.map{|x| x.id}.join(", ")}\" will be canceled") + BuildCommServer.send(req, "\"#{cancel_job.id}, #{cancel_job.get_sub_jobs().map{|x| x.id}.join(", ")}\" will be canceled") cancel_job.cancel_state = "INIT" else if not check_project_password( cancel_job.get_project, tok[2], req) then