The container assist-result mount "/srv/result" dir, the function credible? need "/srv/result" dir, so it can be implemented in the container.
Signed-off-by: Cao Xueliang caoxl78320@163.com --- container/assist-result/Dockerfile | 2 +- container/assist-result/routes.rb | 12 ++++++++++++ .../assist-result/views/check_job_credible.rb | 9 +++++++++ lib/assist_result_client.rb | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 container/assist-result/views/check_job_credible.rb
diff --git a/container/assist-result/Dockerfile b/container/assist-result/Dockerfile index 47ef92f..60a2fbf 100644 --- a/container/assist-result/Dockerfile +++ b/container/assist-result/Dockerfile @@ -12,4 +12,4 @@ RUN sed -ri.origin 's|^https?://dl-cdn.alpinelinux.org|http://mirrors.huaweiclou
RUN umask 002 && \ echo ':sources: ["http://rubygems.org"]' >> ~/.gemrc && \ - gem install rest-client activesupport json yaml elasticsearch sinatra puma + gem install rest-client activesupport json yaml elasticsearch sinatra puma terminal-table diff --git a/container/assist-result/routes.rb b/container/assist-result/routes.rb index 1013643..077a427 100755 --- a/container/assist-result/routes.rb +++ b/container/assist-result/routes.rb @@ -7,6 +7,7 @@ require 'json' require 'sinatra'
require_relative './views/get_job_yaml' +require_relative './views/check_job_credible'
configure do set :bind, '0.0.0.0' @@ -22,3 +23,14 @@ get '/get_job_yaml/:job_id' do
return [200, result.to_json] end + +post '/check_job_credible' do + begin + data = JSON.parse(Base64.decode64(request.body.read)) + result = check_job_credible(data['pre_job_id'], data['cur_job_id'], data['error_id']) + rescue StandardError => e + return [400, e.backtrace.inspect] + end + + return [200, {'credible' => result}.to_json] +end diff --git a/container/assist-result/views/check_job_credible.rb b/container/assist-result/views/check_job_credible.rb new file mode 100644 index 0000000..a8d387f --- /dev/null +++ b/container/assist-result/views/check_job_credible.rb @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require_relative "#{ENV['CCI_SRC']}/lib/compare_error_messages" + +def check_job_credible(pre_job_id, cur_job_id, error_id) + return credible?(pre_job_id, cur_job_id, error_id) +end diff --git a/lib/assist_result_client.rb b/lib/assist_result_client.rb index 042b189..fcf5d9d 100644 --- a/lib/assist_result_client.rb +++ b/lib/assist_result_client.rb @@ -3,6 +3,8 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
+require 'json' +require 'base64' require 'rest-client' require_relative 'constants'
@@ -19,4 +21,17 @@ class AssistResult
return response.body end + + def check_job_credible(pre_job_id, cur_job_id, error_id) + data = { + 'pre_job_id' => pre_job_id, + 'cur_job_id' => cur_job_id, + 'error_id' => error_id + } + resource = RestClient::Resource.new("http://#%7B@host%7D:#%7B@port%7D/check_job_credible") + response = resource.post(Base64.encode64(data.to_json)) + return nil unless response.code == 200 + + return JSON.parse(response.body) + end end