2013-07-03 sources upload tizen_2.2 2.2.1_release
authordonghee yang <donghee.yang@samsung.com>
Wed, 3 Jul 2013 05:51:34 +0000 (14:51 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Wed, 3 Jul 2013 05:51:34 +0000 (14:51 +0900)
Change-Id: Ib1624efc670f0bf8d77ffe04b5feae792bbaedb1

160 files changed:
build-cli
build-svr
dibs-web/Gemfile
dibs-web/Gemfile.lock
dibs-web/app/controllers/admin_controller.rb
dibs-web/app/controllers/admin_distribution_controller.rb
dibs-web/app/controllers/admin_group_controller.rb
dibs-web/app/controllers/admin_project_controller.rb
dibs-web/app/controllers/admin_server_controller.rb
dibs-web/app/controllers/admin_user_controller.rb
dibs-web/app/controllers/application_controller.rb
dibs-web/app/controllers/jobs_controller.rb
dibs-web/app/controllers/projects_controller.rb
dibs-web/app/controllers/utils.rb
dibs-web/app/models/job.rb
dibs-web/app/models/project.rb
dibs-web/app/models/user.rb
dibs-web/config/routes.rb
dibs-web/public/index.html
dibs-web/public/javascripts/admin-distribution-modify.js
dibs-web/public/javascripts/admin-distribution.js
dibs-web/public/javascripts/admin-group-add.js
dibs-web/public/javascripts/admin-group-modify.js
dibs-web/public/javascripts/admin-group.js
dibs-web/public/javascripts/admin-project-add.js
dibs-web/public/javascripts/admin-project-modify.js
dibs-web/public/javascripts/admin-project.js
dibs-web/public/javascripts/admin-server-add.js
dibs-web/public/javascripts/admin-server-modify.js
dibs-web/public/javascripts/admin-server-remove.js
dibs-web/public/javascripts/admin-server.js
dibs-web/public/javascripts/admin-user-modify.js
dibs-web/public/javascripts/admin-user.js
dibs-web/public/javascripts/build.js
dibs-web/public/javascripts/dibs-api.js
dibs-web/public/javascripts/jobs.js
dibs-web/public/javascripts/log.js
dibs-web/public/javascripts/main.js
dibs-web/public/javascripts/projects.js
dibs-web/public/javascripts/session.js
dibs-web/public/upload.html
package/changelog
package/pkginfo.manifest
pkg-build
pkg-clean
pkg-cli
src/build_server/BinaryUploadProject.rb
src/build_server/BuildClientOptionParser.rb
src/build_server/BuildJob.rb
src/build_server/BuildServer.rb
src/build_server/BuildServerController.rb
src/build_server/BuildServerException.rb
src/build_server/BuildServerOptionParser.rb
src/build_server/CommonJob.rb
src/build_server/CommonProject.rb
src/build_server/GitBuildJob.rb
src/build_server/GitBuildProject.rb
src/build_server/JobLog.rb
src/build_server/JobManager.rb
src/build_server/MultiBuildJob.rb
src/build_server/PackageSync.rb
src/build_server/ProjectManager.rb
src/build_server/RegisterPackageJob.rb
src/build_server/RemoteBuilder.rb
src/build_server/ReverseBuildChecker.rb
src/build_server/SocketJobRequestListener.rb
src/build_server/monitor_log.rb [new file with mode: 0755]
src/build_server/receive_file.rb [new file with mode: 0755]
src/build_server/send_file.rb [new file with mode: 0755]
src/builder/Builder.rb
src/common/BuildComm.rb
src/common/FileTransferViaDirect.rb
src/common/FileUtil.rb [new file with mode: 0644]
src/common/PropertyParser.rb [new file with mode: 0644]
src/common/execute_with_log.rb
src/common/log.rb
src/common/model/Property.rb [new file with mode: 0644]
src/common/package.rb
src/common/utils.rb
src/pkg_server/ChangeLogController.rb [new file with mode: 0644]
src/pkg_server/PackageServerConstants.rb [new file with mode: 0644]
src/pkg_server/SnapshotController.rb [new file with mode: 0644]
src/pkg_server/client.rb
src/pkg_server/clientOptParser.rb
src/pkg_server/distribution.rb
src/pkg_server/downloader.rb
src/pkg_server/model/distribution.rb [new file with mode: 0644]
src/pkg_server/model/snapshot.rb [new file with mode: 0644]
src/pkg_server/packageServer.rb
src/pkg_server/packageServerConfig.rb
src/pkg_server/packageServerLog.rb [deleted file]
src/pkg_server/serverOptParser.rb
test/build-server.basic1/build-cli-01.testcase
test/build-server.basic1/build-cli-03.testcase
test/build-server.basic1/build-cli-04.testcase
test/build-server.basic1/build-cli-05.testcase
test/build-server.basic1/build-cli-06.testcase
test/build-server.basic1/build-cli-07.testcase
test/build-server.basic1/build-cli-08.testcase
test/build-server.basic1/build-cli-09.testcase
test/build-server.basic1/build-cli-10.testcase
test/build-server.basic1/build-cli-11.testcase
test/build-server.basic1/build-cli-12.testcase
test/build-server.basic1/build-cli-12_1.testcase
test/build-server.basic1/build-cli-13.testcase
test/build-server.basic1/build-cli-14.testcase
test/build-server.basic1/build-cli-15.testcase
test/build-server.basic1/build-cli-16.testcase
test/build-server.basic1/build-cli-17.testcase
test/build-server.basic1/build-cli-18.testcase
test/build-server.basic1/build-cli-22.testcase
test/build-server.basic1/build-cli-23.testcase
test/build-server.basic1/build-cli-24.testcase
test/build-server.basic1/build-cli-25.testcase
test/build-server.basic1/build-cli-26.testcase
test/build-server.basic1/build-cli-27.testcase
test/build-server.basic1/build-cli-28.testcase
test/build-server.basic1/build-cli-29.testcase
test/build-server.basic1/build-cli-30.testcase
test/build-server.basic1/build-cli-31.testcase [new file with mode: 0644]
test/build-server.basic1/build-cli-32.testcase [new file with mode: 0644]
test/build-server.basic1/build-cli-33.testcase [new file with mode: 0644]
test/build-server.basic1/build-cli-34.testcase [new file with mode: 0644]
test/build-server.basic1/build-cli-35.testcase [new file with mode: 0644]
test/build-server.basic1/build-cli-36.testcase [new file with mode: 0644]
test/build-server.basic1/build-cli-37.testcase [new file with mode: 0644]
test/build-server.basic1/build-cli-38.testcase [new file with mode: 0644]
test/build-server.basic1/buildsvr.init
test/build-server.basic1/testsuite
test/build-server.basic2/build-svr-02.testcase
test/build-server.basic2/build-svr-03.testcase
test/build-server.basic2/build-svr-05.testcase
test/build-server.basic2/build-svr-06.testcase
test/build-server.basic2/build-svr-11.testcase
test/build-server.basic2/build-svr-13.testcase
test/build-server.basic2/build-svr-14.testcase
test/build-server.basic2/build-svr-17.testcase
test/build-server.basic2/build-svr-18.testcase
test/build-server.basic2/build-svr-19.testcase
test/build-server.basic2/build-svr-20.testcase
test/build-server.basic2/build-svr-21.testcase
test/build-server.basic2/build-svr-23.testcase [new file with mode: 0644]
test/build-server.basic2/build-svr-24.testcase [new file with mode: 0644]
test/build-server.basic2/build-svr-25.testcase [new file with mode: 0644]
test/build-server.basic2/testsuite
test/build-server.multi-svr1/01.testcase
test/build-server.multi-svr1/02.testcase
test/build-server.multi-svr1/03.testcase [new file with mode: 0644]
test/build-server.multi-svr1/buildsvr2.init
test/build-server.multi-svr1/testsuite
test/build-server.multi_dist1/build-svr2-01.testcase
test/build-server.multi_dist2/build-svr3-01.testcase
test/build-server.multi_dist2/build-svr3-02.testcase
test/build-server.multi_dist2/build-svr3-03.testcase
test/build-server.multi_dist2/build-svr3-04.testcase
test/build-server.multi_dist2/build-svr3-05.testcase
test/build-server.multi_dist2/build-svr3-06.testcase [new file with mode: 0644]
test/build-server.multi_dist2/testsuite
test/test_client.rb
upgrade

index e6120db..494d209 100755 (executable)
--- a/build-cli
+++ b/build-cli
@@ -37,6 +37,9 @@ require "BuildClientOptionParser"
 require "BuildComm"
 require "FileTransferViaFTP"
 require "FileTransferViaDirect"
+require "JobLog"
+require "BuildServerException"
+require "RemoteBuilder"
 
 
 #option parsing
@@ -44,14 +47,20 @@ begin
        option = option_parse
 rescue => e
        puts e.message
-       exit 0
+       exit 1
 end
 
 
 # check HOST OS
 if not Utils.check_host_OS() then
-       puts "Error: Your host OS is not supported!"
-       exit 1
+
+       if Utils.is_linux_like_os Utils::HOST_OS then
+               Utils.set_default_linux_host_os
+               puts "Warning: Your host OS is not supported!\nWe assume your host OS as #{Utils::HOST_OS} !!!"
+       else
+               puts "Error: Your host OS is not supported!"
+               exit 1
+       end
 end
 
 def query( ip, port, sym )
@@ -139,18 +148,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
 
@@ -168,41 +180,40 @@ end
 begin
        case option[:cmd]
        when "build"
-               result = Utils.parse_server_addr(option[:domain])
-               if result.nil? then
+               client = nil
+               result = false
+               job_id = nil
+               job_status = ""
+               job_error = ""
+
+               addr = Utils.parse_server_addr(option[:domain])
+               if addr.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 not client.nil? then
-                       client.send "BUILD|GIT|#{option[:project]}|#{option[:passwd]}|#{option[:os]}|#{option[:async]}|#{option[:noreverse]}|#{option[:dist]}|#{option[:user]}|#{option[:verbose]}"
-                       if not client.print_stream then
-                               puts "ERROR: #{client.get_error_msg()}"
-                       end
 
-                       client.terminate
-               else
-                       puts "Connection to server failed!"
-                       exit 1
+               builder = RemoteBuilder.new(addr[0], addr[1], nil, nil, nil, nil)
+               options = RemoteBuilder.init_options()
+               options[:projects] = option[:project]
+               options[:passwd] = option[:passwd]
+               options[:os] =  option[:os]
+               options[:noreverse] = (option[:noreverse] == "YES") ? true : false
+               options[:dist] = option[:dist]
+               options[:user] = option[:user]
+               options[:rebuild] = (option[:rebuild] == "YES") ? true : false
+               options[:async] = (option[:async] == "YES") ? true : false
+               options[:monitor_level] = Log::LV_USER
+               options[:save] = option[:save]
+               if options[:save] then
+                       options[:dock] = Utils.create_uniq_name()
+                       options[:src_path] = Utils::WORKING_DIR
                end
-#      when "resolve"
-#              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 not client.nil? then
-#                      client.send "RESOLVE|GIT|#{option[:project]}|#{option[:passwd]}|#{option[:os]}|#{option[:async]}|#{option[:dist]}|#{option[:user]}|#{option[:verbose]}"
-#                      if not client.print_stream then
-#                              puts "ERROR: #{client.get_error_msg()}"
-#                      end
-#                      client.terminate
-#              end
+               result = builder.build(options)
+
+               if not result then exit(-1) end
+
        when "query"
                result = Utils.parse_server_addr(option[:domain])
                if result.nil? then
@@ -251,6 +262,72 @@ begin
 
                query_job_list( result[0], result[1] )
 
+       when "query-log"
+               result = false
+               addr = Utils.parse_server_addr(option[:domain])
+               if addr.nil? then
+                       puts "Server address is incorrect. (#{option[:domain]})"
+                       puts "Tune as following format."
+                       puts " <ip>:<port>"
+                       exit 1
+               end
+               output = option[:output]
+               flock = "ON"
+
+               begin
+                       if output.nil? then
+                               log = STDOUT
+                       else
+                               if File.exist? output
+                                       raise RuntimeError, "The output file is already exist."
+                               end
+
+                               log = File.open(output, "w")
+                               if not log.flock(File::LOCK_EX|File::LOCK_NB) then
+                                       raise RuntimeError, "The output file is already exist."
+                               end
+                               log.sync = true
+                               puts "Started query log, writing to the file \"#{output}\""
+                       end
+
+                       result = JobLog.monitor(addr[0], addr[1], option[:job].strip) do |line,status,errmsg|
+                               if line.nil? then 
+                                       next 
+                               end
+
+                               if line.eql? "=LOG_ERROR" then
+                                       result = false
+                               end
+
+                               log.puts line
+                               if not output.nil? and flock.eql? "ON" then
+                                       log.flock(File::LOCK_UN)
+                                       flock = "OFF"
+                               end
+                       end
+                       if result and not output.nil? then
+                               log.puts "=LOG_END"
+                               puts "End query log, check file \"#{output}\""
+                       end
+               rescue BuildServerException => e
+                       log.puts e.err_message()
+                       result = false
+               rescue => e
+                       puts "ERROR: #{e}"
+                       puts e.backtrace.inspect
+                       result = false
+               ensure
+                       if not output.nil? then
+                               log.close if not log.nil?
+                       end
+               end
+
+               if not result then
+                       puts "Fail query-log #{option[:job]}."
+                       FileUtils.rm output if not output.nil?
+                       exit(1)
+               end
+
        when "cancel"
                result = Utils.parse_server_addr(option[:domain])
                if result.nil? then
@@ -280,6 +357,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]}"
@@ -323,8 +406,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 
@@ -338,13 +421,67 @@ 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
+
+               if not result then exit(1) end
+
+               # Query log in case sync
+               begin
+                       result = JobLog.monitor(bs_ip, bs_port, job_id) do |line,status,errmsg|
+                               job_status = status
+                               job_error = errmsg
+                               if line.nil? then 
+                                       next 
+                               end
+
+                               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
+
+                       # Check job status
+                       if not job_status.eql? "FINISHED" then
+                               result = false
+                       end
+               rescue BuildServerException => e
+                       puts e.err_message()
+                       result = false
+               rescue  => e
+                       puts "ERROR: #{e}"
+                       result = false
+               end
+
+               if not result then exit(-1) end
+
        else
                raise RuntimeError, "input option incorrect : #{option[:cmd]}"
        end
index 12306e9..db67cba 100755 (executable)
--- a/build-svr
+++ b/build-svr
@@ -46,8 +46,14 @@ end
 
 # check HOST OS
 if not Utils.check_host_OS() then
-       puts "Error: Your host OS is not supported!"
-       exit 1
+
+       if Utils.is_linux_like_os Utils::HOST_OS then
+               Utils.set_default_linux_host_os
+               puts "Warning: Your host OS is not supported!\nWe assume your host OS as #{Utils::HOST_OS} !!!"
+       else
+               puts "Error: Your host OS is not supported!"
+               exit 1
+       end
 end
 
 begin
@@ -84,10 +90,17 @@ begin
                        log = Log.new( "#{BuildServer::CONFIG_ROOT}/#{option[:name]}/main.log" )
                        begin
                                while(true)
-                                       log.info "Build Server[#{option[:name]}] Start - PORT:[#{option[:port]}]"
+                                       log.info "Build Server[#{option[:name]}] Start - PORT: [#{option[:port]}]"
+                                       
+                                       # set port option
+                                       port_option = ((option[:port] != "") and (option[:port] != nil)) ? "-p #{option[:port]}" : ""                                   
+
                                        # Start child process
-                                       cmd = Utils.generate_shell_command("#{File.dirname(__FILE__)}/build-svr start -n #{option[:name]} -p #{option[:port]} --CHILD")
-                                       IO.popen(cmd)
+                                       cmd = Utils.generate_shell_command("#{File.dirname(__FILE__)}/build-svr start -n #{option[:name]} #{port_option} --CHILD")
+                                       
+                                       io = IO.popen(cmd) 
+                                       puts io.readlines()
+                               
                                        pid = Process.wait
 
                                        # End chlid process
@@ -96,11 +109,11 @@ begin
                                                log.info "Down Build Server."
                                                break
                                        elsif ($?.exitstatus == 99) then # DIBS UPGRADE
-                                               cmd = "#{File.dirname(__FILE__)}/upgrade -l #{File.dirname(__FILE__)} -S -t BUILDSERVER -n #{option[:name]} -p #{option[:port]}"
+                                               cmd = "#{File.dirname(__FILE__)}/upgrade -l #{File.dirname(__FILE__)} -S -t BUILDSERVER -n #{option[:name]} #{port_option}"
                                                if File.exist? "#{BuildServer::CONFIG_ROOT}/#{option[:name]}/upgrade_dist" then
                                                        File.open("#{BuildServer::CONFIG_ROOT}/#{option[:name]}/upgrade_dist","r") do |f|
                                                                f.each_line do |l|
-                                                                       cmd += " -D #{l.strip}"
+                                                                       cmd += " -u #{l.strip}"
                                                                        break
                                                                end
                                                        end
@@ -114,6 +127,7 @@ begin
                                                log.info "Down Build Server for DIBS upgrade."
                                                break
                                        else
+                                         log.error("Exit value : #{$?.exitstatus}")
                                                log.error "Down Build Server. Try reboot Build Server."
                                        end
                                end
@@ -127,19 +141,9 @@ begin
        when "upgrade"
                if not (option[:dist].nil? or option[:dist].empty?) then
                        build_server = BuildServerController.get_server(option[:name])
-                       # distribution check
-                       if not build_server.distmgr.get_distribution(option[:dist]).nil? then
-                               File.open("#{BuildServer::CONFIG_ROOT}/#{option[:name]}/upgrade_dist","w") do |f|
-                                       f.puts option[:dist]
-                               end
-                       else
-                               puts "Distribution \"#{option[:dist]}\" is not exits"
-                               puts "Upgrade Failed!!"
-                               exit 1
-                       end
                end
 
-               BuildServerController.upgrade_server( option[:name] )
+               BuildServerController.upgrade_server( option[:name], option[:url], option[:dist] )
 
        when "add-svr"
                svr_result = Utils.parse_server_addr(option[:domain])
@@ -192,19 +196,16 @@ begin
        when "add-prj"
                if not option[:git].nil? then
                        BuildServerController.add_project( option[:name], option[:pid],
-                                                                                         option[:git], option[:branch], option[:remote], option[:passwd],
+                                                                                         option[:git], option[:branch], option[:remote], 
                                                                                          option[:os], option[:dist] )
                else
                        BuildServerController.add_binary_project( option[:name], option[:pid],
-                                                                                                        option[:package], option[:passwd], option[:os], option[:dist] )
+                                                                                                        option[:package], option[:os], option[:dist] )
                end
 
        when "remove-prj"
                BuildServerController.remove_project( option[:name], option[:pid], option[:dist] )
 
-       when "fullbuild"
-               BuildServerController.build_all_projects( option[:name], option[:dist] )
-
        when "register"
                BuildServerController.register_package( option[:name], option[:package], option[:dist] )
 
index cfe9b05..47512b4 100644 (file)
@@ -5,8 +5,6 @@ gem 'rails', '3.2.8'
 # Bundle edge Rails instead:
 # gem 'rails', :git => 'git://github.com/rails/rails.git'
 
-gem 'sqlite3'
-
 gem 'json'
 
 gem 'execjs'
index d4f7f1a..2f3f71c 100644 (file)
@@ -90,7 +90,6 @@ GEM
       hike (~> 1.2)
       rack (~> 1.0)
       tilt (~> 1.1, != 1.3.0)
-    sqlite3 (1.3.6)
     thor (0.16.0)
     tilt (1.3.3)
     treetop (1.4.10)
@@ -114,5 +113,4 @@ DEPENDENCIES
   mysql2 (> 0.3)
   rails (= 3.2.8)
   sass-rails (~> 3.2.3)
-  sqlite3
   uglifier (>= 1.0.3)
index c6ea473..c97a5e9 100644 (file)
@@ -31,7 +31,9 @@ class AdminController < ApplicationController
        before_filter :check_login_status, :check_admin_group
 
        def queryAllOS
-               os_list = SupportedOs.find_by_sql("SELECT supported_os.name AS os_name
+               os_list = SupportedOs.find_by_sql("SELECT supported_os.id AS os_id
+                                                                                               , supported_os.name AS os_name
+                                                                                               , os_category.id AS category_id
                                                                                                , os_category.name AS category_name
                                                                                         FROM supported_os
                                                                                                , os_category
@@ -45,8 +47,10 @@ class AdminController < ApplicationController
                        doc.Data {
                                os_list.each do |os|
                                        doc.OS {
-                                               doc.OsName(os.os_name)
-                                               doc.OsCategory(os.category_name)
+                                               doc.Id(os.os_id)
+                                               doc.Name(os.os_name)
+                                               doc.CategoryId(os.category_id)
+                                               doc.CategoryName(os.category_name)
                                        }
                                end
                        }
@@ -65,7 +69,10 @@ class AdminController < ApplicationController
 
                        doc.Data {
                                os_category_list.each do |category|
-                                       doc.OsCategoryName(category.name)
+                                       doc.OsCategory{
+                                               doc.Id(category.id)
+                                               doc.Name(category.name)
+                                       }
                                end
                        }
                }
index aa91a87..00b5ad4 100644 (file)
@@ -31,22 +31,22 @@ class AdminDistributionController < ApplicationController
        before_filter :check_login_status, :check_admin_group
 
        def queryDistributionInfo
-               dist_name = params[:distribution]
+               dist_id = params[:distId]
 
-               if dist_name.nil? or dist_name.empty? 
-                       render :text => "Distribution name is empty", :content_type => "text/xml", :status => 406
+               if dist_id.nil? or dist_id.empty? 
+                       render :text => "Distribution id is empty", :content_type => "text/xml", :status => 406
                        return
                end
 
                # get distribution 
-               distribution = Distribution.find(:first, :conditions => ["name = ?", dist_name])
+               distribution = Distribution.find(:first, :conditions => ["id = ?", dist_id])
                if distribution.nil? 
-                       render :text => "Can't find distribution : #{dist_name}", :content_type => "text/xml", :status => 406
+                       render :text => "Can't find distribution: [#{dist_id}]", :content_type => "text/xml", :status => 406
                        return
                end
 
                # get sync package server 
-               sync_package_server = SyncPkgServer.find(:first, :conditions => ["distribution_id = ?", distribution.id])
+               sync_package_server = SyncPkgServer.find(:first, :conditions => ["distribution_id = ?", dist_id])
 
                doc = Builder::XmlMarkup.new( :target => out_string = "", :indent => 2 )
                doc.Response {
@@ -55,7 +55,8 @@ class AdminDistributionController < ApplicationController
                        #generate to XML
                        doc.Data{
                                doc.DistributionInfo{
-                                       doc.DistributionName(distribution.name)
+                                       doc.Id(distribution.id)
+                                       doc.Name(distribution.name)
                                        doc.PackageServerUrl(distribution.pkgsvr_url)
                                        doc.PackageServerAddress(distribution.pkgsvr_addr)
                                        doc.Status(distribution.status)
@@ -87,7 +88,7 @@ class AdminDistributionController < ApplicationController
                
                dist_name = change_item[:DistributionName]
                if dist_name.nil? or dist_name.empty? then
-                       errmsg = "Can't find [#{dist_name}] information"
+                       errmsg = "Distribution name is empty"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
@@ -95,7 +96,7 @@ class AdminDistributionController < ApplicationController
                dist = Distribution.find(:first, :conditions => ["name = ?", dist_name])
                if dist.nil?
                        dist = Distribution.new
-                       dist.name = change_item[:DistributionName]
+                       dist.name = dist_name
                        dist.pkgsvr_url = change_item[:URL]
                        dist.pkgsvr_addr = change_item[:Address]
                        dist.status = change_item[:DistStatus]
@@ -109,7 +110,7 @@ class AdminDistributionController < ApplicationController
                        sync_pkg_svr.description = change_item[:SyncPkgSvrDescription]
                        sync_pkg_svr.save
                else
-                       errmsg = "Distribution[#{dist_name}] already exist"
+                       errmsg = "Distribution [#{dist_name}] already exist"
                end
 
                if errmsg.empty?
@@ -124,16 +125,16 @@ class AdminDistributionController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
                
-               dist_name = change_item[:DistributionName]
-               if dist_name.nil? or dist_name.empty? then
-                       errmsg = "Can't find [#{dist_name}] information"
+               dist_id = change_item[:DistributionId]
+               if dist_id.nil? or dist_id.empty? then
+                       errmsg = "Distribution id is empty"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               dist = Distribution.find(:first, :conditions => ["name = ?", dist_name])
+               dist = Distribution.find(:first, :conditions => ["id = ?", dist_id])
                if dist.nil?
-                       errmsg = "Distribution[#{dist_name}] not exist"
+                       errmsg = "Can't find distribution: [#{dist_id}]"
                else
                        # first, remove sync package server
                        sync_pkg_svr = SyncPkgServer.find(:first, :conditions => ["distribution_id = ?", dist.id])
@@ -158,16 +159,16 @@ class AdminDistributionController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
                
-               dist_name = change_item[:DistributionName]
-               if dist_name.nil? or dist_name.empty? then
-                       errmsg = "Can't find [#{dist_name}] information"
+               dist_id = change_item[:DistributionId]
+               if dist_id.nil? or dist_id.empty? then
+                       errmsg = "Distribution id is empty"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               dist = Distribution.find(:first, :conditions => ["name = ?", dist_name])
+               dist = Distribution.find(:first, :conditions => ["id = ?", dist_id])
                if dist.nil?
-                       errmsg = "Distribution[#{dist_name}] not exist"
+                       errmsg = "Can't find distribution: [#{dist_id}]"
                else
                        dist.pkgsvr_url = change_item[:URL]
                        dist.pkgsvr_addr = change_item[:Address]
@@ -200,40 +201,4 @@ class AdminDistributionController < ApplicationController
                        render :json => { :error=> errmsg }, :status => 406
                end
        end
-
-       def fullBuildDistribution
-               change_group_list = params[:ChangeInfoList]
-               change_item = change_group_list[0]
-               errmsg = ""
-               
-               dist_name = change_item[:DistributionName]
-               if dist_name.nil? or dist_name.empty? then
-                       errmsg = "Can't find [#{dist_name}] information"
-                       render :json => { :error => errmsg }, :status => 406
-                       return
-               end
-
-               dist = Distribution.find(:first, :conditions => ["name = ?", dist_name])
-               if dist.nil?
-                       errmsg = "Distribution[#{dist_name}] not exist"
-               end
-
-               server_config = Server_config.find(:first, :conditions => ["property = \"id\""])
-               if server_config.nil? 
-                       errmsg = "Server name can't find"
-               else
-                       server_name = server_config.value
-
-                       if server_name.nil? or server_name.empty?
-                               errmsg = "Server name can't find"
-                       end
-               end
-
-               if errmsg.empty?
-                       Utils.sbi_fullbuild_command(server_name, dist_name)
-                       render :json => { :success => "OK!" }
-               else
-                       render :json => { :error=> errmsg }, :status => 406
-               end
-       end
 end
index 6820593..22b538e 100644 (file)
@@ -41,6 +41,7 @@ class AdminGroupController < ApplicationController
                        doc.Data {
                                group_list.each do |group|
                                        doc.Group {
+                                               doc.GroupId(group.id)
                                                doc.GroupName(group.name)
                                                doc.AdminFlag(group.admin)
                                                doc.Description(group.description)
@@ -53,6 +54,7 @@ class AdminGroupController < ApplicationController
                                                                                                                                                WHERE group_project_accesses.group_id = #{group.id}
                                                                                                                                                  AND projects.id = group_project_accesses.project_id
                                                                                                                                                  AND distributions.id = projects.distribution_id
+                                                                                                                                                 AND distributions.status = 'OPEN'
                                                                                                                                                ORDER BY projects.name")
 
                                                project_list.each do |project|
@@ -71,15 +73,15 @@ class AdminGroupController < ApplicationController
        end
 
        def queryGroupInfo
-               group_name = params[:groupName]
-               if group_name.nil? or group_name.empty? 
-                       render :text => "Group name is empty", :content_type => "text/xml", :status => 406
+               group_id = params[:groupId]
+               if group_id.nil? or group_id.empty? 
+                       render :text => "Group id is empty", :content_type => "text/xml", :status => 406
                        return
                end
 
-               group = Group.find(:first, :conditions => ["name = ?", group_name])
+               group = Group.find(:first, :conditions => ["id = ?", group_id])
                if group.nil? 
-                       render :text => "Can't find group : #{group_name}", :content_type => "text/xml", :status => 406
+                       render :text => "Can't find group: #{group_id}", :content_type => "text/xml", :status => 406
                        return
                end
 
@@ -94,12 +96,13 @@ class AdminGroupController < ApplicationController
                                                                                                          FROM projects
                                                                                                                 , distributions
                                                                                                         WHERE distributions.id = projects.distribution_id
+                                                                                                          AND distributions.status = 'OPEN'
                                                                                                         ORDER BY projects.name")
                                                                                                                                  
                                project_list.each do |project|
                                        doc.Project{
-                                               doc.Name(project.project_name)
                                                doc.Id(project.project_id)
+                                               doc.Name(project.project_name)
                                                doc.DistName(project.distribution_name)
                                        }
                                end
@@ -126,23 +129,24 @@ class AdminGroupController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
 
-               group_name = change_item[:GroupName]
-               if group_name.nil? or group_name.empty?
-                       render :text => "Group name is invalid", :status => 406
+               group_id = change_item[:GroupId]
+               if group_id.nil? or group_id.empty?
+                       errmsg = "group id is empty"
+                       render :json => { :error => errmsg }, :status => 406
                        return
                else
-                       group = Group.find(:first, :conditions => ["name= ?", group_name])
+                       group = Group.find(:first, :conditions => ["id= ?", group_id])
                end
                
                if group.nil?
-                       errmsg = "Can't find group"
+                       errmsg = "Can't find group: #{group_id}"
                else
-                       new_group_name = change_item[:NewGroupName]
+                       group_name = change_item[:GroupName]
                        admin_flag = change_item[:AdminFlag]
                        description = change_item[:Description]
                        project_id_list = change_item[:ProjectList].split(",")
             
-                       group.name = new_group_name
+                       group.name = group_name
                        group.admin = admin_flag
                        group.description = description
                        group.save
@@ -162,7 +166,7 @@ class AdminGroupController < ApplicationController
                if errmsg.empty?
                        render :json => { :success => "OK!" }
                else
-                       render :text => errmsg, :status => 406
+                       render :json => { :error=> errmsg }, :status => 406
                end
        end
 
@@ -171,30 +175,31 @@ class AdminGroupController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
 
-               group_name = change_item[:GroupName]
-               if group_name.nil? or group_name.empty?
-                       render :text => "Group name is invalid", :status => 406
+               group_id = change_item[:GroupId].to_s
+               if group_id.nil? or group_id.empty?
+                       errmsg = "group id is empty"
+                       render :json => { :error => errmsg }, :status => 406
                        return
                else
-                       group = Group.find(:first, :conditions => ["name= ?", group_name])
+                       group = Group.find(:first, :conditions => ["id = ?", group_id])
                end
                
                if group.nil?
-                       errmsg = "Can't find group"
+                       errmsg = "Can't find group: #{group_id}"
                else
                        user_group = UserGroup.find(:first, :conditions => ["group_id = ?", group.id])
                        if user_group.nil?
                                GroupProjectAccess.delete_all(["group_id = ?", group.id])
                                group.destroy
                        else
-                               errmsg = "Can't remove. #{group_name} has users."
+                               errmsg = "Can't remove. #{group.id} has users."
                        end
                end
                
                if errmsg.empty?
                        render :json => { :success => "OK!" }
                else
-                       render :text => errmsg, :status => 406
+                       render :json => { :error=> errmsg }, :status => 406
                end
        end
 
@@ -205,7 +210,8 @@ class AdminGroupController < ApplicationController
 
                group_name = change_item[:GroupName]
                if group_name.nil? or group_name.empty?
-                       render :text => "Group name is invalid", :status => 406
+                       errmsg = "Group name is invalid"
+                       render :json => { :error => errmsg }, :status => 406
                        return
                else
                        group = Group.find(:first, :conditions => ["name= ?", group_name])
@@ -232,7 +238,7 @@ class AdminGroupController < ApplicationController
                if errmsg.empty?
                        render :json => { :success => "OK!" }
                else
-                       render :text => errmsg, :status => 406
+                       render :json => { :error=> errmsg }, :status => 406
                end
        end
 end
index e125bc6..bfc5fa7 100644 (file)
@@ -27,46 +27,11 @@ Contributors:
 =end
 
 class AdminProjectController < ApplicationController
-       def queryAllProject
-               project_list = Project.find_by_sql("SELECT projects.name AS project_name
-                                                                                                , projects.id AS project_id
-                                                                                                , distributions.name AS distribution_name
-                                                                                         FROM projects
-                                                                                                , distributions
-                                                                                        WHERE distributions.id = projects.distribution_id
-                                                                                        ORDER BY projects.name")
-
-               doc = Builder::XmlMarkup.new( :target => out_string = "", :indent => 2 )
-               doc.Response {
-                       generate_xml_header(doc)
-
-                       doc.Data {
-                               project_list.each do |project|
-                                       doc.Project{
-                                               doc.Name(project.project_name)
-                                               doc.Id(project.project_id)
-                                               doc.DistName(project.distribution_name)
-                                       }
-                               end
-                       }
-               }
-
-               #send_data
-               render :text => out_string, :content_type => "text/xml"
-       end
-
        def queryProjectsInDistributionForAdmin
-               dist_name = params[:distribution]
-
-               if dist_name.nil? or dist_name.empty? 
-                       render :text => "Distribution name is empty", :content_type => "text/xml", :status => 406
-                       return
-               end
+               dist_id = params[:distId]
 
-               # get distribution 
-               distribution = Distribution.find(:first, :conditions => ["name = ?", dist_name])
-               if distribution.nil? 
-                       render :text => "Can't find distribution : #{dist_name}", :content_type => "text/xml", :status => 406
+               if dist_id.nil? or dist_id.empty? 
+                       render :text => "Distribution id is empty", :content_type => "text/xml", :status => 406
                        return
                end
 
@@ -79,16 +44,19 @@ class AdminProjectController < ApplicationController
                                project_list = Project.find_by_sql("SELECT projects.id
                                                                                                             , projects.name 
                                                                                                             , projects.ptype
+                                                                                                            , projects.status
                                                                                                          FROM projects
                                                                                                                 , distributions
-                                                                                                        WHERE distributions.name = \"#{dist_name}\"
+                                                                                                        WHERE distributions.id = \"#{dist_id}\"
                                                                                                           AND distributions.id = projects.distribution_id 
                                                                                                         ORDER BY projects.name")
 
                                project_list.each do |project|
                                        doc.Project {
-                                               doc.ProjectName(project.name)
+                                               doc.Id(project.id)
+                                               doc.Name(project.name)
                                                doc.Type(project.ptype)
+                                               doc.ProjectStatus(project.status)
             
                                                os_list = ProjectOs.find_by_sql("SELECT supported_os.name AS name
                                                                                                                   FROM project_os
@@ -129,28 +97,42 @@ class AdminProjectController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
                
+               dist_id = change_item[:DistId]
                project_name = change_item[:Name]
                project_type = change_item[:ProjectType].upcase
-               project_dist_name = change_item[:Distribution]
-               project_password = change_item[:ProjectPass]
+               project_status = change_item[:ProjectStatus].upcase
 
-               if project_name.nil? or project_name.empty? then
-                       errmsg = "Can't find [Name] information"
+               if dist_id.nil? or dist_id.empty? or
+                               project_name.nil? or project_name.empty? or
+                               project_type.nil? or project_type.empty? or
+                               project_status.nil? or project_status.empty? then
+                       errmsg = "add project information invalid"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               distribution = Distribution.find(:first, :conditions => ["name = ?", project_dist_name])
-               project = Project.find(:first, :conditions => ["name = ? and distribution_id = ? and ptype = ?", project_name, distribution.id, project_type])
+               if not project_type.eql? "GIT" and not project_type.eql? "BINARY"
+                       errmsg = "project type is invalid"
+                       render :json => { :error => errmsg }, :status => 406
+                       return
+               end
+               if not project_status.eql? "OPEN" and not project_status.eql? "CLOSE"
+                       errmsg = "project status is invalid"
+                       render :json => { :error => errmsg }, :status => 406
+                       return
+               end
 
-               if not project.nil? 
-                       errmsg = "project already exist"
+               distribution = Distribution.find(:first, :conditions => ["id = ?", dist_id])
+               if distribution.nil? 
+                       errmsg = "Can't find distribution: #{dist_id}"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               if not project_type.eql? "GIT" and not project_type.eql? "BINARY"
-                       errmsg = "project type is invalid"
+               project = Project.find(:first, :conditions => ["name = ? and distribution_id = ?", project_name, dist_id])
+
+               if not project.nil? 
+                       errmsg = "project already exist"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
@@ -158,17 +140,22 @@ class AdminProjectController < ApplicationController
                project = Project.new
                project.name = project_name
                project.ptype = project_type
-               project.password = project_password
-               project.distribution_id = distribution.id
+               project.status = project_status
+               project.distribution_id = dist_id
                #TODO: set project user is admin. admin user id is '1'
                project.user_id = 1
                project.save
 
-               if not change_item[:OSNameList].nil?
-                       os_name_list = change_item[:OSNameList].split(",")
-                       os_name_list.each do |os_name|
-                               supported_os = SupportedOs.find(:first, :conditions => ["name = ?", os_name])
-                               #need check not found
+               if not change_item[:OSIdList].nil?
+                       os_id_list = change_item[:OSIdList].split(",")
+                       os_id_list.each do |os_id|
+                               supported_os = SupportedOs.find(:first, :conditions => ["id = ?", os_id])
+                               if supported_os.nil? 
+                                       errmsg = "project os id is invalid: #{os_id}"
+                                       render :json => { :error => errmsg }, :status => 406
+                                       return
+                               end
+
                                project_os = ProjectOs.new
                                project_os.project_id = project.id
                                project_os.supported_os_id = supported_os.id
@@ -198,32 +185,30 @@ class AdminProjectController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
                
-               if change_item[:Name].nil? or change_item[:Name].empty? then
-                       errmsg = "Can't find [Name] information"
+               if change_item[:ProjectId].nil? or change_item[:ProjectId].empty? then
+                       errmsg = "project id is empty"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               dist_name = change_item[:Distribution]
-               project_name = change_item[:Name]
-               project_type = change_item[:ProjectType]
-               distribution = Distribution.find(:first, :conditions => ["name = ?", dist_name])
-               project = Project.find(:first, :conditions => ["name = ? and distribution_id = ?", project_name, distribution.id])
+               project_id  = change_item[:ProjectId]
+
+               project = Project.find(:first, :conditions => ["id = ?", project_id])
 
                if project.nil? 
-                       errmsg = "project does not exist"
+                       errmsg = "project does not exist: #{project_id}"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               case project_type.upcase
+               case project.ptype
                when "GIT"
-                       ProjectGit.delete_all(["project_id = ?", project.id])
-                       ProjectOs.delete_all(["project_id = ?", project.id])
-                       GroupProjectAccess.delete_all(["project_id = ?", project.id])
+                       ProjectGit.delete_all(["project_id = ?", project_id])
+                       ProjectOs.delete_all(["project_id = ?", project_id])
+                       GroupProjectAccess.delete_all(["project_id = ?", project_id])
                when "BINARY"
-                       ProjectBin.delete_all(["project_id = ?", project.id])
-                       GroupProjectAccess.delete_all(["project_id = ?", project.id])
+                       ProjectBin.delete_all(["project_id = ?", project_id])
+                       GroupProjectAccess.delete_all(["project_id = ?", project_id])
                else
                        errmsg = "project type is invalid"
                        render :json => { :error => errmsg }, :status => 406
@@ -231,7 +216,7 @@ class AdminProjectController < ApplicationController
                end
 
                # remove project os 
-               ProjectOs.delete_all(["project_id = ?", project.id])
+               ProjectOs.delete_all(["project_id = ?", project_id])
 
                # remove project 
                project.destroy
@@ -244,46 +229,69 @@ class AdminProjectController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
                
-               dist_name = change_item[:Distribution]
-               old_project_name = change_item[:Name]
-               project_type = change_item[:ProjectType].upcase
+               project_id = change_item[:Id]
+               project_name = change_item[:Name]
+               project_status = change_item[:ProjectStatus].upcase
 
-               if old_project_name.nil? or old_project_name.empty? then
-                       errmsg = "Can't find [#{old_project_name}] information"
+               if project_id.nil? or project_id.empty? or
+                               project_name.nil? or project_name.empty? or
+                               project_status.nil? or project_status.empty? then
+                       errmsg = "project information invalid"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               if not project_type.eql? "GIT" and not project_type.eql? "BINARY"
-                       errmsg = "project type is invalid"
+               if not project_status.eql? "OPEN" and not project_status.eql? "CLOSE"
+                       errmsg = "project status is invalid"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               distribution = Distribution.find(:first, :conditions => ["name = ?", dist_name])
-               project = Project.find(:first, :conditions => ["name = ? and distribution_id = ? and ptype = ?", old_project_name, distribution.id, project_type])
-               project.name = change_item[:NewProjectName]
-               project.password = change_item[:ProjectPass]
+               project = Project.find(:first, :conditions => ["id = ?", project_id])
+               if project.nil? 
+                       errmsg = "project does not exist"
+                       render :json => { :error => errmsg }, :status => 406
+                       return
+               end
+
+               # project data update
+               if not project.name.eql? project_name then
+                       name_check_project = Project.find(:first, :conditions => ["name = ? and distribution_id = ?", project_name, project.distribution_id])
+            
+                       if not name_check_project.nil? 
+                               errmsg = "project already exist"
+                               render :json => { :error => errmsg }, :status => 406
+                               return
+                       end
+            
+                       project.name = project_name
+               end
+               project.status = project_status
 
                # remove project os and reset project os
-               ProjectOs.delete_all(["project_id = ?", project.id])
-               if not change_item[:OSNameList].nil?
-                       os_name_list = change_item[:OSNameList].split(",")
-                       os_name_list.each do |os_name|
-                               supported_os = SupportedOs.find(:first, :conditions => ["name = ?", os_name])
-                               #need check not found
+               ProjectOs.delete_all(["project_id = ?", project_id])
+               if not change_item[:OSIdList].nil?
+                       os_id_list = change_item[:OSIdList].split(",")
+                       os_id_list.each do |os_id|
+                               supported_os = SupportedOs.find(:first, :conditions => ["id = ?", os_id])
+                               if supported_os.nil? 
+                                       errmsg = "project os id is invalid: #{os_id}"
+                                       render :json => { :error => errmsg }, :status => 406
+                                       return
+                               end
+
                                project_os = ProjectOs.new
-                               project_os.project_id = project.id
+                               project_os.project_id = project_id
                                project_os.supported_os_id = supported_os.id
                                project_os.save
                        end
                end
 
-               case project_type
+               case project.ptype
                when "GIT"
-                       project_git = ProjectGit.find(:first, :conditions => ["project_id = ?", project.id])
+                       project_git = ProjectGit.find(:first, :conditions => ["project_id = ?", project_id])
                        if project_git.nil?
-                               project_git.project_id = project.id
+                               project_git.project_id = project_id
                                project_git = ProjectGit.new
                        end
                        project_git.git_repos = change_item[:ProjectAddress]
@@ -291,10 +299,10 @@ class AdminProjectController < ApplicationController
                        project_git.save
 
                when "BINARY"
-                       project_bin = ProjectBin.find(:first, :conditions => ["project_id = ?", project.id])
+                       project_bin = ProjectBin.find(:first, :conditions => ["project_id = ?", project_id])
                        if project_bin.nil?
                                project_bin = ProjectBin.new
-                               project_bin.project_id = project.id
+                               project_bin.project_id = project_id
                        end
                        project_bin.pkg_name = change_item[:PackageName]
                        project_bin.save
@@ -303,4 +311,24 @@ class AdminProjectController < ApplicationController
                project.save
                render :json => { :success => "OK!" }
        end
+
+       def changeAllProjectStatus
+               change_group_list = params[:ChangeInfoList]
+               change_item = change_group_list[0]
+               errmsg = ""
+               
+               dist_id = change_item[:DistId]
+               projectStatus = change_item[:ProjectStatus]
+
+               if projectStatus.nil? or not (projectStatus.eql? "OPEN" or projectStatus.eql? "CLOSE") then
+                       errmsg = "project status must be OPEN or CLOSE"
+                       render :json => { :error => errmsg }, :status => 406
+                       return
+               end
+
+               distribution = Distribution.find(:first, :conditions => ["id = ?", dist_id])
+               Project.update_all("status=\"#{projectStatus}\"", :distribution_id => distribution.id)
+
+               render :json => { :success => "OK!" }
+       end
 end
index 35f0d5a..aa55578 100644 (file)
@@ -40,6 +40,7 @@ class AdminServerController < ApplicationController
                        doc.Data {
                                server_config.each do |info|
                                        doc.ServerConfig {
+                                               doc.Id( info.id )
                                                doc.Property( info.property )
                                                doc.Value( info.value )
                                        }
@@ -47,6 +48,7 @@ class AdminServerController < ApplicationController
 
                                remote_build_servers.each do |server|
                                        doc.RemoteBuildServer {
+                                               doc.Id(server.id)
                                                doc.Address(server.svr_addr)
                                                supported_os = SupportedOs.find(:first, :conditions => ["id = ?", server.supported_os_id])
                                                if supported_os.nil?
@@ -68,6 +70,93 @@ class AdminServerController < ApplicationController
                render :text => out_string, :content_type => "text/xml"
        end
 
+       def queryServerConfig
+               config_id = params[:configId]
+               if config_id.nil? 
+                       #send_data
+                       render :text => "Config id value is invalid", :content_type => "text/xml"
+                       return
+               end
+               
+               server_config = Server_config.find(:first, :conditions => ["id = ?", config_id])
+               if server_config.nil? 
+                       #send_data
+                       render :text => "Can't find server config: #{config_id}", :content_type => "text/xml"
+                       return
+               end
+               
+               doc = Builder::XmlMarkup.new( :target => out_string = "", :indent => 2 )
+               doc.Response {
+                       generate_xml_header(doc)
+        
+                       #generate to XML
+                       doc.Data {
+                               doc.Id(server_config.id)
+                               doc.Property(server_config.property)
+                               doc.Value(server_config.value)
+                       }
+               }
+               
+               #send_data
+               render :text => out_string, :content_type => "text/xml"
+       end
+
+       def querySupportedOS
+               os_id = params[:osId]
+               if os_id.nil? 
+                       #send_data
+                       render :text => "Supported os id is invalid", :content_type => "text/xml"
+                       return
+               end
+               
+               supported_os = SupportedOs.find(:first, :conditions => ["id = ?", os_id])
+               if supported_os.nil? 
+                       #send_data
+                       render :text => "Can't find supported os: #{os_id}", :content_type => "text/xml"
+                       return
+               end
+               
+               doc = Builder::XmlMarkup.new( :target => out_string = "", :indent => 2 )
+               doc.Response {
+                       generate_xml_header(doc)
+        
+                       #generate to XML
+                       doc.Data {
+                               doc.Id(supported_os.id)
+                               doc.Name(supported_os.name)
+                               doc.CategoryId(supported_os.os_category_id)
+                       }
+               }
+               
+               #send_data
+               render :text => out_string, :content_type => "text/xml"
+       end
+
+       def queryRemoteBuildServer
+               server_id = params[:serverId]
+               remote_server = RemoteBuildServer.find(:first, :conditions => ["id = ?", server_id])
+               if remote_server.nil? 
+                       #send_data
+                       render :text => "Can't find server: #{server_id}", :content_type => "text/xml"
+                       return
+               end
+               
+               doc = Builder::XmlMarkup.new( :target => out_string = "", :indent => 2 )
+               doc.Response {
+                       generate_xml_header(doc)
+        
+                       #generate to XML
+                       doc.Data {
+                               doc.Id(remote_server.id)
+                               doc.Address(remote_server.svr_addr)
+                               doc.Description(remote_server.description)
+                       }
+               }
+               
+               #send_data
+               render :text => out_string, :content_type => "text/xml"
+       end
+
        def addRemoteBuildServer
                change_group_list = params[:ChangeInfoList]
                change_item = change_group_list[0]
@@ -86,14 +175,13 @@ class AdminServerController < ApplicationController
         
                if server.nil? 
                        server = RemoteBuildServer.new
-                       server.svr_addr = address
+                       server.svr_addr = address.strip
                        server.description = description 
                        server.save
 
                        render :json => { :success => "OK!" }
                else
                        errmsg = "Server already exist"
-
                        render :json => { :error => errmsg }, :status => 406
                end
        end
@@ -103,32 +191,34 @@ class AdminServerController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
 
+               id = change_item[:Id]
                address = change_item[:Address]
-               if address.nil? or address.empty? 
-                       errmsg = "Server address is empty"
+               description = change_item[:Description]
+               if id.nil? or 
+                               address.nil? or address.empty? 
+                       errmsg = "Server information is invalid"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               server = RemoteBuildServer.find(:first, :conditions => ["svr_addr = ?", address])
+               server = RemoteBuildServer.find(:first, :conditions => ["id = ?", id])
 
                if server.nil? 
                        errmsg = "Server does not exist"
                else
-                       new_address = change_item[:NewAddress]
-                       description = change_item[:Description]
-                       
                        # error check for server already exist
-                       if not address.eql? new_address
-                               new_server = RemoteBuildServer.find(:first, :conditions => ["svr_addr = ?", new_address])
+                       if not server.svr_addr.eql? address
+                               check_server = RemoteBuildServer.find(:first, :conditions => ["svr_addr = ?", address])
                                
-                               if not new_server.nil?
+                               if not check_server.nil?
                                        errmsg = "Server already exist"
+                                       render :json => { :error => errmsg }, :status => 406
+                                       return
                                end
                        end
 
-                       server.svr_addr = new_address
-                       server.description = description
+                       server.svr_addr = address.strip 
+                       server.description = description.strip
                        server.save
                end
                
@@ -145,14 +235,14 @@ class AdminServerController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
 
-               address = change_item[:Address]
-               if address.nil? or address.empty? 
-                       errmsg = "Server address is empty"
+               id = change_item[:Id]
+               if id.nil? or id.empty? 
+                       errmsg = "Server id is empty"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
-               server = RemoteBuildServer.find(:first, :conditions => ["svr_addr = ?", address])
+               server = RemoteBuildServer.find(:first, :conditions => ["id = ?", id])
         
                if server.nil? 
                        errmsg = "Server does not exist"
@@ -163,7 +253,7 @@ class AdminServerController < ApplicationController
                end
        end
 
-       def addOsCategory
+       def addOSCategory
                change_group_list = params[:ChangeInfoList]
                change_item = change_group_list[0]
                errmsg = ""
@@ -186,25 +276,24 @@ class AdminServerController < ApplicationController
                        render :json => { :success => "OK!" }
                else
                        errmsg = "Os category already exist"
-
                        render :json => { :error => errmsg }, :status => 406
                end
        end
 
-       def removeOsCategory
+       def removeOSCategory
                change_group_list = params[:ChangeInfoList]
                change_item = change_group_list[0]
                errmsg = ""
 
-               name = change_item[:Name]
-               if name.nil? or name.empty? 
-                       errmsg = "Os category name is empty"
+               id = change_item[:Id]
+               if id.nil? or id.empty? 
+                       errmsg = "Os category id is empty"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
                # get server for error check
-               osCategory = OsCategory.find(:first, :conditions => ["name = ?", name])
+               osCategory = OsCategory.find(:first, :conditions => ["id = ?", id])
         
                if osCategory.nil? 
                        errmsg = "Can't find os category"
@@ -221,36 +310,33 @@ class AdminServerController < ApplicationController
                errmsg = ""
 
                os_name = change_item[:Name]
-               category_name = change_item[:OsCategory]
+               category_id = change_item[:OsCategoryId]
                if os_name.nil? or os_name.empty? 
                        errmsg = "Os name is empty"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
-               if category_name.nil? or category_name.empty? 
+               if category_id.nil? or category_id.empty? 
                        errmsg = "Os category is empty"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
                # get server for error check
-               os_category = OsCategory.find(:first, :conditions => ["name = ?", category_name])
+               os_category = OsCategory.find(:first, :conditions => ["id = ?", category_id])
                supported_os = SupportedOs.find(:first, :conditions => ["name = ?", os_name])
         
                if os_category.nil? 
                        errmsg = "Os category does not exist"
-
                        render :json => { :error => errmsg }, :status => 406
                elsif not supported_os.nil?
                        errmsg = "supported os already exist"
-
                        render :json => { :error => errmsg }, :status => 406
                else
                        supported_os = SupportedOs.new
-                       supported_os.name = os_name 
+                       supported_os.name = os_name.strip
                        supported_os.os_category_id = os_category.id
                        supported_os.save
-
                        render :json => { :success => "OK!" }
                end
        end
@@ -260,25 +346,23 @@ class AdminServerController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
 
-               os_name = change_item[:Name]
-               if os_name.nil? or os_name.empty? 
-                       errmsg = "Os name is empty"
+               os_id = change_item[:Id]
+               if os_id.nil? or os_id.empty? 
+                       errmsg = "Os id is empty"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
                # get server for error check
-               supported_os = SupportedOs.find(:first, :conditions => ["name = ?", os_name])
+               supported_os = SupportedOs.find(:first, :conditions => ["id = ?", os_id])
         
                if supported_os.nil?
                        errmsg = "supported os does not exist"
-
                        render :json => { :error => errmsg }, :status => 406
-               else
-                       supported_os.destroy
-
-                       render :json => { :success => "OK!" }
                end
+
+               supported_os.destroy
+               render :json => { :success => "OK!" }
        end
 
        def modifySupportedOS
@@ -286,18 +370,20 @@ class AdminServerController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
 
+               os_id = change_item[:Id]
                os_name = change_item[:Name]
-               new_os_name = change_item[:NewName]
-               category_name = change_item[:OsCategory]
-               if os_name.nil? or os_name.empty? 
-                       errmsg = "Os name is empty"
+               category_id = change_item[:OsCategoryId]
+               if os_id.nil? or os_id.empty? or
+                               os_name.nil? or os_name.empty? or
+                               category_id.nil? or category_id.empty? 
+                       errmsg = "modify os data is invalid"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
                # get server for error check
-               os_category = OsCategory.find(:first, :conditions => ["name = ?", category_name])
-               supported_os = SupportedOs.find(:first, :conditions => ["name = ?", os_name])
+               os_category = OsCategory.find(:first, :conditions => ["id = ?", category_id])
+               supported_os = SupportedOs.find(:first, :conditions => ["id = ?", os_id])
         
                if os_category.nil? 
                        errmsg = "Os category does not exist"
@@ -308,13 +394,12 @@ class AdminServerController < ApplicationController
 
                        render :json => { :error => errmsg }, :status => 406
                else
-                       if not os_name.eql? new_os_name
-                               new_supported_os = SupportedOs.find(:first, :conditions => ["name = ?", new_os_name])
-                               if new_supported_os.nil?
-                                       supported_os.name = new_os_name 
+                       if not supported_os.name.eql? os_name
+                               check_supported_os = SupportedOs.find(:first, :conditions => ["name = ?", os_name])
+                               if check_supported_os.nil?
+                                       supported_os.name = os_name 
                                else
                                        errmsg = "supported os already exist"
-                    
                                        render :json => { :error => errmsg }, :status => 406
                                        return
                                end
@@ -322,7 +407,6 @@ class AdminServerController < ApplicationController
 
                        supported_os.os_category_id = os_category.id
                        supported_os.save
-
                        render :json => { :success => "OK!" }
                end
        end
@@ -366,26 +450,25 @@ class AdminServerController < ApplicationController
                change_item = change_group_list[0]
                errmsg = ""
 
+               id = change_item[:Id]
                property = change_item[:Property]
                value = change_item[:Value]
-               if property.nil? or property.empty? 
-                       errmsg = "Property is empty"
-                       render :json => { :error => errmsg }, :status => 406
-                       return
-               end
-               if value.nil? or value.empty? 
-                       errmsg = "Value is empty"
+               if id.nil? or id.empty? or
+                               value.nil? or value.empty? or
+                               property.nil? or property.empty? 
+                       errmsg = "server info is invalid"
                        render :json => { :error => errmsg }, :status => 406
                        return
                end
 
                # get server for error check
-               config = Server_config.find(:first, :conditions => ["property = ?", property])
+               config = Server_config.find(:first, :conditions => ["id = ?", id])
         
                if config.nil? 
                        errmsg = "Config does not exist"
                        render :json => { :error => errmsg }, :status => 406
                else
+                       config.property = property
                        config.value = value
                        config.save
 
index 17791c3..07158e1 100644 (file)
@@ -114,24 +114,37 @@ class AdminUserController < ApplicationController
                change_item = change_user_list[0]
                errmsg = ""
 
+               id = change_item[:Id]
                email = change_item[:Email]
+               name = change_item[:Name]
                group_id_list = change_item[:GroupIdList].split(",")
-               user_name = change_item[:UserName]
 
-               if email.nil? or email.empty?
-                       render :text => "Email is invalid", :status => 406
+               if id.nil? or 
+                               email.nil? or email.empty?
+                       render :text => "User data is invalid", :status => 406
                        return
-               else
-                       user = User.find(:first, :conditions => ["email = ?", email])
+               end
+
+               user = User.find(:first, :conditions => ["id = ?", id])
+
+               if user.nil? 
+                       errmsg = "Can't find user information"
+                       render :text => errmsg, :status => 406
+                       return
+               end
 
-                       if user.nil? 
-                               errmsg = "Can't find user information"
+               if not user.email.eql? email 
+                       check_user = User.find(:first, :conditions => ["email = ?", email])
+                       if not check_user.nil?
+                               errmsg = "Email address already used"
                                render :text => errmsg, :status => 406
                                return
                        end
+
+                       user.email = email 
                end
 
-               user.name = user_name
+               user.name = name
                user.save
 
                UserGroup.delete_all(["user_id = ?", user.id])
@@ -155,22 +168,23 @@ class AdminUserController < ApplicationController
                change_item = change_user_list[0]
                errmsg = ""
 
-               email = change_item[:Email]
-               if email.nil? or email.empty?
-                       render :text => "Email is invalid", :status => 406
+               id = change_item[:Id]
+               if id.nil? 
+                       render :text => "User infomation invalid", :status => 406
                        return
-               else
-                       user = User.find(:first, :conditions => ["email = ?", email])
                end
+                       
+               user = User.find(:first, :conditions => ["id = ?", id])
 
                if user.nil?
                        errmsg = "Can't find user information"
                        render :text => errmsg, :status => 406
-               else
-                       UserGroup.delete_all(["user_id = ?", user.id])
-
-                       user.destroy
-                       render :json => { :success => "OK!" }
+                       return
                end
+               
+               UserGroup.delete_all(["user_id = ?", user.id])
+
+               user.destroy
+               render :json => { :success => "OK!" }
        end
 end
index 1ad4921..6027ab4 100644 (file)
@@ -57,6 +57,18 @@ class ApplicationController < ActionController::Base
                end
        end
 
+       def get_user_password
+               if @current_user.nil?
+                       current_user
+               end
+
+               if not @current_user.nil?
+                       return @current_user.password_hash
+               else
+                       return nil
+               end
+       end
+
        def get_group_list(email)
                if not email.nil?
                        group_list = Group.find_by_sql("SELECT groups.id
index b4f3797..01ec9f3 100644 (file)
@@ -140,26 +140,12 @@ class JobsController < ApplicationController
                                                                doc.UserName(job.user_name)
                                                                doc.StartTime(job.start_time)
                                                                doc.EndTime(job.end_time)
-                                                       }
+                                                               doc.ErrorCode(job.error_code)
 
-                                                       if job.job_attribute == "MULTI"
-                                                               child_jobs = get_child_job_info(job.job_id)
-                                                               child_jobs.each {|job|
-                                                                       doc.Job {
-                                                                               doc.Id(job.job_id)
-                                                                               doc.Distribution(job.distribution_name)
-                                                                               doc.ProjectName(job.project_name)
-                                                                               doc.JobType(job.job_type)
-                                                                               doc.JobAttribute("CHILD")
-                                                                               doc.ParentJobId(job.parent_job_id)
-                                                                               doc.Os(job.supported_os_name)
-                                                                               doc.Status(job.status)
-                                                                               doc.UserName(job.user_name)
-                                                                               doc.StartTime(job.start_time)
-                                                                               doc.EndTime(job.end_time)
-                                                                       }
-                                                               }
-                                                       end
+                                                               project_list = get_child_job_project_name(job.job_id)
+                                                               doc.ProjectList(project_list)
+                                                       }
+                                                       generate_xml_sub_jobs(doc,job.job_id)
                                                end
                                        end
                                }
@@ -178,11 +164,11 @@ class JobsController < ApplicationController
                end
 
                if(status == "ALL")
-                       status = "'FINISHED', 'JUST_CREATED', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING', 'ERROR', 'CANCELED'"
+                       status = "'FINISHED', 'INITIALIZING', 'JUST_CREATED', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING', 'ERROR', 'CANCELED'"
                elsif(status == "SUCCESS")
                        status = "'FINISHED'"
                elsif(status == "WORKING")
-                       status = "'JUST_CREATE', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING'"
+                       status = "'INITIALIZING', 'JUST_CREATED', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING'"
                elsif(status == "ERROR")
                        status = "'ERROR', 'CANCELED'"
                end
@@ -234,7 +220,6 @@ class JobsController < ApplicationController
                doc.JobList {
                        jobs.each {|job_list|
                                job = get_job_info(job_list.id)
-
                                doc.Job {
                                        doc.Id(job.job_id)
                                        doc.Distribution(job.distribution_name)
@@ -247,25 +232,12 @@ class JobsController < ApplicationController
                                        doc.UserName(job.user_name)
                                        doc.StartTime(job.start_time)
                                        doc.EndTime(job.end_time)
-                               }
+                                       doc.ErrorCode(job.error_code)
 
-                               if job_list.job_attribute == "MULTI"
-                                       child_jobs = get_child_job_info(job.job_id)
-                                       child_jobs.each {|job|
-                                               doc.Job {
-                                                       doc.Id(job.job_id)
-                                                       doc.Distribution(job.distribution_name)
-                                                       doc.ProjectName(job.project_name)
-                                                       doc.JobType(job.job_type)
-                                                       doc.JobAttribute("CHILD")
-                                                       doc.Os(job.supported_os_name)
-                                                       doc.Status(job.status)
-                                                       doc.UserName(job.user_name)
-                                                       doc.StartTime(job.start_time)
-                                                       doc.EndTime(job.end_time)
-                                               }
-                                       }
-                               end
+                                       project_list = get_child_job_project_name(job.job_id)
+                                       doc.ProjectList(project_list)
+                               }
+                               generate_xml_sub_jobs(doc,job.job_id)
                        }
                }
        end
@@ -277,11 +249,11 @@ class JobsController < ApplicationController
                end
 
                if(status == "ALL")
-                       status = "'FINISHED', 'JUST_CREATED', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING', 'ERROR', 'CANCELED'"
+                       status = "'FINISHED', 'INITIALIZING', 'JUST_CREATED', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING', 'ERROR', 'CANCELED'"
                elsif(status == "SUCCESS")
                        status = "'FINISHED'"
                elsif(status == "WORKING")
-                       status = "'JUST_CREATE', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING'"
+                       status = "'INITIALIZING', 'JUST_CREATED', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING'"
                elsif(status == "ERROR")
                        status = "'ERROR', 'CANCELED'"
                end
@@ -337,25 +309,12 @@ class JobsController < ApplicationController
                                                doc.UserName(job.user_name)
                                                doc.StartTime(job.start_time)
                                                doc.EndTime(job.end_time)
-                                       }
+                                               doc.ErrorCode(job.error_code)
 
-                                       if job_list.job_attribute == "MULTI"
-                                               child_jobs = get_child_job_info(job.job_id)
-                                               child_jobs.each {|job|
-                                                       doc.Job {
-                                                               doc.Id(job.job_id)
-                                                               doc.Distribution(job.distribution_name)
-                                                               doc.ProjectName(job.project_name)
-                                                               doc.JobType(job.job_type)
-                                                               doc.JobAttribute("CHILD")
-                                                               doc.Os(job.supported_os_name)
-                                                               doc.Status(job.status)
-                                                               doc.UserName(job.user_name)
-                                                               doc.StartTime(job.start_time)
-                                                               doc.EndTime(job.end_time)
-                                                       }
-                                               }
-                                       end
+                                               project_list = get_child_job_project_name(job.job_id)
+                                               doc.ProjectList(project_list)
+                                       }
+                                       generate_xml_sub_jobs(doc,job.job_id)
                                }
                        }
                }
@@ -367,11 +326,11 @@ class JobsController < ApplicationController
                end
 
                if(status == "ALL")
-                       status = "'FINISHED', 'JUST_CREATED', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING', 'ERROR', 'CANCELED'"
+                       status = "'FINISHED', 'INITIALIZING', 'JUST_CREATED', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING', 'ERROR', 'CANCELED'"
                elsif(status == "SUCCESS")
                        status = "'FINISHED'"
                elsif(status == "WORKING")
-                       status = "'JUST_CREATE', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING'"
+                       status = "'INITIALIZING', 'JUST_CREATED', 'WAITING', 'WORKING', 'REMOTE_WORKING', 'PENDING'"
                elsif(status == "ERROR")
                        status = "'ERROR', 'CANCELED'"
                end
@@ -432,6 +391,10 @@ class JobsController < ApplicationController
                                                doc.UserName(job.user_name)
                                                doc.StartTime(job.start_time)
                                                doc.EndTime(job.end_time)
+                                               doc.ErrorCode(job.error_code)
+
+                                               project_list = get_child_job_project_name(job.job_id)
+                                               doc.ProjectList(project_list)
                                        }
                                }
                        }
@@ -443,13 +406,13 @@ class JobsController < ApplicationController
                                                                         , jobs.jtype AS job_type
                                                                         , jobs.status AS status
                                                                         , jobs.parent_job_id AS parent_job_id
+                                                                        , jobs.error_code AS error_code
                                                                         , DATE_FORMAT(jobs.start_time, '%Y-%m-%d %H:%i:%s') AS start_time
                                                                         , DATE_FORMAT(jobs.end_time, '%Y-%m-%d %H:%i:%s') AS end_time
                                                                         , CASE WHEN jobs.jtype like \"MULTI%\" THEN \"MULTI\"
                                                                                         ELSE \"SINGLE\" END \"job_attribute\"
                                                                     , projects.name AS project_name
                                                                     , projects.ptype AS project_type
-                                                                    , projects.password AS project_password
                                                                     , users.name AS user_name
                                                                     , users.email AS user_email
                                                                     , supported_os.name AS supported_os_name
@@ -483,6 +446,7 @@ class JobsController < ApplicationController
                                                                         , jobs.jtype AS job_type
                                                                         , jobs.status AS status
                                                                         , jobs.parent_job_id AS parent_job_id
+                                                                        , jobs.error_code AS error_code
                                                                         , DATE_FORMAT(jobs.start_time, '%Y-%m-%d %H:%i:%s') AS start_time
                                                                         , DATE_FORMAT(jobs.end_time, '%Y-%m-%d %H:%i:%s') AS end_time
                                                                     , projects.name AS project_name
@@ -515,10 +479,56 @@ class JobsController < ApplicationController
                return job
        end
 
-       def log_more
-               @cursor = nil
-               @file = nil
+       def get_child_job_project_name(parent_job_id)
+               project_list = nil
+               job = Job.find_by_sql("SELECT DISTINCT projects.name AS project_name
+                                                                 FROM jobs 
+                                                                 LEFT JOIN projects 
+                                                                   ON jobs.project_id = projects.id
+                                                                 WHERE jobs.parent_job_id = #{parent_job_id}
+                                                                 ORDER BY projects.name")
+               job.each do |job|
+                       if project_list.nil? then
+                               project_list = job.project_name
+                       else
+                               project_list = project_list + ', ' + job.project_name
+                       end
+               end
+               return project_list
+       end
+
+       def get_sub_job_count(job_id)
+               return Job.where(:parent_job_id => job_id).count
+       end
        
+       def generate_xml_sub_jobs(doc, job_id)
+               sub_job_cnt = get_sub_job_count(job_id)
+               if sub_job_cnt > 0
+                       child_jobs = get_child_job_info(job_id)
+                       child_jobs.each {|job|
+                               doc.Job {
+                                       doc.Id(job.job_id)
+                                       doc.Distribution(job.distribution_name)
+                                       doc.ProjectName(job.project_name)
+                                       doc.JobType(job.job_type)
+                                       doc.JobAttribute("CHILD")
+                                       doc.ParentJobId(job.parent_job_id)
+                                       doc.Os(job.supported_os_name)
+                                       doc.Status(job.status)
+                                       doc.UserName(job.user_name)
+                                       doc.StartTime(job.start_time)
+                                       doc.EndTime(job.end_time)
+                                       doc.ErrorCode(job.error_code)
+
+                                       project_list = get_child_job_project_name(job.job_id)
+                                       doc.ProjectList(project_list)
+                               }
+                               generate_xml_sub_jobs(doc,job.job_id)
+                       }
+               end
+       end
+
+       def log_more
                line_cnt = 999
                conti= 1
                id = params[:id]
@@ -538,46 +548,57 @@ class JobsController < ApplicationController
                end
 
                # Get log file infomation
-               file_name = "log"
-               buildsvr_path = Server_config.find(:first, :conditions => ["property = ?", "path"])
-               directory = "#{buildsvr_path.value}/jobs/#{id}"
-       
-               # create the file path                                                                         
-               path = File.join(directory, file_name)                                                              
-       
-               # read the file                                                                               
-               if File.exist?(path)
-                       @cursor = File.size(path)
-                       @file = File.open(path, 'r')
-                       data = @file.readlines
-               end
+               server_id = Server_config.find(:first, :conditions => ["property = \"id\""])
+               svr_dir = File.join(Utils::DIBS_WEB_CONFIG_PATH, server_id.value)
+               log_dir = File.join(svr_dir, "log")
+               path = File.join(log_dir, "#{id}.log")
        
                time = Time.new
                timestamp = time.getlocal
-       
-               start_line = line 
-               last_line = start_line + line_cnt
-       
-               #count line
-               tok = nil
-               IO.popen("wc -l #{path}") do |wc|
-                       tok = wc.read.split(" ")
+
+               #check svr dir
+               if not File.exist?(svr_dir) then
+                       render :text => "[#{svr_dir}] does not exist. please mail to server administrator", :status => 406
+                       return
                end
-               end_line = tok[0].to_i
-       
-               #check line
-               if last_line > end_line
-                       last_line = end_line
+
+               #check log dir
+               if not File.exist?(log_dir) then
+                       FileUtils.mkdir_p(log_dir)              
                end
+
+               #check file exist 
+               if not File.exist?(path) then
+                       #if file does not exist then execute query-log command
+                       Utils.sbi_query_log_command(id, path)
+                       sleep(1)
+                       conti = 1
+               else
+                       start_line = line 
+                       last_line = start_line + line_cnt
+           
+                       #count line
+                       tok = nil
+                       IO.popen("wc -l #{path}") do |wc|
+                               tok = wc.read.split(" ")
+                       end
+                       end_line = tok[0].to_i
+           
+                       #check line
+                       if last_line > end_line
+                               last_line = end_line
+                       end
        
-               #read log file
-               temp = nil
-               if start_line < end_line
-                       IO.popen("sed -n \"#{start_line},#{last_line}p\" #{path}") do |sed| 
-                               temp = sed.read
+                       #read log file
+                       log_contents = nil
+                       if start_line <= end_line
+                               IO.popen("sed -n \"#{start_line},#{last_line}p\" #{path}") do |sed| 
+                                       log_contents = sed.read
+                                       if log_contents.include? "=LOG_END" then
+                                               conti = 0
+                                       end     
+                               end
                        end
-               else
-                       conti= 0
                end
        
                #generate to XML
@@ -592,8 +613,8 @@ class JobsController < ApplicationController
                                doc.Status(job.status)
                                doc.Time(timestamp)
                                doc.Continue(conti)
-                               if temp
-                                       temp.each do |data|
+                               if log_contents
+                                       log_contents.each do |data|
                                                doc.LogData(data, "Line" => line) 
                                                line = line + 1
                                        end
@@ -617,18 +638,33 @@ class JobsController < ApplicationController
                # Check job builder
                if get_user_email != job.user_email 
                        if not is_admin(get_user_email)
-                               render :text => "You don't have authority to calcel.", :status => 406
+                               render :text => "You don't have authority to cancel.", :status => 406
                                return
                        end
                end
 
                # Excute command
+               message = ""
                begin
-                       Utils.sbi_cancel_command(id, job.project_password)
+                       result, message = Utils.sbi_cancel_command(id, get_user_email, get_user_password)
                rescue => e
                        render :text => e.message, :status => 406
-                       return
                end
-               render :xml=> "<Message>OK</Message>"
+
+               #generate to XML
+               doc = Builder::XmlMarkup.new( :target => out_string = "", :indent => 2 )
+               doc.Responser {
+                       generate_xml_header(doc)
+                       doc.Data {
+                               doc.JobId(id)
+                               doc.Distribution(job.distribution_name)
+                               doc.Project(job.project_name)
+                               doc.Builder(job.user_name)
+                               doc.Status(job.status)
+                               doc.Message(message)
+                       }
+               }
+
+               render :text => out_string, :content_type => "text/xml"
        end
 end
index 947b5e0..30ad127 100644 (file)
@@ -43,41 +43,61 @@ class ProjectsController < ApplicationController
        # get information : dist_name, project_hash, password
        change_group_list = params[:ChangeInfoList]
 
+       distribution_list = []
        project_list = []
        os_list = []
-       password_list = []
 
        dist_name = nil
 
+       if change_group_list.nil? or change_group_list.empty?
+               errmsg = "Build project is empty"
+               render :json => { :error => errmsg }, :status => 406
+               return
+       end
+
        change_group_list.each do |change_item|
-               dist_name = change_item[:distribution]
-               project_name = change_item[:projectName]
-               os = change_item[:os]
+               project_id = change_item[:projectId]
+               os_id = change_item[:osId]
 
-               distribution = Distribution.find(:first, :conditions => ["name = ?", dist_name])
-               project = Project.find(:first, :conditions => ["name = ? AND distribution_id =?", project_name, distribution.id])
+               project = Project.find(:first, :conditions => ["id = ?", project_id])
+               if project_list.nil?
+                       errmsg = "Can't find project information: [#{project_id}]"
+                       render :json => { :error => errmsg }, :status => 406
+                       return
+               end
+               os = SupportedOs.find(:first, :conditions => ["id = ?", os_id])
+               if os.nil?
+                       errmsg = "Can't find os information: [#{os_id}]"
+                       render :json => { :error => errmsg }, :status => 406
+                       return
+               end
 
+               distribution_list.push project.distribution_id
                project_list.push project.name 
-               password_list.push project.password
-               os_list.push os
+               os_list.push os.name
        end
 
+       distribution_list.uniq!
        project_list.uniq!
        os_list.uniq!
-       password_list.uniq!
-
-       if (project_list.length > 1) or (not (project_list[0].nil? or project_list[0].empty?))
-               # execute build command
-               begin
-                       Utils.sbi_build_command(dist_name, project_list, os_list, password_list, get_user_email)
-               rescue => e
-                       render :text => e.message, :status => 406
-                       return
+
+       if(distribution_list.length > 1)
+               errmsg = "Can't build multiple distribution"
+               render :json => { :error => errmsg }, :status => 406
+               return
+       end
+       distribution = Distribution.find(:first, :conditions => ["id = ?", distribution_list[0]])
+
+       # execute build command
+       begin
+               result, job_id, msg = Utils.sbi_build_command(distribution.name, project_list, os_list, get_user_email, get_user_password)
+               if result then
+                       render :json => { :result => "SUCCESS", :job_id => job_id }
+               else
+                       render :json => { :result => "ERROR", :message => msg }
                end
-    
-               render :json => { :success => "OK!" }
-       else
-               render :text => "Can't build project", :status => 406
+       rescue => e
+               render :text => e.message, :status => 406
        end
 
   end
@@ -127,7 +147,12 @@ class ProjectsController < ApplicationController
   end
 
   def queryProjectsInfoInDistribution
-       dist_name = params[:distribution]
+       dist_id = params[:distId]
+       if dist_id.nil?
+               errmsg = "Distribution id is null"
+               render :json => { :error => errmsg }, :status => 406
+               return
+       end
 
        user_id = get_user_id
        projects = Project.find_by_sql("SELECT projects.name AS project_name
@@ -135,11 +160,10 @@ class ProjectsController < ApplicationController
                                                                                 , projects.id AS project_id
                                                                                 , users.email AS maintainer
                                                                          FROM projects
-                                                                                , distributions
                                                                                 , users
-                                                                        WHERE distributions.name = \"#{dist_name}\"
-                                                                          AND projects.distribution_id = distributions.id
-                                                                          AND users.id = projects.user_id")
+                                                                        WHERE projects.distribution_id = #{dist_id}
+                                                                          AND users.id = projects.user_id
+                                                                        ORDER BY projects.name")
 
        #generate to XML
        doc = Builder::XmlMarkup.new( :target => out_string = "", :indent => 2 )
@@ -149,6 +173,7 @@ class ProjectsController < ApplicationController
                        doc.ProjectList {
                                projects.each { |project|
                                        doc.Project {
+                                               doc.Id(project.project_id)
                                                doc.Name(project.project_name)
                                                doc.Type(project.project_type)
                                                doc.Maintainer(project.maintainer)
@@ -253,9 +278,18 @@ class ProjectsController < ApplicationController
   end
 
   def queryProjectsInDistribution
-       dist_name = params[:distribution]
+       dist_id = params[:distId]
+       if dist_id.nil? 
+               render :text => "Distribution id is empty", :content_type => "text/xml", :status => 406
+               return
+       end
+
+       distribution = Distribution.find(:first, :conditions => ["id = ?", dist_id])
+       if distribution.nil? 
+               render :text => "Can't find distribution information: #{dist_id}", :content_type => "text/xml", :status => 406
+               return
+       end
 
-       distribution = Distribution.find(:first, :conditions => ["name = ?", dist_name])
        projects = Project.find(:all, :conditions => ["distribution_id = ?", distribution.id], :order => "name")
        osList = SupportedOs.find(:all)
 
@@ -267,11 +301,13 @@ class ProjectsController < ApplicationController
                generate_xml_header(doc)
                doc.Data {
                        doc.BuildServerInfo {
-                               if not osList.nil?
-                                       osList.each do |os|
-                                               doc.supportedOs(os.name)
-                                       end
+                               osList.each do |os|
+                                       doc.SupportedOs{
+                                               doc.Id(os.id)
+                                               doc.Name(os.name)
+                                       }
                                end
+                               doc.DistributionStatus(distribution.status)
                        }
     
                        projects.each do |project|
@@ -279,37 +315,43 @@ class ProjectsController < ApplicationController
                                        bin = ProjectBin.find(:first, :conditions => ["project_id = ?", project.id])
                                        if checkUserAccessProject(user_id, project.id)
                                                doc.BinaryProject {
-                                                       doc.ProjectName(project.name)
+                                                       doc.Id(project.id)
+                                                       doc.Name(project.name)
+                                                       doc.Status(project.status)
                                                        if not bin.nil? then
                                                                doc.PackageName(bin.pkg_name)
                                                        end
                                                }
                                        else
                                                doc.OtherBinaryProject {
-                                                       doc.ProjectName(project.name)
+                                                       doc.Id(project.id)
+                                                       doc.Name(project.name)
+                                                       doc.Status(project.status)
                                                        if not bin.nil? then
                                                                doc.PackageName(bin.pkg_name)
                                                        end
                                                }
                                        end
                                else
-                                       buildOsNameList = []
-                                       prjOsLists = ProjectOs.find(:all, :conditions => ["project_id = ?", project.id])
-    
-                                       prjOsLists.each do |list| 
-                                               supported_os = SupportedOs.find(:first, :conditions => ["id = ?", list.supported_os_id])
-                                               buildOsNameList.push(supported_os.name)
+                                       buildOsIdList = []
+                                       projectOsList = ProjectOs.find(:all, :conditions => ["project_id = ?", project.id])
+                                       projectOsList.each do |projectOs| 
+                                               buildOsIdList.push(projectOs.supported_os_id)
                                        end
     
                                        if checkUserAccessProject(user_id, project.id)
                                                doc.Project {
-                                                       doc.ProjectName(project.name)
-                                                       doc.OsList(buildOsNameList.join(","))
+                                                       doc.Id(project.id)
+                                                       doc.Name(project.name)
+                                                       doc.Status(project.status)
+                                                       doc.OsList(buildOsIdList.join(","))
                                                }
                                        else
                                                doc.OtherProject {
-                                                       doc.ProjectName(project.name)
-                                                       doc.OsList(buildOsNameList.join(","))
+                                                       doc.Id(project.id)
+                                                       doc.Name(project.name)
+                                                       doc.Status(project.status)
+                                                       doc.OsList(buildOsIdList.join(","))
                                                }
                                        end
                                end
@@ -325,6 +367,29 @@ class ProjectsController < ApplicationController
 
   def queryDistribution
        # get full distribution list
+       distribution_list = Distribution.find(:all, :conditions => ["status = 'OPEN'"])
+
+       #generate to XML
+       doc = Builder::XmlMarkup.new( :target => out_string = "", :indent => 2 )
+       doc.Response {
+               generate_xml_header(doc)
+
+               doc.Data {
+                       distribution_list.each do |distribution|
+                               doc.Distribution {
+                                       doc.Id(distribution.id)
+                                       doc.Name(distribution.name)
+                               }
+                       end
+               }
+       }
+       
+       #send_data
+       render :text => out_string, :content_type => "text/xml"
+  end
+
+  def queryAllDistribution
+       # get full distribution list
        distribution_list = Distribution.find(:all)
 
        #generate to XML
@@ -334,7 +399,10 @@ class ProjectsController < ApplicationController
 
                doc.Data {
                        distribution_list.each do |distribution|
-                               doc.DistributionName(distribution.name)
+                               doc.Distribution {
+                                       doc.Id(distribution.id)
+                                       doc.Name(distribution.name)
+                               }
                        end
                }
        }
@@ -343,6 +411,37 @@ class ProjectsController < ApplicationController
        render :text => out_string, :content_type => "text/xml"
   end
 
+       def queryAllProjectInOpenStatus
+               project_list = Project.find_by_sql("SELECT projects.name AS project_name
+                                                                                                , projects.id AS project_id
+                                                                                                , distributions.id AS distribution_id
+                                                                                                , distributions.name AS distribution_name
+                                                                                         FROM projects
+                                                                                                , distributions
+                                                                                        WHERE distributions.id = projects.distribution_id
+                                                                                          AND distributions.status = 'OPEN'
+                                                                                        ORDER BY projects.name")
+
+               doc = Builder::XmlMarkup.new( :target => out_string = "", :indent => 2 )
+               doc.Response {
+                       generate_xml_header(doc)
+
+                       doc.Data {
+                               project_list.each do |project|
+                                       doc.Project{
+                                               doc.Id(project.project_id)
+                                               doc.Name(project.project_name)
+                                               doc.DistId(project.distribution_id)
+                                               doc.DistName(project.distribution_name)
+                                       }
+                               end
+                       }
+               }
+
+               #send_data
+               render :text => out_string, :content_type => "text/xml"
+       end
+
   def projects
   end
 
@@ -351,8 +450,7 @@ class ProjectsController < ApplicationController
   end
 
   def binaryFileUpload
-    dist_name = params[:distribution]
-    project = params[:project]
+    project_id = params[:ProjectId]
     uploaded_io = params[:file]
  
        file_path = Rails.root.join('public', 'data', uploaded_io.original_filename)
@@ -360,15 +458,15 @@ class ProjectsController < ApplicationController
        file.write(uploaded_io.read)
     end
 
-       distribution = Distribution.find(:first, :conditions => ["name = ?", dist_name])
-       project = Project.find(:first, :conditions => ["name = ? AND distribution_id =?", project, distribution.id])
+       project = Project.find(:first, :conditions => ["id = ?", project_id])
+       distribution = Distribution.find(:first, :conditions => ["id = ?", project.distribution_id])
        if project.nil? 
-               render :nothing => true
+               render :text => "Can't find project information: [#{project_id}]", :content_type => "text/xml"
                return
        end
 
        begin
-               Utils.sbi_register_command(distribution.name, file_path,  project.password, get_user_email)
+               Utils.sbi_register_command(distribution.name, file_path, get_user_email, get_user_password)
        rescue => e
                render :text => e.message, :status => 406
                return
index 92c9826..ee8aad3 100644 (file)
@@ -28,64 +28,57 @@ Contributors:
 
 # constant
 BUILD_SERVER_ADDRESS = "127.0.0.1"
+DIBS_PATH = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__))))
 
 class Utils < ApplicationController
-  def Utils.sbi_build_command(distribution, project_list, os_list, password_list, email)
-       dibs_path = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__))))
+  def Utils.sbi_build_command(distribution, project_list, os_list, email, password)
+       job_id = nil
        dibs_config = Server_config.find(:first, :conditions => ["property = \"port\""])
        if dibs_config.nil?
-               raise RuntimeError, "Build sever not started"
+               raise RuntimeError, "Can't find server port information"
        else
                dibs_address = BUILD_SERVER_ADDRESS + ":" + dibs_config.value
        end
 
-       options = "-d #{dibs_address} --async "
+       options = "-d #{dibs_address} --async -U #{email} -w \'#{password}\'"
        options = options + " -N #{project_list.join(",")} -D #{distribution} " 
        if (os_list.length > 1) or (not os_list[0].nil?)
                options = options + " -o #{os_list.join(",")} "
        end
-       if (password_list.length > 1) or (not (password_list[0].nil? or password_list[0].empty?))
-               options = options + " -w #{password_list.join(",")} "
-       end
-       if not email.nil?
-               options = options + " -U #{email} "
-       end
 
-       cmd = "#{dibs_path}/build-cli build #{options}"
+       cmd = "#{DIBS_PATH}/build-cli build #{options}"
 puts "Build command"
 puts "[[[#{cmd}]]]"
 
-       return execute_shell_return(cmd)
+       result, msg = execute_shell_return(cmd)
+       msg.each { |line|
+               if line =~ /Info: Added new job "([0-9][0-9]*)" for.*/ then 
+                       job_id = $1 
+               end
+       }
+       return result, job_id, msg
   end
 
-  def Utils.sbi_register_command(distribution, file_path, password, email)
-       dibs_path = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__))))
+  def Utils.sbi_register_command(distribution, file_path, email, password)
        dibs_config = Server_config.find(:first, :conditions => ["property = \"port\""])
        if dibs_config.nil?
-               raise RuntimeError, "Build sever not started"
+               raise RuntimeError, "Can't find server port information"
        else
                dibs_address = BUILD_SERVER_ADDRESS + ":" + dibs_config.value
        end
 
-       options = "-P #{file_path} -d #{dibs_address} -D #{distribution} --async "
-       if (not password.nil?)
-               options = options + " -w #{password}"
-       end
-       if not email.nil?
-               options = options + " -U #{email} "
-       end
+       options = "-P #{file_path} -d #{dibs_address} -D #{distribution} --async -U #{email} -w \'#{password}\' "
 
-       cmd = "#{dibs_path}/build-cli register #{options}"
+       cmd = "#{DIBS_PATH}/build-cli register #{options}"
 puts "Register command"
 puts "[[[#{cmd}]]]"
        return execute_shell_return(cmd)
   end
 
-  def Utils.sbi_cancel_command(job_id, password)
-       dibs_path = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__))))
+  def Utils.sbi_cancel_command(job_id, email, password)
        dibs_config = Server_config.find(:first, :conditions => ["property = \"port\""])
        if dibs_config.nil?
-               raise RuntimeError, "Build sever not started"
+               raise RuntimeError, "Can't find server port information"
        else
                dibs_address = BUILD_SERVER_ADDRESS + ":" + dibs_config.value
        end
@@ -94,38 +87,77 @@ puts "[[[#{cmd}]]]"
                raise RuntimeError, "Invalid job id : #{job_id}"
        end
 
-       options = "-d #{dibs_address} "
-       options = options + " -j #{job_id}"
-       if (not password.nil?)
-               options = options + " -w #{password}"
-       end
+       options = "-d #{dibs_address} -j #{job_id} -U #{email} -w \'#{password}\' "
 
-       cmd = "#{dibs_path}/build-cli cancel #{options}"
+       cmd = "#{DIBS_PATH}/build-cli cancel #{options}"
 puts "Cancel command"
 puts "[[[#{cmd}]]]"
-       return execute_shell_return(cmd)
+       result, msg = execute_shell_return(cmd)
+       return result, msg
   end
 
   def Utils.sbi_fullbuild_command(server_name, dist_name)
-       dibs_path = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__))))
-
        options = "-n #{server_name} --dist #{dist_name} "
-       cmd = "#{dibs_path}/build-svr fullbuild #{options}"
+       cmd = "#{DIBS_PATH}/build-svr fullbuild #{options}"
        cmd = "which ruby"
 puts "Fullbuild command"
 puts "[[[#{cmd}]]]"
        return execute_shell_return(cmd)
   end
 
+  def Utils.sbi_query_log_command(job_id, path)
+       dibs_web_config_path = File.join(Utils::HOME,".build_tools","web_server")
+       dibs_config = Server_config.find(:first, :conditions => ["property = \"port\""])
+       if dibs_config.nil?
+               raise RuntimeError, "Can't find server port information"
+       else
+               dibs_address = BUILD_SERVER_ADDRESS + ":" + dibs_config.value
+       end
+
+       if job_id.nil? or path.nil? then
+               raise RuntimeError, "Invalid query command id : #{job_id} path : #{path}"
+       end
+
+       options = "-d #{dibs_address} "
+       options = options + " -j #{job_id}"
+       options = options + " --output #{path}"
+
+       cmd = "#{DIBS_PATH}/build-cli query-log #{options}"
+puts "Query-log command"
+puts "[[[#{cmd}]]]"
+
+       Thread.new do
+               system(cmd)
+       end
+
+       return path
+  end
+
   def Utils.execute_shell_return(cmd)
+       result = false
     result_lines = []
-    ret = false
   
     # get result
-    #IO.popen("#{cmd}")
-    system "#{cmd}"
+       IO.popen("#{cmd} 2>&1") do |io|
+               io.each do |line|
+                       result_lines.push line
+               end
+       end
 
-       return true
+       if $? == 0 then
+               result = true
+       end
+
+       return result, result_lines
   end
 
+       # set static variable in WORKING_DIR, HOME
+       if defined?(WORKING_DIR).nil? then WORKING_DIR = Dir.pwd end
+       if defined?(HOME).nil? then
+               # get home directory, using Dir.chdir
+               Dir.chdir
+               HOME = Dir.pwd
+               Dir.chdir WORKING_DIR
+       end
+       DIBS_WEB_CONFIG_PATH = File.join(HOME,".build_tools","web_server")
 end
index 3c15994..c48ed96 100644 (file)
@@ -1,3 +1,3 @@
 class Job < ActiveRecord::Base
-  attr_accessible :distribution_id, :id, :supported_os_id, :project_id, :status, :user_id, :remote_build_server_id, :parent_job_id, :source_id, :jtype, :start_time, :end_time
+  attr_accessible :distribution_id, :id, :supported_os_id, :project_id, :status, :user_id, :remote_build_server_id, :parent_job_id, :source_id, :jtype, :start_time, :end_time, :error_code
 end
index 1c9d56e..1c66c6a 100644 (file)
@@ -1,3 +1,3 @@
 class Project < ActiveRecord::Base
-   attr_accessible :id, :distribution_id, :name, :ptype, :password
+   attr_accessible :id, :distribution_id, :name, :ptype, :status
 end
index ebfb5f1..40432ec 100644 (file)
@@ -1,7 +1,7 @@
 class User < ActiveRecord::Base
 #      has_many :user_groups
 #      has_many :groups, :through => :user_groups
-       attr_accessible :id, :email, :password, :password_confirmation, :name
+       attr_accessible :id, :email, :password, :password_confirmation, :password_hash, :name
 
        attr_accessor :password
        before_save :encrypt_password
index b9b9e8d..851c7e8 100644 (file)
@@ -34,7 +34,6 @@ Dibs::Application.routes.draw do
 
     get "jobs" => "jobs#list"
     
-       get "projects" => "projects#projects"
        get "projects/fileUpload"
     
        get "signup" => "users#new", :as => "signup"
@@ -58,24 +57,23 @@ Dibs::Application.routes.draw do
     get "jobs/list/date/:date/:distribution/:status/:lastID" => "jobs#listSearchDate", :constraints => { :distribution => /[0-9A-Za-z\-\.\_]+/ }
 
        match "jobs/update" => "jobs#updateList", :format => "json"
-       match "jobs/log/:id" => "jobs#log"
        match "jobs/log/:id/:line" => "jobs#log_more"
        match "jobs/cancel/:id" => "jobs#cancelJob"
 
 
        get "projects/queryDistribution"
-       match "projects/queryProject/:distribution" => "projects#queryProject", :constraints => { :distribution => /[0-9A-Za-z\-\.\_]+/ }
+       get "projects/queryAllDistribution"
+       get "projects/queryAllProjectInOpenStatus" 
        post "projects/binaryFileUpload"
        
        # projects
-       match "projects/queryRunningProjectsInfoInDistribution/:distribution" => "projects#queryRunningProjectsInfoInDistribution", :constraints => { :distribution => /[0-9A-Za-z\-\.\_]+/ }
-       match "projects/queryProjectsInfoInDistribution/:distribution" => "projects#queryProjectsInfoInDistribution", :constraints => { :distribution => /[0-9A-Za-z\-\.\_]+/ }
-       match "projects/queryProjectsInDistribution/:distribution" => "projects#queryProjectsInDistribution" , :constraints => { :distribution => /[0-9A-Za-z\-\.\_]+/ }
+       match "projects/queryProjectsInfoInDistribution/:distId" => "projects#queryProjectsInfoInDistribution"
+       match "projects/queryProjectsInDistribution/:distId" => "projects#queryProjectsInDistribution"
        post "projects/buildProject" 
 
        # admin group
        get "admin_group/queryAllGroup" 
-       match "admin_group/queryGroupInfo/:groupName" => "admin_group#queryGroupInfo"
+       match "admin_group/queryGroupInfo/:groupId" => "admin_group#queryGroupInfo"
        post "admin_group/addGroup"
        post "admin_group/removeGroup"
        post "admin_group/modifyGroup"
@@ -88,12 +86,15 @@ Dibs::Application.routes.draw do
 
        # admin server
        get "admin_server/queryAllServer" 
+       match "admin_server/queryServerConfig/:configId" => "admin_server#queryServerConfig"
+       match "admin_server/querySupportedOS/:osId" => "admin_server#querySupportedOS"
+       match "admin_server/queryRemoteBuildServer/:serverId" => "admin_server#queryRemoteBuildServer"
        post "admin_server/addRemoteBuildServer" 
        post "admin_server/removeRemoteBuildServer" 
        post "admin_server/modifyRemoteBuildServer" 
-       post "admin_server/addOsCategory" 
-       post "admin_server/removeOsCategory" 
-       post "admin_server/modifyOsCategory" 
+       post "admin_server/addOSCategory" 
+       post "admin_server/removeOSCategory" 
+       post "admin_server/modifyOSCategory" 
        post "admin_server/addSupportedOS" 
        post "admin_server/removeSupportedOS" 
        post "admin_server/modifySupportedOS" 
@@ -102,20 +103,18 @@ Dibs::Application.routes.draw do
        post "admin_server/modifyServerInfo" 
 
        # admin project 
-       get "admin_project/queryAllProject" 
-       match "admin_project/queryProjectsInDistributionForAdmin/:distribution" => "admin_project#queryProjectsInDistributionForAdmin", :constraints => { :distribution => /[0-9A-Za-z\-\.\_]+/ }
+       match "admin_project/queryProjectsInDistributionForAdmin/:distId" => "admin_project#queryProjectsInDistributionForAdmin"
        post "admin_project/addProject" 
        post "admin_project/removeProject" 
        post "admin_project/modifyProject" 
+       post "admin_project/changeAllProjectStatus" 
 
        # admin distribution
-       match "admin_distribution/queryDistributionInfo/:distribution" => "admin_distribution#queryDistributionInfo", :constraints => { :distribution => /[0-9A-Za-z\-\.\_]+/ } 
+       match "admin_distribution/queryDistributionInfo/:distId" => "admin_distribution#queryDistributionInfo"
        post "admin_distribution/addDistribution" 
        post "admin_distribution/removeDistribution" 
        post "admin_distribution/modifyDistribution" 
 
-       post "admin_distribution/fullBuildDistribution" 
-
        get "admin/queryAllOS" 
        get "admin/queryAllOSCategory" 
 
index 23771bb..14ff2ec 100644 (file)
@@ -100,11 +100,21 @@ Contributors:
                <div data-role="content">
                        <form id="login-form">
                                <label for="login-form-email" >Email</label>
-                               <input id="login-form-email" type="email" name="email"/>
-                               <label for="login-form-password">Password</label>
-                               <input id="login-form-password" type="password" name="password"/>
+                               <span style="float: left; width: 80%;">
+                                       <input id="login-form-email" type="email" name="email" autocomplete="on"/>
+                               </span>
+                               <span style="float: right;">
+                                       <input id="login-form-save" type="checkbox" name="save" class="custom" data-mini="true" checked/>
+                                       <label for="login-form-save">Save</label>
+                               </span>
+                               <div style="clear: both; float: left;">
+                                       <label for="login-form-password">Password</label>
+                               </div>
+                               <div style="clear: both;">
+                                       <input id="login-form-password" type="password" name="password"/>
+                               </div>
                                <br/>
-                               <div data-role="controlgroup" data-type="horizontal">   
+                               <div data-role="controlgroup" data-type="horizontal" style="float: left;">   
                                        <a href="#" data-rel="back" data-role="button" data-mini="true" >Cancel</a>
                                        <a href="#" onClick="sessionLogin()" data-role="button" data-mini="true" >Log in</a>
                                </div>
@@ -145,20 +155,20 @@ Contributors:
                <div data-role="content" >
                        <div class="content-primary">
                                <div data-role="fieldcontain" style="text-align: center; font-size: 14px;">
-                                       <select id="projects-distribution-select"  data-native-menu="false" onchange='projectsQueryProjectListType("MY")'>
+                                       <select id="projects-distribution-select"  data-native-menu="false" onchange='projectsQueryProjectListType()'>
                                        </select>
                                </div>
                                <br>
                                <div id="projects-type-select">
                                        <fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
                                                <form>
-                                                       <input type="radio" name="radio-choice" id="projects-type-select-1" checked="checked" onClick='projectsQueryProjectListType("MY")' />
+                                                       <input type="radio" name="projects-type-select" id="projects-type-select-1" value="MY" checked="checked" onClick='projectsQueryProjectListType()' />
                                                        <label for="projects-type-select-1">MY PROJECT</label>
-                                                       <input type="radio" name="radio-choice" id="projects-type-select-2" onClick='projectsQueryProjectListType("ALL")'/>
+                                                       <input type="radio" name="projects-type-select" id="projects-type-select-2" value="ALL" onClick='projectsQueryProjectListType()'/>
                                                        <label for="projects-type-select-2">ALL PROJECT</label>
-                                                       <input type="radio" name="radio-choice" id="projects-type-select-3" onClick='projectsQueryProjectListType("GIT")' />
+                                                       <input type="radio" name="projects-type-select" id="projects-type-select-3" value="GIT" onClick='projectsQueryProjectListType()' />
                                                        <label for="projects-type-select-3">GIT PROJECT</label>
-                                                       <input type="radio" name="radio-choice" id="projects-type-select-4" onClick='projectsQueryProjectListType("BINARY")' />
+                                                       <input type="radio" name="projects-type-select" id="projects-type-select-4" value="BINARY" onClick='projectsQueryProjectListType()' />
                                                        <label for="projects-type-select-4">BINARY PROJECT</label>
                                                </form>
                                        </fieldset>
@@ -191,6 +201,7 @@ Contributors:
                                                </select>
                                        </div>
                                </div>
+                               <div id="build-distribution-lock"> </div>
                                <div data-role="collapsible" data-collapsed="false" style="width: auto;" >
                                        <h3>Git project</h3>
                                        <div align="right" style="font-size: 10px">
@@ -287,7 +298,7 @@ Contributors:
                                        <a href="#" onClick="searchJobDate()" data-role="button" data-mini="true"  data-inline="true">Search</a>
                                </div>
                                <br>
-
+                               <br>
                                <ul id="jobs-job-list" data-role="listview">
                                </ul>
                                <br>
@@ -332,11 +343,13 @@ Contributors:
                </div>
                <div data-role="content">
                        <form method="post" style="font-size: 12px">
+                               <input type="hidden" id="adminUserModify-id" name="id" /> 
+                               <br>
                                <label for="adminUserModify-name"> User name </label>
-                               <input type="text" id="adminUserModify-name" name="adminUserModify-contents" /> 
+                               <input type="text" id="adminUserModify-name" name="name" /> 
                                <br>
                                <label for="adminUserModify-email"> Email </label>
-                               <input type="text" id="adminUserModify-email" name="adminUserModify-contents" disabled="disabled"/>
+                               <input type="text" id="adminUserModify-email" name="email" />
                                <br>
                                <div>
                                        <fieldset data-role="controlgroup" data-mini="true" data-role="fieldcontain" id="adminUserModify-group">
@@ -347,7 +360,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href=#adminUser onClick="adminUserModify()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href=#adminUser onClick="adminUserModify()" data-role="button" data-inline="true" data-mini="true" data-icon="gear" id="adminUserModify-save">Save</a>
                </div>
        </div><!-- /page -->
 
@@ -363,7 +376,7 @@ Contributors:
                        <div class="content-primary">
                                <h2>Group information</h2>
                                <div align="right" style="font-size: 10px">
-                                       <a href="#adminGroupAdd" data-role="button" data-rel="dialog"  data-inline="true" data-icon="plus"> Add group </a>
+                                       <a href="#adminGroupAdd" data-role="button" data-rel="dialog"  data-inline="true" data-mini="ture" data-icon="plus"> Add group </a>
                                </div>
                                <div data-role="content" class="container">
                                        <table class="imagetable" style="font-size: 14px" id="adminGroup-contents">
@@ -390,7 +403,7 @@ Contributors:
                        <div class="content-primary">
                                <h2>Server information</h2>
                                <div align="right" style="font-size: 10px">
-                                       <a href="#adminServerAddServerInfo" data-role="button" data-rel="dialog" data-inline="true" data-icon="plus"> Add server config </a>
+                                       <a href="#adminServerAddServerInfo" data-role="button" data-rel="dialog" data-inline="true" data-mini="ture" data-icon="plus"> Add server config </a>
                                </div>
                                <div data-role="collapsible" data-theme="c" data-content-theme="d" data-collapsed="false">
                                        <h2> Server info </h2>
@@ -398,9 +411,9 @@ Contributors:
                                        </ul>
                                </div>  
                                <div align="right" style="font-size: 10px">
-                                       <a href="#adminServerAddSupportedOs" data-role="button" data-rel="dialog" data-inline="true" data-icon="plus"> Add supported os</a>
-                                       <a href="#adminServerAddOSCategory" data-role="button" data-rel="dialog" data-inline="true" data-icon="plus"> Add os category</a>
-                                       <a href="#adminServerRemoveOSCategory" data-role="button" data-rel="dialog" data-inline="true" data-icon="minus"> Remove os category</a>
+                                       <a href="#adminServerAddSupportedOs" data-role="button" data-rel="dialog" data-inline="true" data-mini="ture" data-icon="plus"> Add supported os</a>
+                                       <a href="#adminServerAddOSCategory" data-role="button" data-rel="dialog" data-inline="true" data-mini="ture" data-icon="plus"> Add os category</a>
+                                       <a href="#adminServerRemoveOSCategory" data-role="button" data-rel="dialog" data-inline="true" data-mini="ture" data-icon="minus"> Remove os category</a>
                                </div>
                                <div data-role="collapsible" data-theme="c" data-content-theme="d" data-collapsed="false">
                                        <h2> Supported OS </h2>
@@ -408,7 +421,7 @@ Contributors:
                                        </ul>
                                </div>  
                                <div align="right" style="font-size: 10px">
-                                       <a href="#adminServerAddRemoteBuildServer" data-role="button" data-rel="dialog" data-inline="true" data-icon="plus"> Add remote build server </a>
+                                       <a href="#adminServerAddRemoteBuildServer" data-role="button" data-rel="dialog" data-inline="true" data-mini="ture" data-icon="plus"> Add remote build server </a>
                                </div>  
                                <div data-role="collapsible" data-theme="c" data-content-theme="d" data-collapsed="false">
                                        <h2> Remote build server </h2>
@@ -441,11 +454,15 @@ Contributors:
                                        </div>
                                </div>
                                <div>
+                                       <div align="right" style="font-size: 10px">
+                                               <a href="#" data-role="button" data-inline="true" data-mini="true" onClick='adminProjectAllProjectStatusChange("OPEN")'>ALL project OPEN</a>
+                                               <a href="#" data-role="button" data-inline="true" data-mini="true" onClick='adminProjectAllProjectStatusChange("CLOSE")'>ALL project CLOSE</a>
+                                       </div>
                                        <div style="margin-left: 20px; margin-right: 20px; margin-top: 10px">
                                                <div data-role="collapsible" data-theme="b" data-content-theme="c" data-collapsed="false" > 
                                                        <h2> Git project </h2>
                                                        <div align="right" style="font-size: 10px">
-                                                               <a href="#adminProjectAddGit"  data-role="button" data-rel="dialog"  data-inline="true" data-icon="plus"> Add git project</a>
+                                                               <a href="#adminProjectAddGit"  data-role="button" data-rel="dialog" data-inline="true" data-mini="true" data-icon="plus"> Add git project</a>
                                                        </div>
                                                        <br> 
                                                        <table class="imagetable" id="adminProject-git" style="font-size: 14px">
@@ -455,7 +472,7 @@ Contributors:
                                                <div data-role="collapsible" data-theme="b" data-content-theme="c" data-collapsed="false" > 
                                                        <h2> Binary project </h2>
                                                        <div align="right" style="font-size: 10px">
-                                                               <a href="#adminProjectAddBinary"  data-role="button"data-rel="dialog"  data-inline="true" data-icon="plus"> Add binary project</a>
+                                                               <a href="#adminProjectAddBinary"  data-role="button"data-rel="dialog" data-inline="true" data-mini="true" data-icon="plus"> Add binary project</a>
                                                        </div>
                                                        <table class="imagetable" id="adminProject-binary" style="font-size: 14px">
                                                        </table>
@@ -487,9 +504,6 @@ Contributors:
                                                <select id="adminDistribution-distribution-select" data-native-menu="false" onchange="adminDistributionSetInfo()">
                                                </select>
                                        </div>
-                                       <div align="right" style="font-size: 10px">
-                                               <a href="javascript:adminDistributionFullBuild()" data-role="button" data-inline="true" data-icon="gear"> Full build</a>
-                                       </div>
                                        <div data-role="collapsible" data-theme="c" data-content-theme="d" data-collapsed="false" > 
                                                <h2> Package server url </h2>
                                                <p id="adminDistribution-url" style="font-size: 14px"> </p>
@@ -513,9 +527,9 @@ Contributors:
                                        </div>  
                                        <br> 
                                        <div align="right" style="font-size: 10px">
-                                               <a href="#adminDistributionAdd" data-role="button" data-rel="dialog" data-inline="true" data-icon="plus"> Add distribution</a>
-                                               <a href="#adminDistributionModify" data-role="button" data-rel="dialog" data-inline="true" data-icon="gear"> Modify distribution</a>
-                                               <a href="javascript:adminDistributionRemove()" data-role="button" data-rel="dialog" data-inline="true" data-icon="minus"> Remove distribution</a>
+                                               <a href="#adminDistributionAdd" data-role="button" data-rel="dialog" data-inline="true" data-mini="true" data-icon="plus"> Add distribution</a>
+                                               <a href="#adminDistributionModify" data-role="button" data-rel="dialog" data-inline="true" data-mini="true" data-icon="gear"> Modify distribution</a>
+                                               <a href="javascript:adminDistributionRemove()" data-role="button" data-rel="dialog" data-inline="true" data-mini="true" data-icon="minus"> Remove distribution</a>
                                        </div>
                                </div>
                        </div><!--/content-primary -->
@@ -563,7 +577,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href=# onClick="adminDistributionAdd()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href=# onClick="adminDistributionAdd()" data-role="button" data-inline="true" data-mini="true" data-icon="gear">Save</a>
                </div>
        </div><!-- /page -->
        
@@ -573,6 +587,8 @@ Contributors:
                </div>
                <div data-role="content">
                        <form method="post" style="font-size: 12px">
+                               <input type="hidden" id="adminDistributionModify-id" name="id" />
+                               <br>
                                <label for="adminDistributionModify-url"> Package server url </label>
                                <input type="text" id="adminDistributionModify-url" name="description" />
                                <br>
@@ -611,15 +627,16 @@ Contributors:
                                <label for="adminProjectAddGit-name"> Project name </label>
                                <input type="text" id="adminProjectAddGit-name" name="name" />
                                <br>
-                               <label for="adminProjectAddGit-password"> Project password </label>
-                               <input type="text" id="adminProjectAddGit-password" name="password" />
-                               <br>
                                <label for="adminProjectAddGit-address"> Git address </label>
                                <input type="text" id="adminProjectAddGit-address" name="address" />
                                <br>
                                <label for="adminProjectAddGit-branch"> Git Branch </label>
                                <input type="text" id="adminProjectAddGit-branch" name="branch" />
                                <br>
+                               <label for="adminProjectAddGit-status"> Project status </label>
+                               <select id="adminProjectAddGit-status" name="status" >
+                               </select>
+                               <br>
                                <div data-role="fieldcontain">
                                        <fieldset data-role="controlgroup" data-mini="true" id="adminProjectAddGit-os" name="os" >
                                        </fieldset>
@@ -628,7 +645,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#adminProject" onClick="adminProjectAddGitProject()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href="#adminProject" onClick="adminProjectAddGitProject()" data-role="button" data-inline="true" data-mini="true" data-icon="gear">Save</a>
                </div>
        </div><!-- /page -->
        
@@ -641,11 +658,13 @@ Contributors:
                                <label for="adminProjectAddBinary-name"> Project name </label>
                                <input type="text" id="adminProjectAddBinary-name" name="name" />
                                <br>
-                               <label for="adminProjectAddBinary-password"> Project password</label>
-                               <input type="text" id="adminProjectAddBinary-password" name="password" />
-                               <br>
                                <label for="adminProjectAddBinary-packagename"> Pakcage name</label>
                                <input type="text" id="adminProjectAddBinary-packagename" name="name" />
+                               <br>
+                               <label for="adminProjectAddBinary-status"> Project status </label>
+                               <select id="adminProjectAddBinary-status" name="status" >
+                               </select>
+                               <br>
                                <div data-role="fieldcontain">
                                        <fieldset data-role="controlgroup" data-mini="true" id="adminProjectAddBinary-os" name="os" >
                                        </fieldset>
@@ -654,7 +673,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#" onClick="adminProjectAddBinaryProject()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href="#" onClick="adminProjectAddBinaryProject()" data-role="button" data-inline="true" data-mini="true" data-icon="gear">Save</a>
                </div>
        </div><!-- /page -->
        
@@ -664,13 +683,14 @@ Contributors:
                </div>
                <div data-role="content">
                        <form method="post" style="font-size: 12px">
-                               <input type="hidden" id="adminProjectModifyBinary-oldName" disabled="disabled" name="name" /> 
+                               <input type="hidden" id="adminProjectModifyBinary-id" disabled="disabled" name="id" /> 
                                <br>
-                               <label for="adminProjectModifyBinary-newName"> New Project name </label>
-                               <input type="text" id="adminProjectModifyBinary-newName" name="name" /> 
+                               <label for="adminProjectModifyBinary-name"> Project name </label>
+                               <input type="text" id="adminProjectModifyBinary-name" name="name" /> 
                                <br>
-                               <label for="adminProjectModifyBinary-password"> Project password</label>
-                               <input type="text" id="adminProjectModifyBinary-password" name="name" />
+                               <label for="adminProjectModifyBinary-status"> Project status </label>
+                               <select id="adminProjectModifyBinary-status" name="status" >
+                               </select>
                                <br>
                                <label for="adminProjectModifyBinary-packageName"> Pakcage name</label>
                                <input type="text" id="adminProjectModifyBinary-packageName" name="name" />
@@ -682,7 +702,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#" onClick="adminProjectModfyBinaryProject()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href="#" onClick="adminProjectModfyBinaryProject()" data-role="button" data-inline="true" data-mini="true" data-icon="gear" id="adminProjectModifyBinary-save">Save</a>
                </div>
        </div><!-- /page -->
 
@@ -692,13 +712,14 @@ Contributors:
                </div>
                <div data-role="content">
                        <form method="post" style="font-size: 12px">
-                               <input type="hidden" id="adminProjectModifyGit-oldName" disabled="disabled" name="name" /> 
+                               <input type="hidden" id="adminProjectModifyGit-id" disabled="disabled" name="id" /> 
                                <br>
-                               <label for="adminProjectModifyGit-newName"> New Project name </label>
-                               <input type="text" id="adminProjectModifyGit-newName" name="name" /> 
+                               <label for="adminProjectModifyGit-name"> Project name </label>
+                               <input type="text" id="adminProjectModifyGit-name" name="name" /> 
                                <br>
-                               <label for="adminProjectModifyGit-password"> Project password</label>
-                               <input type="text" id="adminProjectModifyGit-password" name="password" />
+                               <label for="adminProjectModifyGit-status"> Project status </label>
+                               <select id="adminProjectModifyGit-status" name="status" >
+                               </select>
                                <br>
                                <label for="adminProjectModifyGit-address"> Git address </label>
                                <input type="text" id="adminProjectModifyGit-address" name="address" />
@@ -714,7 +735,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#" onClick="adminProjectModfyGitProject()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href="#" onClick="adminProjectModfyGitProject()" data-role="button" data-inline="true" data-mini="true" data-icon="gear" id="adminProjectModifyGit-save">Save</a>
                </div>
        </div><!-- /page -->
 
@@ -747,7 +768,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href=# onClick="adminGroupAddGroup()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href=# onClick="adminGroupAddGroup()" data-role="button" data-inline="true" data-mini="true" data-icon="gear">Save</a>
                </div>
        </div><!-- /page -->
        
@@ -757,10 +778,10 @@ Contributors:
                </div>
                <div data-role="content" data-role="fieldcontain">
                        <form method="post" style="font-size: 12px">
-                               <input type="hidden" id="adminGroupModify-oldName" name="name" />
+                               <input type="hidden" id="adminGroupModify-id" name="id" />
                                <br>
-                               <label for="adminGroupModify-newName"> New group name </label>
-                               <input type="text" id="adminGroupModify-newName" name="name" />
+                               <label for="adminGroupModify-name"> Group name </label>
+                               <input type="text" id="adminGroupModify-name" name="name" />
                                <br>
                                <div data-role="fieldcontain">
                                        <label for="adminGroupModify-admin"> Admin Flag </label>
@@ -780,7 +801,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#" onClick="adminGroupModifyGroup()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href="#" onClick="adminGroupModifyGroup()" data-role="button" data-inline="true" data-mini="true" data-icon="gear" id="adminGroupModify-save">Save</a>
                </div>
        </div><!-- /page -->
        
@@ -798,7 +819,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href=# onClick="adminServerAddRemoteBuildServer()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href=# onClick="adminServerAddRemoteBuildServer()" data-role="button" data-inline="true" data-mini="true" data-icon="gear">Save</a>
                </div>
        </div><!-- /page -->
        
@@ -807,18 +828,18 @@ Contributors:
                </div>
                <div data-role="content" data-role="fieldcontain">
                        <form method="post" style="font-size: 12px">
-                               <input type="hidden" id="adminServer-modifyRemoteBuildServer-OldAddress" name="address" />
+                               <input type="hidden" id="adminServer-modifyRemoteBuildServer-id" name="id" />
                                <br>
-                               <label for="adminServer-modifyRemoteBuildServer-newAddress"> New server address </label>
-                               <input type="text" id="adminServer-modifyRemoteBuildServer-newAddress" name="address" />
+                               <label for="adminServer-modifyRemoteBuildServer-address"> Server address </label>
+                               <input type="text" id="adminServer-modifyRemoteBuildServer-address" name="address" />
                                <br>
                                <label for="adminServer-modifyRemoteBuildServer-description"> Description </label>
                                <input type="text" id="adminServer-modifyRemoteBuildServer-description" name="description" />
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href=# onClick="adminServerModifyRemoteBuildServer()" data-role="button" data-inline="true" data-icon="gear">Save</a>
-                       <a href=# onClick="adminServerRemoveRemoteBuildServer()" data-role="button" data-inline="true" data-icon="minus">Delete</a>
+                       <a href=# onClick="adminServerModifyRemoteBuildServer()" data-role="button" data-inline="true" data-mini="true" data-icon="gear" id="adminServer-modifyRemoteBuildServer-save" >Save</a>
+                       <a href=# onClick="adminServerRemoveRemoteBuildServer()" data-role="button" data-inline="true" data-mini="true" data-icon="minus">Delete</a>
                </div>
        </div><!-- /page -->
 
@@ -842,7 +863,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#" onClick="userModifyUserInfo()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href="#" onClick="userModifyUserInfo()" data-role="button" data-inline="true" data-mini="true" data-icon="gear">Save</a>
                </div>
        </div><!-- /page -->
        
@@ -852,19 +873,21 @@ Contributors:
                </div>
                <div data-role="content" data-role="fieldcontain">
                        <form method="post" style="font-size: 12px">
-                               <label for="adminServer-AddSupportedOs-OsName">Supported os name</label>
-                               <input type="text" id="adminServer-AddSupportedOs-OsName" name="os" />
+                               <input type="hidden" id="adminServer-AddSupportedOs-id" name="id" />
+                               <br>
+                               <label for="adminServer-AddSupportedOs-name">Supported os name</label>
+                               <input type="text" id="adminServer-AddSupportedOs-name" name="name" />
                                <br>
                                <div data-role="fieldcontain">
                                        <label for="adminServer-AddSupportedOs-OsCategory"> Os category </label>
                                        <br>
-                                       <select id="adminServer-AddSupportedOs-OsCategory" name="os-category" >
+                                       <select id="adminServer-AddSupportedOs-OsCategory" name="category" >
                                        </select>
                                </div>
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#" onClick="adminServerAddSupportedOs()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href="#" onClick="adminServerAddSupportedOs()" data-role="button" data-inline="true" data-mini="true" data-icon="gear">Save</a>
                </div>
        </div><!-- /page -->
 
@@ -874,9 +897,10 @@ Contributors:
                </div>
                <div data-role="content" data-role="fieldcontain">
                        <form method="post" style="font-size: 12px">
-                               <input type="hidden" id="adminServer-ModifySupportedOs-OldOsName" disabled="disabled" name="name" />
-                               <label for="adminServer-ModifySupportedOs-OsName">Supported os name</label>
-                               <input type="text" id="adminServer-MoidfySupportedOs-OsName" name="name" />
+                               <input type="hidden" id="adminServer-ModifySupportedOs-id" name="id" />
+                               <br>
+                               <label for="adminServer-ModifySupportedOs-name">Supported os name</label>
+                               <input type="text" id="adminServer-MoidfySupportedOs-name" name="name" />
                                <br>
                                <div data-role="fieldcontain">
                                        <label for="adminServer-ModifySupportedOs-OsCategory"> Os category </label>
@@ -887,8 +911,8 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#" onClick="adminServerRemoveSupportedOS()" data-role="button" data-inline="true" data-icon="minus">Remove</a>
-                       <a href="#" onClick="adminServerModifySupportedOS()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href="#" onClick="adminServerModifySupportedOS()" data-role="button" data-inline="true" data-mini="true" data-icon="gear" id="adminServer-ModifySupportedOs-save" >Save</a>
+                       <a href="#" onClick="adminServerRemoveSupportedOS()" data-role="button" data-inline="true" data-mini="true" data-icon="minus">Remove</a>
                </div>
        </div><!-- /page -->
 
@@ -898,18 +922,18 @@ Contributors:
                </div>
                <div data-role="content" data-role="fieldcontain">
                        <form method="post" style="font-size: 12px">
-                               <label for="adminServer-AddOsCategory-Name">OS category name</label>
-                               <input type="text" id="adminServer-AddOsCategory-Name" name="name" />
+                               <label for="adminServer-AddOsCategory-name">OS category name</label>
+                               <input type="text" id="adminServer-AddOsCategory-name" name="name" />
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#" onClick="adminServerAddOSCategory()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href="#" onClick="adminServerAddOSCategory()" data-role="button" data-inline="true" data-mini="true" data-icon="gear">Save</a>
                </div>
        </div><!-- /page -->
 
        <div data-role="page" id="adminServerRemoveOSCategory" style="height: 800px; width: 800px"> 
                <div data-role="header" >
-                       <h1>Add os category</h1>
+                       <h1>Remove os category</h1>
                </div>
                <div data-role="content" data-role="fieldcontain">
                        <form method="post" style="font-size: 12px">
@@ -922,7 +946,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href="#" onClick="adminServerRemoveOSCategory()" data-role="button" data-inline="true" data-icon="minus">Delete</a>
+                       <a href="#" onClick="adminServerRemoveOSCategory()" data-role="button" data-inline="true" data-mini="true" data-icon="minus">Delete</a>
                </div>
        </div><!-- /page -->
 
@@ -939,7 +963,7 @@ Contributors:
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href=# onClick="adminServerAddServerInfo()" data-role="button" data-inline="true" data-icon="gear">Save</a>
+                       <a href=# onClick="adminServerAddServerInfo()" data-role="button" data-inline="true" data-mini="true" data-icon="gear">Save</a>
                </div>
        </div><!-- /page -->
 
@@ -948,16 +972,18 @@ Contributors:
                </div>
                <div data-role="content" data-role="fieldcontain">
                        <form method="post" style="font-size: 12px">
+                               <input type="hidden" id="adminServer-modifyServerInfo-id" name="property" />
+                               <br>
                                <label for="adminServer-modifyServerInfo-property"> Property</label>
-                               <input type="text" id="adminServer-modifyServerInfo-property" disabled="disabled" name="property" />
+                               <input type="text" id="adminServer-modifyServerInfo-property" name="property" />
                                <br>
                                <label for="adminServer-modifyServerInfo-value"> Value </label>
                                <input type="text" id="adminServer-modifyServerInfo-value" name="value" />
                        </form>
                </div>
                <div align="right" style="font-size: 10px">
-                       <a href=# onClick="adminServerModifyServerInfo()" data-role="button" data-inline="true" data-icon="gear">Save</a>
-                       <a href=# onClick="adminServerRemoveServerInfo()" data-role="button" data-inline="true" data-icon="minus">Delete</a>
+                       <a href=# onClick="adminServerModifyServerInfo()" data-role="button" data-inline="true" data-mini="true" data-icon="gear" id="adminServer-modifyServerInfo-save">Save</a>
+                       <a href=# onClick="adminServerRemoveServerInfo()" data-role="button" data-inline="true" data-mini="true" data-icon="minus">Delete</a>
                </div>
        </div><!-- /page -->
 
index 679e46a..1508088 100644 (file)
@@ -27,7 +27,7 @@ Contributors:
 */
 
 function adminDistributionModifyPopupInit() {
-       var distName = $("#adminDistribution-distribution-select option:selected").val();
+       var distId = $("#adminDistribution-distribution-select option:selected").val();
        var packageServerUrl = $("#adminDistribution-url").html();
        var packageServeraddress = $("#adminDistribution-address").html();
        var serverStatusText = $("#adminDistribution-status").html();
@@ -54,6 +54,7 @@ function adminDistributionModifyPopupInit() {
                syncPkgSvrDescription = ""
        }
 
+       $("#adminDistributionModify-id").val(distId);
        $("#adminDistributionModify-url").val(packageServerUrl);
        $("#adminDistributionModify-address").val(packageServeraddress);
        $("#adminDistributionModify-description").val(serverDescription);
@@ -73,16 +74,17 @@ function adminDistributionModifyPopupInit() {
        if(serverStatusText.toUpperCase() == "CLOSE") {
                option = '<option value="CLOSE" selected="selected">CLOSE</option>';
        } else {
-               option = '<option value="CLOSE">FALSE</option>';
+               option = '<option value="CLOSE">CLOSE</option>';
        }
        $("#adminDistributionModify-status").append(option);
+       
        $("#adminDistributionModify-status").selectmenu("refresh");
 }
 
 function adminDistributionModify() {
        var changeInfoList = [];
        var changeInfoItem;
-       var distName = $("#adminDistribution-distribution-select option:selected").val();
+       var distId = $("#adminDistributionModify-id").val();
        var url = $("#adminDistributionModify-url").val();
        var address = $("#adminDistributionModify-address").val();
        var description = $("#adminDistributionModify-description").val();
@@ -91,7 +93,7 @@ function adminDistributionModify() {
        var syncPkgSvrPeriod = $("#adminDistributionModify-syncPackageServer-period").val();
        var syncPkgSvrDescription = $("#adminDistributionModify-syncPackageServer-description").val();
 
-       if(distName == "" || url == "" || address == ""){
+       if(distId == "" || url == "" || address == ""){
                alert("You must input full data");
                return;
        }
@@ -100,7 +102,7 @@ function adminDistributionModify() {
                distStatus = "OPEN";
        }
 
-       changeInfoItem = {"DistributionName":distName, "URL":url, "Address":address, "DistStatus":distStatus, "Description":description, "SyncPkgSvrUrl":syncPkgSvrUrl, "SyncPkgSvrPeriod":syncPkgSvrPeriod, "SyncPkgSvrDescription":syncPkgSvrDescription};
+       changeInfoItem = {"DistributionId":distId, "URL":url, "Address":address, "DistStatus":distStatus, "Description":description, "SyncPkgSvrUrl":syncPkgSvrUrl, "SyncPkgSvrPeriod":syncPkgSvrPeriod, "SyncPkgSvrDescription":syncPkgSvrDescription};
        changeInfoList.push(changeInfoItem);
        
        modifyDistribution( changeInfoList, function () {
index 7fd24de..d75f66c 100644 (file)
@@ -27,23 +27,24 @@ Contributors:
 */
 
 function adminDistributionInit() {
-       queryDistribution( function (xml) {
-               var oldDistName = $("#adminDistribution-distribution-select option:selected").val();
+       queryAllDistribution( function (xml) {
+               var oldDistId = $("#adminDistribution-distribution-select option:selected").val();
                var find = false;
-               var distributionList = $(xml).find("Data").find("DistributionName");
+               var distributionList = $(xml).find("Data").find("Distribution");
 
                // remove old select options
                $("#adminDistribution-distribution-select").empty();
 
                distributionList.each(function(){
-                       var name = $(this).text();
+                       var distId = $(this).find("Id").text();
+                       var distName = $(this).find("Name").text();
        
-                       if( oldDistName == name ) {
-                               $("#adminDistribution-distribution-select").append("<option value=\'"+name+"\' selected=\"selected\">"+name+"</option>");
+                       if( oldDistId == distId ) {
+                               $("#adminDistribution-distribution-select").append("<option value=\'"+distId+"\' selected=\"selected\">"+distName+"</option>");
                                find = true;
                                
                        } else {
-                               $("#adminDistribution-distribution-select").append("<option value=\'"+name+"\'>"+name+"</option>");
+                               $("#adminDistribution-distribution-select").append("<option value=\'"+distId+"\'>"+distName+"</option>");
                        }
                });
        
@@ -60,16 +61,17 @@ function adminDistributionInit() {
 }
 
 function adminDistributionSetInfo() {
-       var distName = $("#adminDistribution-distribution-select option:selected").val();
+       var distId = $("#adminDistribution-distribution-select option:selected").val();
 
-       queryDistributionInfo( distName, function (xml) {
-               var data = $(xml).find("Data").find("DistributionInfo");
+       queryDistributionInfo( distId, function (xml) {
                var syncPackageServer = $(xml).find("Data").find("SyncPackageServer");
-               var name = data.find("DistributionName").text();
-               var url = data.find("PackageServerUrl").text();
-               var address = data.find("PackageServerAddress").text();
-               var distStatus = data.find("Status").text();
-               var distDescription = data.find("Description").text();
+               var distInfo = $(xml).find("Data").find("DistributionInfo");
+               var id = distInfo.find("Id").text();
+               var name = distInfo.find("Name").text();
+               var url = distInfo.find("PackageServerUrl").text();
+               var address = distInfo.find("PackageServerAddress").text();
+               var distStatus = distInfo.find("Status").text();
+               var distDescription = distInfo.find("Description").text();
 
                $("#adminDistribution-url").text(url);
                $("#adminDistribution-address").text(address);
@@ -83,12 +85,12 @@ function adminDistributionSetInfo() {
 function adminDistributionRemove() {
        var changeInfoList = [];
        var changeInfoItem;
-       var distName = $("#adminDistribution-distribution-select option:selected").val();
+       var distId = $("#adminDistribution-distribution-select option:selected").val();
 
-       changeInfoItem = {"DistributionName":distName};
+       changeInfoItem = {"DistributionId":distId};
        changeInfoList.push(changeInfoItem);
        
-       var r=confirm("Distribution ["+distName+"] will be removed!!!");
+       var r=confirm("Distribution will be removed!!!");
        if (r==false)
        {
                return;
@@ -108,23 +110,3 @@ function adminDistributionInitSyncPackageServer(serverInfo){
                
        $("#adminDistribution-syncPackageServer").append(info);
 }
-
-function adminDistributionFullBuild() {
-       var changeInfoList = [];
-       var changeInfoItem;
-       var distName = $("#adminDistribution-distribution-select option:selected").val();
-
-       changeInfoItem = {"DistributionName":distName};
-       changeInfoList.push(changeInfoItem);
-       
-       var r=confirm("Distribution ["+distName+"] fullbuild will be started!!! it takes several time");
-       if (r==false)
-       {
-               return;
-       }
-
-       fullBuildDistribution( changeInfoList, function (xml) {
-               $.mobile.changePage("#adminDistribution"); 
-       });
-}
-
index 9811bd6..949b384 100644 (file)
@@ -30,7 +30,7 @@ function adminGroupAddInit() {
        $("#adminGroupAdd-name").val("");
        $("#adminGroupAdd-description").val("");
 
-       queryAllProject( function(xml) {
+       queryAllProjectInOpenStatus( function(xml) {
                var fullProjectList = $(xml).find("Data").find("Project");
 
                adminGroupAddGenerateProjectSelect(fullProjectList);
index 51b4e65..b2e9dec 100644 (file)
@@ -26,14 +26,14 @@ Contributors:
 - S-Core Co., Ltd
 */
 
-function adminGroupModifyInit() {
-       var index = localStorage.groupTableIndex;
-       var groupName = $("#adminGroup-contents-"+index+"-name").html();
-       var adminFlagText = $("#adminGroup-contents-"+index+"-flag").html();
-       var description = $("#adminGroup-contents-"+index+"-description").html();
-
-       $("#adminGroupModify-oldName").val(groupName);
-       $("#adminGroupModify-newName").val(groupName);
+function adminGroupModifyInit(groupId) {
+       var groupName = $("#adminGroup-contents-"+groupId+"-name").html();
+       var adminFlagText = $("#adminGroup-contents-"+groupId+"-flag").html();
+       var description = $("#adminGroup-contents-"+groupId+"-description").html();
+
+       $("#adminGroupModify-save").attr("onClick", "");
+       $("#adminGroupModify-id").val(groupId);
+       $("#adminGroupModify-name").val(groupName);
        $("#adminGroupModify-description").val(description);
 
        $("#adminGroupModify-admin").empty();
@@ -48,21 +48,23 @@ function adminGroupModifyInit() {
        } else {
                $("#adminGroupModify-admin").append('<option value="FALSE">FALSE</option>');
        }
+       $("#adminGroupModify-admin").selectmenu();
        $("#adminGroupModify-admin").selectmenu("refresh");
 
-       queryGroupInfo(groupName, function(xml) {
+       queryGroupInfo(groupId, function(xml) {
                var fullProjectList = $(xml).find("Data").find("Project");
                var projectIdList = $(xml).find("Data").find("Group").find("ProjectIdList").text().split(",");
 
                adminGroupModifyGenerateProjectSelect(fullProjectList, projectIdList);
+               $("#adminGroupModify-save").attr("onClick", "adminGroupModifyGroup()");
        });
 }
 
 function adminGroupModifyGenerateProjectSelect(fullProjectList, projectIdList) {
        $("#adminGroupModify-project").empty();
        fullProjectList.each(function(){
-               var projectName = $(this).find("Name").text();
                var projectId = $(this).find("Id").text();
+               var projectName = $(this).find("Name").text();
                var projectDistName = $(this).find("DistName").text();
 
                var input; 
@@ -83,21 +85,18 @@ function adminGroupModifyGenerateProjectSelect(fullProjectList, projectIdList) {
 }
 
 function adminGroupModifyGroup() {
-       var oldGroupName = $("#adminGroupModify-oldName").val();
-       var groupName = $("#adminGroupModify-newName").val();
+       var groupId = $("#adminGroupModify-id").val();
+       var groupName = $("#adminGroupModify-name").val();
        var description = $("#adminGroupModify-description").val();
        var adminFlag = $("#adminGroupModify-admin option:selected").val();
        var selectProjectList = [];
        var changeInfoList = [];
        
-       var selectArray = $("input[name='adminGroupModify-project-checkbox']");
-       for(var i = 0; i < selectArray.length; i++) {
-               if (selectArray[i].checked == true) {
-                       selectProjectList.push(selectArray[i].value);
-               }
-       }
+       $("input[name='adminGroupModify-project-checkbox']:checked").each(function() {
+               selectProjectList.push($(this).val());
+       });
                
-       changeItem = {"GroupName" : oldGroupName, "NewGroupName":groupName, "AdminFlag":adminFlag, "Description":description, "ProjectList":selectProjectList.toString()};
+       changeItem = {"GroupId" : groupId, "GroupName":groupName, "AdminFlag":adminFlag, "Description":description, "ProjectList":selectProjectList.toString()};
        changeInfoList.push(changeItem);
 
        changeGroup(changeInfoList, function() {
index f897766..2084bb3 100644 (file)
@@ -46,20 +46,19 @@ function adminGroupFillTableInfo(groupList) {
        
        $("#adminGroup-contents").append(tableHeader);
 
-       var index = 2;
-
        groupList.each(function(){
                var row = groupTable.insertRow(-1);
                var cell;
+               var groupId = $(this).find("GroupId").text();
                var groupName = $(this).find("GroupName").text();
                var adminFlag = $(this).find("AdminFlag").text();
                var description = $(this).find("Description").text();
                var projectList = $(this).find("AccessableProject");
 
-               row.setAttribute('id', 'table:'+index);
+               row.setAttribute('id', 'adminGroup-contents-'+groupId);
 
                cell = row.insertCell(-1);
-               cell.setAttribute('id', 'adminGroup-contents-'+index+'-name');
+               cell.setAttribute('id', 'adminGroup-contents-'+groupId+'-name');
                cell.innerHTML = groupName
 
                cell = row.insertCell(-1);
@@ -67,11 +66,11 @@ function adminGroupFillTableInfo(groupList) {
                cell.appendChild(div);
 
                cell = row.insertCell(-1);
-               cell.setAttribute('id', 'adminGroup-contents-'+index+'-flag');
+               cell.setAttribute('id', 'adminGroup-contents-'+groupId+'-flag');
                cell.innerHTML = adminFlag;
 
                cell = row.insertCell(-1);
-               cell.setAttribute('id', 'adminGroup-contents-'+index+'-description');
+               cell.setAttribute('id', 'adminGroup-contents-'+groupId+'-description');
                cell.innerHTML = description;
 
                cell = row.insertCell(-1);
@@ -79,7 +78,7 @@ function adminGroupFillTableInfo(groupList) {
                button.setAttribute('href','#adminGroupModify');
                button.setAttribute('data-role','button');
                button.setAttribute('data-rel','dialog');
-               button.setAttribute('onClick','adminGroupModifySetup(\"'+index+'\")');
+               button.setAttribute('onClick','adminGroupModifyInit(\"'+groupId+'\")');
                button.setAttribute('class','adminGroup-contents-button');
                button.innerHTML = " "
                cell.appendChild(button);
@@ -87,21 +86,15 @@ function adminGroupFillTableInfo(groupList) {
                cell = row.insertCell(-1);
                var button = document.createElement('input');
                button.setAttribute('type','button');
-               button.setAttribute('onClick','adminGroupRemoveGroup('+index+')');
+               button.setAttribute('onClick','adminGroupRemoveGroup('+groupId+')');
                button.setAttribute('class','adminGroup-contents-button');
                cell.appendChild(button);
-
-               index = index + 1;
        });
 
        $(".adminGroup-projectList").collapsible();
        $(".adminGroup-contents-button").button();
 }
 
-function adminGroupModifySetup(index) {
-       localStorage.groupTableIndex = index;
-}
-
 function adminGroupGenerateProjectListCell(projectList) {
        var div = document.createElement('div');
        div.setAttribute('data-role', 'collapsible');
@@ -128,8 +121,8 @@ function adminGroupGenerateProjectListCell(projectList) {
        return div;
 }
 
-function adminGroupRemoveGroup(index) {
-       var groupName = $("#adminGroup-contents-"+index+"-name").html();
+function adminGroupRemoveGroup(groupId) {
+       var groupName = $("#adminGroup-contents-"+groupId+"-name").html();
 
        var r=confirm("User ["+groupName+"] will be removed!!!");
        if (r==false)
@@ -139,7 +132,7 @@ function adminGroupRemoveGroup(index) {
 
        var changeInfoList = [];
        var changeInfoItem;
-       changeInfoItem = {"GroupName":groupName};
+       changeInfoItem = {"GroupId":groupId};
        changeInfoList.push(changeInfoItem);
 
        removeGroup(changeInfoList, function() {
index 8aa5ddb..19f11ce 100644 (file)
@@ -28,21 +28,29 @@ Contributors:
 
 function adminProjectAddGitInit() {
        $("#adminProjectAddGit-name").val("");
-       $("#adminProjectAddGit-password").val("");
        $("#adminProjectAddGit-address").val("");
        $("#adminProjectAddGit-branch").val("");
+       $("#adminProjectAddGit-status").empty();
+
+       var option; 
+       option = '<option value="OPEN" selected="selected">OPEN</option>';
+       $("#adminProjectAddGit-status").append(option);
+       option = '<option value="CLOSE">CLOSE</option>';
+       $("#adminProjectAddGit-status").append(option);
+       $("#adminProjectAddGit-status").selectmenu("refresh");
 
        queryAllOS( function (xml) {
-               var osList = $(xml).find("Data").find("OsName");
+               var osList = $(xml).find("Data").find("OS");
 
                $("#adminProjectAddGit-os").empty();
                $("#adminProjectAddGit-os").append("<legend>os list</legend>");
         
                osList.each(function(){
-                       var osName = $(this).text();
+                       var osId = $(this).find("Id").text();
+                       var osName = $(this).find("Name").text();
         
-                       var input = '<input type=checkbox id=adminProjectAddGit-os-checkbox-'+osName+' name=adminProjectAddGit-os-checkbox value='+osName+' checked=checked />'
-                       var label = '<label for=adminProjectAddGit-os-checkbox-'+osName+'> '+osName+'<label>';
+                       var input = '<input type=checkbox id=adminProjectAddGit-os-checkbox-'+osId+' name=adminProjectAddGit-os-checkbox value='+osId+' checked=checked />'
+                       var label = '<label for=adminProjectAddGit-os-checkbox-'+osId+'> '+osName+'<label>';
                        $("#adminProjectAddGit-os").append(input);
                        $("#adminProjectAddGit-os").append(label);
                });
@@ -53,20 +61,28 @@ function adminProjectAddGitInit() {
 
 function adminProjectAddBinaryInit() {
        $("#adminProjectAddBinary-name").val("");
-       $("#adminProjectAddBinary-password").val("");
        $("#adminProjectAddBinary-packagename").val("");
+       $("#adminProjectAddBinary-status").empty();
+
+       var option; 
+       option = '<option value="OPEN" selected="selected">OPEN</option>';
+       $("#adminProjectAddBinary-status").append(option);
+       option = '<option value="CLOSE">CLOSE</option>';
+       $("#adminProjectAddBinary-status").append(option);
+       $("#adminProjectAddBinary-status").selectmenu("refresh");
 
        queryAllOS( function (xml) {
-               var osList = $(xml).find("Data").find("OsName");
+               var osList = $(xml).find("Data").find("OS");
 
                $("#adminProjectAddBinary-os").empty();
                $("#adminProjectAddBinary-os").append("<legend>os list</legend>");
         
                osList.each(function(){
-                       var osName = $(this).text();
+                       var osId = $(this).find("Id").text();
+                       var osName = $(this).find("Name").text();
         
-                       var input = '<input type=checkbox id=adminProjectAddBinary-os-checkbox-'+osName+' name=adminProjectAddBinary-os-checkbox value='+osName+' checked=checked />'
-                       var label = '<label for=adminProjectAddBinary-os-checkbox-'+osName+'> '+osName+'<label>';
+                       var input = '<input type=checkbox id=adminProjectAddBinary-os-checkbox-'+osId+' name=adminProjectAddBinary-os-checkbox value='+osId+' checked=checked />'
+                       var label = '<label for=adminProjectAddBinary-os-checkbox-'+osId+'> '+osName+'<label>';
                        $("#adminProjectAddBinary-os").append(input);
                        $("#adminProjectAddBinary-os").append(label);
                });
@@ -78,12 +94,11 @@ function adminProjectAddBinaryInit() {
 function adminProjectAddGitProject() {
        var changeInfoList = [];
        var changeInfoItem;
-       var distName = $("#adminProject-distribution-select option:selected").val();
-       var type = "GIT";
+       var distId = $("#adminProject-distribution-select option:selected").val();
        var name = $("#adminProjectAddGit-name").val();
-       var password = $("#adminProjectAddGit-password").val();
        var address = $("#adminProjectAddGit-address").val();
        var branch = $("#adminProjectAddGit-branch").val();
+       var projectStatus = $("#adminProjectAddGit-status option:selected").val();
        var selectOsList = [];
 
        var selectArray = $("input[name='adminProjectAddGit-os-checkbox']");
@@ -93,12 +108,12 @@ function adminProjectAddGitProject() {
                }
        }
 
-       if(name == "" || password == "" || address == "" || branch == ""){
-               alert("You must input full data(Project name, Git password, Git address, Branch)");
+       if(name == "" || address == "" || branch == ""){
+               alert("You must input full data(Project name, Git address, Branch)");
                return;
        }
 
-       changeInfoItem = {"Distribution":distName, "Name":name, "ProjectType":type, "ProjectPass":password, "Address":address, "Branch":branch, "OSNameList":selectOsList.toString()};
+       changeInfoItem = {"DistId":distId, "Name":name, "Address":address, "Branch":branch, "ProjectStatus":projectStatus, "ProjectType":"GIT", "OSIdList":selectOsList.toString()};
        changeInfoList.push(changeInfoItem);
        
        addProject(changeInfoList, function () {
@@ -109,11 +124,10 @@ function adminProjectAddGitProject() {
 function adminProjectAddBinaryProject() {
        var changeInfoList = [];
        var changeInfoItem;
-       var distName = $("#adminProject-distribution-select option:selected").val();
-       var type = "BINARY";
+       var distId = $("#adminProject-distribution-select option:selected").val();
        var name = $("#adminProjectAddBinary-name").val();
-       var password = $("#adminProjectAddBinary-password").val();
        var pkgName = $("#adminProjectAddBinary-packagename").val();
+       var projectStatus = $("#adminProjectAddBinary-status option:selected").val();
        var selectOsList = [];
 
        var selectArray = $("input[name='adminProjectAddBinary-os-checkbox']");
@@ -128,7 +142,7 @@ function adminProjectAddBinaryProject() {
                return;
        }
 
-       changeInfoItem = {"Distribution":distName, "Name":name, "ProjectType":type, "ProjectPass":password, "PackageName":pkgName, "OSNameList":selectOsList.toString()};
+       changeInfoItem = {"DistId":distId, "Name":name, "PackageName":pkgName, "ProjectStatus":projectStatus, "ProjectType":"BINARY", "OSIdList":selectOsList.toString()};
        changeInfoList.push(changeInfoItem);
        
        addProject(changeInfoList, function () {
index 16930e2..49acac4 100644 (file)
@@ -26,115 +26,151 @@ Contributors:
 - S-Core Co., Ltd
 */
 
-function adminProjectModifyBinaryProjectInit() {
-       var projectName = localStorage.projectName;
-       var packageName = $("#adminProject-binary-packageName-"+projectName).html();
-
-       $("#adminProjectModifyBinary-oldName").val(projectName);
-       $("#adminProjectModifyBinary-newName").val(projectName);
-       $("#adminProjectModifyBinary-password").val("");
+function adminProjectModifyBinaryProjectInit(projectId) {
+       var projectName = $("#adminProject-binary-"+projectId+"-name").html();
+       var projectStatus = $("#adminProject-binary-"+projectId+"-status").html();
+       var packageName = $("#adminProject-binary-"+projectId+"-packageName").html();
+
+       $("#adminProjectModifyBinary-save").attr("onClick", "");
+       $("#adminProjectModifyBinary-id").val(projectId);
+       $("#adminProjectModifyBinary-name").val(projectName);
        $("#adminProjectModifyBinary-packageName").val(packageName);
+       $("#adminProjectModifyBinary-status").empty();
        $("#adminProjectModifyBinary-os").empty();
        $("#adminProjectModifyBinary-os").append("<legend> os list </legend>");
+       $("#adminProjectModifyBinary-status").empty();
+
+       var option; 
+       if(projectStatus.toUpperCase() == "OPEN") {
+               option = '<option value="OPEN" selected="selected">OPEN</option>';
+       } else {
+               option = '<option value="OPEN">OPEN</option>';
+       }
+       $("#adminProjectModifyBinary-status").append(option);
+       
+       if(projectStatus.toUpperCase() == "CLOSE") {
+               option = '<option value="CLOSE" selected="selected">CLOSE</option>';
+       } else {
+               option = '<option value="CLOSE">CLOSE</option>';
+       }
+       $("#adminProjectModifyBinary-status").append(option);
+       $("#adminProjectModifyBinary-status").selectmenu();
+       $("#adminProjectModifyBinary-status").selectmenu("refresh");
 
        queryAllOS( function (xml) {
-               var osList = $(xml).find("Data").find("OsName");
+               var osList = $(xml).find("Data").find("OS");
                var selectedOsList = [];
-               var projectName = localStorage.projectName;
        
-               var osListElement = document.getElementById("adminProject-binary-"+projectName+"-osList");
+               var osListElement = document.getElementById("adminProject-binary-"+projectId+"-osList");
                for(var i = 0; i < osListElement.childNodes.length; i++)
                {
                        selectedOsList.push(osListElement.childNodes[i].innerHTML);
                }
 
                osList.each(function(){
-                       var osName = $(this).text();
+                       var osId = $(this).find("Id").text();
+                       var osName = $(this).find("Name").text();
                        var input;
                        if(contains(selectedOsList, osName))
                        {
-                               input = '<input type=checkbox id=adminProjectModifyBinary-os-checkbox-'+osName+' name=adminProjectModifyBinary-os-checkbox value='+osName+' checked=checked />';
+                               input = '<input type=checkbox id=adminProjectModifyBinary-os-checkbox-'+osId+' name=adminProjectModifyBinary-os-checkbox value='+osId+' checked=checked />';
                        } else {
-                               input = '<input type=checkbox id=adminProjectModifyBinary-os-checkbox-'+osName+' name=adminProjectModifyBinary-os-checkbox value='+osName+' />';
+                               input = '<input type=checkbox id=adminProjectModifyBinary-os-checkbox-'+osId+' name=adminProjectModifyBinary-os-checkbox value='+osId+' />';
             
                        }
-                       var label = '<label for=adminProjectModifyBinary-os-checkbox-'+osName+'> '+osName+' <label>';
+                       var label = '<label for=adminProjectModifyBinary-os-checkbox-'+osId+'> '+osName+' <label>';
                        
                        $("#adminProjectModifyBinary-os").append(input);
                        $("#adminProjectModifyBinary-os").append(label);
                });
         
                $("input[name='adminProjectModifyBinary-os-checkbox']").checkboxradio();
+               $("#adminProjectModifyBinary-save").attr("onClick", "adminProjectModfyBinaryProject()");
        });
 }
 
-function adminProjectModifyGitProjectInit() {
-       var projectName = localStorage.projectName;
-       var projectAddress = $("#adminProject-git-"+projectName+"-address").html();
-       var projectBranch = $("#adminProject-git-"+projectName+"-branch").html();
+function adminProjectModifyGitProjectInit(projectId) {
+       var projectName = $("#adminProject-git-"+projectId+"-name").html();
+       var projectAddress = $("#adminProject-git-"+projectId+"-address").html();
+       var projectBranch = $("#adminProject-git-"+projectId+"-branch").html();
+       var projectStatus = $("#adminProject-git-"+projectId+"-status").html();
 
-       $("#adminProjectModifyGit-oldName").val(projectName);
-       $("#adminProjectModifyGit-newName").val(projectName);
-       $("#adminProjectModifyGit-password").val("");
+       $("#adminProjectModifyGit-save").attr("onClick", "");
+       $("#adminProjectModifyGit-id").val(projectId);
+       $("#adminProjectModifyGit-name").val(projectName);
        $("#adminProjectModifyGit-address").val(projectAddress);
        $("#adminProjectModifyGit-branch").val(projectBranch);
+       $("#adminProjectModifyGit-status").empty();
        $("#adminProjectModifyGit-os").empty();
        $("#adminProjectModifyGit-os").append("<legend> os list </legend>");
+       var option; 
+       if(projectStatus.toUpperCase() == "OPEN") {
+               option = '<option value="OPEN" selected="selected">OPEN</option>';
+       } else {
+               option = '<option value="OPEN">OPEN</option>';
+       }
+       $("#adminProjectModifyGit-status").append(option);
+       
+       if(projectStatus.toUpperCase() == "CLOSE") {
+               option = '<option value="CLOSE" selected="selected">CLOSE</option>';
+       } else {
+               option = '<option value="CLOSE">CLOSE</option>';
+       }
+       $("#adminProjectModifyGit-status").append(option);
+       $("#adminProjectModifyGit-status").selectmenu();
+       $("#adminProjectModifyGit-status").selectmenu("refresh");
 
        queryAllOS( function (xml) {
-               var osList = $(xml).find("Data").find("OsName");
+               var osList = $(xml).find("Data").find("OS");
                var selectedOsList = [];
-               var projectName = localStorage.projectName;
        
-               var osListElement = document.getElementById("adminProject-git-"+projectName+"-osList");
+               var osListElement = document.getElementById("adminProject-git-"+projectId+"-osList");
                for(var i = 0; i < osListElement.childNodes.length; i++)
                {
                        selectedOsList.push(osListElement.childNodes[i].innerHTML);
                }
 
                osList.each(function(){
-                       var osName = $(this).text();
+                       var osId = $(this).find("Id").text();
+                       var osName = $(this).find("Name").text();
                        var input;
                        if(contains(selectedOsList, osName))
                        {
-                               input = '<input type=checkbox id=adminProjectModifyGit-os-checkbox-'+osName+' name=adminProjectModifyGit-os-checkbox value='+osName+' checked=checked />';
+                               input = '<input type=checkbox id=adminProjectModifyGit-os-checkbox-'+osId+' name=adminProjectModifyGit-os-checkbox value='+osId+' checked=checked />';
                        } else {
-                               input = '<input type=checkbox id=adminProjectModifyGit-os-checkbox-'+osName+' name=adminProjectModifyGit-os-checkbox value='+osName+' />';
+                               input = '<input type=checkbox id=adminProjectModifyGit-os-checkbox-'+osId+' name=adminProjectModifyGit-os-checkbox value='+osId+' />';
             
                        }
-                       var label = '<label for=adminProjectModifyGit-os-checkbox-'+osName+'> '+osName+' <label>';
+                       var label = '<label for=adminProjectModifyGit-os-checkbox-'+osId+'> '+osName+' <label>';
                        
                        $("#adminProjectModifyGit-os").append(input);
                        $("#adminProjectModifyGit-os").append(label);
                });
         
                $("input[name='adminProjectModifyGit-os-checkbox']").checkboxradio();
+               $("#adminProjectModifyGit-save").attr("onClick", "adminProjectModfyGitProject()");
        });
 }
 
 function adminProjectModfyBinaryProject() {
-       var distName = $("#adminProject-distribution-select option:selected").val();
        var changeInfoList = [];
        var changeInfoItem;
-       var oldProjectName = $("#adminProjectModifyBinary-oldName").val();
-       var newProjectName = $("#adminProjectModifyBinary-newName").val();
-       var projectPassword = $("#adminProjectModifyBinary-password").val();
+       var projectId = $("#adminProjectModifyBinary-id").val();
+       var projectName = $("#adminProjectModifyBinary-name").val();
+       var projectStatus = $("#adminProjectModifyBinary-status option:selected").val();
        var packageName = $("#adminProjectModifyBinary-packageName").val();
        var selectOsList = [];
 
-       var selectArray = $("input[name='adminProjectModifyBinary-os-checkbox']");
-       for(var i = 0; i < selectArray.length; i++) {
-               if (selectArray[i].checked == true) {
-                       selectOsList.push(selectArray[i].value);
-               }
-       }
+       $("input[name='adminProjectModifyBinary-os-checkbox']:checked").each(function() {
+               selectOsList.push($(this).val());
+       });
 
-       if(oldProjectName == "" || newProjectName == "" || projectPassword == "" || packageName == ""){
+       if(projectId == "" || projectName == "" || packageName == ""){
                alert("You must input full data");
                return;
        }
                
-       changeInfoItem = {"Distribution":distName, "Name":oldProjectName, "NewProjectName":newProjectName, "ProjectType":"BINARY", "ProjectPass":projectPassword, "PackageName":packageName, "OSNameList":selectOsList.toString()};
+       changeInfoItem = {"Id":projectId, "Name":projectName, "ProjectStatus":projectStatus, "PackageName":packageName, "OSIdList":selectOsList.toString()};
        changeInfoList.push(changeInfoItem);
 
        modifyProject(changeInfoList, function () {
@@ -146,26 +182,23 @@ function adminProjectModfyGitProject() {
        var distName = $("#adminProject-distribution-select option:selected").val();
        var changeInfoList = [];
        var changeInfoItem;
-       var oldProjectName = $("#adminProjectModifyGit-oldName").val();
-       var newProjectName = $("#adminProjectModifyGit-newName").val();
-       var projectPassword = $("#adminProjectModifyGit-password").val();
+       var projectId = $("#adminProjectModifyGit-id").val();
+       var projectName = $("#adminProjectModifyGit-name").val();
        var projectAddress = $("#adminProjectModifyGit-address").val();
        var projectBranch = $("#adminProjectModifyGit-branch").val();
+       var projectStatus = $("#adminProjectModifyGit-status option:selected").val();
        var selectOsList = [];
 
-       var selectArray = $("input[name='adminProjectModifyGit-os-checkbox']");
-       for(var i = 0; i < selectArray.length; i++) {
-               if (selectArray[i].checked == true) {
-                       selectOsList.push(selectArray[i].value);
-               }
-       }
+       $("input[name='adminProjectModifyGit-os-checkbox']:checked").each(function() {
+               selectOsList.push($(this).val());
+       });
 
-       if(oldProjectName == "" || newProjectName == "" || projectPassword == "" || projectAddress == "" || projectBranch == ""){
+       if(projectId == "" || projectName == "" || projectAddress == "" || projectBranch == ""){
                alert("You must input full data");
                return;
        }
                
-       changeInfoItem = {"Distribution":distName, "Name":oldProjectName, "NewProjectName":newProjectName, "ProjectType":"GIT", "ProjectPass":projectPassword, "ProjectAddress":projectAddress, "ProjectBranch":projectBranch, "OSNameList":selectOsList.toString()};
+       changeInfoItem = {"Id":projectId, "Name":projectName, "ProjectAddress":projectAddress, "ProjectBranch":projectBranch, "ProjectStatus":projectStatus, "OSIdList":selectOsList.toString()};
        changeInfoList.push(changeInfoItem);
 
        modifyProject(changeInfoList, function () {
index f28ef05..7333d47 100644 (file)
@@ -29,10 +29,11 @@ Contributors:
 function adminProjectInit() {
        if( $("#adminProject-distribution-select").children().length == 0 ) {
                queryDistribution( function(xml) {
-                       $(xml).find("Data").find("DistributionName").each(function(){
-                               var name = $(this).text();
+                       $(xml).find("Data").find("Distribution").each(function(){
+                               var distId = $(this).find("Id").text();
+                               var distName = $(this).find("Name").text();
                
-                               $("#adminProject-distribution-select").append("<option value=\'"+name+"\'>"+name+"</option>");
+                               $("#adminProject-distribution-select").append("<option value=\'"+distId+"\'>"+distName+"</option>");
                        });
                
                        /* default distribution selection */
@@ -49,9 +50,9 @@ function adminProjectInit() {
 }
 
 function adminProjectSetProjectInfo() {
-       var distName = $("#adminProject-distribution-select option:selected").val();
+       var distId = $("#adminProject-distribution-select option:selected").val();
 
-       queryProjectsInDistributionForAdmin( distName, function (xml) {
+       queryProjectsInDistributionForAdmin( distId, function (xml) {
                var projectList = $(xml).find("Data").find("Project");
        
                // update project info
@@ -59,12 +60,8 @@ function adminProjectSetProjectInfo() {
        });
 }
 
-function popupModifyProject(projectName) {
-       localStorage.projectName = projectName;
-}
-
-function adminProjectRemoveProject(projectType, projectName ) {
-       var distName = $("#adminProject-distribution-select option:selected").val();
+function adminProjectRemoveProject(projectType, projectId) {
+       var projectName = $("#adminProject-"+projectType+"-"+projectId+"-name").html();
 
        var r=confirm("Project ["+projectName+"] is removed!!!");
        if (r==false)
@@ -74,7 +71,7 @@ function adminProjectRemoveProject(projectType, projectName ) {
 
        var changeInfoList = [];
        var changeInfoItem;
-       changeInfoItem = {"Distribution":distName, "ProjectType":projectType, "Name":projectName};
+       changeInfoItem = {"ProjectId":projectId};
        changeInfoList.push(changeInfoItem);
        
        removeProject(changeInfoList, function () {
@@ -94,19 +91,22 @@ function adminProjectUpdateTable(projectList) {
        $("#adminProject-binary").empty();
 
        // Project table header
-       var tableHeader = "<tr><th>Project</th><th>Git repos</th><th>Branch</th><th>OS list</th><th>Modify</th><th>Delete</th>";
+       var tableHeader = "<tr><th>Project</th><th>Git repos</th><th>Branch</th><th>OS list</th><th>Status</th><th>Modify</th><th>Delete</th>";
        $("#adminProject-git").append(tableHeader);
 
        // Binary project table header
-       var tableHeader = "<tr><th>Project</th><th>Package name</th><th>OS list</th><th>Modify</th><th>Delete</th>";
+       var tableHeader = "<tr><th>Project</th><th>Package name</th><th>OS list</th><th>Status</th><th>Modify</th><th>Delete</th>";
+
        $("#adminProject-binary").append(tableHeader);
 
-       var projectIdx = 1;
        var binaryProjectIdx = 1;
        // add project information
        projectList.each(function(){
-               var name = $(this).find("ProjectName").text();
+               var id = $(this).find("Id").text();
+               var name = $(this).find("Name").text();
                var type = $(this).find("Type").text();
+               var projectStatus = $(this).find("ProjectStatus").text();
+               var projectPassword = $(this).find("ProjectPassword").text();
                var osList = $(this).find("OS");
 
                if(type.toUpperCase() == "GIT")
@@ -116,29 +116,34 @@ function adminProjectUpdateTable(projectList) {
 
                        cell = row.insertCell(-1);
                        cell.setAttribute('style', 'text-align: left');
+                       cell.setAttribute('id',"adminProject-git-"+id+"-name");
                        cell.innerHTML = name;
 
                        cell = row.insertCell(-1);
                        cell.setAttribute('style', 'text-align: left');
-                       cell.setAttribute('id',"adminProject-git-"+name+"-address");
+                       cell.setAttribute('id',"adminProject-git-"+id+"-address");
                        cell.innerHTML = $(this).find("GitRepos").text();
 
                        cell = row.insertCell(-1);
                        cell.setAttribute('style', 'text-align: left');
-                       cell.setAttribute('id',"adminProject-git-"+name+"-branch");
+                       cell.setAttribute('id',"adminProject-git-"+id+"-branch");
                        cell.innerHTML = $(this).find("GitBranch").text();
 
                        cell = row.insertCell(-1);
-                       div = adminProjectApendOsCell(osList, name, "GIT");
+                       div = adminProjectApendOsCell(osList, id, "git");
                        cell.appendChild(div);
 
                        cell = row.insertCell(-1);
+                       cell.setAttribute('id',"adminProject-git-"+id+"-status");
+                       cell.innerHTML = projectStatus;
+
+                       cell = row.insertCell(-1);
                        var button = document.createElement('a');
                        button.setAttribute('href','#adminProjectModifyGit');
                        button.setAttribute('data-role','button');
                        button.setAttribute('data-rel','dialog');
                        button.setAttribute('data-mini','true');
-                       button.setAttribute('onClick','popupModifyProject(\"'+name+'\")');
+                       button.setAttribute('onClick','adminProjectModifyGitProjectInit(\"'+id+'\")');
                        button.setAttribute('class','binaryProjectTableButton');
                        button.innerHTML = " "
                        cell.appendChild(button);
@@ -146,14 +151,11 @@ function adminProjectUpdateTable(projectList) {
                        cell = row.insertCell(-1);
                        var button = document.createElement('input');
                        button.setAttribute('type','button');
-                       button.setAttribute('id','button:git:'+projectIdx+':'+name);
                        button.setAttribute('data-mini','true');
                        button.setAttribute('name',name);
                        button.setAttribute('class','binaryProjectTableButton');
-                       button.setAttribute('onClick','adminProjectRemoveProject(\"GIT\"'+',\"'+name+'\"'+')');
+                       button.setAttribute('onClick','adminProjectRemoveProject(\"git\"'+',\"'+id+'\"'+')');
                        cell.appendChild(button);
-
-                       projectIdx = projectIdx + 1;
                }
                else if (type.toUpperCase() == "BINARY")
                {
@@ -162,25 +164,30 @@ function adminProjectUpdateTable(projectList) {
 
                        cell = row.insertCell(-1);
                        cell.setAttribute('style', 'text-align: left');
+                       cell.setAttribute('id',"adminProject-binary-"+id+"-name");
                        cell.innerHTML = name;
 
                        cell = row.insertCell(-1);
                        cell.setAttribute('style', 'text-align: left');
-                       cell.setAttribute('id',"adminProject-binary-packageName-"+name);
+                       cell.setAttribute('id',"adminProject-binary-"+id+"-packageName");
                        cell.innerHTML = $(this).find("PackageName").text();
 
                        cell = row.insertCell(-1);
-                       div = adminProjectApendOsCell(osList, name, "BINARY");
+                       div = adminProjectApendOsCell(osList, id, "binary");
                        cell.appendChild(div);
 
                        cell = row.insertCell(-1);
+                       cell.setAttribute('id',"adminProject-binary-"+id+"-status");
+                       cell.innerHTML = projectStatus;
+
+                       cell = row.insertCell(-1);
                        var button = document.createElement('a');
                        button.setAttribute('href','#adminProjectModifyBinary');
                        button.setAttribute('data-role','button');
                        button.setAttribute('data-inline','true');
                        button.setAttribute('data-mini','true');
                        button.setAttribute('data-rel','dialog');
-                       button.setAttribute('onClick','popupModifyProject(\"'+name+'\")');
+                       button.setAttribute('onClick','adminProjectModifyBinaryProjectInit(\"'+id+'\")');
                        button.setAttribute('class','binaryProjectTableButton');
                        cell.appendChild(button);
 
@@ -190,7 +197,7 @@ function adminProjectUpdateTable(projectList) {
                        button.setAttribute('class','binaryProjectTableButton');
                        button.setAttribute('data-mini','true');
                        button.setAttribute('name',name);
-                       button.setAttribute('onClick','adminProjectRemoveProject(\"BINARY\"'+',\"'+name+'\"'+')');
+                       button.setAttribute('onClick','adminProjectRemoveProject(\"binary\"'+',\"'+id+'\"'+')');
                        cell.appendChild(button);
 
                        binaryProjectIdx = binaryProjectIdx + 1;
@@ -204,7 +211,7 @@ function adminProjectUpdateTable(projectList) {
        $(".adminProject-OsList").collapsible();
 }
 
-function adminProjectApendOsCell(osList, projectName, projectType) {
+function adminProjectApendOsCell(osList, projectId, projectType) {
 
        var div = document.createElement('div');
 
@@ -218,7 +225,7 @@ function adminProjectApendOsCell(osList, projectName, projectType) {
        div.appendChild(header);
 
        var ul = document.createElement('ul');
-       ul.setAttribute('id', 'adminProject-'+projectType.toLowerCase()+'-'+projectName+'-osList');
+       ul.setAttribute('id', 'adminProject-'+projectType+'-'+projectId+'-osList');
 
        // if osList does not exist then just return 
        if (osList != undefined) {
@@ -233,4 +240,21 @@ function adminProjectApendOsCell(osList, projectName, projectType) {
        return div;
 }
 
+function adminProjectAllProjectStatusChange(projectStatus) {
+       var distId = $("#adminProject-distribution-select option:selected").val();
+       var changeInfoList = [];
+       var changeInfoItem;
+
+       var r=confirm("All project status is changed to "+projectStatus+"!!!");
+       if (r==false)
+       {
+               return;
+       }
+
+       changeInfoItem = {"DistId":distId, "ProjectStatus":projectStatus}
+       changeInfoList.push(changeInfoItem);
 
+       changeAllProjectStatus(changeInfoList, function () {
+               $.mobile.changePage("#adminProject"); 
+       });
+}
index 3d46b09..928cd2f 100644 (file)
@@ -27,14 +27,12 @@ Contributors:
 */
 
 function adminServerAddSupportedOsInit() {
-       // Remove select option
-       $("#adminServer-AddSupportedOs-OsCategory").empty();
-
        queryAllOSCategory(function(xml){
-               $(xml).find("Data").find("OsCategoryName").each(function(){
-                       var name = $(this).text();
+               $(xml).find("Data").find("OsCategory").each(function(){
+                       var categoryId = $(this).find("Id").text();
+                       var categoryName = $(this).find("Name").text();
 
-                       $('#adminServer-AddSupportedOs-OsCategory').append("<option value=\'"+name+"\'>"+name+"</option>");
+                       $('#adminServer-AddSupportedOs-OsCategory').append("<option value=\'"+categoryId+"\'>"+categoryName+"</option>");
        
                        $('#adminServer-AddSupportedOs-OsCategory').selectmenu('refresh');
                });
@@ -68,19 +66,21 @@ function adminServerAddSupportedOs() {
        var changeInfoList = [];
        var changeInfoItem;
 
-       var osName = $("#adminServer-AddSupportedOs-OsName").val();
-       var osCategory = $("#adminServer-AddSupportedOs-OsCategory option:selected").val();
+       var osName = $("#adminServer-AddSupportedOs-name").val();
+       var osCategoryId = $("#adminServer-AddSupportedOs-OsCategory option:selected").val();
 
-       if(osName == ""){
-               alert("You must input server address");
+       if(osName == "" || osCategoryId == ""){
+               alert("You must input os name");
                return;
        }
 
-       changeInfoItem = {"Name":osName, "OsCategory":osCategory};
+       changeInfoItem = {"Name":osName, "OsCategoryId":osCategoryId};
        changeInfoList.push(changeInfoItem);
        
        addSupportedOS(changeInfoList, function () {
-               $("#adminServer-AddSupportedOs-OsName").val("");
+               // Remove select option
+               $("#adminServer-AddSupportedOs-name").val("");
+               $("#adminServer-AddSupportedOs-OsCategory").empty();
 
                $.mobile.changePage("#adminServer"); 
        });
@@ -90,7 +90,7 @@ function adminServerAddOSCategory() {
        var changeInfoList = [];
        var changeInfoItem;
 
-       var categoryName = $("#adminServer-AddOsCategory-Name").val();
+       var categoryName = $("#adminServer-AddOsCategory-name").val();
 
        if(categoryName == ""){
                alert("You must input category name");
@@ -101,7 +101,7 @@ function adminServerAddOSCategory() {
        changeInfoList.push(changeInfoItem);
        
        addOSCategory(changeInfoList, function () {
-               $("#adminServer-AddOsCategory-Name").val("");
+               $("#adminServer-AddOsCategory-name").val("");
 
                $.mobile.changePage("#adminServer"); 
        }); 
index 26dae6d..accf973 100644 (file)
@@ -26,40 +26,62 @@ Contributors:
 - S-Core Co., Ltd
 */
 
-function adminServerModifyRemoteBuildServerInit() {
-       var serverAddress = localStorage.remoteBuildServerAddress;
-       var serverDescription = localStorage.remoteBuildServerDescription;
+function adminServerModifyServerInfoInit(configId) {
+       $("#adminServer-modifyServerInfo-id").val(configId);
+       $("#adminProjectModifyBinary-save").attr("onClick", "");
 
-       $("#adminServer-modifyRemoteBuildServer-OldAddress").val(serverAddress);
-       $("#adminServer-modifyRemoteBuildServer-newAddress").val(serverAddress);
-       $("#adminServer-modifyRemoteBuildServer-description").val(serverDescription);
+       queryServerConfig(configId, function(xml) {
+               var property = $(xml).find("Data").find("Property").text();
+               var value = $(xml).find("Data").find("Value").text();
+
+               $("#adminServer-modifyServerInfo-property").val(property);
+               $("#adminServer-modifyServerInfo-value").val(value);
+               $("#adminProjectModifyBinary-save").attr("onClick", "adminServerModifyServerInfo()");
+       });
 }
 
-function adminServerModifyServerInfoInit(property, value) {
-       $("#adminServer-modifyServerInfo-property").val(property);
-       $("#adminServer-modifyServerInfo-value").val(value);
+function adminServerModifyRemoteBuildServerInit(serverId) {
+       $("#adminServer-modifyRemoteBuildServer-id").val(serverId);
+       $("#adminServer-modifyRemoteBuildServer-save").attr("onClick", "");
+
+       queryRemoteBuildServer(serverId, function(xml) {
+               var address = $(xml).find("Data").find("Address").text();
+               var description = $(xml).find("Data").find("Description").text();
+
+               $("#adminServer-modifyRemoteBuildServer-address").val(address);
+               $("#adminServer-modifyRemoteBuildServer-description").val(description);
+               $("#adminServer-modifyRemoteBuildServer-save").attr("onClick", "adminServerModifyRemoteBuildServer()");
+       });
+
 }
 
-function adminServerModifySupportedOSInit(osName, osCategory) {
-       // Remove select option
-       $('#adminServer-ModifySupportedOs-OsCategory').empty();
-
-       $("#adminServer-ModifySupportedOs-OldOsName").val(osName);
-       $("#adminServer-MoidfySupportedOs-OsName").val(osName);
-
-       queryAllOSCategory( function(xml){
-               $(xml).find("Data").find("OsCategoryName").each(function(){
-                       var name = $(this).text();
-                       var option = ""
-                       
-                       if(name == osCategory) {
-                               option = '<option value="'+name+'" selected="selected">'+name+'</option>'
-                       } else {
-                               option = '<option value="'+name+'">'+name+'</option>'
-                       }
-
-                       $('#adminServer-ModifySupportedOs-OsCategory').append(option);
-                       $('#adminServer-ModifySupportedOs-OsCategory').selectmenu("refresh");
+function adminServerModifySupportedOSInit(osId) {
+       $("#adminServer-ModifySupportedOs-OsCategory").empty();
+       $("#adminServer-ModifySupportedOs-id").val(osId);
+       $("#adminServer-ModifySupportedOs-save").attr("onClick", "");
+
+       querySupportedOS(osId, function(xml) {
+               var name = $(xml).find("Data").find("Name").text();
+               var category = $(xml).find("Data").find("CategoryId").text();
+    
+               $("#adminServer-MoidfySupportedOs-name").val(name);
+    
+               queryAllOSCategory( function(xml){
+                       $(xml).find("Data").find("OsCategory").each(function(){
+                               var categoryId = $(this).find("Id").text();
+                               var categoryName = $(this).find("Name").text();
+                               var option = ""
+                               
+                               if(categoryId == category) {
+                                       option = '<option value="'+categoryId+'" selected="selected">'+categoryName+'</option>'
+                               } else {
+                                       option = '<option value="'+categoryId+'">'+categoryName+'</option>'
+                               }
+    
+                               $('#adminServer-ModifySupportedOs-OsCategory').append(option);
+                               $('#adminServer-ModifySupportedOs-OsCategory').selectmenu("refresh");
+                               $("#adminServer-ModifySupportedOs-save").attr("onClick", "adminServerModifySupportedOS()");
+                       });
                });
        });
 }
@@ -67,16 +89,16 @@ function adminServerModifySupportedOSInit(osName, osCategory) {
 function adminServerModifyRemoteBuildServer() {
        var changeInfoList = [];
        var changeInfoItem;
-       var serverAddress = $("#adminServer-modifyRemoteBuildServer-OldAddress").val();
-       var newServerAddress = $("#adminServer-modifyRemoteBuildServer-newAddress").val();
+       var id = $("#adminServer-modifyRemoteBuildServer-id").val();
+       var address = $("#adminServer-modifyRemoteBuildServer-address").val();
        var description = $("#adminServer-modifyRemoteBuildServer-description").val();
 
-       if(serverAddress == ""){
-               alert("server address is invalid");
+       if(id == "" || address == ""){
+               alert("server infomation is invalid");
                return;
        }
 
-       changeInfoItem = {"Address":serverAddress, "NewAddress":newServerAddress, "Description":description};
+       changeInfoItem = {"Id":id, "Address":address, "Description":description};
        changeInfoList.push(changeInfoItem);
 
        modifyRemoteBuildServer(changeInfoList, function () {
@@ -87,11 +109,11 @@ function adminServerModifyRemoteBuildServer() {
 function adminServerModifySupportedOS() {
        var changeInfoList = [];
        var changeInfoItem;
-       var oldOsName = $("#adminServer-ModifySupportedOs-OldOsName").val();
-       var osName = $("#adminServer-MoidfySupportedOs-OsName").val();
+       var id = $("#adminServer-ModifySupportedOs-id").val();
+       var name = $("#adminServer-MoidfySupportedOs-name").val();
        var osCategory = $("#adminServer-ModifySupportedOs-OsCategory option:selected").val();
 
-       changeInfoItem = {"Name":oldOsName, "NewName":osName, "OsCategory":osCategory};
+       changeInfoItem = {"Id":id, "Name":name, "OsCategoryId":osCategory};
        changeInfoList.push(changeInfoItem);
 
        modifySupportedOS(changeInfoList, function () {
@@ -100,11 +122,17 @@ function adminServerModifySupportedOS() {
 }
 
 function adminServerModifyServerInfo() {
+       var id = $("#adminServer-modifyServerInfo-id").val();
        var property = $("#adminServer-modifyServerInfo-property").val();
        var value = $("#adminServer-modifyServerInfo-value").val();
        var changeInfoList = [];
        var changeInfoItem;
 
+       if(id == ""){
+               alert("info data is invalid");
+               return;
+       }
+
        if(property == ""){
                alert("property is empty");
                return;
@@ -115,7 +143,7 @@ function adminServerModifyServerInfo() {
                return;
        }
 
-       changeInfoItem = {"Property":property, "Value":value};
+       changeInfoItem = {"Id":id, "Property":property, "Value":value};
        changeInfoList.push(changeInfoItem);
        
        modifyServerInfo(changeInfoList, function () {
index 676ac99..a2b0ae1 100644 (file)
@@ -31,27 +31,29 @@ function adminServerRemoveOSCategoryInit() {
        $('#adminServer-RemoveOSCategory-CategorySelect').empty();
 
        queryAllOSCategory(function(xml){
-               $(xml).find("Data").find("OsCategoryName").each(function(){
-                       var name = $(this).text();
+               $(xml).find("Data").find("OsCategory").each(function(){
+                       var categoryId = $(this).find("Id").text();
+                       var categoryName = $(this).find("Name").text();
 
-                       $('#adminServer-RemoveOSCategory-CategorySelect').append("<option value=\'"+name+"\'>"+name+"</option>");
+                       $('#adminServer-RemoveOSCategory-CategorySelect').append("<option value=\'"+categoryId+"\'>"+categoryName+"</option>");
                        
-                       $('#adminServer-RemoveOSCategory-CategorySelect').selectmenu('refresh');
                });
        });
+       
+       $('#adminServer-RemoveOSCategory-CategorySelect').selectmenu('refresh');
 }
 
 function adminServerRemoveOSCategory() {
        var changeInfoList = [];
        var changeInfoItem;
-       var osCategory = $("#adminServer-RemoveOSCategory-CategorySelect option:selected").val();
+       var osCategoryId = $("#adminServer-RemoveOSCategory-CategorySelect option:selected").val();
 
-       if(osCategory == ""){
+       if(osCategoryId == ""){
                alert("Os category is invalid");
                return;
        }
 
-       changeInfoItem = {"Name":osCategory};
+       changeInfoItem = {"Id":osCategoryId};
        changeInfoList.push(changeInfoItem);
 
        removeOSCategory(changeInfoList, function () {
@@ -62,15 +64,9 @@ function adminServerRemoveOSCategory() {
 function adminServerRemoveSupportedOS() {
        var changeInfoList = [];
        var changeInfoItem;
-       var oldOsName = $('#adminServer-ModifySupportedOs-OldOsName').val();
-       var osName = $('#adminServer-MoidfySupportedOs-OsName').val();
-
-       if(oldOsName != osName ){
-               alert("Remove command must be same to original os name");
-               return;
-       }
+       var id = $('#adminServer-ModifySupportedOs-id').val();
 
-       changeInfoItem = {"Name":osName};
+       changeInfoItem = {"Id":id};
        changeInfoList.push(changeInfoItem);
 
        removeSupportedOS(changeInfoList, function () {
@@ -99,14 +95,14 @@ function adminServerRemoveServerInfo() {
 function adminServerRemoveRemoteBuildServer() {
        var changeInfoList = [];
        var changeInfoItem;
-       var serverAddress = $('#adminServer-modifyRemoteBuildServer-OldAddress').val();
+       var serverId = $('#adminServer-modifyRemoteBuildServer-id').val();
 
-       if(serverAddress == ""){
+       if(serverId == ""){
                alert("server address is invalid");
                return;
        }
 
-       changeInfoItem = {"Address":serverAddress};
+       changeInfoItem = {"Id":serverId};
        changeInfoList.push(changeInfoItem);
 
        removeRemoteBuildServer(changeInfoList, function () {
index 6aae3e9..f994b7c 100644 (file)
@@ -41,14 +41,16 @@ function adminServerInit() {
                $("#adminServer-SupportedOS").empty();
 
                $(xml).find("Data").find("OS").each(function(){
-                       var osName = $(this).find("OsName").text();
-                       var osCategory = $(this).find("OsCategory").text();
+                       var id = $(this).find("Id").text();
+                       var name = $(this).find("Name").text();
+                       var categoryId = $(this).find("CategoryId").text();
+                       var categoryName = $(this).find("CategoryName").text();
 
                        var li = '<li><a href="#adminServerModifySupportedOS" ';
-                       li += 'onClick="adminServerModifySupportedOSInit(\''+osName+'\',\''+osCategory+'\')" ';
+                       li += 'onClick="adminServerModifySupportedOSInit(\''+id+'\')" ';
                        li += 'data-rel="dialog">';
-                       li += '<h3>'+osName+'</h3>';
-                       li += '<p>OS category : '+osCategory+'</p>';
+                       li += '<h3>'+name+'</h3>';
+                       li += '<p>OS category : '+categoryName+'</p>';
                        li += '</a></li>';
 
                        $("#adminServer-SupportedOS").append(li);
@@ -62,11 +64,12 @@ function adminServerInitServerInfo(serverConfig){
        $("#adminServer-ServerInfo").empty();
 
        serverConfig.each(function(){
+               var id = $(this).find("Id").text();
                var property = $(this).find("Property").text();
                var value = $(this).find("Value").text();
 
                var li = '<li><a href="#adminServerModifyServerInfo" ';
-               li += 'onClick="adminServerModifyServerInfoInit(\''+property+'\',\''+value+'\')" ';
+               li += 'onClick="adminServerModifyServerInfoInit('+id+')" ';
                li += 'data-rel="dialog">';
                li += '<p>'+property+' : '+value+'</p>';
                li += '</a></li>';
@@ -80,11 +83,12 @@ function adminServerRemoteInitRemoteBuildServer(serverList){
        $("#adminServer-RemoteBuildServer").empty();
 
        serverList.each(function(){
+               var id = $(this).find("Id").text();
                var address = $(this).find("Address").text();
                var description = $(this).find("Description").text();
 
                var li = '<li><a href="#adminServerModifyRemoteBuildServer" ';
-               li += 'onClick="popupModifyRemoteBuildServerInfo(\''+address+'\',\''+description+'\')" ';
+               li += 'onClick="adminServerModifyRemoteBuildServerInit(\''+id+'\')" ';
                li += 'data-rel="dialog">';
                li += '<h3>'+address+'</h3>';
                li += '<p>Description : '+$(this).find("Description").text()+'</p>';
@@ -101,9 +105,3 @@ function adminServerRemoteInitRemoteBuildServer(serverList){
 
        $("#adminServer-RemoteBuildServer").listview('refresh');
 }
-
-function popupModifyRemoteBuildServerInfo(address, description) {
-       localStorage.remoteBuildServerAddress = address;
-       localStorage.remoteBuildServerDescription = description;
-}
-
index 4add083..5dc67f8 100644 (file)
@@ -26,19 +26,21 @@ Contributors:
 - S-Core Co., Ltd
 */
 
-function adminUserModifyInit() {
-       var userId = localStorage.userId;
-       var userName = $("#adminUser-contents-"+userId+"-name").html();
+function adminUserModifyInit(userId) {
+       var name = $("#adminUser-contents-"+userId+"-name").html();
        var email = $("#adminUser-contents-"+userId+"-email").html();
 
-       $("#adminUserModify-name").val(userName);
+       $("#adminUserModify-id").val(userId);
+       $("#adminUserModify-name").val(name);
        $("#adminUserModify-email").val(email);
+       $("#adminUserModify-save").attr("onClick", "");
 
        queryUserInfoForAdmin(userId, function(xml) {
                var fullGroupList = $(xml).find("Data").find("GroupInfo").find("Group");
                var userGroupIdList = $(xml).find("Data").find("GroupInfo").find("GroupIdList").text().split(",");
                
                adminUserModifyGenerateGroupSelect(fullGroupList, userGroupIdList); 
+               $("#adminUserModify-save").attr("onClick", "adminUserModify()");
        });
 }
 
@@ -69,18 +71,16 @@ function adminUserModifyGenerateGroupSelect(fullGroupList, userGroupIdList) {
 function adminUserModify() {
        var changeInfoList = [];
        var changeInfoItem;
-       var userName = $("#adminUserModify-name").val();
+       var id = $("#adminUserModify-id").val();
+       var name = $("#adminUserModify-name").val();
        var email = $("#adminUserModify-email").val();
        var selectGroupList = [];
 
-       var selectArray = $("input[name='adminUserModify-group-checkbox']");
-       for(var i = 0; i < selectArray.length; i++) {
-               if (selectArray[i].checked == true) {
-                       selectGroupList.push(selectArray[i].value);
-               }
-       }
+       $("input[name='adminUserModify-group-checkbox']:checked").each(function() {
+               selectGroupList.push($(this).val());
+       });
                
-       changeInfoItem = {"Type":"ModifyUser", "Email":email, "UserName":userName, "GroupIdList":selectGroupList.toString()};
+       changeInfoItem = {"Type":"ModifyUser", "Id":id, "Email":email, "Name":name, "GroupIdList":selectGroupList.toString()};
        changeInfoList.push(changeInfoItem);
 
        changeUser(changeInfoList, function () {
index c41f888..ed95262 100644 (file)
@@ -46,10 +46,10 @@ function adminUserFillTable(userList) {
        userList.each(function(){
                var row = userTable.insertRow(-1);
                var cell;
+               var userId = $(this).find("Id").text();
                var userName = $(this).find("Name").text();
                var groupList = $(this).find("GroupName");
                var email = $(this).find("Email").text();
-               var userId = $(this).find("Id").text();
 
                cell = row.insertCell(-1);
                cell.setAttribute('id',"adminUser-contents-"+userId+"-name");
@@ -68,8 +68,9 @@ function adminUserFillTable(userList) {
                button.setAttribute('href','#adminUserModify');
                button.setAttribute('data-role','button');
                button.setAttribute('data-rel','dialog');
+               button.setAttribute('data-mini','ture');
                button.setAttribute('class','adminUser-contentsButton');
-               button.setAttribute('onClick','adminUserModifySetup('+userId+')');
+               button.setAttribute('onClick','adminUserModifyInit('+userId+')');
                button.innerHTML = " "
                cell.appendChild(button);
 
@@ -77,6 +78,7 @@ function adminUserFillTable(userList) {
                var button = document.createElement('input');
                button.setAttribute('type','button');
                button.setAttribute('name',email);
+               button.setAttribute('data-mini','ture');
                button.setAttribute('class','adminUser-contentsButton');
                button.setAttribute('onClick','adminUserRemoveUser('+userId+')');
                cell.appendChild(button);
@@ -97,12 +99,8 @@ function adminUserGenerateGroupListCell(groupList) {
        return div;
 }
 
-function adminUserModifySetup(id) {
-       localStorage.userId = id;
-}
-
 function adminUserRemoveUser(userId) {
-       var email = $("#adminUser-contents-"+userId+"-email").val();
+       var email = $("#adminUser-contents-"+userId+"-email").html();
 
        var r=confirm("User ["+email+"] is removed!!!");
        if (r==false)
@@ -112,7 +110,7 @@ function adminUserRemoveUser(userId) {
 
        var changeInfoList = [];
        var changeInfoItem;
-       changeInfoItem = {"Type":"RemoveUser", "Email":email};
+       changeInfoItem = {"Type":"RemoveUser", "Id":userId};
        changeInfoList.push(changeInfoItem);
 
        removeUser(changeInfoList, function () {
index f204833..e491e5a 100644 (file)
@@ -29,22 +29,21 @@ Contributors:
 function buildInit() {
        if( $("#build-distribution-select").children().length == 0 ) {
                queryDistribution( function(xml) {
-                       $(xml).find("Data").find("DistributionName").each(function(){
-                               var name = $(this).text();
+                       $(xml).find("Data").find("Distribution").each(function(){
+                               var id = $(this).find("Id").text();
+                               var name = $(this).find("Name").text();
                
-                               $("#build-distribution-select").append("<option value=\'"+name+"\'>"+name+"</option>");
+                               $("#build-distribution-select").append("<option value=\'"+id+"\'>"+name+"</option>");
                        });
                
                        /* default distribution selection */
-                       $("#build-distribution-select option:eq(0)").attr("selected", "selected");
+                       defualt_dist_id = buildGetCookieDistribution();
+                       $("#build-distribution-select").val(defualt_dist_id);
                        $("#build-distribution-select").selectmenu('refresh');
                
                        // query Project list
                        buildQueryProjectList();
             
-                       // query Running project list
-                       //buildQueryRunningProjectList();
-            
                        // add batch file selector event
                        //buildBatchFilePathSelector();
                });
@@ -52,58 +51,45 @@ function buildInit() {
                // query Project list
                buildQueryProjectList();
         
-               // query Running project list
-               //buildQueryRunningProjectList();
-        
                // add batch file selector event
                //buildBatchFilePathSelector();
        }
 }
 
 function buildQueryProjectList() {
-       var distName = $("#build-distribution-select option:selected").val();
+       var distId = $("#build-distribution-select option:selected").val();
+
+       buildSetCookieDistribution(distId);
 
-       queryProjectsInDistribution( distName, function(xml) {
+       queryProjectsInDistribution( distId, function(xml) {
                $("#build-git-table").empty();
                $("#build-binary-table").empty();
                
                var xmlBody = $(xml).find("Data");
-               buildAddTableRow( xmlBody.find("BuildServerInfo").find("supportedOs"),
+               var distributionStatus = xmlBody.find("BuildServerInfo").find("DistributionStatus").text();
+               if (distributionStatus == "CLOSE") {
+                       var distributionLock = document.getElementById("build-distribution-lock");
+                       distributionLock.innerHTML = '<p> Distribution is locked </p>';
+               } else {
+                       var distributionLock = document.getElementById("build-distribution-lock");
+                       distributionLock.innerHTML = '';
+               }
+
+               buildAddGitTableRow( xmlBody.find("BuildServerInfo").find("SupportedOs"),
+                                        distributionStatus,
                                         xmlBody.find("Project"),
                                         xmlBody.find("OtherProject"));
-               buildAddBinaryTableRow( xmlBody.find("BinaryProject"),
+               buildAddBinaryTableRow( distributionStatus,
+                                        xmlBody.find("BinaryProject"),
                                         xmlBody.find("OtherBinaryProject"));
        });
 }
 
-function buildQueryRunningProjectList() {
-       var distName = $("#build-distribution-select option:selected").val();
-
-       queryRunningProjectsInfoInDistribution( distName, function(xml) {
-               var running_project = $(xml).find("RunProjectInfo");
-               running_project.each(function(){
-                       var project_name = $(this).find("ProjectName").text();
-                       var project_os = $(this).find("ProjectOs").text();
-                       var project_type = $(this).find("ProjectType").text();
-                       var project_status = $(this).find("Status").text();
-
-                       if (project_type == "GIT") {
-                               var cell = document.getElementById("buildGitProjectTable"+":"+project_name+':'+project_os);
-
-                               if(cell){
-                                       cell.setAttribute('bgcolor', '#fbff00');
-                               }
-                       } 
-               });
-       });
-}
-
-function buildSelectAll(element) {
-       var checkboxes = document.getElementsByName(element.id);
-       var checked = element.checked;
+function buildSelectAll(id, flag) {
+       var checkboxes = document.getElementsByName('buildGitProjectTable-checkbox-'+id);
        for(var i in checkboxes) {
                if(!checkboxes[i].disabled) { 
-                       checkboxes[i].checked = checked;
+                       checkboxes[i].checked = flag;
                } 
        }
 }
@@ -117,7 +103,7 @@ function contains(a, obj) {
        return false; 
 }
 
-function buildAddTableRow(supportedOs, projectList, otherProjectList) {
+function buildAddGitTableRow(supportedOs, distributionStatus, projectList, otherProjectList) {
        // Table header
        var idx = 0;
        var tableHeader = "";
@@ -127,10 +113,11 @@ function buildAddTableRow(supportedOs, projectList, otherProjectList) {
        // Project table header
        tableHeader = "<tr><th>Project</th>";
        supportedOs.each(function(){
-               var osName = $(this).text();
+               var osId = $(this).find("Id").text();
+               var osName = $(this).find("Name").text();
                tableHeader = tableHeader + "<th>"+osName+"</th>";
 
-               osArray[idx] = osName;
+               osArray[idx] = osId;
                idx++;
        });
 
@@ -138,12 +125,12 @@ function buildAddTableRow(supportedOs, projectList, otherProjectList) {
        $("#build-git-table").append(tableHeader);
 
        // table row - projectList
-       var index = 2;
-
        projectList.each(function(){
-               var name = $(this).find("ProjectName").text();
-               var osLists = $(this).find("OsList").text();
-               var osList = osLists.split(",");
+               var id = $(this).find("Id").text();
+               var name = $(this).find("Name").text();
+               var projectOsArray = $(this).find("OsList").text().split(",");
+               var projectStatus = $(this).find("Status").text();
+               var buildAvailable = true;
        
                var row = projectTable.insertRow(-1);
                
@@ -152,44 +139,16 @@ function buildAddTableRow(supportedOs, projectList, otherProjectList) {
                cell.setAttribute('bgcolor', '#dcddc0');
                cell.innerHTML = name;
                
-               for (i=0;i<osArray.length;i++)
-               {
-                       var cell = row.insertCell(-1);
-                       var os = osArray[i];
-       
-                       cell.setAttribute('id', "buildGitProjectTable"+":"+name+":"+os);
-                       cell.setAttribute('style', 'text-align: center');
-                       cell.setAttribute('bgcolor', '#dcddc0');
-       
-                       var buttonnode = document.createElement('input');
-                       buttonnode.setAttribute('type','checkbox');
-                       buttonnode.setAttribute('id',"table"+":"+name+':'+os);
-                       buttonnode.setAttribute('name','projectBuildCheckbox'+":"+name);
-                       buttonnode.setAttribute('class','projectTableBuildButton');
-                       cell.appendChild(buttonnode);
-
-                       if(!contains(osList, os))
-                       {
-                               buttonnode.setAttribute('disabled','disabled');
-                       }
+               if (distributionStatus == "CLOSE" || projectStatus == "CLOSE")  {
+                       buildAvailable = false;
                }
-       
-               /* append all checkbox */
-               var cell = row.insertCell(-1);
-               cell.setAttribute('style', 'text-align: center');
-               cell.setAttribute('bgcolor', '#dcddc0');
-       
-               var buttonnode = document.createElement('input');
-               buttonnode.setAttribute('type','checkbox');
-               buttonnode.setAttribute('id','projectBuildCheckbox'+":"+name);
-               buttonnode.setAttribute('name','all-checkbox');
-               buttonnode.setAttribute('class','projectTableAllButton');
-               buttonnode.setAttribute('onClick','buildSelectAll(this)');
-               cell.appendChild(buttonnode);
+
+               buildAddBinaryTableCell(id, osArray, projectOsArray, buildAvailable, row);
        });
 
        otherProjectList.each(function(){
-               var name =  $(this).find("ProjectName").text();
+               var id = $(this).find("Id").text();
+               var name =  $(this).find("Name").text();
                var row = projectTable.insertRow(-1);
                
                var cell = row.insertCell(0);
@@ -197,25 +156,11 @@ function buildAddTableRow(supportedOs, projectList, otherProjectList) {
                cell.setAttribute('bgcolor', '#c0c0c0');
                cell.innerHTML = name;
        
-               /* add empty cell for status */
-               for (i=0;i<osArray.length;i++)
-               {
-                       cell = row.insertCell(-1);
-                       cell.setAttribute('id', "table"+":"+name+"-"+osArray[i]);
-                       cell.setAttribute('style', 'text-align: left');
-                       cell.setAttribute('bgcolor', '#c0c0c0');
-                       cell.innerHTML = ""; 
-               }
-       
-               /* add empty cell for all*/
-               cell = row.insertCell(-1);
-               cell.setAttribute('style', 'text-align: left');
-               cell.setAttribute('bgcolor', '#c0c0c0');
-               cell.innerHTML = "";
+               buildAddBinaryTableCell(id, osArray, "", false, row);
        });
 }
 
-function buildAddBinaryTableRow(binaryProjectList, otherProjectList) {
+function buildAddBinaryTableRow(distributionStatus, binaryProjectList, otherProjectList) {
        var binaryProjectTable = document.getElementById("build-binary-table");
        var row = binaryProjectTable.insertRow(-1);
        var thCell = document.createElement('th');
@@ -230,18 +175,24 @@ function buildAddBinaryTableRow(binaryProjectList, otherProjectList) {
 
        /* insert binary project in binary project table */
        binaryProjectList.each(function(){
-               var name =  $(this).find("ProjectName").text();
+               var id =  $(this).find("Id").text();
+               var name =  $(this).find("Name").text();
+               var projectStatus = $(this).find("Status").text();
                var packageName =  $(this).find("PackageName").text();
                var row = '<tr><td bgcolor="#dcddc0" style="text-align:left">'+name+'</td>';
                row += '<td bgcolor="#dcddc0" style="text-align:left">' + packageName + '</td>'
-               row += '<td bgcolor="#dcddc0" style="text-align:left"><a href="upload.html" onClick="buildUploadBinaryName(\'' +name+'\')" class="binary_project_button" data-role="button" data-ajax="false" data-mini="true">REGISTER</a>';
+               if (distributionStatus == "CLOSE" || projectStatus == "CLOSE")  {
+                       row += '<td bgcolor="#c0c0c0" style="text-align:left"></td>';
+               } else {
+                       row += '<td bgcolor="#dcddc0" style="text-align:left"><a href="upload.html" onClick="buildUploadBinaryName(\'' +id+'\')" class="binary_project_button" data-role="button" data-ajax="false" data-mini="true">REGISTER</a>';
+               }
                row += '</tr>'
                
                $("#build-binary-table tr:last").after(row);
        });
 
        otherProjectList.each(function(){
-               var name =  $(this).find("ProjectName").text();
+               var name =  $(this).find("Name").text();
                var packageName =  $(this).find("PackageName").text();
                var row = binaryProjectTable.insertRow(-1);
                
@@ -273,35 +224,88 @@ function buildAddBinaryTableRow(binaryProjectList, otherProjectList) {
        });
 }
 
+function buildAddBinaryTableCell(projectId, osArray, projectOsArray, buildAvailable, row) {
+       for (i=0;i<osArray.length;i++)
+       {
+               var cell = row.insertCell(-1);
+               var osId = osArray[i];
+       
+               cell.setAttribute('id', "buildGitProjectTable-"+projectId+"-"+osId);
+               cell.setAttribute('style', 'text-align: center');
+               if (buildAvailable) {
+                       /* add cell with build checkbox */
+                       cell.setAttribute('bgcolor', '#dcddc0');
+           
+                       var buttonnode = document.createElement('input');
+                       buttonnode.setAttribute('type','checkbox');
+                       buttonnode.setAttribute('id','buildGitProjectTable-checkbox-'+projectId+'-'+osId);
+                       buttonnode.setAttribute('name','buildGitProjectTable-checkbox-'+projectId);
+                       buttonnode.setAttribute('class','projectTableBuildButton');
+                       cell.appendChild(buttonnode);
+            
+                       if(!contains(projectOsArray, osId))
+                       {
+                               buttonnode.setAttribute('disabled','disabled');
+                       }
+               } else {
+                       /* add empty cell for status */
+                       cell.setAttribute('bgcolor', '#c0c0c0');
+                       cell.innerHTML = ""; 
+               }
+       }
+
+       if (buildAvailable) {
+               /* append all checkbox */
+               var cell = row.insertCell(-1);
+               cell.setAttribute('style', 'text-align: center');
+               cell.setAttribute('bgcolor', '#dcddc0');
+               
+               var buttonnode = document.createElement('input');
+               buttonnode.setAttribute('type','checkbox');
+               buttonnode.setAttribute('id','buildGitProjectTable-all-checkbox'+projectId);
+               buttonnode.setAttribute('name','all-checkbox');
+               buttonnode.setAttribute('class','projectTableAllButton');
+               buttonnode.setAttribute('onClick','buildSelectAll(\''+projectId+'\', this.checked)');
+               cell.appendChild(buttonnode);
+       } else {
+               /* add empty cell for all*/
+               cell = row.insertCell(-1);
+               cell.setAttribute('style', 'text-align: left');
+               cell.setAttribute('bgcolor', '#c0c0c0');
+               cell.innerHTML = "";
+       }
+}
+
 function buildBuildProject() {
-       var distName = $("#build-distribution-select option:selected").val();
+       var distId = $("#build-distribution-select option:selected").val();
+       var checkedBuildButton = $(".projectTableBuildButton:checked");
        var buildProjectList = [];
 
-       //var node_list = document.getElementsByTagName('input');
-       var node_list = $("#build input")
-       for (var i = 0; i < node_list.length; i++) {
-               var node = node_list[i];
-       
-               if (node.getAttribute('type') == "checkbox") {
-                       if (node.checked == true) {
-                               if (node.getAttribute('name') != "all-checkbox") {
-                                       var prjName = node.id.split(":")[1];
-                                       var osName = node.id.split(":")[2];
-                                       var buildData = { "distribution":distName, "projectName" : prjName, "os" : osName };
-                                       buildProjectList.push(buildData);
-                               }
+       checkedBuildButton.each(function(index){
+               var name = $(this).attr("id");
+               var projectId = name.split("-")[2];
+               var osId = name.split("-")[3];
+               var buildData = { "distId":distId, "projectId" : projectId, "osId" : osId};
+               buildProjectList.push(buildData);
+       });
+
+       buildProject(buildProjectList, function (json) {
+               if(json.result != "SUCCESS") {
+                       if(json.error != "") {
+                               alert(json.message);
+                       }
+                       else {
+                               alert("Build request fail!");
                        }
                }
-       }
-       
-       buildProject(buildProjectList, function () {
-               $.mobile.changePage("#jobs"); 
+               else {
+                       $.mobile.changePage("#jobs"); 
+               }
        });
 }
 
-function buildUploadBinaryName(project_name) {
-       localStorage.distibutionName = $("#build-distribution-select option:selected").val();
-       localStorage.uploadBinaryProjectName = project_name;
+function buildUploadBinaryName(project_id) {
+       localStorage.uploadBinaryProjectId = project_id;
 }
 
 function buildBatchFilePathSelector() {
@@ -326,3 +330,17 @@ function buildClear() {
        $("#build-git-table").empty();
        $("#build-binary-table").empty();
 }
+
+function buildSetCookieDistribution(id)
+{
+       saveCookie("build_distribution", id, 7);
+}
+
+function buildGetCookieDistribution()
+{
+       id = getCookie("build_distribution");
+       if(id == "") {
+               id = 0;
+       }
+       return id;
+}
index 4cbee8b..fd324b7 100644 (file)
@@ -62,24 +62,28 @@ function queryDistribution(successFunction) {
        getInfoFromServer(url, successFunction);
 }
 
-// controller : projects
-function buildProject(changeInfoList, successFunction) {
-       var url = 'projects/buildProject';
-       postForServer(url, changeInfoList, successFunction);
+function queryAllDistribution(successFunction) {
+       var url = 'projects/queryAllDistribution';
+       getInfoFromServer(url, successFunction);
 }
 
-function queryProjectsInDistribution(distName, successFunction) {
-       var url = 'projects/queryProjectsInDistribution/' + distName;
+function queryAllProjectInOpenStatus(successFunction) {
+       var url = 'projects/queryAllProjectInOpenStatus';
        getInfoFromServer(url, successFunction);
 }
 
-function queryRunningProjectsInfoInDistribution(distName, successFunction) {
-       var url = 'projects/queryRunningProjectsInfoInDistribution/' + distName;
+function buildProject(changeInfoList, successFunction) {
+       var url = 'projects/buildProject';
+       postForServer(url, changeInfoList, successFunction);
+}
+
+function queryProjectsInDistribution(distId, successFunction) {
+       var url = 'projects/queryProjectsInDistribution/' + distId;
        getInfoFromServer(url, successFunction);
 }
 
-function queryProjectsInfoInDistribution(distName, successFunction) {
-       var url = 'projects/queryProjectsInfoInDistribution/' + distName;
+function queryProjectsInfoInDistribution(distId, successFunction) {
+       var url = 'projects/queryProjectsInfoInDistribution/' + distId;
        getInfoFromServer(url, successFunction);
 }
 
@@ -107,8 +111,8 @@ function queryAllGroup(successFunction) {
        getInfoFromServer(url, successFunction);
 }
 
-function queryGroupInfo(groupName, successFunction) {
-       var url = 'admin_group/queryGroupInfo/' + groupName;
+function queryGroupInfo(groupId, successFunction) {
+       var url = 'admin_group/queryGroupInfo/' + groupId;
        getInfoFromServer(url, successFunction);
 }
 
@@ -149,13 +153,23 @@ function removeUser(changeInfoList, successFunction) {
 }
 
 // controller : admin_server
-function queryServerInfo(successFunction) {
-       var url = 'admin_server/queryServerInfo';
+function queryAllServer(successFunction) {
+       var url = 'admin_server/queryAllServer';
        getInfoFromServer(url, successFunction);
 }
 
-function queryAllServer(successFunction) {
-       var url = 'admin_server/queryAllServer';
+function queryServerConfig(configId, successFunction) {
+       var url = 'admin_server/queryServerConfig/' + configId;
+       getInfoFromServer(url, successFunction);
+}
+
+function queryRemoteBuildServer(serverId, successFunction) {
+       var url = 'admin_server/queryRemoteBuildServer/' + serverId;
+       getInfoFromServer(url, successFunction);
+}
+
+function querySupportedOS(osId, successFunction) {
+       var url = 'admin_server/querySupportedOS/' + osId;
        getInfoFromServer(url, successFunction);
 }
 
@@ -175,17 +189,17 @@ function modifyRemoteBuildServer(changeInfoList, successFunction) {
 }
 
 function addOSCategory(changeInfoList, successFunction) {
-       var url = 'admin_server/addOsCategory';
+       var url = 'admin_server/addOSCategory';
        postForServer(url, changeInfoList, successFunction);
 }
 
 function removeOSCategory(changeInfoList, successFunction) {
-       var url = 'admin_server/removeOsCategory';
+       var url = 'admin_server/removeOSCategory';
        postForServer(url, changeInfoList, successFunction);
 }
 
 function modifyOSCategory(changeInfoList, successFunction) {
-       var url = 'admin_server/modifyOsCategory';
+       var url = 'admin_server/modifyOSCategory';
        postForServer(url, changeInfoList, successFunction);
 }
 
@@ -220,13 +234,8 @@ function modifyServerInfo(changeInfoList, successFunction) {
 }
 
 // controller : admin_project
-function queryAllProject(successFunction) {
-       var url = 'admin_project/queryAllProject';
-       getInfoFromServer(url, successFunction);
-}
-
-function queryProjectsInDistributionForAdmin(distName, successFunction) {
-       var url = 'admin_project/queryProjectsInDistributionForAdmin/' + distName;
+function queryProjectsInDistributionForAdmin(distId, successFunction) {
+       var url = 'admin_project/queryProjectsInDistributionForAdmin/' + distId;
        getInfoFromServer(url, successFunction);
 }
 
@@ -245,9 +254,14 @@ function modifyProject(changeInfoList, successFunction) {
        postForServer(url, changeInfoList, successFunction);
 }
 
+function changeAllProjectStatus(changeInfoList, successFunction) {
+       var url = 'admin_project/changeAllProjectStatus';
+       postForServer(url, changeInfoList, successFunction);
+}
+
 // controller : admin_distribution
-function queryDistributionInfo(distName, successFunction) {
-       var url = 'admin_distribution/queryDistributionInfo/' + distName;
+function queryDistributionInfo(distId, successFunction) {
+       var url = 'admin_distribution/queryDistributionInfo/' + distId;
        getInfoFromServer(url, successFunction);
 }
 
@@ -266,11 +280,6 @@ function modifyDistribution(changeInfoList, successFunction) {
        postForServer(url, changeInfoList, successFunction);
 }
 
-function fullBuildDistribution(changeInfoList, successFunction) {
-       var url = 'admin_distribution/fullBuildDistribution';
-       postForServer(url, changeInfoList, successFunction);
-}
-
 // controller : admin
 function queryAllOS(successFunction) {
        var url = 'admin/queryAllOS';
index 40c2047..cb7260d 100644 (file)
@@ -279,8 +279,9 @@ function jobQueryDistribution() {
                        // append "ALL" distribution
                        $("#jobs-distribution-select").append("<option value='ALL'>ALL</option>");
                
-                       $(xml).find("Data").find("DistributionName").each(function(){
-                               var name = $(this).text();
+                       $(xml).find("Data").find("Distribution").each(function(){
+                               var id = $(this).find("Id").text();
+                               var name = $(this).find("Name").text();
                
                                $("#jobs-distribution-select").append("<option value=\'"+name+"\'>"+name+"</option>");
                        });
@@ -309,17 +310,46 @@ function queryJobList(requestUrl, condition, param, queryDistribution, selectedS
                var lastJobId = 0;
                $(xml).find("JobList").find("Job").each(function(){
                        var id = $(this).find("Id").text();
-                       var li = generateHtmlJobList($(this));
+                       var jobAttribute = $(this).find("JobAttribute").text();
+                       var parentJobId = $(this).find("ParentJobId").text();
+                       var li = "";
+                       if(jobAttribute == "CHILD")
+                       {
+                               li = generateHtmlJobList($(this));
+                               console.log("add-child-job parent's id:"+parentJobId);
+                               $("#jobs-li-"+parentJobId+"-sub-job-area").append(li);
+                               $("#jobs-li-"+id).collapsible();
+                               $("#jobs-li-"+id+"-sub-job-button").button();
 
-                       lastJobId = id;
-                       $("#jobs-job-list").append(li).listview('refresh');
+                               $("#jobs-li-link-"+id).popupWindow({ 
+                                       height:900, 
+                                       width:800, 
+                                       top:30, 
+                                       left:50 
+                               });
+                               console.log("add-child-job id:"+id);
+
+                               //Display sub-jobs button
+                               if($("#jobs-li-"+parentJobId+"-sub-job-button-div").hasClass("ui-screen-hidden") == true) {
+                                       $("#jobs-li-"+parentJobId+"-sub-job-button-div").removeClass("ui-screen-hidden");
+                               }
+                       }
+                       else
+                       {
+                               li = generateHtmlJobList($(this));
+
+                               lastJobId = id;
+                               $("#jobs-job-list").append(li).listview('refresh');
+                               $("#jobs-li-"+id+"-sub-job-button").button();
+
+                               $("#jobs-li-link-"+id).popupWindow({ 
+                                       height:900, 
+                                       width:800, 
+                                       top:30, 
+                                       left:50 
+                               });
+                       }
 
-                       $("#jobs-li-link-"+id).popupWindow({ 
-                               height:900, 
-                               width:800, 
-                               top:30, 
-                               left:50 
-                       });
                });
 
                console.log("last job id :"+lastJobId);
@@ -353,17 +383,42 @@ function jobUpdateList(condition, param, distribution, selectedStatus) {
                // Add new job list
                $(xml).find("JobList").find("Job").each(function(){
                        var id = $(this).find("Id").text();
+                       var jobAttribute = $(this).find("JobAttribute").text();
+                       var parentJobId = $(this).find("ParentJobId").text();
                        var li = generateHtmlJobList($(this));
 
-                       $(li).insertBefore(firstLi);
-                       $("#jobs-job-list").listview('refresh');
-                       $("#jobs-li-link-"+id).popupWindow({ 
-                               height:900, 
-                               width:800, 
-                               top:30, 
-                               left:50 
-                       });
-                       console.log("ADD List :"+id);
+                       if(jobAttribute == "CHILD") {
+                               console.log("add-child-job parent's id:"+parentJobId);
+                               $("#jobs-li-"+parentJobId+"-sub-job-area").append(li);
+                               $("#jobs-li-"+id).collapsible();
+                               $("#jobs-li-"+id+"-sub-job-button").button();
+                               $("#jobs-job-list").listview('refresh');
+
+                               $("#jobs-li-link-"+id).popupWindow({ 
+                                       height:900, 
+                                       width:800, 
+                                       top:30, 
+                                       left:50 
+                               });
+                               console.log("add-child-job id:"+id);
+
+                               //Display sub-jobs button
+                               if($("#jobs-li-"+parentJobId+"-sub-job-button-div").hasClass("ui-screen-hidden") == true) {
+                                       $("#jobs-li-"+parentJobId+"-sub-job-button-div").removeClass("ui-screen-hidden");
+                               }
+                       }
+                       else {
+                               $(li).insertBefore(firstLi);
+                               $("#jobs-job-list").listview('refresh');
+                               $("#jobs-li-"+id+"-sub-job-button").button();
+                               $("#jobs-li-link-"+id).popupWindow({ 
+                                       height:900, 
+                                       width:800, 
+                                       top:30, 
+                                       left:50 
+                               });
+                               console.log("ADD List :"+id);
+                       }
                });
 
                // Update working job list
@@ -371,6 +426,7 @@ function jobUpdateList(condition, param, distribution, selectedStatus) {
                        var job_id = $(this).find("Id").text();
                        var parent_job_id = $(this).find("ParentJobId").text();
                        var job_status = $(this).find("Status").text();
+                       var job_error_code = $(this).find("ErrorCode").text();
                        var start_time = $(this).find("StartTime").text();
                        var end_time = $(this).find("EndTime").text();
                        var font_color = "black";
@@ -378,6 +434,9 @@ function jobUpdateList(condition, param, distribution, selectedStatus) {
                        switch(job_status)
                        {
                                case "ERROR" :
+                                       if(job_error_code != "") {
+                                               job_status = job_error_code;
+                                       }
                                case "CANCELED" :
                                        font_color = "red";
                                        break;
@@ -409,23 +468,25 @@ function jobUpdateList(condition, param, distribution, selectedStatus) {
                                console.log("UPDATE List :"+job_id);
                        }
                        else {
-                               var next_parent_job_li = $("#jobs-li-"+parent_job_id).nextAll(".jobs-li-header").first();
-                               console.log(parent_job_id);
-                               console.log($("#jobs-li-"+parent_job_id));
-                               console.log(next_parent_job_li);
-                               console.log(next_parent_job_li.text());
-
+                               console.log("add-child-job parent's id:"+parent_job_id);
                                var li = generateHtmlJobList($(this));
-
-                               $(li).insertBefore(next_parent_job_li);
+                               $("#jobs-li-"+parent_job_id+"-sub-job-area").append(li);
+                               $("#jobs-li-"+job_id).collapsible();
+                               $("#jobs-li-"+job_id+"-sub-job-button").button();
                                $("#jobs-job-list").listview('refresh');
+
                                $("#jobs-li-link-"+job_id).popupWindow({ 
                                        height:900, 
                                        width:800, 
                                        top:30, 
                                        left:50 
                                });
-                               console.log("ADD child list :"+job_id);
+                               console.log("add-child-job id:"+job_id);
+
+                               //Display sub-jobs button
+                               if($("#jobs-li-"+parent_job_id+"-sub-job-button-div").hasClass("ui-screen-hidden") == true) {
+                                       $("#jobs-li-"+parent_job_id+"-sub-job-button-div").removeClass("ui-screen-hidden");
+                               }
                        }
                });
        });
@@ -507,7 +568,7 @@ function jobsQueryProjectsList() {
        suggestion_list = [];
 
        if(distribution == "ALL") {
-               queryAllProject(function(xml) {
+               queryAllProjectInOpenStatus(function(xml) {
                        var idx = 0;
        
                        $(xml).find("Data").find("Project").each(function(){
@@ -535,6 +596,7 @@ function jobsClear() {
        clearJobList();
 }
 
+
 function generateHtmlJobList(xml) {
        var id = xml.find("Id").text();
        var distribution = xml.find("Distribution").text();
@@ -543,15 +605,22 @@ function generateHtmlJobList(xml) {
        var jobAttribute = xml.find("JobAttribute").text();
        var os = xml.find("Os").text();
        var jobStatus = xml.find("Status").text();
+       var jobErrorCode = xml.find("ErrorCode").text();
        var userName = xml.find("UserName").text();
        var startTime = xml.find("StartTime").text();
        var endTime = xml.find("EndTime").text();
+       var projectList = xml.find("ProjectList").text();
        var li = "";
        var font_color = "black";
 
        switch(jobStatus)
        {
                case "ERROR" :
+                       if(jobErrorCode != "") {
+                               jobStatus = jobErrorCode;
+                       }
+                       console.log(id);
+                       console.log(jobErrorCode);
                case "CANCELED" :
                        font_color = "red";
                        break;
@@ -578,7 +647,7 @@ function generateHtmlJobList(xml) {
        {
                li = '<li class="jobs-li-header" data-role="list-divider" title="'+id+'">'
                        + '<span>'+id+ ' ' +projectName+ '</span><span style="float: right">'+distribution+'</span></li>'
-                       + '<li id="jobs-li-'+id+'" class="jobs-list-data" title="'+id+'">'
+                       + '<li id="jobs-li-'+id+'" class="jobs-list-data" title="'+id+'" data-icon="false">'
                        + '<a href=log.html?jobid='+id+' id="jobs-li-link-'+id+'" class="logWindow" data-ajax="false">'
                        + '<h3>' +projectName+ '</h3>'
                        + '<p>ID : <strong>' +id+ '</strong></p>'
@@ -588,46 +657,61 @@ function generateHtmlJobList(xml) {
                        + '<p id="jobs-li-time-'+id+'">TIME: <strong>' +startTime+ ' ~ '+endTime+ '</strong></p>';
                         
                        li = li + '<p id="jobs-li-status-'+id+'" class="ui-li-aside jobs-li-status"><strong><font color="'+font_color+'">'+jobStatus+'</strong></p>';
-                       li = li + '<div hidden="hidden" class="jobs-li-hidden ui-screen-hidden">'
+                       li = li + '</a>';
+               li = li + '<div id="jobs-li-'+id+'-sub-job-button-div" class="ui-screen-hidden" style="position: absolute; top: 95px; right: 20px;"><button id="jobs-li-'+id+'-sub-job-button" data-inline="true" data-mini="true" data-icon="plus" data-iconpos="notext" data-corners="true" onClick="clickSubJobs('+id+')"></button></div>'
+                       li = li + '<div class="ui-screen-hidden">'
                                + '<p class="jobs-li-hidden-id">'+id+'</p>'
                                + '<p class="jobs-li-hidden-attr">'+jobAttribute+'</p>'
                                + '</div>';
-                       li = li + '</a></li>';
+                       li = li + '</li>';
+                       //For Sub job
+                       li = li + '<li id="jobs-li-'+id+'-child" class="ui-screen-hidden">'
+                               + '<div id="jobs-li-'+id+'-sub-job-area"></div></li>';
        }
        else if(jobAttribute == "MULTI")
        {
                li = '<li class="jobs-li-header" data-role="list-divider" title="'+id+'">'
-                       + '<span>'+id+ ' ' +jobAttribute+ '</span><span style="float: right">'+distribution+'</span></li>'
-                       + '<li id="jobs-li-'+id+'" class="jobs-list-data" title="'+id+'">'
-                       + '<a href=log.html?jobid='+id+' id="jobs-li-link-'+id+'" class="logWindow" data-ajax="false">'
+                       + '<span>'+id+ ' ' +jobAttribute+ '</span><span style="float: right">'+distribution+'</span></li>';
+               li = li + '<li id="jobs-li-'+id+'" class="jobs-list-data" title="'+id+'" data-icon="false">';
+               li = li + '<a href=log.html?jobid='+id+' id="jobs-li-link-'+id+'" class="logWindow" data-ajax="false">'
+                       + '<h3>' +projectList+ '</h3>'
+                       + '<p>ID : <strong>' +id+ '</strong></p>'
+                       + '<p>TYPE : <strong>' +jobType+ '</strong></p>'
                        + '<p>USER : <strong>' +userName+ '</strong></p>'
                        + '<p id="jobs-li-time-'+id+'">TIME: <strong>' +startTime+ ' ~ '+endTime+ '</strong></p>'
-                       + '<p id="jobs-li-attr-'+id+'" hidden="hidden">'+jobAttribute+'</p>';
                        
-                       li = li + '<p id="jobs-li-status-'+id+'" class="ui-li-aside jobs-li-status" title="'+id+'"><strong><font color="'+font_color+'">'+jobStatus+'</strong></p>';
-                       li = li + '<div hidden="hidden" class="jobs-li-hidden ui-screen-hidden">'
-                               + '<p class="jobs-li-hidden-id">'+id+'</p>'
-                               + '<p class="jobs-li-hidden-attr">'+jobAttribute+'</p>'
-                               + '</div>';
-                       li = li + '</a></li>';
+               li = li + '<p id="jobs-li-status-'+id+'" class="ui-li-aside jobs-li-status" title="'+id+'"><strong><font color="'+font_color+'">'+jobStatus+'</strong></p>';
+               li = li + '</a>';
+               li = li + '<div id="jobs-li-'+id+'-sub-job-button-div" class="ui-screen-hidden" style="position: absolute; top: 80px; right: 20px;"><button id="jobs-li-'+id+'-sub-job-button" data-inline="true" data-mini="true" data-icon="plus" data-iconpos="notext" data-corners="true" onClick="clickSubJobs('+id+')"></button></div>'
+               li = li + '<div class="ui-screen-hidden">'
+                       + '<p class="jobs-li-hidden-id">'+id+'</p>'
+                       + '<p class="jobs-li-hidden-attr">'+jobAttribute+'</p>'
+                       + '</div>';
+               li = li + '</li>';
+               //For Sub job
+               li = li + '<li id="jobs-li-'+id+'-child" class="ui-screen-hidden">'
+                               + '<div id="jobs-li-'+id+'-sub-job-area"></div></li>';
        }
        else if(jobAttribute == "CHILD")
        {
-               li = '<li id="jobs-li-'+id+'" class="jobs-list-data" title="'+id+'">'
-                       + '<a href=log.html?jobid='+id+' id="jobs-li-link-'+id+'" class="logWindow" data-ajax="false">'
-                       + '<h3>' +projectName+ '</h3>'
-                       + '<p>ID : <strong>' +id+ '</strong></p>'
+               li = '<div id="jobs-li-'+id+'" class="jobs-list-data" title="'+id+'" data-role="collapsible" data-collapsed="true" data-mini="true" data-iconpos="right" style="clear: both;">'
+                       + '<h3><span style="width: 80%;">['+id+ '] '+projectName+' - '+os+'</span><span id="jobs-li-status-'+id+'" class="jobs-li-status" style="float: right; font-size: 12px;"><font color="'+font_color+'">'+jobStatus+'</font></span></h3>'
+                       + '<a href=log.html?jobid='+id+' id="jobs-li-link-'+id+'" class="logWindow" data-ajax="false" style="text-decoration: none; color: black">'
+                       + '<h4>' +projectName+ '</h4>'
+                       + '<p class="ui-li-desc">ID : <strong>' +id+ '</strong></p>'
                        + '<p>TYPE : <strong>' +jobType+ '</strong></p>'
                        + '<p>OS : <strong>' +os+ '</strong></p>'
                        + '<p id="jobs-li-time-'+id+'">TIME: <strong>' +startTime+ ' ~ '+endTime+ '</strong></p>'
-                       + '<p id="jobs-li-attr-'+id+'" hidden="hidden">'+jobAttribute+'</p>';
-                       
-                       li = li + '<p id="jobs-li-status-'+id+'" class="ui-li-aside jobs-list-status" title="'+id+'"><strong><font color="'+font_color+'">'+jobStatus+'</strong></p>';
-                       li = li + '<div hidden="hidden" class="jobs-li-hidden ui-screen-hidden">'
-                               + '<p class="jobs-li-hidden-id">'+id+'</p>'
-                               + '<p class="jobs-li-hidden-attr">'+jobAttribute+'</p>'
-                               + '</div>';
-                       li = li + '</a></li>';
+                       + '</a>';       
+               li = li + '<div class="ui-screen-hidden">'
+                       + '<p class="jobs-li-hidden-id">'+id+'</p>'
+                       + '<p class="jobs-li-hidden-attr">'+jobAttribute+'</p>'
+                       + '</div>';
+               li = li + '<div id="jobs-li-'+id+'-sub-job-button-div" class="ui-screen-hidden" style="float: right; position: relative; top: -20px;"><button id="jobs-li-'+id+'-sub-job-button" data-inline="true" data-mini="true" data-icon="minus" data-iconpos="notext" data-corners="true" onClick="clickSubJobs('+id+')"></button></div>';
+               //For Sub job
+               li = li + '<div id="jobs-li-'+id+'-child" style="clear: both; width: 97%; position: relative; left: 30px;">'
+                               + '<div id="jobs-li-'+id+'-sub-job-area"></div></div>';
+               li = li + '</div>';
        }
 
        return li;
@@ -647,9 +731,7 @@ function searchWorkingList() {
                        case "WORKING" :
                        case "REMOTE_WORKING" :
                        case "WAITING" :
-                               if(job_attr != "CHILD") {
-                                       working_job_array.push(job_id);
-                               }
+                               working_job_array.push(job_id);
                                break;
                        default:
                                break;
@@ -692,3 +774,14 @@ function isPolling(idx) {
        }
 }
 
+function clickSubJobs(job_id) {
+       if($("#jobs-li-"+job_id+"-child").hasClass("ui-screen-hidden") == true) {
+               $("#jobs-li-"+job_id+"-child").removeClass("ui-screen-hidden");
+               $("#jobs-li-"+job_id+"-sub-job-button").buttonMarkup({icon:"minus"});
+       }
+       else {
+               $("#jobs-li-"+job_id+"-child").addClass("ui-screen-hidden");
+               $("#jobs-li-"+job_id+"-sub-job-button").buttonMarkup({icon:"plus"});
+       }
+}
+
index be17b7a..de72f9b 100644 (file)
@@ -128,12 +128,13 @@ function queryLog()
 }
 
 function autoQueryLog(conti, working_status) {
-       if(conti && stop) {
-               queryLog();
-       }
-       else if(working_status == 1 && stop) {
+       if(working_status == 1 && stop) {
                console.log("status is working. try request");
-               setTimeout(function(){queryLog()}, 3000);
+               setTimeout(function(){queryLog()}, 1000);
+       }
+       else if(conti && stop) {
+               console.log("contiue request");
+               setTimeout(function(){queryLog()}, 100);
        }
 }
 
@@ -148,7 +149,8 @@ function moreLog() {
 
 function cancelJob() {
        cancelJobsJobid(job_id, function(xml) {
-               alert("Reqeusted cancel job : "+job_id);
+               var message = $(xml).find("Data").find("Message").text();
+               alert(message);
        });
 }
 
index 245617c..b5d997d 100644 (file)
@@ -69,7 +69,8 @@ $( document ).bind( "pagechange", function( event, data ){
                        clearFormData('signup-form');
                        break;
                case "login":
-                       clearFormData('login-form');
+                       clearLoginData();
+                       getUserId();
                        break;
                case "projects":
                        generateNavigationBar(id);
@@ -109,24 +110,9 @@ $( document ).bind( "pagechange", function( event, data ){
                case "adminDistributionModify":
                        adminDistributionModifyPopupInit();
                        break;
-               case "adminUserModify":
-                       adminUserModifyInit();
-                       break;
-               case "adminProjectModifyBinary":
-                       adminProjectModifyBinaryProjectInit();
-                       break;
-               case "adminProjectModifyGit":
-                       adminProjectModifyGitProjectInit();
-                       break;
                case "adminGroupAdd":
                        adminGroupAddInit();
                        break;
-               case "adminGroupModify":
-                       adminGroupModifyInit();
-                       break;
-               case "adminServerModifyRemoteBuildServer":
-                       adminServerModifyRemoteBuildServerInit();
-                       break;
                case "adminProjectAddGit":
                        adminProjectAddGitInit();
                        break;
@@ -335,3 +321,26 @@ function dibsWebClear(){
        buildClear();
        jobsClear();
 }
+
+function getCookie(key)
+{
+       var cook = document.cookie + ";";
+       var idx = cook.indexOf(key, 0);
+       var val = "";
+
+       if (idx != -1) {
+                       cook = cook.substring(idx, cook.length);
+                       begin = cook.indexOf("=", 0) + 1;
+                       end = cook.indexOf(";", begin);
+                       val = unescape(cook.substring(begin, end));
+       }
+
+       return val;
+}
+
+function saveCookie(key, value, expire_days)
+{
+       var today = new Date();
+       today.setDate(today.getDate() + expire_days);
+       document.cookie = key + "=" + escape(value) + "; path=/; expires=" + today.toGMTString() + ";";
+}
index e982f67..1aa86c6 100644 (file)
@@ -29,37 +29,40 @@ Contributors:
 function projectsInit() {
        if( $("#projects-distribution-select").children().length == 0 ) {
                queryDistribution( function(xml) {
-                       $(xml).find("Data").find("DistributionName").each(function(){
-                               var name = $(this).text();
+                       $(xml).find("Data").find("Distribution").each(function(){
+                               var id = $(this).find("Id").text();
+                               var name = $(this).find("Name").text();
                
-                               $("#projects-distribution-select").append("<option value=\'"+name+"\'>"+name+"</option>");
+                               $("#projects-distribution-select").append("<option value=\'"+id+"\'>"+name+"</option>");
                        });
                
                        /* default distribution selection */
-                       $("#projects-distribution-select option:eq(0)").attr("selected", "selected");
+                       defualt_dist_id = projectsGetCookieDistribution();
+                       $("#projects-distribution-select").val(defualt_dist_id);
                        $("#projects-distribution-select").selectmenu('refresh');
                
-                       projectsQueryProjectListType("MY"); 
                        $('#projects-type-select input[type="radio"]').attr("checked",false).checkboxradio("refresh");
                        $('#projects-type-select input[type="radio"]:first').attr("checked",true).checkboxradio("refresh");
+                       projectsQueryProjectListType(); 
                });
        } else {
-               projectsQueryProjectListType("MY"); 
-               $('#projects-type-select input[type="radio"]').attr("checked",false).checkboxradio("refresh");
-               $('#projects-type-select input[type="radio"]:first').attr("checked",true).checkboxradio("refresh");
+               projectsQueryProjectListType(); 
        }
 }
 
-function projectsQueryProjectListType(queryType) {
-       var distName = $("#projects-distribution-select option:selected").val();
+function projectsQueryProjectListType() {
+       var dist_id = $("#projects-distribution-select option:selected").val();
 
-       queryProjectsInfoInDistribution( distName, function(xml) {
+       projectsSetCookieDistribution(dist_id);
+
+       queryProjectsInfoInDistribution( dist_id, function(xml) {
                $("#projects-project-list").empty();
 
                var projectList = document.getElementById("projects-project-list");
+               var projectType = $('#projects-type-select').find("input[type='radio']:checked").val();
 
                $(xml).find("Data").find("ProjectList").find("Project").each(function(){
-                       switch(queryType) {
+                       switch(projectType) {
                                case "ALL":
                                        projectsAppendProjectList($(this), projectList);
                                        break;
@@ -93,6 +96,7 @@ function projectsQueryProjectListType(queryType) {
 }
 
 function projectsAppendProjectList( project, projectList ) {
+       var id = project.find("Id").text();
        var name = project.find("Name").text();
        var type = project.find("Type").text();
        var groupAccess = project.find("GroupAccess").text();
@@ -163,3 +167,16 @@ function projectsClear() {
        $("#projects-project-list").empty();
 }
 
+function projectsSetCookieDistribution(id)
+{
+       saveCookie("projects_distribution", id, 7);
+}
+
+function projectsGetCookieDistribution()
+{
+       id = getCookie("projects_distribution");
+       if(id == "") {
+               id = 0;
+       }
+       return id;
+}
index 89c1e2b..244107f 100644 (file)
@@ -119,11 +119,41 @@ function sessionLogin() {
                        sessionStorage.sessionInfoName = name;
                        sessionStorage.sessionInfoGroup = group;
                        sessionStorage.sessionInfoAdmin = admin;
+
+                       saveUserId(email);
+
                        $.mobile.changePage("#index"); 
                } 
                else
                {
                        alert(message);
-                       }
+               }
        });
 } 
+
+function clearLoginData()
+{
+       $("#login-form-email").val("");
+       $("#login-form-password").val("");
+}
+function getUserId()
+{
+       id = getCookie("user_email");
+       if(id != "") {
+               $("#login-form-email").val(id);
+       }
+}
+
+function saveUserId(id)
+{
+       if($("#login-form-save").attr("checked") ==  "checked") {
+               if (id != "") {
+                               saveCookie("user_email", id, 7);
+               } else {
+                               saveCookie("user_email", id, -1);
+               }
+       }
+       else {
+               saveCookie("user_email", id, -1);
+       }
+}
index 3d56aeb..6466218 100644 (file)
@@ -40,12 +40,10 @@ Contributors:
 
 <script>
 $('#register').click(function(){
-       var dist_name = localStorage.distibutionName;
-       var prj_name = localStorage.uploadBinaryProjectName;
+       var prj_id = localStorage.uploadBinaryProjectId;
     var formData = new FormData($('form')[0]);
 
-       formData.append("distribution", dist_name);
-       formData.append("project", prj_name);
+       formData.append("ProjectId", prj_id);
 
        $('progress').removeAttr("hidden");
 
index 834a7e7..0461468 100644 (file)
@@ -1,3 +1,111 @@
+* 2.1.40
+- Fixed some minor bugs
+== Sungmin Kim <dev.sungmin.kim@samsung.com> 2013-06-04
+* 2.1.33
+- Applied "retry count" when downloading files
+- Changed "stop" command format of pkg sver
+- Fixed some minor bugs
+== donghee yang <donghee.yang@samsung.com> 2013-06-04
+* 2.1.32
+- DIBS command should be forcibly enter your email address and password.
+== Taejun ha <taejun.ha@samsung.com> 2013-04-24
+* 2.1.31
+- Fixed a bug that calc for empty room
+- Fixed a bug that local commit id is used for remote build
+- Shows reverse build jobs in DIBS WEB
+- Shows "ERROR CODE" in DIBS WEB
+== donghee yang <donghee.yang@samsung.com> 2013-04-24
+* 2.1.30
+- Fixed a bug that infinite loop of getting source code
+== donghee yang <donghee.yang@samsung.com> 2013-04-19
+* 2.1.29
+- Fixed a bug that migrating DB does not work
+== donghee yang <donghee.yang@samsung.com> 2013-04-19
+* 2.1.28
+- Fixed a bug that upgrade does not work
+== donghee yang <donghee.yang@samsung.com> 2013-04-19
+* 2.1.27
+- Fixed build server failure caused by job number
+== donghee yang <donghee.yang@samsung.com> 2013-04-19
+* 2.1.26
+- Added new user "sync-manager" for package synchronization
+- Changed to insert error code when job is ended with "ERROR"
+- Added time-stamping of job
+- Modified to make child build servers work without DB
+== donghee yang <donghee.yang@samsung.com> 2013-04-19
+* 2.1.25
+- Fixed a bug that remote job is not released from remote server queue
+== donghee yang <donghee.yang@samsung.com> 2013-04-12
+* 2.1.24
+- Fixed a bug that job assignment to child server is wrong
+== donghee yang <donghee.yang@samsung.com> 2013-04-12
+* 2.1.23
+- Modified to make build-server work when max-job is zero
+== donghee yang <donghee.yang@samsung.com> 2013-04-12
+* 2.1.22
+- Fixed not to build redundent jobs
+- Modified to use separate process for file transfering
+== donghee yang <donghee.yang@samsung.com> 2013-04-11
+* 2.1.21
+- Fixed the calculation of file transfer rate 
+== donghee yang <donghee.yang@samsung.com> 2013-04-11
+* 2.1.20
+- Separate the process for log monitor
+== donghee yang <donghee.yang@samsung.com> 2013-04-10
+* 2.1.19
+- Fixed a bug that noreverse option is not working
+- Fixed a bug about checking dependency of multi job
+- Modified to continue build process when "git reset fail"
+- Fixed a but that remote job return wrong status
+- Fixed a bug that JOB numbering return 0
+== donghee yang <donghee.yang@samsung.com> 2013-04-05
+* 2.1.18
+- Increase protocol version from 1.8.0 to 1.9.0
+== Sungmin kim <dev.sungmin.kim@samsung.com> 2013-04-04
+* 2.1.17
+- Add command about "pkg-cli changeLog -u url [-s snapshotName1,snapshotName2]"
+- Fixed Multi-job about sub-job add internal job for cancel process
+- Fixed stoping query-log when couldn't search in JOB queue
+- Fixed reverse-job to add int DB first after creation
+== Sungmin kim <dev.sungmin.kim@samsung.com> 2013-04-03
+* 2.1.16
+- Fixed query-log terminated when status is not "FINISHED"
+- Fixed bug about file lock in build-cli
+== Sungmin kim <dev.sungmin.kim@samsung.com> 2013-04-01
+* 2.1.15
+- Fixed some bug about query-log
+- Improve process in web side
+== Sungmin kim <dev.sungmin.kim@samsung.com> 2013-03-29
+* 2.1.14
+- Support query-log command
+- Improve process to receive log 
+== Sungmin kim <dev.sungmin.kim@samsung.com> 2013-03-28
+* 2.1.13
+- Fixed a bug that there are too many open files on build-svr
+== donghee yang <donghee.yang@samsung.com> 2013-03-27
+* 2.1.12
+- Project lock Applied with dibs web
+== taejun ha <taejun.ha@samsung.com> 2013-03-26
+* 2.1.11
+- Fixed a bug that "CANCEL" of remote job is not finished
+== donghee yang <donghee.yang@samsung.com> 2013-03-26
+* 2.1.10
+- Added more check points for immediate "CANCEL" 
+== donghee yang <donghee.yang@samsung.com> 2013-03-26
+* 2.1.9
+- Fixed a bug that "CANCEL" is not done immediately
+== donghee yang <donghee.yang@samsung.com> 2013-03-26
+* 2.1.8
+- Modified to use hard-link instead of copying
+- Removed "verbose" option in build-cli
+== donghee yang <donghee.yang@samsung.com> 2013-03-25
+* 2.1.7
+- add log for debug
+== hyoun jiil <jiil.hyoun@samsung.com> 2013-03-21
+* 2.1.6
+- Fixed client cache bug
+- Fixed Job numbering bug
+== donghee yang <donghee.yang@samsung.com> 2013-03-20
 * 2.1.5
 - bug fix : log file remove when job initializing 
 == hyoun jiil <jiil.hyoun@samsung.com> 2013-03-15
index f6a68c1..c550b41 100644 (file)
@@ -1,5 +1,5 @@
 Source : dibs
-Version :2.1.5
+Version :2.1.40
 Maintainer : taejun ha<taejun.ha@samsung.com>, jiil hyoun <jiil.hyoun@samsung.com>, donghyuk yang <donghyouk.yang@samsung.com>, donghee yang <donghee.yang@samsung.com>, sungmin kim <dev.sungmin.kim@samsung.com
 
 Package : dibs
index dbfad26..4f9dad7 100755 (executable)
--- a/pkg-build
+++ b/pkg-build
@@ -47,8 +47,14 @@ end
 
 # check HOST OS
 if not Utils.check_host_OS() then
-       puts "Error: Your host OS is not supported!"
-       exit 1
+
+       if Utils.is_linux_like_os Utils::HOST_OS then
+               Utils.set_default_linux_host_os
+               puts "Warning: Your host OS is not supported!\nWe assume your host OS as #{Utils::HOST_OS} !!!"
+       else
+               puts "Error: Your host OS is not supported!"
+               exit 1
+       end
 end
 
 # if "--os" is not specified, use host os type
index 6a6cbb4..acb105d 100755 (executable)
--- a/pkg-clean
+++ b/pkg-clean
@@ -48,8 +48,14 @@ option = parse
 
 # check HOST OS
 if not Utils.check_host_OS() then
-       puts "Error: Your host OS is not supported!"
-       exit 1
+
+       if Utils.is_linux_like_os Utils::HOST_OS then
+               Utils.set_default_linux_host_os
+               puts "Warning: Your host OS is not supported!\nWe assume your host OS as #{Utils::HOST_OS} !!!"
+       else
+               puts "Error: Your host OS is not supported!"
+               exit 1
+       end
 end
 
 begin
diff --git a/pkg-cli b/pkg-cli
index 9cbb4c8..14226eb 100755 (executable)
--- a/pkg-cli
+++ b/pkg-cli
@@ -53,8 +53,14 @@ end
 
 # check HOST OS
 if not Utils.check_host_OS() then
-       puts "Error: Your host OS is not supported!"
-       exit 1
+
+       if Utils.is_linux_like_os Utils::HOST_OS then
+               Utils.set_default_linux_host_os
+               puts "Warning: Your host OS is not supported!\nWe assume your host OS as #{Utils::HOST_OS} !!!"
+       else
+               puts "Error: Your host OS is not supported!"
+               exit 1
+       end
 end
 #if "--os" is not specfied, use host os type
 if option[:os].nil? then
@@ -63,36 +69,83 @@ end
 
 case option[:cmd]
 when "clean" then
-       client = Client.new( nil, option[:loc], nil, false )
+       client = Client.create( nil, option[:loc], nil, false )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        client.clean(option[:f])
 when "download" then
-       client = Client.new( option[:url], option[:loc], nil )
+       client = Client.create( option[:url], option[:loc], nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        file_loc = client.download( option[:pkg], option[:os], option[:t] )
+when "make-img" then
+       client = Client.create( option[:url], option[:loc], nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end
+       client.make_img( option[:os] )
 when "install" then
-       client = Client.new( option[:url], option[:loc], nil )
+       client = Client.create( option[:url], option[:loc], nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        client.install( option[:pkg], option[:os], option[:t], option[:f] )
 when "install-file" then
        if option[:t] then
-               client = Client.new( option[:url], option[:loc], nil )
+               client = Client.create( option[:url], option[:loc], nil )
+               if client.nil? then
+                       puts "Error: Cannot create package client!"
+                       exit 1
+               end                     
                client.install_local_pkg( option[:pkg], option[:t], option[:f] )
        else
-               client = Client.new( nil, option[:loc], nil, false )
+               client = Client.create( nil, option[:loc], nil, false )
+               if client.nil? then
+                       puts "Error: Cannot create package client!"
+                       exit 1
+               end                     
                client.install_local_pkg( option[:pkg], option[:t], option[:f] )
        end                     
 when "uninstall" then
-       client = Client.new( nil, option[:loc], nil, false )
+       client = Client.create( nil, option[:loc], nil, false )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        client.uninstall( option[:pkg], option[:t] )
 when "upgrade" then
-       client = Client.new( option[:url], option[:loc], nil )
+       client = Client.create( option[:url], option[:loc], nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        client.upgrade( option[:os], option[:t] )
 when "check-upgrade" then
-       client = Client.new( option[:url], option[:loc], nil )
+       client = Client.create( option[:url], option[:loc], nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        client.check_upgrade( option[:os] )
 when "show-rpkg" then
-       client = Client.new( option[:url], nil, nil )
+       client = Client.create( option[:url], nil, nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        puts client.show_pkg_info( option[:pkg], option[:os] )
 when "list-rpkg" then
-       client = Client.new( option[:url], nil, nil )
+       client = Client.create( option[:url], nil, nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        result = client.show_pkg_list( option[:os] )
        if not result.nil? and not result.empty? then
                result.each do |i|
@@ -103,10 +156,18 @@ when "list-rpkg" then
                end
        end
 when "show-lpkg" then
-       client = Client.new( nil, option[:loc], nil, false )
+       client = Client.create( nil, option[:loc], nil, false )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        puts client.show_installed_pkg_info( option[:pkg] )
 when "list-lpkg" then
-       client = Client.new( nil, option[:loc], nil, false )
+       client = Client.create( nil, option[:loc], nil, false )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        result = client.show_installed_pkg_list()
        if not result.nil? and not result.empty? then
                result.each do |i|
@@ -119,7 +180,11 @@ when "list-lpkg" then
                puts "Info: There is no any package."
        end
 when "build-dep" then
-       client = Client.new( option[:url], nil, nil )
+       client = Client.create( option[:url], nil, nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        result = client.get_build_dependent_packages( option[:pkg], option[:os], true )
        if result.nil? then
                puts "Error: Failed to get remote package list. try update first."
@@ -133,7 +198,11 @@ when "build-dep" then
        ret[-3..-1] = ""
        puts ret
 when "install-dep" then
-       client = Client.new( option[:url], nil, nil )
+       client = Client.create( option[:url], nil, nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        result = client.get_install_dependent_packages( option[:pkg], option[:os], true, false )
        if result.nil? then
                puts "Error: Failed to get remote package list. try update first."
@@ -147,8 +216,30 @@ when "install-dep" then
        ret[-3..-1] = ""
        puts ret
 when "register" then
-       client = Client.new( nil, nil, nil )
+       client = Client.create( nil, nil, nil )
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
        client.register(option[:address], option[:dist], option[:pkg], option[:passwd])
+when "snapshotlist" then
+       client = Client.create(option[:url],nil,nil);
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
+       client.printSnapshotList(option[:all]);
+when "changelog" then
+       client = Client.create(option[:url], nil, nil);
+       if client.nil? then
+               puts "Error: Cannot create package client!"
+               exit 1
+       end                     
+       if option[:snapshot].nil?() then
+       client.printChangeLog();
+       else
+       client.printChangeLog(option[:snapshot][0], option[:snapshot][1]);
+       end
 else
        raise RuntimeError, "Input is incorrect : #{option[:cmd]}"
 end
index f653b80..b65b8cb 100644 (file)
@@ -40,7 +40,7 @@ class BinaryUploadProject < CommonProject
 
        # initialize
        def initialize( name, server, os_list, dist_name, pkg_name = nil )
-               super(name, "BINARY", server, os_list, dist_name)
+               super(name, "BINARY", server, os_list, dist_name, "OPEN")
                @pkg_name = pkg_name
        end
 
@@ -139,13 +139,13 @@ class BinaryUploadProject < CommonProject
                row, prj_os_list, source_info, package_info = load_row(name, dist_name, db)
                prj_id = row['id']
                prj_name = row['name']
-               prj_passwd = row['password']
+               prj_status = row['status']
 
                new_project = BinaryUploadProject.new(prj_name, server, prj_os_list, dist_name)
-               if not prj_passwd.empty? then new_project.passwd = prj_passwd end
                new_project.set_project_id( prj_id )
                new_project.set_source_info( source_info )
                new_project.set_package_info( package_info )
+               new_project.set_project_status( prj_status )
 
                row=db.select_one("SELECT * FROM project_bins WHERE project_id=#{prj_id}")
                if row.nil? then return nil end
index d2c98a1..550e7b5 100644 (file)
@@ -31,14 +31,14 @@ require 'optparse'
 require 'utils'
 
 class BuildClientUsage
-       BUILD="build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>] [-U user-email] [-V]"
-       #RESOLVE="build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>] [-U user-email] [-V]"
+       BUILD="build-cli build -N <project name> -d <server address> -U <user-id> -w <user-password> [-o <os>] [--async] [-D <distribution name>] [--save]"
        QUERY="build-cli query -d <server address>"
        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>"
-       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]"
+       QUERY_LOG="build-cli query-log -d <server address> -j <job number> [--output <output file path>]"
+       CANCEL="build-cli cancel -j <job number> -d <server address> -U user-id -w <user-password>"
+       REGISTER="build-cli register -P <package file> -d <server address> -U user-id -w <user-password> [-t <ftp server url>] [-D <distribution name>]"
 end
 
 
@@ -47,16 +47,12 @@ def option_error_check( options )
 
        when "build" then
                if options[:project].nil? or options[:project].empty? or
-                       options[:domain].nil? or options[:domain].empty? then
+                       options[:domain].nil? or options[:domain].empty? or
+                       options[:passwd].nil? or options[:passwd].empty? or
+                       options[:user].nil? or options[:user].empty? then
                        raise ArgumentError, "Usage: " + BuildClientUsage::BUILD
                end
 
-#      when "resolve" then
-#              if options[:project].nil? or options[:project].empty? or
-#                      options[:domain].nil?  or options[:domain].empty? then
-#                      raise ArgumentError, "Usage: " + BuildClientUsage::RESOLVE
-#              end
-#
        when "query" then
                if options[:domain].nil? or options[:domain].empty? then
                        raise ArgumentError, "Usage: " + BuildClientUsage::QUERY
@@ -77,14 +73,24 @@ def option_error_check( options )
                        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
+                       options[:domain].nil? or options[:domain].empty? or
+                       options[:passwd].nil? or options[:passwd].empty? or
+                       options[:user].nil? or options[:user].empty? then
                        raise ArgumentError, "Usage: " + BuildClientUsage::CANCEL
                end
        when "register" then
                if options[:package].nil? or options[:package].empty? or
-                       options[:domain].nil? or options[:domain].empty? then
+                       options[:domain].nil? or options[:domain].empty? or
+                       options[:passwd].nil? or options[:passwd].empty? or
+                       options[:user].nil? or options[:user].empty? then
                        raise ArgumentError, "Usage: " + BuildClientUsage::REGISTER
                end
 
@@ -107,6 +113,7 @@ def option_parse
                + "\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" \
@@ -115,6 +122,7 @@ def option_parse
                + "\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"
@@ -158,12 +166,22 @@ def option_parse
                        options[:noreverse] = "YES"
                end
 
+               options[:rebuild] = "NO"
+               opts.on( '--rebuild', 'do not check package version' ) do
+                       options[:rebuild] = "YES"
+               end
+
+               options[:save] = false
+               opts.on( '--save', 'save the files built from remote server' ) do
+                       options[:save] = true
+               end
+
                opts.on( '-j', '--job <job number>', 'job number' ) do|job|
                        options[:job] = job
                end
 
                options[:passwd] = ""
-               opts.on( '-w', '--passwd <password>', 'password for managing project' ) do|passwd|
+               opts.on( '-w', '--passwd <user-password>', 'user password' ) do|passwd|
                        options[:passwd] = passwd
                end
 
@@ -179,18 +197,18 @@ def option_parse
                        options[:fdomain] = domain
                end
 
-               options[:user] = "admin@user"
+               options[:user] = ""
                opts.on( '-U', '--user <user email>', 'user email infomation' ) do|user|
                        options[:user] = user
                end
 
-               options[:verbose] = "NO"
-               opts.on( '-V', '--verbose', 'verbose mode' ) do
-                       options[:verbose] = "YES"
+               options[:output] = nil
+               opts.on( '--output <output_path>', 'output file path' ) do|path|
+                       options[:output] = path
                end
 
                opts.on( '-h', '--help', 'display help' ) do
-                       opts.help.split("\n").each {|op| puts op if not op.include? "--noreverse"}
+                       opts.help.split("\n").each {|op| puts op if not op.include? "--noreverse" and not op.include? "--rebuild"}
                        exit
                end
 
@@ -199,6 +217,7 @@ def option_parse
                        exit
                end
 
+
        end
 
        cmd = ARGV[0]
@@ -206,6 +225,7 @@ def option_parse
        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
index 8d9c8e4..3682166 100644 (file)
@@ -36,20 +36,18 @@ require "PackageManifest.rb"
 require "Version.rb"
 require "Builder.rb"
 require "RemoteBuilder.rb"
-require "JobLog.rb"
 require "mail.rb"
 require "utils.rb"
 require "ReverseBuildChecker.rb"
 require "CommonJob.rb"
+require "BuildServerException.rb"
 
 class BuildJob < CommonJob
 
        attr_accessor :pkginfo, :source_path
-       attr_accessor :pkgsvr_client, :thread
-#      attr_accessor :rev_fail_projects, :rev_success_jobs
-#      attr_accessor :pending_ancestor
+       attr_accessor :pkgsvr_client
        attr_accessor :no_reverse
-       attr_accessor :remote_id
+       attr_accessor :remote_id, :remote_status, :remote_error_msg
 
        # initialize
        def initialize (project, os, server)
@@ -58,9 +56,9 @@ class BuildJob < CommonJob
                @os = os
                @type = "BUILD"
 
-               #@resolve = false
                @host_os = Utils::HOST_OS
-               if not @server.distmgr.nil? then
+               if not @server.distmgr.nil? and @server.has_db? and
+                       not @project.nil? and not @project.is_transferred? then
                        @pkgsvr_url = @server.distmgr.get_distribution(project.dist_name).pkgsvr_url
                        @pkgsvr_ip = @server.distmgr.get_distribution(project.dist_name).pkgsvr_ip
                        @pkgsvr_port = @server.distmgr.get_distribution(project.dist_name).pkgsvr_port
@@ -75,7 +73,6 @@ class BuildJob < CommonJob
                # this item will be initialized on pre-verify
                @pkginfo = nil
                @pkgsvr_client = nil
-               @thread = nil
                @log = nil
                @parent = nil # for job hierachy
 
@@ -83,6 +80,8 @@ class BuildJob < CommonJob
                #@pending_ancestor = nil # for cancel pending job
                @remote_id = nil # for cancel remote_working job
                @build_dep_prjs = nil # for cacnel pending job
+               @remote_status = ""
+               @remote_error_msg = ""
 
                ## for resolving build-break
                #@rev_fail_projects = [] # list of [project,os]
@@ -95,9 +94,12 @@ class BuildJob < CommonJob
                @is_rev_build_check_job = false
                @is_remote_job = false
 
-               # for internal(transferred) job
-               @is_internal_job = false
+               # "verified" means that server will not check any rule
+               @is_verified = false
+               # "send_result_back" mean that server will send package file by network
+               @send_result_back = false
                @dock_num = "0"
+               @result_files = []
 
                @external_pkgs = []
                @force_rebuild = false
@@ -154,17 +156,25 @@ class BuildJob < CommonJob
        end
 
 
-       def set_internal_job( dock_num )
-               @is_internal_job = true
+       def set_verified( value )
+               @is_verified = value
+       end
+
+
+       def set_send_result_back( dock_num )
+               @send_result_back = true
                @dock_num = dock_num
        end
 
 
-       ## set option for waiting for resolve
-       #def set_resolve_flag()
-       #       @resolve = true
-       #end
+       def is_send_result_back?
+               return @send_result_back
+       end
+
 
+       def get_result_files()
+               return @result_files
+       end
 
        # set force rebuild
        # This make project to build
@@ -180,13 +190,19 @@ class BuildJob < CommonJob
        end
 
 
+       # for transferred project, this will overwite URL
+       def set_package_server_url(url)
+               @pkgsvr_url = url
+       end
+
+
        #cancel
        def cancel()
                # kill sub process if exist?
                kill_sub_process()
 
                # cancel all its sub jobs
-               @sub_jobs.select{|x| x.event == "NONE"}.each do |sub|
+               @sub_jobs.select{|x| x.event == "NONE" and x.status != "FINISHED" and x.status != "ERROR" and x.status != "CANCELED" }.each do |sub|
                        sub.event = "CANCEL"
                end
 
@@ -197,16 +213,10 @@ class BuildJob < CommonJob
                        end
                end
 
-               # cancel log print
-               if not @log.nil? then
-                       @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
-               end
-
-               case @status
-               when "REMOTE_WORKING" then
+               if @status == "REMOTE_WORKING" then
                        client = BuildCommClient.create( @remote_server.ip, @remote_server.port, @log )
                        if not client.nil? then
-                               client.send "CANCEL|#{@remote_id}|#{self.get_project.passwd}|admin@user"
+                               client.send "CANCEL|#{@remote_id}||"
                                result1 = client.receive_data()
                                if result1.nil? then
                                        @log.info( "cancel operation failed [connection error] !!", Log::LV_USER)
@@ -217,40 +227,14 @@ class BuildJob < CommonJob
                                end
                                client.terminate
                        end
-               #when "PENDING" then
-               #       if @pending_ancestor.nil? then
-               #               #resolve pending job
-               #               pending_descendants = @server.jobmgr.jobs.select do |j|
-               #                       (not j.pending_ancestor.nil?) and "#{j.pending_ancestor.id}" == "#{@id}"
-               #               end
-               #               pending_descendants.each do |pd|
-               #                       pd.cancel_state = "INIT"
-               #               end
-               #       else
-               #               # remove myself from success job if exist
-               #               # and add myself into rev_fail_project list if not exist
-               #               @pending_ancestor.remove_rev_success_job(self)
-               #               @pending_ancestor.add_rev_fail_project( @project, @os )
-
-               #               # remove the project that depends on me if exist
-               #               # and add it into rev_fail_project list if not exist
-               #               p_sub_jobs = @server.jobmgr.jobs.select do |j|
-               #                       ( not j.pending_ancestor.nil? and
-               #                        "#{j.pending_ancestor.id}" == "#{@pending_ancestor.id}" and
-               #                        j.is_build_dependent_project(@project, @os) )
-               #               end
-               #               p_sub_jobs.each do |d|
-               #                       @pending_ancestor.remove_rev_success_job(d)
-               #                       @pending_ancestor.add_rev_fail_project( d.get_project, d.os )
-
-               #                       if not d.thread.nil? then d.thread.terminate end
-               #                       d.status = "WAITING"
-               #               end
-               #       end
-               when "WORKING", "WAITING" , "INITIALIZING" , "JUST_CREATED" then
-                       #just log
-               else # ERROR | FINISHED | RESOLVED
-                       #do noting
+               end
+
+               # wait for job thread to finish
+               @thread.join if not @thread.nil?
+
+               # cancel log print
+               if not @log.nil? then
+                       @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
                end
        end
 
@@ -260,11 +244,13 @@ class BuildJob < CommonJob
                if @pkginfo.nil? then return false end
 
                @pkginfo.packages.each do |pkg|
-                       if pkg.os_list.include? @os and pkg.build_host_os.include? host_os then
-                               return true
+                       if not pkg.os_list.include? @os then next end
+                       if not pkg.build_host_os.include? host_os then
+                               return false
                        end
                end
-               return false
+
+               return true
        end
 
 
@@ -283,6 +269,31 @@ class BuildJob < CommonJob
        end
 
 
+       def is_same_with?(wjob)
+               # must have same distribution
+               if get_distribution_name() != wjob.get_distribution_name() then
+                       return false
+               end
+
+               if @type != wjob.type then return false end
+
+               prj1 = get_project()
+               prj2 = wjob.get_project()
+
+               # check project name
+               if prj1.nil? or prj2.nil? or
+                       prj1.name != prj2.name then
+                       return false
+               end
+
+               # check version
+               if @pkginfo.nil? or wjob.pkginfo.nil? or
+                       not(Version.new(@pkginfo.get_version()) == Version.new(wjob.pkginfo.get_version())) then
+                       return false
+               end
+       end
+
+
        def is_compatible_with?(o)
                # must have same distribution
                if get_distribution_name() != o.get_distribution_name() then
@@ -400,71 +411,12 @@ class BuildJob < CommonJob
        end
 
 
-       def is_connected?
-               return @log.is_connected?
-       end
-
-
        # return the job is asyncronous job
        def is_asynchronous_job?
-               if not @log.has_second_out? then
-                       return true
-               else
-                       return false
-               end
+               return true
        end
 
 
-       ## remove job from reverse success job
-       #def remove_rev_success_job( job )
-       #       @rev_success_jobs.delete job if @rev_success_jobs.include? job
-       #end
-
-
-       ## check [project,os] is in reverse fail project list
-       #def is_rev_fail_project( prj, os )
-       #       # check the project already exist
-       #       @rev_fail_projects.each do |p|
-       #               if p[0] == prj and p[1] == os then
-       #                       return true
-       #               end
-       #       end
-
-       #       return false
-       #end
-
-
-       ## add [project,os] to reverse fail project list
-       #def add_rev_fail_project( prj, os )
-       #       # check the project already exist
-       #       @rev_fail_projects.each do |p|
-       #               if p[0] == prj and p[1] == os then
-       #                       return
-       #               end
-       #       end
-       #       # if not, add it
-       #       @rev_fail_projects.push [prj,os]
-       #end
-
-
-       ## remove [project,os] from reverse fail project list
-       #def remove_rev_fail_project( prj, os )
-       #       remove_list = []
-
-       #       # check project and os name
-       #       @rev_fail_projects.each do |p|
-       #               if p[0] == prj and p[1] == os then
-       #                       remove_list.push p
-       #               end
-       #       end
-
-       #       # remove
-       #       remove_list.each do |r|
-       #               @rev_fail_projects.delete r
-       #       end
-       #end
-
-
        # get project that my job is dependent on
        def get_build_dependent_projects()
                if @build_dep_prjs.nil? then
@@ -509,16 +461,10 @@ class BuildJob < CommonJob
        def get_log_url()
                # only when server support log url
                if @server.job_log_url.empty? then
-                       return "",""
+                       return ""
                end
 
-               url = "#{@server.job_log_url}/#{@id}/log"
-               # if remote, the file existence must be checked
-               if File.exist? "#{@job_root}/remote_log" then
-                       return url,"#{@server.job_log_url}/#{@id}/remote_log"
-               else
-                       return url,""
-               end
+               return "#{@server.job_log_url}/#{@id}/log"
        end
 
 
@@ -531,46 +477,35 @@ class BuildJob < CommonJob
        protected
        def job_main()
                @log.info( "Invoking a thread for building Job #{@id}", Log::LV_USER)
-               if @status == "ERROR" then return end
                @log.info( "New Job #{@id} is started", Log::LV_USER)
 
                # checking build dependency
-               if not @is_remote_job and not @is_internal_job and
-                       not check_build_dependency() then
-                       if @is_internal_job then copy_result_files_to_master() end
-                       @status = "ERROR"
-                       return false
+               if not @is_remote_job and not @is_verified then
+                       check_build_dependency()
                end
 
                # clean build
-               if not build() then
-                       if @is_internal_job then copy_result_files_to_master() end
-
-                       @status = "ERROR"
-                       return false
-               end
+               build()
 
                lock_event
 
+               if not @parent.nil? and not @is_rev_build_check_job then
+                       copy_result_files(@parent.source_path)
+               end
+
                # upload
-               if not @is_rev_build_check_job and not @is_internal_job and
-                       @parent.nil? and
-                       not upload() then
-                       @status = "ERROR"
-                       return false
+               if not @is_rev_build_check_job and not @send_result_back and @parent.nil? then
+                       upload()
                end
 
                # copy result files to transport path
-               if @is_internal_job then
+               if @send_result_back and not @is_rev_build_check_job then
                        copy_result_files_to_master()
-               elsif not @parent.nil? and not @is_rev_build_check_job then
-                       copy_result_files(@parent.source_path)
                end
 
                # INFO. don't change this string
                @log.info( "Job is completed!", Log::LV_USER)
                @status = "FINISHED"
-               return true
        end
 
 
@@ -581,13 +516,10 @@ class BuildJob < CommonJob
                # check if version is same and source_info is different
                ver_local = @pkginfo.packages[0].version
                old_source_info = @project.get_source_info( ver_local )
-               if not old_source_info.nil? and old_source_info != source_info then
-                       @log.error( "Source code has been changed without increasing version!", Log::LV_USER)
-                       @log.error( " * Version : #{ver_local}", Log::LV_USER)
-                       @log.error( " * Before  : #{old_source_info}", Log::LV_USER)
-                       @log.error( " * Current : #{source_info}", Log::LV_USER)
+               if ( not @force_rebuild and 
+                        not old_source_info.nil? and old_source_info != source_info ) then
 
-                       return false
+                       raise BuildServerException.new("ERR106"), "#{ver_local}"
                end
 
                # compare with package version in package server
@@ -598,10 +530,11 @@ class BuildJob < CommonJob
                        if ver_svr.nil? then next end
 
                        # compare version
-                       if Version.new(ver_local) < Version.new(ver_svr) or
-                               ( not @force_rebuild and Version.new(ver_local) == Version.new(ver_svr) )  then
-                               @log.error( "Version must be increased : #{ver_local} <= #{ver_svr}", Log::LV_USER)
-                               return false
+                       if ( not @force_rebuild and 
+                               ( Version.new(ver_local) < Version.new(ver_svr) or
+                                 Version.new(ver_local) == Version.new(ver_svr) ) ) then
+
+                               raise BuildServerException.new("ERR105"), "#{ver_local} <= #{ver_svr}"
                        end
                end
 
@@ -657,69 +590,28 @@ class BuildJob < CommonJob
 
                # unmet dependencies found , report the errors
                if not unmet_bdeps.empty? or not unmet_ideps.empty? then
-                       @log.error( "Unmet dependency found!", Log::LV_USER)
+                       unmet_pkgs = []
                        unmet_bdeps.each do  |d|
                                os = (d.target_os_list.empty?) ? @os : d.target_os_list[0]
-                               @log.error( " * #{d.package_name}(#{os}) for build-dependency", Log::LV_USER)
+                               unmet_pkgs.push "#{d.package_name}(#{os})"
                        end
                        unmet_ideps.each do  |d|
                                os = (d.target_os_list.empty?) ? @os : d.target_os_list[0]
-                               @log.error( " * #{d.package_name}(#{os}) for install-dependency", Log::LV_USER)
+                               unmet_pkgs.push "#{d.package_name}(#{os})"
                        end
-
-                       return false
-               else
-                       return true
+                       unmet_pkgs.uniq!
+                       raise BuildServerException.new("ERR200"), unmet_pkgs.join(",")
                end
        end
 
 
        # build clean
        def     build()
-
-               ## check there are pending packages which wait for me
-               ## it will return nil if not exist
-               ## this process must be skip if it is sub-job
-               #if not @is_rev_build_check_job and not @is_internal_job then
-               #       @server.cancel_lock.synchronize do
-               #               @pending_ancestor = get_pending_ancestor_job()
-               #       end
-               #end
-
-               #if not @pending_ancestor.nil? then
-               #       # resolve other pending job
-               #       resolve()
-               #elsif @resolve then
-               #       # wait for being resolved by other jobs
-               #       # this condition must be placed after checking pending status
-               #       wait_resolve()
-               #else
-               #       # build
-               #       build_normal()
-               #end
-
                # build
                build_normal()
        end
 
 
-       ## return pending job that wait for me
-       #def get_pending_ancestor_job()
-       #       @server.jobmgr.get_pending_jobs.each do |job|
-       #               # must have same distribution
-       #               if get_distribution_name() != job.get_distribution_name() then
-       #                       next
-       #               end
-
-       #               if job.is_rev_fail_project(@project,@os) then
-       #                       return job
-       #               end
-       #       end
-
-       #       return nil
-       #end
-
-
        # check whether build this job or not
        # if not build, then return its compat pkgs list
        def check_compatable_packages
@@ -769,7 +661,7 @@ class BuildJob < CommonJob
 
                # create builder
                if @is_remote_job then
-                       builder = RemoteBuilder.new("JB#{@id}", @remote_server, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd)
+                       builder = RemoteBuilder.create_from_server(@remote_server, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd)
                        @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
                        @log.info( " - Remote Server : #{@remote_server.ip}:#{@remote_server.port}" )
                        if not @server.ftp_addr.nil? then
@@ -778,9 +670,8 @@ class BuildJob < CommonJob
                else
                        builder = Builder.create( "JB#{@id}", @pkgsvr_url, nil,
                                                                         "#{@buildroot_dir}", @server.build_cache_dir )
-                       if builder.nil?
-                               @log.error( "Creating job builder failed", Log::LV_USER)
-                               return false
+                       if builder.nil? then
+                               raise BuildServerException.new("ERR201")
                        end
                        @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
                        @log.info( " - Package Server : #{@pkgsvr_url}" )
@@ -815,7 +706,7 @@ class BuildJob < CommonJob
                                        base_package_name= File.basename(local_path, "#{cos}#{ext}")
                                        @log.info( "Copying compatible package:#{local_path}", Log::LV_USER)
                                        @log.info( "Creating package file ... #{base_package_name}#{@os}#{ext}", Log::LV_USER)
-                                       FileUtils.cp local_path, "#{@source_path}/#{base_package_name}#{@os}#{ext}"
+                                       FileUtils.ln local_path, "#{@source_path}/#{base_package_name}#{@os}#{ext}", :force => true
                                else
                                        @log.info( "Downloading compatible package:#{pkg_name}(#{cos})", Log::LV_USER)
                                        loc = @pkgsvr_client.download(pkg_name, cos, false)
@@ -839,220 +730,54 @@ class BuildJob < CommonJob
                        # build
                        if @is_remote_job then
                                result = builder.build_job(self, local_pkgs)
+                               # if remote build finishes, remove job from remote server
+                               get_remote_server().remove_working_job(self)
+                               get_remote_server().update_db()
                        else
                                result =  builder.build_job(self, use_clean, local_pkgs, false )
                        end
                        if not result then
-                               @log.error( "Building job failed", Log::LV_USER)
-                               write_log_url()
-                               return false
+                               raise BuildServerException.new("ERR202")
                        end
                end
 
                # check reverse dependecy if not sub jobs
+               if not @no_reverse and not @is_rev_build_check_job and not @is_verified and 
+                       not ReverseBuildChecker.check( self, true ).empty? then
 
-               if not @no_reverse then
-                       if not @is_rev_build_check_job and not @is_internal_job and
-                               not ReverseBuildChecker.check( self, true ).empty? then
-                               @log.error( "Reverse-build-check failed!" )
-                               return false
-                       end
+                       raise BuildServerException.new("ERR203")
                end
-
-               return true
        end
 
 
-       ## wait to be resolved by other jobs
-       #def wait_resolve()
-       #       @log.info( "Started to build this job and wait for being resolved...", Log::LV_USER)
-
-       #       # create builder
-       #       if @is_remote_job then
-       #               builder = RemoteBuilder.new("JB#{@id}", @remote_server, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd)
-       #               @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
-       #               @log.info( " - Remote Server : #{@remote_server.ip}:#{@remote_server.port}" )
-       #               if not @server.ftp_addr.nil? then
-       #                       @log.info( " - FTP Server : #{@server.ftp_addr}" )
-       #               end
-       #       else
-       #               builder = Builder.create( "JB#{@id}", @pkgsvr_url, nil,
-       #                                                                "#{@buildroot_dir}/#{@os}", @server.build_cache_dir )
-       #               if builder.nil?
-       #                       @log.error( "Creating job builder failed", Log::LV_USER)
-       #                       return false
-       #               end
-       #               @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
-       #               @log.info( " - Package Server : #{@pkgsvr_url}" )
-       #               @log.info( " - Build Cache Path : #{@server.build_cache_dir}" )
-       #       end
-       #       @log.info( " - Log Path : #{@log.path}" )
-
-       #       # build
-       #       if @is_remote_job then
-       #               result = builder.build_job(self, [])
-       #       else
-       #               result =  builder.build_job(self, true, [], false )
-       #       end
-       #       if not result then
-       #               @log.error( "Building job failed", Log::LV_USER)
-       #               write_log_url()
-       #               return false
-       #       end
-
-       #       # check reverse dependecy
-       #       @rev_fail_projects = ReverseBuildChecker.check(self, false)
-       #       if @rev_fail_projects.empty? then
-       #               # if no problem?, it OK
-       #               return true
-       #       end
-
-       #       # pending
-       #       @status = "PENDING"
-       #       @log.info( "Entered the PENDING state ...", Log::LV_USER)
-       #       old_msg = ""
-       #       while @status == "PENDING"
-       #               new_msg = @rev_fail_projects.map {|p| "#{p[0].name}(#{p[1]})"}.join(", ")
-       #               if old_msg != new_msg then
-       #                       @log.error( " * Waiting for building next projects: #{new_msg}", Log::LV_USER)
-       #                       old_msg = new_msg
-       #               end
-       #               sleep 1
-       #       end
-
-       #       return true
-       #end
-
-
-       ## resolve other pending job
-       #def    resolve()
-
-       #       # wait for other build-dependent projects are resolved
-       #       old_msg = ""
-       #       wait_prjs = @pending_ancestor.rev_fail_projects.select {|p| is_build_dependent_project(p[0], p[1])}
-       #       @log.info("Checking build dependency before RESOLVE", Log::LV_USER)
-       #       while not wait_prjs.empty?
-       #               @status = "PENDING"
-       #               new_msg = wait_prjs.map {|p| "#{p[0].name}(#{p[1]})"}.join(", ")
-       #               if new_msg != old_msg then
-       #                       @log.info(" * Waiting for building next projects: #{new_msg}", Log::LV_USER)
-       #                       old_msg = new_msg
-       #               end
-       #               sleep 1
-       #               wait_prjs = @pending_ancestor.rev_fail_projects.select {|p| is_build_dependent_project(p[0], p[1])}
-       #       end
-
-       #       # return back to "WORKING"
-       #       @status = "WORKING"
-
-       #       @log.info( "Started to build this job and resolve other pending job...", Log::LV_USER)
-
-       #       # create builder
-       #       if @is_remote_job then
-       #               builder = RemoteBuilder.new("JB#{@id}", @remote_server, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd)
-       #               @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
-       #               @log.info( " - Remote Server : #{@remote_server.ip}:#{@remote_server.port}" )
-       #               if not @server.ftp_addr.nil? then
-       #                       @log.info( " - FTP Server : #{@server.ftp_addr}" )
-       #               end
-       #       else
-       #               builder = Builder.create( "JB#{@id}", @pkgsvr_url, nil,
-       #                                                                "#{@buildroot_dir}/#{@os}", @server.build_cache_dir )
-       #               if builder.nil?
-       #                       @log.error( "Creating job builder failed", Log::LV_USER)
-       #                       return false
-       #               end
-       #               @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
-       #               @log.info( " - Package Server : #{@pkgsvr_url}" )
-       #               @log.info( " - Build Cache Path : #{@server.build_cache_dir}" )
-       #       end
-       #       @log.info( " - Log Path : #{@log.path}" )
-
-       #       # get local packages to overwite
-       #       # they must be composed of packages of pending jobs and its success list
-       #       local_pkgs=[]
-       #       local_pkgs += @external_pkgs
-       #       src_path = @pending_ancestor.source_path
-       #       ver = @pending_ancestor.pkginfo.get_version()
-       #       @pending_ancestor.pkginfo.get_target_packages(@os).each do |pkg|
-       #               local_pkgs.push "#{src_path}/#{pkg.package_name}_#{ver}_#{@os}.zip"
-       #       end
-       #       @pending_ancestor.rev_success_jobs.each do |job|
-       #               src_path = job.source_path
-       #               ver = job.pkginfo.get_version()
-       #               job.pkginfo.get_target_packages(@os).each do |pkg|
-       #                       local_pkgs.push "#{src_path}/#{pkg.package_name}_#{ver}_#{@os}.zip"
-       #               end
-       #       end
-
-       #       # build
-       #       if @is_remote_job then
-       #               result = builder.build_job(self, local_pkgs)
-       #       else
-       #               result = builder.build_job(self, true, local_pkgs, false )
-       #       end
-       #       if not result then
-       #               @log.error( "Building job failed", Log::LV_USER)
-       #               write_log_url()
-       #               return false
-       #       end
-
-       #       # check reverse dependecy and update parent rev_fail_project list
-       #       new_fail_projects = ReverseBuildChecker.check(self, false)
-       #       new_fail_projects.each do |p|
-       #               @pending_ancestor.add_rev_fail_project(p[0], p[1])
-       #       end
-
-       #       # update the status of pending job
-       #       @status = "PENDING"
-       #       @pending_ancestor.remove_rev_fail_project(@project, @os)
-       #       @pending_ancestor.rev_success_jobs.push self
-       #       if @pending_ancestor.rev_fail_projects.empty? then
-       #               @pending_ancestor.status = "RESOLVED"
-       #               @pending_ancestor.rev_success_jobs.each do |job|
-       #                       job.status = "RESOLVED"
-       #               end
-       #       else
-       #               @log.info( "Entered the PENDING state ...", Log::LV_USER)
-       #               old_msg = ""
-       #               while @status == "PENDING"
-       #                       new_msg = @pending_ancestor.rev_fail_projects.map {|p| "#{p[0].name}(#{p[1]})"}.join(", ")
-
-       #                       if new_msg != old_msg then
-       #                               @log.info(" * Waiting for building next projects: #{new_msg}", Log::LV_USER)
-       #                               old_msg = new_msg
-       #                       end
-
-       #                       sleep 1
-       #               end
-       #       end
-
-       #       return true
-       #end
-
-
        def upload()
-               @log.info( "Uploading ...", Log::LV_USER)
+               begin
+                       add_timestamp("UPLOAD_START")
+                       @log.info( "Uploading ...", Log::LV_USER)
 
-               # get package path list
-               binpkg_path_list = Dir.glob("#{@source_path}/*_*_#{@os}.zip")
+                       # get package path list
+                       binpkg_path_list = Dir.glob("#{@source_path}/*_*_#{@os}.zip")
 
-               # upload
-               u_client = Client.new( @pkgsvr_url, nil, @log )
-               snapshot = u_client.upload( @pkgsvr_ip, @pkgsvr_port, binpkg_path_list, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd, @pkgsvr_password)
+                       # upload
+                       u_client = Client.create( @pkgsvr_url, nil, @log )
+                       if u_client.nil? then 
+                               raise BuildServerException.new("ERR023") 
+                       end
 
-               if snapshot.nil? then
-                       @log.info( "Upload failed...", Log::LV_USER)
+                       snapshot = u_client.upload( @pkgsvr_ip, @pkgsvr_port, binpkg_path_list, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd, @pkgsvr_password)
 
-                       return false
-               end
+                       if snapshot.nil? then
+                               raise BuildServerException.new("ERR204")
+                       end
 
-               # update local
-               @log.info( "Upload succeeded. Sync local pkg-server again...", Log::LV_USER)
-               @pkgsvr_client.update
-               @log.info("Snapshot: #{snapshot}", Log::LV_USER)
+                       # update local
+                       @log.info( "Upload succeeded. Sync local pkg-server again...", Log::LV_USER)
+                       @pkgsvr_client.update
+                       @log.info("Snapshot: #{snapshot}", Log::LV_USER)
 
-               return true
+               ensure
+                       add_timestamp("UPLOAD_END")
+               end
        end
 
 
@@ -1063,28 +788,22 @@ class BuildJob < CommonJob
                binpkg_path_list = Dir.glob("#{@source_path}/*_*_#{@os}.zip")
 
                binpkg_path_list.each do |file|
+                       @result_files.push File.basename(file)
                        @log.info( " * #{file}", Log::LV_USER)
-                       FileUtils.cp(file,"#{dst_path}/")
+                       FileUtils.ln(file,"#{dst_path}/", :force => true)
                end
-
-               return true
        end
 
 
        # copy binary package files and log file to transport dir
        def copy_result_files_to_master()
                outgoing_dir = "#{@server.transport_path}/#{@dock_num}"
-
-               @log.info( "Copying log to #{outgoing_dir}", Log::LV_USER)
-               file = "#{@source_path}/../log"
-               FileUtils.copy_file(file, "#{outgoing_dir}/remote_log")
-
-               # copy result files, if not reverse build
-               if not @is_rev_build_check_job then
-                       return copy_result_files( outgoing_dir )
-               else
-                       return true
+               if not File.exist? outgoing_dir then
+                       FileUtils.mkdir_p outgoing_dir
                end
+
+               # copy result files
+               copy_result_files( outgoing_dir )
        end
 
 
@@ -1179,19 +898,6 @@ class BuildJob < CommonJob
        end
 
 
-       # write web url for log
-       protected
-       def write_log_url()
-               url,remote_url = get_log_url()
-               if not url.empty? then
-                       @log.info( " ** Log1: #{url}", Log::LV_USER)
-               end
-               if not remote_url.empty? then
-                       @log.info( " ** Log2: #{remote_url}", Log::LV_USER)
-               end
-       end
-
-
        # get target os of dependency
        protected
        def get_os_of_dependency(dep)
index 38e4bb7..0f7a3e9 100644 (file)
@@ -30,6 +30,8 @@ require 'rubygems'
 require 'fileutils'
 require 'dbi'
 require 'thread'
+require 'bcrypt'
+require 'file/tail'
 $LOAD_PATH.unshift File.dirname(__FILE__)
 $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
 require "SocketJobRequestListener.rb"
@@ -40,11 +42,13 @@ require "PackageSync.rb"
 require "ProjectManager.rb"
 require "DistributionManager.rb"
 require "db_utils.rb"
+require "FileUtil"
 
 class BuildServer
        attr_accessor :id, :path, :status, :host_os, :log
        attr_accessor :remote_servers
        attr_accessor :git_server_url, :git_bin_path
+       attr_accessor :config_port
        attr_accessor :allowed_git_branch
        attr_accessor :jobmgr
        attr_accessor :test_time
@@ -69,9 +73,12 @@ class BuildServer
        def initialize (id, path, ftpsvr_addr, ftpsvr_port, ftpsvr_username, ftpsvr_passwd)
                @id = id
                @path = path
+               @run_file_path = File.join(BuildServer::CONFIG_ROOT, @id, "run") 
                @remote_servers = []
                @req_listener = []
                @finish = false
+               @running_port = nil
+               @config_port = nil
                # status
                @status = "INITIALIZING"
                # host_os
@@ -102,14 +109,17 @@ class BuildServer
 
                #DB settring
                @db = nil
-               @db_dsn = "SQLite3:#{BuildServer::CONFIG_ROOT}/#{@id}/server.db"
+               @db_dsn = nil
                @db_user = nil
                @db_passwd = nil
-               @db_version = 2
+               @db_version = 5
                @sqlite3_db_mutex = Mutex.new
 
                #DB upgrade SQL command
                @db_migrate = []
+
+               @latest_job_id = nil
+               @job_id_mutex = Mutex.new
        end
 
        def send_mail
@@ -122,7 +132,7 @@ class BuildServer
 
        def send_mail=(mail)
                get_db_connection() do |db|
-                       db.do "UPDATE server_configs SET value = '#{mail}' WHERE property = 'send_mail'"
+                       db.do "UPDATE server_configs SET value = '#{mail.strip}' WHERE property = 'send_mail'"
                end
        end
 
@@ -179,21 +189,34 @@ class BuildServer
 
        def job_log_url=(url)
                get_db_connection() do |db|
-                       db.do "UPDATE server_configs SET value = '#{url}' WHERE property = 'job_log_url'"
+                       db.do "UPDATE server_configs SET value = '#{url.strip}' WHERE property = 'job_log_url'"
                end
        end
 
+
        def port
-               result = nil
+               return @running_port
+       end
+
+
+       def port=(svr_port)
+               @running_port = svr_port
+               if has_db? then
+                       get_db_connection() do |db|
+                               db.do "UPDATE server_configs SET value = '#{svr_port}' WHERE property = 'port'"
+                       end
+               end
+       end
+
+       def save_id_to_db(id)
                get_db_connection() do |db|
-                       result = db.select_one("SELECT value FROM server_configs WHERE property = 'port'")[0]
+                       db.do "UPDATE server_configs SET value = '#{id.strip}' WHERE property = 'id'"
                end
-               return (result.nil?) ? "" : result
        end
 
-       def port=(svr_port)
+       def save_path_to_db(path)
                get_db_connection() do |db|
-                       db.do "UPDATE server_configs SET value = '#{svr_port}' WHERE property = 'port'"
+                       db.do "UPDATE server_configs SET value = '#{path.strip}' WHERE property = 'path'"
                end
        end
 
@@ -210,9 +233,15 @@ class BuildServer
        end
 
        def db_insert_id(db)
-               return (@db_dsn =~ /^Mysql/i) ? db.func(:insert_id) : db.select_one("SELECT last_insert_rowid()")[0]
+               return (@db_dsn =~ /^Mysql/i) ? db.func(:insert_id).to_s : db.select_one("SELECT last_insert_rowid()")[0]
+       end
+
+
+       def has_db?()
+               return (not @db_dsn.nil?)
        end
 
+
        # start server daemon
        def start
                # set build cache dir
@@ -221,8 +250,23 @@ class BuildServer
                        FileUtils.mkdir_p @build_cache_dir
                end
 
+               # init job directory if needed
+               if not File.exist? "#{@path}/jobs" then FileUtils.mkdir_p "#{@path}/jobs" end
+               
                # init transport path
                if not File.exist? @transport_path then FileUtils.mkdir_p @transport_path end
+                 
+               #lock the build server. Do not run the same server at the same time
+               if not lockServer() then
+                       printErrorMessage("Server \"#{id}\" is already running.")    
+                       return
+               end
+  
+               #check that the port is open
+               if BuildCommServer.port_open? port then
+                       printErrorMessage("Port \"#{port}\" is already in use.")    
+                       return
+               end
 
                # init project mgr
                @log.info "Setting Project Manager..."
@@ -243,18 +287,29 @@ class BuildServer
                @cleaner =  JobCleaner.new(self)
                @cleaner.start
 
+               # init latest job id
+               if has_db? then
+                       @latest_job_id = get_latest_job_id_from_db()
+               else
+                       @latest_job_id = get_latest_job_id_from_directory()
+               end
+
                # set package server synchrontizer
                @log.info "Setting Package Server Synchronizer..."
-               @pkg_sync =  PackageServerSynchronizer.new(self)
-               @pkg_sync.start
-
+               if has_db? then
+                       @pkg_sync =  PackageServerSynchronizer.new(self)
+                       @pkg_sync.start
+               end
+               
                # update friend server status
                @log.info "Initializing Remote Servers..."
-               @remote_servers = get_remote_servers()
-               @remote_servers.each do |server|
-                       server.create_system_monitor()
+               if has_db? then
+                       @remote_servers = get_remote_servers()
+                       @remote_servers.each do |server|
+                               server.create_system_monitor()
+                       end
                end
-
+               
                # main loop
                @log.info "Entering main loop..."
                @status = "RUNNING"
@@ -367,8 +422,8 @@ class BuildServer
                        row = db.select_one("SELECT distributions.id FROM sync_pkg_servers,distributions WHERE sync_pkg_servers.pkgsvr_url='#{url}' and distributions.name='#{dist}' and sync_pkg_servers.distribution_id = distributions.id")
                        if not row.nil? then return false end
                        row = db.select_one("SELECT id FROM distributions WHERE name='#{dist}'")
-                       dist_id = row['id'];
-                       db.do "INSERT INTO sync_pkg_servers (pkgsvr_url,period,distribution_id) VALUES('#{url}','#{@pkg_sync_period}',#{dist_id})"
+                       dist_id = row['id']
+                       db.do "INSERT INTO sync_pkg_servers (pkgsvr_url,period,distribution_id) VALUES('#{url}',600,#{dist_id})"
                end
 
                return true
@@ -380,7 +435,7 @@ class BuildServer
                get_db_connection() do |db|
                        row = db.select_one("SELECT distributions.id FROM sync_pkg_servers,distributions WHERE sync_pkg_servers.pkgsvr_url='#{url}' and distributions.name='#{dist}' and sync_pkg_servers.distribution_id = distributions.id")
                        if row.nil? then return false end
-                       dist_id = row['id'];
+                       dist_id = row['id']
                        db.do("DELETE FROM sync_pkg_servers WHERE pkgsvr_url='#{url}' and distribution_id=#{dist_id}")
                end
 
@@ -453,8 +508,14 @@ class BuildServer
                end
 
                # get availables server
-               # but, job must not be "REGISTER" and "MULTIBUILD" job
-               if job.type != "REGISTER" and job.type != "MULTIBUILD" then
+               if job.type == "MULTIBUILD" or job.type == "REGISTER" then
+                       # if max working job is zero, check max-non-build-jobs
+                       if @jobmgr.max_working_jobs == 0 and 
+                               local_empty_rooms >= -1 * @jobmgr.get_max_jobs() then
+                               candidates.push self
+                       end
+               else
+                       # if normal JOB
                        @remote_servers.each do |server|
                                if ( server.status == "RUNNING" and server.can_build?( job ) and
                                        not server.has_waiting_jobs and
@@ -465,11 +526,11 @@ class BuildServer
                        end
                end
 
-               best_server = candidates[0]
-               if best_server.nil? or candidates.count == 1 then return best_server end
+               if candidates.count == 0 then return nil end
 
                # get best
                # it is better if working jobs count is less
+               best_server = candidates[0]
                max_empty_room = best_server.get_number_of_empty_room
                candidates.each do |server|
                        # check whether idle, use it
@@ -572,8 +633,22 @@ class BuildServer
                if @db_dsn =~ /^Mysql/i then
                        @db_migrate[1]=["ALTER TABLE jobs CHANGE COLUMN id  id INTEGER AUTO_INCREMENT NOT NULL", 
                                                        "ALTER TABLE distributions ADD pkgsvr_password VARCHAR(64)"]
+                       @db_migrate[2]=["ALTER TABLE projects ADD COLUMN status VARCHAR(32) NOT NULL DEFAULT 'OPEN'"]
+                       @db_migrate[3]=["CREATE TABLE job_timestamps (id INTEGER PRIMARY KEY #{db_inc()}, job_id INTEGER, stamp_name VARCHAR(64), stamp_time DATETIME)#{db_post_fix()}",
+                                                       "ALTER TABLE jobs ADD COLUMN error_code VARCHAR(32)",
+                                                       "INSERT INTO users (name,email,password_hash,password_salt) VALUES ('sync-manager','sync-manager@user','$2a$10$H.w3ssI9KfuvNEXXp1qxD.b3Wm8alJG.HXviUofe4nErDn.TKUAka','$2a$10$H.w3ssI9KfuvNEXXp1qxD.')",
+                                                       "INSERT INTO user_groups (user_id, group_id) SELECT users.id,groups.id FROM users,groups WHERE users.email = 'sync-manager@user' and groups.name = 'admin'",
+                                                       "INSERT INTO server_configs (property,value) VALUES ('max_jobs','4')"]
+                       @db_migrate[4]=["ALTER TABLE projects DROP COLUMN password"]
                else
                        @db_migrate[1]=["ALTER TABLE distributions ADD pkgsvr_password VARCHAR(64)"]
+                       @db_migrate[2]=["ALTER TABLE projects ADD COLUMN status VARCHAR(32) NOT NULL DEFAULT 'OPEN'"]
+                       @db_migrate[3]=["CREATE TABLE job_timestamps (id INTEGER PRIMARY KEY #{db_inc()}, job_id INTEGER, stamp_name VARCHAR(64), stamp_time DATETIME)#{db_post_fix()}",
+                                                       "ALTER TABLE jobs ADD COLUMN error_code VARCHAR(32)",
+                                                       "INSERT INTO users (name,email,password_hash,password_salt) VALUES ('sync-manager','sync-manager@user','$2a$10$H.w3ssI9KfuvNEXXp1qxD.b3Wm8alJG.HXviUofe4nErDn.TKUAka','$2a$10$H.w3ssI9KfuvNEXXp1qxD.')",
+                                                       "INSERT INTO user_groups (user_id, group_id) SELECT users.id,groups.id FROM users,groups WHERE users.email = 'sync-manager@user' and groups.name = 'admin'",
+                                                       "INSERT INTO server_configs (property,value) VALUES ('max_jobs','4')"]
+                       @db_migrate[4]=["ALTER TABLE projects DROP COLUMN password"]
                end
        end
 
@@ -622,6 +697,7 @@ class BuildServer
                        db.do "INSERT INTO server_configs (property,value) VALUES ('db_version','#{@db_version}')"
                        db.do "INSERT INTO server_configs (property,value) VALUES ('port','2222')"
                        db.do "INSERT INTO server_configs (property,value) VALUES ('max_working_jobs','2')"
+                       db.do "INSERT INTO server_configs (property,value) VALUES ('max_jobs','4')"
                        db.do "INSERT INTO server_configs (property,value) VALUES ('send_mail','NO')"
                        db.do "INSERT INTO server_configs (property,value) VALUES ('keep_time','86400')"
                        db.do "INSERT INTO server_configs (property,value) VALUES ('pkg_sync_period','600')"
@@ -662,8 +738,10 @@ class BuildServer
                                        CONSTRAINT fk_users_has_groups_groups1 FOREIGN KEY ( group_id ) REFERENCES groups ( id )) #{post_fix}"
 
                        db.do "INSERT INTO users (name,email,password_hash,password_salt) VALUES ('administrators','admin@user','$2a$10$H.w3ssI9KfuvNEXXp1qxD.b3Wm8alJG.HXviUofe4nErDn.TKUAka','$2a$10$H.w3ssI9KfuvNEXXp1qxD.')"
+                       db.do "INSERT INTO users (name,email,password_hash,password_salt) VALUES ('sync-mananger','sync-manager@user','$2a$10$H.w3ssI9KfuvNEXXp1qxD.b3Wm8alJG.HXviUofe4nErDn.TKUAka','$2a$10$H.w3ssI9KfuvNEXXp1qxD.')"
                        db.do "INSERT INTO groups (name, admin, description) VALUES ('admin','TRUE','')"
                        db.do "INSERT INTO user_groups (user_id, group_id) SELECT users.id,groups.id FROM users,groups WHERE users.email = 'admin@user' and groups.name = 'admin'"
+                       db.do "INSERT INTO user_groups (user_id, group_id) SELECT users.id,groups.id FROM users,groups WHERE users.email = 'sync-manager@user' and groups.name = 'admin'"
 
                        # PROJECTS
                        CommonProject.create_table(db, inc, post_fix)
@@ -687,7 +765,9 @@ class BuildServer
 
        def get_db_connection(transaction=true)
                begin
-                       if @db_dsn =~ /^SQLite3:/ then
+                       if @db_dsn.nil? then
+                               return false
+                       elsif @db_dsn =~ /^SQLite3:/ then
                                @sqlite3_db_mutex.lock
                                @db = DBI.connect("DBI:#{@db_dsn}", @db_user, @db_passwd)
                        else
@@ -695,17 +775,10 @@ class BuildServer
                                        @db = DBI.connect("DBI:#{@db_dsn}", @db_user, @db_passwd)
                                end
                        end
-                       if transaction then
-                               @db['AutoCommit'] = false
-                               begin
-                                       @db.transaction do |dbh|
-                                               yield dbh if block_given?
-                                       end
-                               ensure
-                                       @db['AutoCommit'] = true
-                               end
-                       else
-                               yield @db if block_given?
+
+                       @db['AutoCommit'] = false
+                       @db.transaction do |dbh|
+                               yield dbh if block_given?
                        end
 
                        return true
@@ -753,6 +826,24 @@ class BuildServer
                return -1
        end
 
+       def check_user_password(user_id, passwd)
+               get_db_connection() do |db|
+                       row = db.select_one("SELECT * FROM users WHERE id='#{user_id}'")
+                       if not row.nil?  then
+                               if row['password_hash'].eql? passwd
+                                       # if passwd is encript and that value equal password_hash then return true
+                                       return 1
+                               else
+                                       return row['password_hash'] == BCrypt::Engine.hash_secret(passwd, row['password_salt'])
+                               end
+                       else
+                               return -1
+                       end
+               end
+
+               return -1
+       end
+
 
        def qualify_admin_to_access(prj_id)
                # nothing to do, admin can change everything on web admin tool
@@ -777,5 +868,138 @@ class BuildServer
                        end
                end
        end
+
+       def query_job_log(job_number, conn)
+               @log.info "Sending job log : #{job_number}"
+
+               job_status = ""
+               job = @jobmgr.search_job(job_number)
+
+               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.interval = 0.05
+                                               # send log file information using file-tail
+                                               log.tail do |line| 
+                                                       BuildCommServer.send(conn, line) 
+
+                                                       if not job.nil? then
+                                                               # Send status when changed status
+                                                               if not job.status.eql? job_status then
+                                                                       job_status = job.status
+                                                                       BuildCommServer.send(conn, "=JOB_STATUS,#{job_status}")
+                                                               end
+
+                                                               if not log.return_if_eof and 
+                                                                       (job.status.eql? "FINISHED" or job.status.eql? "ERROR" or job.status.eql? "CANCELED") then
+
+                                                                       log.return_if_eof = true
+                                                                       # this will make a time for finishing log write
+                                                                       sleep 2
+                                                               end
+                                                       else
+                                                               if log.eof? then
+                                                                       break
+                                                               end
+                                                       end
+                                               end
+                                       end
+                                       if not job.nil? and job.status == "FINISHED" and job.is_send_result_back? then
+                                               job.get_result_files().each do |file|
+                                                       BuildCommServer.send(conn, "=JOB_FILE,#{file}")
+                                               end
+                                       end
+                               rescue => e
+                                       @log.error e.message
+                                       @log.error e.backtrace.inspect
+                                       if e.message.eql? "Connection is closed" then
+                                               BuildCommServer.disconnect(conn)
+                                               Thread.exit
+                                       end
+                               end
+                       else
+                               @log.error "Can't find job log file : #{job_log_path}"
+                               BuildCommServer.send(conn, "Can't find job log file : #{job_number}")
+                               BuildCommServer.send(conn, "=LOG_ERROR")
+                       end
+
+                       if job.nil? then 
+                               get_db_connection() do |db|
+                                       job_status = db.select_one("SELECT status FROM jobs WHERE id = #{job_number}")[0]
+                               end
+                               BuildCommServer.send(conn, "=JOB_STATUS,#{job_status}")
+                       end
+
+                       BuildCommServer.send_end(conn)
+                       BuildCommServer.disconnect(conn)
+               end
+
+
+       end
+
+
+       public
+       def get_next_job_id()
+               @job_id_mutex.synchronize do
+                       tmp_id = @latest_job_id.to_i + 1
+                       @latest_job_id = tmp_id.to_s
+
+                       return @latest_job_id
+               end
+       end
+       
+  #If the 'run' file is already locked, server is already running. 
+  #in this case return false 
+  private
+  def lockServer
+    return FileUtil.exclusiveLock(@run_file_path) 
+  end
+    
+  private 
+  def printErrorMessage(errMsg)
+    @log.info "Server creation failed"
+    @log.error errMsg
+    
+    puts "Server creation failed"
+    puts errMsg
+  end
+
+
+       # get latest id from DB
+       private
+       def get_latest_job_id_from_db()
+               job_id = nil
+               get_db_connection() do |db|
+                       row = db.select_one("SELECT MAX(id) as id FROM jobs")   
+                       job_id = row['id']
+               end 
+
+               if not job_id.nil? then
+                       return job_id.to_s
+               else
+                       return "0"
+               end
+       end     
+
+
+       # get id from "jobs" directory
+       private
+       def get_latest_job_id_from_directory()
+               job_directories = Dir.entries("#{@path}/jobs").select { |dir| 
+                       not dir.start_with? "." and File.directory?("#{@path}/jobs/#{dir}") and dir.to_s =~ /^\d+$/ 
+               }
+               max_id = 0
+               job_directories.each do |job_id|
+                       if job_id.to_i > max_id then
+                               max_id = job_id.to_i
+                       end
+               end
+
+               return max_id.to_s
+       end     
+
 end
 
index 8a79443..de7671a 100644 (file)
@@ -29,6 +29,7 @@ Contributors:
 $LOAD_PATH.unshift File.dirname(__FILE__)
 require "BuildServer.rb"
 require "BuildComm.rb"
+require "BuildServerException.rb"
 
 class BuildServerController
        @@instance_map = {}
@@ -46,12 +47,17 @@ class BuildServerController
 
                # create new instance and return it
                @@instance_map[id] = BuildServer.new( id, path, ftpsvr_addr, ftpsvr_port, ftpsvr_username, ftpsvr_passwd)
+               
                # set default
                if Utils.is_windows_like_os(Utils::HOST_OS) then
                        @@instance_map[id].git_bin_path="/c/Program\\ Files/Git/bin/git.exe"
                else
                        @@instance_map[id].git_bin_path="/usr/bin/git"
                end
+               
+               # set default server port
+               default_port = 2222
+               @@instance_map[id].port = default_port
 
                # write config
                write_server_config( @@instance_map[id] )
@@ -60,6 +66,10 @@ class BuildServerController
                @@instance_map[id].log = Log.new( "#{BuildServer::CONFIG_ROOT}/#{id}/log" )
 
                puts "Created new build server: \"#{id}\""
+               puts " - server location : #{path}"
+               puts " - server configure file : #{BuildServer::CONFIG_ROOT}/#{id}/server.cfg"
+               puts " - default server port : #{default_port}"
+
                return @@instance_map[id]
        end
 
@@ -82,7 +92,11 @@ class BuildServerController
        def self.migrate_server (id, dsn, user, passwd)
                # set DB environment
                server = get_server(id)
-               server.db_dsn = dsn if not dsn.nil?
+               # if dsn is nil, use default dsn
+               if dsn.nil? then
+                       dsn = "SQLite3:#{BuildServer::CONFIG_ROOT}/#{id}/server.db"
+               end     
+               server.db_dsn = dsn
                server.db_user = user if not user.nil?
                server.db_passwd = passwd if not passwd.nil?
 
@@ -122,19 +136,39 @@ class BuildServerController
 
 
        # start server
-       def self.start_server( id, port = 2222 )
+       def self.start_server( id, port )
                server = get_server(id)
-               migrate_db(server)
-               server.jobmgr.cancel_broken_status
 
-               # write run port
+               if server.has_db? then
+                       migrate_db(server)
+                       server.jobmgr.cancel_broken_status
+               end
+
                server_dir = "#{BuildServer::CONFIG_ROOT}/#{server.id}"
-               f = File.open( "#{server_dir}/run", "w" )
-               f.puts port
-               f.close
+
+               # if user input exsist, set user's port number.
+               if (port != "") and (port != nil) then
+                       # update server port information
+                       original_string = "SERVER_PORT=#{server.config_port}"
+                       replacement_string = "SERVER_PORT=#{port}"
+                       contents = File.read("#{server_dir}/server.cfg").gsub("#{original_string}", "#{replacement_string}")
+
+                       # write to config file
+                       File.open("#{server_dir}/server.cfg", "w") { |f| f.puts contents }
+                       # update to db
+                       server.port = port
+               else # if user input not exsist, set config file's port number.
+                       server.port = server.config_port
+               end
+
+               # write run port
+               File.open( "#{server_dir}/run", "w" ) { |f| f.puts server.port }
 
                # start
-               server.port = port
+               if server.has_db? then
+                       server.save_id_to_db(server.id)
+                       server.save_path_to_db(server.path)
+               end
                server.start
        end
 
@@ -144,7 +178,7 @@ class BuildServerController
 
                # server
                server = get_server(id)
-               migrate_db(server)
+
                client = BuildCommClient.create( "127.0.0.1", server.port )
                if client.nil? then
                        puts "Server is not running!"
@@ -178,11 +212,35 @@ class BuildServerController
        end
 
        # upgrade server
-       def self.upgrade_server( id )
+       def self.upgrade_server( id, pkgsvr_url, dist_name )
 
-               # server
                server = get_server(id)
-               migrate_db(server)
+
+               # distribution check
+               if pkgsvr_url.nil? then
+                       if not server.has_db? then 
+                               puts BuildServerException.get_message("ERR021")
+                               return false
+                       end
+
+                       if dist_name.nil? then
+                               dist = server.distmgr.get_first_distribution()
+                               if dist.nil? then
+                                       puts "No distribution exits!"
+                                       puts "Upgrade Failed!!"
+                                       return false
+                               end
+                       else
+                               dist = server.distmgr.get_distribution( dist_name )
+                               if dist.nil? then
+                                       puts "Distribution \"#{dist_name}\" is not exits"
+                                       puts "Upgrade Failed!!"
+                                       return false
+                               end
+                       end
+                       pkgsvr_url = dist.pkgsvr_url
+               end
+
                client = BuildCommClient.create( "127.0.0.1", server.port )
                if client.nil? then
                        puts "Server is not running!"
@@ -191,7 +249,7 @@ class BuildServerController
 
                # send request
                upgrade_ok = false
-               if client.send "UPGRADE|#{server.password}" then
+               if client.send "UPGRADE|#{server.password}|#{pkgsvr_url}" then
                        # recevie & print
                        mismatched = false
                        result = client.read_lines do |l|
@@ -215,62 +273,15 @@ class BuildServerController
                return true
        end
 
-       # request upgrade friends build server
-       def self.request_upgrade_server( id )
-
-               server = get_server(id)
-               migrate_db(server)
-               server_dir = "#{BuildServer::CONFIG_ROOT}/#{id}"
-
-               if File.exist? "#{server_dir}/friends" then
-                       File.open( "#{server_dir}/friends", "r" ) do |f|
-                               f.each_line do |l|
-                                       if l.split(",").count < 2 then next end
-                                       ip = l.split(",")[0].strip
-                                       port = l.split(",")[1].strip
-
-                                       client = BuildCommClient.create( ip, port )
-                                       if client.nil? then
-                                               puts "Friend Server #{ip}:#{port} is not running!"
-                                               next
-                                       end
-                                       # send request
-                                       upgrade_ok = false
-                                       if client.send "UPGRADE|#{server.password}" then
-                                               # recevie & print
-                                               mismatched = false
-                                               result = client.read_lines do |l2|
-                                                       puts l2
-                                                       if l2.include? "Password mismatched!" then
-                                                               mismatched = true
-                                                       end
-                                               end
-                                               if result and not mismatched then
-                                                       upgrade_ok = true
-                                               end
-                                       end
-
-                                       # terminate
-                                       client.terminate
-
-                                       if upgrade_ok then
-                                               puts "Friend Server #{ip}:#{port} upgrade requested!"
-                                       else
-                                               puts "Friend Server #{ip}:#{port} upgrade failed!"
-                                       end
-                               end
-                       end
-               else
-                       puts "No Friend Server."
-               end
-
-               return true
-       end
-
 
        # add friend server
        def self.add_remote_server( id, ip, port )
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # add
@@ -287,6 +298,11 @@ class BuildServerController
        # remove friend server
        def self.remove_remote_server( id, ip, port )
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # add
@@ -302,8 +318,12 @@ class BuildServerController
 
        # add supported target os
        def self.add_target_os( id, os_name )
-               # get server
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # add
@@ -319,8 +339,12 @@ class BuildServerController
 
        # remove supported target os
        def self.remove_target_os( id, os_name )
-               # get server
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # add
@@ -338,8 +362,12 @@ class BuildServerController
 
        # add distribution
        def self.add_distribution( id, dist_name, pkgsvr_url, pkgsvr_ip, pkgsvr_port, pkgsvr_password )
-               # get server
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # add
@@ -355,8 +383,12 @@ class BuildServerController
 
        # remove distribution
        def self.remove_distribution( id, dist_name )
-               # get server
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # remove
@@ -372,8 +404,12 @@ class BuildServerController
 
        # lock distribution
        def self.lock_distribution(id, dist_name)
-               # get server
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # remove
@@ -389,8 +425,12 @@ class BuildServerController
        
        # unlock distribution
        def self.unlock_distribution(id, dist_name)
-               # get server
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # remove
@@ -407,6 +447,11 @@ class BuildServerController
        # add remote package server
        def self.add_sync_package_server(id, url, dist_name)
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # check distribution
@@ -439,6 +484,11 @@ class BuildServerController
        # remove remote package server
        def self.remove_sync_package_server(id, url, dist_name)
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # check distribution
@@ -458,9 +508,13 @@ class BuildServerController
 
        # add project
        def self.add_project( id, project_name, git_repos, git_branch, remote_server_id,
-                                                passwd, os_string, dist_name )
-               # get server
+                                                os_string, dist_name )
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # get supported os for project.
@@ -494,7 +548,7 @@ class BuildServerController
                dist_name = check_distribution_name(dist_name, server)
                if dist_name.nil? then return false end
 
-               result = server.prjmgr.add_git_project( project_name, git_repos, git_branch, passwd, os_list, dist_name )
+               result = server.prjmgr.add_git_project( project_name, git_repos, git_branch, os_list, dist_name )
                if result then
                        puts "Adding project succeeded!"
                        return true
@@ -506,9 +560,13 @@ class BuildServerController
 
 
        # add binary project
-       def self.add_binary_project( id, project_name, pkg_name, passwd, os_string, dist_name )
-               # get server
+       def self.add_binary_project( id, project_name, pkg_name, os_string, dist_name )
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # get supported os for project.
@@ -536,7 +594,7 @@ class BuildServerController
                if dist_name.nil? then return false end
 
                # add
-               result = server.prjmgr.add_binary_project( project_name, pkg_name, passwd,
+               result = server.prjmgr.add_binary_project( project_name, pkg_name, 
                                                                                                  os_list, dist_name )
                if result then
                        puts "Adding project succeeded!"
@@ -550,8 +608,12 @@ class BuildServerController
 
        # remove project
        def self.remove_project( id, project_name, dist_name )
-               # get server
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
 
                # check distribution
@@ -569,57 +631,13 @@ class BuildServerController
        end
 
 
-       # full build
-       def self.build_all_projects( id, dist_name )
-
-               # server
+       def self.register_package(id, file_path, dist_name)
                server = get_server(id)
-               migrate_db(server)
 
-               # check distribution
-               dist_name = check_distribution_name(dist_name, server)
-               if dist_name.nil? then return false end
-
-               client = BuildCommClient.create( "127.0.0.1", server.port )
-               if client.nil? then
-                       puts "Server is not running!"
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
                        return false
                end
-
-               # send request
-               fullbuild_ok = false
-               if client.send "FULLBUILD|#{server.password}|#{dist_name}" then
-                       # recevie & print
-                       mismatched = false
-                       dist_not_found = false
-                       result = client.read_lines do |l|
-                               puts l
-                               if l.include? "Password mismatched!" then
-                                       mismatched = true
-                               end
-                               if l.include? "Distribution not found!" then
-                                       dist_not_found = true
-                               end
-                       end
-                       if result and not mismatched and not dist_not_found then
-                               fullbuild_ok = true
-                       end
-               end
-
-               # terminate
-               client.terminate
-
-               if not fullbuild_ok then
-                       puts "Full build failed!"
-               end
-
-               return true
-       end
-
-
-       def self.register_package(id, file_path, dist_name)
-               # server
-               server = get_server(id)
                migrate_db(server)
 
                # check distribution
@@ -634,39 +652,91 @@ 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!"
+               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 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
+
+               if not result then
+                       puts "Registering package failed!"
                        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
+
+               begin
+                       result = JobLog.monitor("127.0.0.1", server.port, job_id) do |line,status,errmsg|
+                               job_status = status
+                               job_error = errmsg
+                               if line.nil? then 
+                                       next 
+                               end
+
+                               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
-                       if result and not mismatched then
-                               success = true
-                       end
+               rescue BuildServerException => e
+                       puts e.err_message()
+                       result = false
                end
 
-               # terminate
-               client.terminate
-
-               if not success then
-                       puts "Registering package failed!"
+               # Check job status
+               if not job_status.eql? "FINISHED" then
+                       result = false
                end
 
-               return true
+               return result
        end
 
        # server
        def self.query_server( id )
                server = get_server(id)
+
+               if not server.has_db? then 
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
                migrate_db(server)
                server.prjmgr.load()
 
@@ -711,11 +781,25 @@ class BuildServerController
                end
 
                server = get_server(id)
+
+               if not server.has_db? and attr != "GIT_BIN_PATH" and attr != "PASSWORD" and 
+                       attr != "FTP_ADDR" and attr != "FTP_PORT" and 
+                       attr != "FTP_USERNAME" and attr != "FTP_PASSWD" and 
+                       attr != "DB_DSN" and attr != "DB_USER" and
+                       attr != "DB_PASSWD" and attr != "PASSWORD" and
+                       attr != "MAX_WORKING_JOBS" and attr != "MAX_JOBS" then
+
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
+
                case attr
                when "GIT_BIN_PATH"
                        server.git_bin_path = value
                when "MAX_WORKING_JOBS"
                        server.jobmgr.max_working_jobs = value.to_i
+               when "MAX_JOBS"
+                       server.jobmgr.set_max_jobs(value.to_i)
                when "JOB_LOG_URL"
                        server.job_log_url = value
                when "SEND_MAIL"
@@ -773,11 +857,24 @@ class BuildServerController
                end
 
                server = get_server(id)
+               if not server.has_db? and attr != "GIT_BIN_PATH" and attr != "PASSWORD" and 
+                       attr != "FTP_ADDR" and attr != "FTP_PORT" and 
+                       attr != "FTP_USERNAME" and attr != "FTP_PASSWD" and 
+                       attr != "DB_DSN" and attr != "DB_USER" and
+                       attr != "DB_PASSWD" and attr != "PASSWORD" and 
+                       attr != "MAX_WORKING_JOBS" and attr != "MAX_JOBS" then
+
+                       puts BuildServerException.get_message("ERR021")
+                       return false
+               end
+
                case attr
                when "GIT_BIN_PATH"
                        puts server.git_bin_path
                when "MAX_WORKING_JOBS"
                        puts server.jobmgr.max_working_jobs
+               when "MAX_JOBS"
+                       puts server.jobmgr.get_max_jobs()
                when "JOB_LOG_URL"
                        puts server.job_log_url
                when "SEND_MAIL"
@@ -840,6 +937,7 @@ class BuildServerController
                        f.puts "ID=#{server.id}"
                        f.puts "PATH=#{server.path}"
                        f.puts "GIT_BIN_PATH=#{server.git_bin_path}"
+                       f.puts "SERVER_PORT=#{server.port}"
                        f.puts "TEST_TIME=#{server.test_time}" if server.test_time > 0
                        f.puts "PASSWORD=#{server.test_time}" if server.password != "0000"
                        if not server.ftp_addr.nil? then
@@ -849,6 +947,10 @@ class BuildServerController
                        f.puts "DB_DSN=#{server.db_dsn}"
                        f.puts "DB_USER=#{server.db_user}"
                        f.puts "DB_PASSWORD=#{server.db_passwd}"
+                       if not server.has_db? then
+                               f.puts "MAX_WORKING_JOBS=#{server.jobmgr.max_working_jobs}"
+                               f.puts "MAX_JOBS=#{server.jobmgr.get_max_jobs()}"
+                       end
                end
        end
 
@@ -857,15 +959,19 @@ class BuildServerController
        def self.read_server_config( id )
                path=""
                git_bin_path="/usr/bin/git"
+               running_port=nil
+               config_port=nil
                test_time=0
                password="0000"
                ftp_addr=nil
                ftp_port=nil
                ftp_username=nil
                ftp_passwd=nil
-               db_dsn="SQLite3:#{BuildServer::CONFIG_ROOT}/#{id}/server.db"
+               db_dsn=nil
                db_user=nil
                db_passwd=nil
+               max_working_jobs=2
+               max_jobs=4
 
                # read configuration
                server_dir = "#{BuildServer::CONFIG_ROOT}/#{id}"
@@ -879,6 +985,8 @@ class BuildServerController
                                        path = l[idx,length].strip
                                elsif l.start_with?("GIT_BIN_PATH=")
                                        git_bin_path = l[idx,length].strip
+                               elsif l.start_with?("SERVER_PORT=")
+                                       config_port = l[idx,length].strip.to_i
                                elsif l.start_with?("TEST_TIME=")
                                        test_time = l[idx,length].strip.to_i
                                elsif l.start_with?("PASSWORD=")
@@ -898,12 +1006,20 @@ class BuildServerController
                                        when /^Mysql:(.*)/i then
                                                db_dsn = "Mysql:#{$1}"
                                        else
-                                               db_dsn = "SQLite3:#{BuildServer::CONFIG_ROOT}/#{id}/server.db"
+                                               db_dsn = nil
                                        end
                                elsif l.start_with?("DB_USER=")
                                        db_user = l[idx,length].strip if not l[idx,length].strip.empty?
                                elsif l.start_with?("DB_PASSWORD=")
                                        db_passwd = l[idx,length].strip if not l[idx,length].strip.empty?
+                               elsif l.start_with?("ID=")
+                                       if not l[idx,length].strip.eql? id then
+                                               raise RuntimeError, "Server configuration FAILED: #{server_dir}/server.cfg: ID must be \"#{id}\""
+                                       end
+                               elsif l.start_with?("MAX_WORKING_JOBS=")
+                                       max_working_jobs = l[idx,length].strip.to_i
+                               elsif l.start_with?("MAX_JOBS=")
+                                       max_jobs = l[idx,length].strip.to_i
                                else
                                        next
                                end
@@ -913,14 +1029,18 @@ class BuildServerController
                # create server object
                obj = BuildServer.new( id, path, ftp_addr, ftp_port, ftp_username, ftp_passwd )
 
-               # check running port
+               # get running port
                if File.exist? "#{server_dir}/run" then
                        f = File.open( "#{server_dir}/run", "r" )
                        l = f.gets
-                       obj.port = l.strip.to_i
+                       running_port = l.strip.to_i
                        f.close
                end
 
+               # set port information
+               obj.port = running_port if (running_port != nil)
+               obj.config_port = config_port
+
                # set git binary path
                obj.git_bin_path = git_bin_path
 
@@ -935,6 +1055,12 @@ class BuildServerController
                obj.db_user = db_user
                obj.db_passwd = db_passwd
 
+               # max working jobs
+               if not obj.has_db? then
+                       obj.jobmgr.max_working_jobs =  max_working_jobs
+                       obj.jobmgr.set_max_jobs(max_jobs)
+               end
+
                # save config
                #write_server_config( obj )
 
index 8c98f08..2433e92 100644 (file)
@@ -1,4 +1,6 @@
 class BuildServerException < Exception
+       attr_accessor :err_code
+
        @@err_msgs = {
                "ERR001" => "Invalid request format is used!",
                "ERR002" => "Distribution not found!",
@@ -10,12 +12,42 @@ class BuildServerException < Exception
                "ERR008" => "Distribution locked!",
                "ERR009" => "Project not found!",
                "ERR010" => "Build operation not allowed on this project type!",
-               "ERR011" => "Project password required!",
-               "ERR012" => "Project password not matched!",
+               "ERR011" => "User password not matched!",
+
                "ERR013" => "Project from file-name/distribution not found!",
                "ERR014" => "Job cancel failed!",
                "ERR015" => "Server password not matched!",
                "ERR016" => "Can't received register file!",
+               "ERR017" => "Project locked!",
+
+               "ERR018" => "Connection failed!",
+               "ERR019" => "Receiving data failed!",
+               "ERR020" => "Sending data failed!",
+
+               "ERR021" => "No DB exists and create(migrate) DB first!",
+               "ERR022" => "There already exists same job.",
+               "ERR023" => "Cannot create package client!",
+
+               "ERR100" => "Package info file(\"package/pkginfo.manifest\") does not exist!",
+               "ERR101" => "Parsing package info file failed!",
+               "ERR102" => "Parsing change-log file failed!",
+               "ERR103" => "Change log not found!",
+               "ERR104" => "No servers supports the \"Host-OS\"!",
+               "ERR105" => "Version must be increased!",
+               "ERR106" => "Source code has been changed without increasing version!",
+               "ERR107" => "Package file not found!",
+               "ERR108" => "Unsupported OS used in package file name!",
+               "ERR109" => "Extracting package file failed!",
+               "ERR110" => "Initializing sub jobs failed!",
+               "ERR111" => "Git clone failed!!",
+               "ERR112" => "Git checkout failed!!",
+
+               "ERR200" => "Unmet dependency found!",
+               "ERR201" => "Creating job builder failed!",
+               "ERR202" => "Building job failed!",
+               "ERR203" => "Reverse-build-check failed!",
+               "ERR204" => "Uploading package file(s) failed!",
+               "ERR205" => "Job stopped by failure of its sub job!",
 
                "ERR900" => "Cancel event received!",
                "ERR901" => "Job already upload status. Cancel failed!"
@@ -25,11 +57,18 @@ class BuildServerException < Exception
                @err_code = code
        end
 
-       def err_message()
-               if not message().nil? and not message().empty? then
-                       return "Error: #{@@err_msgs[@err_code]}: #{message()}"
+       def err_message(prefix = "Error: ")
+               if not message().nil? and not message().empty? and 
+                       message() != "BuildServerException"  then
+
+                       return "#{prefix}#{@@err_msgs[@err_code]}: #{message()}"
                else
-                       return "Error: #{@@err_msgs[@err_code]}"
+                       return "#{prefix}#{@@err_msgs[@err_code]}"
                end
        end
+
+
+       def self.get_message(err_code, prefix = "Error: ")
+               return "#{prefix}#{@@err_msgs[err_code]}"
+       end
 end
index 0ab9726..da97aa9 100644 (file)
@@ -34,9 +34,9 @@ class BuildServerUsage
        CREATE="build-svr create -n <server name> [-t <ftp server url>]"
        REMOVE="build-svr remove -n <server name>"
        MIGRATE="build-svr migrate -n <server name> [--dsn <db dsn> [--dbuser <db_user> --dbpassword <db_password>] ]"
-       START="build-svr start -n <server name> -p <port>"
+       START="build-svr start -n <server name> [-p <port>]"
        STOP="build-svr stop -n <server name>"
-       UPGRADE="build-svr upgrade -n <server name> [-D <distribution name>]"
+       UPGRADE="build-svr upgrade -n <server name> [-D <distribution name>] [-u <package server url>]"
        ADD_SVR="build-svr add-svr -n <server name> -d <friend server address>"
        REMOVE_SVR= "build-svr remove-svr -n <server name> -d <friend server address>"
        ADD_OS= "build-svr add-os -n <server name> -o <os>"
@@ -47,9 +47,8 @@ class BuildServerUsage
        UNLOCK_DIST="build-svr unlock-dist -n <server name> -D <distribution name>"
        ADD_SYNC="build-svr add-sync -n <server name> -u <remote pkg server url> [--dist <distribution>]"
        REMOVE_SYNC="build-svr remove-sync -n <server name> -u <remote pkg server url> [--dist <distribution>]"
-       ADD_PRJ="build-svr add-prj -n <server name> -N <project name> (-g <git repository> -b <git branch>|-P <package name>) [-w <password>] [-o <os list>] [--dist <distribution>]"
+       ADD_PRJ="build-svr add-prj -n <server name> -N <project name> (-g <git repository> -b <git branch>|-P <package name>) [-o <os list>] [--dist <distribution>]"
        REMOVE_PRJ="build-svr remove-prj -n <server name> -N <project name> [--dist <distribution>]"
-       FULLBUILD="build-svr fullbuild -n <server name> [--dist <distribution>]"
        REGISTER="build-svr register -n <server name> -P <package file> [--dist <distribution>]"
        QUERY="build-svr query -n <server name>"
        SET_ATTR="build-svr set-attr -n <server name> -A <attribute> -V <value>"
@@ -75,8 +74,7 @@ def option_error_check( options )
                end
 
        when "start"
-               if options[:name].nil? or options[:name].empty? or
-                       options[:port].nil? then
+               if options[:name].nil? or options[:name].empty? then
                        raise ArgumentError, "Usage: " + BuildServerUsage::START
                end
 
@@ -164,11 +162,6 @@ def option_error_check( options )
                        raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_PRJ
                end
 
-       when "fullbuild"
-               if options[:name].nil? or options[:name].empty? then
-                       raise ArgumentError, "Usage: " + BuildServerUsage::FULLBUILD
-               end
-
        when "register"
                if options[:name].nil? or options[:name].empty? or
                        options[:package].nil? or options[:package].empty?  then
@@ -222,7 +215,6 @@ def option_parse
                + "\t" + "add-prj       Add project to build." + "\n" \
                + "\t" + "remove-prj    Remove project." + "\n" \
                + "\t" + "register      Register the package to the build-server." + "\n" \
-               + "\t" + "fullbuild     Build all your projects and upload them to package server." + "\n" \
                + "\t" + "query         Show build server configuration." + "\n" \
                + "\t" + "set-attr      Set build server atribute." + "\n" \
                + "\t" + "get-attr      Get build server atribute." + "\n" \
@@ -245,7 +237,6 @@ def option_parse
                + "\t" + BuildServerUsage::REMOVE_SYNC + "\n" \
                + "\t" + BuildServerUsage::ADD_PRJ + "\n" \
                + "\t" + BuildServerUsage::REMOVE_PRJ + "\n" \
-               + "\t" + BuildServerUsage::FULLBUILD + "\n" \
                + "\t" + BuildServerUsage::REGISTER + "\n" \
                + "\t" + BuildServerUsage::QUERY + "\n" \
                + "\t" + BuildServerUsage::SET_ATTR + "\n" \
@@ -270,7 +261,7 @@ def option_parse
                        options[:domain] = domain
                end
 
-               options[:port] = 2222
+               options[:port] = nil
                opts.on( '-p', '--port <port>', 'server port number: 2224' ) do|port|
                        options[:port] = port.strip.to_i
                end
@@ -367,7 +358,7 @@ def option_parse
                cmd.eql? "lock-dist" or cmd.eql? "unlock-dist" or
                cmd.eql? "add-sync" or cmd.eql? "remove-sync" or
                cmd.eql? "add-prj" or cmd.eql? "remove-prj" or
-               cmd.eql? "fullbuild" or cmd.eql? "register" or
+               cmd.eql? "register" or
                cmd.eql? "query" or
                cmd.eql? "set-attr" or cmd.eql? "get-attr" or
                cmd =~ /(-v)|(--version)/ or
index a352271..7d6376e 100644 (file)
@@ -31,11 +31,14 @@ require "time"
 $LOAD_PATH.unshift File.dirname(__FILE__)
 $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
 require "utils.rb"
+require "JobLog.rb"
+require "BuildServerException.rb"
+
 
 class CommonJob
 
        attr_accessor :id, :server, :log, :status, :priority
-       attr_accessor :os, :type, :pre_jobs, :user_id, :event, :sub_jobs
+       attr_accessor :os, :type, :pre_jobs, :user_id, :event, :sub_jobs, :thread, :error
        USER_JOB_PRIORITY = 100
        AUTO_JOB_PRIORITY = 0
 
@@ -59,9 +62,12 @@ class CommonJob
                @locked = false
                @log = nil
 
-               @start_time = Time.now
+               @start_time = nil
                @end_time = nil
+               @thread = nil
                @sub_pid = 0
+
+               @error = nil
        end
 
        # event check
@@ -109,8 +115,8 @@ class CommonJob
 
        # create logger
        public
-       def create_logger( second_out, verbose = false )
-               @log = JobLog.new( self, second_out, verbose )
+       def create_logger( verbose = false )
+               @log = JobLog.new( self, verbose )
                return @log
        end
 
@@ -126,6 +132,16 @@ class CommonJob
                @project = project
        end
 
+
+       public
+       def is_transferred?
+               if not @project.nil? then 
+                       return @project.is_transferred?
+               else
+                       return false
+               end
+       end
+
        public
        def get_user_email
                return @server.get_email_using_user_id(@user_id)
@@ -140,17 +156,23 @@ class CommonJob
                @thread = Thread.new do
                        begin
                                job_main()
-
-                               # parent job will call sub job's terminate method
-                               if not is_sub_job? then terminate() end
                        rescue BuildServerException => e
-                               @log.error e.message
-                               if @status == "WORKING" then @status = "ERROR" end
+                               @log.error( e.err_message, Log::LV_USER )
+                               # "CANCEL" operation(ERR900) must be excluded
+                               if e.err_code != "ERR900"  then 
+                                       @status = "ERROR" 
+                                       @error = e
+                               end
                        rescue => e
                                @log.error e.message
                                @log.error e.backtrace.inspect
-                               if @status == "WORKING" then @status = "ERROR" end
+                               @status = "ERROR"
                        ensure
+                               # parent job will call sub job's terminate method
+                               # if "WORKING"(canceled) and "ERROR", must call "terminate" here
+                               if not is_sub_job? and (@status == "ERROR" or @status == "FINISHED") then 
+                                       terminate() 
+                               end
                                @thread = nil
                        end
                end
@@ -172,6 +194,14 @@ class CommonJob
        #cancel
        public
        def cancel()
+               kill_sub_process
+
+               @sub_jobs.select{|x| x.event == "NONE" and x.status != "FINISHED" and x.status != "ERROR" and x.status != "CANCELED" }.each do |sub|
+                       sub.event = "CANCEL"
+               end
+               # wait for job thread to finish
+               @thread.join if not @thread.nil?
+
                if not @log.nil? then
                        @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
                end
@@ -189,6 +219,9 @@ class CommonJob
        # create process to execute command
        public
        def execute_command(cmd)
+               # if canceled, must prevent invoking more process
+               check_event
+
                # execute
                pid, status = Utils.execute_shell_with_log(cmd, @log.path, false)
                @sub_pid = pid
@@ -202,7 +235,9 @@ class CommonJob
                end
                @sub_pid = 0
 
+               # if canceled, must exit job thread
                check_event
+
                # return
                return pid, status
        end
@@ -233,6 +268,7 @@ class CommonJob
                        status VARCHAR(32) NOT NULL DEFAULT 'JUST_CREATED', 
                        start_time DATETIME, 
                        end_time DATETIME,
+                       error_code VARCHAR(32),
                        CONSTRAINT fk_jobs_projects1 FOREIGN KEY ( project_id ) REFERENCES projects ( id ),
                        CONSTRAINT fk_jobs_users1 FOREIGN KEY ( user_id ) REFERENCES users ( id ),
                        CONSTRAINT fk_jobs_supported_os1 FOREIGN KEY ( supported_os_id ) REFERENCES supported_os ( id ),
@@ -240,22 +276,27 @@ class CommonJob
                        CONSTRAINT fk_jobs_jobs1 FOREIGN KEY ( parent_job_id ) REFERENCES jobs ( id ),
                        CONSTRAINT fk_jobs_sources1 FOREIGN KEY ( source_id ) REFERENCES sources ( id ), 
                        CONSTRAINT fk_jobs_remote_build_servers1 FOREIGN KEY ( remote_build_server_id ) REFERENCES remote_build_servers ( id ) )#{post_fix}"
+               db.do "CREATE TABLE job_timestamps (
+                       id INTEGER PRIMARY KEY #{inc},
+                       job_id INTEGER, 
+                       stamp_name VARCHAR(64), 
+                       stamp_time DATETIME)#{post_fix}"
        end
 
 
        # save to db
        public
-       def save(db, now)
-
+       def save(db)
+               now = @server.db_now
                prj_id = @project.nil? ? "NULL" : @project.get_project_id()
                if @id.nil? then
-                       start_time = @start_time.strftime("%F %T")
+                       @start_time = Time.now
                        os_id = BuildServer.get_supported_os_id(db, @os)
                        dist_id = PackageDistribution.get_distribution_id(db, get_distribution_name())
                        parent_id = @parent.nil? ? "NULL" : @parent.id
-                       db.do "INSERT INTO jobs(project_id,user_id,supported_os_id, distribution_id, parent_job_id,jtype,status,start_time) 
-                               VALUES (#{prj_id},#{@user_id},#{os_id},#{dist_id},#{parent_id},'#{@type}','#{@status}',#{now})"
-                       @id = @server.db_insert_id(db)
+                       @id = @server.get_next_job_id()
+                       db.do "INSERT INTO jobs(id,project_id,user_id,supported_os_id, distribution_id, parent_job_id,jtype,status,start_time) 
+                               VALUES (#{@id},#{prj_id},#{@user_id},#{os_id},#{dist_id},#{parent_id},'#{@type}','#{@status}',#{now})"
                else
                        remote_bs_id = (@type == "BUILD" and not get_remote_server().nil?) ? 
                                get_remote_server().id : "NULL"
@@ -265,14 +306,31 @@ class CommonJob
                                db.do "UPDATE jobs SET source_id=#{source_id} WHERE id=#{@id}"
                        end
                        db.do "UPDATE jobs SET status='#{@status}',remote_build_server_id=#{remote_bs_id} WHERE id=#{@id}"
-                       if @status == "FINISHED" or @status == "ERROR" or @status == "CANCELED" then
-                               @end_time = Time.now.strftime("%F %T")
+                       if @end_time.nil? and 
+                               @status == "FINISHED" or @status == "ERROR" or @status == "CANCELED" then
+
+                               @end_time = Time.now
                                db.do "UPDATE jobs SET end_time=#{now} WHERE id=#{@id}"
+                               if @status == "ERROR" and not @error.nil? then
+                                       db.do "UPDATE jobs SET error_code='#{@error.err_code}' WHERE id=#{@id}"
+                               end
                        end
                end
        end
 
 
+       public
+       def add_timestamp(name)
+               if not @server.has_db? then return end
+
+               now = @server.db_now()
+               @server.get_db_connection() do |db|
+                       db.do "INSERT INTO job_timestamps(job_id,stamp_name,stamp_time)
+                               VALUES (#{@id},'#{name}',#{now})"
+               end
+       end
+
+
        def kill_sub_process()
                if @sub_pid != 0 then
                        if not @log.nil? then
index a2b46ac..8f66fb9 100644 (file)
@@ -31,17 +31,21 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
 $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
 
 class CommonProject
-       attr_accessor :name, :type, :passwd, :os_list, :dist_name, :path
+       attr_accessor :name, :type, :os_list, :dist_name, :path, :status
 
        # initialize
-       def initialize( name, type, server, os_list, dist_name="BASE" )
+       def initialize( name, type, server, os_list, dist_name="BASE", status="OPEN" )
                @prj_id = -1
-               @name = name
+               if name.nil? then
+                       @name = "TRANSFERRED"
+               else
+                       @name = name
+               end
                @type = type
-               @passwd = ""
                @os_list = os_list
                @server = server
                @dist_name = dist_name
+               @status = status
                @source_info = {}
                @package_info = {}
                if @dist_name == "BASE" then
@@ -63,20 +67,8 @@ class CommonProject
        end
 
 
-       #return passwd
-       def is_passwd_set?()
-               return ( not @passwd.empty? )
-       end
-
-
-       def passwd_match?(word)
-               if not is_passwd_set? then return true end
-
-               if word.eql? @passwd then
-                       return true
-               else
-                       return false
-               end
+       def is_transferred? 
+               return @name == "TRANSFERRED"
        end
 
 
@@ -165,6 +157,14 @@ class CommonProject
                return @prj_id
        end
 
+       def set_project_status(status)
+               @status = status
+       end
+
+       def get_project_status()
+               return @status
+       end
+
        def self.create_table(db, inc, post_fix) 
                db.do "CREATE TABLE projects ( 
                        id INTEGER PRIMARY KEY #{inc}, 
@@ -172,7 +172,7 @@ class CommonProject
                        user_id INTEGER,
                        name VARCHAR(32) NOT NULL, 
                        ptype VARCHAR(32) NOT NULL, 
-                       password VARCHAR(32),
+                       status VARCHAR(32) NOT NULL DEFAULT 'OPEN',
                        CONSTRAINT fk_projects_users1 FOREIGN KEY ( user_id ) REFERENCES users ( id ),
                        CONSTRAINT fk_projects_distributions1 FOREIGN KEY ( distribution_id ) REFERENCES distributions ( id ) )#{post_fix}"
 
@@ -242,8 +242,8 @@ class CommonProject
                if @prj_id == -1 then
                        row = db.select_one("SELECT * FROM distributions WHERE name='#{@dist_name}'")
                        dist_id = row['id']
-                       db.do "INSERT INTO projects (distribution_id,name,ptype,password
-                               VALUES (#{dist_id},'#{@name}','#{@type}','#{@passwd}')"
+                       db.do "INSERT INTO projects (distribution_id,name,ptype,status
+                               VALUES (#{dist_id},'#{@name}','#{@type}','#{@status}')"
                        case @server.db_dsn
                        when /^SQLite3:/ then @prj_id = db.select_one("select last_insert_rowid()")[0]
                        when /^Mysql:/ then @prj_id = db.func(:insert_id)
@@ -259,7 +259,7 @@ class CommonProject
                else
                        row = db.select_one("SELECT * FROM distributions WHERE name='#{@dist_name}'")
                        dist_id = row['id']
-                       db.do "UPDATE projects SET ptype='#{@type}',password='#{@passwd}' WHERE name='#{@name}' and distribution_id=#{dist_id})"
+                       db.do "UPDATE projects SET ptype='#{@type}',status='#{@status}' WHERE name='#{@name}' and distribution_id=#{dist_id})"
                        db.do "DELETE FROM project_os WHERE project_id=#{@prj_id}"
                        @os_list.each do |os|
                                row = db.select_one("SELECT * FROM supported_os WHERE name='#{os}'")
@@ -299,6 +299,9 @@ class CommonProject
                if row1.nil? then
                        db.do "INSERT INTO sources(project_id, pkg_ver,location) 
                                VALUES(#{@prj_id},'#{src_ver}','#{info}')"
+               else
+                       db.do "UPDATE sources SET location='#{info}' "+
+                                       "WHERE project_id=#{@prj_id} and pkg_ver='#{src_ver}'"
                end
        end
 
@@ -339,7 +342,7 @@ class CommonProject
 
        public
        def self.get_project_from_pkg_name_row(pkg_name, dist_name, db)
-               return db.select_one("SELECT projects.id,projects.distribution_id,projects.name,projects.ptype,projects.password 
+               return db.select_one("SELECT projects.id,projects.distribution_id,projects.name,projects.ptype
                                                         FROM distributions,projects,project_bins
                                                         WHERE distributions.name='#{dist_name}' and
                                                         distributions.id = projects.distribution_id and
index 34e0dde..84aa21e 100644 (file)
@@ -32,6 +32,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
 $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
 require "BuildJob.rb"
 require "utils.rb"
+require "BuildServerException.rb"
 
 
 $git_mutex = Mutex.new
@@ -63,9 +64,11 @@ class GitBuildJob < BuildJob
 
                        # if succeeded, register source info and copy pkginfo.manifest
                        @log.info( "Updating the source info for project \"#{@project.name}\"" , Log::LV_USER)
-                       @project.save_source_info( @pkginfo.get_version(), @git_commit)
-                       @project.save_package_info_from_manifest( @pkginfo.get_version(),
-                               "#{@source_path}/package/pkginfo.manifest", @os)
+                       if not is_transferred? then
+                               @project.save_source_info( @pkginfo.get_version(), @git_commit)
+                               @project.save_package_info_from_manifest( @pkginfo.get_version(),
+                                       "#{@source_path}/package/pkginfo.manifest", @os)
+                       end
                        @server.jobmgr.save_job_status(self)
                        # clean up
                        @server.cleaner.clean(@id)
@@ -121,13 +124,13 @@ class GitBuildJob < BuildJob
 
                # create logger
                if @log.nil? then
-                       @log = JobLog.new(self, nil )
+                       @log = JobLog.new(self)
                end
 
                @log.info( "Initializing job...", Log::LV_USER)
 
                # if internal job, copy external_pkgs
-               if @is_internal_job then
+               if not @external_pkgs.empty? then
                        @log.info( "Copying external dependent pkgs...", Log::LV_USER)
                        ext_pkgs_dir = "#{@job_root}/external_pkgs"
 
@@ -141,39 +144,34 @@ class GitBuildJob < BuildJob
 
                # download source code
                @git_commit = get_source_code()
-               if @git_commit.nil? then
-                       @status = "ERROR"
-                       return false
-               end
 
                # check pkginfo.manifest
-               if not File.exist? "#{@source_path}/package/pkginfo.manifest"
-                       @log.error( "package/pkginfo.manifest does not exist", Log::LV_USER)
-                       @status = "ERROR"
-                       return false
+               if not File.exist? "#{@source_path}/package/pkginfo.manifest" then
+                       raise BuildServerException.new("ERR100")
                end
 
                # set up pkg info
                begin
                        @pkginfo = PackageManifest.new("#{@source_path}/package/pkginfo.manifest")
                rescue => e
-                       @log.error( e.message, Log::LV_USER)
-                       return false
+                       raise BuildServerException.new("ERR101"), e.message
                end
 
                # set up pkgsvr_client
-               @pkgsvr_client =  Client.new(@pkgsvr_url, @job_working_dir, @log)
+               @pkgsvr_client =  Client.create(@pkgsvr_url, @job_working_dir, @log)
+               if @pkgsvr_client.nil? then
+                       raise BuildServerException.new("ERR023")
+               end
 
                # checking version if not reverse-build job or not internal-job
-               if not @is_rev_build_check_job and not @is_internal_job  then
+               if not @is_rev_build_check_job and not @is_verified then
 
                        #check change log
                        change_log = {}
                        begin
                                change_log = Parser.read_changelog "#{@source_path}/package/changelog" if File.exist? "#{@source_path}/package/changelog"
                        rescue => e
-                               @log.error( e.message, Log::LV_USER)
-                               return false
+                               raise BuildServerException.new("ERR102"), e.message
                        end
 
                        if not change_log.empty? and @pkginfo.packages[0].change_log.empty? then
@@ -181,24 +179,50 @@ class GitBuildJob < BuildJob
                        end
 
                        if @server.changelog_check and not @pkginfo.packages[0].does_change_exist? then
-                               @log.error( "change log not found", Log::LV_USER )
-                               return false
+                               raise BuildServerException.new("ERR103"), @pkginfo.packages[0].version
                        end
 
                        # check availabiltiy
                        if not @server.check_job_availability( self ) then
-                               @log.error( "No servers that are able to build your packages.", Log::LV_USER)
-                               @log.error( "Host-OS (#{@os}) is not supported in build server.", Log::LV_USER)
-                               @status = "ERROR"
-                               @server.log.info "Adding the job \"#{@id}\" is canceled"
-                               return false
+                               raise BuildServerException.new("ERR104"), "#{@os}"
                        end
 
-                       if not check_package_version(@git_commit) then
-                               @status = "ERROR"
-                               return false
-                       end
+                       check_package_version(@git_commit)
+               end
+
+               return true
+       end
+
+
+       def is_same_with?(wjob)
+               # must have same distribution
+               if get_distribution_name() != wjob.get_distribution_name() then
+                       return false
                end
+               if @type != wjob.type then return false end
+
+               prj1 = @project
+               prj2 = wjob.get_project()
+
+               # check project name
+               if prj1.nil? or prj2.nil? or
+                       prj1.name != prj2.name then
+                       return false
+               end
+
+               # check version
+               if @pkginfo.nil? or wjob.pkginfo.nil? or
+                       not(Version.new(@pkginfo.get_version()) == Version.new(wjob.pkginfo.get_version())) then
+                       return false
+               end
+
+               if @git_commit != wjob.git_commit then return false end
+
+               # check compat os
+               wjob.pkginfo.get_target_packages(wjob.os).each do |p|
+                       if not p.os_list.include?(@os) then return false end
+               end
+
 
                return true
        end
@@ -219,11 +243,11 @@ class GitBuildJob < BuildJob
        protected
        def get_source_code_internal()
                # check git directory
-               git_path = "#{@project.path}/cache/git"
                cache_path = "#{@project.path}/cache"
                if not File.exist? cache_path then
                        FileUtils.mkdir_p cache_path
                end
+               git_path = "#{cache_path}/#{File.basename(@git_repos)}"
 
                # verify git & check branch name
                if File.exist? git_path then
@@ -246,6 +270,12 @@ class GitBuildJob < BuildJob
                        end
                end
 
+               # git reset origin operation
+               if File.exist? git_path and not git_cmd("reset --hard origin/#{@git_branch}", git_path,@log) then
+                       @log.warn( "Failed on \"git reset --hard origin/#{@git_branch}\"", Log::LV_USER)
+                       FileUtils.rm_rf git_path
+               end
+
                # git pull operation
                if File.exist? git_path and not git_cmd("pull", git_path,@log) then
                        @log.warn( "Failed on \"git pull\"", Log::LV_USER)
@@ -255,14 +285,12 @@ class GitBuildJob < BuildJob
                # if no git, clone it
                if  not File.exist? git_path then
                        # if "git pull" failed, try to "git clone"
-                       if not git_cmd("clone #{@git_repos} git", cache_path, @log) then
-                               @log.error( "Failed on \"git clone #{@git_repos}\"", Log::LV_USER)
-                               return nil
+                       if not git_cmd("clone #{@git_repos}", cache_path, @log) then
+                               raise BuildServerException.new("ERR111"), "git clone #{@git_repos}"
                        end
                        # git checkout
                        if not git_cmd("checkout #{@git_branch}", git_path, @log) then
-                               @log.error( "Failed on \"git checkout #{@git_branch}\"", Log::LV_USER)
-                               return nil
+                               raise BuildServerException.new("ERR112"), "git checkout #{@git_branch}"
                        end
                end
 
@@ -282,8 +310,10 @@ class GitBuildJob < BuildJob
                else
                        # git reset
                        if not git_cmd("reset --hard #{@git_commit}", git_path, @log) then
-                               @log.error( "Failed on \"git reset --hard #{@git_commit}\"", Log::LV_USER)
-                               return nil
+                               @log.warn( "Failed on \"git reset --hard #{@git_commit}\"", Log::LV_USER)
+                               FileUtils.rm_rf git_path
+                               @git_commit = nil
+                               @git_commit = get_source_code_internal()
                        end
                end
 
index 589651b..1bb60ce 100644 (file)
@@ -42,7 +42,7 @@ class GitBuildProject < CommonProject
 
        # initialize
        def initialize( name, server, os_list, dist_name, repos = nil, branch = nil )
-               super(name, "GIT", server, os_list, dist_name)
+               super(name, "GIT", server, os_list, dist_name, "OPEN")
                @repository = repos
                @branch = branch
        end
@@ -114,13 +114,13 @@ class GitBuildProject < CommonProject
 
                prj_id = row['id']
                prj_name = row['name']
-               prj_passwd = row['password']
+               prj_status = row['status']
 
                new_project = GitBuildProject.new(prj_name, server, prj_os_list, dist_name)
-               if not prj_passwd.empty? then new_project.passwd = prj_passwd end
                new_project.set_project_id( prj_id )
                new_project.set_source_info( source_info )
                new_project.set_package_info( package_info )
+               new_project.set_project_status( prj_status )
 
                row=db.select_one("SELECT * FROM project_gits WHERE project_id=#{prj_id}")
                if row.nil? then return nil end
index 2dade44..fcfad61 100644 (file)
@@ -31,10 +31,12 @@ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) + "/common"
 require "log"
 require "logger"
 require "BuildComm.rb"
+require "BuildServerException.rb"
+
 
 class JobLog < Log
 
-       def initialize(job, stream_out, verbose = false)
+       def initialize(job, verbose = false)
                log_level = (verbose) ?  Log::LV_NORMAL : Log::LV_USER
                if job.nil? then
                        super(nil)
@@ -45,69 +47,72 @@ class JobLog < Log
                        super("#{job.server.path}/jobs/#{job.id}/log",log_level)
                end
                @parent_job=job
-               @second_out = stream_out
        end
 
 
-       def set_second_out( out )
-               @second_out = out
-       end
-
-
-       def close
-               # close communication
-               if not @second_out.nil? then
-                       begin
-                               if  not @second_out.closed? then
-                                       BuildCommServer.send_end(@second_out)
-                               end
-                       rescue
-                       end
-                       BuildCommServer.disconnect(@second_out)
+       def JobLog.parse_log(line)
+               data = line.sub(/(^[a-zA-Z], \[[^\]]*\][ \t]*)/,"")                                     
+               if $1.nil? then
+                       return "UNKNOWN", 1, line
                end
 
-               @second_out = nil
-       end
-
-
-       def is_connected?
-               if @second_out.nil? or @second_out.closed? then
-                       return false
-               else
-                       return true
+               data_tok = data.split(" -- : ")
+               if data_tok.nil? then 
+                       return "UNKNOWN", 1, line
+               elsif data_tok.count != 2 then 
+                       return "INFO", 1, "" 
                end
-       end
 
+               category = data_tok[0]
+               sub_data = data_tok[1]
+               level = sub_data[1..1].to_i
+               contents = sub_data[4..-1]
 
-       def has_second_out?
-               if @second_out.nil? then
-                       return false
-               else
-                       return true
+               if contents.nil? then
+                       contents = ""
                end
+
+               return category, level, contents
        end
 
 
-       protected
+       def JobLog.monitor(ip, port, job_id)
 
-       # overide
-       def output_extra(msg)
+               result = true
+               job_status = ""
                begin
-                       if not @second_out.nil? then
-                               BuildCommServer.send( @second_out, msg )
+                       client = BuildCommClient.create( ip, port, nil, 0 )
+                       if client.nil? then
+                               raise BuildServerException.new("ERR018"), "#{ip}:#{port}"
                        end
-               rescue
-                       # close second_out
-                       @second_out.close
-                       @second_out = nil
 
-                       error "Connection closed by remote client"
+                       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]
+
+                                       if block_given? then
+                                               yield nil,job_status,job_error
+                                       end
+                               else
+                                       if block_given? then
+                                               yield line.strip,job_status,job_error
+                                       else
+                                               puts line.strip
+                                       end
+                               end
+                       end
 
-                       # cancel parent job
-                       if not @parent_job.nil? and @parent_job.event == "NONE" then
-                               @parent_job.event = "CANCEL"
+                       if not result then
+                               raise BuildServerException.new("ERR019"), "#{client.get_error_msg()}"
                        end
+                               
+               ensure
+                       client.terminate if not client.nil?
                end
-       end
 
+               return result
+       end
 end
index f8d890a..cc21616 100644 (file)
@@ -33,7 +33,7 @@ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/pkg_server"
 require "SocketJobRequestListener.rb"
 require "RegisterPackageJob.rb"
 require "packageServer.rb"
-
+require "BuildServerException.rb"
 
 class JobManager
        attr_accessor :jobs, :internal_jobs, :reverse_build_jobs
@@ -48,6 +48,8 @@ class JobManager
                @new_job_index = 0
                @internal_job_schedule = Mutex.new
                @latest_job_touch = Mutex.new
+               @max_build_jobs = 2
+               @max_jobs = 4
        end
 
        def cancel_broken_status
@@ -57,19 +59,64 @@ class JobManager
        end
 
        def max_working_jobs
-               result = nil
-               @server.get_db_connection() do |db|
-                       result = db.select_one("SELECT value FROM server_configs WHERE property = 'max_working_jobs'")[0]
+               if @server.has_db? then
+                       result = nil
+                       @server.get_db_connection() do |db|
+                               result = db.select_one("SELECT value FROM server_configs WHERE property = 'max_working_jobs'")[0]
+                       end
+                       @max_build_jobs = result.to_i if not result.nil?
                end
-               return (result.nil?) ? 2 : result.to_i
+
+               return @max_build_jobs
        end
 
        def max_working_jobs=(job_cnt)
-               @server.get_db_connection() do |db|
-                       db.do "UPDATE server_configs SET value = '#{job_cnt}' WHERE property = 'max_working_jobs'"
+               @max_build_jobs = job_cnt
+               if @max_jobs < @max_build_jobs then
+                       @max_jobs = @max_build_jobs
+               end
+
+               if @server.has_db? then
+                       @server.get_db_connection() do |db|
+                               db.do "UPDATE server_configs SET value = '#{@max_build_jobs}' WHERE property = 'max_working_jobs'"
+                               db.do "UPDATE server_configs SET value = '#{@max_jobs}' WHERE property = 'max_jobs'"
+                       end
                end
        end
 
+
+       def get_max_jobs()
+               if @server.has_db? then
+                       result = nil
+                       @server.get_db_connection() do |db|
+                               result = db.select_one("SELECT value FROM server_configs WHERE property = 'max_jobs'")[0]
+                       end
+                       @max_jobs = result.to_i if not result.nil?
+               end
+
+               if @max_jobs < @max_build_jobs then
+                       @max_jobs = @max_build_jobs
+               end
+
+               return @max_jobs
+       end
+
+
+       def set_max_jobs(cnt)
+               if cnt > @max_build_jobs then
+                       @max_jobs = cnt
+               else
+                       @max_jobs = @max_build_jobs
+               end
+
+               if @server.has_db? then
+                       @server.get_db_connection() do |db|
+                               db.do "UPDATE server_configs SET value = '#{@max_jobs}' WHERE property = 'max_jobs'"
+                       end
+               end
+       end
+
+
        # initialize
        def init()
                # load latest job idx if exist
@@ -157,27 +204,38 @@ class JobManager
        def initialize_job ( job )
                job.status = "INITIALIZING"
                job.thread = Thread.new do
-                       save_job_status(job)
                        begin
+                               save_job_status(job)
+                               job.add_timestamp("INIT_START")
+
                                # init
-                               if not job.init or job.status == "ERROR" then
-                                       if job.event == "NONE" then job.status = "ERROR" end
-                                       @server.log.info "Adding the job \"#{job.id}\" is canceled"
-                                       job.terminate()
-                                       save_job_status(job)
-                                       Thread.current.exit
-                               end
+                               job.init
                                job.check_event
                                if job.status == "INITIALIZING" then
                                        job.status = "WAITING"
                                        save_job_status(job)
+                                       job.add_timestamp("INIT_END")
                                end
                                @server.log.info "Checking the job \"#{job.id}\" was finished!"
                        rescue BuildServerException => e
-                               @server.log.error e.message
+                               @server.log.info "Initializig the job \"#{job.id}\" failed!"
+                               if e.err_code != "ERR900"  then 
+                                       job.status = "ERROR" 
+                               end
+                               if not job.log.nil? then
+                                       job.log.error(e.err_message(""), Log::LV_USER)
+                               else
+                                       @server.log.error e.message
+                               end
+                               if job.status == "ERROR" then
+                                       job.error = e
+                                       job.terminate()
+                                       save_job_status(job)
+                               end
                        rescue => e
                                @server.log.error e.message
                                @server.log.error e.backtrace.inspect
+                               job.status = "ERROR"
                        ensure
                                job.thread = nil
                        end
@@ -190,6 +248,7 @@ class JobManager
        def execute(job)
                job.status = "WORKING"
                save_job_status(job)
+               job.add_timestamp("WORK_START")
 
                # start build
                job.execute
@@ -202,10 +261,13 @@ class JobManager
 
                # start build
                set_remote(job, rserver)
+
+               # status change & job control
+               job.status = "REMOTE_WORKING"
+               save_job_status(job)
+               job.add_timestamp("WORK_START")
+
                if job.execute() then
-                       # status change & job control
-                       job.status = "REMOTE_WORKING"
-                       save_job_status(job)
                        @server.log.info "Moved the job \"#{job.id}\" to remote job list"
                else
                        @server.log.info "Moving the job \"#{job.id}\" to remote failed"
@@ -217,14 +279,7 @@ class JobManager
                @server.log.info "Creating thread for canceling the job \"#{job.id}\""
                Thread.new do
                        begin
-                               job.kill_sub_process
-
-                               job.sub_jobs.select{|x| x.event == "NONE" and x.status != "FINISHED" and x.status != "ERROR" and x.status != "CANCELED" }.each do |sub|
-                                       sub.event = "CANCEL"
-                               end
-                               job.thread.join if not job.thread.nil?
-
-                               # job cacncel
+                               # job cancel
                                job.cancel
 
                                # cancel finished
@@ -317,19 +372,11 @@ class JobManager
                        if job.status == "JUST_CREATED" then
                                initialize_job( job )
                        end
-
-                       # check the connection if job is not asynchronous job
-                       if ( job.status == "WAITING" or job.status == "REMOTE_WORKING" ) and #or job.status == "PENDING") and
-                               not job.is_asynchronous_job? and
-                               not job.is_connected? then
-
-                               job.status = "ERROR"
-                               save_job_status(job)
-                               dispose_job( job )
-                               @server.log.info "Job \"#{job.id}\" is disconnected by user. Removed!"
-                       end
                end
 
+               # remove duplicated jobs
+               remove_duplicated_jobs()
+
                # reverse build job ->  internal job -> normal job
                job = get_available_job
 
@@ -350,11 +397,11 @@ class JobManager
 
 
        def dispose_job(job)
-               # if remote job, remove it from remote server's queue
-               if job.type == "BUILD" and job.is_remote_job then
+               # update remote server state if needed
+               if job.type == "BUILD" and job.is_remote_job then 
                        job.get_remote_server.remove_working_job(job)
                        job.get_remote_server.update_db()
-               end
+               end 
 
                # remove from queue
                @jobs.delete_if {|j| j.id == job.id}
@@ -362,6 +409,34 @@ class JobManager
                @reverse_build_jobs.delete_if {|j| j.id == job.id}
        end
 
+
+       # will remove redundent jobs
+       def remove_duplicated_jobs()
+               @jobs.reverse.each do |j1|
+                       if j1.status != "WAITING" then next end
+
+                       @jobs.each do |j2|
+                               if j1.id == j2.id then next end
+                               if j2.status != "WAITING" and j2.status != "WORKING" and
+                                       j2.status != "REMOTE_WORKING" then 
+                                       next    
+                               end
+
+                               if j1.is_same_with?(j2) then
+                                       begin
+                                               raise BuildServerException.new("ERR022"), "(#{j2.id})"
+                                       rescue BuildServerException => e
+                                               j1.error = e
+                                               j1.log.error(e.err_message(""), Log::LV_USER)
+                                               j1.status = "ERROR"
+                                       end
+                                       break
+                               end
+                       end     
+               end
+       end
+
+
        # select the job whith no build-dependency problem
        def get_available_job
                # select reverse build job with round-robin method
@@ -403,6 +478,8 @@ class JobManager
                (@jobs + @internal_jobs + @reverse_build_jobs).each do |job|
                        if job.status == "WORKING" then
                                working_cnt = working_cnt + 1
+                       else
+                               next
                        end
 
                        # must exclude parent job
@@ -477,35 +554,46 @@ class JobManager
        end
 
 
-       #def get_pending_jobs
-       #       result = []
-       #       @jobs.each do |job|
-       #               if job.status == "PENDING" then
-       #                       result.push job
-       #               end
-       #       end
-
-       #       return result
-       #end
-
+       # Additionally, "commit" option will assign job number 
        def commit_job(job)
-               result = save_job_status(job)
+               if @server.has_db? and not job.is_transferred? then
+                       result = save_job_status(job)
+               else
+                       job.id = @server.get_next_job_id()
+                       result = true
+               end
                return result
        end
 
+
        def save_job_status(job)
-               now = @server.db_now
+               # if transferred job, no need to save
+               if job.is_transferred? then return true end
+
                result = @server.get_db_connection() do |db|
-                       job.save(db, now)
+                       job.save(db)
                        job.sub_jobs.each do |j|
-                               j.save(db, now)
+                               j.save(db)
                        end
                end
 
                return result
        end
 
-
+       def search_job (job_id)
+               (@jobs + @internal_jobs + @reverse_build_jobs).each do |job|
+                       if job.id == job_id then
+                               return job
+                       end
+                       job.sub_jobs.each do |job|
+                               if job.id == job_id then
+                                       return job
+                               end
+                       end
+               end
+               return nil
+       end
+       
        protected
        # select the job whith no build-dependency problem
        # if "check_dep_wait" is true, it will check the build dependency
@@ -538,10 +626,6 @@ class JobManager
                                if (cjob.status == "WORKING" or cjob.status == "REMOTE_WORKING" ) and
                                        (job.has_build_dependency?( cjob ) or job.is_compatible_with?( cjob)) then
                                        pre_jobs.push cjob
-                       #       # In case that "PENDING" job is depends on me (not depended )
-                       #       elsif cjob.status == "PENDING"  and (not job.does_depend_on? cjob) and
-                       #               (job.has_build_dependency?( cjob ) or job.is_compatible_with?( cjob)) then
-                       #               pre_jobs.push cjob
                                elsif check_dep_wait and cjob.status == "WAITING" and
                                        (job.does_depend_on? cjob or
                                         (job.id > cjob.id and job.is_compatible_with? cjob) ) then
index 8bcf6a5..da32078 100644 (file)
@@ -43,7 +43,7 @@ require "CommonJob.rb"
 class MultiBuildJob < CommonJob
 
        attr_accessor :source_path
-       attr_accessor :pkgsvr_client, :thread
+       attr_accessor :pkgsvr_client
 
        # initialize
        def initialize (server)
@@ -56,6 +56,11 @@ class MultiBuildJob < CommonJob
                @pkgsvr_ip = nil
                @pkgsvr_port = nil
                @pkgsvr_password = nil
+
+               # "send_result_back" mean that server will send package file by network
+               @send_result_back = false
+               @dock_num = "0"
+               @result_files = []
        end
 
 
@@ -80,6 +85,31 @@ class MultiBuildJob < CommonJob
        end
 
 
+       # This make project to build
+       # even though there is a package of same version on pkg-server
+       def set_force_rebuild(value)
+               @sub_jobs.each do |sub|
+                       sub.set_force_rebuild(value)
+               end
+       end
+
+
+       def set_send_result_back( dock_num )
+               @send_result_back = true
+               @dock_num = dock_num
+       end
+
+
+       def is_send_result_back?
+               return @send_result_back
+       end
+
+
+       def get_result_files()
+               return @result_files
+       end
+
+
        #
        def init
                @job_root = "#{@server.path}/jobs/#{@id}"
@@ -92,7 +122,7 @@ class MultiBuildJob < CommonJob
 
                # create logger
                if @log.nil? then
-                       @log = JobLog.new(self, nil )
+                       @log = JobLog.new(self)
                end
 
                @log.info( "Initializing job...", Log::LV_USER)
@@ -105,29 +135,41 @@ class MultiBuildJob < CommonJob
                # initialize all sub jobs and add them to "internal_jobs"
                tstatus = @status
                @sub_jobs.each do |job|
-                       # initialize job
-                       if not job.init or job.status == "ERROR" then
-                               job.status = "ERROR"
-                               @log.info( "Failed to initialize sub-job \"#{job.get_project().name}\" for #{job.os}. (#{job.id})", Log::LV_USER)
-                               job.terminate()
-                       end
+                       begin
+                               job.status = "INITIALIZING"
+                               @log.info( "Initializing sub-job(#{job.id})...", Log::LV_USER)
 
-                       if job.status != "ERROR" then
-                               job.status = "WAITING"
-                       else
-                               job.status = "ERROR"
+                               job.add_timestamp("INIT_START")
+
+                               # initialize job
+                               job.init
+                               if job.status == "INITIALIZING" then
+                                       job.status = "WAITING"
+                                       job.add_timestamp("INIT_END")
+                               end
+                       rescue BuildServerException => e
+                               if e.err_code != "ERR900"  then 
+                                       job.error = e
+                                       job.status = "ERROR" 
+                               end
+                               @log.error( "Failed to initialize sub-job \"#{job.get_project().name}\" for #{job.os}. (#{job.id})", Log::LV_USER)
+                               @log.error( " * #{e.err_message("")}", Log::LV_USER)
                                tstatus = "ERROR"
                        end
                end
+
                if tstatus == "ERROR" then
                        # Changed the status of initialized sub-jobs if parent is in ERROR status
                        @sub_jobs.each do |job|
                                if job.status == "WAITING" then
+                                       job.event = "CANCEL"
                                        job.status = "CANCELED"
                                end 
+                               # Add internal job for cancel,error process
+                               @server.jobmgr.add_internal_job(job)
                        end
-                       @status = tstatus
-                       return false
+
+                       raise BuildServerException.new("ERR110")
                end
 
 
@@ -137,7 +179,10 @@ class MultiBuildJob < CommonJob
                @pkgsvr_ip = @server.distmgr.get_distribution(first_project.dist_name).pkgsvr_ip
                @pkgsvr_port = @server.distmgr.get_distribution(first_project.dist_name).pkgsvr_port
                @pkgsvr_password = @server.distmgr.get_distribution(first_project.dist_name).pkgsvr_password
-               @pkgsvr_client =  Client.new(@pkgsvr_url, @job_working_dir, @log)
+               @pkgsvr_client =  Client.create(@pkgsvr_url, @job_working_dir, @log)
+               if @pkgsvr_client.nil? then
+                       raise BuildServerException.new("ERR023")
+               end
 
                return true
        end
@@ -221,6 +266,11 @@ class MultiBuildJob < CommonJob
        end
 
 
+       def is_same_with?(o)
+               return false
+       end
+
+
        def is_compatible_with?(o)
                return false
        end
@@ -239,24 +289,14 @@ class MultiBuildJob < CommonJob
 
 
        def has_same_packages?( wjob )
-               # must have same distribution
-               if get_distribution_name() != wjob.get_distribution_name() then
-                       return false
-               end
-
-               # same package must have same os
-               if not @os.eql? wjob.os then
-                       return false
-               end
-
-               # check package name
-               get_packages.each do |pkg|
-                       wjob.get_packages().each do |wpkg|
-                               if pkg.package_name == wpkg.package_name then
-                                       #puts "Removed from candiated... A == B"
-                                       return true
+               @sub_jobs.each do |job2|
+                       if wjob.type == "MULTIBUILD" then
+                               wjob.sub_jobs.each do |wjob2|
+                                       if job2.has_same_packages?( wjob2 ) then return true end
                                end
-                       end
+                       else
+                               if job2.has_same_packages?( wjob ) then return true end
+                       end                     
                end
 
                return false
@@ -307,11 +347,6 @@ class MultiBuildJob < CommonJob
        end
 
 
-       def is_connected?
-               return true
-       end
-
-
        # return the job is asyncronous job
        def is_asynchronous_job?
                return false
@@ -321,10 +356,10 @@ class MultiBuildJob < CommonJob
        def get_log_url()
                # only when server support log url
                if @server.job_log_url.empty? then
-                       return "",""
+                       return ""
                end
 
-               return "#{@server.job_log_url}/#{@id}/log",""
+               return "#{@server.job_log_url}/#{@id}/log"
        end
 
        #
@@ -336,7 +371,6 @@ class MultiBuildJob < CommonJob
        protected
        def job_main()
                @log.info( "Invoking a thread for MULTI-BUILD Job #{@id}", Log::LV_USER)
-               if @status == "ERROR" then return end
                @log.info( "New Job #{@id} is started", Log::LV_USER)
 
                # initialize status map
@@ -352,9 +386,6 @@ class MultiBuildJob < CommonJob
                                @server.jobmgr.add_internal_job(job)
                                @log.info( "Added new job \"#{job.get_project().name}\" for #{job.os}! (#{job.id})",
                                        Log::LV_USER)
-                               if not @server.job_log_url.empty? then
-                                       @log.info( " * Log URL : #{@server.job_log_url}/#{job.id}/log", Log::LV_USER)
-                               end
                        end
                end
 
@@ -364,47 +395,54 @@ class MultiBuildJob < CommonJob
                while not all_jobs_finished
                        all_jobs_finished = true
                        @sub_jobs.each do |job|
+                               job_status = job.status
                                # check status chanaged, if then print
-                               if job_status_map[ job.id ]  != job.status then
-                                       @log.info(" * Sub-Job \"#{job.get_project().name}(#{job.os})\" has entered \"#{job.status}\" state. (#{job.id})", Log::LV_USER)
-                                       job_status_map[ job.id ] = job.status
+                               if job_status_map[ job.id ]  != job_status then
+                                       @log.info(" * Sub-Job \"#{job.get_project().name}(#{job.os})\" has entered \"#{job_status}\" state. (#{job.id})", Log::LV_USER)
+                                       job_status_map[ job.id ] = job_status
                                end
                                # check all jobs are finished
-                               if job.status != "ERROR" and job.status != "FINISHED" and job.status != "CANCELED" then
+                               if job_status != "ERROR" and job_status != "FINISHED" and job_status != "CANCELED" then
                                        all_jobs_finished = false
                                end
                                # check there is some error or cancel
                                if stop_status == "FINISHED" and
-                                       (job.status == "ERROR" or job.status == "CANCELED") then
-                                       # write url
-                                       write_log_url(job)
+                                       (job_status == "ERROR" or job_status == "CANCELED") then
                                        # cancel all other un-finished jobs
                                        @sub_jobs.each do |sub|
-                                               if sub.status != "ERROR" and sub.status != "FINISHED" and
-                                                       sub.status != "CANCELED" and sub.event == "NONE" then
+                                               sub_status = sub.status
+                                               if sub_status != "ERROR" and sub_status != "FINISHED" and
+                                                       sub_status != "CANCELED" and sub.event == "NONE" then
                                                        @log.info(" * Sub-Job \"#{sub.get_project().name}(#{sub.os})\" has entered \"CANCELING\" state. (#{sub.id})", Log::LV_USER)
                                                        sub.event = "CANCEL"
                                                end
                                        end
 
-                                       stop_status = job.status
+                                       stop_status = job_status
                                        break
                                end
                        end
                        check_event
+                       sleep 1
                end
 
-               if stop_status == "ERROR" or stop_status == "CANCELED" then
-                       @status = stop_status
-                       return
+               if stop_status == "ERROR" then
+                       raise BuildServerException.new("ERR205")
+               elsif stop_status == "CANCELED" then
+                       @event = "CANCEL" if @event == "NONE"
+                       raise BuildServerException.new("ERR205")
                end
 
                lock_event
 
                # upload
-               if not upload() then
-                       @status = "ERROR"
-                       return
+               if not @send_result_back then 
+                       upload()
+               end
+
+               # copy result files to transport path
+               if @send_result_back then
+                       copy_result_files_to_master()
                end
 
                # INFO. don't change this string
@@ -421,33 +459,48 @@ class MultiBuildJob < CommonJob
                binpkg_path_list = Dir.glob("#{@source_path}/*_*_*.zip")
 
                # upload
-               u_client = Client.new( @pkgsvr_url, nil, @log )
+               u_client = Client.create( @pkgsvr_url, nil, @log )
+               if u_client.nil? then 
+                       raise BuildServerException.new("ERR023") 
+               end
+
                snapshot = u_client.upload( @pkgsvr_ip, @pkgsvr_port, binpkg_path_list, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd, @pkgsvr_password)
 
                if snapshot.nil? then
-                       @log.info( "Upload failed...", Log::LV_USER)
-
-                       return false
+                       raise BuildServerException.new("ERR204")
                end
 
                # update local
                @log.info( "Upload succeeded. Sync local pkg-server again...", Log::LV_USER)
                @pkgsvr_client.update
                @log.info("Snapshot: #{snapshot}", Log::LV_USER)
-
-               return true
        end
 
 
-       # write web url for log
+       # copy binary package files and log file to transport dir
        private
-       def write_log_url(job)
-               url,remote_url = job.get_log_url()
-               if not url.empty? then
-                       @log.info( " ** Log1: #{url}", Log::LV_USER)
+       def copy_result_files_to_master()
+               outgoing_dir = "#{@server.transport_path}/#{@dock_num}"
+               if not File.exist? outgoing_dir then
+                       FileUtils.mkdir_p outgoing_dir
                end
-               if not remote_url.empty? then
-                       @log.info( " ** Log2: #{remote_url}", Log::LV_USER)
+
+               # copy result files
+               copy_result_files( outgoing_dir )
+       end
+
+
+       private
+       def copy_result_files(dst_path)
+               @log.info( "Copying result files to #{dst_path}", Log::LV_USER)
+
+               # get package path list
+               binpkg_path_list = Dir.glob("#{@source_path}/*_*_*.zip")
+
+               binpkg_path_list.each do |file|
+                       @result_files.push File.basename(file)
+                       @log.info( " * #{file}", Log::LV_USER)
+                       FileUtils.ln(file,"#{dst_path}/", :force => true)
                end
        end
 
index 0695349..e5c29e2 100644 (file)
@@ -32,6 +32,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
 $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
 require "Action.rb"
 require "ScheduledActionHandler.rb"
+require "BuildServerException.rb"
 
 
 class PackageSyncAction < Action
@@ -50,6 +51,7 @@ class PackageSyncAction < Action
                @sync_root = "#{@server.path}/sync/#{my_id}"
                @download_path = "#{@sync_root}/remote"
                @original_path = "#{@sync_root}/main"
+               @user_id = nil
        end
 
 
@@ -64,10 +66,18 @@ class PackageSyncAction < Action
                FileUtils.mkdir_p @original_path
 
                # create client
-               @pkgsvr_client = Client.new( @pkgsvr_url, @download_path, @server.log )
+               @pkgsvr_client = Client.create( @pkgsvr_url, @download_path, @server.log )
+               if @pkgsvr_client.nil? then
+                       raise BuildServerException.new("ERR023")
+               end
 
                main_url = @server.distmgr.get_distribution(@dist_name).pkgsvr_url
-               @main_client = Client.new( main_url, @original_path, @server.log )
+               @main_client = Client.create( main_url, @original_path, @server.log )
+               if @main_client.nil? then
+                       raise BuildServerException.new("ERR023")
+               end
+
+               @user_id = @server.check_user_id_from_email("sync-manager@user")
        end
 
 
@@ -108,11 +118,12 @@ class PackageSyncAction < Action
                                        next
                                end
                                new_job.priority = CommonJob::AUTO_JOB_PRIORITY
+                               new_job.user_id = @user_id if @user_id != -1
 
                                # add job
                                @server.jobmgr.commit_job(new_job)
                                # create logger, this step must be done after 'commit'
-                               new_job.create_logger( nil )
+                               new_job.create_logger()
                                @server.jobmgr.add_job( new_job )
                                registered_jobs.push new_job
                        end
@@ -230,8 +241,13 @@ class PackageServerSynchronizer
                                
                                if not exist then
                                        new_time = Time.new + 10
-                                       @handler.register( PackageSyncAction.new(new_time, url, dist_name, @server) )
-                                       @server.log.info "Registered package-sync action!: #{dist_name} <= \"#{url}\""
+                                       begin
+                                               @handler.register( PackageSyncAction.new(new_time, url, dist_name, @server) )
+                                               @server.log.info "Registered package-sync action!: #{dist_name} <= \"#{url}\""
+                                       rescue BuildServerException => e
+                                               @server.log.error e.message
+                                               @server.log.error "Registering package-sync action failed!: #{dist_name} <= \"#{url}\""
+                                       end     
                                end
                        end
 
index c717213..73aa601 100644 (file)
@@ -89,7 +89,7 @@ class ProjectManager
        end
 
 
-       def add_git_project(name, repos, branch, passwd, os_list, dist_name)
+       def add_git_project(name, repos, branch, os_list, dist_name)
                new_prj = nil
                result = @server.get_db_connection() do |db|
                        prj = get_project_internal(name, dist_name, db)
@@ -100,9 +100,6 @@ class ProjectManager
                                
                        # create new object
                        new_prj = GitBuildProject.new(name, @server, os_list, dist_name, repos, branch)
-                       if not passwd.nil? and not passwd.empty? then
-                               new_prj.passwd = passwd
-                       end
 
                        # save to db
                        new_prj.save(db)
@@ -118,7 +115,7 @@ class ProjectManager
        end
 
 
-       def add_binary_project(name, pkg_name, passwd, os_list, dist_name)
+       def add_binary_project(name, pkg_name, os_list, dist_name)
                new_prj = nil
                result = @server.get_db_connection() do |db|
                        prj = get_project_internal(name, dist_name, db)
@@ -129,9 +126,6 @@ class ProjectManager
                        
                        # create new object
                        new_prj = BinaryUploadProject.new(name, @server, os_list, dist_name, pkg_name)
-                       if not passwd.nil? and not passwd.empty? then
-                               new_prj.passwd = passwd
-                       end
 
                        # save to db
                        new_prj.save(db)
@@ -223,35 +217,6 @@ class ProjectManager
        end
 
 
-       # create new full job
-       def create_new_full_build_job(dist_name="BASE")
-               # create multi job
-               result = MultiBuildJob.new( @server )
-
-               # create sub jobs
-               get_all_projects().each do |prj|
-                       if prj.type != "GIT" then next end
-                       if prj.dist_name != dist_name then next end
-
-                       prj.os_list.each do |os|
-                               if not @server.supported_os_list.include? os then next end
-
-                               new_job = create_new_job( prj.name, os, dist_name )
-                               if new_job.nil? then next end
-
-                               # This make project to build
-                               # even though there is a package of same version on pkg-server
-                               new_job.set_force_rebuild(true)
-
-                               # add to multi job
-                               result.add_sub_job( new_job )
-                       end
-               end
-
-               return result
-       end
-
-
        # get project that includes specified pkg name and os
        # will return [project,os,ver] list
        def get_projects_from_pkgs(pkgs, dist_name="BASE")
@@ -299,18 +264,9 @@ class ProjectManager
        end
 
 
-       def create_unnamed_git_project(repos, dist_name)
-               name = "UNNAMED_PRJ_#{get_all_projects().count}"
-               branch = "master"
-               passwd = nil
-               os_list = Utils.get_all_OSs()
-               os_list.each do |os|
-                       @server.add_supported_os(os)
-               end
-               # add
-               add_git_project(name , repos, branch, passwd, os_list, dist_name)
-               # get
-               return get_project(name, dist_name)
+       # this project will not be saved on DB
+       def create_transferred_git_project(repos, dist_name, os)
+               return GitBuildProject.new(nil, @server, [os], dist_name, repos, "master")
        end
 
 
index 53f9104..726b609 100644 (file)
@@ -34,17 +34,18 @@ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/plkg_server"
 require "client.rb"
 require "PackageManifest.rb"
 require "Version.rb"
-require "JobLog.rb"
 require "mail.rb"
 require "utils.rb"
 require "ReverseBuildChecker.rb"
 require "CommonJob.rb"
+require "JobLog.rb"
+require "BuildServerException.rb"
 
 class RegisterPackageJob < CommonJob
 
        attr_accessor :source_path
-       attr_accessor :pkgsvr_client, :thread, :pkg_type
-       attr_accessor :pkg_name, :pkginfo
+       attr_accessor :pkgsvr_client, :pkg_type
+       attr_accessor :pkg_name, :pkginfo, :pkg_version
        attr_accessor :no_reverse
 
 
@@ -80,6 +81,7 @@ class RegisterPackageJob < CommonJob
                else
                        @pkg_type = "ARCHIVE"
                        @pkg_name = @filename
+                       @pkg_version = "0"
                end
                @pkginfo = nil #This info is valid only for BINARY package
                @project = project
@@ -118,8 +120,22 @@ class RegisterPackageJob < CommonJob
                @no_reverse = true
        end
 
+
+       def set_send_result_back( dock_num )
+               # do nothing
+       end
+
+
+       def is_send_result_back?
+               return false
+       end
+
+
        def execute_shell(cmd)
+               # if canceled, must prevent invoking more process
+               check_event
                ret = Utils.execute_shell(cmd)
+               # if canceled, must exit job thread
                check_event
                return ret
        end
@@ -137,7 +153,7 @@ class RegisterPackageJob < CommonJob
 
                # create logger
                if @log.nil? then
-                       @log = JobLog.new(self, nil )
+                       @log = JobLog.new(self)
                end
 
                @log.info( "Initializing job...", Log::LV_USER)
@@ -150,28 +166,28 @@ class RegisterPackageJob < CommonJob
                # copy package file to source path
                @file_path = "#{@source_path}/#{File.basename(@local_path)}"
                if not File.exist? @local_path then
-                       @log.error( "File not found!", Log::LV_USER)
-                       @status = "ERROR"
-                       return false
+                       raise BuildServerException.new("ERR107"), @local_path
+               end
+
+               if @auto_remove then
+                       # if remote upload remove file and its directory
+                       FileUtils.mv(@local_path, @file_path)
+                       FileUtils.rm_rf("#{File.dirname(@local_path)}")
                else
-                       if @auto_remove then
-                               # if remote upload remove file and its directory
-                               FileUtils.mv(@local_path, @file_path)
-                               FileUtils.rm_rf("#{File.dirname(@local_path)}")
-                       else
-                               FileUtils.cp(@local_path, @file_path)
-                       end
+                       FileUtils.ln(@local_path, @file_path, :force => true)
                end
 
                # set up pkgsvr_client
-               @pkgsvr_client =  Client.new(@pkgsvr_url, @job_working_dir, @log)
+               @pkgsvr_client =  Client.create(@pkgsvr_url, @job_working_dir, @log)
+               if @pkgsvr_client.nil? then
+                       raise BuildServerException.new("ERR023")
+               end
 
                # check if the os is supported by build server
                if @pkg_type == "BINARY" and
                        not @server.supported_os_list.include? @os then
-                       @log.error( "Unsupported OS \"#{@os}\" is used!", Log::LV_USER)
-                       @status = "ERROR"
-                       return false
+
+                       raise BuildServerException.new("ERR108"), @os
                end
 
                # checking version if not reverse-build job
@@ -179,29 +195,24 @@ class RegisterPackageJob < CommonJob
                        # extrac pkg file
                        cmd = "cd \"#{@source_path}\";unzip #{@file_path}"
                        if not execute_shell(cmd) then
-                               @log.error( "Extracting package file failed!", Log::LV_USER)
-                               @status = "ERROR"
-                               return false
+                               raise BuildServerException.new("ERR109"), @file_path
+                       end
+
+                       # check pkginfo.manifest
+                       if not File.exist? "#{@source_path}/pkginfo.manifest" then
+                               raise BuildServerException.new("ERR100")
                        end
 
                        # set up pkg info
                        begin
                                @pkginfo = PackageManifest.new("#{@source_path}/pkginfo.manifest")
                        rescue => e
-                               @log.error( e.message, Log::LV_USER)
-                               @status = "ERROR"
-                               return false
+                               raise BuildServerException.new("ERR101"), e.message
                        end
 
-                       #if @server.changelog_check and not @pkginfo.packages[0].does_change_exist? then
-                       #       @log.error( "change log not found", Log::LV_USER )
-                       #       return false
-                       #end
+                       # TODO: need to check change log file 
 
-                       if not check_package_version() then
-                               @status = "ERROR"
-                               return false
-                       end
+                       check_package_version()
                end
 
                return true
@@ -233,14 +244,6 @@ class RegisterPackageJob < CommonJob
        end
 
 
-       #cancel
-       def cancel()
-               if not @log.nil? then
-                       @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
-               end
-       end
-
-
        # check building is possible
        def can_be_built_on?(host_os)
                return true
@@ -266,6 +269,30 @@ class RegisterPackageJob < CommonJob
        end
 
 
+       def is_same_with?(wjob)
+               # must have same distribution
+               if get_distribution_name() != wjob.get_distribution_name() then
+                       return false
+               end
+
+               if @type != wjob.type then return false end
+
+               case @pkg_type
+               when "BINARY"
+                       if @pkg_name == wjob.pkg_name and
+                               @pkg_version == wjob.pkg_version and
+                               wjob.pkginfo.packages.count == 1 and
+                               wjob.pkginfo.packages[0].os_list.include?(@os) then
+                               return true
+                       end
+               when "ARCHIVE"
+                       if @pkg_name == wjob.pkg_name then return true end
+               end
+
+               return false
+       end
+
+
        def is_compatible_with?(o)
                return false
        end
@@ -338,11 +365,6 @@ class RegisterPackageJob < CommonJob
        end
 
 
-       def is_connected?
-               return true
-       end
-
-
        # return the job is asyncronous job
        def is_asynchronous_job?
                return false
@@ -357,10 +379,10 @@ class RegisterPackageJob < CommonJob
        def get_log_url()
                # only when server support log url
                if @server.job_log_url.empty? then
-                       return "",""
+                       return ""
                end
 
-               return "#{@server.job_log_url}/#{@id}/log",""
+               return "#{@server.job_log_url}/#{@id}/log"
        end
 
        #
@@ -372,14 +394,11 @@ class RegisterPackageJob < CommonJob
        protected
        def job_main()
                @log.info( "Invoking a thread for REGISTER Job #{@id}", Log::LV_USER)
-               if @status == "ERROR" then return  end
                @log.info( "New Job #{@id} is started", Log::LV_USER)
 
                # clean build
                if not ReverseBuildChecker.check( self, true ).empty? then
-                       @status = "ERROR"
-                       @log.error( "Reverse-build-check failed!" )
-                       return
+                       raise BuildServerException.new("ERR203")
                end
 
                # if this package has compatible OS, check
@@ -401,14 +420,12 @@ class RegisterPackageJob < CommonJob
                                # make new package file for compatible OS
                                newfile = "#{@pkg_name}_#{@pkg_version}_#{os}.zip"
                                @log.info( "Copying #{@filename} to #{newfile}" )
-                               FileUtils.cp(@file_path,"#{@source_path}/#{newfile}")
+                               FileUtils.ln(@file_path,"#{@source_path}/#{newfile}",:force => true)
 
                                # reverse check
                                if not @no_reverse then
                                        if not ReverseBuildChecker.check( self, true, os ) then
-                                               @status = "ERROR"
-                                               @log.error( "Reverse-build-check failed!" )
-                                               return
+                                               raise BuildServerException.new("ERR203")
                                        end
                                end
                        end
@@ -417,10 +434,7 @@ class RegisterPackageJob < CommonJob
                lock_event
 
                # upload
-               if not upload() then
-                       @status = "ERROR"
-                       return
-               end
+               upload()
 
                # INFO. don't change this string
                @log.info( "Job is completed!", Log::LV_USER)
@@ -501,21 +515,21 @@ class RegisterPackageJob < CommonJob
                end
 
                # upload
-               u_client = Client.new( @pkgsvr_url, nil, @log )
+               u_client = Client.create( @pkgsvr_url, nil, @log )
+               if u_client.nil? then
+                       raise BuildServerException.new("ERR023")
+               end
+
                snapshot = u_client.upload( @pkgsvr_ip, @pkgsvr_port, binpkg_path_list, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd, @pkgsvr_password)
 
                if snapshot.nil? then
-                       @log.info( "Upload failed...", Log::LV_USER)
-
-                       return false
+                       raise BuildServerException.new("ERR204")
                end
 
                # update local
                @log.info( "Upload succeeded. Sync local pkg-server again...", Log::LV_USER)
                @pkgsvr_client.update
                @log.info("Snapshot: #{snapshot}", Log::LV_USER)
-
-               return true
        end
 
 
@@ -531,8 +545,7 @@ class RegisterPackageJob < CommonJob
                        #ver_svr = @pkgsvr_client.get_package_version( pkg.package_name, @os )
                        ver_svr = @pkgsvr_client.get_attr_from_pkg( pkg.package_name, @os, "version")
                        if not ver_svr.nil? and Version.new(ver_local) <= Version.new(ver_svr) then
-                               @log.error( "Version must be increased : #{ver_local} <= #{ver_svr}", Log::LV_USER)
-                               return false
+                               raise BuildServerException.new("ERR105"), "#{ver_local} <= #{ver_svr}"
                        end
                end
 
index 78d3fa9..413686a 100644 (file)
@@ -34,25 +34,32 @@ require "PackageManifest"
 require "log"
 require "FileTransferViaFTP"
 require "FileTransferViaDirect"
+require "BuildServerException.rb"
+
 
 class RemoteBuilder
-       attr_accessor :id, :log
+       attr_accessor :log
 
        # initialize
-       def initialize( id, server,ftp_addr, ftp_port, ftp_username, ftp_passwd)
-               @id = id
-               @server = server
-               @addr = server.ip
-               @port = server.port
+       def initialize( addr, port ,ftp_addr, ftp_port, ftp_username, ftp_passwd)
+               @addr = addr
+               @port = port
                @ftp_addr = ftp_addr
                @ftp_port = ftp_port
                @ftp_username = ftp_username
                @ftp_passwd = ftp_passwd
-               @log = DummyLog.new
+
+               @log = StandardOutLogPrinter.new
                @job = nil
        end
 
 
+       def RemoteBuilder.create_from_server(rserver, ftp_addr, ftp_port, ftp_username, ftp_passwd)
+
+               return RemoteBuilder.new(rserver.ip, rserver.port, ftp_addr, ftp_port, ftp_username, ftp_passwd)
+       end
+
+
        # build_job
        def build_job( job, local_pkgs )
                # set job
@@ -61,9 +68,20 @@ class RemoteBuilder
                @log = job.log
 
                # build
-               ret = build(@job.get_project().repository, @job.source_path, @job.os,
-                                       @job.is_rev_build_check_job(), @job.git_commit, @job.no_reverse,
-                                       local_pkgs, @job.get_project().dist_name,"admin@user" )
+               options = RemoteBuilder.init_options()
+               options[:git_repos] = @job.get_project().repository
+               options[:git_commit] = @job.git_commit
+               options[:src_path] = @job.source_path
+               options[:os] = @job.os
+               options[:noreverse] = @job.no_reverse
+               options[:local_pkgs] = local_pkgs
+               options[:dist] = @job.get_project().dist_name
+               options[:user] = "admin@user"
+               options[:is_rev_build] = @job.is_rev_build_check_job()
+               options[:dock] = Utils.create_uniq_name()
+               options[:save] = @job.is_rev_build_check_job() ? false : true
+               options[:pkgsvr_url] = @job.server.distmgr.get_distribution(options[:dist]).pkgsvr_url
+               ret = build( options )
 
                # reset job
                @job = nil
@@ -75,57 +93,117 @@ class RemoteBuilder
 
 
        # build
-       def build( git_repos, source_path, os, is_rev_build, srcinfo, no_reverse, local_pkgs, dist_name, user_email )
-               @log.info( "Start to build on remote server...", Log::LV_USER )
-
-               # create unique dock number
-               dock = Utils.create_uniq_name()
-
-               # send local packages
-               begin
-                       @server.add_file_transfer()
-                       local_pkgs.each do |pkg_path|
-                               @log.info( "Sending file... : #{pkg_path}", Log::LV_USER )
-                               result = send_file_to_remote( pkg_path, dock )
-                               if not result then
-                                       @log.error( "File transfering failed!", Log::LV_USER )
-                                       @server.remove_file_transfer()
-                                       return false
+       def build( options )
+               @log.info( "Start to build on remote server...", Log::LV_USER ) if not @job.nil?
+
+               # send local packages if build is invoked from JOB
+               if not @job.nil? and not options[:local_pkgs].empty? then
+                       begin
+                               @job.add_timestamp("REMOTE_UPLOAD_START")
+                               @job.get_remote_server().add_file_transfer()
+                               options[:local_pkgs].each do |pkg_path|
+                                       @log.info( "Sending file... : #{pkg_path}", Log::LV_USER )
+                                       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()
+                                               return false
+                                       end
                                end
+                       ensure
+                               @job.get_remote_server().remove_file_transfer()
+                               @job.add_timestamp("REMOTE_UPLOAD_END")
                        end
-               ensure
-                       @server.remove_file_transfer()
                end
 
                # send build request
-               @log.info( "Sending build request to remote server...", Log::LV_USER )
-               result, result_files = send_build_request(git_repos, os, is_rev_build,
-                                                                                                 srcinfo, no_reverse, local_pkgs, dock, dist_name, user_email, @log.is_verbose)
+               @log.info( "Sending build request to remote server...", Log::LV_USER ) if not @job.nil?
 
-               @log.info( "Receiving log file from remote server...", Log::LV_USER )
-               if not receive_file_from_remote( "#{source_path}/../remote_log", dock ) then
-                       @log.warn( "File transfering failed! : remote_log", Log::LV_USER )
+               result, job_id, job_error = send_build_request( options )
+               if not result then
+                       @log.error( job_error, Log::LV_USER ) if not job_error.nil?
+                       @log.error( "Building job request on remote server failed!", Log::LV_USER ) if not @job.nil?
+                       return false
+               end
+
+               if options[:async] then return result end
+
+               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 )
+
+                       #Cancel remote job
+                       if not @job.nil? then
+                               begin
+                                       client = BuildCommClient.create( @addr, @port, @log )
+                                       if not client.nil? then
+                                               client.send "CANCEL|#{@job.remote_id}|#{@job.get_project.passwd}|admin@user"
+                                               client.receive_data()
+                                               client.terminate
+                                       end
+                               rescue e
+                                       @log.error(e, Log::LV_USER)
+                               end
+                       end
                        return false
                end
 
-               # receive binary package
-               result_files.each do |file_name|
-                       @log.info( "Receiving file from remote server : #{file_name}", Log::LV_USER )
-                       result = receive_file_from_remote( "#{source_path}/#{file_name}", dock )
-                       if not result then
-                               @log.error( "File transfering failed! : #{file_name}", Log::LV_USER )
-                               return false
+               # receive binary package if not reverse build
+               if options[:save] then
+                       @job.add_timestamp("REMOTE_DOWNLOAD_START") if not @job.nil?
+                       result_files.each do |file_name|
+                               @log.info( "Receiving file from remote server : #{file_name}", Log::LV_USER )
+                               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
+                               end
                        end
+                       @job.add_timestamp("REMOTE_DOWNLOAD_END") if not @job.nil?
                end
 
                return true
        end
 
 
+       protected 
+       def RemoteBuilder.init_options()
+               options = {}
+               options[:projects] = nil
+               options[:passwd] = nil
+               options[:git_repos] = nil
+               options[:git_commit] = nil
+               options[:src_path] = nil
+               options[:os] = nil
+               options[:noreverse] = false
+               options[:local_pkgs] = []
+               options[:dist] = nil
+               options[:user] = nil
+               options[:is_rev_build] = false
+               options[:rebuild] = false
+               options[:save] = false
+               options[:async] = false
+               options[:monitor_level] = Log::LV_NORMAL
+               options[:pkgsvr_url] = nil
+
+               return options
+       end
+
+
        # upload binary packages that is need to be overwrite
        # before remote package
        protected
@@ -161,65 +239,215 @@ class RemoteBuilder
        end
 
 
-       # send build request
        protected
-       def send_build_request(git_repos, os, is_rev_build, commit, no_reverse, local_pkgs, dock, dist_name, user_email, verbose)
-               result_files = []
+       def send_file_to_remote2(file_path, dock = "0")
+               result = true
 
-               client = BuildCommClient.create( @addr, @port, @log )
-               if client.nil? then
-                       @log.error( "Creating communication client failed!", Log::LV_USER)
-                       return false, result_files
+               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
 
-               # get local package names
-               local_pkg_names = local_pkgs.map { |path| File.basename(path) }
+               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
 
-               # send
-               #          0   | 1 |    2     |   3  | 4|  5  |     6    |    7    |    8     |   9   |   10   |   11    |  12  | 13 |  14
-               # format: BUILD|GIT|repository|passwd|os|async|no_reverse|dist_name|user_email|verbose|internal|rev-build|commit|pkgs|dock_num
-               # value : BUILD|GIT|repository|      |os|NO   |no_reverse|dist_name|user_email|verbose|YES     |rev-build|commit|pkgs|dock_num
-               result = true
-               commit = commit.nil? ? "":commit
-               pkg_list = local_pkg_names.join(",")
-               rev = is_rev_build ? "YES":"NO"
-               msg = "BUILD|GIT|#{git_repos}||#{os}|NO|#{no_reverse}|#{dist_name}|#{user_email}|#{verbose}|YES|#{rev}|#{commit}|#{pkg_list}|#{dock}"
-               result = client.send( msg )
-               if not result then
-                       @log.error( "Communication failed! #{client.get_error_msg()}", Log::LV_USER)
-                       return false, result_files
+               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
 
-               r_job_number = Regexp.new('Added new job "([^"]*)"')
-               error = false
-               result = client.read_lines do |l|
-                       # write log first
-                       @log.output( l.strip, Log::LV_USER)
+               return result
+       end
+
+
+       # send build request
+       protected
+       def send_build_request( options )
+               result = true
+               job_id = nil
+               job_status = ""
+               job_error = nil
 
-                       # set remote job id
-                       if not @job.nil? and  @job.remote_id.nil? and l =~ r_job_number then
-                               @job.remote_id = $1
+               begin
+                       client = BuildCommClient.create( @addr, @port, @log )
+                       if client.nil? then
+                               raise BuildServerException.new("ERR018"), "#{@addr}:#{@port}"
+                       end
+
+                       if not options[:git_repos].nil? then
+                               commit = options[:git_commit].nil? ? "" : options[:git_commit]
+                               pkg_list = options[:local_pkgs].map { |path| File.basename(path) }.join(",")
+                               # format: BUILD|GIT|repository|passwd|os|async|
+                               #         no_reverse|dist_name|
+                               #         user_email|rebuild|internal|rev-build|
+                               #         commit|pkgs|dock_num|pkgsvr_url
+                               msg = "BUILD|GIT|#{options[:git_repos]}||#{options[:os]}|NO|"+
+                                       "#{options[:noreverse] ? "YES" : "NO"}|#{options[:dist]}|"+
+                                       "#{options[:user]}|NO|YES|#{options[:is_rev_build] ? "YES":"NO"}|"+
+                                       "#{commit}|#{pkg_list}|#{options[:dock]}|#{options[:pkgsvr_url]}"
+                       else
+                               # format: BUILD|GIT|project_list|passwd|
+                               #         os|async|
+                               #                 no_reverse|dist_name|
+                               #         user_email|rebuild
+                               #         internal|rev-build|commit|pkgs|dock_num
+                               msg = "BUILD|GIT|#{options[:projects]}|#{options[:passwd]}|"+
+                                       "#{options[:os]}|"+
+                                       "#{options[:async] ? "YES" : "NO"}|"+
+                                       "#{options[:noreverse] ? "YES" : "NO"}|#{options[:dist]}|"+
+                                       "#{options[:user]}|#{options[:rebuild] ? "YES" : "NO"}|"+
+                                       "NO||||#{options[:dock].nil? ? "" : options[:dock]}"
                        end
 
-                       # check build result
-                       if l.include? "Job is stopped by ERROR" or
-                               l.include? "Error:" then
-                               error = true
+                       if not client.send( msg ) then
+                               raise BuildServerException.new("ERR020"), "#{client.get_error_msg()}"
                        end
 
-                       # gather result files if not reverse build
-                       if not is_rev_build and l =~ /Creating package file \.\.\. (.*)/ then
-                               file_name = $1
-                               result_files.push file_name
+                       result = client.read_lines do |line|
+                               if 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
+                                       @log.output( line.strip, Log::LV_USER)
+                               end
                        end
+               
+                       if not result then
+                               raise BuildServerException.new("ERR019"), "#{client.get_error_msg()}"
+                       end
+                       if job_id.nil? then
+                               result = false
+                       end
+
+                       @job.remote_id = job_id if not @job.nil?
+                       @job.remote_status = job_status if not @job.nil?
+                       @job.remote_error_msg = job_error if not @job.nil?
+               rescue BuildServerException => e
+                       @log.error( e.err_message(""), Log::LV_USER )
+                       result = false
+               rescue => e
+                       @log.error( "#{e.message()}", Log::LV_USER )
+                       result = false
+               ensure
+                       client.terminate if not client.nil?
                end
-               if not result then
-                       @log.error( "Communication failed! #{client.get_error_msg()}", Log::LV_USER)
+
+               return result, job_id, job_error
+       end
+
+
+       # send monitor request
+       protected
+       def send_monitor_request(job_id, min_level)
+               result_files = []
+               result = true
+               job_status = "JUST_CREATED"
+
+               begin
+                       result = JobLog.monitor(@addr, @port, job_id) do |line,status,errmsg|
+                               job_status = status
+                               @job.remote_status = status if not @job.nil?
+                               @job.remote_error_msg = errmsg if not @job.nil?
+                               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 )
+                               elsif category == "WARN" then
+                                       @log.warn( contents, level )
+                               elsif category == "ERROR" then
+                                       @log.error( contents, level )
+                               else
+                                       next
+                               end
+                       end
+
+               rescue BuildServerException => e
+                       @log.error( e.err_message(""), Log::LV_USER )
+                       result = false
+               rescue => e
+                       @log.error( "#{e.message()}", Log::LV_USER )
+                       result = false
                end
-               if error then result=false end
 
-               # close socket
-               client.terminate
+               if job_status != "FINISHED" then
+                       if not @job.nil? then 
+                               @log.error( "Remote job is finished with \"#{@job.remote_status}\"! #{@job.remote_error_msg}", Log::LV_USER)
+                       end
+                       result = false 
+               end
+
+               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
@@ -256,4 +484,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
index 5fe2ea2..990be4b 100644 (file)
@@ -32,7 +32,6 @@ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
 $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/pkg_server"
 require "utils.rb"
 require "client.rb"
-require "JobLog.rb"
 require "PackageManifest.rb"
 
 class ReverseBuildChecker
@@ -83,22 +82,6 @@ class ReverseBuildChecker
                        if rev_prj.type != "GIT" then next end
                        found = false
 
-                       ## if job on resolve process, its unresolved project
-                       ##of pending ancestor must be excluded.
-                       #if job.type == "BUILD" and not job.pending_ancestor.nil? then
-                       #       found = false
-                       #       job.pending_ancestor.rev_fail_projects.each do  |fp|
-                       #               f_prj = fp[0]
-                       #               f_os =  fp[1]
-
-                       #               if rev_prj == f_prj and rev_os == f_os then
-                       #                       found = true
-                       #                       break
-                       #               end
-                       #       end
-                       #       if found then next end
-                       #end
-
                        # if this is sub job, all other sibling job must be excluded
                        if job.is_sub_job? then
                                job.get_parent_job().get_sub_jobs().each do |sub_job|
@@ -119,6 +102,9 @@ class ReverseBuildChecker
                        # set user id
                        new_job.user_id = job.user_id
 
+                       # commit to DB
+                       job.server.jobmgr.commit_job(new_job)
+
                        rev_build_jobs.push new_job
                end
 
@@ -155,7 +141,6 @@ class ReverseBuildChecker
                                        if not is_project_included?(failure_list, rev_prj, rev_os) then
                                                log.info( " * Reverse-build FAIL ... #{rev_prj.name}(#{rev_os}) (#{rev_job.id})", Log::LV_USER)
                                                failure_list.push [ rev_prj, rev_os ]
-                                               write_log_url(log, rev_job)
                                        end
 
                                        #  if "exist on error" cancel all other jobs
@@ -205,17 +190,4 @@ class ReverseBuildChecker
 
                return false
        end
-
-
-       # write web url for log
-       private
-       def self.write_log_url(log, job)
-               url,remote_url = job.get_log_url()
-               if not url.empty? then
-                       log.info( " ** Log1: #{url}", Log::LV_USER)
-               end
-               if not remote_url.empty? then
-                       log.info( " ** Log2: #{remote_url}", Log::LV_USER)
-               end
-       end
 end
index a6dbba1..f0caca5 100644 (file)
@@ -27,7 +27,6 @@ Contributors:
 =end
 
 $LOAD_PATH.unshift File.dirname(__FILE__)
-require "JobLog.rb"
 require "BuildComm.rb"
 require "BuildServerException.rb"
 
@@ -126,8 +125,6 @@ class SocketJobRequestListener
                case  cmd
                when "BUILD"
                        handle_cmd_build( req_line, req )
-               #when "RESOLVE"
-               #       handle_cmd_resolve( req_line, req )
                when "QUERY"
                        handle_cmd_query( req_line, req )
                when "CANCEL"
@@ -136,12 +133,12 @@ class SocketJobRequestListener
                        handle_cmd_stop( req_line, req )
                when "UPGRADE"
                        handle_cmd_upgrade( req_line, req )
-               when "FULLBUILD"
-                       handle_cmd_fullbuild( req_line, req )
                when "REGISTER"
                        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
@@ -178,7 +175,7 @@ class SocketJobRequestListener
                        handle_cmd_build_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)
                end
@@ -199,30 +196,32 @@ class SocketJobRequestListener
                end
 
                #          0  | 1 |     2      |  3   |  4    |  5  |     6    |    7    |   8      |   9   |   10   |    11   |  12  | 13 |   14
-               # Case1. BUILD|GIT|project_name|passwd|os_list|async|no_reverse|dist_name|user_email|verbose
-               # Case2. BUILD|GIT|git_repos   |      |os     |async|no_reverse|dist_name|user_email|verbose|internal|rev_build|commit|pkgs|dock_num
+               # Case1. BUILD|GIT|project_name|passwd|os_list|async|no_reverse|dist_name|user_email|rebuild
+               # Case2. BUILD|GIT|git_repos   |      |os     |async|no_reverse|dist_name|user_email|rebuild|internal|rev_build|commit|pkgs|dock_num
 
                # parse
                project_name_list = tok[2].split(",")
-               passwd_list = tok[3].split(",")
-               passwd = passwd_list[0]
+               passwd = tok[3]
                os_list = tok[4].split(",")
                async = tok[5].eql? "YES"
                no_reverse = tok[6].eql? "YES"
                dist_name = (not tok[7].nil? and not tok[7].empty?) ? tok[7].strip : ""
                user_email = (not tok[8].nil? and not tok[8].empty?) ? tok[8].strip : ""
-               verbose = tok[9].eql? "YES"
+               rebuild = tok[9].eql? "YES"
                is_internal = tok[10].eql? "YES"
                rev_job = tok[11].eql? "YES"
                git_commit = (not tok[12].nil? and not tok[12].empty?) ? tok[12] : nil
                pkg_files = (not tok[13].nil? and not tok[13].empty?) ? tok[13].split(",") : []
                dock_num = (not tok[14].nil? and not tok[14].empty?) ? tok[14].strip : "0"
+               pkgsvr_url = (not tok[15].nil? and not tok[15].empty?) ? tok[15].strip : nil
                if (dist_name.nil? or dist_name.empty?) then
                        dist_name = @parent_server.distmgr.get_default_distribution_name()
                end
 
                # check distribution
-               check_distribution(dist_name, req)
+               if not is_internal then
+                       check_distribution(dist_name, req)
+               end
 
                # check supported os if not internal job
                if not is_internal then
@@ -230,9 +229,16 @@ class SocketJobRequestListener
                end
 
                # check user email
-               user_id = @parent_server.check_user_id_from_email( user_email )
-               if user_id == -1 then
-                       raise BuildServerException.new("ERR004"), user_email
+               if not is_internal then
+                       user_id = @parent_server.check_user_id_from_email( user_email )
+                       if user_id == -1 then
+                               raise BuildServerException.new("ERR004"), user_email
+                       end
+               end
+
+               # check user psssword
+               if not is_internal and not @parent_server.check_user_password(user_id, passwd) then
+                       raise BuildServerException.new("ERR011"), "Email : #{user_email} && Password : #{passwd}"
                end
 
 
@@ -241,9 +247,7 @@ class SocketJobRequestListener
                        new_job_list = []
                        i = 0
                        project_name_list.each do |pname|
-                               if not passwd_list[i].nil? then passwd = passwd_list[i]
-                               else passwd = passwd_list[0] end
-                               check_build_project(pname,passwd,dist_name,req)
+                               check_build_project(pname,dist_name,req)
                                if not check_project_user_id(pname,dist_name,user_id) then
                                        raise BuildServerException.new("ERR005"), "#{user_email} -> #{pname}"
                                end
@@ -274,12 +278,12 @@ class SocketJobRequestListener
                                raise BuildServerException.new("ERR006"),"No valid sub jobs in Multi-Build job"
                        end
 
-                       # transfered job
+                       # transferred job
                elsif is_internal then
                        git_repos = project_name_list[0]
                        os = os_list[0]
 
-                       new_job = create_new_internal_job(git_repos, os, git_commit, pkg_files, dock_num, dist_name )
+                       new_job = create_new_transferred_job(git_repos, os, git_commit, pkg_files, dock_num, dist_name, pkgsvr_url )
                        if new_job.nil? then
                                raise BuildServerException.new("ERR006"),"Transfered-Build job"
                        else
@@ -292,7 +296,7 @@ class SocketJobRequestListener
                        pname = project_name_list[0]
                        os = os_list[0]
 
-                       check_build_project(pname,passwd,dist_name,req)
+                       check_build_project(pname,dist_name,req)
                        if not check_project_user_id(pname,dist_name,user_id) then
                                raise BuildServerException.new("ERR005"), "#{user_email} -> #{pname}"
                        end
@@ -309,25 +313,30 @@ class SocketJobRequestListener
                # check reverse build
                if no_reverse then new_job.set_no_reverse end
 
+               # set force rebuild if needed
+               if rebuild then new_job.set_force_rebuild(true) end
+
+               # set send result back
+               if dock_num != "0" and not is_internal then
+                       new_job.set_send_result_back( dock_num )
+               end
+
                @parent_server.jobmgr.commit_job(new_job)
 
-               # create logger and set
+               # create logger and disconnect client
+               logger = new_job.create_logger(false)
+               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)
+               end
+
                if async then
-                       new_job.create_logger( nil, verbose)
                        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!")
-                       BuildCommServer.send_end(req)
-                       BuildCommServer.disconnect(req)
-               else
-                       logger = new_job.create_logger( req, verbose)
-                       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)
-                       end
                end
+               BuildCommServer.send_end(req)
+               BuildCommServer.disconnect(req)
 
                # add to job queue
                if new_job.is_rev_build_check_job() then
@@ -338,13 +347,15 @@ class SocketJobRequestListener
        end
 
 
-       def check_build_project(prj_name, passwd, dist_name, req)
+       def check_build_project(prj_name, dist_name, req)
                # check project
                prj = check_project_exist(prj_name, dist_name, req)
 
-               # check passwd
-               check_project_password(prj, passwd, req)
-
+               # check project status
+               if prj.status != "OPEN" then
+                       raise BuildServerException.new("ERR017"), "#{prj_name} on #{dist_name}. project is [[#{prj.status}]]"
+               end
+               
                # check project type
                if prj.type == "BINARY" then
                        raise BuildServerException.new("ERR010"), prj.type
@@ -352,106 +363,6 @@ class SocketJobRequestListener
        end
 
 
-       ## "RESOLVE"
-       #def handle_cmd_resolve( line, req )
-       #       @log.info "Received REQ: #{line}"
-
-       #       begin
-       #               handle_cmd_resolve_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}"
-       #end
-
-
-       #def handle_cmd_resolve_internal( line ,req)
-       #       tok = line.split("|").map { |x| x.strip }
-       #       if tok.count < 3 then
-       #               raise BuildServerException.new("ERR001"), line
-       #       end
-
-       #       case tok[1]
-       #               # RESOLVE|GIT|project_name|passwd|os|async|dist_name|user_email|verbose
-       #       when "GIT"
-
-       #               # parse
-       #               project_name=tok[2]
-       #               passwd=tok[3]
-       #               os=tok[4]
-       #               async = tok[5].eql? "YES"
-       #               dist_name = tok[6]
-       #               user_email = (not tok[7].nil? and not tok[7].empty?) ? tok[7].strip : ""
-       #               verbose = tok[8].eql? "YES"
-       #               if (dist_name.nil? or dist_name.empty?) then
-       #                       dist_name = @parent_server.distmgr.get_default_distribution_name()
-       #               end
-
-       #               # check distribution
-       #               check_distribution(dist_name, req)
-
-       #               # check project
-       #               prj = check_project_exist(project_name, dist_name, req)
-
-       #               # check passwd
-       #               check_project_password(prj, passwd, req)
-
-       #               # check os
-       #               os_list = check_supported_os( [os] , req )
-       #               os = os_list[0]
-
-       #               # check user email
-       #               user_id = @parent_server.check_user_id_from_email( user_email )
-       #               if user_id == -1 then
-       #                       raise BuildServerException.new("ERR004"), user_email
-       #               end
-
-       #               # check user accessable
-       #               if not check_project_user_id(project_name,dist_name,user_id) then
-       #                       raise BuildServerException.new("ERR005"), "#{user_email} -> #{project_name}"
-       #               end
-
-       #               # create new job
-       #               new_job = create_new_job( project_name, os, dist_name )
-       #               if new_job.nil? then
-       #                       raise BuildServerException.new("ERR006"), "Resolve job #{project_name} #{os}"
-       #               end
-       #               @log.info "Received a request for resolving this project : #{project_name}, #{os}"
-
-       #               new_job.user_id = user_id
-
-       #               # resolve
-       #               new_job.set_resolve_flag()
-
-       #               # create logger and set
-       #               if async then
-       #                       new_job.create_logger( nil, verbose)
-       #                       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!")
-       #                       BuildCommServer.send_end(req)
-       #                       BuildCommServer.disconnect(req)
-       #               else
-       #                       logger = new_job.create_logger( req, verbose)
-       #                       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)
-       #                       end
-       #               end
-
-       #               @parent_server.jobmgr.add_job( new_job )
-       #       else
-       #               raise BuildServerException.new("ERR001"), line
-       #       end
-       #end
-
-
        # "QUERY"
        def handle_cmd_query( line, req )
                begin
@@ -592,43 +503,51 @@ class SocketJobRequestListener
 
        def handle_cmd_cancel_internal( line, req )
                tok = line.split("|").map { |x| x.strip }
-               if tok.count < 2 then
+               if tok.count < 4 then
                        raise BuildServerException.new("ERR001"), line
                end
                cancel_job = nil
 
-               # check user email
-               user_id = @parent_server.check_user_id_from_email( tok[3] )
-               if user_id == -1 then
-                       raise BuildServerException.new("ERR004"), tok[3]
-               end
+               job_number = tok[1]
+               user_password = tok[2]
+               user_email = tok[3]
 
                #CANCEL, JOB
                (@parent_server.jobmgr.jobs + @parent_server.jobmgr.internal_jobs + @parent_server.jobmgr.reverse_build_jobs).each do |j|
-                       if "#{j.id}" == "#{tok[1]}" then
+                       if "#{j.id}" == "#{job_number}" then
                                cancel_job = j
                                break
                        end
                end
 
                if cancel_job.nil? then
-                       raise BuildServerException.new("ERR014"), "Job #{tok[1]} not found."
+                       raise BuildServerException.new("ERR014"), "Job #{job_number} not found."
                end
 
                if cancel_job.event != "NONE" then
                        raise BuildServerException.new("ERR014"), "Job already canceled."
                end
 
-               # check passwd
-               if not @parent_server.jobmgr.is_user_accessable(cancel_job,user_id) then
-                       raise BuildServerException.new("ERR014"), "Access denied #{tok[3]}"
-               end
+               if not cancel_job.is_transferred? then
+                       # check user email
+                       user_id = @parent_server.check_user_id_from_email(user_email)
+                       if user_id == -1 then
+                               raise BuildServerException.new("ERR004"), user_email
+                       end
+            
+                       # check user psssword
+                       if not @parent_server.check_user_password(user_id, user_password) then
+                               raise BuildServerException.new("ERR011"), "Email : #{user_email} && Password : #{passwd}"
+                       end
 
-               if cancel_job.type == "MULTIBUILD" then
-                       cancel_job.get_sub_jobs().select{|x| x.event == "NONE" }.each do |sub|
-                               check_project_password( sub.get_project, tok[2], req)
+                       # check project accessable
+                       if not @parent_server.jobmgr.is_user_accessable(cancel_job,user_id) then
+                               raise BuildServerException.new("ERR014"), "Access denied #{user_email}"
                        end
+               end
 
+               if cancel_job.type == "MULTIBUILD" then
+                       sub_projects = cancel_job.get_sub_jobs().map{|sub| sub.get_project }
                        BuildCommServer.send(req, "\"#{cancel_job.id}, #{cancel_job.get_sub_jobs().map{|x| x.id}.join(", ")}\" will be canceled")
 
                else
@@ -637,8 +556,6 @@ class SocketJobRequestListener
                                raise BuildServerException.new("ERR014"), "No project infomation"
                        end
 
-                       check_project_password( prj, tok[2], req)
-
                        BuildCommServer.send(req, "\"#{cancel_job.id}\" will be canceled")
                end
 
@@ -703,71 +620,28 @@ class SocketJobRequestListener
 
        def handle_cmd_upgrade_internal( line, req )
                tok = line.split("|").map { |x| x.strip }
-               if tok.count < 2 then
+               if tok.count < 3 then
                        raise BuildServerException.new("ERR001"), line
                end
+               password = tok[1]
+               pkgsvr_url = tok[2]
 
-               if tok[1] != @parent_server.password then
+               # write package server url
+               File.open("#{BuildServer::CONFIG_ROOT}/#{@parent_server.id}/upgrade_dist","w") do |f|
+                       f.puts pkgsvr_url
+               end
+
+               if password != @parent_server.password then
                        raise BuildServerException.new("ERR015"), ""
                else
                        BuildCommServer.send(req,"Server will be upgraded!")
                        BuildCommServer.send_end(req)
                        BuildCommServer.disconnect(req)
                end
-               if tok[1] == @parent_server.password then
-                       @parent_server.finish = true
-                       @parent_server.upgrade = true
-               end
-       end
-
-
-       # "FULLBUILD"
-       def handle_cmd_fullbuild( line, req )
-               @log.info "Received REQ: #{line}"
-
-               begin
-                       handle_cmd_fullbuild_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}"
-       end
-
-
-       def handle_cmd_fullbuild_internal( line, req )
-               tok = line.split("|").map { |x| x.strip }
-               if tok.count < 2 then
-                       raise BuildServerException.new("ERR001"), line
-               end
-
-               server_passwd = tok[1]
-               dist_name = tok[2]
-               if (dist_name.nil? or dist_name.empty?) then
-                       dist_name = @parent_server.distmgr.get_default_distribution_name()
-               end
-
-               # check distribution
-               check_distribution(dist_name, req, true)
-
-               # check server password
-               if server_passwd != @parent_server.password then
-                       raise BuildServerException.new("ERR015"), ""
-               end
-
-               # create full build job
-               new_job = @parent_server.prjmgr.create_new_full_build_job(dist_name)
-
-               @parent_server.jobmgr.commit_job(new_job)
-
-               # set logger
-               new_job.create_logger( req ) 
-
-               # add to job
-               @parent_server.jobmgr.add_job( new_job )
+               # set flag for quit message loop
+               @parent_server.finish = true
+               @parent_server.upgrade = true
        end
 
 
@@ -780,7 +654,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
@@ -816,8 +690,28 @@ class SocketJobRequestListener
                        # check distribution
                        check_distribution(dist_name, req)
 
+                       # check project
+                       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( 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}")
+                       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)
+                       end
+            
+                       BuildCommServer.send_end(req)
+                       BuildCommServer.disconnect(req)
 
                        # add
                        @parent_server.jobmgr.add_job( new_job )
@@ -842,19 +736,26 @@ class SocketJobRequestListener
                        # check project
                        prj = check_project_for_package_file_name(filename, 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
+
                        # check user email
                        user_id = @parent_server.check_user_id_from_email( user_email )
                        if user_id == -1 then
                                raise BuildServerException.new("ERR004"), user_email
                        end
 
+                       # check user psssword
+                       if not @parent_server.check_user_password(user_id, passwd) then
+                               raise BuildServerException.new("ERR011"), "Email : #{user_email} && Password : #{passwd}"
+                       end
+
                        if not check_project_pkg_name_user_id(filename, dist_name, user_id) then
                                raise BuildServerException.new("ERR005"), "#{user_email} -> #{prj.name}"
                        end
 
-                       # check passwd
-                       check_project_password(prj, passwd, req)
-
                        # save thread and wait uplaod
                        BuildCommServer.send(req, "WAITFORUPLOAD")
                        req_line = req.gets
@@ -866,7 +767,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
@@ -879,14 +780,18 @@ class SocketJobRequestListener
                        @parent_server.jobmgr.commit_job(new_job)
 
                        # create logger and set
-                       logger = new_job.create_logger(req)
+                       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)
                        end
 
+                       BuildCommServer.send_end(req)
+                       BuildCommServer.disconnect(req)
+
                        # add
                        @parent_server.jobmgr.add_job( new_job )
                else
@@ -913,6 +818,23 @@ class SocketJobRequestListener
        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
@@ -929,6 +851,17 @@ class SocketJobRequestListener
        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}"
@@ -998,7 +931,6 @@ class SocketJobRequestListener
                # get package name
                new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
                pkg_name = new_name.split(",")[0]
-
                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}"
@@ -1007,22 +939,6 @@ class SocketJobRequestListener
                return prj
        end
 
-
-       private
-       def check_project_password(prj, passwd, req)
-
-               if prj.is_passwd_set?  then
-                       if passwd.nil? or passwd.empty? then
-                               raise BuildServerException.new("ERR011"), "Use -w option to input your project password"
-                       end
-
-                       if not prj.passwd_match?(passwd) then
-                               raise BuildServerException.new("ERR012"), ""
-                       end
-               end
-       end
-
-
        private
        def check_distribution(dist_name, req, only_exist = false)
                dist = @parent_server.distmgr.get_distribution(dist_name)
@@ -1033,7 +949,6 @@ class SocketJobRequestListener
                end
        end
 
-
        private
        def check_supported_os(os_list, req)
 
@@ -1064,10 +979,8 @@ class SocketJobRequestListener
                        elsif @parent_server.supported_os_list.include?(os) then
                                result.push os
                        else
-                               msgs = "#{os}\n\tSupported OS list.\n"
-                               @parent_server.supported_os_list.each do |os_name|
-                                       msgs += "\t * #{os_name}\n"
-                               end
+                               msgs = "#{os}... Use a name in (" +
+                                       @parent_server.supported_os_list.join("|") + ")"
                                raise BuildServerException.new("ERR003"),msgs
                        end
                end
@@ -1088,22 +1001,20 @@ 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
 
 
        private
-       def create_new_internal_job( git_repos, os, git_commit, pkg_files, dock_num, dist_name )
-               prj = @parent_server.prjmgr.get_git_project( git_repos, dist_name )
-               if prj.nil? then
-                       prj = @parent_server.prjmgr.create_unnamed_git_project( git_repos, dist_name )
-               end
+       def create_new_transferred_job( git_repos, os, git_commit, pkg_files, dock_num, dist_name, pkgsvr_url )
+               prj = @parent_server.prjmgr.create_transferred_git_project( git_repos, dist_name, os )
                new_job = prj.create_new_job(os)
-               new_job.set_internal_job( dock_num )
+               new_job.set_package_server_url(pkgsvr_url)
+               new_job.set_verified( true )
+               new_job.set_send_result_back( dock_num )
                new_job.git_commit = git_commit
-               incoming_dir = "#{@parent_server.transport_path}/#{dock_num}"
                pkg_files.each do |file|
                        new_job.add_external_package( file )
                end
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)
diff --git a/src/build_server/receive_file.rb b/src/build_server/receive_file.rb
new file mode 100755 (executable)
index 0000000..327c507
--- /dev/null
@@ -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 <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'
+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
+       result = false
+
+       # create client
+       client = BuildCommClient.create( addr, port, log )
+       if client.nil? then
+               log.error( "Creating communication client failed!", Log::LV_USER)
+               exit(1)
+       end
+
+       # download file
+       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 (executable)
index 0000000..496164d
--- /dev/null
@@ -0,0 +1,96 @@
+#!/usr/bin/ruby
+=begin
+
+ send_file.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'
+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
+       result = false
+
+       # create client
+       client = BuildCommClient.create( addr, port, log )
+       if client.nil? then
+               log.error( "Creating communication client failed!", Log::LV_USER)
+               exit(1)
+       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
+
index 5774c31..f4048a2 100644 (file)
@@ -229,7 +229,11 @@ class Builder
 
                # create client
                @log.info( "Downloding client is initializing...", Log::LV_USER)
-               cl = Client.new(@pkgserver_url, build_root_dir, @log)
+               cl = Client.create(@pkgserver_url, build_root_dir, @log)
+               if cl.nil? then
+                       @log.error( "Cannot create package client!", Log::LV_USER )
+                       return false
+               end
                if clean then
                        cl.clean(true)
                end
@@ -244,6 +248,9 @@ class Builder
                # install build dependencies
                @log.info( "Installing dependent packages...", Log::LV_USER)
                pkginfo.get_build_dependencies( os ).each do |dep|
+                       # if job, check "CANCEL" 
+                       if not @job.nil? then @job.check_event() end
+
                        if dep.target_os_list.count != 0 then
                                dep_target_os = dep.target_os_list[0]
                        else
@@ -585,7 +592,7 @@ VERSION=\"#{version}\" "
                                return true
                        end
 
-                       FileUtils.cp(src, tar)
+                       FileUtils.ln(src, tar,:force => true)
                end
 
                return true
@@ -644,7 +651,7 @@ VERSION=\"#{version}\" "
                                return true
                        end
 
-                       FileUtils.cp(src, tar)
+                       FileUtils.ln(src, tar,:force => true)
                end
                return true
        end
index 2f3817b..fab444f 100644 (file)
@@ -1,5 +1,3 @@
-require "socket"
-
 =begin
 
  BuildComm.rb
@@ -30,6 +28,7 @@ Contributors:
 
 $LOAD_PATH.unshift File.dirname(__FILE__)
 require "log"
+require "socket"
 require 'timeout'
 require "net/ftp"
 require 'thread'
@@ -39,7 +38,7 @@ require "FileTransferViaDirect"
 ATTEMPTS = ["first", "second", "third"]
 
 class BuildCommServer
-       VERSION = "1.8.0"
+       VERSION = "1.9.0"
 
        private_class_method :new
 
@@ -296,7 +295,7 @@ class BuildCommServer
 
                                # if hit , touch and copy
                                FileUtils.touch cache_file
-                               FileUtils.copy_file(cache_file, dst_file)
+                               FileUtils.ln(cache_file, dst_file, :force => true)
 
                                found = true
                        end
@@ -322,7 +321,7 @@ class BuildCommServer
                cache_file = "#{@cache_dir}/#{file_name}"
                @download_cache_mutex.synchronize do
                        # copy & touch
-                       FileUtils.copy_file(dst_file, cache_file)
+                       FileUtils.ln(dst_file, cache_file, :force => true)
                        FileUtils.touch cache_file
                end
        end
@@ -330,12 +329,15 @@ end
 
 
 class BuildCommClient
-       VERSION = "1.8.0"
+       VERSION = "1.9.0"
        FIRST_RESPONSE_TIMEOUT = 120
 
        private_class_method :new
 
        def initialize(socket, log)
+               @job_id = nil
+               @job_status = ""
+               @job_error = ""
                @log = log
                @socket = socket
                @error_msg = ""
@@ -344,19 +346,24 @@ class BuildCommClient
 
        # create
        # if sec 0 or nil then not set timeout. it's timeout spec
-       def self.create(ip, port, log = nil, sec = 5)
-               # open socket
-               socket = nil
-               begin
-                       timeout(sec) do
-                               socket = TCPSocket.open( ip, port )
+       def self.create(ip, port, log = nil, sec = 10, retries = 3)                                     
+               # open socket                                                                               
+               socket = nil                                                                                
+               for i in 1..retries
+                       begin
+                               timeout(sec) do
+                                       socket = TCPSocket.open( ip, port )
+                               end
+                       rescue Timeout::Error
+                               log.warn("Connection Timed Out!") if not log.nil?
+                               socket = nil
+                       rescue => e # unknown exception
+                               log.warn("TCPSocket Error: #{e.message}") if not log.nil?
+                               socket = nil
                        end
-               rescue Timeout::Error
-                       return nil
-               rescue
-                       # unknown exception
-                       return nil
-               end
+                       if not socket.nil? then break end
+                       log.warn("Retrying...") if not log.nil? and i < retries
+        end                                                                                         
 
                # refused
                if socket.nil? then
@@ -370,11 +377,21 @@ class BuildCommClient
                return new(socket, log)
        end
 
-
        def get_error_msg()
                return @error_msg
        end
 
+       def get_job_id 
+               return @job_id
+       end
+
+       def get_job_status
+               return @job_status
+       end
+
+       def get_job_error
+               return @job_status
+       end
 
        def set_error_msg( msg )
                @error_msg = msg
@@ -386,42 +403,8 @@ class BuildCommClient
                        @error_msg = "Connection is not available!"
                        return false 
                end
-
-               @socket.puts( msg )
-               return true
-       end
-
-
-       def print_stream
-
                begin
-                       l = nil
-                       timeout(FIRST_RESPONSE_TIMEOUT) do
-                               l = @socket.gets()
-                       end
-
-                       if l.nil? then
-                               @error_msg = "Connection closed or no more message"
-                               return false
-                       end
-
-                       # check protocol
-                       if not protocol_matched? l.strip then
-                               @error_msg = "Comm. Protocol version is mismatched! #{VERSION}. Upgrade your DIBS client!"
-                               return false
-                       end
-
-                       # get contents
-                       while line = @socket.gets()
-                               if line.strip == "=END" then break end
-                               if line.strip == "=CHK" then next end
-                               # print
-                               puts line.strip
-                       end
-               rescue Timeout::Error
-                       @error_msg = "Connection timed out!"
-                       return false
-
+                       @socket.puts( msg )
                rescue => e
                        @error_msg = e.message
                        return false
@@ -434,6 +417,7 @@ class BuildCommClient
        # handle
        def read_lines(begin_timeout = nil, data_timeout = nil)
 
+               result = true
                begin
                        # get first line
                        l = nil
@@ -457,7 +441,6 @@ class BuildCommClient
                        end
 
                        # get contents
-                       result = true
                        while true
                                line = nil
                                if not data_timeout.nil? then
@@ -467,23 +450,30 @@ class BuildCommClient
                                else
                                        line = @socket.gets()
                                end
-                               if line.nil? then break end
-                               if line.strip == "=END" then break end
-                               if line.strip == "=CHK" then next end
+
+                               if line.nil? then 
+                                       @error_msg = "Disconnected by remote server!"
+                                       result = false
+                                       break
+                               elsif line.strip == "=END" then 
+                                       break
+                               elsif line.strip == "=CHK" then 
+                                       next 
+                               end
 
                                # execute
                                yield line.strip if block_given?
                        end
                rescue Timeout::Error
                        @error_msg = "Connection timed out!"
-                       return false
+                       result = false
 
                rescue => e
                        @error_msg = e.message
-                       return false
+                       result = false
                end
 
-               return true
+               return result
        end
 
 
index 744c6f6..3d44890 100644 (file)
@@ -64,6 +64,7 @@ class FileTransferDirect
                                old_progress = 0
                                # read file contents
                                # send via tcp/ip
+                               trBegin = Time.now()
                                File.open(src_file, "rb") do |io|
                                        while size > 0
                                                buf = io.read(size > 1024*1024 ? 1024*1024 : size)
@@ -77,8 +78,9 @@ class FileTransferDirect
                                                end
                                        end
                                end
-
-                               @log.info "Upload is succeeded!"
+                               trEnd = Time.now()
+                               trRate = (full_size / (trEnd - trBegin) / 1000).to_i
+                               @log.info "Upload is succeeded! #{trRate}KByte/s"
                                conn.puts "SEND_OK"
 
                                # wait for download result
@@ -114,12 +116,14 @@ class FileTransferDirect
                                @log.info "Received file info from remote site"
                                filename = tok[1].strip
                                size = tok[2].strip.to_i
+                               full_size = size
                                checksum = tok[3].strip
 
                                if File.directory? dst_file then
                                        dst_file = File.join(dst_file, filename)
                                end
 
+                               trBegin = Time.now()
                                File.open( dst_file, "wb" ) do  |io|
                                        while size > 0
                                                buf = conn.read(size > 1024*1024 ? 1024*1024 : size)
@@ -131,6 +135,9 @@ class FileTransferDirect
                                                size -= buf.length
                                        end
                                end
+                               trEnd = Time.now()
+                               trRate = (full_size / (trEnd - trBegin) / 1000).to_i
+                               @log.info "Download is succeeded! #{trRate}KByte/s"
 
                                conn.puts "RECEIVE_OK"
 
diff --git a/src/common/FileUtil.rb b/src/common/FileUtil.rb
new file mode 100644 (file)
index 0000000..e39483e
--- /dev/null
@@ -0,0 +1,33 @@
+require "fileutils"
+
+class FileUtil
+  public
+  def FileUtil.getFileNameFromURL(url)
+    fileName = url.split('/')[-1]
+    return fileName
+  end
+  
+  public 
+  def FileUtil.getFlatURL(url)
+    if url.nil? or url.empty? then
+      return ""
+    end
+
+    return url.delete(".:/@")
+  end
+  
+  public 
+  def FileUtil.exclusiveLock(filePath)
+    if (not File.exist?(filePath))
+      FileUtils.mkdir_p(filePath)
+    end
+    
+    file = File.new(filePath)
+    if (file.flock(File::LOCK_EX | File::LOCK_NB))
+      return true;
+    else
+      return false
+    end
+  end
+  
+end
\ No newline at end of file
diff --git a/src/common/PropertyParser.rb b/src/common/PropertyParser.rb
new file mode 100644 (file)
index 0000000..a620f9d
--- /dev/null
@@ -0,0 +1,39 @@
+#$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common/model"
+require 'model/Property'
+
+class PropertyParser
+  attr_accessor :seperate
+  def initialize(seperate)
+    if seperate.nil? then
+      @seperate = ":";
+    else 
+      @seperate = seperate;
+    end
+  end
+  
+  public
+  def parseFile(filePath)
+    propertySection = Array.new;
+    properties = Array.new;
+    
+    f = File.open(filePath,"r");
+    f.each_line do |line|
+      if line.empty? || line.eql?("\n") then
+        if not properties.empty?() then
+          propertySection.push(properties);
+          properties = Array.new
+        end
+      else
+        sepLine = line.split(@seperate);
+        properties.push(Property.new(sepLine[0].strip, sepLine[1].strip))
+      end
+      
+    end
+    
+    if (not properties.empty?) then
+      propertySection.push(properties);
+    end
+    
+    return propertySection;
+  end
+end
index 58cb982..1f5bb79 100755 (executable)
@@ -48,7 +48,7 @@ cmd = Utils.generate_shell_command(cmd, nil)
 # execute and write log
 IO.popen("#{cmd} 2>&1") do  |io|
        io.each do  |line|
-               log.info line
+               log.info "{1} #{line}"
        end
 end
 
index 3ea5ef4..a8ee767 100644 (file)
@@ -30,7 +30,7 @@ require "logger"
 
 class Log
 
-       attr_accessor :path, :cnt
+       attr_accessor :path, :cnt, :logger
 
        # Log LEVEL
        LV_NORMAL = 1
@@ -41,15 +41,14 @@ class Log
        def initialize(path, lv=LV_USER)
                @cnt = 0
                @path = path
+               @level = lv
+               @closed = false
                if @path.nil? then
                        @logger = Logger.new(STDOUT)
                else
                        @logger = Logger.new(path, "monthly")
                end
-               # if log level is bigger/equal to second out level
-               # , we will send the log to second-out
-               @second_out_level = lv
-               @second_out = nil
+
                # diable logger format
                @default_formatter = @logger.formatter
                @no_prefix_formatter = proc do |severity, datetime, progname, msg|
@@ -59,54 +58,42 @@ class Log
 
 
        def info(msg, lv=LV_NORMAL)
-               if @path.nil? and not @second_out.nil? then puts "Info: #{msg}"
-               else @logger.info msg end
-               if not @second_out.nil? and lv >= @second_out_level then
-                       output_extra "Info: " + msg
-               end
+               if @path.nil? then puts "Info: #{msg}" else @logger.info "{#{lv}} #{msg}" end
+               output_extra("Info: " + msg, lv)
                @cnt = @cnt + 1
        end
 
        def warn(msg, lv=LV_NORMAL)
-               if @path.nil? and not @second_out.nil? then puts "Warn: #{msg}"
-               else @logger.warn msg end
-               if not @second_out.nil? and lv >= @second_out_level then
-                       output_extra "Warn: " + msg
-               end
+               if @path.nil? then puts "Warn: #{msg}" else @logger.warn "{#{lv}} #{msg}" end
+               output_extra("Warn: " + msg, lv)
                @cnt = @cnt + 1
        end
 
 
        def error(msg, lv=LV_NORMAL)
-               if @path.nil? and not @second_out.nil? then puts "Error: #{msg}"
-               else @logger.error msg end
-               if not @second_out.nil? and lv >= @second_out_level then
-                       output_extra "Error: " + msg
-               end
+               if @path.nil? then puts "Error: #{msg}" else @logger.error "{#{lv}} #{msg}" end
+               output_extra("Error: " + msg, lv)
                @cnt = @cnt + 1
        end
 
 
        def output(msg, lv=LV_NORMAL)
-               if @path.nil? and not @second_out.nil? then puts msg
-               else @logger.info msg end
-               if not @second_out.nil? and lv >= @second_out_level then
-                       output_extra msg
-               end
+               if @path.nil? then puts msg else @logger.info "{#{lv}} #{msg}" end
+               output_extra(msg, lv)
                @cnt = @cnt + 1
        end
 
        def close
-               @second_out= nil
+               @closed = true
        end
 
-       def is_verbose
-               return @second_out_level.eql? Log::LV_NORMAL
-       end
 
+       def is_closed?
+               return @closed
+       end
 
        protected
-       def output_extra(msg)
+       def output_extra(msg, lv)
                #do nothing
        end
 end
@@ -132,15 +119,55 @@ class DummyLog
        end
 end
 
+
 class StandardOutLog < Log
 
        def initialize(path)
                super(path)
-               @second_out = $stdout
        end
 
        protected
-       def output_extra(msg)
-               @second_out.puts msg
+       def output_extra(msg, lv)
+               if lv >= @level then
+                       $stdout.puts msg
+               end
+       end
+end
+
+
+class StandardOutLogPrinter < Log
+
+       def initialize()
+               super(nil)
+       end
+
+       def info(msg, lv=LV_NORMAL)
+               if lv >= @level then
+                       puts "Info: #{msg}"
+                       @cnt = @cnt + 1
+               end
+       end
+
+       def warn(msg, lv=LV_NORMAL)
+               if lv >= @level then
+                       puts "Warn: #{msg}"
+                       @cnt = @cnt + 1
+               end
+       end
+
+
+       def error(msg, lv=LV_NORMAL)
+               if lv >= @level then
+                       puts "Error: #{msg}"
+                       @cnt = @cnt + 1
+               end
+       end
+
+
+       def output(msg, lv=LV_NORMAL)
+               if lv >= @level then
+                       puts msg
+                       @cnt = @cnt + 1
+               end
        end
 end
diff --git a/src/common/model/Property.rb b/src/common/model/Property.rb
new file mode 100644 (file)
index 0000000..75cb749
--- /dev/null
@@ -0,0 +1,8 @@
+class Property
+  attr_accessor(:key, :value)
+  
+  def initialize(key, value)
+    @key = key;
+    @value = value;
+  end
+end
\ No newline at end of file
index b05b3c8..0339060 100644 (file)
@@ -112,7 +112,7 @@ class Package
        end
 
        def does_change_exist?
-               if not @change_log.empty? and not @change_log[@version].nil? then
+               if not @change_log[@version].nil? then
                        return true
                end
                return false
index e7804dd..93e6f20 100644 (file)
@@ -38,16 +38,18 @@ class Utils
 
                case `uname -s`.strip
                when "Linux"
+                       arch = `getconf LONG_BIT`.strip
+                       arch = "unknown" if arch.length != 2
                        if File.exist? "/etc/debian_version" then
-                               arch = (`uname -i`.strip == "x86_64") ? "64" : "32"
                                os = "ubuntu-#{arch}"
                        elsif File.exist? "/etc/redhat-release" then
-                               os = "redhat-unknown"
+                               os = "redhat-#{arch}"
                        elsif File.exist? "/etc/SuSE-release" then
-                               arch = (`uname -i`.strip == "x86_64") ? "64" : "32"
                                os = "opensuse-#{arch}"
                        elsif File.exist? "/etc/mandrake-release" then
-                               os = "mandrake-unknown"
+                               os = "mandrake-#{arch}"
+                       else
+                               os = "unknownlinux-#{arch}"
                        end
                when "MINGW32_NT-5.1"
                        progfile_path = Utils.execute_shell_return("echo $PROGRAMFILES","windows")[0].strip
@@ -64,6 +66,9 @@ class Utils
                return os
        end
 
+       def Utils.set_default_linux_host_os()
+               HOST_OS.sub!(/.*-/,"ubuntu-")
+       end
 
        def Utils.check_host_OS()
                if Utils.get_all_OSs().include? HOST_OS then
@@ -75,7 +80,7 @@ class Utils
 
 
        def Utils.get_all_OSs()
-               return ["ubuntu-32","ubuntu-64","windows-32","windows-64","macos-64","opensuse-32", "opensuse-64"]
+               return ["ubuntu-32","ubuntu-64","windows-32","windows-64","macos-64"]
        end
 
 
@@ -258,19 +263,7 @@ class Utils
 
        end
 
-       def Utils.create_process(command,redirStdout="", redirStderr="")
-
-               if redirStdout.length > 0
-                       tmpfile = File.new(redirStdout,"w")
-                       save_stdout = $stdout.clone
-                       $stdout.reopen(tmpfile)
-               end
-
-               if redirStderr.length > 0
-                       tmpfile = File.new(redirStderr,"w")
-                       save_stderr = $stderr.clone
-                       $stderr.reopen(tmpfile)
-               end
+       def Utils.create_process(command)
 
                params = [
                        'L', # IN LPCSTR lpApplicationName
@@ -293,18 +286,6 @@ class Utils
 
                createProcess.call(0, command, 0, 0, 0, NORMAL_PRIORITY_CLASS, 0, 0, startupInfo, processInfo)
 
-               if redirStdout.length > 0
-                       $stdout.reopen(save_stdout)
-               end
-
-               save_stdout.close if save_stdout
-
-               if redirStderr.length > 0
-                       $stderr.reopen(save_stderr)
-               end
-
-               save_stderr.close if save_stderr
-
                ($0 == __FILE__ ) ? processInfo : processInfo.unpack("LLLL")[2]
        end
 
@@ -456,8 +437,7 @@ class Utils
 
        # check if the os is unix-like
        def Utils.is_unix_like_os(os_name)
-               if os_name.start_with? "ubuntu-" or
-                       os_name.start_with? "opensuse-" or
+               if Utils.is_linux_like_os os_name or
                        os_name.start_with?"macos-" then
                        return true
                else
@@ -469,7 +449,10 @@ class Utils
        # check if the os is linux-like
        def Utils.is_linux_like_os(os_name)
                if os_name.start_with? "ubuntu-" or
-                       os_name.start_with? "opensuse-" then
+                       os_name.start_with? "redhat-" or
+                       os_name.start_with? "opensuse-" or
+                       os_name.start_with? "mandrake-" or
+                       os_name.start_with? "unknownlinux-" then
                        return true
                else
                        return false
@@ -488,11 +471,11 @@ class Utils
 
 
        def Utils.get_os_category(os_name)
-               if os_name.start_with? "ubuntu-" or os_name.start_with? "opensuse-" then
+               if is_linux_like_os os_name then
                        return "linux"
-               elsif os_name.start_with?"macos-" then
+               elsif is_macos_like_os os_name then
                        return "macos"
-               elsif os_name.start_with? "windows-" then
+               elsif is_windows_like_os os_name then
                        return "windows"
                else
                        return os_name
@@ -540,12 +523,22 @@ class Utils
 
        def Utils.checksum(file_path)
                if File.exist? file_path then
-                       return Utils.execute_shell_return("shasum -a 256 \"#{file_path}\"")[0].split(" ")[0]
+                       return execute_shell_return("shasum -a 256 \"#{file_path}\"")[0].split(" ")[0]
                else
                        return nil
                end
        end
 
+       def Utils.validatePkgFile(filepath, orig_checksum, orig_size)
+               checksum = checksum(filepath)
+               size = File.size filepath
+               if checksum.eql? orig_checksum and size.to_s.eql? orig_size then
+                       return true
+               else
+                       return false
+               end
+       end
+
        def Utils.get_version()
                version_file = "#{File.dirname(__FILE__)}/../../VERSION"
 
@@ -631,8 +624,8 @@ class Utils
                        Find.find(path) do |dep_path|
                                if (File.exist?(dep_path) and not File.directory? dep_path)
                                        fsize = File.size(dep_path)
-                                       ctime = File.new(dep_path).ctime
-                                       mtime = File.new(dep_path).mtime
+                                       ctime = File.ctime(dep_path)
+                                       mtime = File.mtime(dep_path)
                                        list.push [dep_path,fsize,ctime,mtime]
                                end
                        end
@@ -675,5 +668,4 @@ class Utils
                Dir.chdir WORKING_DIR
        end
 
-
 end
diff --git a/src/pkg_server/ChangeLogController.rb b/src/pkg_server/ChangeLogController.rb
new file mode 100644 (file)
index 0000000..a424edf
--- /dev/null
@@ -0,0 +1,100 @@
+require "SnapshotController"
+require "PackageServerConstants"
+require "fileutils"
+
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "FileUtil"
+
+class ChangeLogController
+  def initialize(serverURL, ssController)
+    @serverUrl = serverURL
+    @ssController = ssController
+  end
+  
+  ##Get 
+  public
+  def getLatestChangeLog()
+    recentSnapshotName = @ssController.getLatestSnapshot().getName();
+    return getChangeLog(recentSnapshotName)
+  end
+  
+  public
+  def getChangeLog(snapshotName)
+    logPath = downloadChangeLog(snapshotName)
+    
+    if (logPath.nil?() || !File.exist?(logPath)) then
+      return;
+    end
+    
+    
+    return loadChangeLog(logPath);
+  end
+  
+  public
+  def getTotalChangeLog(startSnapshotName, endSnapshotName)
+    if (endSnapshotName.nil?())
+      return;
+    elsif (endSnapshotName.nil?())
+      return getChangeLog(startSnapshot);
+    else
+      changeLog = String.new
+      
+      totalSnapshotList = @ssController.getTotalSnapshotName(startSnapshotName,endSnapshotName)
+      totalSnapshotList.each() do |snapshotName|
+        changeLog = changeLog + getChangeLog(snapshotName) + "\n"
+      end
+     
+     return changeLog
+    end
+  end
+  
+  private 
+  def downloadChangeLog(snapshotName)
+    changeLogURLPath = getChangeLogURLPath(snapshotName)
+    
+    localPath = getChangeLogPath()
+        
+    FileUtils.mkdir_p(localPath)
+    
+    logger = DummyLog.new()
+    
+    if (FileDownLoader.download(changeLogURLPath,localPath,logger)) then
+      return File.join(localPath, getChangeLogFile(snapshotName))
+    else
+      return nil
+    end
+  end
+  
+  private
+  def getChangeLogPath()
+    flatServerName = FileUtil.getFlatURL(@serverUrl)
+    return File.join(PackageServerConfig::CONFIG_PATH, flatServerName, PackageServerConstants::CHANGE_LOG_DIRECTORY_NAME)
+  end
+  
+  private
+  def getChangeLogURLPath(snapshotName)
+    changeLogURLPath = File.join(@serverUrl, PackageServerConstants::CHANGE_LOG_DIRECTORY_NAME, getChangeLogFile(snapshotName));
+    
+    return changeLogURLPath
+  end
+  
+  private
+  def getChangeLogFile(snapshotName)
+    if (snapshotName.nil?() || snapshotName.empty?())
+      return ""
+    end
+    return snapshotName + PackageServerConstants::CHANGE_LOG_FILE_EXTENSION
+  end
+  
+  private 
+  def loadChangeLog(logPath)
+    changeLog = String.new
+    
+    file = File.open(logPath,"r")
+    file.each_line do |line|
+      changeLog = changeLog + line
+    end
+    
+    return changeLog
+  end
+end
\ No newline at end of file
diff --git a/src/pkg_server/PackageServerConstants.rb b/src/pkg_server/PackageServerConstants.rb
new file mode 100644 (file)
index 0000000..30a8b49
--- /dev/null
@@ -0,0 +1,16 @@
+class PackageServerConstants
+  #changelog information
+  CHANGE_LOG_DIRECTORY_NAME = "changes"
+  CHANGE_LOG_FILE_EXTENSION = ".log"
+  
+  #distribution information
+  DISTRIBUTION_INFO_FILE_NAME = "distribution.info"
+  
+  #snapshot information
+  SNAPSHOT_INFO_FILE_NAME = "snapshot.info"
+  SNAPSHOT_NAME_FIELD = "name"
+  SNAPSHOT_TIME_FIELD = "time"
+  SNAPSHOT_TYPE_FIELD = "type"
+  SNAPSHOT_PATH_FIELD = "path"
+  SNAPSHOT_MANUAL_TYPE_VALUE = "manual"
+end
\ No newline at end of file
diff --git a/src/pkg_server/SnapshotController.rb b/src/pkg_server/SnapshotController.rb
new file mode 100644 (file)
index 0000000..cc9eb81
--- /dev/null
@@ -0,0 +1,78 @@
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "PropertyParser"
+require "PackageServerConstants"
+require 'model/snapshot'
+  
+class SnapshotController
+  attr_accessor :snapshotList
+  def initialize(snapshotFilePath)
+    @snapshotList = Array.new
+    
+    if (File.directory? snapshotFilePath) then
+      snapshotFilePath = File.join(snapshotFilePath, PackageServerConstants::SNAPSHOT_INFO_FILE_NAME)
+    end
+      
+    loadSnapshot(snapshotFilePath)
+  end
+  
+  public
+  def getAllSnapshotList
+    return @snapshotList
+  end
+  
+  public
+  def getManualSnapshotList
+    manualSnapshotList = Array.new
+    
+    @snapshotList.each() do |snapshot|
+      if (snapshot.getType().eql?(PackageServerConstants::SNAPSHOT_MANUAL_TYPE_VALUE)) then
+        manualSnapshotList.push(snapshot[name])
+      end
+    end
+    
+    return manualSnapshotList
+  end
+  
+  public
+  def getLatestSnapshot
+    return @snapshotList.pop()
+  end
+  
+  public
+  def getTotalSnapshotName(startSnapshotName, endSnapshotName)
+    totalSnapshotList = Array.new
+     
+    @snapshotList.each() do |snapshot|
+      snapshotName = snapshot.getName()
+      if (snapshotName.eql?(startSnapshotName) || snapshotName.eql?(endSnapshotName)) then
+        if (totalSnapshotList.empty?) then
+          totalSnapshotList.push(snapshotName)
+        else
+          break
+        end
+      end
+      
+      if (not totalSnapshotList.empty?) then
+        totalSnapshotList.push(snapshotName)
+      end
+    end
+    
+    return totalSnapshotList
+  end
+  
+  private
+  def loadSnapshot(snapshotPath)
+    if not File.exist?(snapshotPath) then
+      return;
+    end
+    
+    parser = PropertyParser.new(nil)
+    propertySection = parser.parseFile(snapshotPath);
+    
+    propertySection.each() do |properties|
+      snapshot = Snapshot.new(properties)
+      @snapshotList.push(snapshot);
+    end
+    
+  end
+end
\ No newline at end of file
index b864fe9..2f18f62 100644 (file)
@@ -44,6 +44,10 @@ require "BuildComm"
 require "FileTransferViaFTP"
 require "FileTransferViaDirect"
 require 'digest'
+require "SnapshotController"
+require "ChangeLogController"
+require 'PackageServerConstants'
+
 
 
 $update_mutex = Mutex.new
@@ -62,6 +66,7 @@ class Client
        ARCHIVE_PKG_LIST_FILE = "archive_pkg_list"
 
        attr_accessor :server_addr, :location, :pkg_hash_os, :is_server_remote, :installed_pkg_hash_loc, :archive_pkg_list, :all_dep_list, :log, :support_os_list, :config_dist_path, :download_path, :tmp_path, :snapshot_path, :snapshots_path, :snapshot_url
+       private_class_method :new
 
        public
        # initialize
@@ -98,6 +103,7 @@ class Client
                        if not server_addr.nil? then
                                # chop server address, if end with "/"
                                if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
+                               server_addr.strip!
 
                                if is_snapshot_url(server_addr) then
                                        @snapshot_url = true
@@ -117,13 +123,35 @@ class Client
                                if not File.exist? @snapshots_path then FileUtils.mkdir_p "#{@snapshots_path}" end
                                if not File.exist? @tmp_path then FileUtils.mkdir_p "#{@tmp_path}" end
                        end             
+               end
+
+               @configs = {}
+               #default cache size = 8G
+               @configs[:CACHE_SIZE] = "8000"
+       end
+
+
+       public
+       def self.create(server_addr, location, logger, access_svr = true)
+               new_client = new(server_addr, location, logger, access_svr )
+               if new_client.init(access_svr) then
+                       return new_client
+               else
+                       return nil
+               end
+       end
+
 
+       public
+       def init(access_svr)
+               if access_svr then
                        # read remote pkg list, and hash list
                        @log.info "Update remote package list and supported os list.."
                        if update() then 
-                               @log.info "Initialize - #{server_addr}, #{location}" 
+                               @log.info "Initialize - #{@server_addr}, #{@location}" 
                        else 
-                               @log.error "Failed to update remote package list."                                      
+                               @log.error "Failed to update remote package list."
+                               return false
                        end
                end
 
@@ -132,9 +160,7 @@ class Client
                @log.info "Update local package list.. [#{@location}]"
                read_installed_pkg_list()
 
-               @configs = {}
-               #default cache size = 4G
-               @configs[:CACHE_SIZE] = "4000"
+               return true
        end
 
 
@@ -164,9 +190,7 @@ class Client
                if not remove_list.empty? then
                        @log.info "Removed oldest package files.. (Now not fully caching)"
                        @log.info "  * #{remove_list.map{|path| File.basename(path)}.join(", ")}"
-                       $cache_mutex.synchronize do
-                               FileUtils.rm_rf remove_list
-                       end
+                       FileUtils.rm_rf remove_list
                end
        end
 
@@ -177,7 +201,7 @@ class Client
 
        private
        def get_config_max_cache_size
-               return (@configs[:CACHE_SIZE] =~ /^([0-9][0-9]*)$/i)?  ($1.to_i * 1024 * 1024)  :  (4 * 1024 * 1024 * 1024) #default size 4G : unit = MB
+               return (@configs[:CACHE_SIZE] =~ /^([0-9][0-9]*)$/i)?  ($1.to_i * 1024 * 1024)  :  (8 * 1024 * 1024 * 1024) #default size 4G : unit = MB
        end
 
        private
@@ -314,19 +338,22 @@ class Client
                        file_path = get_file_from_cache(filename, pkg_checksum, pkg_size, loc)
                        if file_path.nil? then
 
-                               if not FileDownLoader.download(url, loc, @log) then
+                               file_path = File.join(loc, filename)
+
+                               result = FileDownLoader.download(url, loc, @log)
+                               if not result or not File.exist? file_path then
                                        @log.error "File Download Failed!!"
                                        @log.error "* #{url} -> #{loc}"
                                        return nil
                                end
 
-                               file_path = File.join(loc, filename)
-                               if validatePkgFile(file_path, pkg_checksum, pkg_size) then
+                               if Utils.validatePkgFile(file_path, pkg_checksum, pkg_size) then
                                        add_file_to_cache(file_path)
                                else
                                        @log.error "File Validation Failed!!"
-                                       return nil                                              
-                               end                                             
+                                       @log.info "Valiate : file path : #{file_path}, shasum : #{pkg_checksum}, size : #{pkg_size}", Log::LV_USER
+                                       return nil
+                               end
                        else
                                @log.info "Cached #{pkg_name} package file.. OK"
                        end
@@ -341,27 +368,72 @@ class Client
                return file_local_path
        end
 
-       private
-       def validatePkgFile(filepath, orig_checksum, orig_size)
-               checksum = Digest::SHA256.file(filepath).hexdigest
-               size = File.size filepath
-               if checksum.to_s.eql? orig_checksum and size.to_s.eql? orig_size then
-                       return true
-               else
-                       return false                            
-               end                             
-       end     
+       public
+       # make sdk image
+       def make_img(os)
+               # get package list
+               all_pkg_list = @pkg_hash_os[os].values
+
+               # select meta and install-type packages
+               img_pkg_list = []
+               all_pkg_list.each { |pkg|
+                       attr = get_attr_from_pkg(pkg.package_name, os, "attribute")
+                       if attr.nil? or attr.empty? then next end
+                       if attr[0].strip.upcase.eql? "ROOT" or attr[0].strip.upcase.eql? "INSTALL" then
+                               dependent_pkg_list = get_install_dependent_packages(pkg.package_name, os, true, true)
+                               img_pkg_list = img_pkg_list + dependent_pkg_list
+                       end
+               }
+               img_pkg_list.uniq!
+
+               # init workspace
+               workspace = @location+"/temp_for_tizen_sdk_imgs_#{os}"
+               if File.directory? workspace then FileUtils.remove_dir(workspace, true) end
+               
+               # download packages
+               img_pkg_list.each do |pkg| download(pkg, os, false, "#{workspace}/binary") end
+
+               # write pkg_list_os file
+               FileUtils.cp("#{get_pkglist_path}/pkg_list_#{os}", "#{workspace}")
+
+               # write os_info file
+               File.open("#{workspace}/#{OS_INFO_FILE}", 'w') do |f| f.puts os end
+
+               # compress files
+               snapshot = snapshot_path.split('/')[-1]
+               img_name = "TIZNE-SDK-IMG_#{snapshot}_#{os}.zip"
+               cmd = "cd #{workspace}; zip -q -r #{@location}/TIZNE-SDK-IMG_#{snapshot_path.split('/')[-1]}_#{os}.zip *;"
+               Utils.execute_shell_with_log(cmd, @log.path)
+
+               # clean workspace
+               FileUtils.remove_dir(workspace, true)
+               @log.info "<< SDK-Image Info. >>"
+               @log.info " - server addr : #{@server_addr}"
+               @log.info " - snapshot : #{snapshot}"
+               @log.info " - os : #{os}"
+               @log.info " - location : #{location}/"
+               @log.info " - name : #{img_name}"
+
+               return
+       end
 
        private
        def get_file_from_cache(filename, pkg_checksum, pkg_size, location)
+               if not File.directory? location then return nil end
                downloaded_file_path = nil
-               $cache_mutex.synchronize do
+               @log.info "Wait for cache sync",Log::LV_USER
+               begin
+                       lock = Utils.file_lock(File.join(CONFIG_PATH,".cache_lock"))
+                       @log.info "Entering cache sync",Log::LV_USER
                        cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size)
-                       if not cached_filepath.nil? then
-                               FileUtils.cp(cached_filepath, location)
+                       if not cached_filepath.nil? and File.exist? cached_filepath then
+                               FileUtils.ln(cached_filepath, location, :force => true)
                                downloaded_file_path = File.join(location, File.basename(cached_filepath))
                        end
+               ensure
+                       Utils.file_unlock(lock) if not lock.nil?
                end
+               @log.info "Cache sync done",Log::LV_USER
                if not downloaded_file_path.nil? and not File.exist? downloaded_file_path then
                        downloaded_file_path = nil
                end
@@ -370,8 +442,8 @@ class Client
 
        private
        def add_file_to_cache(filepath)
-               if filepath.nil? or filepath.empty? then return end
-               if not File.exist? @download_path then FileUtils.mkdir_p "#{download_path}" end
+               if filepath.nil? or filepath.empty? or not File.exist? filepath then return end
+               if not File.exist? @download_path then FileUtils.mkdir_p "#{@download_path}" end
 
                filename = File.basename(filepath)
                cachefile = File.join(@download_path, filename)
@@ -380,14 +452,21 @@ class Client
                @log.info "  [path: #{@download_path}]"
 
                if not File.exist? cachefile then
-                       FileUtils.cp(filepath, @download_path)
+                       FileUtils.ln(filepath, @download_path, :force => true)
                end
 
                if not File.exist? cachefile then
                        @log.info "Failed to move [#{filename}] to "
-                       @log.info "  [#{download_path}]"
+                       @log.info "  [#{@download_path}]"
+               end
+
+               begin
+                       lock = Utils.file_lock(File.join(CONFIG_PATH,".cache_lock"))
+
+                       remove_old_files_in_cache
+               ensure 
+                       Utils.file_unlock(lock) if not lock.nil?
                end
-               remove_old_files_in_cache
        end
 
        private
@@ -406,7 +485,7 @@ class Client
        def get_cached_filepath(pkg_filename, pkg_checksum, pkg_size)
                cached_filepath = "#{@download_path}/#{pkg_filename}"
                if File.exist? cached_filepath then
-                       if validatePkgFile(cached_filepath, pkg_checksum, pkg_size) then
+                       if Utils.validatePkgFile(cached_filepath, pkg_checksum, pkg_size) then
                                FileUtils.touch cached_filepath                                 
                                return cached_filepath
                        else
@@ -1502,17 +1581,21 @@ class Client
 
                # install package
                #download
-               tmp_location = File.join(@tmp_path,Utils.create_uniq_name)
-               filepath = download(pkg_name, os, false, tmp_location)
-               if filepath.nil? or filepath[0].nil? then
-                       return false
-               end
+               tmp_location = nil
+               begin
+                       tmp_location = File.join(@tmp_path,Utils.create_uniq_name)
+                       filepath = download(pkg_name, os, false, tmp_location)
+                       if filepath.nil? or filepath[0].nil? then
+                               return false
+                       end
 
-               #install
-               ret = FileInstaller.install(pkg_name, filepath[0], type, @location, @log)
+                       #install
+                       ret = FileInstaller.install(pkg_name, filepath[0], type, @location, @log)
+               ensure
+                       #remove garbage
+                       FileUtils.rm_rf tmp_location if not tmp_location.nil? and File.exist? tmp_location
+               end
 
-               #remove garbage
-               FileUtils.rm_rf tmp_location
                return ret
        end
 
@@ -1615,11 +1698,16 @@ class Client
                file_url = File.join(@server_addr, ssinfo_file)
                if from_server then
                        if not FileDownLoader.download(file_url, @config_dist_path, @log) then
-                               @log.warn "Server does not have \"#{ssinfo_file}\" file. This error can be ignored."
+                               @log.error "Server does not have \"#{ssinfo_file}\" file."
+                               return nil 
                        end
                else
-                       if File.exist? file_url then FileUtils.cp(file_url, @config_dist_path)
-                       else @log.warn "Server does not have \"#{ssinfo_file}\" file. This error can be ignored." end
+                       if File.exist? file_url then 
+                               FileUtils.cp(file_url, @config_dist_path)
+                       else 
+                               @log.error "Server does not have \"#{ssinfo_file}\" file."
+                               return nil 
+                       end
                end
 
                file_path = File.join(@config_dist_path, ssinfo_file)
@@ -1658,7 +1746,7 @@ class Client
                if addr.nil? then addr = @server_addr end
                addr_arr = addr.split('/')
                if addr_arr[-2].eql? "snapshots" then
-                       return addr_arr[0..-3].join("/"), addr_arr[-2..-1].join("/")
+                       return addr_arr[0..-3].join("/"), "/"+addr_arr[-2..-1].join("/")
                else
                        return nil
                end
@@ -1837,7 +1925,7 @@ class Client
 
                attr = get_attr_from_pkg(pkg_name, os, "attribute")
                if attr.nil? or attr.empty? then return false end
-               if attr[0].strip.upcase.eql? "META" then return true
+               if attr[0].strip.upcase.eql? "ROOT" then return true
                else return false end
        end
 
@@ -1867,4 +1955,45 @@ class Client
 
                if ret then @log.info "Snapshot is generated : #{ret}" end
        end
+       
+       ##Print change log to console.
+       public
+       def printChangeLog(snapshot1 = nil, snapshot2 = nil)
+   snapshotPath = File.join(@config_dist_path, PackageServerConstants::SNAPSHOT_INFO_FILE_NAME)
+         @log.info("Read information of snapshot from " + snapshotPath);
+         
+   ssController = SnapshotController.new(snapshotPath);
+         changeLogController = ChangeLogController.new(@server_addr, ssController)
+         
+         if (snapshot1.nil?()) then
+           changeLog = changeLogController.getLatestChangeLog();
+         elsif snapshot2.nil?() then
+           changeLog = changeLogController.getChangeLog(snapshot1);
+         else
+           changeLog = changeLogController.getTotalChangeLog(snapshot1, snapshot2);
+         end
+         
+         puts changeLog
+       end
+       
+       ##Print snapshot list to console.
+       public
+       def printSnapshotList(showAll=false)
+         snapshotPath = File.join(@config_dist_path, PackageServerConstants::SNAPSHOT_INFO_FILE_NAME)
+         @log.info("Read information of snapshot from " + snapshotPath);
+         
+         ssController = SnapshotController.new(snapshotPath);
+         if showAll then
+           result = ssController.getAllSnapshotList;
+         else
+           result = ssController.getManualSnapshotList ;
+         end
+         
+         result.each() do |snapshot|
+           puts PackageServerConstants::SNAPSHOT_NAME_FIELD + ": " + snapshot.getName()
+           puts PackageServerConstants::SNAPSHOT_TIME_FIELD + ": " + snapshot.getTime()
+           puts
+         end
+           
+       end
 end
index dd5caa8..76b6e51 100644 (file)
@@ -34,6 +34,7 @@ def set_default( options )
        if options[:t].nil? then options[:t] = false end
        if options[:f].nil? then options[:f] = false end
        if options[:v].nil? then options[:v] = false end
+ if options[:all].nil? then options[:all] = false end
 end
 
 def option_error_check( options )
@@ -57,7 +58,10 @@ def option_error_check( options )
                                options[:url].nil? or options[:url].empty? then
                        raise ArgumentError, "Usage: pkg-cli download -P <package name> -u <package server url> [-o <os>] [-l <location>] [--trace]"
                end
-
+       when "make-img" then
+               if options[:url].nil? or options[:url].empty? then
+                       raise ArgumentError, "Usage: pkg-cli make-img -u <package server url> [-o <os>]"
+               end
        when "install" then
                if options[:pkg].nil? or options[:pkg].empty? or
                                options[:url].nil? or options[:url].empty? then
@@ -109,6 +113,11 @@ def option_error_check( options )
                                options[:dist].nil? or options[:dist].empty? then
                        raise ArgumentError, "Usage: pkg-cli register -P <package file path> -a <server address> -d <distribution name> -w <password>"
                end
+       when "snapshotlist"
+  if options[:url].nil? or options[:url].empty? then
+    raise ArgumentError, "Usage: pkg-cli install-dep -P <package name> -u <package server url> [-o <os>]"
+  end
+       when "changelog"
 
        else
                raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
@@ -122,6 +131,7 @@ def option_parse
                + "\n" + "Subcommands:" + "\n" \
                + "\t" + "clean         Delete the package in your SDK environment." + "\n" \
                + "\t" + "download      Download the package in your SDK environment." + "\n" \
+               + "\t" + "make-img      Make SDK-Image." + "\n" \
                + "\t" + "install       Download the package from package-server and install the package in your SDK environment." + "\n" \
                + "\t" + "install-file  Install the package in your SDK environment." + "\n" \
                + "\t" + "uninstall     Uninstall the package in your SDK environment." + "\n" \
@@ -131,11 +141,14 @@ def option_parse
                + "\t" + "list-rpkg     Show the all packages in the package-server." + "\n" \
                + "\t" + "show-lpkg     Show the package in your SDK environment." + "\n" \
                + "\t" + "list-lpkg     Show the all packages in your SDK environment." + "\n" \
+               + "\t" + "snapshotlist  Show the snapshot list in your SDK environment." + "\n" \
+               + "\t" + "changelog     Show the change log in your SDK environment." + "\n" \
                + "\t" + "build-dep     Show build-dependency packages" + "\n" \
                + "\t" + "install-dep   Show install-dependency packages" + "\n" \
                + "\n" + "Subcommand usage:" + "\n" \
                + "\t" + "pkg-cli clean [-l <location>] [--force]" + "\n" \
                + "\t" + "pkg-cli download -P <package name> -u <package server url> [-o <os>] [-l <location>] [--trace]" + "\n" \
+               + "\t" + "pkg-cli make-img -u <package server url> [-o <os>]" + "\n" \
                + "\t" + "pkg-cli install -P <package name> -u <package server url> [-o <os>] [-l <location>] [--trace] [--force]" + "\n" \
                + "\t" + "pkg-cli install-file -P <package file> [-l <location>] [-u <package server url>] [--trace] [--force]" + "\n" \
                + "\t" + "pkg-cli uninstall -P <package name> [-l <location>] [--trace]" + "\n" \
@@ -145,6 +158,8 @@ def option_parse
                + "\t" + "pkg-cli list-rpkg -u <package server url> [-o <os>]" + "\n" \
                + "\t" + "pkg-cli show-lpkg -P <package name> [-l <location>]" + "\n"  \
                + "\t" + "pkg-cli list-lpkg [-l <location>]" + "\n" \
+               + "\t" + "pkg-cli snapshotlist -u <package server url> [--all]" + "\n"  \
+               + "\t" + "pkg-cli changelog -u <package server url> [-snapshot <snapshot name,snapshot name>]" + "\n"  \
                + "\t" + "pkg-cli build-dep -P <package name> -u <package server url> [-o <os>]" + "\n" \
                + "\t" + "pkg-cli install-dep -P <package name> -u <package server url> [-o <os>]" + "\n" \
                + "\t" + "pkg-cli register -P <package file path> -a <server address> -d <distribution name> -w <password>" + "\n" \
@@ -153,6 +168,7 @@ def option_parse
        optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
                # Set a banner, displayed at the top
                # of the help screen.
+         
 
                opts.banner = banner
 
@@ -201,11 +217,20 @@ def option_parse
                        puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
                        exit
                end
+               
+               opts.on('--all', 'show all information') do
+                 options[:all] = true
+               end
+               
+               opts.on('-s', '--snapshot snapshotName1,snapshotName2', Array, 'snapshot name') do |snapshotName|
+                 puts snapshotName[0], snapshotName[1]
+                 options[:snapshot] = snapshotName
+               end
 
        end
 
        cmd = ARGV[0]
-       if  cmd.eql? "download" or
+       if  cmd.eql? "download" or cmd.eql? "make-img" or
                cmd.eql? "install" or cmd.eql? "show-rpkg" or
                cmd.eql? "list-rpkg" or
                cmd.eql? "uninstall" or cmd.eql? "show-lpkg" or
@@ -214,6 +239,8 @@ def option_parse
                cmd.eql? "upgrade" or cmd.eql? "check-upgrade" or
                cmd.eql? "build-dep" or cmd.eql? "install-dep" or
                cmd.eql? "register" or
+               cmd.eql?("changelog") or
+               cmd.eql?("snapshotlist") or
                cmd =~ /(-v)|(--version)/  or
                cmd =~ /(help)|(-h)|(--help)/  then
 
index 5aa613b..b39957b 100644 (file)
@@ -216,7 +216,10 @@ class Distribution
                else
                        server_url = "#{@server_url}/snapshots/#{snapshot}"
                end
-               client = Client.new( server_url, "#{@location}/binary", @log )
+               client = Client.create( server_url, "#{@location}/binary", @log )
+               if client.nil? then
+                       raise RuntimeError, "Cannot create package client."
+               end
 
                # parents package server check
                if client.pkg_hash_os.keys.empty? then
@@ -930,7 +933,10 @@ class Distribution
        end
 
        def sync_archive_pkg
-               client = Client.new( @server_url, "#{@location}/source", @log )
+               client = Client.create( @server_url, "#{@location}/source", @log )
+               if client.nil? then
+                       raise RuntimeError, "Cannot create package client."
+               end
 
                download_list = client.archive_pkg_list - @archive_pkg_list
 
index 9d28540..8a1ef96 100644 (file)
@@ -46,9 +46,9 @@ class FileDownLoader
                logger.info "Downloading #{url}"
                if is_remote then
                        if logger.path.nil? or logger.path.empty? then
-                               ret = system "wget #{url} -O #{fullpath} -nv --tries=3"
+                               ret = system "wget #{url} -O #{fullpath} -nv --tries=3 --connect-timeout=10"
                        else                            
-                               pid,status = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv --tries=3", logger.path )
+                               pid,status = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv --tries=3 --connect-timeout=10", logger.path )
                                if not status.nil? then
                                        ret = (status.exitstatus != 0) ? false : true
                                end
@@ -66,8 +66,8 @@ class FileDownLoader
                if ret then
                        logger.info "Downloaded #{filename}.. OK"
                else
-                       logger.info "Failed to download #{filename}"
-                       logger.info "  [dist: #{path}]"
+                       logger.error "Failed to download #{filename}"
+                       logger.error "  [dist: #{path}]"
                end
                return ret
        end
diff --git a/src/pkg_server/model/distribution.rb b/src/pkg_server/model/distribution.rb
new file mode 100644 (file)
index 0000000..7253daa
--- /dev/null
@@ -0,0 +1,9 @@
+  
+class Distribution
+  attr_accessor :name, :time
+  
+  def initialize(name, time)
+    @name = name
+    @time = time
+  end
+end
\ No newline at end of file
diff --git a/src/pkg_server/model/snapshot.rb b/src/pkg_server/model/snapshot.rb
new file mode 100644 (file)
index 0000000..baf92f6
--- /dev/null
@@ -0,0 +1,40 @@
+
+
+class Snapshot
+  attr_accessor :properties    
+  
+  def initialize(properties)
+    @properties = properties;
+  end                        
+  
+  private 
+  def getValue(key)
+    properties.each() do |property|
+      if property.key().eql?(key) then
+        return property.value()
+      end
+    end
+    
+    return nil;
+  end
+  
+  public
+  def getName
+    return getValue(PackageServerConstants::SNAPSHOT_NAME_FIELD)
+  end
+  
+  public
+  def getTime
+    return getValue(PackageServerConstants::SNAPSHOT_TIME_FIELD)
+  end
+  
+  public 
+  def getType
+    return getValue(PackageServerConstants::SNAPSHOT_TYPE_FIELD)
+  end
+  
+  public
+  def getPath
+    return getValue(PackageServerConstants::SNAPSHOT_PATH_FIELD)
+  end
+end
\ No newline at end of file
index 5c803b4..47519fb 100644 (file)
@@ -31,14 +31,15 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
 $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
 $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/build_server"
 require "BuildComm"
-require "packageServerLog"
 require "packageServerConfig"
 require "distribution"
 require "SocketRegisterListener"
 require "client"
 require "utils"
+require "FileUtil"
 require "mail"
 require "DistSync"
+require "log"
 
 class PackageServer
        attr_accessor :id, :location, :log, :integrity
@@ -71,7 +72,7 @@ class PackageServer
                if not File.exist?( SERVER_ROOT )
                        FileUtils.mkdir_p( SERVER_ROOT )
                end
-               @log = PackageServerLog.new( @log_file_path )
+               @log = StandardOutLog.new( @log_file_path )
 
                server_information_initialize()
        end
@@ -120,6 +121,7 @@ class PackageServer
                        f.puts "integrity check : #{@integrity}"
                        f.puts "auto sync : #{@auto_sync_flag}"
                        f.puts "sync interval : #{@sync_interval}"
+                       f.puts "server port : #{@port}"
                        f.puts "server_url : #{dist_name} ->  #{server_url}"
                end
 
@@ -130,6 +132,9 @@ class PackageServer
                Utils.file_unlock(lock_file)
 
                @log.output( "package server [#{@id}] created successfully", Log::LV_USER )
+               @log.output( " - server location : #{@location}", Log::LV_USER )
+               @log.output( " - server configure file : #{@config_file_path}", Log::LV_USER )
+               @log.output( " - default server port : #{@port}", Log::LV_USER )
        end
 
        def register( file_path_list, dist_name, snapshot, test_flag, internal_flag = false )
@@ -203,9 +208,9 @@ class PackageServer
                # move file to package server
                binary_pkg_file_path_list.each do |l|
                        if test_flag then
-                               FileUtils.copy_file( l, "#{distribution.location}/temp/#{File.basename(l)}" )
+                               FileUtils.ln( l, "#{distribution.location}/temp/#{File.basename(l)}", :force => true )
                        else
-                               FileUtils.copy_file( l, "#{distribution.location}/binary/#{File.basename(l)}" )
+                               FileUtils.ln( l, "#{distribution.location}/binary/#{File.basename(l)}", :force => true )
                        end
                end
 
@@ -249,7 +254,7 @@ class PackageServer
                # if snapshot mode is true then generate snapshot
                if snapshot or test_flag then
                        @log.info "generaging snapshot"
-                       snapshot_name = distribution.generate_snapshot("", "", false, "Changed package: \n" + registed_package_list.map{|x|"- #{x.package_name}"}.join("\n") + "\n\n" + get_changelog_string(registed_package_list) )
+                       snapshot_name = distribution.generate_snapshot("", "", false, "Changed packages: \n" + registed_package_list.map{|x|"- #{x.package_name}"}.uniq.sort.join("\n") + "\n\n" + get_changelog_string(registed_package_list) )
                end
 
                Utils.file_unlock(@lock_file)
@@ -474,14 +479,34 @@ class PackageServer
        # start server daemon
        def start( port, passwd )
                @log.info "Package server Start..."
-               # set port number. default port is 3333
-               @port = port
-
-               # write package server port
-               File.open(@run_file_path, "w") do |f|
-                       f.puts @port
+               # if user input exsist, set port number.
+               if (port != "") then
+                       # update server port information
+                       # config file
+                       original_string = "server port : #{@port}"
+                       replacement_string = "server port : #{port}"
+                       contents = File.read(@config_file_path).gsub("#{original_string}", "#{replacement_string}")
+                       File.open(@config_file_path, "w") { |f| f.puts contents }
+                       
+                       # global variable
+                       @port = port
+               end
+
+               # write package server port for server lock
+               File.open(@run_file_path, "w") { |f| f.puts @port }
+
+               #lock the package server. Do not run the same server at the same time
+               if (not lockServer()) then
+                       printErrorMessage("Server \"#{id}\" is already running.")
+                       return
                end
-
+               
+               #check that the port is open
+               if BuildCommServer.port_open? port then
+                       printErrorMessage("Port \"#{port}\" is already in use.")
+                       return
+               end
+                
                # set job request listener
                @log.info "Setting listener..."
                listener = SocketRegisterListener.new(self)
@@ -549,7 +574,7 @@ class PackageServer
        end
 
        def self.list_id
-               @@log = PackageServerLog.new("#{SERVER_ROOT}/.log")
+               @@log = StandardOutLog.new("#{SERVER_ROOT}/.log")
 
                d = Dir.new( SERVER_ROOT )
                s = d.select {|f| not f.start_with?(".") }
@@ -570,7 +595,7 @@ class PackageServer
        end
 
        def self.list_dist( id )
-               @@log = PackageServerLog.new( "#{SERVER_ROOT}/.log" )
+               @@log = StandardOutLog.new( "#{SERVER_ROOT}/.log" )
 
                @@log.output( "=== ID [#{id}]'s distribution list ===", Log::LV_USER)
 
@@ -648,6 +673,8 @@ class PackageServer
                                                @auto_sync_flag = l.split(" :")[1].strip.upcase
                                        elsif l.start_with?( "sync interval :" ) then
                                                @sync_interval = l.split(" :")[1].strip.to_i
+                                       elsif l.start_with?( "server port :" ) then
+                                               @port = l.split(" :")[1].strip.to_i
                                        elsif l.start_with?( "server_url :" ) then
                                                info = l.split(" :")[1].split("->")
                                                @dist_to_server_url[info[0].strip] = info[1].strip
@@ -769,4 +796,20 @@ class PackageServer
                @incoming_path = "#{@config_dir}/incoming"
                @server_lock_file_path = "#{@config_dir}/.server_lock"
        end
+       
+       #If the 'run' file is already locked, Package server is already running. 
+       #in this case return false 
+       private
+       def lockServer
+         return FileUtil.exclusiveLock(@run_file_path) 
+       end
+         
+       private 
+       def printErrorMessage(errMsg)
+    @log.info "Server creation failed"
+    @log.error errMsg
+    
+    puts "Server creation failed"
+    puts errMsg
+       end
 end
index 3c782a6..eaef35a 100644 (file)
@@ -30,5 +30,8 @@ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
 require "utils"
 
 class PackageServerConfig
+  
        CONFIG_ROOT = "#{Utils::HOME}/.build_tools"
+ CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client"
 end
diff --git a/src/pkg_server/packageServerLog.rb b/src/pkg_server/packageServerLog.rb
deleted file mode 100644 (file)
index 1ca1068..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-=begin
-
- packageServerLog.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
-
-$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) + "/common"
-require "log"
-require "logger"
-
-class PackageServerLog < Log
-
-       def initialize(path)
-               super(path)
-               @second_out = $stdout
-       end
-
-       protected
-       def output_extra(msg)
-               @second_out.puts msg
-       end
-
-
-end
index 753a428..f44e746 100644 (file)
@@ -38,7 +38,7 @@ def set_default( options )
        options[:pkgs] = []
        options[:snaps] = []
        options[:bsnap] = ""
-       options[:port] = "3333"
+       options[:port] = ""
        options[:gensnap] = true
        options[:force] = false
        options[:test] = false
@@ -88,9 +88,6 @@ def option_error_check( options )
                        raise ArgumentError, "Usage: pkg-svr gen-snapshot -n <server name> -d <distribution> -s <snapshot name> [-b <base snapshot name>]"
                end
        when "start"
-               if options[:port].empty? then
-                       raise ArgumentError, "Usage: pkg-svr start -n <server name> -p <port> [-w <password>]"
-               end
        when "stop"
        when "sync"
        when "list"
@@ -132,7 +129,7 @@ def option_parse
                + "\t" + "pkg-svr sync -n <server name> -d <distribution> -s <snapshot_name> [--force] " + "\n"  \
                + "\t" + "pkg-svr clean -n <server name> -d <distribution> [-s <snapshot list>] " + "\n" \
                + "\t" + "pkg-svr start -n <server name> -p <port> [-w <password>]" + "\n" \
-               + "\t" + "pkg-svr stop -n <server name> " + "\n" \
+               + "\t" + "pkg-svr stop -n <server name> [-w <password>]" + "\n" \
                + "\t" + "pkg-svr list [-n <server name>] " + "\n" \
                + "\n" + "Options:" + "\n"
 
index 8461051..2799a40 100644 (file)
@@ -13,29 +13,32 @@ query         Query information about build-server.
 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.
 
 Subcommand usage:
-build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>] [-U user-email] [-V]
+build-cli build -N <project name> -d <server address> -U <user-id> -w <user-password> [-o <os>] [--async] [-D <distribution name>] [--save]
 build-cli query -d <server address>
 build-cli query-system -d <server address>
 build-cli query-project -d <server address>
 build-cli query-job -d <server address>
-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]
+build-cli query-log -d <server address> -j <job number> [--output <output file path>]
+build-cli cancel -j <job number> -d <server address> -U user-id -w <user-password>
+build-cli register -P <package file> -d <server address> -U user-id -w <user-password> [-t <ftp server url>] [-D <distribution name>]
 
 Options:
 -N, --project <project name>     project name
 -d, --address <server address>   build server address: 127.0.0.1:2224
 -o, --os <operating system>      target operating system: ubuntu-32/ubuntu-64/windows-32/windows-64/macos-64
 --async                      asynchronous job
+--save                       save the files built from remote server
 -j, --job <job number>           job number
--w, --passwd <password>          password for managing project
+-w, --passwd <user-password>     user password
 -P, --pkg <package file>         package file path
 -D, --dist <distribution name>   distribution name
 -t, --ftp <ftp server url>       ftp server url: ftp://dibsftp:dibsftp@127.0.0.1
--U, --user <user email>          user email infomation
--V, --verbose                    verbose mode
+-U, --user <user email>          user email
+--output <output_path>       output file path
 -h, --help                       display help
 -v, --version                    display version
index b084d40..6a68b77 100644 (file)
@@ -1,6 +1,6 @@
 #PRE-EXEC
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -u admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
index 977d486..66c798c 100644 (file)
@@ -1,6 +1,6 @@
 #PRE-EXEC
 #EXEC
-../../build-cli build -N non_exist_project -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N non_exist_project -d 127.0.0.1:2223 -o ubuntu-32  -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
-Error: Project not found!: non_exist_project on BASE
+Error: Project not found!: non_exist_project on unstable
index 0072e13..2ff3cdc 100644 (file)
@@ -1,6 +1,6 @@
 #PRE-EXEC
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:11113 -o ubuntu-32
+../../build-cli build -N testa -d 127.0.0.1:11113 -o ubuntu-32  -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
-Connection to server failed!
+Error: Connection failed!: 127.0.0.1:11113
index 1682338..b7dd7fd 100644 (file)
@@ -1,6 +1,6 @@
 #PRE-EXEC
 #EXEC
-../../build-cli build -N testa -d 111.11q.111.111:1111 -o ubuntu-32
+../../build-cli build -N testa -d 111.11q.111.111:1111 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
-Connection to server failed!
+Error: Connection failed!: 111.11q.111.111:1111
index 10e64d4..7e47e56 100644 (file)
@@ -1,11 +1,12 @@
 #PRE-EXEC
 echo "testa project is already built and uploaded in previeous testcase"
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
 Info: Initializing job...
 Info: Checking package version ...
-Error: Version must be increased :
+Error: Version must be increased!: 0.0.1 <= 0.0.1
 Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
index 6d08be1..ff224ad 100644 (file)
@@ -1,7 +1,7 @@
 #PRE-EXEC
 echo "Assume testa project is already built and uploaded in previeous testcase"
 #EXEC
-../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
@@ -16,6 +16,9 @@ Info: JobBuilder
 Info: Downloding client is initializing...
 Info: Installing dependent packages...
 Info:  * a
+Info: Wait for cache sync
+Info: Entering cache sync
+Info: Cache sync done
 Info: Downloading dependent source packages...
 Info: Make clean...
 Info: Make build...
index b20cb5b..83dc108 100644 (file)
@@ -4,7 +4,7 @@ echo "Assume testa/testb project is already built and uploaded in previeous test
 ../../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P b
 ../../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P a
 #EXEC
-../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
@@ -14,6 +14,6 @@ Info: Invoking a thread for building Job
 Info: New Job
 Info: Checking build dependency ...
 Info: Checking install dependency ...
-Error: Unmet dependency found!
-Error:  * a(ubuntu-32) for build-dependency
+Error: Error: Unmet dependency found!: a(ubuntu-32)
 Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
index c585766..e6fd14d 100644 (file)
@@ -2,7 +2,7 @@
 echo "This is the test case for omitting os"
 ../../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P a
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:2223 
+../../build-cli build -N testa -d 127.0.0.1:2223 -U admin@user -w 1234 
 #POST-EXEC
 #EXPECT
 Info: Added new job
index 83311d4..e20ea04 100644 (file)
@@ -1,11 +1,11 @@
 #PRE-EXEC
 echo "if there doe not exist server to build, error"
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:2223 -o windows-32
+../../build-cli build -N testa -d 127.0.0.1:2223 -o windows-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
 Info: Initializing job...
-Error: No servers that are able to build your packages.
-Error: Host-OS (windows-32) is not supported in build server.
+Error: No servers supports the "Host-OS"!: windows-32
 Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
index a0b9e6f..d29093c 100644 (file)
@@ -2,10 +2,7 @@
 echo "wrong os name in build command"
 ../../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P a
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:2223 -o wrong_os_name
+../../build-cli build -N testa -d 127.0.0.1:2223 -o wrong_os_name -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
-Error: Unsupported OS name used!: wrong_os_name
-Supported OS list.
-* ubuntu-32
-* windows-32
+Error: Unsupported OS name used!: wrong_os_name... Use a name in (ubuntu-32|windows-32)
index cccfe9f..529308f 100644 (file)
@@ -1,7 +1,7 @@
 #PRE-EXEC
 echo "wrong os name in resolve command"
 #EXEC
-../../build-cli resolve -N testa -d 127.0.0.1:2223 -o wrong_os_name
+../../build-cli resolve -N testa -d 127.0.0.1:2223 -o wrong_os_name -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Error: Unsupported OS name used!: wrong_os_name
index 59fd045..d49db61 100644 (file)
@@ -3,10 +3,10 @@ echo "Assume that testc project has the password (1111)"
 echo "Assume that testa,testb which are depended by testc are built and uploaded"
 echo "For, work around solution, removed cache"
 rm -rf buildsvr01/projects/testa/cache
-../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32
-../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
+../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
 #EXEC
-../../build-cli build -N testc -d 127.0.0.1:2223 -w 1111 -o ubuntu-32
+../../build-cli build -N testc -d 127.0.0.1:2223 -w 1111 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
@@ -21,7 +21,13 @@ Info: JobBuilder
 Info: Downloding client is initializing...
 Info: Installing dependent packages...
 Info:  * a
+Info: Wait for cache sync
+Info: Entering cache sync
+Info: Cache sync done
 Info:  * b
+Info: Wait for cache sync
+Info: Entering cache sync
+Info: Cache sync done
 Info: Downloading dependent source packages...
 Info: Make clean...
 Info: Make build...
index df9fff2..1a4ed6a 100644 (file)
@@ -2,7 +2,7 @@
 echo "Assume that testc project has the password (1111)"
 echo "Assume that testa,testb which are depended by testc are built and uploaded"
 #EXEC
-../../build-cli build -N testc -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N testc -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user 
 #POST-EXEC
 #EXPECT
-Error: Project password required!: Use -w option to input your project password
+Usage: build-cli build -N <project name> -d <server address> -U <user-id> -w <user-password> [-o <os>] [--async] [-D <distribution name>] [--save]
index 9b7cd98..a0485d7 100644 (file)
@@ -2,7 +2,7 @@
 echo "Assume that testc project has the password (1111)"
 echo "Assume that testa,testb which are depended by testc are built and uploaded"
 #EXEC
-../../build-cli build -N testc -d 127.0.0.1:2223 -w 2222 -o ubuntu-32
+../../build-cli build -N testc -d 127.0.0.1:2223 -w 2222 -o ubuntu-32 -U admin@user -w 1111
 #POST-EXEC
 #EXPECT
-Error: Project password not matched!
+Error: User password not matched!: Email : admin@user && Password : 1111
index 1f798aa..acc64cb 100644 (file)
@@ -1,7 +1,7 @@
 #PRE-EXEC
 ../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P c
 #EXEC
-../../build-cli build -N testc -d 127.0.0.1:2223 -w 1111 --async -o ubuntu-32
+../../build-cli build -N testc -d 127.0.0.1:2223 -w 1111 --async -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
index 9653e45..038a506 100644 (file)
@@ -3,9 +3,9 @@
 ../../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P b
 ../../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P a
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:2223 --async -o ubuntu-32
+../../build-cli build -N testa -d 127.0.0.1:2223 --async -o ubuntu-32 -U admin@user -w 1234
 sleep 1
-../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
@@ -24,6 +24,9 @@ Info: JobBuilder
 Info: Downloding client is initializing...
 Info: Installing dependent packages...
 Info:  * a
+Info: Wait for cache sync
+Info: Entering cache sync
+Info: Cache sync done
 Info: Downloading dependent source packages...
 Info: Make clean...
 Info: Make build...
index 32218a2..a321649 100644 (file)
@@ -3,7 +3,7 @@ echo "reverse fail"
 #EXEC
 rm -rf git01/a
 cd git01;tar xf a_v2.tar.gz
-../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
@@ -25,7 +25,9 @@ Info: Generatiing pkginfo.manifest...
 Info: Zipping...
 Info: Creating package file ... a_0.0.2_ubuntu-32.zip
 Info: Checking reverse build dependency ...
-Info:  * Will check reverse-build for projects: testb(ubuntu-32)
-Info:  * Added new job for reverse-build ... testb(ubuntu-32)
-Info:  * Reverse-build FAIL ... testb(ubuntu-32)
+Info:  * Will check reverse-build for projects:
+Info:  * Added new job for reverse-build ... testb
+Info:  * Reverse-build FAIL ... testb
+Error: Error: Reverse-build-check failed!
 Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
index 9ee83c9..304acd4 100644 (file)
@@ -3,14 +3,12 @@ echo "Trying to upload a_0.0.1 with different commit-id is already uploaded"
 rm -rf git01/c
 cd git01;tar xf c_v1_1.tar.gz
 #EXEC
-../../build-cli build -N testc -d 127.0.0.1:2223 -o ubuntu-32 -w 1111
+../../build-cli build -N testc -d 127.0.0.1:2223 -o ubuntu-32 -w 1111 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
 Info: Initializing job...
 Info: Checking package version ...
-Error: Source code has been changed without increasing version!
-Error:  * Version :
-Error:  * Before  :
-Error:  * Current :
+Error: Source code has been changed without increasing version!: 0.0.1
 Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
index 44ff734..20204d7 100644 (file)
@@ -3,11 +3,14 @@ cd git01;tar xf a_v2.tar.gz
 cd git01;tar xf b_v2.tar.gz
 cd git01;tar xf c_v2.tar.gz
 #EXEC
-../../build-cli build -N testa,testb,testc -d 127.0.0.1:2223 -o ubuntu-32 -w 1111
+../../build-cli build -N testa,testb,testc -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
 Info: Initializing job...
+Info: Initializing sub-job
+Info: Initializing sub-job
+Info: Initializing sub-job
 Info: Invoking a thread for MULTI-BUILD Job
 Info: New Job
 Info: Added new job "testa" for ubuntu-32!
index de1b348..65f1d85 100644 (file)
@@ -1,12 +1,20 @@
 #PRE-EXEC
 echo "This test case must be execute right after testcase 22"
 #EXEC
-../../build-cli build -N testa,testb,testc -d 127.0.0.1:2223 -o ubuntu-32 -w 1111
+../../build-cli build -N testa,testb,testc -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
 Info: Initializing job...
-Info: Failed to initialize sub-job
-Info: Failed to initialize sub-job
-Info: Failed to initialize sub-job
+Info: Initializing sub-job
+Error: Failed to initialize sub-job "testa" for
+Error:  * Version must be increased!:
+Info: Initializing sub-job
+Error: Failed to initialize sub-job "testb" for
+Error:  * Version must be increased!:
+Info: Initializing sub-job
+Error: Failed to initialize sub-job "testc" for
+Error:  * Version must be increased!:
+Error: Initializing sub jobs failed!
 Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
index adaeb98..878a67d 100644 (file)
@@ -1,11 +1,13 @@
 #PRE-EXEC
 cd git01;tar xf a_v3.tar.gz
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32,windows-32
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32,windows-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
 Info: Initializing job...
+Info: Initializing sub-job
+Info: Initializing sub-job
 Info: Invoking a thread for MULTI-BUILD Job
 Info: New Job
 Info: Added new job "testa" for ubuntu-32!
index eb0965c..e5b0e40 100644 (file)
@@ -6,10 +6,20 @@ cd git01;tar xf a_v4.tar.gz
 cd git01;tar xf b_v4.tar.gz
 cd git01;tar xf c_v4.tar.gz
 #EXEC
-../../build-svr fullbuild -n testserver3
+../../build-cli build -N testa,testb,testc,testa1,testd -o all --rebuild -d 127.0.0.1:2223 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
+Info: Added new job
 Info: Initializing job...
+Info: Initializing sub-job
+Info: Initializing sub-job
+Info: Initializing sub-job
+Info: Initializing sub-job
+Info: Initializing sub-job
+Info: Initializing sub-job
+Info: Initializing sub-job
+Info: Initializing sub-job
+Info: Initializing sub-job
 Info: Invoking a thread for MULTI-BUILD Job
 Info: New Job
 Info: Added new job 
index 66eb1cf..4d01aff 100644 (file)
@@ -1,7 +1,7 @@
 #PRE-EXEC
 cd git01;tar xf c_v5.tar.gz
 #EXEC
-../../build-cli build -N testc -d 127.0.0.1:2223 -o li_* -w 1111
+../../build-cli build -N testc -d 127.0.0.1:2223 -o li_* -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Error: Unsupported OS name used!: There is no OS name matched.
index 27dfb11..a6c315d 100644 (file)
@@ -1,7 +1,7 @@
 #PRE-EXEC
 echo "wild card"
 #EXEC
-../../build-cli build -N testc -d 127.0.0.1:2223 -o ubuntu-* -w 1111
+../../build-cli build -N testc -d 127.0.0.1:2223 -o ubuntu-* -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
@@ -16,7 +16,13 @@ Info: JobBuilder
 Info: Downloding client is initializing...
 Info: Installing dependent packages...
 Info:  * a
+Info: Wait for cache sync
+Info: Entering cache sync
+Info: Cache sync done
 Info:  * b
+Info: Wait for cache sync
+Info: Entering cache sync
+Info: Cache sync done
 Info: Downloading dependent source packages...
 Info: Make clean...
 Info: Make build...
index 47d1580..4ce364d 100644 (file)
@@ -3,7 +3,7 @@ echo "reverse success"
 #EXEC
 rm -rf git01/a
 cd git01;tar xf a_v5.tar.gz
-../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
index 2fe774e..ee1c706 100644 (file)
@@ -1,7 +1,7 @@
 #PRE-EXEC
 echo "user check"
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -U xxuser@user
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -U xxuser@user -w 1234
 #POST-EXEC
 #EXPECT
 Error: User account not found!: xxuser@user
diff --git a/test/build-server.basic1/build-cli-31.testcase b/test/build-server.basic1/build-cli-31.testcase
new file mode 100644 (file)
index 0000000..a37f1e0
--- /dev/null
@@ -0,0 +1,31 @@
+#PRE-EXEC
+echo "query-log"
+#EXEC
+../../build-cli query-log -d 127.0.0.1:2223 -j 1 | grep {2} | cut -d '}' -f2
+#POST-EXEC
+#EXPECT
+Added new job
+Initializing job...
+Checking package version ...
+Invoking a thread for building Job
+New Job
+hecking build dependency ...
+Checking install dependency ...
+Started to build this job...
+JobBuilder
+ownloding client is initializing...
+Installing dependent packages...
+Downloading dependent source packages...
+Make clean...
+Make build...
+Make install...
+eneratiing pkginfo.manifest...
+Zipping...
+Creating package file ... a_0.0.1_ubuntu-32.zip
+Checking reverse build dependency ...
+Uploading ...
+Upload succeeded. Sync local pkg-server again...
+Snapshot:
+Job is completed!
+Job is FINISHED successfully!
+Updating the source info for project "testa"
diff --git a/test/build-server.basic1/build-cli-32.testcase b/test/build-server.basic1/build-cli-32.testcase
new file mode 100644 (file)
index 0000000..5a14609
--- /dev/null
@@ -0,0 +1,10 @@
+#PRE-EXEC
+echo "query-log"
+rm -rf a.txt
+#EXEC
+../../build-cli query-log -d 127.0.0.1:2223 -j 1 --output a.txt
+#POST-EXEC
+rm -rf a.txt
+#EXPECT
+Started query log, writing to the file "a.txt"
+End query log, check file "a.txt"
diff --git a/test/build-server.basic1/build-cli-33.testcase b/test/build-server.basic1/build-cli-33.testcase
new file mode 100644 (file)
index 0000000..a54288d
--- /dev/null
@@ -0,0 +1,36 @@
+#PRE-EXEC
+echo "This case will test --save option"
+#EXEC
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 --save --rebuild -U admin@user -w 1234
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Info: Invoking a thread for building Job
+Info: New Job
+Info: Checking build dependency ...
+Info: Checking install dependency ...
+Info: Started to build this job...
+Info: JobBuilder
+Info: Downloding client is initializing...
+Info: Installing dependent packages...
+Info: Downloading dependent source packages...
+Info: Make clean...
+Info: Make build...
+Info: Make install...
+Info: Generatiing pkginfo.manifest...
+Info: Zipping...
+Info: Creating package file ...
+Info: Checking reverse build dependency ...
+Info:  * Will check reverse-build for projects: testb(ubuntu-32), testc(ubuntu-32)
+Info:  * Added new job for reverse-build ... testb(ubuntu-32)
+Info:  * Added new job for reverse-build ... testc(ubuntu-32)
+Info:  * Reverse-build OK ...
+Info:  * Reverse-build OK ...
+Info: Copying result files to
+Info:  *
+Info: Job is completed!
+Info: Job is FINISHED successfully!
+Info: Updating the source info for project "testa"
+Info: Receiving file from remote server : 
diff --git a/test/build-server.basic1/build-cli-34.testcase b/test/build-server.basic1/build-cli-34.testcase
new file mode 100644 (file)
index 0000000..074ecd8
--- /dev/null
@@ -0,0 +1,24 @@
+#PRE-EXEC
+echo "This case will test --save option for MULTI build job"
+#EXEC
+../../build-cli build -N testa,testb -d 127.0.0.1:2223 -o ubuntu-32 --save --rebuild -U admin@user -w 1234
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Initializing sub-job
+Info: Initializing sub-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
+Info:  * Sub-Job
+Info:  * Sub-Job
+Info:  * Sub-Job
+Info: Copying result files to
+Info:  *
+Info:  *
+Info: Job is completed!
+Info: Receiving file from remote server :
+Info: Receiving file from remote server :
diff --git a/test/build-server.basic1/build-cli-35.testcase b/test/build-server.basic1/build-cli-35.testcase
new file mode 100644 (file)
index 0000000..4bfac46
--- /dev/null
@@ -0,0 +1,30 @@
+#PRE-EXEC
+echo "This case will test --noreverse option"
+#EXEC
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 --rebuild --noreverse -U admin@user -w 1234
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Info: Invoking a thread for building Job
+Info: New Job
+Info: Checking build dependency ...
+Info: Checking install dependency ...
+Info: Started to build this job...
+Info: JobBuilder
+Info: Downloding client is initializing...
+Info: Installing dependent packages...
+Info: Downloading dependent source packages...
+Info: Make clean...
+Info: Make build...
+Info: Make install...
+Info: Generatiing pkginfo.manifest...
+Info: Zipping...
+Info: Creating package file ...
+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 "testa"
diff --git a/test/build-server.basic1/build-cli-36.testcase b/test/build-server.basic1/build-cli-36.testcase
new file mode 100644 (file)
index 0000000..4a9a2b7
--- /dev/null
@@ -0,0 +1,13 @@
+#PRE-EXEC
+echo "This case will check redundent job"
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 --rebuild -U admin@user -w 1234  &
+#EXEC
+sleep 2
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 --rebuild -U admin@user -w 1234
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Error: There already exists same job.
+Error: Building job on remote server failed!
diff --git a/test/build-server.basic1/build-cli-37.testcase b/test/build-server.basic1/build-cli-37.testcase
new file mode 100644 (file)
index 0000000..9362416
--- /dev/null
@@ -0,0 +1,12 @@
+#PRE-EXEC
+echo "error case when wrong git repository setted"
+../../build-svr add-prj -n testserver3 -N testaErr -g `pwd`/git01/aErr -b master
+#EXEC
+../../build-cli build -N testaErr -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Error: Git clone failed!!: git clone 
+Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
diff --git a/test/build-server.basic1/build-cli-38.testcase b/test/build-server.basic1/build-cli-38.testcase
new file mode 100644 (file)
index 0000000..544cc9c
--- /dev/null
@@ -0,0 +1,12 @@
+#PRE-EXEC
+echo "error case when wrong git branch setted"
+../../build-svr add-prj -n testserver3 -N testbErr -g `pwd`/git01/b -b testError
+#EXEC
+../../build-cli build -N testbErr -d 127.0.0.1:2223 -o ubuntu-32 -U admin@user -w 1234
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Error: Git checkout failed!!: git checkout
+Error: Job is stopped by ERROR
+Error: Building job on remote server failed!
index 39fd9ab..c72a03c 100755 (executable)
@@ -24,13 +24,13 @@ mysql -u root -p --password=$DB_PASSWD -h localhost < a
 ${RUBY} ../../../build-svr migrate -n testserver3 --dsn Mysql:testserver3:localhost --dbuser root --dbpassword $DB_PASSWD
 rm -f a
 cd ..
-${RUBY} ../../build-svr add-dist -n testserver3 -D BASE -u `pwd`/pkgsvr01/unstable -d 127.0.0.1:3333 -w score
+${RUBY} ../../build-svr add-dist -n testserver3 -D unstable -u `pwd`/pkgsvr01/unstable -d 127.0.0.1:3333 -w score
 ${RUBY} ../../build-svr add-svr -n testserver3 -d 127.0.0.1:2224
 ${RUBY} ../../build-svr add-os -n testserver3 -o ubuntu-32
 ${RUBY} ../../build-svr add-os -n testserver3 -o windows-32
 ${RUBY} ../../build-svr add-prj -n testserver3 -N testa -g `pwd`/git01/a -b master
 ${RUBY} ../../build-svr add-prj -n testserver3 -N testb -g `pwd`/git01/b -b master
-${RUBY} ../../build-svr add-prj -n testserver3 -N testc -g `pwd`/git01/c -b master -w 1111
+${RUBY} ../../build-svr add-prj -n testserver3 -N testc -g `pwd`/git01/c -b master 
 ${RUBY} ../../build-svr add-prj -n testserver3 -N testd -g `pwd`/git01/d -b master -o ubuntu-32
 ${RUBY} ../../build-svr add-prj -n testserver3 -N teste -P bin
 ${RUBY} ../../build-svr add-prj -n testserver3 -N testa1 -g `pwd`/git01/a1 -b master
index 478f804..babed08 100644 (file)
@@ -28,3 +28,11 @@ build-cli-27.testcase
 build-cli-28.testcase
 build-cli-29.testcase
 build-cli-30.testcase
+build-cli-31.testcase
+build-cli-32.testcase
+build-cli-33.testcase
+build-cli-34.testcase
+build-cli-35.testcase
+build-cli-36.testcase
+build-cli-37.testcase
+build-cli-38.testcase
index 271b3c0..0f25cb9 100644 (file)
@@ -27,7 +27,6 @@ remove-sync   Remove package repository URL.
 add-prj       Add project to build.
 remove-prj    Remove project.
 register      Register the package to the build-server.
-fullbuild     Build all your projects and upload them to package server.
 query         Show build server configuration.
 set-attr      Set build server atribute.
 get-attr      Get build server atribute.
@@ -36,7 +35,7 @@ Subcommand usage:
 build-svr create -n <server name> [-t <ftp server url>]
 build-svr remove -n <server name>
 build-svr migrate -n <server name> [--dsn <db dsn> [--dbuser <db_user> --dbpassword <db_password>] ]
-build-svr start -n <server name> -p <port>
+build-svr start -n <server name> [-p <port>]
 build-svr stop -n <server name>
 build-svr upgrade -n <server name>
 build-svr add-svr -n <server name> -d <friend server address>
@@ -51,7 +50,6 @@ build-svr add-sync -n <server name> -u <remote pkg server url> [--dist <distribu
 build-svr remove-sync -n <server name> -u <remote pkg server url> [--dist <distribution>]
 build-svr add-prj -n <server name> -N <project name> (-g <git repository> -b <git branch>|-P <package name>) [-w <password>] [-o <os list>] [--dist <distribution>]
 build-svr remove-prj -n <server name> -N <project name> [--dist <distribution>]
-build-svr fullbuild -n <server name> [--dist <distribution>]
 build-svr register -n <server name> -P <package file> [--dist <distribution>]
 build-svr query -n <server name>
 build-svr set-attr -n <server name> -A <attribute> -V <value>
index 236a9ef..c018e1b 100644 (file)
@@ -2,6 +2,7 @@
 rm -rf buildsvr01
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -t ftp://dibsftp:coreps2@172.21.111.132
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 cd buildsvr01; ../../../build-svr add-dist -n testserver3 -D BASE -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 
 #EXEC
 ../../build-svr add-svr -n testserver3 -d 127.0.0.1:2223
index 23d530f..e26bc5f 100644 (file)
@@ -2,6 +2,7 @@
 mkdir buildsvr01
 rm -rf ~/.build_tools/build_server/testserver3
 cd buildsvr01; ../../../build-svr create -n testserver3 -t ftp://dibsftp:coreps2@172.21.111.132
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 cd buildsvr01; ../../../build-svr add-dist -n testserver3 -D BASE -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333
 ../../build-svr start -n testserver3 -p 2223 &
 #EXEC
index b3f62fe..421fbf0 100644 (file)
@@ -1,11 +1,11 @@
 #PRE-EXEC
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 #EXEC
 ../../build-svr stop -n testserver3
 #POST-EXEC
 ../../build-svr remove -n testserver3
 rm -rf buildsvr01
 #EXPECT
-generating
 Server is not running!
index 0b2f399..3e6f3bc 100644 (file)
@@ -2,6 +2,7 @@
 rm -rf buildsvr01
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -t ftp://dibsftp:coreps2@172.21.111.132
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 cd buildsvr01; ../../../build-svr add-dist -n testserver3 -D BASE -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333
 ../../build-svr add-os -n testserver3 -o ubuntu-32
 #EXEC
index f87355b..c00d823 100644 (file)
@@ -2,6 +2,7 @@
 rm -rf buildsvr01
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -t ftp://dibsftp:coreps2@172.21.111.132
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 cd buildsvr01; ../../../build-svr add-dist -n testserver3 -D BASE -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333
 #EXEC
 ../../build-svr add-prj -n testserver3 -N testa -g test_git -b test_branch -w 1111
index ce59935..fff93a4 100644 (file)
@@ -3,6 +3,7 @@ rm -rf buildsvr01
 rm -rf ~/.build_tools/build_server/testserver3
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -t ftp://ftpuser:ftpuser@127.0.0.1
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 cd buildsvr01; ../../../build-svr add-dist -n testserver3 -D BASE -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333
 ../../build-svr add-os -n testserver3 -o ubuntu-32
 #EXEC
index 244ce63..02b86bf 100644 (file)
@@ -2,6 +2,7 @@
 rm -rf buildsvr01
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -t ftp://dibsftp:coreps2@172.21.111.132
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 cd buildsvr01; ../../../build-svr add-dist -n testserver3 -D BASE -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333
 #EXEC
 ../../build-svr add-os -n testserver3 -o ubuntu-32
index d2517ee..2adde9c 100644 (file)
@@ -2,6 +2,7 @@
 rm -rf buildsvr01
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 #EXEC
 ../../build-svr add-os -n testserver3 -o ubuntu-32
 ../../build-svr add-os -n testserver3 -o ubuntu-32
@@ -9,6 +10,5 @@ cd buildsvr01; ../../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/uns
 ../../build-svr remove -n testserver3
 rm -rf buildsvr01
 #EXPECT
-generating
 Target OS is added successfully!
 Target OS already exists in list!
index 5a7ce72..9176c14 100644 (file)
@@ -2,6 +2,7 @@
 rm -rf buildsvr01
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 ../../build-svr add-os -n testserver3 -o ubuntu-32
 ../../build-svr add-os -n testserver3 -o windows-32
 #EXEC
index 1396b9c..61be17e 100644 (file)
@@ -2,8 +2,10 @@
 rm -rf buildsvr01
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -t ftp://ftpuser:ftpuser@172.21.111.124
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 cd buildsvr01; ../../../build-svr add-dist -n testserver3 -D BASE -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333
 ../../build-svr add-os -n testserver3 -o ubuntu-32
+../../build-svr add-prj -n testserver3 -N bin -P bin -o ubuntu-32
 mkdir -p bin
 cp ../bin/bin_0.0.0_ubuntu-32.zip bin/bin_0.0.0_wrongosname.zip
 ../../build-svr start -n testserver3 -p 2223 &
@@ -17,6 +19,7 @@ sleep 1
 rm -rf buildsvr01
 rm -rf bin/bin/bin_0.0.0_wrongosname.zip
 #EXPECT
+Info: Added new job
 Info: Initializing job...
-Error: Unsupported OS "wrongosname" is used!
+Error: Unsupported OS used in package file name!: wrongosname
 Error: Job is stopped by ERROR
index b703113..ae9258a 100644 (file)
@@ -2,7 +2,7 @@
 rm -rf buildsvr01
 mkdir buildsvr01
 cd buildsvr01; ../../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://ftpuser:ftpuser@172.21.111.124
-cd buildsvr01; ../../../build-svr migrate -n testserver3
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 #EXEC
 ../../build-svr set-attr -n testserver3 -A MAX_WORKING_JOBS -V 3
 ../../build-svr get-attr -n testserver3 -A MAX_WORKING_JOBS
diff --git a/test/build-server.basic2/build-svr-23.testcase b/test/build-server.basic2/build-svr-23.testcase
new file mode 100644 (file)
index 0000000..ce6af1a
--- /dev/null
@@ -0,0 +1,41 @@
+#PRE-EXEC
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://ftpuser:ftpuser@172.21.111.124
+#EXEC
+../../build-svr add-dist -n testserver3 -D BASE -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333
+../../build-svr remove-dist -n testserver3 -D BASE
+../../build-svr query -n testserver3
+../../build-svr add-svr -n testserver3 -d 127.0.0.1:2223
+../../build-svr remove-svr -n testserver3 -d 127.0.0.1:2223
+../../build-svr add-os -n testserver3 -o ubuntu-32
+../../build-svr remove-os -n testserver3 -o ubuntu-32
+../../build-svr lock-dist -n testserver3 -D BASE
+../../build-svr unlock-dist -n testserver3 -D BASE
+../../build-svr add-sync -n testserver3 -u `pwd`/../pkgsvr01/unstable
+../../build-svr remove-sync -n testserver3 -u `pwd`/../pkgsvr01/unstable
+../../build-svr add-prj -n testserver3 -N testx -g test_git -b test_branch -o ubuntu-32
+../../build-svr remove-prj -n testserver3 -N testx
+../../build-svr register -n testserver3 -P bin/bin_0.0.0_ubuntu-32.zip
+../../build-svr set-attr -n testserver3 -A MAX_WORKING_JOBS -V 3
+../../build-svr get-attr -n testserver3 -A MAX_WORKING_JOBS
+#POST-EXEC
+../../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
+Error: No DB exists and create(migrate) DB first!
diff --git a/test/build-server.basic2/build-svr-24.testcase b/test/build-server.basic2/build-svr-24.testcase
new file mode 100644 (file)
index 0000000..895215a
--- /dev/null
@@ -0,0 +1,12 @@
+#PRE-EXEC
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://ftpuser:ftpuser@172.21.111.124
+#EXEC
+../../build-svr set-attr -n testserver3 -A MAX_WORKING_JOBS -V 3
+../../build-svr get-attr -n testserver3 -A MAX_WORKING_JOBS
+#POST-EXEC
+../../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+3
diff --git a/test/build-server.basic2/build-svr-25.testcase b/test/build-server.basic2/build-svr-25.testcase
new file mode 100644 (file)
index 0000000..ef0ab7d
--- /dev/null
@@ -0,0 +1,15 @@
+#PRE-EXEC
+../../build-svr remove -n testserver3
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://ftpuser:ftpuser@172.21.111.124
+#EXEC
+../../build-svr get-attr -n testserver3 -A MAX_JOBS
+../../build-svr set-attr -n testserver3 -A MAX_JOBS -V 3
+../../build-svr get-attr -n testserver3 -A MAX_JOBS
+#POST-EXEC
+../../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+4
+3
index 05f65d2..7b2d0f6 100644 (file)
@@ -17,3 +17,6 @@ build-svr-18.testcase
 build-svr-19.testcase
 build-svr-20.testcase
 build-svr-21.testcase
+build-svr-23.testcase
+build-svr-24.testcase
+build-svr-25.testcase
index 21843e1..384b21b 100644 (file)
@@ -1,6 +1,6 @@
 #PRE-EXEC
 #EXEC
-../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -D unstable
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -D unstable -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
@@ -14,7 +14,6 @@ Info: Start to build on remote server...
 Info: Sending build request to remote server...
 Info: Added new job
 Info: Initializing job...
-Info: Copying external dependent pkgs...
 Info: Invoking a thread for building Job
 Info: New Job
 Info: Started to build this job...
@@ -28,13 +27,11 @@ Info: Make install...
 Info: Generatiing pkginfo.manifest...
 Info: Zipping...
 Info: Creating package file ... a_0.0.1_ubuntu-32.zip
-Info: Copying log to
 Info: Copying result files to
 Info:  *
 Info: Job is completed!
 Info: Job is FINISHED successfully!
-Info: Updating the source info for project "UNNAMED
-Info: Receiving log file from remote server...
+Info: Updating the source info for project "TRANSFERRED"
 Info: Receiving file from remote server : a_0.0.1_ubuntu-32.zip
 Info: Checking reverse build dependency ...
 Info: Uploading ...
index cbe7440..40c07a4 100644 (file)
@@ -1,6 +1,6 @@
 #PRE-EXEC
 #EXEC
-../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32 -D unstable
+../../build-cli build -N testb -d 127.0.0.1:2223 -o ubuntu-32 -D unstable -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
@@ -14,7 +14,6 @@ Info: Start to build on remote server...
 Info: Sending build request to remote server...
 Info: Added new job
 Info: Initializing job...
-Info: Copying external dependent pkgs...
 Info: Invoking a thread for building Job
 Info: New Job
 Info: Started to build this job...
@@ -22,6 +21,9 @@ Info: JobBuilder
 Info: Downloding client is initializing...
 Info: Installing dependent packages...
 Info:  * a
+Info: Wait for cache sync
+Info: Entering cache sync
+Info: Cache sync done
 Info: Downloading dependent source packages...
 Info: Make clean...
 Info: Make build...
@@ -29,13 +31,11 @@ Info: Make install...
 Info: Generatiing pkginfo.manifest...
 Info: Zipping...
 Info: Creating package file ... b_0.0.1_ubuntu-32.zip
-Info: Copying log to
 Info: Copying result files to
 Info:  *
 Info: Job is completed!
 Info: Job is FINISHED successfully!
-Info: Updating the source info for project "UNNAMED
-Info: Receiving log file from remote server...
+Info: Updating the source info for project "TRANSFERRED"
 Info: Receiving file from remote server : b_0.0.1_ubuntu-32.zip
 Info: Checking reverse build dependency ...
 Info: Uploading ...
diff --git a/test/build-server.multi-svr1/03.testcase b/test/build-server.multi-svr1/03.testcase
new file mode 100644 (file)
index 0000000..ee12728
--- /dev/null
@@ -0,0 +1,21 @@
+#PRE-EXEC
+#EXEC
+../../build-cli build -N testa,testb -d 127.0.0.1:2223 -o ubuntu-32 -D unstable --rebuild -U admin@user -w 1234
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Initializing sub-job
+Info: Initializing sub-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!
index 56b8da5..5dac695 100755 (executable)
@@ -3,24 +3,13 @@ if [ "x${RUBY}" = "x" ] ;then
     RUBY="ruby -d"
 fi
 
-if [ ! "$DB_PASSWD" ] ; then
-       read -p "Insert DB password: " input
-       export DB_PASSWD=$input
-else
-       echo $DB_PASSWD
-fi
-
 rm -rf buildsvr02
 
 ../../build-svr remove -n testserver4
 mkdir buildsvr02
 cd buildsvr02
 ${RUBY} ../../../build-svr create -n testserver4
-echo "DROP DATABASE testserver4;" > a
-mysql -u root -p --password=$DB_PASSWD -h localhost < a
-${RUBY} ../../../build-svr migrate -n testserver4 --dsn Mysql:testserver4:localhost --dbuser root --dbpassword $DB_PASSWD
-rm -f a
 cd ..
-${RUBY} ../../build-svr add-dist -n testserver4 -D unstable -u `pwd`/pkgsvr01/unstable -d 127.0.0.1:3333
+#${RUBY} ../../build-svr add-dist -n testserver4 -D unstable -u `pwd`/pkgsvr01/unstable -d 127.0.0.1:3333
 
 ${RUBY} ../../build-svr start -n testserver4 -p 2224 --CHILD
index fb3d879..e54b816 100644 (file)
@@ -3,6 +3,7 @@ rm -rf buildsvr01
 rm -rf ~/.build_tools/build_server/testserver3
 mkdir buildsvr01
 cd buildsvr01;../../../build-svr create -n testserver3 -t ftp://ftpuser:ftpuser@127.0.0.1
+cd buildsvr01; ../../../build-svr migrate -n testserver3 --dsn SQLite3:`pwd`/server.db
 ../../build-svr add-os -n testserver3 -o ubuntu-32
 ../../build-svr add-os -n testserver3 -o ubuntu-64
 #EXEC
index 224c40a..9248410 100644 (file)
@@ -1,8 +1,9 @@
 #PRE-EXEC
 #EXEC
-../../build-svr register -n testserver3 -D unstable -P bin/bin_0.0.0_ubuntu-32.zip
+../../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 b25a3de..e1534b6 100644 (file)
@@ -1,7 +1,7 @@
 #PRE-EXEC
 #EXEC
-../../build-cli build  -N testa -d 127.0.0.1:2223 -D unstable
-../../build-cli build  -N testa -d 127.0.0.1:2223 -D unstable2
+../../build-cli build  -N testa -d 127.0.0.1:2223 -D unstable -U admin@user -w 1234
+../../build-cli build  -N testa -d 127.0.0.1:2223 -D unstable2 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 Info: Added new job
index fd3d663..6a89696 100644 (file)
@@ -1,6 +1,6 @@
 #PRE-EXEC
 #EXEC
-../../build-cli register -d 127.0.0.1:2223 -P bin/bin_0.0.0_ubuntu-32.zip -D unstable2 #-t ftp://ftpuser:ftpuser@127.0.0.1
+../../build-cli register -d 127.0.0.1:2223 -P bin/bin_0.0.0_ubuntu-32.zip -D unstable2 -U admin@user -w 1234 #-t ftp://ftpuser:ftpuser@127.0.0.1
 #POST-EXEC
 #EXPECT
 I, [
@@ -8,6 +8,7 @@ I, [
 I, [
 I, [
 I, [
+I, [
 Info: Added new job
 Info: Initializing job...
 Info: Checking package version ...
@@ -18,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 fe29a83..a0af793 100644 (file)
@@ -1,9 +1,12 @@
 #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 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
+Info: Added new job
 Info: Initializing job...
+Info: Initializing sub-job
+Info: Initializing sub-job
 Info: Invoking a thread for MULTI-BUILD Job
 Info: New Job
 Info: Added new job "testa" for ubuntu-32!
index 6836515..1815f13 100644 (file)
@@ -4,11 +4,11 @@
 echo "=="
 ../../build-svr lock-dist -n testserver3 -D unstable2
 echo "=="
-../../build-cli build -N testb -d 127.0.0.1:2223 -D unstable2
+../../build-cli build -N testb -d 127.0.0.1:2223 -D unstable2 -U admin@user -w 1234
 echo "=="
 ../../build-svr unlock-dist -n testserver3 -D unstable2
 echo "=="
-../../build-cli build -N testb -d 127.0.0.1:2223 -D unstable2
+../../build-cli build -N testb -d 127.0.0.1:2223 -D unstable2 -U admin@user -w 1234
 #POST-EXEC
 #EXPECT
 ==
@@ -30,6 +30,9 @@ Info: JobBuilder
 Info: Downloding client is initializing...
 Info: Installing dependent packages...
 Info:  * a
+Info: Wait for cache sync
+Info: Entering cache sync
+Info: Cache sync done
 Info: Downloading dependent source packages...
 Info: Make clean...
 Info: Make build...
diff --git a/test/build-server.multi_dist2/build-svr3-06.testcase b/test/build-server.multi_dist2/build-svr3-06.testcase
new file mode 100644 (file)
index 0000000..8002d16
--- /dev/null
@@ -0,0 +1,12 @@
+#PRE-EXEC
+echo "Will check duplicated registration" 
+../../build-svr register -n testserver3 -D unstable -P bin/bin_0.0.1_ubuntu-32.zip & 
+#EXEC
+sleep 1
+../../build-svr register -n testserver3 -D unstable -P bin/bin_0.0.1_ubuntu-32.zip 
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Error: There already exists same job.
index 9f25506..e306053 100644 (file)
@@ -3,3 +3,4 @@ build-svr3-02.testcase
 build-svr3-03.testcase
 build-svr3-04.testcase
 build-svr3-05.testcase
+build-svr3-06.testcase
index 68d5ba2..bea231c 100755 (executable)
@@ -3,13 +3,13 @@
 require File.dirname(__FILE__) + "/../src/pkg_server/client"
 require File.dirname(__FILE__) + "/../src/pkg_server/serverConfig"
 
-### Client.new("server","dist","snapshot","location") 
+### Client.create("server","dist","snapshot","location") 
 
 # local server
-#cl = Client.new("/home/yangttak/test-packageserver")
+#cl = Client.create("/home/yangttak/test-packageserver")
 
 # remote server
-cl = Client.new("http://172.21.111.132/pkgserver/unstable", "/home/yangttak/build_root")
+cl = Client.create("http://172.21.111.132/pkgserver/unstable", "/home/yangttak/build_root")
 #cl.update()
 result = cl.get_install_dependent_packages("cross-arm-gcc-4.5", "linux", true)
 puts "----"
@@ -26,27 +26,27 @@ puts result
 #cl.install_local_pkg("/home/yangttak/test0208/sdk-build/smart-build-interface_0.20.0_linux.zip", "linux")
 #cl.show_pkg_info("tizen-ide", "linux")
 
-#cl = Client.new("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot3-linux", "/tmp/client-test")
+#cl = Client.create("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot3-linux", "/tmp/client-test")
 #cl.update()
 #result = cl.get_install_dependent_packages("smart-build-interface", "linux")
 #puts result
 
 # if location is nil
-#cl = Client.new("http://172.21.111.132/pkgserver/unstable", nil)
+#cl = Client.create("http://172.21.111.132/pkgserver/unstable", nil)
 
 # if server addr is nil
-#cl = Client.new(nil, "/tmp/client-test")
+#cl = Client.create(nil, "/tmp/client-test")
 
 # install package list
 #cl.download("base-toolchain", "windows")
 
 # test install different veriosn package
-#cl = Client.new("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot2-linux", "/tmp/client-test")
+#cl = Client.create("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot2-linux", "/tmp/client-test")
 #cl.install("tizen-ide", "linux")
 #cl.install("smart-build-interface", "linux")
 
 
-#cl = Client.new("http://172.21.111.132/pkgserver/unstable", "/tmp/client-test")
+#cl = Client.create("http://172.21.111.132/pkgserver/unstable", "/tmp/client-test")
 #result = cl.get_build_dependent_packages("mpfr", "linux")
 #puts result
 #result = cl.get_install_dependent_packages("arm-linux-gnueabi-gdb-7.2", "linux")
diff --git a/upgrade b/upgrade
index 26120ad..7007d18 100755 (executable)
--- a/upgrade
+++ b/upgrade
@@ -135,15 +135,20 @@ begin
        UPGRADE_CMD = "#{PREV_VER_PATH}/upgrade"
        BUILD_CONFIG_ROOT = "#{Utils::HOME}/.build_tools/build_server/#{svr_name}"
 
-       if not svr_dist.nil? then
+       if pkg_svr_url.nil? and not svr_dist.nil? then
                build_server = BuildServerController.get_server(svr_name)
-               dist = build_server.distmgr.get_distribution(svr_dist)
+               if build_server.has_db? then
+                       dist = build_server.distmgr.get_distribution(svr_dist)
+               else
+                       dist = nil
+               end
                if dist.nil? then
                        log.error "Upgrade failed : No distribution name \"#{svr_dist}\" exist!", Log::LV_USER
                        cmd = Utils.generate_shell_command("#{dibs_path}/build-svr start -n #{svr_name} -p #{svr_port}")
                        Utils.spawn(cmd)
                        exit 1
                end
+               pkg_svr_url = dist.pkgsvr_url
        end
 
        if not File.exist? BACKUP_ROOT then FileUtils.mkdir_p(BACKUP_ROOT) end
@@ -164,17 +169,15 @@ begin
                # Run Upgrade
                if start_opt and svr_type.eql? "BUILDSERVER"  then
                        cmd = "#{UPGRADE_CMD} -I -l #{dibs_path} -S -t #{svr_type} -n #{svr_name} -p #{svr_port}"
+               else
+                       cmd = "#{UPGRADE_CMD} -I -l #{dibs_path}"
+               end
 
-                       if not (pkg_svr_url.nil? or pkg_svr_url.empty?) then
-                               cmd += " -u #{pkg_svr_url}"
-                       end
-
-                       if not (svr_dist.nil? or svr_dist.empty?) then
-                               cmd += " -D #{svr_dist}"
-                       end
-
+               if not (pkg_svr_url.nil? or pkg_svr_url.empty?) then
+                       cmd += " -u #{pkg_svr_url}"
                else
-                       cmd = "#{UPGRADE_CMD} -I -l #{dibs_path} -u #{pkg_svr_url}"
+                       log.error "Upgrade failed : No package server URL!", Log::LV_USER
+                       exit 1
                end
 
                cmd = Utils.generate_shell_command(cmd)
@@ -182,81 +185,73 @@ begin
 
        else
                # Get SERVER INFORMATION
-               if start_opt and svr_type.eql? "BUILDSERVER" then
-                       # only when acesss build server controller
-                       build_server = BuildServerController.get_server(svr_name)
-                       if pkg_svr_url.nil? or pkg_svr_url.empty? then
-                               if svr_dist.nil? or svr_dist.empty? then
-                                       pkg_svr_url = build_server.distmgr.get_default_pkgsvr_url()
-                               else
-                                       dist = build_server.distmgr.get_distribution(svr_dist)
-                                       if not dist.nil? then
-                                               pkg_svr_url = dist.pkgsvr_url
-                                       else
-                                               log.error "Upgrade failed : No distribution name \"#{svr_dist}\" exist!", Log::LV_USER
-                                               exit 1
-                                       end
-                               end
-                       end
+               if svr_type.eql? "BUILDSERVER" then
                        log.info("Build server : [#{svr_name}][#{svr_port}]", Log::LV_USER)
                end
                log.info("Package Server : [#{pkg_svr_url}]", Log::LV_USER)
                log.info("DIBS Path : [#{dibs_path}]", Log::LV_USER)
 
                # Download DIBS Package
-       client = Client.new( pkg_svr_url, NEW_VER_PATH, log)
+       client = Client.create( pkg_svr_url, NEW_VER_PATH, log)
+               if client.nil? then
+                       log.error("Cannot create package client!", Log::LV_USER)
+                       exit(1)
+               end
        client.update()
                client.install( DIBS_PKG_NAME, Utils::HOST_OS, true, true)
+               if not File.exist? "#{NEW_VER_PATH}/tools/dibs" then
+                       log.error("Not installed package error.", Log::LV_USER)
+                       exit(1)
+               end
 
                # Copy Current path
                if File.exist? "#{dibs_path}" then
                        FileUtils.rm_rf("#{dibs_path}")
                        #FileUtils.mkdir_p("#{dibs_path}")
                end
-               if File.exist? "#{NEW_VER_PATH}/tools/dibs" then
-                       FileUtils.cp_r("#{NEW_VER_PATH}/tools/dibs/.", "#{dibs_path}", :preserve => true)
-               else
-                       log.error("Not installed package error.", Log::LV_USER)
-                       exit(1)
-               end
+
+               FileUtils.cp_r("#{NEW_VER_PATH}/tools/dibs/.", "#{dibs_path}", :preserve => true)
 
                # Execute start command
-               if start_opt
-                       if not build_server.nil? and svr_type.eql? "BUILDSERVER" then
+               if start_opt then
+                       if svr_type.eql? "BUILDSERVER" then
                                # get friends server information
-                               build_server.get_remote_servers().each do |svr|
-                                       ip = svr.ip
-                                       port = svr.port
-
-                                       build_client = BuildCommClient.create( ip, port )
-                                       if build_client.nil? then
-                                               log.info("Friend Server #{ip}:#{port} is not running!", Log::LV_USER)
-                                               next
-                                       end
+                               build_server = BuildServerController.get_server(svr_name)
+                               if build_server.has_db? then            
+                                       build_server.get_remote_servers().each do |svr|
+                                               ip = svr.ip
+                                               port = svr.port
+
+                                               build_client = BuildCommClient.create( ip, port )
+                                               if build_client.nil? then
+                                                       log.info("Friend Server #{ip}:#{port} is not running!", Log::LV_USER)
+                                                       next
+                                               end
 
-                                       # send request
-                                       log.info("Upgrading Friend Server #{ip}:#{port}...", Log::LV_USER)
-                                       if build_client.send "UPGRADE|#{build_server.password}" then
-                                               # recevie & print
-                                               mismatched = false
-                                               result = build_client.read_lines do |l|
-                                                       log.info(l, Log::LV_USER)
-                                                       if l.include? "Password mismatched!" then
-                                                               mismatched = true
+                                               # send request
+                                               log.info("Upgrading Friend Server #{ip}:#{port}...", Log::LV_USER)
+                                               if build_client.send "UPGRADE|#{build_server.password}|#{pkg_svr_url}" then
+                                                       # recevie & print
+                                                       mismatched = false
+                                                       result = build_client.read_lines do |l|
+                                                               log.info(l, Log::LV_USER)
+                                                               if l.include? "Password mismatched!" then
+                                                                       mismatched = true
+                                                               end
                                                        end
-                                               end
-                                               if not result then
+                                                       if not result then
+                                                               log.info("Upgrading failed! #{build_client.get_error_msg()}", Log::LV_USER)
+                                                       elsif mismatched then
+                                                               log.info("Upgrading failed! Password mismatched!", Log::LV_USER)
+                                                       end
+                                               else
                                                        log.info("Upgrading failed! #{build_client.get_error_msg()}", Log::LV_USER)
-                                               elsif mismatched then
-                                                       log.info("Upgrading failed! Password mismatched!", Log::LV_USER)
+                                                       next
                                                end
-                                       else
-                                               log.info("Upgrading failed! #{build_client.get_error_msg()}", Log::LV_USER)
-                                               next
-                                       end
 
-                                       # terminate
-                                       build_client.terminate
+                                               # terminate
+                                               build_client.terminate
+                                       end
                                end
 
                                # Start Build server