The assist-result container mount the "/srv/result" dir,
we should implement some API about "/srv/result".
An API is provided to support to get job yaml for now.
Example:
input:
curl localhost:8102/get_job_yaml/crystal.304189
output:
the yaml content about crystal.304189
Signed-off-by: Cao Xueliang <caoxl78320(a)163.com>
---
container/assist-result/routes.rb | 24 +++++++++++++++++++
container/assist-result/views/get_job_yaml.rb | 13 ++++++++++
2 files changed, 37 insertions(+)
create mode 100755 container/assist-result/routes.rb
create mode 100644 container/assist-result/views/get_job_yaml.rb
diff --git a/container/assist-result/routes.rb b/container/assist-result/routes.rb
new file mode 100755
index 0000000..1013643
--- /dev/null
+++ b/container/assist-result/routes.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+# SPDX-License-Identifier: MulanPSL-2.0+
+# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+# frozen_string_literal: true
+
+require 'json'
+require 'sinatra'
+
+require_relative './views/get_job_yaml'
+
+configure do
+ set :bind, '0.0.0.0'
+ set :port, ENV['ASSIST_RESULT_PORT']
+end
+
+get '/get_job_yaml/:job_id' do
+ begin
+ result = get_job_yaml(params[:job_id])
+ rescue StandardError => e
+ return [400, e.backtrace.inspect]
+ end
+
+ return [200, result.to_json]
+end
diff --git a/container/assist-result/views/get_job_yaml.rb b/container/assist-result/views/get_job_yaml.rb
new file mode 100644
index 0000000..4544835
--- /dev/null
+++ b/container/assist-result/views/get_job_yaml.rb
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: MulanPSL-2.0+
+# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+# frozen_string_literal: true
+
+require 'yaml'
+
+require_relative "#{ENV['CCI_SRC']}/lib/es_query"
+
+def get_job_yaml(job_id)
+ content = ESQuery.new.query_by_id(job_id)
+ result_root = content['result_root']
+ return YAML.load(File.open(File.join('/srv', "#{result_root}", 'job.yaml')))
+end
--
2.23.0