[Title] Fixed a bug that job is continued even if package server is not connected
authordonghee yang <donghee.yang@samsung.com>
Thu, 25 Apr 2013 07:24:38 +0000 (16:24 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Thu, 25 Apr 2013 07:24:38 +0000 (16:24 +0900)
12 files changed:
pkg-cli
src/build_server/BuildJob.rb
src/build_server/BuildServerException.rb
src/build_server/GitBuildJob.rb
src/build_server/MultiBuildJob.rb
src/build_server/PackageSync.rb
src/build_server/RegisterPackageJob.rb
src/builder/Builder.rb
src/pkg_server/client.rb
src/pkg_server/distribution.rb
test/test_client.rb
upgrade

diff --git a/pkg-cli b/pkg-cli
index 12f3b72131967ddcd723ade00321eb8e9e16056e..7e9ecee551cddfbb99cc0c2e898de1798241627e 100755 (executable)
--- 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
index ad5b0b6f85f63004f1848f312859610cbbf312bc..3682166c8dbb3d98df2f7c759d01add4b0a4114d 100644 (file)
@@ -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
index 7611d3f80675439f149a3e564607213850c4589a..2433e92a5a9083d3e29edaa1e28ee31bea8b02b4 100644 (file)
@@ -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!",
index 9f9c8006717a1e110c81c0bcd64aa1983c32c11b..84aa21e9ed7eaa63a0d3bafbdc73bafb92fc7775 100644 (file)
@@ -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
index ca19c4aa16ad02574965ae27dc6d1636179c97ac..da32078b3539eb31159e629f61a073523416fda6 100644 (file)
@@ -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
index 0bfec44a3cc389e6b036cc5d312593a092579ea1..e5c29e2bc01314b416ad2d7e3189f7219c5e33ea 100644 (file)
@@ -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
 
index d88d7961a3feb59793b8e7cf3bdfd31d4622d178..726b6093570bf057324e4de85f18344db5d75fb0 100644 (file)
@@ -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
index ec4459c0ab06b326edcf66e019f1dc96e4f589f2..f4048a296d6b7adec012fa5dca042218c735220b 100644 (file)
@@ -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
index 351ac4457c33e507e34a04fc9e257ddcbe2a59ba..58efd8b24815b4122980a9d446c65b6dc52baceb 100644 (file)
@@ -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)
index 5aa613b129fb992961d473044546ec4d328cb014..b39957ba667dc479769398aab7ffec65eecfa44d 100644 (file)
@@ -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
 
index 68d5ba251fc00841fccf55a8a0073f05ff48220b..bea231cf54531daac3667302a344b80aad03a675 100755 (executable)
@@ -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 a9eed0bbe2e02ec44eb4a1acd2605c4c5ea3d8db..7007d1887240871ff96d00ae40449ecfd5333529 100755 (executable)
--- 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