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
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
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
#
# 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
# 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
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)
}
}
--- /dev/null
+=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
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}"
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
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
# 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
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}"
@pre_jobs = [] #pre-requisite jobs
@cancel_state = "NONE"
- # children
- @sub_jobs = []
end
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|
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
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
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
end
+ private
def upload()
@log.info( "Uploading ...", Log::LV_USER)
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}"
end
- def is_sub_job?
- return false
- end
-
-
def get_project()
return @project
end
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
return false
end
- # set logger
- def set_logger( logger )
- @log = logger
- end
-
def progress
if not @log.nil? then
#
# 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
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
# 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
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
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