Class: Mu::Scale

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/mu/api/scale.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#ask, #error, #format_float, #get_file_as_string_array, #msg, #shift, #to_boolean

Constructor Details

#initialize(host = ENV['MU_IP'], username = ENV['MU_ADMIN_USER'], password = ENV['MU_ADMIN_PASS']) ⇒ Scale

Returns a new instance of Scale.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mu/api/scale.rb', line 7

def initialize(host=ENV['MU_IP'], username=ENV['MU_ADMIN_USER'], password=ENV['MU_ADMIN_PASS'])
  @host = host
  @username  = username
  @password  = password
  @docroot = "/api/v5/scale/"
  @uuid = nil
  @tracks = Array.new # an array of @configuration objects for multi-track execution
  @http = HttpHelper.new(@host, @username, @password, @docroot)
  @config_file = (ENV['SCALE_CONFIG_FILE'].nil?) ? "scale.json" : ENV['SCALE_CONFIG_FILE']
  if File.readable? @config_file
    msg "reading config file: #{@config_file}", Logger::DEBUG
    @configuration = JSON.parse File.read(@config_file)
  else
    @configuration = {
      "hosts"=> {
        "host_0"=> "a1/*",
        "host_1"=> "a2/*"
      },
      "timeout"=> 5000,
      "delay"=> 0,
      "volume"=> 1,
      "holdConcurrency"=> true,
      "limitConcurrency"=> false,
      "vectorAddressPairing"=> false,
      "musl" => "",
      "csv" => "",
      "pattern" => {}
    }
  end
  @uuid = session
  msg "Created Scale Api session [#{@uuid}] on :#{@host}", Logger::DEBUG
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.



5
6
7
# File 'lib/mu/api/scale.rb', line 5

def config_file
  @config_file
end

#configurationObject

Returns the value of attribute configuration.



5
6
7
# File 'lib/mu/api/scale.rb', line 5

def configuration
  @configuration
end

#docrootObject

Returns the value of attribute docroot.



5
6
7
# File 'lib/mu/api/scale.rb', line 5

def docroot
  @docroot
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/mu/api/scale.rb', line 5

def host
  @host
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/mu/api/scale.rb', line 5

def password
  @password
end

#tracksObject

Returns the value of attribute tracks.



5
6
7
# File 'lib/mu/api/scale.rb', line 5

def tracks
  @tracks
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/mu/api/scale.rb', line 5

def username
  @username
end

#uuidObject

Returns the value of attribute uuid.



5
6
7
# File 'lib/mu/api/scale.rb', line 5

def uuid
  @uuid
end

Instance Method Details

#aboutObject

lists information about the the Scale Player and all active and inactive Scale Engines



116
117
118
119
120
# File 'lib/mu/api/scale.rb', line 116

def about
    response = get "about"
    msg response, Logger::DEBUG
    return response
end

#configure(param, value) ⇒ Object

configures a parameter in the class @configuration object

* param = the parameter to configure (e.g. volume)
* value = the parameter's value ( e.g. 100)


57
58
59
60
61
62
63
# File 'lib/mu/api/scale.rb', line 57

def configure(param, value)
   if param == "pattern" and value.is_a?(String)
       value = JSON.parse(value)
   end
   @configuration[param] = value
   File.open(@config_file,'w'){|f| f.write(JSON.pretty_generate(@configuration))}
end

#data(view = 'TIMELINE', zoom = "0", position = "0", bot_id = "") ⇒ Object

gets chart data for the Scale test

* view = the TIMELINE or CALLGRAPH chart.
* zoom = the zoom level (0 to 1). 1 returns data for 100% of the time range, 0.5 returns data for 50% of the time range, and 0 returns only the last minute of data
* position = 0.
* bot_id = the scale engine id


143
144
145
146
147
# File 'lib/mu/api/scale.rb', line 143

def data(view='TIMELINE', zoom="0", position="0", bot_id="")
    response = get "data", "view=#{view.upcase}&zoom=#{zoom}&position=#{position}&bot_id=#{bot_id}"
    msg response, Logger::DEBUG
    return response
end

#delete_scale_engine(bot_id) ⇒ Object

removes a Scale engine from the list of available engines

* bot_id = the scale engine id


191
192
193
194
195
# File 'lib/mu/api/scale.rb', line 191

def delete_scale_engine(bot_id)
    response = get "deleteScaleEngine", "botId=#{bot_id}"
    msg response, Logger::DEBUG
    return response
end

#listObject

returns the current Scale Player’s session id



109
110
111
112
113
# File 'lib/mu/api/scale.rb', line 109

def list
    response = get "list"
    msg response, Logger::DEBUG
    return response
end

#pattern(zoom = "0", position = "0") ⇒ Object

returns scale test data for charting

* command-line args require a zoom level and position(0)
 * zoom = the zoom level (0 to 1). 1 returns data for 100% of the time range, 0.5 returns data for 50% of the time range, and 0 returns only the last minute of data
 * position = 0.


153
154
155
156
157
# File 'lib/mu/api/scale.rb', line 153

def pattern(zoom="0", position="0")
    response = get "pattern", "zoom=#{zoom}&position=#{position}"
    msg response, Logger::DEBUG
    return response
end

#pcap(bot_id, file) ⇒ Object

returns a packet capture file from scale verify

* bot_id = the id of the scale engine
* file = the name of the pcap file to retrieve


125
126
127
128
129
# File 'lib/mu/api/scale.rb', line 125

def pcap(bot_id, file)
    response = get "pcap", "botId=#{bot_id}&file=#{file}"
    msg response, Logger::DEBUG
    return response
end

#releaseObject

releases the scale player



167
168
169
170
171
# File 'lib/mu/api/scale.rb', line 167

def release
    response = get "release"
    msg response, Logger::DEBUG
    return response
end

#release_scale_engine(bot_id) ⇒ Object

marks the specified Scale Engine as inactive (will not participate in a Scale test)

* bot_id = the scale engine id


183
184
185
186
187
# File 'lib/mu/api/scale.rb', line 183

def release_scale_engine(bot_id)
    response = get "releaseScaleEngine", "botId=#{bot_id}"
    msg response, Logger::DEBUG
    return response
end

#reserve_scale_engine(bot_id) ⇒ Object

marks the specified Scale Engine as active (will participate in a Scale test

* bot_id = the scale engine id


175
176
177
178
179
# File 'lib/mu/api/scale.rb', line 175

def reserve_scale_engine(bot_id)
    response = get "reserveScaleEngine", "botId=#{bot_id}"
    msg response, Logger::DEBUG
    return response
end

#sessionObject

creates a new Studio Scale session, returning the session id



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mu/api/scale.rb', line 41

def session
   uuid = nil
   list = get("list")
   if !list.empty?
       msg list
       uuid = list[0]  # return existing session identifier if there is one
       return uuid
   end
   uuid = get "new" # return a new session identifier
   msg "uuid from /new = #{uuid}"
   return uuid
end

#startObject

starts a scale test with the class @configuration object



66
67
68
69
70
# File 'lib/mu/api/scale.rb', line 66

def start
    response = post "start", {"request" => @configuration}
    msg response, Logger::DEBUG
    return response
end

#start_nObject

starts a multi-track scale test with the class @tracks object



73
74
75
76
77
# File 'lib/mu/api/scale.rb', line 73

def start_n
    response = post "start_n", {"request" => @tracks}
    msg response, Logger::DEBUG
    return response
end

#statusObject

gets information about the currently running Scale test.



102
103
104
105
106
# File 'lib/mu/api/scale.rb', line 102

def status
    response = get "status"
    msg response, Logger::DEBUG
    return response
end

#statusesObject

gets the status of all active and inactive Scale engines



132
133
134
135
136
# File 'lib/mu/api/scale.rb', line 132

def statuses
    response = get "statuses"
    msg response, Logger::DEBUG
    return response
end

#stopObject

stops a scale test



160
161
162
163
164
# File 'lib/mu/api/scale.rb', line 160

def stop
    response = get "stop"
    msg response, Logger::DEBUG
    return response
end

#update(params) ⇒ Object

updates a running scale test, as long as the test pattern is ‘none’

* params = a json object containing the information to update, such as { "volume" : 100 }


95
96
97
98
99
# File 'lib/mu/api/scale.rb', line 95

def update(params)
    response = get "update", params
    msg response, Logger::DEBUG
    return response
end

#verifyObject

verifies the class @configuration object



80
81
82
83
84
# File 'lib/mu/api/scale.rb', line 80

def verify
    response = post "verify", {"request" => @configuration}
    msg response, Logger::DEBUG
    return response
end

#verify_nObject

verifies the multi-track class @tracks object



87
88
89
90
91
# File 'lib/mu/api/scale.rb', line 87

def verify_n
    response = post "verify_n", {"request" => @tracks}
    msg response, Logger::DEBUG
    return response
end