Skip to content

Commit

Permalink
Merge branch 'master-2.x-local-dev' into 'master-2.x'
Browse files Browse the repository at this point in the history
Master 2.x local dev

See merge request changming.xie/tcc-transaction!4
  • Loading branch information
changming.xie committed Apr 12, 2024
2 parents f69a1c2 + de62ec1 commit 17d619b
Show file tree
Hide file tree
Showing 44 changed files with 994 additions and 146 deletions.
2 changes: 2 additions & 0 deletions tcc-transaction-admin-web/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Welcome from './pages/tcc/welcome/index';
import Domain from './pages/tcc/domain/index';
import Transaction from './pages/tcc/transaction/index';
import Task from "./pages/tcc/task/index";
import Registry from "./pages/tcc/registry/index";

import store from './store';
import TccLayout from "./layout/TccLayout";
Expand All @@ -25,6 +26,7 @@ function App(props) {
<Route path="/domain" component={Domain}></Route>
<Route path="/transaction" component={Transaction}></Route>
<Route path="/task" component={Task}></Route>
<Route path="/registry" component={Registry}></Route>
</>
}>
</TccLayout>
Expand Down
19 changes: 19 additions & 0 deletions tcc-transaction-admin-web/src/common/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ export function taskModifyCron(params) {
});
}

export function registryQueryStatus(){
return http.get("/tcc-transaction-dashboard/api/registry/queryStatus")
}

export function registryOnline(ip, port) {
return http.post("/tcc-transaction-dashboard/api/registry/online",
{
ip: ip,
port: port
});
}

export function registryOffline(ip, port) {
return http.post("/tcc-transaction-dashboard/api/registry/offline",
{
ip: ip,
port: port
});
}

export function userLogin(params) {
return http.post("/tcc-transaction-dashboard/api/user/login", {
Expand Down
11 changes: 8 additions & 3 deletions tcc-transaction-admin-web/src/layout/TccLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ const Page = (props) => {
</Menu.Item>
{
isServerMode ?
<Menu.Item key='task'>
<Link to="/task">任务管理</Link>
</Menu.Item>
<>
<Menu.Item key='task'>
<Link to="/task">任务管理</Link>
</Menu.Item>
<Menu.Item key='registry'>
<Link to="/registry">Server管理</Link>
</Menu.Item>
</>
:
<></>
}
Expand Down
114 changes: 114 additions & 0 deletions tcc-transaction-admin-web/src/pages/tcc/registry/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React, {useEffect, useState} from 'react';
import {registryOnline, registryOffline, registryQueryStatus} from "../../../common/api";
import {Button, Col, Popconfirm, Row, Space, Table} from "antd";

const Page = () => {
const [registryStatusList, setRegistryStatusList] = useState([]);
const [loadingStatus, setLoadingStatus] = useState(false); //加载数据

useEffect(() => {
reloadRegistryStatus(0);
}, []);

const reloadRegistryStatus = (delay) => {
setLoadingStatus(true)
setTimeout(() => {
registryQueryStatus().then(data => {
setLoadingStatus(false)
setRegistryStatusList(data)
}).catch((res) => {
setLoadingStatus(false)
})
}, delay);
};

const columns =[
{
title: '实例',
dataIndex: 'instance',
render:(text, record)=>{
return `${record.ip}:${record.port}`
}
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
render: (text, record) => {
switch (text) {
case 1:
return "已上线";
case 2:
return "已下线";
case 3:
return "未知";
default:
return text;
}
}
},
{
title: '操作',
key: 'operation',
render: (text,record)=>(
<Space>
{
record.status !== 1?
<Popconfirm
title="是否执行"
onConfirm={() => {
registryOnline(record.ip, record.port).then(resp => {
reloadRegistryStatus(3000)
})
}}
okText="是"
cancelText="否">
<Button size="small" type="primary" danger>上线</Button>
</Popconfirm>
: <></>
}
{
record.status !== 2?
<Popconfirm
title="警告:实例下线可能会降低整体服务的可用性,请谨慎操作!"
onConfirm={() => {
registryOffline(record.ip,record.port).then(resp => {
reloadRegistryStatus(3000)
})
}}
okText="确认下线"
cancelText="取消">
<Button size="small" type="primary" danger>下线</Button>
</Popconfirm>
: <></>
}
</Space>

)
},
]
return(
<div>
<Row style={{padding: '12px'}}>
<Col span={23}>
&nbsp;
</Col>
<Col span={1}>
<Button type="primary"
size="small"
onClick={() => reloadRegistryStatus(0)}
disabled={loadingStatus}>
刷新
</Button>
</Col>
</Row>
<Table rowKey={record => `${record.ip}:${record.port}`}
dataSource={registryStatusList}
columns={columns}
pagination={false}
loading={loadingStatus}/>
</div>
)
}

export default Page;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.mengyun.tcctransaction.discovery.registry.RegistryRole;
import org.mengyun.tcctransaction.discovery.registry.RegistryService;
import org.mengyun.tcctransaction.exception.SystemException;
import org.mengyun.tcctransaction.observe.ObservableCenter;
import org.mengyun.tcctransaction.processor.ClientRecoveryExecutor;
import org.mengyun.tcctransaction.processor.ClientRecoveryProcessor;
import org.mengyun.tcctransaction.recovery.RecoveryExecutor;
Expand Down Expand Up @@ -202,6 +203,8 @@ public void start() throws Exception {
@PreDestroy
public void shutdown() throws Exception {

ObservableCenter.INSTANCE.close();

if (this.clientConfig.getStorageType() == StorageType.REMOTING) {
this.remotingClient.shutdown();
this.remotingClient = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ public RecoveryExecutor getRecoveryExecutor() {
return recoveryExecutor;
}

public List<RegistryService> getRegistryServices() {
return registryServices;
}

public StatsManager getStatsManager() {
return statsManager;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.mengyun.tcctransaction.dashboard.dto;

/**
* @author Nervose.Wu
* @date 2024/2/19 11:23
*/
public class AddressDto {
private String ip;
private Integer port;

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public Integer getPort() {
return port;
}

public void setPort(Integer port) {
this.port = port;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.mengyun.tcctransaction.dashboard.dto;

/**
* @author Nervose.Wu
* @date 2024/2/19 10:49
*/
public class RegistryStatusDto {
private String ip;
private Integer port;
private Integer status;

public RegistryStatusDto(String ip, Integer port, Integer status) {
this.ip = ip;
this.port = port;
this.status = status;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public Integer getPort() {
return port;
}

public void setPort(Integer port) {
this.port = port;
}

public Integer getStatus() {
return status;
}

public void setStatus(Integer status) {
this.status = status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public enum ResponseCodeEnum {
TRANSACTION_DETAIL_NOT_EXIST(10501, "事件详情不存在"),
TRANSACTION_CONTENT_VISUALIZE_ERROR(10502, "事件详情解析异常"),
TRANSACTION_CONTENT_VISUALIZE_ERROR_WITH_MESSAGE(10502, "事件详情解析异常:%s"),
;

// server上下线相关
SERVER_ONLINE_ERROR(10600, "tcc-server上线失败"),
SERVER_OFFLINE_ERROR(10601, "tcc-server下线失败");

private int responseCode;
private String responseMessage;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.mengyun.tcctransaction.dashboard.service;

import org.mengyun.tcctransaction.dashboard.dto.RegistryStatusDto;
import org.mengyun.tcctransaction.dashboard.dto.ResponseDto;

import java.util.List;

/**
* @author Nervose.Wu
* @date 2024/2/19 10:56
*/
public interface ServerRegistryService {
ResponseDto<List<RegistryStatusDto>> queryStatus();

ResponseDto<Void> online(String ip, Integer port);

ResponseDto<Void> offline(String ip, Integer port);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.mengyun.tcctransaction.dashboard.service.impl;

import org.mengyun.tcctransaction.dashboard.dto.RegistryStatusDto;
import org.mengyun.tcctransaction.dashboard.dto.ResponseDto;
import org.mengyun.tcctransaction.dashboard.enums.ResponseCodeEnum;
import org.mengyun.tcctransaction.dashboard.exception.TransactionException;
import org.mengyun.tcctransaction.dashboard.service.ServerRegistryService;

import java.util.Collections;
import java.util.List;

/**
* @author Nervose.Wu
* @date 2024/2/19 10:59
*/
public class BaseServerRegistryServiceImpl implements ServerRegistryService {
@Override
public ResponseDto<List<RegistryStatusDto>> queryStatus() {
return ResponseDto.returnSuccess(Collections.emptyList());
}

@Override
public ResponseDto<Void> online(String ip, Integer port) {
throw new TransactionException(ResponseCodeEnum.NOT_SUPPORT);
}

@Override
public ResponseDto<Void> offline(String ip, Integer port) {
throw new TransactionException(ResponseCodeEnum.NOT_SUPPORT);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.mengyun.tcctransaction.discovery.registry;

import org.mengyun.tcctransaction.exception.RegistryException;
import org.mengyun.tcctransaction.observe.ObservableType;
import org.mengyun.tcctransaction.observe.ObservableCenter;

import java.net.InetSocketAddress;
import java.util.ArrayList;
Expand Down Expand Up @@ -63,6 +65,7 @@ protected void setServerAddresses(List<String> address, boolean addressForDashbo
this.serverAddressesForDashboard = address;
} else {
this.serverAddresses = address;
ObservableCenter.INSTANCE.publish(ObservableType.REGISTRY, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public interface RegistryService {

void register(InetSocketAddress address, InetSocketAddress addressForDashboard);

RegistryStatus queryServerRegistryStatus();

void serverOnline();

void serverOffline();

void subscribe(boolean addressForDashboard);

List<String> lookup(boolean addressForDashboard);
Expand Down
Loading

0 comments on commit 17d619b

Please sign in to comment.