From: donghee yang Date: Thu, 25 Apr 2013 07:24:38 +0000 (+0900) Subject: [Title] Fixed a bug that job is continued even if package server is not connected X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ea22d4ae0e083e31b04d8185cbb72794c7eb1591;p=sdk%2Ftools%2Fsdk-build.git [Title] Fixed a bug that job is continued even if package server is not connected --- diff --git a/pkg-cli b/pkg-cli index 12f3b72..7e9ecee 100755 --- a/pkg-cli +++ b/pkg-cli @@ -63,36 +63,76 @@ end case option[:cmd] when "clean" then - client = Client.new( nil, option[:loc], nil, false ) + client = Client.create( nil, option[:loc], nil, false ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end client.clean(option[:f]) when "download" then - client = Client.new( option[:url], option[:loc], nil ) + client = Client.create( option[:url], option[:loc], nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end file_loc = client.download( option[:pkg], option[:os], option[:t] ) when "install" then - client = Client.new( option[:url], option[:loc], nil ) + client = Client.create( option[:url], option[:loc], nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end client.install( option[:pkg], option[:os], option[:t], option[:f] ) when "install-file" then if option[:t] then - client = Client.new( option[:url], option[:loc], nil ) + client = Client.create( option[:url], option[:loc], nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end client.install_local_pkg( option[:pkg], option[:t], option[:f] ) else - client = Client.new( nil, option[:loc], nil, false ) + client = Client.create( nil, option[:loc], nil, false ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end client.install_local_pkg( option[:pkg], option[:t], option[:f] ) end when "uninstall" then - client = Client.new( nil, option[:loc], nil, false ) + client = Client.create( nil, option[:loc], nil, false ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end client.uninstall( option[:pkg], option[:t] ) when "upgrade" then - client = Client.new( option[:url], option[:loc], nil ) + client = Client.create( option[:url], option[:loc], nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end client.upgrade( option[:os], option[:t] ) when "check-upgrade" then - client = Client.new( option[:url], option[:loc], nil ) + client = Client.create( option[:url], option[:loc], nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end client.check_upgrade( option[:os] ) when "show-rpkg" then - client = Client.new( option[:url], nil, nil ) + client = Client.create( option[:url], nil, nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end puts client.show_pkg_info( option[:pkg], option[:os] ) when "list-rpkg" then - client = Client.new( option[:url], nil, nil ) + client = Client.create( option[:url], nil, nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end result = client.show_pkg_list( option[:os] ) if not result.nil? and not result.empty? then result.each do |i| @@ -103,10 +143,18 @@ when "list-rpkg" then end end when "show-lpkg" then - client = Client.new( nil, option[:loc], nil, false ) + client = Client.create( nil, option[:loc], nil, false ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end puts client.show_installed_pkg_info( option[:pkg] ) when "list-lpkg" then - client = Client.new( nil, option[:loc], nil, false ) + client = Client.create( nil, option[:loc], nil, false ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end result = client.show_installed_pkg_list() if not result.nil? and not result.empty? then result.each do |i| @@ -119,7 +167,11 @@ when "list-lpkg" then puts "Info: There is no any package." end when "build-dep" then - client = Client.new( option[:url], nil, nil ) + client = Client.create( option[:url], nil, nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end result = client.get_build_dependent_packages( option[:pkg], option[:os], true ) if result.nil? then puts "Error: Failed to get remote package list. try update first." @@ -133,7 +185,11 @@ when "build-dep" then ret[-3..-1] = "" puts ret when "install-dep" then - client = Client.new( option[:url], nil, nil ) + client = Client.create( option[:url], nil, nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end result = client.get_install_dependent_packages( option[:pkg], option[:os], true, false ) if result.nil? then puts "Error: Failed to get remote package list. try update first." @@ -147,18 +203,30 @@ when "install-dep" then ret[-3..-1] = "" puts ret when "register" then - client = Client.new( nil, nil, nil ) + client = Client.create( nil, nil, nil ) + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end client.register(option[:address], option[:dist], option[:pkg], option[:passwd]) when "snapshotlist" then - client = Client.new(option[:url],nil,nil); - client.printSnapshotList(option[:all]); + client = Client.create(option[:url],nil,nil); + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end + client.printSnapshotList(option[:all]); when "changelog" then - client = Client.new(option[:url], nil, nil); - if option[:snapshot].nil?() then - client.printChangeLog(); - else - client.printChangeLog(option[:snapshot][0], option[:snapshot][1]); - end + client = Client.create(option[:url], nil, nil); + if client.nil? then + puts "Error: Cannot create package client!" + exit 1 + end + if option[:snapshot].nil?() then + client.printChangeLog(); + else + client.printChangeLog(option[:snapshot][0], option[:snapshot][1]); + end else raise RuntimeError, "Input is incorrect : #{option[:cmd]}" end diff --git a/src/build_server/BuildJob.rb b/src/build_server/BuildJob.rb index ad5b0b6..3682166 100644 --- a/src/build_server/BuildJob.rb +++ b/src/build_server/BuildJob.rb @@ -759,7 +759,11 @@ class BuildJob < CommonJob binpkg_path_list = Dir.glob("#{@source_path}/*_*_#{@os}.zip") # upload - u_client = Client.new( @pkgsvr_url, nil, @log ) + u_client = Client.create( @pkgsvr_url, nil, @log ) + if u_client.nil? then + raise BuildServerException.new("ERR023") + end + snapshot = u_client.upload( @pkgsvr_ip, @pkgsvr_port, binpkg_path_list, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd, @pkgsvr_password) if snapshot.nil? then diff --git a/src/build_server/BuildServerException.rb b/src/build_server/BuildServerException.rb index 7611d3f..2433e92 100644 --- a/src/build_server/BuildServerException.rb +++ b/src/build_server/BuildServerException.rb @@ -26,6 +26,7 @@ class BuildServerException < Exception "ERR021" => "No DB exists and create(migrate) DB first!", "ERR022" => "There already exists same job.", + "ERR023" => "Cannot create package client!", "ERR100" => "Package info file(\"package/pkginfo.manifest\") does not exist!", "ERR101" => "Parsing package info file failed!", diff --git a/src/build_server/GitBuildJob.rb b/src/build_server/GitBuildJob.rb index 9f9c800..84aa21e 100644 --- a/src/build_server/GitBuildJob.rb +++ b/src/build_server/GitBuildJob.rb @@ -158,7 +158,10 @@ class GitBuildJob < BuildJob end # set up pkgsvr_client - @pkgsvr_client = Client.new(@pkgsvr_url, @job_working_dir, @log) + @pkgsvr_client = Client.create(@pkgsvr_url, @job_working_dir, @log) + if @pkgsvr_client.nil? then + raise BuildServerException.new("ERR023") + end # checking version if not reverse-build job or not internal-job if not @is_rev_build_check_job and not @is_verified then diff --git a/src/build_server/MultiBuildJob.rb b/src/build_server/MultiBuildJob.rb index ca19c4a..da32078 100644 --- a/src/build_server/MultiBuildJob.rb +++ b/src/build_server/MultiBuildJob.rb @@ -179,7 +179,10 @@ class MultiBuildJob < CommonJob @pkgsvr_ip = @server.distmgr.get_distribution(first_project.dist_name).pkgsvr_ip @pkgsvr_port = @server.distmgr.get_distribution(first_project.dist_name).pkgsvr_port @pkgsvr_password = @server.distmgr.get_distribution(first_project.dist_name).pkgsvr_password - @pkgsvr_client = Client.new(@pkgsvr_url, @job_working_dir, @log) + @pkgsvr_client = Client.create(@pkgsvr_url, @job_working_dir, @log) + if @pkgsvr_client.nil? then + raise BuildServerException.new("ERR023") + end return true end @@ -456,7 +459,11 @@ class MultiBuildJob < CommonJob binpkg_path_list = Dir.glob("#{@source_path}/*_*_*.zip") # upload - u_client = Client.new( @pkgsvr_url, nil, @log ) + u_client = Client.create( @pkgsvr_url, nil, @log ) + if u_client.nil? then + raise BuildServerException.new("ERR023") + end + snapshot = u_client.upload( @pkgsvr_ip, @pkgsvr_port, binpkg_path_list, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd, @pkgsvr_password) if snapshot.nil? then diff --git a/src/build_server/PackageSync.rb b/src/build_server/PackageSync.rb index 0bfec44..e5c29e2 100644 --- a/src/build_server/PackageSync.rb +++ b/src/build_server/PackageSync.rb @@ -32,6 +32,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__) $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common" require "Action.rb" require "ScheduledActionHandler.rb" +require "BuildServerException.rb" class PackageSyncAction < Action @@ -65,10 +66,16 @@ class PackageSyncAction < Action FileUtils.mkdir_p @original_path # create client - @pkgsvr_client = Client.new( @pkgsvr_url, @download_path, @server.log ) + @pkgsvr_client = Client.create( @pkgsvr_url, @download_path, @server.log ) + if @pkgsvr_client.nil? then + raise BuildServerException.new("ERR023") + end main_url = @server.distmgr.get_distribution(@dist_name).pkgsvr_url - @main_client = Client.new( main_url, @original_path, @server.log ) + @main_client = Client.create( main_url, @original_path, @server.log ) + if @main_client.nil? then + raise BuildServerException.new("ERR023") + end @user_id = @server.check_user_id_from_email("sync-manager@user") end @@ -234,8 +241,13 @@ class PackageServerSynchronizer if not exist then new_time = Time.new + 10 - @handler.register( PackageSyncAction.new(new_time, url, dist_name, @server) ) - @server.log.info "Registered package-sync action!: #{dist_name} <= \"#{url}\"" + begin + @handler.register( PackageSyncAction.new(new_time, url, dist_name, @server) ) + @server.log.info "Registered package-sync action!: #{dist_name} <= \"#{url}\"" + rescue BuildServerException => e + @server.log.error e.message + @server.log.error "Registering package-sync action failed!: #{dist_name} <= \"#{url}\"" + end end end diff --git a/src/build_server/RegisterPackageJob.rb b/src/build_server/RegisterPackageJob.rb index d88d796..726b609 100644 --- a/src/build_server/RegisterPackageJob.rb +++ b/src/build_server/RegisterPackageJob.rb @@ -178,7 +178,10 @@ class RegisterPackageJob < CommonJob end # set up pkgsvr_client - @pkgsvr_client = Client.new(@pkgsvr_url, @job_working_dir, @log) + @pkgsvr_client = Client.create(@pkgsvr_url, @job_working_dir, @log) + if @pkgsvr_client.nil? then + raise BuildServerException.new("ERR023") + end # check if the os is supported by build server if @pkg_type == "BINARY" and @@ -512,7 +515,11 @@ class RegisterPackageJob < CommonJob end # upload - u_client = Client.new( @pkgsvr_url, nil, @log ) + u_client = Client.create( @pkgsvr_url, nil, @log ) + if u_client.nil? then + raise BuildServerException.new("ERR023") + end + snapshot = u_client.upload( @pkgsvr_ip, @pkgsvr_port, binpkg_path_list, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd, @pkgsvr_password) if snapshot.nil? then diff --git a/src/builder/Builder.rb b/src/builder/Builder.rb index ec4459c..f4048a2 100644 --- a/src/builder/Builder.rb +++ b/src/builder/Builder.rb @@ -229,7 +229,11 @@ class Builder # create client @log.info( "Downloding client is initializing...", Log::LV_USER) - cl = Client.new(@pkgserver_url, build_root_dir, @log) + cl = Client.create(@pkgserver_url, build_root_dir, @log) + if cl.nil? then + @log.error( "Cannot create package client!", Log::LV_USER ) + return false + end if clean then cl.clean(true) end diff --git a/src/pkg_server/client.rb b/src/pkg_server/client.rb index 351ac44..58efd8b 100644 --- a/src/pkg_server/client.rb +++ b/src/pkg_server/client.rb @@ -66,6 +66,7 @@ class Client ARCHIVE_PKG_LIST_FILE = "archive_pkg_list" attr_accessor :server_addr, :location, :pkg_hash_os, :is_server_remote, :installed_pkg_hash_loc, :archive_pkg_list, :all_dep_list, :log, :support_os_list, :config_dist_path, :download_path, :tmp_path, :snapshot_path, :snapshots_path, :snapshot_url + private_class_method :new public # initialize @@ -122,13 +123,35 @@ class Client if not File.exist? @snapshots_path then FileUtils.mkdir_p "#{@snapshots_path}" end if not File.exist? @tmp_path then FileUtils.mkdir_p "#{@tmp_path}" end end + end + + @configs = {} + #default cache size = 8G + @configs[:CACHE_SIZE] = "8000" + end + + public + def self.create(server_addr, location, logger, access_svr = true) + new_client = new(server_addr, location, logger, access_svr ) + if new_client.init(access_svr) then + return new_client + else + return nil + end + end + + + public + def init(access_svr) + if access_svr then # read remote pkg list, and hash list @log.info "Update remote package list and supported os list.." if update() then - @log.info "Initialize - #{server_addr}, #{location}" + @log.info "Initialize - #{@server_addr}, #{@location}" else - @log.error "Failed to update remote package list." + @log.error "Failed to update remote package list." + return false end end @@ -137,9 +160,7 @@ class Client @log.info "Update local package list.. [#{@location}]" read_installed_pkg_list() - @configs = {} - #default cache size = 8G - @configs[:CACHE_SIZE] = "8000" + return true end @@ -1628,11 +1649,16 @@ class Client file_url = File.join(@server_addr, ssinfo_file) if from_server then if not FileDownLoader.download(file_url, @config_dist_path, @log) then - @log.warn "Server does not have \"#{ssinfo_file}\" file. This error can be ignored." + @log.error "Server does not have \"#{ssinfo_file}\" file." + return nil end else - if File.exist? file_url then FileUtils.cp(file_url, @config_dist_path) - else @log.warn "Server does not have \"#{ssinfo_file}\" file. This error can be ignored." end + if File.exist? file_url then + FileUtils.cp(file_url, @config_dist_path) + else + @log.error "Server does not have \"#{ssinfo_file}\" file." + return nil + end end file_path = File.join(@config_dist_path, ssinfo_file) diff --git a/src/pkg_server/distribution.rb b/src/pkg_server/distribution.rb index 5aa613b..b39957b 100644 --- a/src/pkg_server/distribution.rb +++ b/src/pkg_server/distribution.rb @@ -216,7 +216,10 @@ class Distribution else server_url = "#{@server_url}/snapshots/#{snapshot}" end - client = Client.new( server_url, "#{@location}/binary", @log ) + client = Client.create( server_url, "#{@location}/binary", @log ) + if client.nil? then + raise RuntimeError, "Cannot create package client." + end # parents package server check if client.pkg_hash_os.keys.empty? then @@ -930,7 +933,10 @@ class Distribution end def sync_archive_pkg - client = Client.new( @server_url, "#{@location}/source", @log ) + client = Client.create( @server_url, "#{@location}/source", @log ) + if client.nil? then + raise RuntimeError, "Cannot create package client." + end download_list = client.archive_pkg_list - @archive_pkg_list diff --git a/test/test_client.rb b/test/test_client.rb index 68d5ba2..bea231c 100755 --- a/test/test_client.rb +++ b/test/test_client.rb @@ -3,13 +3,13 @@ require File.dirname(__FILE__) + "/../src/pkg_server/client" require File.dirname(__FILE__) + "/../src/pkg_server/serverConfig" -### Client.new("server","dist","snapshot","location") +### Client.create("server","dist","snapshot","location") # local server -#cl = Client.new("/home/yangttak/test-packageserver") +#cl = Client.create("/home/yangttak/test-packageserver") # remote server -cl = Client.new("http://172.21.111.132/pkgserver/unstable", "/home/yangttak/build_root") +cl = Client.create("http://172.21.111.132/pkgserver/unstable", "/home/yangttak/build_root") #cl.update() result = cl.get_install_dependent_packages("cross-arm-gcc-4.5", "linux", true) puts "----" @@ -26,27 +26,27 @@ puts result #cl.install_local_pkg("/home/yangttak/test0208/sdk-build/smart-build-interface_0.20.0_linux.zip", "linux") #cl.show_pkg_info("tizen-ide", "linux") -#cl = Client.new("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot3-linux", "/tmp/client-test") +#cl = Client.create("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot3-linux", "/tmp/client-test") #cl.update() #result = cl.get_install_dependent_packages("smart-build-interface", "linux") #puts result # if location is nil -#cl = Client.new("http://172.21.111.132/pkgserver/unstable", nil) +#cl = Client.create("http://172.21.111.132/pkgserver/unstable", nil) # if server addr is nil -#cl = Client.new(nil, "/tmp/client-test") +#cl = Client.create(nil, "/tmp/client-test") # install package list #cl.download("base-toolchain", "windows") # test install different veriosn package -#cl = Client.new("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot2-linux", "/tmp/client-test") +#cl = Client.create("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot2-linux", "/tmp/client-test") #cl.install("tizen-ide", "linux") #cl.install("smart-build-interface", "linux") -#cl = Client.new("http://172.21.111.132/pkgserver/unstable", "/tmp/client-test") +#cl = Client.create("http://172.21.111.132/pkgserver/unstable", "/tmp/client-test") #result = cl.get_build_dependent_packages("mpfr", "linux") #puts result #result = cl.get_install_dependent_packages("arm-linux-gnueabi-gdb-7.2", "linux") diff --git a/upgrade b/upgrade index a9eed0b..7007d18 100755 --- a/upgrade +++ b/upgrade @@ -192,7 +192,11 @@ begin log.info("DIBS Path : [#{dibs_path}]", Log::LV_USER) # Download DIBS Package - client = Client.new( pkg_svr_url, NEW_VER_PATH, log) + client = Client.create( pkg_svr_url, NEW_VER_PATH, log) + if client.nil? then + log.error("Cannot create package client!", Log::LV_USER) + exit(1) + end client.update() client.install( DIBS_PKG_NAME, Utils::HOST_OS, true, true) if not File.exist? "#{NEW_VER_PATH}/tools/dibs" then