def components_shutdown(request): """ 停止服务器 """ COMPS_FOR_SHUTDOWN = [ Define.BOTS_TYPE, Define.LOGINAPP_TYPE, Define.CELLAPP_TYPE, Define.BASEAPP_TYPE, Define.CELLAPPMGR_TYPE, Define.BASEAPPMGR_TYPE, Define.DBMGR_TYPE, Define.INTERFACES_TYPE, Define.LOGGER_TYPE, ] components = Machines.Machines(request.session["sys_uid"], request.session["sys_user"]) for ctid in COMPS_FOR_SHUTDOWN: components.stopServer(ctid, trycount=0) return render(request, "WebConsole/components_shutdown.html", {})
def components_query(request): """ 请求获取组件数据 """ components = Machines.Machines(request.session["sys_uid"], request.session["sys_user"]) components.queryAllInterfaces(timeout=0.5) # [ [machine, other-components, ...], ...] kbeComps = [] for mID, comps in components.interfaces_groups.items(): if len(comps) <= 1: continue dl = [] kbeComps.append(dl) for comp in comps: d = { "ip": comp.intaddr, "componentType": comp.componentType, "componentName": comp.componentName, "fullname": comp.fullname, "uid": comp.uid, "pid": comp.pid, "componentID": comp.componentID, "globalOrderID": comp.globalOrderID, "cpu": comp.cpu, "mem": comp.mem, "usedmem": comp.usedmem, "entities": comp.entities, "proxies": comp.proxies, "clients": comp.clients, "consolePort": comp.consolePort, } dl.append(d) return HttpResponse(json.dumps(kbeComps), content_type="application/json")
def pull_log(request): VALID_CT = set([ Define.LOGGER_TYPE, ]) components = Machines.Machines(request.session["sys_uid"], request.session["sys_user"]) components.queryAllInterfaces(timeout=0.5) # [(machine, [components, ...]), ...] kbeComps = [] for mID, comps in components.interfaces_groups.items(): for comp in comps: if comp.componentType in VALID_CT: kbeComps.append(comp) POST = request.POST try: intaddr = kbeComps[0].intaddr intport = kbeComps[0].intport extaddr = kbeComps[0].extaddr extport = kbeComps[0].extport # host = kbeComps[0].extaddr # port = kbeComps[0].consolePort uid = request.session["sys_uid"] except: message = {"unlogger": "logger进程未运行"} return HttpResponse(json.dumps(message)) # return render(request, html_template, context) #获取进程选中状态 components_checks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] components_checks2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] baseapp_check = POST.get("baseapp_check") baseappmgr_check = POST.get("baseappmgr_check") cellapp_check = POST.get("cellapp_check") dbmgr_check = POST.get("dbmgr_check") loginapp_check = POST.get("loginapp_check") pull_state = POST.get("pull_state") if pull_state == 0: pull_state = 1 if baseapp_check: components_checks[6] = Define.BASEAPP_TYPE if baseappmgr_check: components_checks[3] = Define.BASEAPPMGR_TYPE if cellapp_check: components_checks[5] = Define.CELLAPP_TYPE if dbmgr_check: components_checks[1] = Define.DBMGR_TYPE if loginapp_check: components_checks[2] = Define.LOGINAPP_TYPE if components_checks[6] == 0 \ and components_checks[3] == 0 \ and components_checks[5] == 0 \ and components_checks[1] == 0 \ and components_checks[2] == 0 : components_checks[6] = Define.BASEAPP_TYPE components_checks[3] = Define.BASEAPPMGR_TYPE components_checks[5] = Define.CELLAPP_TYPE components_checks[1] = Define.DBMGR_TYPE components_checks[2] = Define.LOGINAPP_TYPE baseapp_check = 1 baseappmgr_check = 1 cellapp_check = 1 dbmgr_check = 1 loginapp_check = 1 # if len(components_checks)<=1:components_checks[].append(Define.COMPONENT_END_TYPE) #获取log类型 CRITICAL_check = 0 DEBUG_check = 0 ERROR_check = 0 INFO_check = 0 PRINT_check = 0 S_DBG_check = 0 S_ERR_check = 0 S_INFO_check = 0 S_NORM_check = 0 S_WARN_check = 0 WARNING_check = 0 logtype = 0x00000000 CRITICAL = POST.get("CRITICAL") DEBUG = POST.get("DEBUG") ERROR = POST.get("ERROR") INFO = POST.get("INFO") PRINT = POST.get("PRINT") S_DBG = POST.get("S_DBG") S_ERR = POST.get("S_ERR") S_INFO = POST.get("S_INFO") S_NORM = POST.get("S_NORM") S_WARN = POST.get("S_WARN") WARNING = POST.get("WARNING") if CRITICAL: logtype |= logName2type["CRITICAL"] CRITICAL_check = 1 if DEBUG: logtype |= logName2type["DEBUG"] DEBUG_check = 1 if ERROR: logtype |= logName2type["ERROR"] ERROR_check = 1 if INFO: logtype |= logName2type["INFO"] INFO_check = 1 if PRINT: logtype |= logName2type["PRINT"] PRINT_check = 1 if S_DBG: logtype |= logName2type["S_DBG"] S_DBG_check = 1 if S_ERR: logtype |= logName2type["S_ERR"] S_ERR_check = 1 if S_INFO: logtype |= logName2type["S_INFO"] S_INFO_check = 1 if S_NORM: logtype |= logName2type["S_NORM"] S_NORM_check = 1 if S_WARN: logtype |= logName2type["S_WARN"] S_WARN_check = 1 if WARNING: logtype |= logName2type["S_WARN"] WARNING_check = 1 if logtype == 0x00000000: logtype = 0xffffffff CRITICAL_check = 1 DEBUG_check = 1 ERROR_check = 1 INFO_check = 1 PRINT_check = 1 S_DBG_check = 1 S_ERR_check = 1 S_INFO_check = 1 S_NORM_check = 1 S_WARN_check = 1 WARNING_check = 1 #自定义搜索 globalOrder = POST.get("globalOrder") groupOrder = POST.get("groupOrder") searchDate = POST.get("searchDate") keystr = POST.get("keystr") if globalOrder == None: globalOrder = "" if groupOrder == None: groupOrder = "" if searchDate == None: searchDate = "" if keystr == None: keystr = "" message = { "ws_url": ws_url, "baseapp_check": components_checks[6], "baseappmgr_check": components_checks[3], "cellapp_check": components_checks[5], "dbmgr_check": components_checks[1], "loginapp_check": components_checks[2], "CRITICAL_check": CRITICAL_check, "DEBUG_check": DEBUG_check, "ERROR_check": ERROR_check, "INFO_check": INFO_check, "PRINT_check": PRINT_check, "S_DBG_check": S_DBG_check, "S_ERR_check": S_ERR_check, "S_INFO_check": S_ERR_check, "S_NORM_check": S_NORM_check, "S_WARN_check": S_WARN_check, "WARNING_check": WARNING_check, "globalOrder": globalOrder, "groupOrder": groupOrder, "searchDate": searchDate, "keystr": keystr, "components_checks": components_checks, } return HttpResponse(json.dumps(message), content_type='application/json')
def components_load_layout(request): """ 加载某个保存的服务器运行配置,并启动服务器 """ VALID_CT = set([ Define.DBMGR_TYPE, Define.LOGINAPP_TYPE, Define.BASEAPPMGR_TYPE, Define.CELLAPPMGR_TYPE, Define.CELLAPP_TYPE, Define.BASEAPP_TYPE, Define.INTERFACES_TYPE, Define.LOGGER_TYPE, ]) try: id = int(request.GET["id"]) except: id = 0 if not id: return render(request, "WebConsole/components_load_layout.html", {"error": "无效的参数"}) components = Machines.Machines(request.session["sys_uid"], request.session["sys_user"]) components.queryAllInterfaces(timeout=0.5) for mID, comps in components.interfaces_groups.items(): if len(comps) > 1: return render(request, "WebConsole/components_load_layout.html", {"error": "服务器正在运行,不允许加载"}) # 计数器 t2c = [ 0, ] * len(Define.COMPONENT_NAME) components_ct = [ 0, ] * len(Define.COMPONENT_NAME) components_cid = [ 0, ] * len(Define.COMPONENT_NAME) components_gus = [ 0, ] * len(Define.COMPONENT_NAME) ly = ServerLayout.objects.get(pk=id) layoutData = json.loads(ly.config) for ct in VALID_CT: compnentName = Define.COMPONENT_NAME[ct] components_ct[ct] = ct for comp in layoutData.get(compnentName, []): cid = comp["cid"] if cid <= 0: cid = components.makeCID(ct) components_cid[ct] = cid gus = comp["gus"] if gus <= 0: gus = components.makeGUS(ct) components_gus[ct] = gus t2c[ct] += 1 components.startServer(ct, cid, gus, comp["ip"], 0) context = { "run_counter": str(t2c), "components_ct": str(components_ct), "components_cid": str(components_cid), "components_gus": str(components_gus), "components_ip": comp["ip"] } return render(request, "WebConsole/components_load_layout.html", context)