Class: Cwb::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cwb/client.rb

Overview

Serves as cwb-server client library in cloud VMs (if configured against a cwb-server) or as standalone utility otherwise where cwb-server communication (e.g., metric submission) is logged to stdout.

Constant Summary collapse

VM_INSTANCE =

RESTful endpoints

"virtual_machine_instances"
METRIC_OBSERVATIONS =
"metric_observations"

Instance Method Summary collapse

Instance Method Details

#deep_fetch(*keys) ⇒ String

Securly access nested attributes.

Examples:

Acess benchmark attribute hash

@cwb.deep_fetch("sysbench", "cli_options")

Access node attribute (collected by ohai)

@cwb.deep_fetch("cpu", "0", "model_name")

Returns:

  • (String)

    an empty string if attribute cannot be found



39
40
41
# File 'lib/cwb/client.rb', line 39

def deep_fetch(*keys)
  @config.deep_fetch(*keys)
end

#notify_failed_execution(message = "") ⇒ void

Note:

The cwb-server will shutdown all VMs of this execution after a timeout (~15’).

This method returns an undefined value.

Notifies the cwb-server that the benchmark failed during the execution



87
88
89
90
91
92
93
# File 'lib/cwb/client.rb', line 87

def notify_failed_execution(message = "")
  if @config.complete?
    post_notify("/#{VM_INSTANCE}/complete_benchmark", false, message)
  else
    puts "Notify failure on running. (message suppressed to avoid redundant logging)"
  end
end

#notify_finished_executionvoid

Note:

The cwb-server will shutdown all VMs of this executions.

This method returns an undefined value.

Notifies the cwb-server that the benchmark successfully completed.



76
77
78
79
80
81
82
# File 'lib/cwb/client.rb', line 76

def notify_finished_execution
  if @config.complete?
    post_notify("/#{VM_INSTANCE}/complete_postprocessing", true)
  else
    puts "Notify finished postprocessing."
  end
end

#reconfigure(config) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Reconfigures the Client with a configuration object against a cwb-server.



22
23
24
25
26
27
28
29
30
31
# File 'lib/cwb/client.rb', line 22

def reconfigure(config)
  @config = config
  if @config.complete?
    @connection = Faraday.new(:url => "http://#{@config.server}") do |f|
      f.request :multipart
      f.request :json
      f.adapter Faraday.default_adapter
    end
  end
end

#submit_metric(metric_definition_id, time, value) ⇒ void

This method returns an undefined value.

Submit a single metric

Parameters:

  • metric_definition_id (String)

    the name of the CWB metric

  • time (Integer)

    the UNIX timestamp when the metric was captured

  • value (String (nominal-scale) or Numeric (otherwise))

    the value of the metric



48
49
50
51
52
53
54
# File 'lib/cwb/client.rb', line 48

def submit_metric(metric_definition_id, time, value)
  if @config.complete?
    submit_remote_metric(metric_definition_id, time, value)
  else
    puts "#{metric_definition_id},#{time},#{value}"
  end
end

#submit_metrics(metric_definition_id, csv_file) ⇒ void

Note:

the csv file must:

  • have two columns: ‘time’ [Integer], ‘value’ [String (nominal-scale) or Numeric (otherwise)]

  • be formatted without headers

This method returns an undefined value.

Submit a csv file with metrics

Parameters:

  • metric_definition_id (String)

    the name of the CWB metric

  • csv_file (String)

    the path to the csv file containing the metrics



63
64
65
66
67
68
69
70
71
# File 'lib/cwb/client.rb', line 63

def submit_metrics(metric_definition_id, csv_file)
  if @config.complete?
    submit_remote_metrics(metric_definition_id, csv_file)
  else
    CSV.foreach(csv_file) do |row|
      puts row.join(',')
    end
  end
end