[Title] Separated the process for remote log monitor
authordonghee yang <donghee.yang@samsung.com>
Wed, 10 Apr 2013 01:32:25 +0000 (10:32 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Wed, 10 Apr 2013 01:32:25 +0000 (10:32 +0900)
src/build_server/RemoteBuilder.rb
src/build_server/monitor_log.rb [new file with mode: 0755]

index f5e0c74a9b476964b1c6e4bfd6fe08e1e4158da6..af11c266d1c5f3038f9eccfaa7dd8d77ee19b5e3 100644 (file)
@@ -125,7 +125,12 @@ class RemoteBuilder
 
                if options[:async] then return result end
 
-               result, result_files = send_monitor_request(job_id, options[:monitor_level])
+               result_files = []
+               if Utils.is_unix_like_os(Utils::HOST_OS) then
+                       result, result_files = send_monitor_request2(job_id, options[:monitor_level])
+               else
+                       result, result_files = send_monitor_request(job_id, options[:monitor_level])
+               end
 
                if not result then
                        @log.error( "Building job on remote server failed!", Log::LV_USER )
@@ -349,6 +354,47 @@ class RemoteBuilder
                return result, result_files
        end
 
+
+       protected
+       def send_monitor_request2(job_id, min_level)
+               result_files = []
+               result = true
+               job_status = "JUST_CREATED"
+               job_errmsg = ""
+
+               ruby_path=File.join(Config::CONFIG["bindir"],
+                                                       Config::CONFIG["RUBY_INSTALL_NAME"] +
+                                                       Config::CONFIG["EXEEXT"])
+
+               if @log.path.nil? then
+                       cmd = "#{ruby_path} \"#{File.expand_path(File.dirname(__FILE__))}/monitor_log.rb\" #{@addr} #{@port} #{job_id} #{min_level}"
+               else
+                       cmd = "#{ruby_path} \"#{File.expand_path(File.dirname(__FILE__))}/monitor_log.rb\" #{@addr} #{@port} #{job_id} #{min_level} \"#{@log.path}\""
+               end
+               cmd = Utils.generate_shell_command( cmd )
+               IO.popen("#{cmd} 2>&1") do |io|
+                       if @log.path.nil? then
+                               io.each do |l|
+                                       if l.start_with?("=LOG_END") then
+                                               break
+                                       else 
+                                               puts l
+                                       end
+                               end
+                       end
+                       result, job_status, job_errmsg, result_files = Marshal.load(io.read)
+               end
+               if job_status != "FINISHED" then
+                       if not @job.nil? then 
+                               @log.error( "Remote job is finished with \"#{job_status}\"! #{job_errmsg}", Log::LV_USER)
+                       end
+                       result = false 
+               end
+
+               return result, result_files
+       end
+
+
        # receive binary package of remote server
        protected
        def receive_file_from_remote(file_path, dock = "0")
diff --git a/src/build_server/monitor_log.rb b/src/build_server/monitor_log.rb
new file mode 100755 (executable)
index 0000000..e2c9e3d
--- /dev/null
@@ -0,0 +1,90 @@
+#!/usr/bin/ruby
+=begin
+
+ monitor_log.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'logger'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) + "/common"
+require 'JobLog'
+require 'log.rb'
+require 'utils.rb'
+
+# parse arguments
+addr = ARGV[0]
+port = ARGV[1]
+job_id = ARGV[2]
+min_level = ARGV[3].to_i
+log_path = ARGV[4]
+if log_path.nil? then
+       log = StandardOutLogPrinter.new
+else
+       log = Log.new(log_path)
+end
+result_files = []
+result = true
+job_status = "JUST_CREATED"
+job_errmsg = ""
+begin
+       result = JobLog.monitor(addr, port, job_id) do |line,status,errmsg|
+               job_status = status
+               job_errmsg = errmsg
+               if line.nil? then 
+                       next 
+               end
+               if line.strip.start_with?("=JOB_FILE") then
+                       result_files.push( line.strip.split(",")[1] )
+               end
+                       
+               category, level, contents = JobLog.parse_log(line)
+               if level < min_level then next end
+               if category == "INFO" then
+                       log.info( contents, level )
+                       STDOUT.flush
+               elsif category == "WARN" then
+                       log.warn( contents, level )
+                       STDOUT.flush
+               elsif category == "ERROR" then
+                       log.error( contents, level )
+                       STDOUT.flush
+               else
+                       next
+               end
+       end
+
+rescue BuildServerException => e
+       log.error( e.err_message("") )
+       result = false
+rescue => e
+       log.error( "#{e.message()}" )
+       result = false
+end
+if log_path.nil? then
+       puts "=LOG_END"
+       STDOUT.flush
+end
+Marshal.dump([result, job_status, job_errmsg, result_files], $stdout)