diff --git a/AgileConfig.Server.Apisite/Controllers/ServiceController.cs b/AgileConfig.Server.Apisite/Controllers/ServiceController.cs index 4f085c98..2af8ac69 100644 --- a/AgileConfig.Server.Apisite/Controllers/ServiceController.cs +++ b/AgileConfig.Server.Apisite/Controllers/ServiceController.cs @@ -66,7 +66,40 @@ public async Task Add([FromBody] ServiceInfoVM model) success = true }); } - + + [HttpPost] + public async Task Remove(string id) + { + if (string.IsNullOrEmpty(id)) + { + throw new ArgumentNullException("id"); + } + + var service = await _serviceInfoService.GetByUniqueIdAsync(id); + if (service == null) + { + return Json(new + { + success = false, + message = "该服务不存在" + }); + } + + await _registerCenterService.UnRegisterAsync(id); + + //send a message to notify other services + dynamic param = new ExpandoObject(); + param.ServiceId = service.ServiceId; + param.ServiceName = service.ServiceName; + param.UniqueId = service.Id; + TinyEventBus.Instance.Fire(EventKeys.UNREGISTER_A_SERVICE,param); + + return Json(new + { + success = true + }); + } + public async Task Search(string serviceName, string serviceId, ServiceStatus? status, string sortField, string ascOrDesc, int current = 1, int pageSize = 20) diff --git a/AgileConfig.Server.Service/RemoteServerNodeProxy.cs b/AgileConfig.Server.Service/RemoteServerNodeProxy.cs index b397750e..d376bfcf 100644 --- a/AgileConfig.Server.Service/RemoteServerNodeProxy.cs +++ b/AgileConfig.Server.Service/RemoteServerNodeProxy.cs @@ -78,11 +78,20 @@ public async Task AllClientsDoActionAsync(string address, WebsocketAction using (var service = GetSysLogService()) { + var module = ""; + if (action.Module == "R") + { + module = "注册中心"; + } + if (action.Module == "C") + { + module = "配置中心"; + } await service.AddSysLogAsync(new SysLog { LogTime = DateTime.Now, LogType = result ? SysLogType.Normal : SysLogType.Warn, - LogText = $"通知节点【{address}】所有客户端:【{action.Module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}" + LogText = $"通知节点【{address}】所有客户端:【{module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}" }); } @@ -114,12 +123,21 @@ public async Task AppClientsDoActionAsync(string address, string appId, st using (var service = GetSysLogService()) { + var module = ""; + if (action.Module == "R") + { + module = "注册中心"; + } + if (action.Module == "C") + { + module = "配置中心"; + } await service.AddSysLogAsync(new SysLog { LogTime = DateTime.Now, LogType = result ? SysLogType.Normal : SysLogType.Warn, AppId = appId, - LogText = $"通知节点【{address}】应用【{appId}】的客户端:【{action.Module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}" + LogText = $"通知节点【{address}】应用【{appId}】的客户端:【{module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}" }); } @@ -164,11 +182,20 @@ public async Task OneClientDoActionAsync(string address, string clientId, using (var service = GetSysLogService()) { + var module = ""; + if (action.Module == "R") + { + module = "注册中心"; + } + if (action.Module == "C") + { + module = "配置中心"; + } await service.AddSysLogAsync(new SysLog { LogTime = DateTime.Now, LogType = result ? SysLogType.Normal : SysLogType.Warn, - LogText = $"通知节点【{address}】的客户端【{clientId}】:【{action.Module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}" + LogText = $"通知节点【{address}】的客户端【{clientId}】:【{module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}" }); } diff --git a/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx b/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx index 76beaf96..a6b8cbee 100644 --- a/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx +++ b/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx @@ -2,12 +2,13 @@ import { PlusOutlined } from '@ant-design/icons'; import { FormInstance, ModalForm, ProFormDependency, ProFormSelect, ProFormText } from '@ant-design/pro-form'; import { PageContainer } from '@ant-design/pro-layout'; import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table'; -import { Button, message } from 'antd'; +import { Button, message, Modal } from 'antd'; import React, { useRef, useState } from 'react'; import { getIntl, getLocale } from 'umi'; import { ServiceItem } from './data'; -import { addService, queryService } from './service'; +import { addService, queryService, removeService } from './service'; import styles from './index.less'; +const { confirm } = Modal; const handleAdd = async (fields: ServiceItem) => { const intl = getIntl(getLocale()); @@ -34,6 +35,25 @@ const handleAdd = async (fields: ServiceItem) => { return false; } }; +const handleDelSome = async (service: ServiceItem):Promise => { + const intl = getIntl(getLocale()); + const hide = message.loading(intl.formatMessage({id:'deleting'})); + try { + const result = await removeService(service); + hide(); + const success = result.success; + if (success) { + message.success(intl.formatMessage({id:'delete_success'})); + } else { + message.error(intl.formatMessage({id:'delete_fail'})); + } + return success; + } catch (error) { + hide(); + message.error(intl.formatMessage({id:'delete_fail'})); + return false; + } +}; const services: React.FC = () => { const actionRef = useRef(); @@ -114,7 +134,21 @@ const services: React.FC = () => { title: '操作', valueType: 'option', render: (text, record, _, action) => [ - + { + confirm({ + content:`确定删除选中的服务吗?`, + onOk: async ()=>{ + const result = await handleDelSome(record) + if (result) { + actionRef.current?.reload(); + } + } + }) + } + } + > 删除 ] diff --git a/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/service.ts b/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/service.ts index 4614a735..dd3ed5b9 100644 --- a/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/service.ts +++ b/AgileConfig.Server.UI/react-ui-antd/src/pages/Services/service.ts @@ -33,4 +33,13 @@ export async function addService(service: ServiceItem) { ...service } }); +} + +export async function removeService(service: ServiceItem) { + return request('/service/remove', { + method: 'POST', + params:{ + id: service.id + } + }); } \ No newline at end of file