blob: c7b4e3effe6dfe6026f028b9a545785b16020fe2 [file] [log] [blame]
stgleb75c70412015-02-17 02:52:00 +02001import datetime
gstepanov501151a2015-03-06 17:22:28 +02002from data_processing import Measurement, create_measurement, process_build_data
stgleb75c70412015-02-17 02:52:00 +02003from flask import json
gstepanove6ad1f02015-03-02 19:58:00 +02004from meta_info import collect_lab_data, total_lab_info
stgleb75c70412015-02-17 02:52:00 +02005from sqlalchemy import sql
6from persistance.models import *
7
8
gstepanov15681d62015-02-23 17:17:50 +02009def get_build_info(build_name):
10 session = db.session()
gstepanove6ad1f02015-03-02 19:58:00 +020011 result = session.query(Result, Build).join(Build).\
12 filter(Build.name == build_name).first()
gstepanov15681d62015-02-23 17:17:50 +020013 lab = session.query(Lab).filter(Lab.id == result[0].lab_id).first()
14 return eval(lab.lab_general_info)
15
16
17def get_build_detailed_info(build_name):
18 data = get_build_info(build_name)
19 return total_lab_info(data)
20
21
stgleb75c70412015-02-17 02:52:00 +020022def add_io_params(session):
gstepanov501151a2015-03-06 17:22:28 +020023 """Filling Param table with initial parameters. """
24
gstepanove6ad1f02015-03-02 19:58:00 +020025 param1 = Param(name="operation", type='{"write", "randwrite", '
26 '"read", "randread"}',
27 descr="type of write operation")
28 param2 = Param(name="sync", type='{"a", "s"}',
29 descr="Write mode synchronous/asynchronous")
30 param3 = Param(name="block size",
31 type='{"1k", "2k", "4k", "8k", "16k", '
32 '"32k", "64k", "128k", "256k"}')
stgleb75c70412015-02-17 02:52:00 +020033
34 session.add(param1)
35 session.add(param2)
36 session.add(param3)
37
38 session.commit()
39
40
stgleb75c70412015-02-17 02:52:00 +020041def add_build(session, build_id, build_name, build_type, md5):
gstepanov501151a2015-03-06 17:22:28 +020042 """Function which adds particular build to database."""
43
gstepanove6ad1f02015-03-02 19:58:00 +020044 build = Build(type=build_type, build_id=build_id,
45 name=build_name, md5=md5)
stgleb75c70412015-02-17 02:52:00 +020046 session.add(build)
47 session.commit()
48
49 return build.id
50
51
stgleb75c70412015-02-17 02:52:00 +020052def insert_results(session, build_id, lab_id, params_combination_id,
53 time=None, bandwith=0.0, meta=""):
gstepanov501151a2015-03-06 17:22:28 +020054 """Function insert particular result. """
55
gstepanove6ad1f02015-03-02 19:58:00 +020056 result = Result(build_id=build_id, lab_id=lab_id,
57 params_combination_id=params_combination_id, time=time,
stgleb75c70412015-02-17 02:52:00 +020058 bandwith=bandwith, meta=meta)
59 session.add(result)
60 session.commit()
61
62
stgleb75c70412015-02-17 02:52:00 +020063def add_param_comb(session, *params):
gstepanov501151a2015-03-06 17:22:28 +020064 """function responsible for adding particular params
65 combination to database"""
66
gstepanove6ad1f02015-03-02 19:58:00 +020067 params_names = sorted([s for s in dir(ParamCombination)
68 if s.startswith('param_')])
stgleb75c70412015-02-17 02:52:00 +020069 d = zip(params_names, params)
70 where = ""
71
72 for item in d:
73 where = sql.and_(where, getattr(ParamCombination, item[0]) == item[1])
74
75 query = session.query(ParamCombination).filter(where)
76 rs = session.execute(query).fetchall()
77
stgleb75c70412015-02-17 02:52:00 +020078 if len(rs) == 0:
79 param_comb = ParamCombination()
80
81 for p in params_names:
82 i = int(p.split('_')[1])
stgleb75c70412015-02-17 02:52:00 +020083
gstepanove6ad1f02015-03-02 19:58:00 +020084 if i - 1 < len(params):
85 param_comb.__setattr__('param_' + str(i), params[i - 1])
86 param = session.query(Param).filter(Param.id == i).one()
87 values = eval(param.type)
stgleb75c70412015-02-17 02:52:00 +020088
gstepanove6ad1f02015-03-02 19:58:00 +020089 if params[i - 1] not in values:
90 values.add(params[i - 1])
91 param.type = str(values)
stgleb75c70412015-02-17 02:52:00 +020092
93 session.add(param_comb)
94 session.commit()
95 return param_comb.id
96 else:
97 return rs[0][0]
98
99
gstepanove6ad1f02015-03-02 19:58:00 +0200100def add_lab(session, lab_url, lab_name, ceph_version,
101 fuel_version, data, info):
gstepanov501151a2015-03-06 17:22:28 +0200102 """ Function add data about particular lab"""
gstepanov15681d62015-02-23 17:17:50 +0200103 result = session.query(Lab).filter(Lab.name == lab_name).all()
stgleb75c70412015-02-17 02:52:00 +0200104
gstepanov15681d62015-02-23 17:17:50 +0200105 if len(result) != 0:
106 return result[0].id
107 else:
108 lab = Lab(name=lab_name, url=lab_url, ceph_version=ceph_version,
gstepanove6ad1f02015-03-02 19:58:00 +0200109 fuel_version=fuel_version, lab_general_info=str(data),
110 lab_meta=str(info))
gstepanov15681d62015-02-23 17:17:50 +0200111 session.add(lab)
112 session.commit()
113 return lab.id
stgleb75c70412015-02-17 02:52:00 +0200114
gstepanove6ad1f02015-03-02 19:58:00 +0200115
stgleb75c70412015-02-17 02:52:00 +0200116def add_data(data):
gstepanov501151a2015-03-06 17:22:28 +0200117 """Function store list of builds in database"""
118
stgleb75c70412015-02-17 02:52:00 +0200119 data = json.loads(data)
120 session = db.session()
121 add_io_params(session)
122
123 for build_data in data:
124 build_id = add_build(session,
125 build_data.pop("build_id"),
126 build_data.pop("name"),
127 build_data.pop("type"),
128 build_data.pop("iso_md5"),
129 )
gstepanove6ad1f02015-03-02 19:58:00 +0200130
gstepanov15681d62015-02-23 17:17:50 +0200131 creds = {"username": build_data.pop("username"),
132 "password": build_data.pop("password"),
gstepanove6ad1f02015-03-02 19:58:00 +0200133 "tenant_name": build_data.pop("tenant_name")}
134
gstepanov15681d62015-02-23 17:17:50 +0200135 lab_url = build_data.pop("lab_url")
136 lab_name = build_data.pop("lab_name")
137 ceph_version = build_data.pop("ceph_version")
138 data = collect_lab_data(lab_url, creds)
139 data['name'] = lab_name
140 info = total_lab_info(data)
141 lab_id = add_lab(session, lab_url=lab_name, lab_name=lab_url,
gstepanove6ad1f02015-03-02 19:58:00 +0200142 ceph_version=ceph_version,
143 fuel_version=data['fuel_version'],
144 data=data, info=info)
gstepanov15681d62015-02-23 17:17:50 +0200145
stgleb75c70412015-02-17 02:52:00 +0200146 date = build_data.pop("date")
147 date = datetime.datetime.strptime(date, "%a %b %d %H:%M:%S %Y")
148
149 for params, [bw, dev] in build_data.items():
150 param_comb_id = add_param_comb(session, *params.split(" "))
gstepanove6ad1f02015-03-02 19:58:00 +0200151 result = Result(param_combination_id=param_comb_id,
152 build_id=build_id, bandwith=bw,
153 date=date, lab_id=lab_id)
stgleb75c70412015-02-17 02:52:00 +0200154 session.add(result)
155 session.commit()
156
157
gstepanove6ad1f02015-03-02 19:58:00 +0200158def load_data(lab_id=None, build_id=None, *params):
gstepanov501151a2015-03-06 17:22:28 +0200159 """ Function loads data by parameters described in *params tuple."""
160
stgleb75c70412015-02-17 02:52:00 +0200161 session = db.session()
gstepanove6ad1f02015-03-02 19:58:00 +0200162 params_names = sorted([s for s in dir(ParamCombination)
163 if s.startswith('param_')])
stgleb75c70412015-02-17 02:52:00 +0200164 d = zip(params_names, params)
165 where = ""
166
167 for item in d:
168 where = sql.and_(where, getattr(ParamCombination, item[0]) == item[1])
169
170 query = session.query(ParamCombination).filter(where)
171 rs = session.execute(query).fetchall()
172
173 ids = [r[0] for r in rs]
174
gstepanove6ad1f02015-03-02 19:58:00 +0200175 rs = session.query(Result).\
176 filter(Result.param_combination_id.in_(ids)).all()
stgleb75c70412015-02-17 02:52:00 +0200177
gstepanove6ad1f02015-03-02 19:58:00 +0200178 if lab_id is not None:
179 rs = [r for r in rs if r.lab_id == lab_id]
180
181 if build_id is not None:
182 rs = [r for r in rs if r.build_id == build_id]
183
184 return rs
stgleb75c70412015-02-17 02:52:00 +0200185
186
stgleb75c70412015-02-17 02:52:00 +0200187def load_all():
gstepanov501151a2015-03-06 17:22:28 +0200188 """Load all builds from database"""
189
stgleb75c70412015-02-17 02:52:00 +0200190 session = db.session()
gstepanove6ad1f02015-03-02 19:58:00 +0200191 results = session.query(Result, Build, ParamCombination).\
192 join(Build).join(ParamCombination).all()
stgleb75c70412015-02-17 02:52:00 +0200193
194 return results
195
196
stgleb75c70412015-02-17 02:52:00 +0200197def collect_builds_from_db(*names):
gstepanov501151a2015-03-06 17:22:28 +0200198 """ Function collecting all builds from database and filter it by names"""
199
stgleb75c70412015-02-17 02:52:00 +0200200 results = load_all()
201 d = {}
202
203 for item in results:
204 result_data = item[0]
205 build_data = item[1]
206 param_combination_data = item[2]
207
208 if build_data.name not in d:
gstepanove6ad1f02015-03-02 19:58:00 +0200209 d[build_data.name] = \
210 [build_data, result_data, param_combination_data]
stgleb75c70412015-02-17 02:52:00 +0200211 else:
212 d[build_data.name].append(result_data)
213 d[build_data.name].append(param_combination_data)
214
215 if len(names) == 0:
216 return {k: v for k, v in d.items()}
217
218 return {k: v for k, v in d.items() if k in names}
219
220
stgleb75c70412015-02-17 02:52:00 +0200221def prepare_build_data(build_name):
gstepanov501151a2015-03-06 17:22:28 +0200222 """
223 #function preparing data for display plots.
224 #Format {build_name : Measurement}
225 """
226
stgleb75c70412015-02-17 02:52:00 +0200227 session = db.session()
228 build = session.query(Build).filter(Build.name == build_name).first()
229 names = []
230
231 if build.type == 'GA':
232 names = [build_name]
233 else:
gstepanove6ad1f02015-03-02 19:58:00 +0200234 res = session.query(Build).\
235 filter(Build.type.in_(['GA', 'master', build.type])).all()
stgleb75c70412015-02-17 02:52:00 +0200236 for r in res:
237 names.append(r.name)
238
stgleb75c70412015-02-17 02:52:00 +0200239 d = collect_builds_from_db()
240 d = {k: v for k, v in d.items() if k in names}
241 results = {}
242
243 for data in d.keys():
244 m = create_measurement(d[data])
245 results[m.build_type] = m
246
247 return results
248
249
stgleb75c70412015-02-17 02:52:00 +0200250def builds_list():
gstepanov501151a2015-03-06 17:22:28 +0200251 """
252 Function getting list of all builds available to index page
253 returns list of dicts which contains data to display on index page.
254 """
255
stgleb75c70412015-02-17 02:52:00 +0200256 res = []
257 builds = set()
258 data = load_all()
259
260 for item in data:
261 build = item[1]
262 result = item[0]
263
264 if not build.name in builds:
265 builds.add(build.name)
266 d = {}
267 d["type"] = build.type
268 d["url"] = build.name
269 d["date"] = result.date
270 d["name"] = build.name
271 res.append(d)
272
273 return res
274
275
stgleb75c70412015-02-17 02:52:00 +0200276def get_builds_data(names=None):
gstepanov501151a2015-03-06 17:22:28 +0200277 """
278 Processing data from database.
279 List of dicts, where each dict contains build meta
280 info and kev-value measurements.
281 key - param combination.
282 value - [mean, deviation]
283 """
284
stgleb75c70412015-02-17 02:52:00 +0200285 d = collect_builds_from_db()
286
287 if not names is None:
288 d = {k: v for k, v in d.items() if k in names}
289 else:
290 d = {k: v for k, v in d.items()}
291 output = []
292
293 for key, value in d.items():
294 result = {}
295 build = value[0]
296 result["build_id"] = build.build_id
297 result["iso_md5"] = build.md5
298 result["type"] = build.type
299 result["date"] = "Date must be here"
300
301 for i in range(1, len(value), 2):
302 r = value[i]
303 param_combination = value[i + 1]
304
305 if not str(param_combination) in result:
306 result[str(param_combination)] = [r.bandwith]
307 else:
308 result[str(param_combination)].append(r.bandwith)
309
310 output.append(result)
311
312 for build in output:
313 process_build_data(build)
314
315 return output
316
317
stgleb75c70412015-02-17 02:52:00 +0200318def get_data_for_table(build_name=""):
gstepanov501151a2015-03-06 17:22:28 +0200319 """ Function for getting result to display table """
320
stgleb75c70412015-02-17 02:52:00 +0200321 session = db.session()
322 build = session.query(Build).filter(Build.name == build_name).one()
323 names = []
324
gstepanove6ad1f02015-03-02 19:58:00 +0200325 # Get names of build that we need.
stgleb75c70412015-02-17 02:52:00 +0200326 if build.type == 'GA':
327 names = [build_name]
328 else:
gstepanove6ad1f02015-03-02 19:58:00 +0200329 res = session.query(Build).filter(
330 Build.type.in_(['GA', 'master', build.type])).all()
stgleb75c70412015-02-17 02:52:00 +0200331 for r in res:
332 names.append(r.name)
gstepanove6ad1f02015-03-02 19:58:00 +0200333 # get data for particular builds.
stgleb75c70412015-02-17 02:52:00 +0200334 return get_builds_data(names)
335
336
337if __name__ == '__main__':
338 # add_build("Some build", "GA", "bla bla")
gstepanov15681d62015-02-23 17:17:50 +0200339 cred = {"username": "admin", "password": "admin", "tenant_name": "admin"}
stgleb75c70412015-02-17 02:52:00 +0200340 json_data = '[{\
gstepanov15681d62015-02-23 17:17:50 +0200341 "username": "admin",\
342 "password": "admin", \
343 "tenant_name": "admin",\
344 "lab_url": "http://172.16.52.112:8000",\
345 "lab_name": "Perf-1-Env",\
346 "ceph_version": "v0.80 Firefly",\
stgleb75c70412015-02-17 02:52:00 +0200347 "randwrite a 256k": [16885, 1869],\
348 "randwrite s 4k": [79, 2],\
349 "read a 64k": [74398, 11618],\
350 "write s 1024k": [7490, 193],\
351 "randwrite a 64k": [14167, 4665],\
352 "build_id": "1",\
353 "randread a 1024k": [68683, 8604],\
354 "randwrite s 256k": [3277, 146],\
355 "write a 1024k": [24069, 660],\
356 "type": "GA",\
357 "write a 64k": [24555, 1006],\
358 "write s 64k": [1285, 57],\
359 "write a 256k": [24928, 503],\
360 "write s 256k": [4029, 192],\
361 "randwrite a 1024k": [23980, 1897],\
362 "randread a 64k": [27257, 17268],\
363 "randwrite s 1024k": [8504, 238],\
364 "randread a 256k": [60868, 2637],\
365 "randread a 4k": [3612, 1355],\
366 "read a 1024k": [71122, 9217],\
367 "date": "Thu Feb 12 19:11:56 2015",\
368 "write s 4k": [87, 3],\
369 "read a 4k": [88367, 6471],\
370 "read a 256k": [80904, 8930],\
371 "name": "GA - 6.0 GA",\
372 "randwrite s 1k": [20, 0],\
373 "randwrite s 64k": [1029, 34],\
374 "write s 1k": [21, 0],\
375 "iso_md5": "bla bla"\
376 },\
377 {\
gstepanov15681d62015-02-23 17:17:50 +0200378 "username": "admin",\
379 "password": "admin", \
380 "tenant_name": "admin",\
381 "lab_url": "http://172.16.52.112:8000",\
382 "ceph_version": "v0.80 Firefly",\
383 "lab_name": "Perf-1-Env",\
stgleb75c70412015-02-17 02:52:00 +0200384 "randwrite a 256k": [20212, 5690],\
385 "randwrite s 4k": [83, 6],\
386 "read a 64k": [89394, 3912],\
387 "write s 1024k": [8054, 280],\
388 "randwrite a 64k": [14595, 3245],\
389 "build_id": "2",\
390 "randread a 1024k": [83277, 9310],\
391 "randwrite s 256k": [3628, 433],\
392 "write a 1024k": [29226, 8624],\
393 "type": "master",\
394 "write a 64k": [25089, 790],\
395 "write s 64k": [1236, 30],\
396 "write a 256k": [30327, 9799],\
397 "write s 256k": [4049, 172],\
398 "randwrite a 1024k": [29000, 9302],\
399 "randread a 64k": [26775, 16319],\
400 "randwrite s 1024k": [8665, 1457],\
401 "randread a 256k": [63608, 16126],\
402 "randread a 4k": [3212, 1620],\
403 "read a 1024k": [89676, 4401],\
404 "date": "Thu Feb 12 19:11:56 2015",\
405 "write s 4k": [88, 3],\
406 "read a 4k": [92263, 5186],\
407 "read a 256k": [94505, 6868],\
408 "name": "6.1 Dev",\
409 "randwrite s 1k": [22, 3],\
410 "randwrite s 64k": [1105, 46],\
411 "write s 1k": [22, 0],\
412 "iso_md5": "bla bla"\
413 },\
414 {\
gstepanov15681d62015-02-23 17:17:50 +0200415 "username": "admin",\
416 "password": "admin", \
417 "tenant_name": "admin",\
418 "lab_url": "http://172.16.52.112:8000",\
419 "ceph_version": "v0.80 Firefly",\
420 "lab_name": "Perf-1-Env",\
stgleb75c70412015-02-17 02:52:00 +0200421 "randwrite a 256k": [16885, 1869],\
422 "randwrite s 4k": [79, 2],\
423 "read a 64k": [74398, 11618],\
424 "write s 1024k": [7490, 193],\
425 "randwrite a 64k": [14167, 4665],\
426 "build_id": "1",\
427 "randread a 1024k": [68683, 8604],\
428 "randwrite s 256k": [3277, 146],\
429 "write a 1024k": [24069, 660],\
430 "type": "sometype",\
431 "write a 64k": [24555, 1006],\
432 "write s 64k": [1285, 57],\
433 "write a 256k": [24928, 503],\
434 "write s 256k": [4029, 192],\
435 "randwrite a 1024k": [23980, 1897],\
436 "randread a 64k": [27257, 17268],\
437 "randwrite s 1024k": [8504, 238],\
438 "randread a 256k": [60868, 2637],\
439 "randread a 4k": [3612, 1355],\
440 "read a 1024k": [71122, 9217],\
441 "date": "Thu Feb 12 19:11:56 2015",\
442 "write s 4k": [87, 3],\
443 "read a 4k": [88367, 6471],\
444 "read a 256k": [80904, 8930],\
445 "name": "somedev",\
446 "randwrite s 1k": [20, 0],\
447 "randwrite s 64k": [1029, 34],\
448 "write s 1k": [21, 0],\
449 "iso_md5": "bla bla"\
450 }]'
451
452 # json_to_db(json_data)
gstepanove6ad1f02015-03-02 19:58:00 +0200453 print load_data(1, 2)
454 # add_data(json_data)