History of testbox would be kept.
[sample] { "_index" : "testbox", "_type" : "_doc", "_id" : "vm-2p16g.liyuanchao-969257", "_score" : 1.0, "_source" : { "state" : "rebooting", "job_id" : "crystal.190886", "history" : [ { "time" : "2020-12-15 19:52:14", "mac" : "0a-f5-c0-1f-f0-dd", "ip" : "172.18.202.96", "job_id" : "crystal.190886", "state" : "running" }, { "time" : "2020-12-15 19:57:22", "mac" : "0a-f5-c0-1f-f0-dd", "ip" : "172.18.202.96", "job_id" : "crystal.190886", "state" : "rebooting" } ] } }
Signed-off-by: Li Yuanchao lyc163mail@163.com --- src/lib/sched.cr | 1 + src/scheduler/elasticsearch_client.cr | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index 10a51ab..7cb0dbf 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -104,6 +104,7 @@ class Sched end
@redis.update_wtmp(testbox, hash) + @es.update_tbox(testbox, hash)
# json log hash["testbox"] = testbox diff --git a/src/scheduler/elasticsearch_client.cr b/src/scheduler/elasticsearch_client.cr index 7c92204..b17d7f8 100644 --- a/src/scheduler/elasticsearch_client.cr +++ b/src/scheduler/elasticsearch_client.cr @@ -87,6 +87,27 @@ class Elasticsearch::Client ) end
+ def update_tbox(testbox : String, wtmp_hash : Hash) + query = {:index => "testbox", :type => "_doc", :id => testbox} + result = @client.get_source(query) if @client.exists(query) + history = result["history"].as_a? if result.is_a?(JSON::Any) + history ||= [] of JSON::Any + history << JSON.parse(wtmp_hash.to_json) + + @client.create( + { + :index => "testbox", + :type => "_doc", + :id => testbox, + :body => { + :state => wtmp_hash["state"], + :job_id => wtmp_hash["job_id"], + :history => history + } + } + ) + end + private def create(job_content : JSON::Any, job_id : String) return @client.create( {
On Wed, Dec 16, 2020 at 04:54:44PM +0800, Li Yuanchao wrote:
History of testbox would be kept.
What's the purpose? For monitoring the testbox?
You can add the purpose in your change log.
Thanks, Xueliang
[sample] { "_index" : "testbox", "_type" : "_doc", "_id" : "vm-2p16g.liyuanchao-969257", "_score" : 1.0, "_source" : { "state" : "rebooting", "job_id" : "crystal.190886", "history" : [ { "time" : "2020-12-15 19:52:14", "mac" : "0a-f5-c0-1f-f0-dd", "ip" : "172.18.202.96", "job_id" : "crystal.190886", "state" : "running" }, { "time" : "2020-12-15 19:57:22", "mac" : "0a-f5-c0-1f-f0-dd", "ip" : "172.18.202.96", "job_id" : "crystal.190886", "state" : "rebooting" } ] } }
Signed-off-by: Li Yuanchao lyc163mail@163.com
src/lib/sched.cr | 1 + src/scheduler/elasticsearch_client.cr | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index 10a51ab..7cb0dbf 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -104,6 +104,7 @@ class Sched end
@redis.update_wtmp(testbox, hash)
@es.update_tbox(testbox, hash)
# json log hash["testbox"] = testbox
diff --git a/src/scheduler/elasticsearch_client.cr b/src/scheduler/elasticsearch_client.cr index 7c92204..b17d7f8 100644 --- a/src/scheduler/elasticsearch_client.cr +++ b/src/scheduler/elasticsearch_client.cr @@ -87,6 +87,27 @@ class Elasticsearch::Client ) end
- def update_tbox(testbox : String, wtmp_hash : Hash)
- query = {:index => "testbox", :type => "_doc", :id => testbox}
- result = @client.get_source(query) if @client.exists(query)
- history = result["history"].as_a? if result.is_a?(JSON::Any)
- history ||= [] of JSON::Any
- history << JSON.parse(wtmp_hash.to_json)
- @client.create(
{
:index => "testbox",
:type => "_doc",
:id => testbox,
:body => {
:state => wtmp_hash["state"],
:job_id => wtmp_hash["job_id"],
:history => history
}
}
- )
- end
- private def create(job_content : JSON::Any, job_id : String) return @client.create( {
-- 2.23.0