require "utils.rb"
require "ReverseBuildChecker.rb"
require "CommonJob.rb"
+require "BuildServerException.rb"
class BuildJob < CommonJob
if ( not @force_rebuild and
not old_source_info.nil? and old_source_info != source_info ) then
- @log.error( "Source code has been changed without increasing version!", Log::LV_USER)
- @log.error( " * Version : #{ver_local}", Log::LV_USER)
- @log.error( " * Before : #{old_source_info}", Log::LV_USER)
- @log.error( " * Current : #{source_info}", Log::LV_USER)
-
- return false
+ raise BuildServerException.new("ERR106"), "#{ver_local}"
end
# compare with package version in package server
( Version.new(ver_local) < Version.new(ver_svr) or
Version.new(ver_local) == Version.new(ver_svr) ) ) then
- @log.error( "Version must be increased : #{ver_local} <= #{ver_svr}", Log::LV_USER)
- return false
+ raise BuildServerException.new("ERR105"), "#{ver_local} <= #{ver_svr}"
end
end
"ERR021" => "No DB exists and create(migrate) DB first!",
+ "ERR100" => "Package info file(\"package/pkginfo.manifest\") does not exist!",
+ "ERR101" => "Parsing package info file failed!",
+ "ERR102" => "Parsing change-log file failed!",
+ "ERR103" => "Change log not found!",
+ "ERR104" => "No servers supports the \"Host-OS\"!",
+ "ERR105" => "Version must be increased!",
+ "ERR106" => "Source code has been changed without increasing version!",
+ "ERR107" => "Package file not found!",
+ "ERR108" => "Unsupported OS used in package file name!",
+ "ERR109" => "Extracting package file failed!",
+ "ERR110" => "Initializing sub jobs failed!",
+
"ERR900" => "Cancel event received!",
"ERR901" => "Job already upload status. Cancel failed!"
}
end
def err_message(prefix = "Error: ")
- if not message().nil? and not message().empty? then
+ if not message().nil? and not message().empty? and
+ message() != "BuildServerException" then
+
return "#{prefix}#{@@err_msgs[@err_code]}: #{message()}"
else
return "#{prefix}#{@@err_msgs[@err_code]}"
$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
require "BuildJob.rb"
require "utils.rb"
+require "BuildServerException.rb"
$git_mutex = Mutex.new
end
# check pkginfo.manifest
- if not File.exist? "#{@source_path}/package/pkginfo.manifest"
- @log.error( "package/pkginfo.manifest does not exist", Log::LV_USER)
- @status = "ERROR"
- return false
+ if not File.exist? "#{@source_path}/package/pkginfo.manifest" then
+ raise BuildServerException.new("ERR100")
end
# set up pkg info
begin
@pkginfo = PackageManifest.new("#{@source_path}/package/pkginfo.manifest")
rescue => e
- @log.error( e.message, Log::LV_USER)
- return false
+ raise BuildServerException.new("ERR101"), e.message
end
# set up pkgsvr_client
begin
change_log = Parser.read_changelog "#{@source_path}/package/changelog" if File.exist? "#{@source_path}/package/changelog"
rescue => e
- @log.error( e.message, Log::LV_USER)
- return false
+ raise BuildServerException.new("ERR102"), e.message
end
if not change_log.empty? and @pkginfo.packages[0].change_log.empty? then
end
if @server.changelog_check and not @pkginfo.packages[0].does_change_exist? then
- @log.error( "change log not found", Log::LV_USER )
- return false
+ raise BuildServerException.new("ERR103"), @pkginfo.packages[0].version
end
# check availabiltiy
if not @server.check_job_availability( self ) then
- @log.error( "No servers that are able to build your packages.", Log::LV_USER)
- @log.error( "Host-OS (#{@os}) is not supported in build server.", Log::LV_USER)
- @status = "ERROR"
- @server.log.info "Adding the job \"#{@id}\" is canceled"
- return false
+ raise BuildServerException.new("ERR104"), "#{@os}"
end
- if not check_package_version(@git_commit) then
- @status = "ERROR"
- return false
- end
+ check_package_version(@git_commit)
end
return true
def initialize_job ( job )
job.status = "INITIALIZING"
job.thread = Thread.new do
- save_job_status(job)
- job.add_timestamp("INIT_START")
begin
+ save_job_status(job)
+ job.add_timestamp("INIT_START")
+
# init
- if not job.init or job.status == "ERROR" then
- if job.event == "NONE" then job.status = "ERROR" end
- @server.log.info "Adding the job \"#{job.id}\" is canceled"
- job.terminate()
- save_job_status(job)
- Thread.current.exit
- end
+ job.init
job.check_event
if job.status == "INITIALIZING" then
job.status = "WAITING"
end
@server.log.info "Checking the job \"#{job.id}\" was finished!"
rescue BuildServerException => e
- @server.log.error e.message
+ @server.log.info "Initializig the job \"#{job.id}\" failed!"
+ if e.err_code != "ERR900" then job.status = "ERROR" end
+ if not job.log.nil? then
+ job.log.error(e.err_message(""), Log::LV_USER)
+ else
+ @server.log.error e.message
+ end
+ if job.status == "ERROR" then
+ job.terminate()
+ save_job_status(job)
+ end
rescue => e
@server.log.error e.message
@server.log.error e.backtrace.inspect
# initialize all sub jobs and add them to "internal_jobs"
tstatus = @status
@sub_jobs.each do |job|
- # initialize job
- if not job.init or job.status == "ERROR" then
- job.status = "ERROR"
- @log.info( "Failed to initialize sub-job \"#{job.get_project().name}\" for #{job.os}. (#{job.id})", Log::LV_USER)
- end
+ begin
+ job.status = "INITIALIZING"
- if job.status != "ERROR" then
- job.status = "WAITING"
- else
+ job.add_timestamp("INIT_START")
+
+ # initialize job
+ job.init
+ if job.status == "INITIALIZING" then
+ job.status = "WAITING"
+ job.add_timestamp("INIT_END")
+ end
+ rescue BuildServerException => e
+ if e.err_code != "ERR900" then job.status = "ERROR" end
+ @log.error( "Failed to initialize sub-job \"#{job.get_project().name}\" for #{job.os}. (#{job.id})", Log::LV_USER)
+ @log.error( " * #{e.err_message("")}", Log::LV_USER)
tstatus = "ERROR"
end
end
+
if tstatus == "ERROR" then
# Changed the status of initialized sub-jobs if parent is in ERROR status
@sub_jobs.each do |job|
# Add internal job for cancel,error process
@server.jobmgr.add_internal_job(job)
end
- @status = tstatus
- return false
+
+ raise BuildServerException.new("ERR110")
end
require "ReverseBuildChecker.rb"
require "CommonJob.rb"
require "JobLog.rb"
+require "BuildServerException.rb"
class RegisterPackageJob < CommonJob
# copy package file to source path
@file_path = "#{@source_path}/#{File.basename(@local_path)}"
if not File.exist? @local_path then
- @log.error( "File not found!", Log::LV_USER)
- @status = "ERROR"
- return false
+ raise BuildServerException.new("ERR107"), @local_path
+ end
+
+ if @auto_remove then
+ # if remote upload remove file and its directory
+ FileUtils.mv(@local_path, @file_path)
+ FileUtils.rm_rf("#{File.dirname(@local_path)}")
else
- if @auto_remove then
- # if remote upload remove file and its directory
- FileUtils.mv(@local_path, @file_path)
- FileUtils.rm_rf("#{File.dirname(@local_path)}")
- else
- FileUtils.ln(@local_path, @file_path, :force => true)
- end
+ FileUtils.ln(@local_path, @file_path, :force => true)
end
# set up pkgsvr_client
# check if the os is supported by build server
if @pkg_type == "BINARY" and
not @server.supported_os_list.include? @os then
- @log.error( "Unsupported OS \"#{@os}\" is used!", Log::LV_USER)
- @status = "ERROR"
- return false
+
+ raise BuildServerException.new("ERR108"), @os
end
# checking version if not reverse-build job
# extrac pkg file
cmd = "cd \"#{@source_path}\";unzip #{@file_path}"
if not execute_shell(cmd) then
- @log.error( "Extracting package file failed!", Log::LV_USER)
- @status = "ERROR"
- return false
+ raise BuildServerException.new("ERR109"), @file_path
+ end
+
+ # check pkginfo.manifest
+ if not File.exist? "#{@source_path}/pkginfo.manifest" then
+ raise BuildServerException.new("ERR100")
end
# set up pkg info
begin
@pkginfo = PackageManifest.new("#{@source_path}/pkginfo.manifest")
rescue => e
- @log.error( e.message, Log::LV_USER)
- @status = "ERROR"
- return false
+ raise BuildServerException.new("ERR101"), e.message
end
- #if @server.changelog_check and not @pkginfo.packages[0].does_change_exist? then
- # @log.error( "change log not found", Log::LV_USER )
- # return false
- #end
+ # TODO: need to check change log file
- if not check_package_version() then
- @status = "ERROR"
- return false
- end
+ check_package_version()
end
return true
#ver_svr = @pkgsvr_client.get_package_version( pkg.package_name, @os )
ver_svr = @pkgsvr_client.get_attr_from_pkg( pkg.package_name, @os, "version")
if not ver_svr.nil? and Version.new(ver_local) <= Version.new(ver_svr) then
- @log.error( "Version must be increased : #{ver_local} <= #{ver_svr}", Log::LV_USER)
- return false
+ raise BuildServerException.new("ERR105"), "#{ver_local} <= #{ver_svr}"
end
end
end
def does_change_exist?
- if not @change_log.empty? and not @change_log[@version].nil? then
+ if not @change_log[@version].nil? then
return true
end
return false
Info: Added new job
Info: Initializing job...
Info: Checking package version ...
-Error: Version must be increased :
+Error: Version must be increased!: 0.0.1 <= 0.0.1
Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
#EXPECT
Info: Added new job
Info: Initializing job...
-Error: No servers that are able to build your packages.
-Error: Host-OS (windows-32) is not supported in build server.
+Error: No servers supports the "Host-OS"!: windows-32
Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
Info: Added new job
Info: Initializing job...
Info: Checking package version ...
-Error: Source code has been changed without increasing version!
-Error: * Version :
-Error: * Before :
-Error: * Current :
+Error: Source code has been changed without increasing version!: 0.0.1
Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
#EXPECT
Info: Added new job
Info: Initializing job...
-Info: Failed to initialize sub-job
-Info: Failed to initialize sub-job
-Info: Failed to initialize sub-job
+Error: Failed to initialize sub-job "testa" for
+Error: * Version must be increased!:
+Error: Failed to initialize sub-job "testb" for
+Error: * Version must be increased!:
+Error: Failed to initialize sub-job "testc" for
+Error: * Version must be increased!:
+Error: Initializing sub jobs failed!
Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
#EXPECT
Info: Added new job
Info: Initializing job...
-Error: Unsupported OS "wrongosname" is used!
+Error: Unsupported OS used in package file name!: wrongosname
Error: Job is stopped by ERROR