[Title] Fixed "REGISTER" to show log correctly
authordonghee yang <donghee.yang@samsung.com>
Thu, 28 Mar 2013 09:43:21 +0000 (18:43 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Thu, 28 Mar 2013 09:43:21 +0000 (18:43 +0900)
build-cli
src/build_server/BuildServerController.rb
src/build_server/BuildServerException.rb
src/build_server/JobLog.rb
src/build_server/SocketJobRequestListener.rb
test/build-server.multi_dist2/build-svr3-01.testcase
test/build-server.multi_dist2/build-svr3-03.testcase
test/build-server.multi_dist2/build-svr3-04.testcase

index 7982fa58ca71ed2534133cda77661fd695ebede6..6b66de9b622051123493c5ea19331c974e1a8937 100755 (executable)
--- 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
index 97b595bc8978e629fe7cfed8b0ae563e0fe9dd03..9dfd6a7bf39ef144ac64d1e5078c896831d76e63 100644 (file)
@@ -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
index 8ab47e4405fb59dc8d5e4c586c5451371e0f4a48..deb0d9fea0d925b48b6d0358a7932ef9a3f9becc 100644 (file)
@@ -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!"
        }
index 46780f3c76da8ccedf50c0e2f014c243a56dd68a..488c4d1852446e59d1a323dbdf807779109ff029 100644 (file)
@@ -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
index 1f2388846e0df305952963c68371cea1a2436f38..39b17f2ec35b7d7b3dbcb31f1f5835f73bea0c88 100644 (file)
@@ -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}"
index 224c40a8133dd8110d2f4e328fd6d9061004a3e2..fbec6c51b36546a91d4754b8cbe804e43bbea9e1 100644 (file)
@@ -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!
index 263c627384453bc4119935a1b15cf9b39d1f4f9a..ebdc057ca4cf2ffdcd4647ff90b90e74c273b028 100644 (file)
@@ -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"
index fe29a83576ac4ab817370a9c6a78ebf558829ff7..af248ffdd5eaaf31042f3188f3b7a4590518c48c 100644 (file)
@@ -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