Class: HttpReport
- Inherits:
-
Object
- Object
- HttpReport
- Defined in:
- lib/load/http_report.rb
Instance Method Summary collapse
-
#initialize(server_address) ⇒ HttpReport
constructor
A new instance of HttpReport.
- #node_finished(params) ⇒ Object
- #node_monitors(params) ⇒ Object
- #node_ready(params) ⇒ Object
- #node_register(params) ⇒ Object
- #node_schedule(params) ⇒ Object
- #node_start?(params) ⇒ Boolean
- #post(action, params) ⇒ Object
- #report_load_to_server(run_id, time, load_count) ⇒ Object
- #report_result(run_id, node_id, test_code, wasp_id, run_at_millis, time, result) ⇒ Object
- #run_create(params) ⇒ Object
- #run_node_info(params) ⇒ Object
- #server_address ⇒ Object
- #status_for_test(run_id, wasp_id) ⇒ Object
Constructor Details
#initialize(server_address) ⇒ HttpReport
Returns a new instance of HttpReport.
6 7 8 9 |
# File 'lib/load/http_report.rb', line 6 def initialize(server_address) raise "No server address" if (!server_address) @server = server_address end |
Instance Method Details
#node_finished(params) ⇒ Object
33 34 35 |
# File 'lib/load/http_report.rb', line 33 def node_finished(params) post "/node_finished", params end |
#node_monitors(params) ⇒ Object
68 69 70 71 72 |
# File 'lib/load/http_report.rb', line 68 def node_monitors(params) response = post("/node_monitors", params) data = JSON.parse(response) return data end |
#node_ready(params) ⇒ Object
88 89 90 91 |
# File 'lib/load/http_report.rb', line 88 def node_ready(params) response = post("/node_ready", params) return response end |
#node_register(params) ⇒ Object
62 63 64 65 66 |
# File 'lib/load/http_report.rb', line 62 def node_register(params) response = post("/node_register", params) data = JSON.parse(response) return data end |
#node_schedule(params) ⇒ Object
82 83 84 85 86 |
# File 'lib/load/http_report.rb', line 82 def node_schedule(params) response = post("/node_schedule", params) data = JSON.parse(response) return data end |
#node_start?(params) ⇒ Boolean
75 76 77 78 79 80 |
# File 'lib/load/http_report.rb', line 75 def node_start?(params) response = post("/node_ask_to_start", params) data = JSON.parse(response) #puts "Node start response: #{data}" return data["start"] end |
#post(action, params) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/load/http_report.rb', line 15 def post(action, params) address = server_address + action puts "Posting to: #{address}, Params: #{params}" uri = URI.parse(server_address + action) begin response = Net::HTTP.post_form(uri, params) rescue Errno::ETIMEDOUT => error raise "Communication with server error: #{error} Address: #{uri}" end if (response.code != "200") puts "Action: #{action} Response: #{response.code} Response body: #{response.body}" puts "Action: #{action} Response: #{response.code}" raise "Bad response from load http: #{response.code}" end return response.body end |
#report_load_to_server(run_id, time, load_count) ⇒ Object
57 58 59 60 |
# File 'lib/load/http_report.rb', line 57 def report_load_to_server(run_id, time, load_count) response = post "/load", {"run_id" => run_id, "time" => time, "load" => load_count} return response end |
#report_result(run_id, node_id, test_code, wasp_id, run_at_millis, time, result) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/load/http_report.rb', line 37 def report_result(run_id, node_id, test_code, wasp_id, run_at_millis, time, result) response = nil begin millis = nil if (time != nil) millis = time * 1000 end response = post "/timing", {"run_at_millis" => run_at_millis, "time" => "#{millis}", "run_id" => run_id, "node_id" => node_id,"test_code" => test_code, "wasp_id" => wasp_id.to_s, "result" => result} rescue Exception => e puts "Error sending results (#{result} in #{millis}) to server(#{server_address}): #{e.}" end return response end |
#run_create(params) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/load/http_report.rb', line 93 def run_create(params) node_count = params[:node_count] if (node_count == nil) node_count = 1 params[:node_count] = node_count end if (params[:config_file_name] != nil) file_name = params[:config_file_name] config_from_file = "" begin File.open(file_name, "r") do |f| config_from_file = f.read() end params[:config_file_name] = file_name configuration = eval(config_from_file) server_list = configuration[:servers] raise "Configuration lacks 'servers' list" unless (server_list != nil) target_server_address = server_list[params[:target_server].to_sym] raise "Configuration lacks entry in 'servers' list for target: ':#{params[:target_server]}'\n #{server_list}" unless target_server_address != nil params[:configuration] = configuration.to_s params[:config_code] = configuration[:code] raise "'duration' not specified for run." unless configuration[:duration] != nil params[:duration] = configuration[:duration] params[:name] = configuration[:name] rescue Exception => e raise "Exception reading config from file(#{File::absolute_path(file_name)}): #{e.}" end end response = post("/run_create", params) data = JSON.parse(response) return data end |
#run_node_info(params) ⇒ Object
128 129 130 131 132 |
# File 'lib/load/http_report.rb', line 128 def run_node_info(params) response = post("/run_node_info", params) data = JSON.parse(response) return data end |
#server_address ⇒ Object
11 12 13 |
# File 'lib/load/http_report.rb', line 11 def server_address return "http://#{@server}/client" end |
#status_for_test(run_id, wasp_id) ⇒ Object
51 52 53 54 55 |
# File 'lib/load/http_report.rb', line 51 def status_for_test(run_id, wasp_id) # Checking for kill or finished run. response = post("/status_for_test", {"run_id" => run_id, 'wasp_id' => wasp_id}) return JSON.parse(response) end |