Class: Mu::Scale

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

Constant Summary

Constants included from Helper

Helper::ESCAPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#ask, #bin2hex, #error, #escape, #format_float, #get_file_as_string_array, #make_xml, #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



120
121
122
123
124
# File 'lib/mu/api/scale.rb', line 120

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
64
65
66
67
# File 'lib/mu/api/scale.rb', line 57

def configure(param, value)
    begin
        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))}
    rescue => e
        raise "Something is wrong with the JSON parsing or generation:#{e} backtrace:#{e.backtrace}"
    end
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


147
148
149
150
151
# File 'lib/mu/api/scale.rb', line 147

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


195
196
197
198
199
# File 'lib/mu/api/scale.rb', line 195

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



113
114
115
116
117
# File 'lib/mu/api/scale.rb', line 113

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.


157
158
159
160
161
# File 'lib/mu/api/scale.rb', line 157

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


129
130
131
132
133
# File 'lib/mu/api/scale.rb', line 129

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

#releaseObject

releases the scale player



171
172
173
174
175
# File 'lib/mu/api/scale.rb', line 171

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


187
188
189
190
191
# File 'lib/mu/api/scale.rb', line 187

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


179
180
181
182
183
# File 'lib/mu/api/scale.rb', line 179

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



70
71
72
73
74
# File 'lib/mu/api/scale.rb', line 70

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



77
78
79
80
81
# File 'lib/mu/api/scale.rb', line 77

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.



106
107
108
109
110
# File 'lib/mu/api/scale.rb', line 106

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

#statusesObject

gets the status of all active and inactive Scale engines



136
137
138
139
140
# File 'lib/mu/api/scale.rb', line 136

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

#stopObject

stops a scale test



164
165
166
167
168
# File 'lib/mu/api/scale.rb', line 164

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 }


99
100
101
102
103
# File 'lib/mu/api/scale.rb', line 99

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

#verifyObject

verifies the class @configuration object



84
85
86
87
88
# File 'lib/mu/api/scale.rb', line 84

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

#verify_nObject

verifies the multi-track class @tracks object



91
92
93
94
95
# File 'lib/mu/api/scale.rb', line 91

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