Add implementation methods for web api GET /get_tbox_state?testbox=$testbox
Signed-off-by: Li Yuanchao lyc163mail@163.com --- src/lib/web_backend.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 07e2e9e..c4182a3 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -461,3 +461,29 @@ def query_testboxes end [200, headers.merge('Access-Control-Allow-Origin' => '*'), body] end + +def get_tbox_state_body(params) + query = { + "query": { + "match": { + "_id": params[:testbox] + } + } + } + body = ES_CLIENT.search(index: 'testbox', body: query)['hits']['hits'][0]['_source'] + + { + testbox: params[:testbox], + states: body + }.to_json +end + +def get_tbox_state(params) + begin + body = get_tbox_state_body(params) + rescue StandardError => e + warn e.message + return [500, headers.merge('Access-Control-Allow-Origin' => '*'), 'get testbox state error'] + end + [200, headers.merge('Access-Control-Allow-Origin' => '*'), body] +end