query_job_list( result[0], result[1] )
+ when "query-log"
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+
+ client = BuildCommClient.create( result[0], result[1], nil, 0 )
+ if client.nil? then
+ puts "Connection to server failed!"
+ return nil
+ end
+ client.send "LOG|#{option[:job].strip}"
+ client.read_lines do |line|
+ puts line
+ end
+ client.terminate
+
when "cancel"
result = Utils.parse_server_addr(option[:domain])
if result.nil? then
QUERY_SYSTEM="build-cli query-system -d <server address>"
QUERY_PROJECT="build-cli query-project -d <server address>"
QUERY_JOB="build-cli query-job -d <server address>"
+ QUERY_LOG="build-cli query-log -d <server address> -j <job number>"
CANCEL="build-cli cancel -j <job number> -d <server address> [-w <password>] [-U user-email]"
REGISTER="build-cli register -P <package file> -d <server address> [-t <ftp server url>] [-w <password>] [-D <distribution name>] [-U user-email]"
end
raise ArgumentError, "Usage: " + BuildClientUsage::QUERY_JOB
end
+ when "query-log" then
+ if options[:domain].nil? or options[:domain].empty? or
+ options[:job].nil? or options[:job].empty? then
+ raise ArgumentError, "Usage: " + BuildClientUsage::QUERY_LOG
+ end
+
when "cancel" then
if options[:job].nil? or options[:job].empty? or
options[:domain].nil? or options[:domain].empty? then
+ "\t" + "query-system Query system information about build-server." + "\n" \
+ "\t" + "query-project Query project information about build-server." + "\n" \
+ "\t" + "query-job Query job information about build-server." + "\n" \
+ + "\t" + "query-log Query log contents about job in build-server." + "\n" \
+ "\t" + "cancel Cancel a building project." + "\n" \
+ "\t" + "register Register the package to the build-server." + "\n" \
+ "\n" + "Subcommand usage:" + "\n" \
+ "\t" + BuildClientUsage::QUERY_SYSTEM + "\n" \
+ "\t" + BuildClientUsage::QUERY_PROJECT + "\n" \
+ "\t" + BuildClientUsage::QUERY_JOB + "\n" \
+ + "\t" + BuildClientUsage::QUERY_LOG + "\n" \
+ "\t" + BuildClientUsage::CANCEL + "\n" \
+ "\t" + BuildClientUsage::REGISTER + "\n" \
+ "\n" + "Options:" + "\n"
if cmd.eql? "build" or #cmd.eql? "resolve" or
cmd.eql? "query" or cmd.eql? "query-system" or
cmd.eql? "query-project" or cmd.eql? "query-job" or
+ cmd.eql? "query-log" or
cmd.eql? "cancel" or
cmd.eql? "register" or
cmd =~ /(-v)|(--version)/ or
require 'fileutils'
require 'dbi'
require 'thread'
+require 'file/tail'
$LOAD_PATH.unshift File.dirname(__FILE__)
$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
require "SocketJobRequestListener.rb"
end
end
end
+
+ def query_job_log(job_number, conn)
+ @log.info "Sending job log : #{job_number}"
+
+ job = nil
+ (@jobmgr.jobs + @jobmgr.internal_jobs + @jobmgr.reverse_build_jobs).each do |manager_job|
+ if manager_job.id.eql? job_number then
+ job = manager_job
+ end
+ end
+
+ Thread.new do
+ job_log_path = File.join(@path, "jobs", job_number, "log")
+
+ if File.exist? job_log_path then
+ begin
+ File::Tail::Logfile.open(job_log_path) do |log|
+ log.tail { |line|
+ BuildCommServer.send(conn, line)
+
+ if log.eof? and (job.nil? or
+ job.status.eql? "FINISHED" or
+ job.status.eql? "ERROR" or
+ job.status.eql? "CANCELED") then
+ break
+ end
+ }
+ end
+ rescue => e
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
+ else
+ @log.error "Can't find job log file : #{job_log_path}"
+ BuildCommServer.send(conn, "Can't find job log file : #{job_number}")
+ end
+
+ BuildCommServer.send_end(conn)
+ BuildCommServer.disconnect(conn)
+ end
+ end
end
handle_cmd_register( req_line, req )
when "MONITOR"
handle_cmd_monitor( req_line, req )
+ when "LOG"
+ handle_cmd_log( req_line, req )
when "DOWNLOAD"
Thread.new do
begin
end
+ # "LOG"
+ def handle_cmd_log( line, req )
+ @log.info "Received REQ: #{line.strip}"
+
+ begin
+ handle_cmd_log_internal( line, req )
+ rescue BuildServerException => e
+ @log.error(e.message)
+ BuildCommServer.send(req, e.err_message())
+ BuildCommServer.send_end(req)
+ BuildCommServer.disconnect(req)
+ end
+
+ @log.info "Handled REQ: #{line.strip}"
+ end
+
+
def handle_cmd_monitor_internal( line, req )
tok = line.split("|").map { |x| x.strip }
if tok.count < 2 then
end
+ def handle_cmd_log_internal( line, req )
+ tok = line.split("|").map { |x| x.strip }
+ if tok.count < 2 then
+ raise BuildServerException.new("ERR001"), line
+ end
+
+ job_number = tok[1]
+ @parent_server.query_job_log(job_number, req)
+ end
+
+
# "UPLOAD"
def handle_cmd_upload( line, req )
@log.info "Received File transfer REQ : #{line}"
query-system Query system information about build-server.
query-project Query project information about build-server.
query-job Query job information about build-server.
+query-log Query log contents about job in build-server.
cancel Cancel a building project.
register Register the package to the build-server.
build-cli query-system -d <server address>
build-cli query-project -d <server address>
build-cli query-job -d <server address>
+build-cli query-log -d <server address> -j <job number>
build-cli cancel -j <job number> -d <server address> [-w <password>]
build-cli register -P <package file> -d <server address> [-t <ftp server url>] [-w <password>] [-D <distribution name>] [-U user-email]