Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.dashboard.model;

import java.util.List;

public class ServiceConfigModel {
private List<String> providers;
private List<String> consumers;

public List<String> getProviders() {
return providers;
}

public void setProviders(List<String> providers) {
this.providers = providers;
}

public List<String> getConsumers() {
return consumers;
}

public void setConsumers(List<String> consumers) {
this.consumers = consumers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
import com.alipay.sofa.dashboard.domain.RpcProvider;
import com.alipay.sofa.dashboard.domain.RpcService;
import com.alipay.sofa.dashboard.model.ServiceAppModel;
import com.alipay.sofa.dashboard.model.ServiceConfigModel;
import com.alipay.sofa.dashboard.model.ServiceModel;
import com.alipay.sofa.dashboard.service.TelnetClient;
import com.alipay.sofa.rpc.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -50,6 +53,7 @@ public class ServiceManageController {

@Autowired
private RegistryDataCache registryDataCache;
public String dataId;

@GetMapping("/all-service")
public List<ServiceModel> queryServiceListByService(@RequestParam("query") String query) {
Expand Down Expand Up @@ -112,6 +116,7 @@ public List<Map<String, String>> queryServiceListByApp(@RequestParam("query") St
*/
@GetMapping("service-app")
public ServiceAppModel queryServiceByAppName(@RequestParam("appName") String appName) {
// System.out.println(appName);
List<String> providersData = new ArrayList<>();
List<String> consumersData = new ArrayList<>();
ServiceAppModel result = new ServiceAppModel();
Expand Down Expand Up @@ -159,7 +164,7 @@ private List<RpcConsumer> fetchConsumerData(String serviceName) {
*/
@GetMapping("query/providers")
public List<RpcProvider> queryServiceProviders(@RequestParam("dataid") String serviceName) {
String dataId = URLDecoder.decode(serviceName);
dataId = URLDecoder.decode(serviceName);
return fetchProviderData(dataId);
}

Expand All @@ -170,7 +175,7 @@ public List<RpcProvider> queryServiceProviders(@RequestParam("dataid") String se
*/
@GetMapping("query/consumers")
public List<RpcConsumer> queryServiceConsumers(@RequestParam("dataid") String serviceName) {
String dataId = URLDecoder.decode(serviceName);
dataId = URLDecoder.decode(serviceName);
return fetchConsumerData(dataId);
}

Expand All @@ -195,6 +200,39 @@ public List<ServiceModel> queryService(@RequestParam("serviceName") String servi
return data;
}

/**
* 查询配置信息
*
* @param address
* @return
* @throws UnsupportedEncodingException
*/
@GetMapping("query/config")
public ServiceConfigModel queryConfig(@RequestParam("address") String address) throws UnsupportedEncodingException {
String EMPTY_BUFFER = new String(new byte[0], 0, 0);
ServiceConfigModel result = new ServiceConfigModel();
List<String> providerConfig = new ArrayList<>();
List<String> consumerConfig = new ArrayList<>();
TelnetClient ws = new TelnetClient(address, 1234);
String str1 = ws.sendCommand("service "+dataId);
str1 = new String(str1.getBytes("ISO-8859-1"), "GBK");
String str2 = ws.sendCommand("list");
str2 = new String(str2.getBytes("ISO-8859-1"), "GBK");
providerConfig.add(str2);

String str3 = ws.sendCommand("reference "+dataId);
str3 = new String(str3.getBytes("ISO-8859-1"), "GBK");
String str4 = ws.sendCommand("list");
str4 = new String(str4.getBytes("ISO-8859-1"), "GBK");
consumerConfig.add(str4);

result.setProviders(providerConfig);
result.setConsumers(consumerConfig);
ws.disconnect();
return result;
}


/**
* 模型转换
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.alipay.sofa.dashboard.service;

import org.apache.commons.net.telnet.TelnetClient;

import java.io.*;
import java.net.SocketException;

public class TelnetClientTest {
private TelnetClient telnet = new TelnetClient("VT220");

InputStream in;
PrintStream out;

String prompt = "sofa-rpc>";

public TelnetClientTest(String ip, int port) {
try {
telnet.connect(ip, port);
in = telnet.getInputStream();
out = new PrintStream(telnet.getOutputStream());
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
* 登录
*
* @param user
* @param password
*/
public void login(String user, String password) {
readUntil("login:");
write(user);
readUntil("password:");
write(password);
readUntil(prompt + "");
}

/**
* 读取分析结果
*
* @param pattern
* @return
*/
public String readUntil(String pattern) {
try {
char lastChar = pattern.charAt(pattern.length() - 1);
StringBuffer sb = new StringBuffer();
char ch = (char) in.read();

while (true) {
sb.append(ch);
if (ch == lastChar) {
if (sb.toString().endsWith(pattern)) {
return sb.toString();
}
}
ch = (char) in.read();
// System.out.print(ch);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

/**
* 写操作
*
* @param value
*/
public void write(String value) {
try {
out.println(value);
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 向目标发送命令字符串
*
* @param command
* @return
*/
public String sendCommand(String command) {
try {
write(command);
return readUntil(prompt + "");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

/**
* 关闭连接
*/
public void disconnect() {
try {
telnet.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}

}
24 changes: 21 additions & 3 deletions sofa-dashboard-front/src/models/governance.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { queryAll, queryServiceByAppName, queryProviderDetails, queryConsumerDetails } from '../services/governance';

// eslint-disable-next-line no-unused-vars
import { queryAll, queryServiceByAppName, queryProviderDetails, queryConsumerDetails, queryConfigs } from '../services/governance';
const GovernanceModel = {
namespace: 'governance',
state: {
list: [],
providerListData: [],
consumerListData: [],
providerDetail: [],
consumerDetail: []
consumerDetail: [],
providerConfig: [],
consumerConfig: []
},
reducers: {
restate(state, action) {
Expand Down Expand Up @@ -38,6 +40,14 @@ const GovernanceModel = {
consumerDetail: action.payload,
}
},

restateForConfigs(state, action) {
return {
...state,
providerConfig: action.payload.providers,
consumerConfig: action.payload.consumers
}
},
},
effects: {
*fetch({ payload }, { call, put }) {
Expand Down Expand Up @@ -80,6 +90,14 @@ const GovernanceModel = {
payload: response,
});
},

*fetchConfigs({ payload }, { call, put }) {
const response = yield call(queryConfigs, payload);
yield put({
type: 'restateForConfigs',
payload: response,
});
},
},
};

Expand Down
64 changes: 61 additions & 3 deletions sofa-dashboard-front/src/pages/Governance/details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ const { Option } = Select;
const { Search } = Input;
const { TabPane } = Tabs;
@connect(({ governance }) => ({
list: governance.list,
providerListData: governance.providerListData || [],
consumerListData: governance.consumerListData || [],
providerDetail: governance.providerDetail,
consumerDetail: governance.consumerDetail
consumerDetail: governance.consumerDetail,
providerConfig: governance.providerConfig,
consumerConfig: governance.consumerConfig
}))
class ServiceDetails extends React.Component {

state = {
visible: false
};
componentDidMount() {
const { dispatch, location } = this.props;
const queryParams = location.query;
Expand All @@ -21,7 +28,27 @@ class ServiceDetails extends React.Component {
}
});
}


showDrawer = (address) => {
this.setState({
visible: true,
});

const { dispatch } = this.props;
dispatch({
type: 'governance/fetchConfigs',
payload: {
"address": address
}
});
};

onClose = () => {
this.setState({
visible: false,
});
};

render() {
const {dispatch, location } = this.props;
const queryParams = location.query;
Expand Down Expand Up @@ -53,6 +80,7 @@ class ServiceDetails extends React.Component {
title: 'IP',
dataIndex: 'address',
key: 'address',
render: address => <a onClick={() => this.showDrawer(address)}>{address}</a>,
},
{
title: '端口',
Expand All @@ -77,6 +105,7 @@ class ServiceDetails extends React.Component {
title: 'IP',
dataIndex: 'address',
key: 'address',
render: address => <a onClick={() => this.showDrawer(address)}>{address}</a>,
},
{
title: '端口',
Expand Down Expand Up @@ -113,6 +142,35 @@ class ServiceDetails extends React.Component {
</TabPane>
</Tabs>
</Card>

<Drawer
title="服务详情"
placement="right"
closable={false}
onClose={this.onClose}
visible={this.state.visible}
width={640}
>
<Card title="发布服务配置详细信息">
<List
size="small"
dataSource={this.props.providerConfig}
style={{ minHeight: 30 }}
renderItem={item => <List.Item>{item}</List.Item>}
/>
</Card>
<Card title="订阅服务配置详细信息" style={{ marginTop: 10 }}>
<List
size="small"
dataSource={this.props.consumerConfig}
style={{ minHeight: 30 }}
renderItem={item => <List.Item>{item}</List.Item>}
/>
</Card>


</Drawer>

</div>
);
}
Expand Down
Loading