[why] Before, we consume job from the queue which has relation with tbox_group. Now, virtual and physical machine will get host by mac at first, then virtual/docker/physical machine get the queues by host, consume the job from the queues.
Signed-off-by: Cao Xueliang caoxl78320@163.com --- src/lib/sched.cr | 106 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 27 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index b2ef6ce..fa65f69 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -243,10 +243,10 @@ class Sched response = add_job(job, job_id) message = (response["error"]? ? response["error"]["root_cause"] : "") job_messages << { - "job_id" => job_id, - "message" => message.to_s, - "job_state" => "submit", - "result_root" => "/srv#{job.result_root}" + "job_id" => job_id, + "message" => message.to_s, + "job_state" => "submit", + "result_root" => "/srv#{job.result_root}", } return job_messages if response["error"]? end @@ -295,10 +295,10 @@ class Sched message = (response["error"]? ? response["error"]["root_cause"] : "")
return [{ - "job_id" => job_id, - "message" => message.to_s, - "job_state" => "submit", - "result_root" => "/srv#{job.result_root}" + "job_id" => job_id, + "message" => message.to_s, + "job_state" => "submit", + "result_root" => "/srv#{job.result_root}", }] end
@@ -381,31 +381,83 @@ class Sched end end
+ def rand_queues(queues) + return queues if queues.empty? + + queues_size = queues.size + base = Random.rand(queues_size) + temp_queues = [] of String + + (0..queues_size - 1).each do |index| + temp_queues << queues[(index + base) % queues_size] + end + + return temp_queues + end + + def get_queues(host) + queues = [] of String + + queues_str = @redis.hash_get("sched/host2queues", host) + return queues unless queues_str + + queues_str.split(',', remove_empty: true) do |item| + queues << item.strip + end + + return rand_queues(queues) + end + + def get_job_from_queues(queues, testbox) + job = nil + + queues.each do |queue| + job = prepare_job("sched/#{queue}", testbox) + return job if job + end + + return job + end + + def get_job_boot(host, boot_type) + queues = get_queues(host) + job = get_job_from_queues(queues, host) + + if job + Jobfile::Operate.create_job_cpio(job.dump_to_json_any, Kemal.config.public_folder) + end + + return boot_content(job, boot_type) + end + + # auto submit a job to collect the host information + # grub hostname is link with ":", like "00:01:02:03:04:05" + # remind: if like with "-", last "-05" is treated as host number + # then hostname will be "sut-00-01-02-03-04" !!! + def submit_host_info_job(mac) + host = "sut-#{mac}" + set_host_mac(mac, host) + + Jobfile::Operate.auto_submit_job( + "#{ENV["LKP_SRC"]}/jobs/host-info.yaml", + "testbox: #{host}") + end + def find_job_boot(env : HTTP::Server::Context) - api_param = env.params.url["value"] + value = env.params.url["value"] + boot_type = env.params.url["boot_type"]
- case env.params.url["boot_type"] + case boot_type when "ipxe" - hostname = @redis.hash_get("sched/mac2host", normalize_mac(api_param)) + host = @redis.hash_get("sched/mac2host", normalize_mac(value)) when "grub" - hostname = @redis.hash_get("sched/mac2host", normalize_mac(api_param)) - if hostname.nil? # auto name new/unknown machine - hostname = "sut-#{api_param}" - set_host_mac(api_param, hostname) - - # auto submit a job to collect the host information - # grub hostname is link with ":", like "00:01:02:03:04:05" - # remind: if like with "-", last "-05" is treated as host number - # then hostname will be "sut-00-01-02-03-04" !!! - Jobfile::Operate.auto_submit_job( - "#{ENV["LKP_SRC"]}/jobs/host-info.yaml", - "testbox: #{hostname}") - end + host = @redis.hash_get("sched/mac2host", normalize_mac(value)) + submit_host_info_job(value) unless host when "container" - hostname = api_param + host = value end
- get_testbox_boot_content(hostname, env.params.url["boot_type"]) + get_job_boot(host, boot_type) end
def find_next_job_boot(env) @@ -415,7 +467,7 @@ class Sched hostname = @redis.hash_get("sched/mac2host", normalize_mac(mac)) end
- get_testbox_boot_content(hostname, "ipxe") + get_job_boot(hostname, "ipxe") end
def get_testbox_boot_content(testbox, boot_type)