From: donghee yang Date: Thu, 11 Apr 2013 08:14:54 +0000 (+0900) Subject: [Title] Separate the process for client's file tranfer call X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=05a514015f35e9600a9b39bceeb6ca9e3119f537;p=sdk%2Ftools%2Fsdk-build.git [Title] Separate the process for client's file tranfer call --- diff --git a/src/build_server/RemoteBuilder.rb b/src/build_server/RemoteBuilder.rb index af11c26..9340c51 100644 --- a/src/build_server/RemoteBuilder.rb +++ b/src/build_server/RemoteBuilder.rb @@ -101,7 +101,11 @@ class RemoteBuilder @job.get_remote_server().add_file_transfer() options[:local_pkgs].each do |pkg_path| @log.info( "Sending file... : #{pkg_path}", Log::LV_USER ) - result = send_file_to_remote( pkg_path, options[:dock] ) + if Utils.is_unix_like_os(Utils::HOST_OS) then + result = send_file_to_remote2( pkg_path, options[:dock] ) + else + result = send_file_to_remote( pkg_path, options[:dock] ) + end if not result then @log.error( "File transfering failed!", Log::LV_USER ) @job.get_remote_server().remove_file_transfer() @@ -155,7 +159,11 @@ class RemoteBuilder if options[:save] then result_files.each do |file_name| @log.info( "Receiving file from remote server : #{file_name}", Log::LV_USER ) - result = receive_file_from_remote( "#{options[:src_path]}/#{file_name}", options[:dock] ) + if Utils.is_unix_like_os(Utils::HOST_OS) then + result = receive_file_from_remote2( "#{options[:src_path]}/#{file_name}", options[:dock] ) + else + result = receive_file_from_remote( "#{options[:src_path]}/#{file_name}", options[:dock] ) + end if not result then @log.error( "File transfering failed! : #{file_name}", Log::LV_USER ) return false @@ -225,6 +233,50 @@ class RemoteBuilder end + protected + def send_file_to_remote2(file_path, dock = "0") + result = true + + ruby_path=File.join(Config::CONFIG["bindir"], + Config::CONFIG["RUBY_INSTALL_NAME"] + + Config::CONFIG["EXEEXT"]) + + if @ftp_addr.nil? then + ftp_addr = "0" + ftp_port = "0" + ftp_username = "0" + ftp_passwd = "0" + else + ftp_addr = @ftp_addr + ftp_port = @ftp_port + ftp_username = @ftp_username + ftp_passwd = @ftp_passwd + end + + if @log.path.nil? then + cmd = "#{ruby_path} \"#{File.expand_path(File.dirname(__FILE__))}/send_file.rb\" #{@addr} #{@port} #{dock} \"#{file_path}\" #{ftp_addr} #{ftp_port} #{ftp_username} #{ftp_passwd}" + else + cmd = "#{ruby_path} \"#{File.expand_path(File.dirname(__FILE__))}/send_file.rb\" #{@addr} #{@port} #{dock} \"#{file_path}\" #{ftp_addr} #{ftp_port} #{ftp_username} #{ftp_passwd} \"#{@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?("=TRANSFER_END") then + break + else + puts l + end + end + end + result = Marshal.load(io.read) + end + + return result + end + + # send build request protected def send_build_request( options ) @@ -426,4 +478,47 @@ class RemoteBuilder return result end + + + protected + def receive_file_from_remote2(file_path, dock = "0") + result = true + + ruby_path=File.join(Config::CONFIG["bindir"], + Config::CONFIG["RUBY_INSTALL_NAME"] + + Config::CONFIG["EXEEXT"]) + + if @ftp_addr.nil? then + ftp_addr = "0" + ftp_port = "0" + ftp_username = "0" + ftp_passwd = "0" + else + ftp_addr = @ftp_addr + ftp_port = @ftp_port + ftp_username = @ftp_username + ftp_passwd = @ftp_passwd + end + + if @log.path.nil? then + cmd = "#{ruby_path} \"#{File.expand_path(File.dirname(__FILE__))}/receive_file.rb\" #{@addr} #{@port} #{dock} \"#{file_path}\" #{ftp_addr} #{ftp_port} #{ftp_username} #{ftp_passwd}" + else + cmd = "#{ruby_path} \"#{File.expand_path(File.dirname(__FILE__))}/receive_file.rb\" #{@addr} #{@port} #{dock} \"#{file_path}\" #{ftp_addr} #{ftp_port} #{ftp_username} #{ftp_passwd} \"#{@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?("=TRANSFER_END") then + break + else + puts l + end + end + end + result = Marshal.load(io.read) + end + + return result + end end diff --git a/src/build_server/receive_file.rb b/src/build_server/receive_file.rb new file mode 100755 index 0000000..816be53 --- /dev/null +++ b/src/build_server/receive_file.rb @@ -0,0 +1,93 @@ +#!/usr/bin/ruby +=begin + + send_file.rb + +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + +Contact: +Taejun Ha +Jiil Hyoun +Donghyuk Yang +DongHee Yang + +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' +require "FileTransferViaFTP" +require "FileTransferViaDirect" + +# parse arguments +addr = ARGV[0] +port = ARGV[1] +dock = ARGV[2] +file_path = ARGV[3] +file_path = ARGV[3] +ftp_addr = ARGV[4] +ftp_port = ARGV[5] +ftp_username = ARGV[6] +ftp_passwd = ARGV[7] +log_path = ARGV[8] +if log_path.nil? then + log = StandardOutLogPrinter.new +else + log = Log.new(log_path) +end + +begin + # create client + client = BuildCommClient.create( addr, port, log ) + if client.nil? then + log.error( "Creating communication client failed!", Log::LV_USER) + return false + end + + # download file + result = true + file_name = file_path.split("/")[-1] + msg = "DOWNLOAD|#{dock}|#{file_name}" + if client.send( msg ) then + if ftp_addr != "0" then + transporter=FileTransferFTP.new(log, ftp_addr, ftp_port, ftp_username, ftp_passwd) + else + transporter=FileTransferDirect.new(log) + end + result=client.receive_file(file_path, transporter) + if not result then + log.error( "File downloading failed...#{file_name}", Log::LV_USER) + end + end +rescue => e + log.error( "#{e.message()}" ) + result = false +ensure + #close connections + client.terminate if not client.nil? + + # send result + if log_path.nil? then + puts "=TRANSFER_END" + STDOUT.flush + end + Marshal.dump(result, $stdout) +end + diff --git a/src/build_server/send_file.rb b/src/build_server/send_file.rb new file mode 100755 index 0000000..b52fc8c --- /dev/null +++ b/src/build_server/send_file.rb @@ -0,0 +1,94 @@ +#!/usr/bin/ruby +=begin + + send_file.rb + +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + +Contact: +Taejun Ha +Jiil Hyoun +Donghyuk Yang +DongHee Yang + +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' +require "FileTransferViaFTP" +require "FileTransferViaDirect" + + +# parse arguments +addr = ARGV[0] +port = ARGV[1] +dock = ARGV[2] +file_path = ARGV[3] +ftp_addr = ARGV[4] +ftp_port = ARGV[5] +ftp_username = ARGV[6] +ftp_passwd = ARGV[7] +log_path = ARGV[8] +if log_path.nil? then + log = StandardOutLogPrinter.new +else + log = Log.new(log_path) +end + +begin + # create client + client = BuildCommClient.create( addr, port, log ) + if client.nil? then + log.error( "Creating communication client failed!", Log::LV_USER) + return false + end + + # upload file + file_name = file_path.split("/")[-1] + msg = "UPLOAD|#{dock}" + if client.send( msg ) then + if ftp_addr != "0" then + transporter=FileTransferFTP.new(log, ftp_addr, ftp_port, ftp_username, ftp_passwd) + else + transporter=FileTransferDirect.new(log) + end + + result=client.send_file( file_path, transporter ) + if not result then + log.error( "File uploading failed...#{file_name}", Log::LV_USER) + end + end + +rescue => e + log.error( "#{e.message()}" ) + result = false +ensure + #close connections + client.terminate if not client.nil? + + # send result + if log_path.nil? then + puts "=TRANSFER_END" + STDOUT.flush + end + Marshal.dump(result, $stdout) +end + diff --git a/test/build-server.multi-svr1/03.testcase b/test/build-server.multi-svr1/03.testcase new file mode 100644 index 0000000..30344d3 --- /dev/null +++ b/test/build-server.multi-svr1/03.testcase @@ -0,0 +1,21 @@ +#PRE-EXEC +../../build-svr set-attr -n testserver3 -A MAX_WORKING_JOBS -V 1 +#EXEC +../../build-cli build -N testa,testb -d 127.0.0.1:2223 -o ubuntu-32 -D unstable --rebuild +#POST-EXEC +../../build-svr set-attr -n testserver3 -A MAX_WORKING_JOBS -V 0 +#EXPECT +Info: Added new job +Info: Initializing job... +Info: Invoking a thread for MULTI-BUILD Job +Info: New Job +Info: Added new job "testa" for ubuntu-32! +Info: Added new job "testb" for ubuntu-32! +Info: * Sub-Job "testa(ubuntu-32)" has entered "REMOTE_WORKING" state. +Info: * Sub-Job "testa(ubuntu-32)" has entered "FINISHED" state. +Info: * Sub-Job "testb(ubuntu-32)" has entered "REMOTE_WORKING" state. +Info: * Sub-Job "testb(ubuntu-32)" has entered "FINISHED" state. +Info: Uploading ... +Info: Upload succeeded. Sync local pkg-server again... +Info: Snapshot: +Info: Job is completed! diff --git a/test/build-server.multi-svr1/testsuite b/test/build-server.multi-svr1/testsuite index 960eff3..ef78fb7 100644 --- a/test/build-server.multi-svr1/testsuite +++ b/test/build-server.multi-svr1/testsuite @@ -1,2 +1,3 @@ 01.testcase 02.testcase +03.testcase