Keep scheduler.cr neat and do not perform operations related to env.
Signed-off-by: Wu Zhende wuzhende666@163.com --- src/lib/sched.cr | 40 +++++++++++++++++++++++++++------- src/scheduler/find_job_boot.cr | 2 +- src/scheduler/scheduler.cr | 32 ++++----------------------- 3 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index a1ef28e..f7220f9 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -51,20 +51,44 @@ class Sched mac.gsub(":", "-") end
- def set_host_mac(mac : String, hostname : String) - @redis.hash_set("sched/mac2host", normalize_mac(mac), hostname) + def set_host_mac + if (hostname = @env.params.query["hostname"]?) && (mac = @env.params.query["mac"]?) + @redis.hash_set("sched/mac2host", normalize_mac(mac), hostname) + + "Done" + else + "No yet!" + end end
- def del_host_mac(mac : String) - @redis.hash_del("sched/mac2host", normalize_mac(mac)) + def del_host_mac + if mac = @env.params.query["mac"]? + @redis.hash_del("sched/mac2host", normalize_mac(mac)) + + "Done" + else + "No yet!" + end end
- def set_host2queues(hostname : String, queues : String) - @redis.hash_set("sched/host2queues", hostname, queues) + def set_host2queues + if (queues = @env.params.query["queues"]?) && (hostname = @env.params.query["host"]?) + @redis.hash_set("sched/host2queues", hostname, queues) + + "Done" + else + "No yet!" + end end
- def del_host2queues(hostname : String) - @redis.hash_del("sched/host2queues", hostname) + def del_host2queues + if hostname = @env.params.query["host"]? + @redis.hash_del("sched/host2queues", hostname) + + "Done" + else + "No yet!" + end end
def update_tbox_wtmp diff --git a/src/scheduler/find_job_boot.cr b/src/scheduler/find_job_boot.cr index 7565375..9b3db88 100644 --- a/src/scheduler/find_job_boot.cr +++ b/src/scheduler/find_job_boot.cr @@ -29,7 +29,7 @@ class Sched # then hostname will be "sut-00-01-02-03-04" !!! def submit_host_info_job(mac) host = "sut-#{mac}" - set_host_mac(mac, host) + @redis.hash_set("sched/mac2host", normalize_mac(mac), host)
Jobfile::Operate.auto_submit_job( "#{ENV["LKP_SRC"]}/jobs/host-info.yaml", diff --git a/src/scheduler/scheduler.cr b/src/scheduler/scheduler.cr index 7ec149c..2103f7c 100644 --- a/src/scheduler/scheduler.cr +++ b/src/scheduler/scheduler.cr @@ -79,46 +79,22 @@ module Scheduler # # curl -X PUT "http://localhost:3000/set_host_mac?hostname=wfg&mac=00-01-02-03-04-05" put "/set_host_mac" do |env| - if (client_hostname = env.params.query["hostname"]?) && (client_mac = env.params.query["mac"]?) - env.sched.set_host_mac(client_mac, client_hostname) - - "Done" - else - "No yet!" - end + env.sched.set_host_mac end
# curl -X PUT "http://localhost:3000/set_host2queues?queues=vm-2p8g.aarch64&host=vm-2p8..." put "/set_host2queues" do |env| - if (client_queues = env.params.query["queues"]?) && (client_host = env.params.query["host"]?) - env.sched.set_host2queues(client_host, client_queues) - - "Done" - else - "No yet" - end + env.sched.set_host2queues end
# curl -X PUT "http://localhost:3000/del_host_mac?mac=00-01-02-03-04-05" put "/del_host_mac" do |env| - if client_mac = env.params.query["mac"]? - env.sched.del_host_mac(client_mac) - - "Done" - else - "No yet!" - end + env.sched.del_host_mac end
# curl -X PUT "http://localhost:3000/del_host2queues?host=vm-2p8g.aarch64" put "/del_host2queues" do |env| - if client_host = env.params.query["host"]? - env.sched.del_host2queues(client_host) - - "Done" - else - "No yet!" - end + env.sched.del_host2queues end
# client(runner) report job's status