121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/scenario.rb', line 121
def run(clients)
clients.each do |client|
client.msg 't' => 'STOP'
end
rand_clients = clients.sort_by { rand }
proxies = rand_clients.slice!(0,2)
master_db = rand_clients.pop
slave_dbs = rand_clients.slice!(0,2)
stats_nodes = rand_clients.slice!(0,2)
rails_nodes = rand_clients.slice!(0,5)
slave_dbs.each do |slave_db|
slave_db.msg 't' => 'ROLE', 'role' => 'db', 'slaves' => [], 'slave' => true
end
master_db.msg 't' => 'ROLE', 'role' => 'db', 'slaves' => slave_dbs.map { |n| n.addr }
stats_nodes.each do |stats|
stats.msg 't' => 'ROLE', 'role' => 'stats', 'db_read' => slave_dbs.map { |n| n.addr }
end
rails_nodes.each do |rails|
rails.msg 't' => 'ROLE', 'role' => 'rails', 'db_write' => [master_db.addr], 'db_read' => slave_dbs.map { |n| n.addr }
end
proxies.each do |proxy|
proxy.msg 't' => 'ROLE', 'role' => 'proxy', 'backends' => rails_nodes.map { |n| n.addr }, 'stats_backends' => stats_nodes.map { |n| n.addr }
end
end
|