[Title] Introduced "CommonJob" of parent of all job types
authordonghee yang <donghee.yang@samsung.com>
Mon, 24 Sep 2012 12:20:31 +0000 (21:20 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Mon, 24 Sep 2012 12:20:31 +0000 (21:20 +0900)
src/build_server/BuildJob.rb
src/build_server/CommonJob.rb [new file with mode: 0644]
src/build_server/FullBuildJob.rb
src/build_server/GitBuildJob.rb
src/build_server/MultiBuildJob.rb
src/build_server/RegisterPackageJob.rb
src/build_server/RemoteBuildJob.rb
src/build_server/ReverseBuildChecker.rb
src/build_server/SocketJobRequestListener.rb

index 223d752950606b4958f3194688c1b6a1749405f4..a2b9f425da4f0ee3862fa03f3d4b5ad02567f7ec 100644 (file)
@@ -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 (file)
index 0000000..520d2b0
--- /dev/null
@@ -0,0 +1,138 @@
+=begin
+
+ CommonJob.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+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
index 5c83feeb55bb12ee9d975873ab032661618e3429..7bf1d592d10410e5c987ac70824ad92d079632b2 100644 (file)
@@ -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
index 5b1b696e857e92f93c9fd09981bb0beffa10cf07..7a46878f0ae36bbaf7ce8b37e88dfb6e90110f16 100644 (file)
@@ -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
index 9e28c9e5e0778d40433237def798b6f6da8507d1..a832ec401a18cf9e0c823e500d70fd4ee94b1590 100644 (file)
@@ -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)
        
index 0655ef00aab2bcd63b0fcdfea6fe2289540646c1..9fb069f2c6310ecd94a73eb318a9c89e5e539d40 100644 (file)
@@ -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
index 845a0c87cf89eb59760c81ebdc41fe560689f9b9..4645786a13f60aa48b38b18d617440edaa2a5f9c 100644 (file)
@@ -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
index 7ae943e77a1cbc01b209c157c16e5b42f5af34c9..ed3e476d8453b940ea7a281e31ee9d1dc7d1907d 100644 (file)
@@ -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 
index ae438a98798a844bc7e881c83f0263668c00cc1d..05ea28eabebcaed6b5713dd7c35e4f954771c6fd 100644 (file)
@@ -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