forked from cmantas/tiramola_v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
288 lines (226 loc) · 7.26 KB
/
cli.py
1
2
3
4
5
6
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
__author__ = 'cmantas'
import sys
from lib.tiramola_logging import get_logger
from os import remove, mkdir
from shutil import move
raw_args = sys.argv
args = dict()
def parse_args():
chosen_function = raw_args[1]
global args
for arg in raw_args[2:]:
i = arg.find("=")
if i == -1:
args[arg] = True
else:
key = arg[:i]
value = arg[i+1:]
args[key] = value
return chosen_function
log = get_logger("CLI", 'INFO')
############################## AVAILABLE ACTIONS #######################################
def info():
print """============== USAGE ==================
tiramola hosts
tiramola private_hosts
tiramola create_cluster nodes=2 clients=2
tiramola bootstrap_cluster used=8
tiramola load_data records=100000
tiramola run_sinusoid target=100 offset=80 period=60 #period time in minutes
tiramola add_nodes [count=2]
tiramola remove_nodes [count=2]
tiramola kill_workload
tiramola kill_nodes
tiramola destroy_servers
tiramola add_clients count=2
tiramola train
tiramola auto_pilot time=60 #time in minutes
tiramola set_cluster_size count=5
tiramola watch
"""
def load_data():
try:
record_count = int(args["records"])
log.info("Loading %d records in the cluster" % record_count)
import CassandraCluster, ClientsCluster
svr_hosts = CassandraCluster.get_hosts(private=True)
args['type'] = 'load'
args['servers'] = svr_hosts
ClientsCluster.run(args)
except KeyError as e:
log.info("record_count requires argument %s" % e.args[0])
def run_sinusoid():
try:
global target, period, offset
target = int(args["target"])
period = 60 * int(args["period"])
args["period"] = period
offset = int(args["offset"])
log.info("running sinusoid for target=%d, offset=%d, period=%d sec" % (target, offset, period))
import CassandraCluster
from ClientsCluster import my_Clients
svr_hosts = CassandraCluster.get_hosts(private=False)
args['type'] = 'sinusoid'
args['servers'] = svr_hosts
my_Clients.run(args)
except KeyError as e:
log.info("run_sinusoid requires argument %s" % e.args[0])
def run_stress():
log.info("running stress workload" )
import CassandraCluster
from ClientsCluster import my_Clients
svr_hosts = CassandraCluster.get_hosts(private=False)
params = {'type':'stress', 'servers': svr_hosts}
my_Clients.run(params)
def create_cluster():
try:
nodes = int(args["nodes"])
log.info("creating cluster with %d nodes " % nodes)
import CassandraCluster
CassandraCluster.create_cluster(nodes-1)
except KeyError as e:
log.info("create_cluster requires argument %s" % e.args[0])
def create_clients():
try:
nodes = int(args["nodes"])
log.info("creating %d client nodes " % nodes)
from ClientsCluster import my_Clients
my_Clients.create_cluster(nodes)
except KeyError as e:
log.info("create_clients requires argument %s" % e.args[0])
def add_clients():
if "count" in args.keys():
count = int(args['count'])
else:
count = 1;
log.info("adding %d clients" % count)
from ClientsCluster import my_Clients
my_Clients.add_nodes(count)
def remove_clients():
if "count" in args.keys():
count = int(args['count'])
else:
count = 1;
log.info("removing %d clients" % count)
from ClientsCluster import my_Clients
my_Clients.remove_nodes(count)
def kill_workload():
log.info("killing workload")
from ClientsCluster import my_Clients
my_Clients.kill_nodes()
def kill_nodes():
log.info("killing cassandra nodes")
import CassandraCluster
CassandraCluster.kill_nodes()
def bootstrap_cluster():
try:
used = int(args['used'])
log.info('Bootstraping Cluster with %d nodes' % used)
import CassandraCluster
CassandraCluster.bootstrap_cluster(used)
except KeyError as e:
log.error("bootstrap_cluster requires argument %s" % e.args[0])
def destroy_servers():
import CassandraCluster
CassandraCluster.destroy_all()
def destroy_clients():
from ClientsCluster import my_Clients
my_Clients.destroy_all()
def hosts():
import CassandraCluster, ClientsCluster
svr_hosts = CassandraCluster.get_hosts(include_stash=True)
clnt_hosts = ClientsCluster.get_hosts()
hosts = dict(svr_hosts.items() + clnt_hosts.items())
rv = ""
for h in hosts.keys():
rv += hosts[h] + " " + h + "\n"
print rv
def private_hosts():
import CassandraCluster
hosts = CassandraCluster.get_hosts(include_clients=True, private=True)
rv = ""
for h in hosts.keys():
rv += hosts[h] + " " + h + "\n"
print rv
def add_nodes():
if "count" in args.keys():
count = int(args['count'])
else:
count = 1;
import CassandraCluster
CassandraCluster.add_nodes(count)
def remove_nodes():
if "count" in args.keys():
count = int(args['count'])
else:
count = 1;
import CassandraCluster
CassandraCluster.remove_nodes(count)
def train():
log.info(" Will run training routine. WARNING: will start workload automatically")
import Coordinator
Coordinator.train()
def auto_pilot():
log.info("Running Tiramola Auto Provisioning super algorithm")
global minutes, env_vars
try:
minutes = int(args['time'])
except KeyError as e:
log.error("auto_pilot requires argument %s" % e.args[0])
return
secs = 60 * minutes
import Coordinator
Coordinator.run(secs)
def monitor():
from lib.persistance_module import env_vars
log.info("simply monitoring")
global env_vars
env_vars["gain"] = '0'
import Coordinator
Coordinator.run()
def simulate():
try:
remove("files/measurements/measurements.txt")
except:
pass
from new_decision_module import RLDecisionMaker
fsm = RLDecisionMaker("localhost", 8)
fsm.simulate_training_set()
from lib.draw_experiment import draw_exp
try:
mkdir("files/measurements/simulation/")
except:
pass
move("files/measurements/measurements.txt", "files/measurements/simulation/measurements.txt")
draw_exp("files/measurements/simulation/measurements.txt")
def run_experiments():
try:
experiment_file = args['file']
except KeyError as e:
log.error("run_experiments requires argument %s" % e.args[0])
return
import Experiment
Experiment.run_experiments(experiment_file)
def repair():
import CassandraCluster
CassandraCluster.repair_cluster()
def set_cluster_size():
try:
count = int(args['count'])
except KeyError as e:
log.error("set cluster size requires argument %s" % e.args[0])
return
import CassandraCluster
CassandraCluster.set_cluster_size(count)
def watch():
import Experiment
Experiment.watch("experiments", Experiment.run_experiments_from_string)
############################ MAIN ################################################
function = parse_args()
try:
#just call the appropriate function with eval!
eval(function+"()")
except NameError as ne:
log.error("No such action")
print str(ne)
info()