Skip to content

Commit

Permalink
Merge pull request #4 from alibaba/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yanlinly authored Nov 5, 2018
2 parents db8e97b + 6d0eb73 commit 4956e20
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public void registerInstance(String serviceName, Instance instance) throws Nacos
beatInfo.setIp(instance.getIp());
beatInfo.setPort(instance.getPort());
beatInfo.setCluster(instance.getCluster().getName());
beatInfo.setWeight(instance.getWeight());
beatInfo.setMetadata(instance.getMetadata());

beatReactor.addBeatInfo(serviceName, beatInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@

import com.alibaba.fastjson.JSON;

import java.util.Map;

/**
* @author dungu.zpf
*/
public class BeatInfo {

private int port;
private String ip;
private double weight;
private String dom;
private String cluster;
private Map<String, String> metadata;

@Override
public String toString() {
Expand Down Expand Up @@ -63,4 +67,20 @@ public int getPort() {
public void setPort(int port) {
this.port = port;
}

public Map<String, String> getMetadata() {
return metadata;
}

public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
}

public double getWeight() {
return weight;
}

public void setWeight(double weight) {
this.weight = weight;
}
}
24 changes: 23 additions & 1 deletion client/src/test/java/com/alibaba/nacos/client/NamingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,38 @@
*/
package com.alibaba.nacos.client;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.junit.Ignore;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
* @author dungu.zpf
*/
public class NamingTest {

@Test
public void testServiceList() {
@Ignore
public void testServiceList() throws Exception {

NamingService namingService = NacosFactory.createNamingService("127.0.0.1:8848");

Instance instance = new Instance();
instance.setIp("1.1.1.1");
instance.setPort(80);
instance.setWeight(2);
Map<String, String> map = new HashMap<String, String>();
map.put("env", "prod");
map.put("version", "2.0");
instance.setMetadata(map);

namingService.registerInstance("dungu.test.1", instance);

Thread.sleep(1000000000L);
}


Expand Down
2 changes: 1 addition & 1 deletion console/src/main/resources/static/index.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion console/src/main/resources/static/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion console/src/main/resources/static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"husky": "^0.12.0",
"roadhog": "^2.0.0"
}
}
}
10 changes: 10 additions & 0 deletions console/src/main/resources/static/src/i18ndoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ module.exports = {
"com.alibaba.nacos.page.serviceManagement.table.column.health_status": "健康实例数",
"com.alibaba.nacos.page.serviceManagement.table.column.operation": "操作",
"com.alibaba.nacos.page.serviceManagement.detail": "详情",
"com.alibaba.nacos.page.serviceManagement.delete": "删除",
"com.alibaba.nacos.page.serviceManagement.prompt": "提示",
"com.alibaba.nacos.page.serviceManagement.prompt_delete": "确定要删除当前服务吗?",
"com.alibaba.nacos.page.serviceManagement.create": "创建服务",
"com.alibaba.nacos.page.serviceManagement.query": "查询",
"serviceManagement": "服务列表",
"com.alibaba.nacos.page.serviceDetail.service_details": "服务详情",
Expand All @@ -502,6 +506,7 @@ module.exports = {
"com.alibaba.nacos.page.serviceDetail.health_check_pattern.client": "客户端",
"com.alibaba.nacos.page.serviceDetail.health_check_pattern.none": "禁止",
"com.alibaba.nacos.page.serviceDetail.metadata": "元数据",
"com.alibaba.nacos.page.serviceDetail.create_service": "创建服务",
"com.alibaba.nacos.page.serviceDetail.update_service": "更新服务",
"com.alibaba.nacos.page.serviceDetail.cluster": "集群",
"com.alibaba.nacos.page.serviceDetail.edit_cluster": "集群配置",
Expand Down Expand Up @@ -1001,9 +1006,14 @@ module.exports = {
"com.alibaba.nacos.page.serviceManagement.table.column.health_status": "Healthy Instance Count",
"com.alibaba.nacos.page.serviceManagement.table.column.operation": "Operation",
"com.alibaba.nacos.page.serviceManagement.detail": "Details",
"com.alibaba.nacos.page.serviceManagement.delete": "Delete",
"com.alibaba.nacos.page.serviceManagement.prompt": "Confirm",
"com.alibaba.nacos.page.serviceManagement.prompt_delete": "Do you want to delete the service?",
"com.alibaba.nacos.page.serviceManagement.create": "Create Service",
"com.alibaba.nacos.page.serviceManagement.query": "Search",
"serviceManagement": "Service Management",
"com.alibaba.nacos.page.serviceDetail.service_details": "Service Details",
"com.alibaba.nacos.page.serviceDetail.create_service": "Create Service",
"com.alibaba.nacos.page.serviceDetail.edit_service": "Edit Service",
"com.alibaba.nacos.page.serviceDetail.back": "Back",
"com.alibaba.nacos.page.serviceDetail.service_name": "Service Name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
*/

import React from 'react';
import { request } from '../../../globalLib';
import { Dialog, Form, Input, Select, Message } from '@alifd/next';
import { I18N, DIALOG_FORM_LAYOUT } from './constant'
import {request} from '../../../globalLib';
import {Dialog, Form, Input, Select, Message} from '@alifd/next';
import {I18N, DIALOG_FORM_LAYOUT} from './constant'

const FormItem = Form.Item;
const Option = Select.Option
Expand All @@ -24,54 +24,61 @@ class EditServiceDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
isCreate: false,
editService: {},
editServiceDialogVisible: false
}
this.show = this.show.bind(this)
}

show(editService) {
const { metadata = {} } = editService
show(editService = {}) {
const {metadata = {}, name} = editService
if (Object.keys(metadata).length) {
editService.metadataText = Object.keys(metadata).map(k => `${k}=${metadata[k]}`).join(',')
}
this.setState({ editService, editServiceDialogVisible: true })
this.setState({editService, editServiceDialogVisible: true, isCreate: !name})
}

hide() {
this.setState({ editServiceDialogVisible: false })
this.setState({editServiceDialogVisible: false})
}

onConfirm() {
const {isCreate} = this.state
const editService = Object.assign({}, this.state.editService)
const { name, protectThreshold, healthCheckMode, metadataText } = editService
const {name, protectThreshold, healthCheckMode, metadataText} = editService
request({
method: 'POST',
url: '/nacos/v1/ns/service/update',
data: { serviceName: name, protectThreshold, healthCheckMode, metadata: metadataText },
method: isCreate ? 'PUT' : 'POST',
url: `/nacos/v1/ns/service/${isCreate ? 'create' : 'update'}`,
data: {serviceName: name, protectThreshold, healthCheckMode, metadata: metadataText},
dataType: 'text',
beforeSend: () => this.setState({ loading: true }),
beforeSend: () => this.setState({loading: true}),
success: res => {
if (res !== 'ok') {
Message.error(res)
return
}
this.props.getServiceDetail()
if (isCreate) {
this.props.queryServiceList()
} else {
this.props.getServiceDetail()
}
},
complete: () => this.setState({ loading: false })
error: res => Message.error(res.responseText || res.statusText),
complete: () => this.setState({loading: false})
})
this.hide()
}

onChangeCluster(changeVal) {
const { editService = {} } = this.state
const {editService = {}} = this.state
this.setState({
editService: Object.assign({}, editService, changeVal)
})
}

render() {
const { editService, editServiceDialogVisible } = this.state
const {isCreate, editService, editServiceDialogVisible} = this.state
const {
name,
protectThreshold,
Expand All @@ -81,28 +88,36 @@ class EditServiceDialog extends React.Component {
return (
<Dialog
className="service-detail-edit-dialog"
title={I18N.UPDATE_SERVICE}
title={isCreate ? I18N.CREATE_SERVICE : I18N.UPDATE_SERVICE}
visible={editServiceDialogVisible}
onOk={() => this.onConfirm()}
onCancel={() => this.hide()}
onClose={() => this.hide()}
>
<Form {...DIALOG_FORM_LAYOUT}>
<FormItem label={`${I18N.SERVICE_NAME}:`}>
<p>{name}</p>
{
!isCreate
? <p>{name}</p>
: <Input
className="in-text"
value={name}
onChange={name => this.onChangeCluster({name})}
/>
}
</FormItem>
<FormItem label={`${I18N.PROTECT_THRESHOLD}:`}>
<Input
className="in-text"
value={protectThreshold}
onChange={protectThreshold => this.onChangeCluster({ protectThreshold })}
onChange={protectThreshold => this.onChangeCluster({protectThreshold})}
/>
</FormItem>
<FormItem label={`${I18N.HEALTH_CHECK_PATTERN}:`}>
<Select
className="in-select"
defaultValue={healthCheckMode}
onChange={healthCheckMode => this.onChangeCluster({ healthCheckMode })}
onChange={healthCheckMode => this.onChangeCluster({healthCheckMode})}
>
<Option value="server">{I18N.HEALTH_CHECK_PATTERN_SERVICE}</Option>
<Option value="client">{I18N.HEALTH_CHECK_PATTERN_CLIENT}</Option>
Expand All @@ -113,7 +128,7 @@ class EditServiceDialog extends React.Component {
<Input
className="in-text"
value={metadataText}
onChange={metadataText => this.onChangeCluster({ metadataText })}
onChange={metadataText => this.onChangeCluster({metadataText})}
/>
</FormItem>
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ I18N.METADATA = getI18N('metadata')
* 更新服务
*/
I18N.UPDATE_SERVICE = getI18N('update_service')
/**
* 创建服务
*/
I18N.CREATE_SERVICE = getI18N('create_service')
/**
* 集群
*/
Expand Down
Loading

0 comments on commit 4956e20

Please sign in to comment.