public async Task <IActionResult> SearchServerNodeClients(string address, int current, int pageSize) { if (current <= 0) { throw new ArgumentException("current can not less than 1 ."); } if (pageSize <= 0) { throw new ArgumentException("pageSize can not less than 1 ."); } var addressess = new List <string>(); if (string.IsNullOrEmpty(address)) { var nodes = await _serverNodeService.GetAllNodesAsync(); addressess.AddRange(nodes.Select(n => n.Address)); } else { addressess.Add(address); } var clients = new List <ClientInfo>(); addressess.ForEach(addr => { var report = _remoteServerNodeProxy.GetClientsReport(addr); if (report != null && report.Infos != null) { clients.AddRange(report.Infos); } }); var page = clients.OrderBy(i => i.Address).ThenBy(i => i.Id).Skip((current - 1) * pageSize).Take(pageSize); return(Json(new { current, pageSize, success = true, total = clients.Count, data = page })); }
public async Task <IActionResult> All() { var nodes = await _serverNodeService.GetAllNodesAsync(); return(Json(new { success = true, data = nodes.OrderBy(n => n.CreateTime) })); }
public async Task <IActionResult> GetAll() { var nodes = await _serverNodeService.GetAllNodesAsync(); var vms = nodes.Select(x => new ServerNodeVM { Address = x.Address, Remark = x.Remark, LastEchoTime = x.LastEchoTime, Status = x.Status }); return(Json(vms)); }
public async Task <IActionResult> AllClients_Reload(string address) { var action = new WebsocketAction { Action = "reload" }; var nodes = await _serverNodeService.GetAllNodesAsync(); var result = await _remoteServerNodeProxy.AllClientsDoActionAsync(address, action); _logger.LogInformation("Request remote node {0} 's action AllClientsDoAction {1} .", address, result ? "success" : "fail"); return(Json(new { success = true, })); }
public Task TestEchoAsync() { return(Task.Run(async() => { while (true) { var nodes = await _serverNodeService.GetAllNodesAsync(); nodes.ForEach(n => { try { FunctionUtil.TRY(() => { using (var resp = (n.Address + "/home/echo").AsHttp().Send()) { if (resp.StatusCode == System.Net.HttpStatusCode.OK && resp.GetResponseContent() == "ok") { n.LastEchoTime = DateTime.Now; n.Status = Data.Entity.NodeStatus.Online; var report = GetClientReport(n); if (_serverNodeClientReports.ContainsKey(n.Address)) { _serverNodeClientReports[n.Address] = report; } else { _serverNodeClientReports.AddOrUpdate(n.Address, report, (k, r) => report); } } else { n.Status = Data.Entity.NodeStatus.Offline; } _serverNodeService.UpdateAsync(n); } }, 5); } catch (Exception e) { _logger.LogInformation(e, "Try test node {0} echo , but fail .", n.Address); } }); await Task.Delay(5000 * 1); } })); }
public async Task <IActionResult> PublishSome([FromBody] List <string> configIds) { if (configIds == null) { throw new ArgumentNullException("configIds"); } var nodes = await _serverNodeService.GetAllNodesAsync(); foreach (var configId in configIds) { var config = await _configService.GetAsync(configId); if (config == null) { return(Json(new { success = false, message = "未找到对应的配置项。" })); } if (config.OnlineStatus == OnlineStatus.Online) { continue; } config.OnlineStatus = OnlineStatus.Online; var result = await _configService.UpdateAsync(config); if (result) { dynamic param = new ExpandoObject(); param.config = config; param.userName = this.GetCurrentUserName(); TinyEventBus.Instance.Fire(EventKeys.PUBLISH_CONFIG_SUCCESS, param); } } return(Json(new { success = true, message = "上线配置成功" })); }
public async Task <IActionResult> NodeCount() { var nodeCount = (await _serverNodeService.GetAllNodesAsync()).Count; return(Json(nodeCount)); }
public async Task <IActionResult> Edit([FromBody] ConfigVM model) { if (model == null) { throw new ArgumentNullException("model"); } var config = await _configService.GetAsync(model.Id); if (config == null) { return(Json(new { success = false, message = "未找到对应的配置项。" })); } var oldConfig = new Config { Key = config.Key, Group = config.Group, Value = config.Value }; if (config.Group != model.Group || config.Key != model.Key) { var anotherConfig = await _configService.GetByAppIdKey(model.AppId, model.Group, model.Key); if (anotherConfig != null) { return(Json(new { success = false, message = "配置键已存在,请重新输入。" })); } } config.AppId = model.AppId; config.Description = model.Description; config.Key = model.Key; config.Value = model.Value; config.Group = model.Group; config.Status = model.Status; config.UpdateTime = DateTime.Now; var result = await _configService.UpdateAsync(config); if (result && !IsOnlyUpdateDescription(config, oldConfig)) { //add modify log await _modifyLogService.AddAsync(new ModifyLog { Id = Guid.NewGuid().ToString("N"), ConfigId = config.Id, Key = config.Key, Group = config.Group, Value = config.Value, ModifyTime = config.UpdateTime.Value }); //syslog await _sysLogService.AddSysLogSync(new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, AppId = config.AppId, LogText = $"编辑配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】" }); //notice clients var action = new WebsocketAction { Action = ActionConst.Update, Item = new ConfigItem { group = config.Group, key = config.Key, value = config.Value }, OldItem = new ConfigItem { group = oldConfig.Group, key = oldConfig.Key, value = oldConfig.Value } }; var nodes = await _serverNodeService.GetAllNodesAsync(); foreach (var node in nodes) { if (node.Status == NodeStatus.Offline) { continue; } await _remoteServerNodeProxy.AppClientsDoActionAsync(node.Address, config.AppId, action); } } return(Json(new { success = result, message = !result ? "修改配置失败,请查看错误日志。" : "" })); }
/// <summary> /// 注册添加系统日志事件 /// </summary> private void RegisterAddSysLog() { TinyEventBus.Instance.Regist(EventKeys.ADMIN_LOGIN_SUCCESS, (parm) => { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, LogText = $"管理员登录成功" }; _sysLogService.AddSysLogAsync(log); }); TinyEventBus.Instance.Regist(EventKeys.INIT_ADMIN_PASSWORD_SUCCESS, (parm) => { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, LogText = $"管理员密码初始化成功" }; _sysLogService.AddSysLogAsync(log); }); TinyEventBus.Instance.Regist(EventKeys.RESET_ADMIN_PASSWORD_SUCCESS, (parm) => { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, LogText = $"修改管理员密码成功" }; _sysLogService.AddSysLogAsync(log); }); TinyEventBus.Instance.Regist(EventKeys.ADD_APP_SUCCESS, (param) => { var app = param as App; if (app != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, LogText = $"新增应用【AppId:{app.Id}】【AppName:{app.Name}】" }; _sysLogService.AddSysLogAsync(log); } }); // app TinyEventBus.Instance.Regist(EventKeys.EDIT_APP_SUCCESS, (param) => { var app = param as App; if (app != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, LogText = $"编辑应用【AppId:{app.Id}】【AppName:{app.Name}】" }; _sysLogService.AddSysLogAsync(log); } }); TinyEventBus.Instance.Regist(EventKeys.DISABLE_OR_ENABLE_APP_SUCCESS, (param) => { var app = param as App; if (app != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, LogText = $"{(app.Enabled ? "启用" : "禁用")}应用【AppId:{app.Id}】" }; _sysLogService.AddSysLogAsync(log); } }); TinyEventBus.Instance.Regist(EventKeys.DELETE_APP_SUCCESS, (param) => { var app = param as App; if (app != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, LogText = $"删除应用【AppId:{app.Id}】" }; _sysLogService.AddSysLogAsync(log); } }); TinyEventBus.Instance.Regist(EventKeys.DELETE_APP_SUCCESS, (param) => { var app = param as App; if (app != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, LogText = $"删除应用【AppId:{app.Id}】" }; _sysLogService.AddSysLogAsync(log); } }); //config TinyEventBus.Instance.Regist(EventKeys.ADD_CONFIG_SUCCESS, (param) => { var config = param as Config; if (config != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, AppId = config.AppId, LogText = $"新增配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】" }; _sysLogService.AddSysLogAsync(log); _modifyLogService.AddAsync(new ModifyLog { Id = Guid.NewGuid().ToString("N"), ConfigId = config.Id, Key = config.Key, Group = config.Group, Value = config.Value, ModifyTime = config.CreateTime }); } }); TinyEventBus.Instance.Regist(EventKeys.EDIT_CONFIG_SUCCESS, (param) => { dynamic param_dy = param; Config config = param_dy.config; Config oldConfig = param_dy.oldConfig; if (config != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, AppId = config.AppId, LogText = $"编辑配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】" }; _sysLogService.AddSysLogAsync(log); _modifyLogService.AddAsync(new ModifyLog { Id = Guid.NewGuid().ToString("N"), ConfigId = config.Id, Key = config.Key, Group = config.Group, Value = config.Value, ModifyTime = config.UpdateTime.Value }); } }); TinyEventBus.Instance.Regist(EventKeys.EDIT_CONFIG_SUCCESS, async(param) => { dynamic param_dy = param; Config config = param_dy.config; Config oldConfig = param_dy.oldConfig; if (config != null) { if (config.OnlineStatus == OnlineStatus.Online) { //notice clients var action = new WebsocketAction { Action = ActionConst.Update, Item = new ConfigItem { group = config.Group, key = config.Key, value = config.Value }, OldItem = new ConfigItem { group = oldConfig.Group, key = oldConfig.Key, value = oldConfig.Value } }; var nodes = await _serverNodeService.GetAllNodesAsync(); foreach (var node in nodes) { if (node.Status == NodeStatus.Offline) { continue; } await _remoteServerNodeProxy.AppClientsDoActionAsync(node.Address, config.AppId, action); } } } }); TinyEventBus.Instance.Regist(EventKeys.DELETE_CONFIG_SUCCESS, (param) => { var config = param as Config; if (config != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, AppId = config.AppId, LogText = $"删除配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】" }; _sysLogService.AddSysLogAsync(log); } }); TinyEventBus.Instance.Regist(EventKeys.DELETE_CONFIG_SUCCESS, async(param) => { var config = param as Config; if (config != null) { var action = await CreateRemoveWebsocketAction(config, config.AppId); var nodes = await _serverNodeService.GetAllNodesAsync(); foreach (var node in nodes) { if (node.Status == NodeStatus.Offline) { continue; } await _remoteServerNodeProxy.AppClientsDoActionAsync(node.Address, config.AppId, action); } } }); TinyEventBus.Instance.Regist(EventKeys.OFFLINE_CONFIG_SUCCESS, (param) => { var config = param as Config; if (config != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, AppId = config.AppId, LogText = $"下线配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】" }; _sysLogService.AddSysLogAsync(log); } }); TinyEventBus.Instance.Regist(EventKeys.OFFLINE_CONFIG_SUCCESS, async(param) => { var config = param as Config; if (config != null) { //notice clients the config item is offline var action = new WebsocketAction { Action = ActionConst.Remove, Item = new ConfigItem { group = config.Group, key = config.Key, value = config.Value } }; var nodes = await _serverNodeService.GetAllNodesAsync(); foreach (var node in nodes) { if (node.Status == NodeStatus.Offline) { continue; } await _remoteServerNodeProxy.AppClientsDoActionAsync(node.Address, config.AppId, action); } } }); TinyEventBus.Instance.Regist(EventKeys.PUBLISH_CONFIG_SUCCESS, (param) => { Config config = param as Config; if (config != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, AppId = config.AppId, LogText = $"上线配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】" }; _sysLogService.AddSysLogAsync(log); } }); TinyEventBus.Instance.Regist(EventKeys.PUBLISH_CONFIG_SUCCESS, async(param) => { Config config = param as Config; if (config != null) { if (config != null && config.OnlineStatus == OnlineStatus.Online) { //notice clients config item is published var action = new WebsocketAction { Action = ActionConst.Add, Item = new ConfigItem { group = config.Group, key = config.Key, value = config.Value } }; var nodes = await _serverNodeService.GetAllNodesAsync(); foreach (var node in nodes) { if (node.Status == NodeStatus.Offline) { continue; } await _remoteServerNodeProxy.AppClientsDoActionAsync(node.Address, config.AppId, action); } } } }); TinyEventBus.Instance.Regist(EventKeys.ROLLBACK_CONFIG_SUCCESS, (param) => { dynamic param_dy = param; Config config = param_dy.config; ModifyLog modifyLog = param_dy.modifyLog; if (config != null && modifyLog != null) { var log = new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, AppId = config.AppId, LogText = $"回滚配置【Key:{config.Key}】 【Group:{config.Group}】 【AppId:{config.AppId}】至历史记录:{modifyLog.Id}" }; _sysLogService.AddSysLogAsync(log); _modifyLogService.AddAsync(new ModifyLog { Id = Guid.NewGuid().ToString("N"), ConfigId = config.Id, Key = config.Key, Group = config.Group, Value = config.Value, ModifyTime = config.UpdateTime.Value }); } }); TinyEventBus.Instance.Regist(EventKeys.ROLLBACK_CONFIG_SUCCESS, async(param) => { dynamic param_dy = param; Config config = param_dy.config; Config oldConfig = param_dy.oldConfig; ModifyLog modifyLog = param_dy.modifyLog; if (config != null && oldConfig != null) { if (config.OnlineStatus == OnlineStatus.Online) { //notice clients var action = new WebsocketAction { Action = ActionConst.Update, Item = new ConfigItem { group = config.Group, key = config.Key, value = config.Value }, OldItem = new ConfigItem { group = oldConfig.Group, key = oldConfig.Key, value = oldConfig.Value } }; var nodes = await _serverNodeService.GetAllNodesAsync(); foreach (var node in nodes) { if (node.Status == NodeStatus.Offline) { continue; } await _remoteServerNodeProxy.AppClientsDoActionAsync(node.Address, config.AppId, action); } } } }); }