When a machine calls boot API,
no matter whether the job is retrieved or not,
it indicates that the machine is alive.
Therefore, we need to update the ES storage information.
If the job is obtained, set the deadline.
Signed-off-by: Wu Zhende <wuzhende666(a)163.com>
---
src/lib/job.cr | 8 ++++++++
src/lib/sched.cr | 37 +++++++++++++++++++---------------
src/scheduler/find_job_boot.cr | 3 ++-
3 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr
index 63ec8fb..f4ca5de 100644
--- a/src/lib/job.cr
+++ b/src/lib/job.cr
@@ -242,6 +242,14 @@ class Job
self["rootfs"] = "#{os}-#{os_version}-#{os_arch}"
end
+ def get_deadline
+ runtime = (self["timeout"]? || self["runtime"]?).to_s
+ runtime = 1800 if runtime.empty?
+
+ # reserve 300 seconds for system startup, hw machine will need such long time
+ (Time.local + (runtime.to_i32 * 2 + 300).second).to_s("%Y-%m-%dT%H:%M:%S+0800")
+ end
+
def set_result_root
update_tbox_group_from_testbox # id must exists, need update tbox_group
self["result_root"] = File.join("/result/#{suite}/#{submit_date}/#{tbox_group}/#{rootfs}", "#{pp_params}", "#{id}")
diff --git a/src/lib/sched.cr b/src/lib/sched.cr
index dfec365..5f28de9 100644
--- a/src/lib/sched.cr
+++ b/src/lib/sched.cr
@@ -103,12 +103,15 @@ class Sched
@log.warn(e)
end
+ def get_time
+ Time.local.to_s("%Y-%m-%dT%H:%M:%S+0800")
+ end
+
def update_tbox_wtmp
testbox = ""
hash = Hash(String, String | Nil).new
- time = Time.local.to_s("%Y-%m-%d %H:%M:%S")
- hash["time"] = time
+ hash["time"] = get_time
%w(mac ip job_id tbox_name tbox_state).each do |parameter|
if (value = @env.params.query[parameter]?)
@@ -117,7 +120,6 @@ class Sched
testbox = value
when "tbox_state"
hash["state"] = value
- hash["deadline"] = nil if value == "rebooting"
when "mac"
hash["mac"] = normalize_mac(value)
else
@@ -136,23 +138,26 @@ class Sched
@log.warn(e)
end
- def set_tbox_boot_wtmp(job : Job)
- time = Time.local
- booting_time = time.to_s("%Y-%m-%dT%H:%M:%S")
-
- runtime = (job["timeout"]? || job["runtime"]?).to_s
- runtime = 1800 if runtime.empty?
+ def set_lifecycle(job, testbox)
+ if job
+ deadline = job.get_deadline
+ job["deadline"] = deadline
+ job["job_state"] = "boot"
+ state = "booting"
+ job_id = job["id"]
+ else
+ deadline = nil
+ job_id = ""
+ state = "requesting"
+ end
- # reserve 300 seconds for system startup, hw machine will need such long time
- deadline = (time + (runtime.to_i32 * 2 + 300).second).to_s("%Y-%m-%dT%H:%M:%S")
hash = {
- "job_id" => job["id"],
- "state" => "booting",
- "booting_time" => booting_time,
+ "job_id" => job_id,
+ "state" => state,
+ "time" => get_time,
"deadline" => deadline
}
-
- @es.update_tbox(job["testbox"], hash)
+ @es.update_tbox(testbox.to_s, hash)
end
def report_ssh_port
diff --git a/src/scheduler/find_job_boot.cr b/src/scheduler/find_job_boot.cr
index 3323d4d..b7fe0e7 100644
--- a/src/scheduler/find_job_boot.cr
+++ b/src/scheduler/find_job_boot.cr
@@ -100,10 +100,11 @@ class Sched
def get_job_boot(host, boot_type)
queues = get_queues(host)
job = get_job_from_queues(queues, host)
+ set_lifecycle(job, host)
if job
+ @es.set_job_content(job)
create_job_cpio(job.dump_to_json_any, Kemal.config.public_folder)
- set_tbox_boot_wtmp(job)
else
# for physical machines
spawn { auto_submit_idle_job(host) }
--
2.23.0