def job_create_view(request): module_id = request.GET.get('module_id') ret = {} ret['module_id'] = int(module_id) ret['module'] = ci_utils.get_module_list() ret['types'] = range(4) return render(request, 'ci_mgr/ci_job_opr.html', {'data': ret})
def jobs_view(request): ret = {} module_name = request.GET.get('module') # name ret['current_module'] = ci_utils.get_module_by_name(module_name) ret['current_task'] = request.GET.get('task_id') # id ret['current_subtask'] = request.GET.get('sub_task') # id ret['module'] = ci_utils.get_module_list() if ret['current_module']: ret['tasks'] = ci_utils.get_task_list(ret['current_module']['id']) else: ret['tasks'] = ci_utils.get_task_all() if ret['current_task'] : ret['sub_tasks'] = ci_utils.get_sub_task_all(ret['current_task']) else: ret['sub_tasks'] = ci_utils.get_sub_task_all() ret['jobs'] = [] if ret['current_module']: ret['jobs'] = ci_utils.get_module_job_list(ret['current_module']['id']) else: # get all module jobs for m in ret['module']: ret['jobs'].extend(ci_utils.get_module_job_list(m['id'])) for j in ret['jobs']: j['module'] = ci_utils.get_module_by_id(j['module_id'])['name'] #all_task = ci_utils.get_task_all() return render(request, 'ci_mgr/ci_jobs.html', {'data':ret})
def job_create_view(request): module_id = request.GET.get('module_id') ret = {} ret['module_id'] = int(module_id) ret['module'] = ci_utils.get_module_list() ret['types'] = range(4) return render(request, 'ci_mgr/ci_job_opr.html', {'data': ret})
def job_modify_view(request): job_id = request.GET.get('job_id') ret = {} ret['current_job'] = ci_utils.get_module_job(job_id) ret['module'] = ci_utils.get_module_list() ret['types'] = range(4) return render(request, 'ci_mgr/ci_job_opr.html', {'data': ret})
def jobs_view(request): ret = {} module_name = request.GET.get('module') # name ret['current_module'] = ci_utils.get_module_by_name(module_name) ret['current_task'] = request.GET.get('task_id') # id ret['current_subtask'] = request.GET.get('sub_task') # id ret['module'] = ci_utils.get_module_list() if ret['current_module']: ret['tasks'] = ci_utils.get_task_list(ret['current_module']['id']) else: ret['tasks'] = ci_utils.get_task_all() if ret['current_task']: ret['sub_tasks'] = ci_utils.get_sub_task_all(ret['current_task']) else: ret['sub_tasks'] = ci_utils.get_sub_task_all() ret['jobs'] = [] if ret['current_module']: ret['jobs'] = ci_utils.get_module_job_list(ret['current_module']['id']) else: # get all module jobs for m in ret['module']: ret['jobs'].extend(ci_utils.get_module_job_list(m['id'])) for j in ret['jobs']: j['module'] = ci_utils.get_module_by_id(j['module_id'])['name'] #all_task = ci_utils.get_task_all() return render(request, 'ci_mgr/ci_jobs.html', {'data': ret})
def job_modify_view(request): job_id = request.GET.get('job_id') ret = {} ret['current_job'] = ci_utils.get_module_job(job_id) ret['module'] = ci_utils.get_module_list() ret['types'] = range(4) return render(request, 'ci_mgr/ci_job_opr.html', {'data': ret})
def module_config_view(request): ret = {} module = request.GET.get('module') if module: # modify a existing module ret['current_module'] = ci_utils.get_module_by_name(module) ret['module'] = ci_utils.get_module_list() ret['types'] = range(4) return render(request, 'ci_mgr/ci_module_config.html', {'data': ret})
def module_config_view(request): ret = {} module = request.GET.get('module') if module: # modify a existing module ret['current_module'] = ci_utils.get_module_by_name(module) ret['module'] = ci_utils.get_module_list() ret['types'] = range(4) return render(request, 'ci_mgr/ci_module_config.html', {'data' : ret})
def get_task_list_view(request): module_name = request.GET.get("module") module_id = ci_utils.get_module_by_name(module_name)['id'] ret = {} ret['task'] = ci_utils.get_task_list(module_id) for i in ret['task']: i['module_name'] = ci_utils.get_module_by_id(i['module_id'])['name'] ret['module'] = ci_utils.get_module_list() ret['current_module'] = {} ret['current_module']['name'] = module_name ret['current_module']['id'] = module_id return render(request, 'ci_mgr/ci_task.html', {"data":ret})
def get_task_list_view(request): module_name = request.GET.get("module") module_id = ci_utils.get_module_by_name(module_name)['id'] ret = {} ret['task'] = ci_utils.get_task_list(module_id) for i in ret['task']: i['module_name'] = ci_utils.get_module_by_id(i['module_id'])['name'] ret['module'] = ci_utils.get_module_list() ret['current_module'] = {} ret['current_module']['name'] = module_name ret['current_module']['id'] = module_id return render(request, 'ci_mgr/ci_task.html', {"data": ret})
def job_seq_view(request): module_id = request.GET.get('module_id') sub_task_id = request.GET.get('sub_task_id') job_id = request.GET.get('job_id') if module_id and sub_task_id and job_id: # get all jobs belong to this module jobs = ci_utils.get_jobs_no_seq_by_sub_task_id(sub_task_id) sub_task = ci_utils.get_sub_task_info(sub_task_id) ret = {} ret['module'] = ci_utils.get_module_list() ret['current_module'] = ci_utils.get_module_by_id(module_id) ret['current_job'] = ci_utils.get_job_info_by_id(job_id) jb_info = ci_utils.get_job_set_by_job_id_sub_task_id( job_id, sub_task_id) if ret['current_job']: if jb_info['next'] == '[]': ret['current_job']['next'] = [] else: ret['current_job']['next'] = [ int(i) for i in jb_info['next'][1:-1].split(',') ] ret['current_job']['pre'] = jb_info['pre'] ret['current_job']['is_start'] = jb_info['is_start'] ret['current_subtask'] = sub_task ret['jobs'] = [] for j in jobs: tmp = ci_utils.get_job_info_by_id(j['job_id']) if not tmp: continue tmp['next'] = j['next'] tmp['pre'] = j['pre'] tmp['is_start'] = j['is_start'] ret['jobs'].append(tmp) job_tree = ci_utils.recursion_scan( ci_utils.get_sub_task_job_list(sub_task_id)['jobs']) # change 'next' to children ret['job_tree'] = [] for i in job_tree: ret['job_tree'].append('[' + json.dumps(i) + ']') return render(request, 'ci_mgr/ci_job_seq_config.html', {'data': ret}) else: return render(request, 'ci_mgr/ci_error.html')
def job_seq_view(request): module_id = request.GET.get('module_id') sub_task_id = request.GET.get('sub_task_id') job_id = request.GET.get('job_id') if module_id and sub_task_id and job_id: # get all jobs belong to this module jobs = ci_utils.get_jobs_no_seq_by_sub_task_id(sub_task_id) sub_task = ci_utils.get_sub_task_info(sub_task_id) ret = {} ret['module'] = ci_utils.get_module_list() ret['current_module'] = ci_utils.get_module_by_id(module_id) ret['current_job'] = ci_utils.get_job_info_by_id(job_id) jb_info = ci_utils.get_job_set_by_job_id_sub_task_id(job_id, sub_task_id) if ret['current_job']: if jb_info['next'] == '[]': ret['current_job']['next'] = [] else: ret['current_job']['next'] = [int(i) for i in jb_info['next'][1:-1].split(',')] ret['current_job']['pre'] = jb_info['pre'] ret['current_job']['is_start'] = jb_info['is_start'] ret['current_subtask'] = sub_task ret['jobs'] = [] for j in jobs: tmp = ci_utils.get_job_info_by_id(j['job_id']) if not tmp: continue tmp['next'] = j['next'] tmp['pre'] = j['pre'] tmp['is_start'] = j['is_start'] ret['jobs'].append(tmp) job_tree = ci_utils.recursion_scan(ci_utils.get_sub_task_job_list(sub_task_id)['jobs']) # change 'next' to children ret['job_tree'] = [] for i in job_tree: ret['job_tree'].append( '[' + json.dumps(i) + ']') return render(request, 'ci_mgr/ci_job_seq_config.html', {'data': ret}) else: return render(request,'ci_mgr/ci_error.html')
def get_task_list_view(request): module_name = request.GET.get("module") type = request.GET.get("type") # create or modify module_id = ci_utils.get_module_by_name(module_name).get('id') ret = {} ret['task'] = ci_utils.get_task_list(module_id) for i in ret['task']: i['status'] = ci_utils.get_task_status(i['id']) i['module_name'] = ci_utils.get_module_by_id(i['module_id'])['name'] tmp_subtask = ci_utils.get_sub_task_list(i['id']) i['sub_task'] = tmp_subtask['include'] + tmp_subtask['exclude'] ret['module'] = ci_utils.get_module_list() ret['current_module'] = {} ret['current_module']['name'] = module_name if module_id: ret['current_module']['id'] = module_id else: return render(request, 'ci_mgr/ci_error.html') ret['types'] = range(1,5) if type == 'create' or type == None: return render(request, 'ci_mgr/ci_task.html', {"data":ret}) elif type == 'modify': task_id = request.GET.get("task_id") ret['current_task'] = ci_utils.get_task(task_id) if ret['current_task'] == {}: return render(request, 'ci_mgr/ci_task.html', {"data":ret}) if ret['current_task']['module_id'] != ret['current_module']['id']: ret['module_not_match'] = 1 else: ret['module_not_match'] = 0 return render(request, 'ci_mgr/ci_task.html', {"data":ret})
def get_task_list_view(request): module_name = request.GET.get("module") type = request.GET.get("type") # create or modify module_id = ci_utils.get_module_by_name(module_name).get('id') ret = {} ret['task'] = ci_utils.get_task_list(module_id) for i in ret['task']: i['status'] = ci_utils.get_task_status(i['id']) i['module_name'] = ci_utils.get_module_by_id(i['module_id'])['name'] tmp_subtask = ci_utils.get_sub_task_list(i['id']) i['sub_task'] = tmp_subtask['include'] + tmp_subtask['exclude'] ret['module'] = ci_utils.get_module_list() ret['current_module'] = {} ret['current_module']['name'] = module_name if module_id: ret['current_module']['id'] = module_id else: return render(request, 'ci_mgr/ci_error.html') ret['types'] = range(1, 5) if type == 'create' or type == None: return render(request, 'ci_mgr/ci_task.html', {"data": ret}) elif type == 'modify': task_id = request.GET.get("task_id") ret['current_task'] = ci_utils.get_task(task_id) if ret['current_task'] == {}: return render(request, 'ci_mgr/ci_task.html', {"data": ret}) if ret['current_task']['module_id'] != ret['current_module']['id']: ret['module_not_match'] = 1 else: ret['module_not_match'] = 0 return render(request, 'ci_mgr/ci_task.html', {"data": ret})
def dashboard_view(request): ret = {} ret['module'] = ci_utils.get_module_list() data = ci_utils.static_dashboard() last_one = [] for l in data['latest']: if len(l.get('task_record')) != 0: last_one_tmp = l.get('task_record')[-1] last_one_tmp['name'] = ci_utils.get_module_by_id(last_one_tmp.get('module_id')).get('name') last_one.append(last_one_tmp) for t in l['task_record']: if "options" not in t: t["options"] = {} t['options']['other'] = json.dumps(t.get('options', {}).get('other')) ret['latest'] = ci_utils.static_dashboard().get('latest') """ # test #last_one = [1,2,3,4,5,6,7,8,9,10,11,12] import random arr_len = random.randint(4,12) for x in range(arr_len): seed = random.randint(0,1) if seed: last_one.append({"name": 'snake' + str(seed), "status" : 3}) else: last_one.append({"name": 'snake' + str(seed), "status" : 4}) """ if len(last_one) <= 5: last_one.append({"name":"待添加", "status": 10}) line_hex = 4 line_hex_even = 5 # last one 蜂窝分行 4 5 4 5 ret['last_one'] = [] flag_even = False while(len(last_one) != 0): if not flag_even: flag_even = True if len(last_one) >= line_hex: ret['last_one'].append(last_one[:line_hex]) last_one = last_one[line_hex:] else: ret['last_one'].append(last_one) break else: flag_even = False if len(last_one) >= line_hex_even: ret['last_one'].append(last_one[:line_hex_even]) last_one = last_one[line_hex_even:] else: ret['last_one'].append(last_one) break # statistics module_list = [] time_series = [] ratio_series = [] for i in range(len(data.get('latest'))): this_item = {} module_list.append(data.get('latest')[i].get("name")) # ci 平均时间 this_item['name'] = data.get('latest')[i].get("name") this_item['type'] = 'line' this_item['stack'] = u'CI平均运行时间' if data.get('latest')[i].get('static'): this_item['data'] = data.get('latest')[i].get('static').get('runtime') if data.get('latest')[i].get('static').get('runtime') == None: this_item['data'] = [0,0,0,0,0] elif len(data.get('latest')[i].get('static').get('runtime')) < 5: this_item['data'].append([0] * (5-len(data.get('latest')[i].get('static').get('runtime')))) else: this_item['data'] = [0,0,0,0,0] time_series.append(this_item) # ci 成功率 this_ratio = {} this_ratio['name'] = data.get('latest')[i].get('name') this_ratio['center'] = json.dumps( [ str((i%5)*20 + 10) + "%" ,str((i/5 + 1)*30) + "%"] ) this_ratio['x'] = str((i%5 )*20) + "%" tmp_data = [] if data.get('latest')[i].get('static'): tmp_data.append({'name': 'other', 'value': 100- int(str(int(data.get('latest')[i]['static']['success_rate']*100))[:2])}) tmp_data.append({'name': data.get('latest')[i].get('name'), 'value': int(str(int(data.get('latest')[i]['static']['success_rate']*100))[:2])}) this_ratio['data'] = tmp_data ratio_series.append(this_ratio) #this_ratio['data'] ret['ratios'] = ratio_series ret['runtime_series'] = json.dumps(time_series) return render(request, 'ci_mgr/ci_dashboard.html', {'data': ret})
def sub_task_view(request): task_id = request.GET.get("task_id") type = request.GET.get("type") # create or modify subtask_id = request.GET.get("subtask_id") page_current = request.GET.get('page_current') if not page_current: page_current = 1 sub_task = ci_utils.get_sub_task_list(task_id) ret = {} ret['module'] = ci_utils.get_module_list() name = "agile" view = data_utils.JenkinsInfo(name) ret['jenkins_module'] = [] for i in view.get_ret(): if i['name'].startswith("newlabs_"): this_module = i['name'][8:] ret['jenkins_module'].append(this_module) ret['current_task'] = ci_utils.get_task(task_id) for i in sub_task['include']: i['jobs'] = ci_utils.get_sub_task_job_all(i['id']) ret['current_task']['sub_task'] = sub_task['include'] ret['current_task']['sub_task_exclude'] = sub_task['exclude'] ret['current_task']['sub_task_no_seq'] = [] ret['current_module'] = {} ret['current_module']['id'] = ci_utils.get_module_by_id( ret['current_task']['module_id'])['id'] module_jobs = ci_utils.get_module_job_list(ret['current_module']['id']) ret['module_jobs'] = module_jobs ret['current_module']['name'] = ci_utils.get_module_by_id( ret['current_task']['module_id'])['name'] ret['types'] = range(1, 5) ret['all_sub_task'] = ci_utils.get_sub_task_all(task_id) job_tree = {} for i in ret['all_sub_task']: job_tree[i['name']] = {} job_tree[i['name']]['jobs'] = ci_utils.recursion_scan( ci_utils.get_sub_task_job_list(i['id'])['jobs']) job_tree[i['name']]['depth'] = ci_utils.get_sub_task_job_list( i['id'])['deep'] if type: if type == 'modify' and sub_task: ret['current_subtask'] = ci_utils.get_sub_task_info(subtask_id) return render(request, 'ci_mgr/ci_subtask_config.html', {'data': ret}) elif type == 'create': return render(request, 'ci_mgr/ci_subtask_config.html', {'data': ret}) ret['job_tree'] = {} for k, v in job_tree.iteritems(): ret['job_tree'][k] = {} ret['job_tree'][k]['jobs'] = [] ret['job_tree'][k]['depth'] = job_tree[k]['depth'] for i in job_tree[k]['jobs']: ret['job_tree'][k]['jobs'].append('[' + json.dumps(i) + ']') for t in ret['current_task']['sub_task']: t['job_line_cnt'] = len(job_tree[t['name']]['jobs']) t['job_depth'] = job_tree[t['name']]['jobs'] ret['all_depth'] = 0 ret['row_len'] = 0 for k, v in job_tree.iteritems(): ret['all_depth'] = ret['all_depth'] + job_tree[k]['depth'] for i in ret['current_task']['sub_task']: if i['name'] == k: i['job_max_depth'] = job_tree[k]['depth'] i['block_len'] = 100 + 110 * i['job_max_depth'] if i['block_len'] > 300: ret['row_len'] = ret['row_len'] + i['block_len'] else: ret['row_len'] = ret['row_len'] + 300 ret['current_task']['sub_task_cnt'] = len(ret['current_task']['sub_task']) ret['row_len'] = ret['row_len'] + ret['current_task']['sub_task_cnt'] * 80 # 获取运行记录 task_record = ci_utils.merge_task_record({ 'task_id': task_id, 'page_current': page_current }) for task_item in task_record['task']: task_item['params_str'] = json.dumps(task_item['params']) for sub_task_item in task_item['sub_task']: for job_item in sub_task_item['job']: job_item['build_url'] = job_item['options'].get( 'result', {}).get('build_url') ret['task_record'] = task_record ret['fail_types'] = ci_utils.get_fail_type() return render(request, 'ci_mgr/ci_subtask.html', {'data': ret})
def dashboard_view(request): ret = {} ret['module'] = ci_utils.get_module_list() data = ci_utils.static_dashboard() last_one = [] for l in data['latest']: if len(l.get('task_record')) != 0: last_one_tmp = l.get('task_record')[-1] last_one_tmp['name'] = ci_utils.get_module_by_id( last_one_tmp.get('module_id')).get('name') last_one.append(last_one_tmp) for t in l['task_record']: if "options" not in t: t["options"] = {} t['options']['other'] = json.dumps( t.get('options', {}).get('other')) ret['latest'] = ci_utils.static_dashboard().get('latest') """ # test #last_one = [1,2,3,4,5,6,7,8,9,10,11,12] import random arr_len = random.randint(4,12) for x in range(arr_len): seed = random.randint(0,1) if seed: last_one.append({"name": 'snake' + str(seed), "status" : 3}) else: last_one.append({"name": 'snake' + str(seed), "status" : 4}) """ if len(last_one) <= 5: last_one.append({"name": "待添加", "status": 10}) line_hex = 4 line_hex_even = 5 # last one 蜂窝分行 4 5 4 5 ret['last_one'] = [] flag_even = False while (len(last_one) != 0): if not flag_even: flag_even = True if len(last_one) >= line_hex: ret['last_one'].append(last_one[:line_hex]) last_one = last_one[line_hex:] else: ret['last_one'].append(last_one) break else: flag_even = False if len(last_one) >= line_hex_even: ret['last_one'].append(last_one[:line_hex_even]) last_one = last_one[line_hex_even:] else: ret['last_one'].append(last_one) break # statistics module_list = [] time_series = [] ratio_series = [] for i in range(len(data.get('latest'))): this_item = {} module_list.append(data.get('latest')[i].get("name")) # ci 平均时间 this_item['name'] = data.get('latest')[i].get("name") this_item['type'] = 'line' this_item['stack'] = u'CI平均运行时间' if data.get('latest')[i].get('static'): this_item['data'] = data.get('latest')[i].get('static').get( 'runtime') if data.get('latest')[i].get('static').get('runtime') == None: this_item['data'] = [0, 0, 0, 0, 0] elif len(data.get('latest')[i].get('static').get('runtime')) < 5: this_item['data'].append( [0] * (5 - len(data.get('latest')[i].get('static').get('runtime')))) else: this_item['data'] = [0, 0, 0, 0, 0] time_series.append(this_item) # ci 成功率 this_ratio = {} this_ratio['name'] = data.get('latest')[i].get('name') this_ratio['center'] = json.dumps( [str((i % 5) * 20 + 10) + "%", str((i / 5 + 1) * 30) + "%"]) this_ratio['x'] = str((i % 5) * 20) + "%" tmp_data = [] if data.get('latest')[i].get('static'): tmp_data.append({ 'name': 'other', 'value': 100 - int( str( int( data.get('latest')[i]['static']['success_rate'] * 100))[:2]) }) tmp_data.append({ 'name': data.get('latest')[i].get('name'), 'value': int( str( int( data.get('latest')[i]['static']['success_rate'] * 100))[:2]) }) this_ratio['data'] = tmp_data ratio_series.append(this_ratio) #this_ratio['data'] ret['ratios'] = ratio_series ret['runtime_series'] = json.dumps(time_series) return render(request, 'ci_mgr/ci_dashboard.html', {'data': ret})
def sub_task_view(request): task_id = request.GET.get("task_id") type = request.GET.get("type") # create or modify subtask_id = request.GET.get("subtask_id") page_current = request.GET.get('page_current') if not page_current: page_current = 1 sub_task = ci_utils.get_sub_task_list(task_id) ret = {} ret['module'] = ci_utils.get_module_list() name = "agile" view = data_utils.JenkinsInfo(name) ret['jenkins_module'] = [] for i in view.get_ret(): if i['name'].startswith("newlabs_"): this_module = i['name'][8:] ret['jenkins_module'].append(this_module) ret['current_task'] = ci_utils.get_task(task_id) for i in sub_task['include']: i['jobs'] = ci_utils.get_sub_task_job_all(i['id']) ret['current_task']['sub_task'] = sub_task['include'] ret['current_task']['sub_task_exclude'] = sub_task['exclude'] ret['current_task']['sub_task_no_seq'] = [] ret['current_module'] = {} ret['current_module']['id'] = ci_utils.get_module_by_id(ret['current_task']['module_id'])['id'] module_jobs = ci_utils.get_module_job_list(ret['current_module']['id']) ret['module_jobs'] = module_jobs ret['current_module']['name'] = ci_utils.get_module_by_id(ret['current_task']['module_id'])['name'] ret['types'] = range(1,5) ret['all_sub_task'] = ci_utils.get_sub_task_all(task_id) job_tree = {} for i in ret['all_sub_task']: job_tree[i['name']] = {} job_tree[i['name']]['jobs'] = ci_utils.recursion_scan(ci_utils.get_sub_task_job_list(i['id'])['jobs']) job_tree[i['name']]['depth'] = ci_utils.get_sub_task_job_list(i['id'])['deep'] if type: if type == 'modify' and sub_task: ret['current_subtask'] = ci_utils.get_sub_task_info(subtask_id) return render(request, 'ci_mgr/ci_subtask_config.html', {'data':ret}) elif type=='create': return render(request, 'ci_mgr/ci_subtask_config.html', {'data':ret}) ret['job_tree'] = {} for k,v in job_tree.iteritems(): ret['job_tree'][k] = {} ret['job_tree'][k]['jobs'] = [] ret['job_tree'][k]['depth'] = job_tree[k]['depth'] for i in job_tree[k]['jobs']: ret['job_tree'][k]['jobs'].append( '[' + json.dumps(i) + ']') for t in ret['current_task']['sub_task']: t['job_line_cnt'] = len(job_tree[t['name']]['jobs']) t['job_depth'] = job_tree[t['name']]['jobs'] ret['all_depth'] = 0 ret['row_len'] = 0 for k,v in job_tree.iteritems(): ret['all_depth'] = ret['all_depth'] + job_tree[k]['depth'] for i in ret['current_task']['sub_task']: if i['name'] == k: i['job_max_depth'] = job_tree[k]['depth'] i['block_len'] = 100 + 110*i['job_max_depth'] if i['block_len'] > 300: ret['row_len'] = ret['row_len'] + i['block_len'] else: ret['row_len'] = ret['row_len'] + 300 ret['current_task']['sub_task_cnt'] = len(ret['current_task']['sub_task']) ret['row_len'] = ret['row_len'] + ret['current_task']['sub_task_cnt']*80 # 获取运行记录 task_record = ci_utils.merge_task_record({'task_id':task_id, 'page_current':page_current}) for task_item in task_record['task']: task_item['params_str'] = json.dumps(task_item['params']) for sub_task_item in task_item['sub_task']: for job_item in sub_task_item['job']: job_item['build_url'] = job_item['options'].get('result', {}).get('build_url') ret['task_record'] = task_record ret['fail_types'] = ci_utils.get_fail_type() return render(request, 'ci_mgr/ci_subtask.html', {'data':ret})