From: donghee yang Date: Thu, 28 Mar 2013 09:43:21 +0000 (+0900) Subject: [Title] Fixed "REGISTER" to show log correctly X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69bbb364e967f914b121f269615de8fb7f7df8a1;p=sdk%2Ftools%2Fsdk-build.git [Title] Fixed "REGISTER" to show log correctly --- diff --git a/build-cli b/build-cli index 7982fa5..6b66de9 100755 --- a/build-cli +++ b/build-cli @@ -140,18 +140,21 @@ def query_job_list(ip, port) end def upload_request(bs_ip, bs_port, dock, transporter, package ) - client = BuildCommClient.create( bs_ip, bs_port, nil, 0 ) - if client.nil? then - raise RuntimeError, "Can't access server #{bs_ip}:#{bs_port}" + result = false + begin + client = BuildCommClient.create( bs_ip, bs_port, nil, 0 ) + if client.nil? then + raise RuntimeError, "Can't access server #{bs_ip}:#{bs_port}" + end + msg = "UPLOAD|#{dock}" + client.send( msg ) + result = client.send_file(package, transporter) + ensure + client.terminate if not client.nil? end - msg = "UPLOAD|#{dock}" - client.send( msg ) - result = client.send_file(package, transporter) - client.terminate + if not result then - raise RuntimeError, "Uploading file failed!.. #{result}" - else - puts "Uploading file success!.. #{result}" + raise RuntimeError, "Uploading file failed!..." end end @@ -214,11 +217,11 @@ begin puts job_error result = false end - client.terminate rescue => e puts "ERROR: #{e}" - client.terminate exit 1 + ensure + client.terminate if not client.nil? end # Query log in case sync @@ -484,43 +487,32 @@ begin client.terminate end - # Query log in case sync - if result then - begin - client = BuildCommClient.create( bs_ip, bs_port, nil, 0 ) - if client.nil? then - puts "Can't access server #{bs_ip}:#{bs_port}" - exit(-1) - end - - client.send "LOG|#{job_id}" - result = client.read_lines do |line| - if line.strip.start_with?("=JOB_STATUS") then - data = line.strip.split(",") - job_status = data[1] - job_error = data[2] - else - # print log - puts line - end - end + if not result then exit(1) end - if not result then - puts "ERROR: Can't query log, Communication failed! #{client.get_error_msg()}" - end - - # Check job status - if not job_status.eql? "FINISHED" then - result = false + # Query log in case sync + begin + result = JobLog.monitor(bs_ip, bs_port, job_id) do |line| + category, level, contents = JobLog.parse_log(line) + if level < Log::LV_USER then next end + + if category == "INFO" then + puts "Info: #{contents}" + elsif category == "WARN" then + puts "Warn: #{contents}" + elsif category == "ERROR" then + puts "Error: #{contents}" + else + next end - ensure - client.terminate end - end - if not result then - exit 1 + rescue BuildServerException => e + puts e.err_message() + result = false end + + if not result then exit(-1) end + else raise RuntimeError, "input option incorrect : #{option[:cmd]}" end diff --git a/src/build_server/BuildServerController.rb b/src/build_server/BuildServerController.rb index 97b595b..9dfd6a7 100644 --- a/src/build_server/BuildServerController.rb +++ b/src/build_server/BuildServerController.rb @@ -636,34 +636,70 @@ class BuildServerController file_path = File.expand_path(file_path) # send request - success = false - client = BuildCommClient.create( "127.0.0.1", server.port ) - if client.nil? then - puts "Server is not running!" - return false - end - if client.send "REGISTER|BINARY-LOCAL|#{file_path}|#{server.password}|#{dist_name}" then - # recevie & print - mismatched = false - result = client.read_lines do |l| - puts l - if l.include? "Password mismatched!" then - mismatched = true - end + success = true + job_id = nil + job_status = nil + job_error = nil + result = false + begin + client = BuildCommClient.create( "127.0.0.1", server.port ) + if client.nil? then + puts "Server is not running!" + return false end - if result and not mismatched then - success = true + if client.send "REGISTER|BINARY-LOCAL|#{file_path}|#{server.password}|#{dist_name}" then + # recevie & print + result = client.read_lines do |l| + if l.strip.start_with?("=JOB_START") then + job_id = l.strip.split(",")[1] + elsif l.strip.start_with?("=JOB_STATUS") then + data = l.strip.split(",") + job_status = data[1] + job_error = data[2] + else + puts l + end + end + if not result then + puts "Error: Communication failed! #{client.get_error_msg()}" + elsif job_id.nil? then + puts job_error + result = false + end end + rescue => e + puts "ERROR: #{e}" + result = false + ensure + client.terminate if not client.nil? end - # terminate - client.terminate - - if not success then + if not result then puts "Registering package failed!" + return false end - return true + begin + result = JobLog.monitor("127.0.0.1", server.port, job_id) do |line| + category, level, contents = JobLog.parse_log(line) + if level < Log::LV_USER then next end + + if category == "INFO" then + puts "Info: #{contents}" + elsif category == "WARN" then + puts "Warn: #{contents}" + elsif category == "ERROR" then + puts "Error: #{contents}" + else + next + end + end + rescue BuildServerException => e + puts e.err_message() + result = false + end + + return result end # server diff --git a/src/build_server/BuildServerException.rb b/src/build_server/BuildServerException.rb index 8ab47e4..deb0d9f 100644 --- a/src/build_server/BuildServerException.rb +++ b/src/build_server/BuildServerException.rb @@ -20,6 +20,9 @@ class BuildServerException < Exception "ERR016" => "Can't received register file!", "ERR017" => "Project locked!", + "ERR018" => "Connection failed!", + "ERR019" => "Receiving log data failed!", + "ERR900" => "Cancel event received!", "ERR901" => "Job already upload status. Cancel failed!" } diff --git a/src/build_server/JobLog.rb b/src/build_server/JobLog.rb index 46780f3..488c4d1 100644 --- a/src/build_server/JobLog.rb +++ b/src/build_server/JobLog.rb @@ -59,4 +59,45 @@ class JobLog < Log return category, level, contents end + + + def JobLog.monitor(ip, port, job_id) + + result = true + job_status = "" + begin + client = BuildCommClient.create( ip, port, nil, 0 ) + if client.nil? then + raise BuildServerException.new("ERR018"), "#{ip}:#{port}" + end + + client.send "LOG|#{job_id}" + result = client.read_lines do |line| + if line.strip.start_with?("=JOB_STATUS") then + data = line.strip.split(",") + job_status = data[1] + job_error = data[2] + else + if block_given? then + yield line.strip + else + puts line.strip + end + end + end + + if not result then + raise BuildServerException.new("ERR019"), "#{client.get_error_msg()}" + end + + # Check job status + if not job_status.eql? "FINISHED" then + result = false + end + ensure + client.terminate if not client.nil? + end + + return result + end end diff --git a/src/build_server/SocketJobRequestListener.rb b/src/build_server/SocketJobRequestListener.rb index 1f23888..39b17f2 100644 --- a/src/build_server/SocketJobRequestListener.rb +++ b/src/build_server/SocketJobRequestListener.rb @@ -688,7 +688,7 @@ class SocketJobRequestListener handle_cmd_register_internal( line, req ) rescue BuildServerException => e @log.error(e.message) - BuildCommServer.send(req, e.err_message()) + BuildCommServer.send(req, "=JOB_STATUS,ERROR,#{e.err_message()}") BuildCommServer.send_end(req) BuildCommServer.disconnect(req) rescue => e @@ -725,26 +725,27 @@ class SocketJobRequestListener check_distribution(dist_name, req) # check project - prj = check_project_for_package_file_name(file_path, dist_name, req) - + file_name = File.basename(file_path) + prj = check_project_for_package_file_name(file_name, dist_name, req) # check project status if prj.status != "OPEN" then raise BuildServerException.new("ERR017"), "#{prj.name} on #{dist_name}. project is [[#{prj.status}]]" end new_job = @parent_server.jobmgr.create_new_register_job( file_path, dist_name ) - new_job.create_logger() - BuildCommServer.send_end(req) - BuildCommServer.disconnect(req) + @parent_server.jobmgr.commit_job(new_job) + logger = new_job.create_logger() + # notify that job has been received BuildCommServer.send(req, "=JOB_START,#{new_job.id}") - BuildCommServer.send(req,"Info: Added new job \"#{new_job.id}\" for #{new_job.os}!") + logger.info( "Added new job \"#{new_job.id}\" for #{new_job.os}!", Log::LV_USER) if not @parent_server.job_log_url.empty? then - BuildCommServer.send(req,"Info: * Log URL : #{@parent_server.job_log_url}/#{new_job.id}/log") + logger.info( " * Log URL : #{@parent_server.job_log_url}/#{new_job.id}/log", Log::LV_USER) end - BuildCommServer.send(req,"Info: Above job(s) will be processed asynchronously!") + BuildCommServer.send_end(req) + BuildCommServer.disconnect(req) # add @parent_server.jobmgr.add_job( new_job ) @@ -814,6 +815,7 @@ class SocketJobRequestListener logger = new_job.create_logger() # notify that job has been received + BuildCommServer.send(req, "=JOB_START,#{new_job.id}") logger.info( "Added new job \"#{new_job.id}\" for #{new_job.os}!", Log::LV_USER) if not @parent_server.job_log_url.empty? then logger.info( " * Log URL : #{@parent_server.job_log_url}/#{new_job.id}/log", Log::LV_USER) @@ -961,7 +963,7 @@ class SocketJobRequestListener # get package name new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3') pkg_name = new_name.split(",")[0] - +puts "========> #{filename} , #{new_name}, #{pkg_name}" prj = @parent_server.prjmgr.get_project_from_package_name(pkg_name, dist_name) if prj.nil? then raise BuildServerException.new("ERR013"), "#{pkg_name} #{dist_name}" diff --git a/test/build-server.multi_dist2/build-svr3-01.testcase b/test/build-server.multi_dist2/build-svr3-01.testcase index 224c40a..fbec6c5 100644 --- a/test/build-server.multi_dist2/build-svr3-01.testcase +++ b/test/build-server.multi_dist2/build-svr3-01.testcase @@ -3,6 +3,7 @@ ../../build-svr register -n testserver3 -D unstable -P bin/bin_0.0.0_ubuntu-32.zip #POST-EXEC #EXPECT +Info: Added new job Info: Initializing job... Info: Checking package version ... Info: Invoking a thread for REGISTER Job @@ -12,3 +13,4 @@ Info: Uploading ... Info: Upload succeeded. Sync local pkg-server again... Info: Snapshot: Info: Job is completed! +Info: Job is FINISHED successfully! diff --git a/test/build-server.multi_dist2/build-svr3-03.testcase b/test/build-server.multi_dist2/build-svr3-03.testcase index 263c627..ebdc057 100644 --- a/test/build-server.multi_dist2/build-svr3-03.testcase +++ b/test/build-server.multi_dist2/build-svr3-03.testcase @@ -19,3 +19,5 @@ Info: Uploading ... Info: Upload succeeded. Sync local pkg-server again... Info: Snapshot: Info: Job is completed! +Info: Job is FINISHED successfully! +Info: Updating the source info for project "testbin" diff --git a/test/build-server.multi_dist2/build-svr3-04.testcase b/test/build-server.multi_dist2/build-svr3-04.testcase index fe29a83..af248ff 100644 --- a/test/build-server.multi_dist2/build-svr3-04.testcase +++ b/test/build-server.multi_dist2/build-svr3-04.testcase @@ -1,8 +1,9 @@ #PRE-EXEC #EXEC -../../build-svr fullbuild -n testserver3 -D unstable2 +../../build-cli build -d 127.0.0.1:2223 -N testa,testb -o all -D unstable2 --rebuild #POST-EXEC #EXPECT +Info: Added new job Info: Initializing job... Info: Invoking a thread for MULTI-BUILD Job Info: New Job