Skip to content

Commit d889350

Browse files
committed
add remove action
1 parent 30d0afe commit d889350

4 files changed

Lines changed: 110 additions & 7 deletions

File tree

AgileConfig.Server.Apisite/Controllers/ServiceController.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,40 @@ public async Task<IActionResult> Add([FromBody] ServiceInfoVM model)
6666
success = true
6767
});
6868
}
69-
69+
70+
[HttpPost]
71+
public async Task<IActionResult> Remove(string id)
72+
{
73+
if (string.IsNullOrEmpty(id))
74+
{
75+
throw new ArgumentNullException("id");
76+
}
77+
78+
var service = await _serviceInfoService.GetByUniqueIdAsync(id);
79+
if (service == null)
80+
{
81+
return Json(new
82+
{
83+
success = false,
84+
message = "该服务不存在"
85+
});
86+
}
87+
88+
await _registerCenterService.UnRegisterAsync(id);
89+
90+
//send a message to notify other services
91+
dynamic param = new ExpandoObject();
92+
param.ServiceId = service.ServiceId;
93+
param.ServiceName = service.ServiceName;
94+
param.UniqueId = service.Id;
95+
TinyEventBus.Instance.Fire(EventKeys.UNREGISTER_A_SERVICE,param);
96+
97+
return Json(new
98+
{
99+
success = true
100+
});
101+
}
102+
70103
public async Task<IActionResult> Search(string serviceName, string serviceId, ServiceStatus? status,
71104
string sortField, string ascOrDesc,
72105
int current = 1, int pageSize = 20)

AgileConfig.Server.Service/RemoteServerNodeProxy.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,20 @@ public async Task<bool> AllClientsDoActionAsync(string address, WebsocketAction
7878

7979
using (var service = GetSysLogService())
8080
{
81+
var module = "";
82+
if (action.Module == "R")
83+
{
84+
module = "注册中心";
85+
}
86+
if (action.Module == "C")
87+
{
88+
module = "配置中心";
89+
}
8190
await service.AddSysLogAsync(new SysLog
8291
{
8392
LogTime = DateTime.Now,
8493
LogType = result ? SysLogType.Normal : SysLogType.Warn,
85-
LogText = $"通知节点【{address}】所有客户端:【{action.Module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}"
94+
LogText = $"通知节点【{address}】所有客户端:【{module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}"
8695
});
8796
}
8897

@@ -114,12 +123,21 @@ public async Task<bool> AppClientsDoActionAsync(string address, string appId, st
114123

115124
using (var service = GetSysLogService())
116125
{
126+
var module = "";
127+
if (action.Module == "R")
128+
{
129+
module = "注册中心";
130+
}
131+
if (action.Module == "C")
132+
{
133+
module = "配置中心";
134+
}
117135
await service.AddSysLogAsync(new SysLog
118136
{
119137
LogTime = DateTime.Now,
120138
LogType = result ? SysLogType.Normal : SysLogType.Warn,
121139
AppId = appId,
122-
LogText = $"通知节点【{address}】应用【{appId}】的客户端:【{action.Module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}"
140+
LogText = $"通知节点【{address}】应用【{appId}】的客户端:【{module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}"
123141
});
124142
}
125143

@@ -164,11 +182,20 @@ public async Task<bool> OneClientDoActionAsync(string address, string clientId,
164182

165183
using (var service = GetSysLogService())
166184
{
185+
var module = "";
186+
if (action.Module == "R")
187+
{
188+
module = "注册中心";
189+
}
190+
if (action.Module == "C")
191+
{
192+
module = "配置中心";
193+
}
167194
await service.AddSysLogAsync(new SysLog
168195
{
169196
LogTime = DateTime.Now,
170197
LogType = result ? SysLogType.Normal : SysLogType.Warn,
171-
LogText = $"通知节点【{address}】的客户端【{clientId}】:【{action.Module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}"
198+
LogText = $"通知节点【{address}】的客户端【{clientId}】:【{module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}"
172199
});
173200
}
174201

AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { PlusOutlined } from '@ant-design/icons';
22
import { FormInstance, ModalForm, ProFormDependency, ProFormSelect, ProFormText } from '@ant-design/pro-form';
33
import { PageContainer } from '@ant-design/pro-layout';
44
import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table';
5-
import { Button, message } from 'antd';
5+
import { Button, message, Modal } from 'antd';
66
import React, { useRef, useState } from 'react';
77
import { getIntl, getLocale } from 'umi';
88
import { ServiceItem } from './data';
9-
import { addService, queryService } from './service';
9+
import { addService, queryService, removeService } from './service';
1010
import styles from './index.less';
11+
const { confirm } = Modal;
1112

1213
const handleAdd = async (fields: ServiceItem) => {
1314
const intl = getIntl(getLocale());
@@ -34,6 +35,25 @@ const handleAdd = async (fields: ServiceItem) => {
3435
return false;
3536
}
3637
};
38+
const handleDelSome = async (service: ServiceItem):Promise<boolean> => {
39+
const intl = getIntl(getLocale());
40+
const hide = message.loading(intl.formatMessage({id:'deleting'}));
41+
try {
42+
const result = await removeService(service);
43+
hide();
44+
const success = result.success;
45+
if (success) {
46+
message.success(intl.formatMessage({id:'delete_success'}));
47+
} else {
48+
message.error(intl.formatMessage({id:'delete_fail'}));
49+
}
50+
return success;
51+
} catch (error) {
52+
hide();
53+
message.error(intl.formatMessage({id:'delete_fail'}));
54+
return false;
55+
}
56+
};
3757

3858
const services: React.FC = () => {
3959
const actionRef = useRef<ActionType>();
@@ -114,7 +134,21 @@ const services: React.FC = () => {
114134
title: '操作',
115135
valueType: 'option',
116136
render: (text, record, _, action) => [
117-
<a className={styles.linkDanger}>
137+
<a className={styles.linkDanger}
138+
onClick={
139+
()=>{
140+
confirm({
141+
content:`确定删除选中的服务吗?`,
142+
onOk: async ()=>{
143+
const result = await handleDelSome(record)
144+
if (result) {
145+
actionRef.current?.reload();
146+
}
147+
}
148+
})
149+
}
150+
}
151+
>
118152
删除
119153
</a>
120154
]

AgileConfig.Server.UI/react-ui-antd/src/pages/Services/service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@ export async function addService(service: ServiceItem) {
3333
...service
3434
}
3535
});
36+
}
37+
38+
export async function removeService(service: ServiceItem) {
39+
return request('/service/remove', {
40+
method: 'POST',
41+
params:{
42+
id: service.id
43+
}
44+
});
3645
}

0 commit comments

Comments
 (0)