[Title] Added "MAX_JOBS" that stands for number of all working jobs
authordonghee yang <donghee.yang@samsung.com>
Wed, 24 Apr 2013 01:09:42 +0000 (10:09 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Wed, 24 Apr 2013 01:09:42 +0000 (10:09 +0900)
src/build_server/BuildServer.rb
src/build_server/BuildServerController.rb
src/build_server/JobManager.rb
test/build-server.basic2/build-svr-25.testcase [new file with mode: 0644]
test/build-server.basic2/testsuite

index 87950cf38dab2655cf1c8bb1f363a1dca6b3aa42..2f8680c09e8248a0c17e77ba6923bfa4997731ad 100644 (file)
@@ -509,7 +509,8 @@ class BuildServer
                # get availables server
                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 >= -4 then
+                       if @jobmgr.max_working_jobs == 0 and 
+                               local_empty_rooms >= -1 * @jobmgr.get_max_jobs() then
                                candidates.push self
                        end
                else
@@ -635,7 +636,8 @@ class BuildServer
                        @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 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')"
                                                        ]
                else
                        @db_migrate[1]=["ALTER TABLE distributions ADD pkgsvr_password VARCHAR(64)"]
@@ -643,7 +645,8 @@ class BuildServer
                        @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 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')"
                                                        ]
                end
        end
@@ -693,6 +696,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')"
index b8a50a746ba37ef87b8ee25236d07e68b3bacb46..d8d9ec030892b1b58ccea3375797bd733e9b91c2 100644 (file)
@@ -787,7 +787,7 @@ class BuildServerController
                        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" then
+                       attr != "MAX_WORKING_JOBS" and attr != "MAX_JOBS" then
 
                        puts BuildServerException.get_message("ERR021")
                        return false
@@ -798,6 +798,8 @@ class BuildServerController
                        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"
@@ -860,7 +862,7 @@ class BuildServerController
                        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" then
+                       attr != "MAX_WORKING_JOBS" and attr != "MAX_JOBS" then
 
                        puts BuildServerException.get_message("ERR021")
                        return false
@@ -871,6 +873,8 @@ class BuildServerController
                        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"
@@ -945,6 +949,7 @@ class BuildServerController
                        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
@@ -966,6 +971,7 @@ class BuildServerController
                db_user=nil
                db_passwd=nil
                max_working_jobs=2
+               max_jobs=4
 
                # read configuration
                server_dir = "#{BuildServer::CONFIG_ROOT}/#{id}"
@@ -1012,6 +1018,8 @@ class BuildServerController
                                        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
@@ -1050,6 +1058,7 @@ class BuildServerController
                # 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
index c8b151d92ae7e899e7fd6c19e9b797afc513c66e..83f28bbcf808f610569447b015aa82497b1d2430 100644 (file)
@@ -49,6 +49,7 @@ class JobManager
                @internal_job_schedule = Mutex.new
                @latest_job_touch = Mutex.new
                @max_build_jobs = 2
+               @max_jobs = 4
        end
 
        def cancel_broken_status
@@ -71,10 +72,46 @@ class JobManager
 
        def max_working_jobs=(job_cnt)
                @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
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 d6a63c3c0f982ef63105eb0db50b298358534943..7b2d0f60d7aee182c9911d56384dc9b98322b1ec 100644 (file)
@@ -19,3 +19,4 @@ build-svr-20.testcase
 build-svr-21.testcase
 build-svr-23.testcase
 build-svr-24.testcase
+build-svr-25.testcase