class HttpReport

Public Class Methods

new(server_address) click to toggle source
# File lib/load/http_report.rb, line 6
def initialize(server_address)
  raise "No server address" if (!server_address)
  @server = server_address
end

Public Instance Methods

node_finished(params) click to toggle source
# File lib/load/http_report.rb, line 33
def node_finished(params)
  post "/node_finished", params
end
node_monitors(params) click to toggle source
# 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) click to toggle source
# File lib/load/http_report.rb, line 88
def node_ready(params)
  response = post("/node_ready", params)
  return response
end
node_register(params) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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.message}"
  end
  return response
end
run_create(params) click to toggle source
# 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.message}"
    end
  end

  response = post("/run_create", params)
  data = JSON.parse(response)
  return data
end
run_node_info(params) click to toggle source
# 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() click to toggle source
# File lib/load/http_report.rb, line 11
def server_address
   return "http://#{@server}/client"
end
status_for_test(run_id, wasp_id) click to toggle source
# 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