def show(request): """""" tpl = get_template("manage/space.html") webaddr = request.META["HTTP_HOST"] interfaces_groups = machinesmgr.queryAllInterfaces(request.session["sys_uid"], request.session["sys_user"]) # [(machine, [components, ...]), ...] cellMgrWSUrl = "" cells = [] for mID, comps in interfaces_groups.items(): for comp in comps: if comp.componentType in VALID_CT: if Define.CELLAPPMGR_TYPE == comp.componentType: cellMgrWSUrl = "ws://{}/wc/space/mgr/open?cp={}&host={}&port={}".format(webaddr, comp.componentType, comp.intaddr, comp.intport) else: wsurl = "ws://{}/wc/space/cell/open?cp={}&host={}&port={}".format(webaddr, comp.componentType, comp.intaddr, comp.intport) cell = [comp.componentID, wsurl] cells.append(cell) print(json.dumps(cells)) return HttpResponse(tpl.render({"cells": cells, "cellMgrWSUrl": cellMgrWSUrl}, request))
def query_stop_servers_status(request): """""" uid = request.POST["uid"] interfacesGroups = machinesmgr.queryAllInterfaces( int(uid), request.session["sys_user"]) dic = {} for ctid in COMPS_FOR_SHUTDOWN: key = Define.COMPONENT_NAME[ctid] dic[key] = 0 finished = True for mid, comps in interfacesGroups.items(): if len(comps) <= 1: continue for comp in comps: if Define.MACHINE_TYPE == comp.componentType: continue finished = False key = Define.COMPONENT_NAME[comp.componentType] if key in dic.keys(): dic[key] += 1 else: dic[key] = 1 keys = list(dic.keys()) keys.sort() lst = [[key, dic[key]] for key in keys] datas = {"success": True, "datas": lst, "finish": finished} return JsonResponse(datas)
def show(request): """""" VALID_CT = {Define.DBMGR_TYPE, Define.LOGINAPP_TYPE, Define.CELLAPP_TYPE, Define.BASEAPP_TYPE, Define.INTERFACES_TYPE, Define.LOGGER_TYPE} interfacesGroups = machinesmgr.queryAllInterfaces(request.session["sys_uid"], request.session["sys_user"]) webaddr = request.META["HTTP_HOST"] pytick = [] cp = [] py = [] event = [] network = [] for mID, comps in interfacesGroups.items(): for comp in comps: if comp.componentType in VALID_CT: wsurl = "ws://{}/wc/profile/query/profile?host={}&port={}".format(webaddr, comp.intaddr, comp.consolePort) wsurl1 = "{}&cmd=pytickprofile".format(wsurl) wsurl2 = "{}&cmd=cprofile".format(wsurl) wsurl3 = "{}&cmd=pyprofile".format(wsurl) wsurl4 = "{}&cmd=eventprofile".format(wsurl) wsurl5 = "{}&cmd=networkprofile".format(wsurl) pytick.append([json.dumps( {"wsurl": wsurl1, "cmd": "pytickprofile", "ip": comp.intaddr, "port": comp.consolePort, "title": "TickProfile"}), comp.fullname]) cp.append( [json.dumps({"wsurl": wsurl2, "cmd": "cprofile", "ip": comp.intaddr, "port": comp.consolePort, "title": "CPProfile"}), comp.fullname]) py.append( [json.dumps({"wsurl": wsurl3, "cmd": "pyprofile", "ip": comp.intaddr, "port": comp.consolePort, "title": "PYProfile"}), comp.fullname]) event.append([json.dumps( {"wsurl": wsurl4, "cmd": "eventprofile", "ip": comp.intaddr, "port": comp.consolePort, "title": "EventProfile"}), comp.fullname]) network.append([json.dumps( {"wsurl": wsurl5, "cmd": "networkprofile", "ip": comp.intaddr, "port": comp.consolePort, "title": "NetworkProfile"}), comp.fullname]) tpl = get_template("manage/profile.html") return HttpResponse(tpl.render({ "pytick": pytick, "cp": cp, "py": py, "event": event, "network": network }, request))
def save_config(request): """""" try: saveTime = request.POST["time"] name = request.POST["name"].strip() except Exception as ex: print(ex) datas = {"success": False, "datas": [], "error": "POST参数错误!"} return JsonResponse(datas) print(saveTime, type(saveTime)) print(name, type(name)) interfaces_groups = machinesmgr.queryAllInterfaces( request.session["sys_uid"], request.session["sys_user"]) conf = {} for machineID, infos in interfaces_groups.items(): for info in infos: if info.componentType not in VALID_CT: continue compnentName = Define.COMPONENT_NAME[info.componentType] if compnentName not in conf: conf[compnentName] = [] d = { "ip": info.intaddr, "cid": info.componentID, "gus": info.genuuid_sections } conf[compnentName].append(d) if len(conf) == 0: datas = {"success": False, "datas": [], "error": "POST参数错误!"} return JsonResponse(datas) try: m = ServerLayout.objects.get(name=name) except Exception as ex: m = ServerLayout() m.name = name m.sys_user = request.session["sys_user"] m.config = json.dumps(conf) m.save() datas = {"success": True, "datas": []} return JsonResponse(datas)
def show(request): """""" tpl = get_template("manage/watcher.html") webaddr = request.META["HTTP_HOST"] interfaces_groups = machinesmgr.queryAllInterfaces(request.session["sys_uid"], request.session["sys_user"]) # [(machine, [components, ...]), ...] kbeComps = [] for mID, comps in interfaces_groups.items(): for comp in comps: if comp.componentType in VALID_CT: wsurl = "ws://{}/wc/watcher/open?cp={}&host={}&port={}".format(webaddr, comp.componentType, comp.intaddr, comp.intport) compname = Define.COMPONENT_NAME[comp.componentType] value = {"wsurl": wsurl, "name": compname} kbeComps.append([json.dumps(value), comp.fullname]) return HttpResponse(tpl.render({"comps": kbeComps}, request))
def show(request): """""" VALID_CT = [Define.LOGGER_TYPE] interfaces_groups = machinesmgr.queryAllInterfaces( request.session["sys_uid"], request.session["sys_user"]) kbeComps = [] for mID, comps in interfaces_groups.items(): for comp in comps: print(comp.__dict__) if comp.componentType in VALID_CT: kbeComps.append(comp) webaddr = request.META["HTTP_HOST"] tpl = get_template("manage/log.html") try: intaddr = kbeComps[0].intaddr intport = kbeComps[0].intport extaddr = kbeComps[0].extaddr extport = kbeComps[0].extport uid = request.session["sys_uid"] except: return HttpResponse( tpl.render( { "intaddr": '', "intport": 0, "extaddr": '', "extport": 0, "uid": 0, "webaddr": webaddr }, request)) return HttpResponse( tpl.render( { "intaddr": intaddr, "intport": intport, "extaddr": extaddr, "extport": extport, "uid": uid, "webaddr": webaddr, }, request))
def query_servers(request): """""" interfacesGroups = machinesmgr.queryAllInterfaces( 0, request.session["sys_user"]) targetIP = request.POST.get("target", None) lst = [] for mID, comps in interfacesGroups.items(): if len(comps) > 1 and comps[0].intaddr == targetIP: lst = comps[1:] break ll = [] for comp in lst: ll.append([ comp.intaddr, comp.fullname, comp.pid, comp.componentType, comp.componentID, comp.globalOrderID, comp.genuuid_sections, '{:.2f}%'.format(comp.cpu), '{:.2f}%'.format(comp.mem), '{:.2f}MB'.format(comp.usedmem / 1048576), comp.entities, comp.proxies, comp.clients, '<div class="btn-group" role="group" aria-label="...">' '<button class="btn btn-warning btn-xs" type="button" onclick="onStopServer({0},{1},\'{2}\')">STOP</button>' '<button class="btn btn-danger btn-xs" type="button" onclick="onKillServer({0},{1},\'{2}\')">KILL</button>' '</div>'.format(comp.componentType, comp.componentID, comp.fullname), ]) datas = {"success": True, "datas": ll} return JsonResponse(datas)
def load_config(request): """""" kbe_root = request.session["kbe_root"] kbe_res_path = request.session["kbe_res_path"] kbe_bin_path = request.session["kbe_bin_path"] try: id = int(request.POST["id"]) except Exception as ex: print(ex) id = 0 if not id: datas = {"success": False, "error": "参数错误!"} return JsonResponse(datas) components = Machines.Machines(request.session["sys_uid"], request.session["sys_user"]) interfaces_groups = machinesmgr.queryAllInterfaces( request.session["sys_uid"], request.session["sys_user"]) for mID, comps in interfaces_groups.items(): if len(comps) > 1: datas = {"success": False, "error": "服务器正在运行,不允许加载!"} return JsonResponse(datas) # 计数器 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) lst = [ Define.LOGGER_TYPE, Define.INTERFACES_TYPE, Define.DBMGR_TYPE, Define.BASEAPPMGR_TYPE, Define.CELLAPPMGR_TYPE, Define.CELLAPP_TYPE, Define.BASEAPP_TYPE, Define.LOGINAPP_TYPE, ] for ct in lst: compnentName = Define.COMPONENT_NAME[ct] components_ct[ct] = ct for comp in layoutData.get(compnentName, []): cid = comp["cid"] if cid <= 0: cid = machinesmgr.makeCID(ct) components_cid[ct] = cid gus = comp["gus"] if gus <= 0: gus = machinesmgr.makeGUS(ct) components_gus[ct] = gus t2c[ct] += 1 components.startServer(ct, cid, gus, comp["ip"], kbe_root, kbe_res_path, kbe_bin_path, 0) datas = {"success": True, "datas": []} return JsonResponse(datas)