[Title] [dibs] register command async
authorhataejun <taejun.ha@samsung.com>
Thu, 28 Mar 2013 04:10:19 +0000 (13:10 +0900)
committerhataejun <taejun.ha@samsung.com>
Thu, 28 Mar 2013 04:10:19 +0000 (13:10 +0900)
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

build-cli
src/build_server/SocketJobRequestListener.rb

index c34682f1feafc55f24c2965ffb23f5afa9cff05e..7982fa58ca71ed2534133cda77661fd695ebede6 100755 (executable)
--- a/build-cli
+++ b/build-cli
@@ -198,15 +198,14 @@ begin
                        result = client.read_lines do |line|
                                if line.strip.start_with?("=JOB_START") then 
                                        job_id = line.strip.split(",")[1]
-                                       next
                                elsif line.strip.start_with?("=JOB_STATUS") then 
                                        data = line.strip.split(",")
                                        job_status = data[1]
                                        job_error = data[2]
-                                       next
+                               else
+                                       # print log 
+                                       puts line
                                end
-                               # print log 
-                               puts line
                        end
 
                        if not result then
@@ -237,21 +236,20 @@ begin
                                                data = line.strip.split(",")
                                                job_status = data[1]
                                                job_error = data[2]
-                                               next
-                                       end
-
-                                       # print log 
-                                       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
+                                               # print log 
+                                               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
                                end
 
@@ -400,6 +398,12 @@ begin
                end
 
        when "register"
+               client = nil
+               result = false
+               job_id = nil
+               job_status = ""
+               job_error = ""
+
                # check file exist
                if not File.exist? option[:package] then
                        puts "The file does not exist!.. #{option[:package]}"
@@ -443,8 +447,8 @@ begin
                begin
                        dock = Utils.create_uniq_name()
                        client.send("REGISTER|BINARY|#{File.basename(option[:package])}|#{option[:passwd]}|#{dock}|#{option[:dist]}|#{option[:user]}|#{option[:noreverse]}")
-                       client.read_lines do |line|
-                               if line.eql?("WAITFORUPLOAD") then
+                       result = client.read_lines do |line|
+                               if line.strip.eql?("WAITFORUPLOAD") then
                                        # upload
                                        thread = Thread.new do
                                                begin 
@@ -458,13 +462,65 @@ begin
             
                                        thread.join
                                        client.send("REGISTERCONTINUE")
+                               elsif line.strip.start_with?("=JOB_START") then
+                                       job_id = line.strip.split(",")[1]
+                               elsif 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
+                               puts "Error: Communication failed! #{client.get_error_msg()}"
+                       elsif job_id.nil? then
+                               puts job_error
+                               result = false
+                       end
                ensure
                        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
+                                       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
+                               end
+                       ensure
+                               client.terminate
+                       end
+               end
+
+               if not result then
+                       exit 1
+               end
        else
                raise RuntimeError, "input option incorrect : #{option[:cmd]}"
        end
index a996c37b38221a0848fe7ada0566cd19907fa20e..c8a3e0eeee00c24d30b75f61ed7fc8ce2e73da89 100644 (file)
@@ -738,6 +738,14 @@ class SocketJobRequestListener
                        BuildCommServer.send_end(req)
                        BuildCommServer.disconnect(req)
 
+                       BuildCommServer.send(req, "=JOB_START,#{new_job.id}")
+                       BuildCommServer.send(req,"Info: Added new job \"#{new_job.id}\" for #{new_job.os}!")
+                       if not @parent_server.job_log_url.empty? then
+                               BuildCommServer.send(req,"Info:  * Log URL : #{@parent_server.job_log_url}/#{new_job.id}/log")
+                       end
+            
+                       BuildCommServer.send(req,"Info: Above job(s) will be processed asynchronously!")
+
                        # add
                        @parent_server.jobmgr.add_job( new_job )
 
@@ -790,7 +798,7 @@ class SocketJobRequestListener
 
                        # create new job
                        @log.info "Received a request for uploading binaries : #{filename}"
-                       new_job = create_new_upload_job( prj.name, filename, dock, dist_name, req )
+                       new_job = create_new_upload_job( prj.name, filename, dock, dist_name )
                        if new_job.nil? then
                                raise BuildServerException.new("ERR006"), "Register-job #{filename}, #{prj.name}, #{dist_name}"
                        end
@@ -1053,7 +1061,7 @@ class SocketJobRequestListener
 
 
        private
-       def create_new_upload_job( project_name, filename, dock, dist_name, req)
+       def create_new_upload_job( project_name, filename, dock, dist_name)
 
                return @parent_server.prjmgr.get_project(project_name, dist_name).create_new_job(filename, dock)
        end