Skip to content

Commit

Permalink
add remove action
Browse files Browse the repository at this point in the history
  • Loading branch information
kklldog committed Apr 5, 2022
1 parent 30d0afe commit d889350
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 7 deletions.
35 changes: 34 additions & 1 deletion AgileConfig.Server.Apisite/Controllers/ServiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,40 @@ public async Task<IActionResult> Add([FromBody] ServiceInfoVM model)
success = true
});
}


[HttpPost]
public async Task<IActionResult> 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<IActionResult> Search(string serviceName, string serviceId, ServiceStatus? status,
string sortField, string ascOrDesc,
int current = 1, int pageSize = 20)
Expand Down
33 changes: 30 additions & 3 deletions AgileConfig.Server.Service/RemoteServerNodeProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,20 @@ public async Task<bool> 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 ? "成功" : "失败")}"
});
}

Expand Down Expand Up @@ -114,12 +123,21 @@ public async Task<bool> 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 ? "成功" : "失败")}"
});
}

Expand Down Expand Up @@ -164,11 +182,20 @@ public async Task<bool> 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 ? "成功" : "失败")}"
});
}

Expand Down
40 changes: 37 additions & 3 deletions AgileConfig.Server.UI/react-ui-antd/src/pages/Services/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -34,6 +35,25 @@ const handleAdd = async (fields: ServiceItem) => {
return false;
}
};
const handleDelSome = async (service: ServiceItem):Promise<boolean> => {
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<ActionType>();
Expand Down Expand Up @@ -114,7 +134,21 @@ const services: React.FC = () => {
title: '操作',
valueType: 'option',
render: (text, record, _, action) => [
<a className={styles.linkDanger}>
<a className={styles.linkDanger}
onClick={
()=>{
confirm({
content:`确定删除选中的服务吗?`,
onOk: async ()=>{
const result = await handleDelSome(record)
if (result) {
actionRef.current?.reload();
}
}
})
}
}
>
删除
</a>
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
}

0 comments on commit d889350

Please sign in to comment.