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 |
# File 'lib/load/http_report.rb', line 6 def initialize(server_address) @server = server_address end |
Instance Method Details
#node_finished(params) ⇒ Object
31 32 33 |
# File 'lib/load/http_report.rb', line 31 def node_finished(params) post "/node_finished", params end |
#node_monitors(params) ⇒ Object
65 66 67 68 69 |
# File 'lib/load/http_report.rb', line 65 def node_monitors(params) response = post("/node_monitors", params) data = JSON.parse(response) return data end |
#node_ready(params) ⇒ Object
85 86 87 88 |
# File 'lib/load/http_report.rb', line 85 def node_ready(params) response = post("/node_ready", params) return response end |
#node_register(params) ⇒ Object
59 60 61 62 63 |
# File 'lib/load/http_report.rb', line 59 def node_register(params) response = post("/node_register", params) data = JSON.parse(response) return data end |
#node_schedule(params) ⇒ Object
79 80 81 82 83 |
# File 'lib/load/http_report.rb', line 79 def node_schedule(params) response = post("/node_schedule", params) data = JSON.parse(response) return data end |
#node_start?(params) ⇒ Boolean
72 73 74 75 76 77 |
# File 'lib/load/http_report.rb', line 72 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
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/load/http_report.rb', line 14 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}" raise "Bad response from load http: #{response.code} Response: #{response.body}" end return response.body end |
#report_load_to_server(run_id, time, load_count) ⇒ Object
55 56 57 |
# File 'lib/load/http_report.rb', line 55 def report_load_to_server(run_id, time, load_count) response = post "/load", {"run_id" => run_id, "time" => time, "load" => load_count} end |
#report_result(run_id, node_id, test_code, wasp_id, run_at_millis, time, result) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/load/http_report.rb', line 35 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.message}" end return response end |
#run_create(params) ⇒ Object
90 91 92 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 |
# File 'lib/load/http_report.rb', line 90 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 # params[:configuration] = config_from_file 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 ':#{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.message}" end end response = post("/run_create", params) data = JSON.parse(response) return data["run_id"].to_i end |
#run_node_info(params) ⇒ Object
126 127 128 129 130 |
# File 'lib/load/http_report.rb', line 126 def run_node_info(params) response = post("/run_node_info", params) data = JSON.parse(response) return data end |
#server_address ⇒ Object
10 11 12 |
# File 'lib/load/http_report.rb', line 10 def server_address return "http://#{@server}/client" end |
#status_for_test(run_id, wasp_id) ⇒ Object
49 50 51 52 53 |
# File 'lib/load/http_report.rb', line 49 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 |