Merge branch 'feature_multi_tenant' into feature_naming_ap

# Conflicts:
#	naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/simpleraft/RaftCore.java
#	naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/simpleraft/RaftStore.java
#	naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java
#	naming/src/main/java/com/alibaba/nacos/naming/core/VirtualClusterDomain.java
#	naming/src/main/java/com/alibaba/nacos/naming/misc/Switch.java
#	naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchDomain.java
#	naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java
This commit is contained in:
nkorange 2019-01-16 18:12:54 +08:00
commit 980e2a62ef
16 changed files with 2119 additions and 1870 deletions

View File

@ -83,6 +83,7 @@ class NameSpaceList extends React.Component {
切换namespace 切换namespace
* */ * */
changeNameSpace(ns, nsName) { changeNameSpace(ns, nsName) {
localStorage.setItem('namespace', ns);
this.setnamespace(ns || ''); this.setnamespace(ns || '');
setParams({ setParams({
namespace: ns || '', namespace: ns || '',
@ -140,6 +141,7 @@ class NameSpaceList extends React.Component {
} }
window.namespaceShowName = namespaceShowName; window.namespaceShowName = namespaceShowName;
setParams('namespace', nownamespace || ''); setParams('namespace', nownamespace || '');
localStorage.setItem('namespace', nownamespace);
// setParams('namespaceShowName', namespaceShowName); // setParams('namespaceShowName', namespaceShowName);
this.props.setNowNameSpace && this.props.setNowNameSpace(namespaceShowName, nownamespace); this.props.setNowNameSpace && this.props.setNowNameSpace(namespaceShowName, nownamespace);
this.setState({ this.setState({
@ -191,8 +193,8 @@ class NameSpaceList extends React.Component {
return ( return (
<div <div
className={namespaceList.length > 0 ? 'namespacewrapper' : ''} className={namespaceList.length ? 'namespacewrapper' : ''}
style={namespaceList.length > 0 ? namespacestyle : {}} style={namespaceList.length ? namespacestyle : {}}
> >
{} {}
{title ? ( {title ? (

View File

@ -217,6 +217,7 @@ const aliwareIntl = (function(_global) {
this.nowData = nowData; this.nowData = nowData;
this.setMomentLocale(this.currentLanguageCode); this.setMomentLocale(this.currentLanguageCode);
} }
let aliwareLocal = aliwareGetCookieByKeyName('aliyun_lang') || 'zh'; let aliwareLocal = aliwareGetCookieByKeyName('aliyun_lang') || 'zh';
let aliwareLocalSite = aliwareGetCookieByKeyName('aliyun_country') || 'cn'; let aliwareLocalSite = aliwareGetCookieByKeyName('aliyun_country') || 'cn';
aliwareLocal = aliwareLocal.toLowerCase(); aliwareLocal = aliwareLocal.toLowerCase();
@ -473,6 +474,7 @@ const request = (function(_global) {
return serviceObj; return serviceObj;
}; };
})(); })();
/** /**
* 添加中间件函数 * 添加中间件函数
* @param {*function} callback 回调函数 * @param {*function} callback 回调函数
@ -485,6 +487,7 @@ const request = (function(_global) {
} }
return this; return this;
} }
/** /**
* 处理中间件 * 处理中间件
* @param {*Object} config ajax请求配置信息 * @param {*Object} config ajax请求配置信息
@ -504,6 +507,7 @@ const request = (function(_global) {
} }
return config; return config;
} }
/** /**
* 处理自定义url * 处理自定义url
* @param {*Object} config ajax请求配置信息 * @param {*Object} config ajax请求配置信息
@ -594,6 +598,10 @@ const request = (function(_global) {
// 处理后置中间件 // 处理后置中间件
config = handleMiddleWare.apply(this, [config, ...args, middlewareBackList]); config = handleMiddleWare.apply(this, [config, ...args, middlewareBackList]);
const namespace = localStorage.getItem('namespace') ? localStorage.getItem('namespace') : '';
const namespaceConf = { namespaceId: namespace };
config.data = config.data ? Object.assign({}, config.data, namespaceConf) : namespaceConf;
return $.ajax( return $.ajax(
Object.assign({}, config, { Object.assign({}, config, {
type: config.type, type: config.type,
@ -621,6 +629,7 @@ const request = (function(_global) {
} }
); );
} }
// 暴露方法 // 暴露方法
Request.handleCustomService = handleCustomService; Request.handleCustomService = handleCustomService;
Request.handleMiddleWare = handleMiddleWare; Request.handleMiddleWare = handleMiddleWare;

View File

@ -64,8 +64,8 @@ class EditClusterDialog extends React.Component {
healthChecker, healthChecker,
} = this.state.editCluster; } = this.state.editCluster;
request({ request({
method: 'POST', method: 'PUT',
url: 'v1/ns/cluster/update', url: 'v1/ns/cluster',
data: { data: {
serviceName, serviceName,
clusterName: name, clusterName: name,

View File

@ -58,8 +58,8 @@ class EditInstanceDialog extends React.Component {
const { serviceName, clusterName, getInstanceList, openLoading, closeLoading } = this.props; const { serviceName, clusterName, getInstanceList, openLoading, closeLoading } = this.props;
const { ip, port, weight, enabled, metadataText } = this.state.editInstance; const { ip, port, weight, enabled, metadataText } = this.state.editInstance;
request({ request({
method: 'POST', method: 'PUT',
url: 'v1/ns/instance/update', url: 'v1/ns/instance',
data: { serviceName, clusterName, ip, port, weight, enable: enabled, metadata: metadataText }, data: { serviceName, clusterName, ip, port, weight, enable: enabled, metadata: metadataText },
dataType: 'text', dataType: 'text',
beforeSend: () => openLoading(), beforeSend: () => openLoading(),

View File

@ -57,7 +57,7 @@ class EditServiceDialog extends React.Component {
const editService = Object.assign({}, this.state.editService); const editService = Object.assign({}, this.state.editService);
const { name, protectThreshold, healthCheckMode, metadataText, selector } = editService; const { name, protectThreshold, healthCheckMode, metadataText, selector } = editService;
request({ request({
method: isCreate ? 'PUT' : 'POST', method: isCreate ? 'POST' : 'PUT',
url: 'v1/ns/service', url: 'v1/ns/service',
data: { data: {
serviceName: name, serviceName: name,

View File

@ -80,8 +80,8 @@ class InstanceTable extends React.Component {
const newVal = Object.assign({}, instance); const newVal = Object.assign({}, instance);
newVal.list[index].enabled = !enabled; newVal.list[index].enabled = !enabled;
request({ request({
method: 'POST', method: 'PUT',
url: 'v1/ns/instance/update', url: 'v1/ns/instance',
data: { data: {
serviceName, serviceName,
clusterName, clusterName,

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -50,6 +50,10 @@ public class WebUtils {
String value = req.getParameter(key); String value = req.getParameter(key);
if (StringUtils.isBlank(value)) {
return defaultValue;
}
String encoding = req.getParameter("encoding"); String encoding = req.getParameter("encoding");
if (!StringUtils.isEmpty(encoding)) { if (!StringUtils.isEmpty(encoding)) {
try { try {

View File

@ -305,7 +305,7 @@ public class RaftCore {
local.resetLeaderDue(); local.resetLeaderDue();
// do apply // do apply
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID) || UtilsAndCommons.INSTANCE_LIST_PERSISTED) { if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE) || UtilsAndCommons.INSTANCE_LIST_PERSISTED) {
RaftStore.write(datum); RaftStore.write(datum);
} }
@ -352,7 +352,7 @@ public class RaftCore {
String key = datum.key; String key = datum.key;
deleteDatum(key); deleteDatum(key);
if (key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID)) { if (key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
if (local.term.get() + PUBLISH_TERM_INCREASE_COUNT > source.term.get()) { if (local.term.get() + PUBLISH_TERM_INCREASE_COUNT > source.term.get()) {
//set leader term: //set leader term:
@ -511,8 +511,8 @@ public class RaftCore {
JSONObject element = new JSONObject(); JSONObject element = new JSONObject();
String key; String key;
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID)) { if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
key = (datum.key).split(UtilsAndCommons.DOMAINS_DATA_ID)[1]; key = (datum.key).split(UtilsAndCommons.DOMAINS_DATA_ID_PRE)[1];
element.put("key", UtilsAndCommons.RAFT_DOM_PRE + key); element.put("key", UtilsAndCommons.RAFT_DOM_PRE + key);
} else if (datum.key.startsWith(UtilsAndCommons.IPADDRESS_DATA_ID_PRE)) { } else if (datum.key.startsWith(UtilsAndCommons.IPADDRESS_DATA_ID_PRE)) {
key = (datum.key).split(UtilsAndCommons.IPADDRESS_DATA_ID_PRE)[1]; key = (datum.key).split(UtilsAndCommons.IPADDRESS_DATA_ID_PRE)[1];
@ -641,7 +641,7 @@ public class RaftCore {
if (key.startsWith(UtilsAndCommons.RAFT_DOM_PRE)) { if (key.startsWith(UtilsAndCommons.RAFT_DOM_PRE)) {
int index = key.indexOf(UtilsAndCommons.RAFT_DOM_PRE); int index = key.indexOf(UtilsAndCommons.RAFT_DOM_PRE);
datumKey = UtilsAndCommons.DOMAINS_DATA_ID + key.substring(index + UtilsAndCommons.RAFT_DOM_PRE.length()); datumKey = UtilsAndCommons.DOMAINS_DATA_ID_PRE + key.substring(index + UtilsAndCommons.RAFT_DOM_PRE.length());
} else if (key.startsWith(UtilsAndCommons.RAFT_IPLIST_PRE)) { } else if (key.startsWith(UtilsAndCommons.RAFT_IPLIST_PRE)) {
int index = key.indexOf(UtilsAndCommons.RAFT_IPLIST_PRE); int index = key.indexOf(UtilsAndCommons.RAFT_IPLIST_PRE);
datumKey = UtilsAndCommons.IPADDRESS_DATA_ID_PRE + key.substring(index + UtilsAndCommons.RAFT_IPLIST_PRE.length()); datumKey = UtilsAndCommons.IPADDRESS_DATA_ID_PRE + key.substring(index + UtilsAndCommons.RAFT_IPLIST_PRE.length());
@ -703,7 +703,7 @@ public class RaftCore {
continue; continue;
} }
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID) || if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE) ||
UtilsAndCommons.INSTANCE_LIST_PERSISTED) { UtilsAndCommons.INSTANCE_LIST_PERSISTED) {
RaftStore.write(datum); RaftStore.write(datum);
} }
@ -711,7 +711,7 @@ public class RaftCore {
datums.put(datum.key, datum); datums.put(datum.key, datum);
local.resetLeaderDue(); local.resetLeaderDue();
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID)) { if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
if (local.term.get() + 100 > remote.term.get()) { if (local.term.get() + 100 > remote.term.get()) {
getLeader().term.set(remote.term.get()); getLeader().term.set(remote.term.get());
local.term.set(getLeader().term.get()); local.term.set(getLeader().term.get());
@ -902,10 +902,8 @@ public class RaftCore {
private void deleteDatum(String key) { private void deleteDatum(String key) {
Datum deleted = datums.remove(key); Datum deleted = datums.remove(key);
if (deleted != null) { if (deleted != null) {
if (key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID)) {
RaftStore.delete(deleted); RaftStore.delete(deleted);
} notifier.addTask(deleted, Notifier.ApplyAction.DELETE);
notifier.addTask(deleted, ApplyAction.DELETE);
Loggers.RAFT.info("datum deleted, key: {}", key); Loggers.RAFT.info("datum deleted, key: {}", key);
} }
} }

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.naming.consistency.persistent.simpleraft; package com.alibaba.nacos.naming.consistency.persistent.simpleraft;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.monitor.MetricsMonitor; import com.alibaba.nacos.naming.monitor.MetricsMonitor;
@ -129,7 +130,28 @@ public class RaftStore {
return null; return null;
} }
return JSON.parseObject(json, Datum.class); Datum datum = JSON.parseObject(json, Datum.class);
if (StringUtils.isBlank(namespaceId)) {
namespaceId = Constants.REQUEST_PARAM_DEFAULT_NAMESPACE_ID;
}
if (!datum.key.contains(UtilsAndCommons.SWITCH_DOMAIN_NAME) && !datum.key.contains(namespaceId)) {
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
datum.key = UtilsAndCommons.DOMAINS_DATA_ID_PRE + namespaceId +
UtilsAndCommons.SERVICE_GROUP_CONNECTOR +
datum.key.substring(UtilsAndCommons.DOMAINS_DATA_ID_PRE.length());
}
if (datum.key.startsWith(UtilsAndCommons.IPADDRESS_DATA_ID_PRE)) {
datum.key = UtilsAndCommons.IPADDRESS_DATA_ID_PRE + namespaceId +
UtilsAndCommons.SERVICE_GROUP_CONNECTOR +
datum.key.substring(UtilsAndCommons.IPADDRESS_DATA_ID_PRE.length());
}
}
RaftCore.addDatum(datum);
} catch (Exception e) { } catch (Exception e) {
Loggers.RAFT.warn("waning: failed to deserialize key: {}", file.getName()); Loggers.RAFT.warn("waning: failed to deserialize key: {}", file.getName());
throw e; throw e;
@ -144,28 +166,35 @@ public class RaftStore {
String namespaceId = null; String namespaceId = null;
Datum writeDatum = new Datum(); if (datum.key.contains(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)) {
writeDatum.key = datum.key; String[] segments = datum.key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0].split("\\.");
writeDatum.value = datum.value;
writeDatum.timestamp.set(datum.timestamp.get());
if (writeDatum.key.contains(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)) {
String[] segments = writeDatum.key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0].split("\\.");
namespaceId = segments[segments.length - 1]; namespaceId = segments[segments.length - 1];
String newKey;
segments = writeDatum.key.split(namespaceId + UtilsAndCommons.SERVICE_GROUP_CONNECTOR);
newKey = segments[0] + segments[1];
writeDatum.key = newKey;
} }
File cacheFile; File cacheFile;
File oldCacheFile = null; File oldCacheFile = null;
if (StringUtils.isNotBlank(namespaceId)) { if (StringUtils.isNotBlank(namespaceId)) {
cacheFile = new File(CACHE_DIR + File.separator + namespaceId + File.separator + encodeFileName(writeDatum.key)); cacheFile = new File(CACHE_DIR + File.separator + namespaceId + File.separator + encodeFileName(datum.key));
} else { } else {
oldCacheFile = new File(CACHE_DIR + File.separator + encodeFileName(writeDatum.key)); cacheFile = new File(CACHE_DIR + File.separator + encodeFileName(datum.key));
cacheFile = new File(CACHE_DIR + File.separator + UtilsAndCommons.getDefaultNamespaceId() + File.separator + encodeFileName(writeDatum.key)); }
if (Constants.REQUEST_PARAM_DEFAULT_NAMESPACE_ID.equals(namespaceId)) {
// remove old format file:
String originDatumKey = null;
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
originDatumKey = UtilsAndCommons.DOMAINS_DATA_ID_PRE +
datum.key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1];
} else if (datum.key.startsWith(UtilsAndCommons.IPADDRESS_DATA_ID_PRE)) {
originDatumKey = UtilsAndCommons.IPADDRESS_DATA_ID_PRE +
datum.key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1];
}
oldCacheFile = new File(CACHE_DIR + File.separator + encodeFileName(originDatumKey));
if (oldCacheFile.exists() && !oldCacheFile.delete()) {
throw new IllegalStateException("remove old format file failed, key:" + originDatumKey);
}
} }
if (!cacheFile.exists() && !cacheFile.getParentFile().mkdirs() && !cacheFile.createNewFile()) { if (!cacheFile.exists() && !cacheFile.getParentFile().mkdirs() && !cacheFile.createNewFile()) {
@ -175,7 +204,7 @@ public class RaftStore {
} }
FileChannel fc = null; FileChannel fc = null;
ByteBuffer data = ByteBuffer.wrap(JSON.toJSONString(writeDatum).getBytes("UTF-8")); ByteBuffer data = ByteBuffer.wrap(JSON.toJSONString(datum).getBytes("UTF-8"));
try { try {
fc = new FileOutputStream(cacheFile, false).getChannel(); fc = new FileOutputStream(cacheFile, false).getChannel();
@ -206,13 +235,49 @@ public class RaftStore {
} }
public static void delete(Datum datum) { public static void delete(Datum datum) {
File cacheFile = new File(CACHE_DIR + File.separator + encodeFileName(datum.key));
if (!cacheFile.delete()) { if (datum.key.contains(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)) {
// datum key contains namespace info:
String namspaceId = null;
String originDatumKey = null;
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
namspaceId = datum.key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0]
.substring(UtilsAndCommons.DOMAINS_DATA_ID_PRE.length());
originDatumKey = UtilsAndCommons.DOMAINS_DATA_ID_PRE +
datum.key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1];
} else if (datum.key.startsWith(UtilsAndCommons.IPADDRESS_DATA_ID_PRE)) {
namspaceId = datum.key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0]
.substring(UtilsAndCommons.IPADDRESS_DATA_ID_PRE.length());
originDatumKey = UtilsAndCommons.IPADDRESS_DATA_ID_PRE +
datum.key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1];
}
if (StringUtils.isNotBlank(namspaceId)) {
if (namspaceId.equals(Constants.REQUEST_PARAM_DEFAULT_NAMESPACE_ID)) {
File cacheFile = new File(CACHE_DIR + File.separator + encodeFileName(originDatumKey));
if (cacheFile.exists() && !cacheFile.delete()) {
Loggers.RAFT.error("[RAFT-DELETE] failed to delete datum: {}, value: {}", datum.key, datum.value); Loggers.RAFT.error("[RAFT-DELETE] failed to delete datum: {}, value: {}", datum.key, datum.value);
throw new IllegalStateException("failed to delete datum: " + datum.key); throw new IllegalStateException("failed to delete datum: " + datum.key);
} }
} }
File cacheFile = new File(CACHE_DIR + File.separator + namspaceId + File.separator + encodeFileName(datum.key));
if (cacheFile.exists() && !cacheFile.delete()) {
Loggers.RAFT.error("[RAFT-DELETE] failed to delete datum: {}, value: {}", datum.key, datum.value);
throw new IllegalStateException("failed to delete datum: " + datum.key);
}
}
} else {
File cacheFile = new File(CACHE_DIR + File.separator + encodeFileName(datum.key));
if (cacheFile.exists() && !cacheFile.delete()) {
Loggers.RAFT.error("[RAFT-DELETE] failed to delete datum: {}, value: {}", datum.key, datum.value);
throw new IllegalStateException("failed to delete datum: " + datum.key);
}
}
}
public void updateTerm(long term) throws Exception { public void updateTerm(long term) throws Exception {
File file = new File(META_FILE_NAME); File file = new File(META_FILE_NAME);
if (!file.exists() && !file.getParentFile().mkdirs() && !file.createNewFile()) { if (!file.exists() && !file.getParentFile().mkdirs() && !file.createNewFile()) {

View File

@ -32,9 +32,9 @@ import java.util.concurrent.TimeUnit;
* @author nacos * @author nacos
*/ */
@Component @Component
public class SwitchDomain implements Domain, DataListener { public class SwitchDomain implements Domain, RaftListener {
public String name = "00-00---000-VIPSRV_SWITCH_DOMAIN-000---00-00"; public String name = UtilsAndCommons.SWITCH_DOMAIN_NAME;
public List<String> masters; public List<String> masters;
@ -235,12 +235,12 @@ public class SwitchDomain implements Domain, DataListener {
@Override @Override
public boolean interests(String key) { public boolean interests(String key) {
return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID + "." + name); return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE + name);
} }
@Override @Override
public boolean matchUnlistenKey(String key) { public boolean matchUnlistenKey(String key) {
return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID + "." + name); return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE + name);
} }
@Override @Override

View File

@ -60,7 +60,7 @@ public class UtilsAndCommons {
public static final String SUPER_TOKEN = "xy"; public static final String SUPER_TOKEN = "xy";
public static final String DOMAINS_DATA_ID = "com.alibaba.nacos.naming.domains.meta"; public static final String DOMAINS_DATA_ID_PRE = "com.alibaba.nacos.naming.domains.meta.";
public static final String IPADDRESS_DATA_ID_PRE = "com.alibaba.nacos.naming.iplist."; public static final String IPADDRESS_DATA_ID_PRE = "com.alibaba.nacos.naming.iplist.";
@ -82,7 +82,7 @@ public class UtilsAndCommons {
public static final int RAFT_PUBLISH_TIMEOUT = 5000; public static final int RAFT_PUBLISH_TIMEOUT = 5000;
static public final String RAFT_DOM_PRE = "meta"; static public final String RAFT_DOM_PRE = "meta.";
static public final String RAFT_IPLIST_PRE = "iplist."; static public final String RAFT_IPLIST_PRE = "iplist.";
static public final String RAFT_TAG_DOM_PRE = "tag.meta"; static public final String RAFT_TAG_DOM_PRE = "tag.meta";
static public final String RAFT_TAG_IPLIST_PRE = "tag.iplist."; static public final String RAFT_TAG_IPLIST_PRE = "tag.iplist.";
@ -228,10 +228,10 @@ public class UtilsAndCommons {
public static String getDomStoreKey(Domain dom) { public static String getDomStoreKey(Domain dom) {
if (dom instanceof VirtualClusterDomain) { if (dom instanceof VirtualClusterDomain) {
return UtilsAndCommons.DOMAINS_DATA_ID + "." + ((VirtualClusterDomain) dom).getNamespaceId() + return UtilsAndCommons.DOMAINS_DATA_ID_PRE + ((VirtualClusterDomain) dom).getNamespaceId() +
UtilsAndCommons.SERVICE_GROUP_CONNECTOR + dom.getName(); UtilsAndCommons.SERVICE_GROUP_CONNECTOR + dom.getName();
} }
return UtilsAndCommons.DOMAINS_DATA_ID + "." + dom.getName(); return UtilsAndCommons.DOMAINS_DATA_ID_PRE + dom.getName();
} }
public static Map<String, String> parseMetadata(String metadata) throws NacosException { public static Map<String, String> parseMetadata(String metadata) throws NacosException {

View File

@ -24,6 +24,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.naming.core.Cluster; import com.alibaba.nacos.naming.core.Cluster;
import com.alibaba.nacos.naming.core.DomainsManager;
import com.alibaba.nacos.naming.core.IpAddress; import com.alibaba.nacos.naming.core.IpAddress;
import com.alibaba.nacos.naming.core.ServiceManager; import com.alibaba.nacos.naming.core.ServiceManager;
import com.alibaba.nacos.naming.core.VirtualClusterDomain; import com.alibaba.nacos.naming.core.VirtualClusterDomain;

View File

@ -527,6 +527,177 @@ public class RestAPI_ITCase {
Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
} }
@Test
public void domServeStatus() throws Exception {
ResponseEntity<String> response = request("/nacos/v1/ns/api/domServeStatus",
Params.newParams()
.appendParam("dom", NamingBase.TEST_DOM_1)
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
Assert.assertTrue(json.getBooleanValue("success"));
Assert.assertTrue(json.getJSONObject("data").getJSONArray("ips").size() > 0);
}
/**
* @TCDescription : 根据serviceName创建服务
* @TestStep :
* @ExpectResult :
*/
@Test
public void createService() throws Exception {
String serviceName = NamingBase.randomDomainName();
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
namingServiceDelete(serviceName);
}
/**
* @TCDescription : 根据serviceName获取服务信息
* @TestStep :
* @ExpectResult :
*/
@Test
public void getService() throws Exception {
String serviceName = NamingBase.randomDomainName();
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
//get service
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
Assert.assertEquals(serviceName, json.getString("name"));
namingServiceDelete(serviceName);
}
/**
* @TCDescription : 获取服务list信息
* @TestStep :
* @ExpectResult :
*/
@Test
public void listService() throws Exception {
String serviceName = NamingBase.randomDomainName();
//get service
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service/list",
Params.newParams()
.appendParam("serviceName", serviceName)
.appendParam("pageNo", "1")
.appendParam("pageSize", "15")
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
int count = json.getIntValue("count");
Assert.assertTrue(count >= 0);
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service/list",
Params.newParams()
.appendParam("serviceName", serviceName)
.appendParam("pageNo", "1")
.appendParam("pageSize", "15")
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
json = JSON.parseObject(response.getBody());
Assert.assertEquals(count+1, json.getIntValue("count"));
namingServiceDelete(serviceName);
}
/**
* @TCDescription : 更新serviceName获取服务信息
* @TestStep :
* @ExpectResult :
*/
@Test
public void updateService() throws Exception {
String serviceName = NamingBase.randomDomainName();
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
//update service
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.appendParam("healthCheckMode", "server")
.appendParam("protectThreshold", "3")
.done(),
String.class,
HttpMethod.POST);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
//get service
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
System.out.println(json);
Assert.assertEquals(3.0f, json.getFloatValue("protectThreshold"), 0.0f);
namingServiceDelete(serviceName);
}
private void namingServiceDelete(String serviceName) {
//delete service
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.DELETE);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
}
private <T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz) { private <T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();

View File

@ -48,7 +48,7 @@ import static com.alibaba.nacos.test.naming.NamingBase.verifyInstanceList;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"}, @SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ServiceListTest { public class ServiceList_ITCase {
private NamingService naming; private NamingService naming;
@ -92,7 +92,6 @@ public class ServiceListTest {
Assert.assertTrue(verifyInstanceList(instances, naming.getAllInstances(serviceName))); Assert.assertTrue(verifyInstanceList(instances, naming.getAllInstances(serviceName)));
serviceInfoList = naming.getSubscribeServices(); serviceInfoList = naming.getSubscribeServices();
System.out.println("dfdfdfd = " + serviceInfoList);
Assert.assertEquals(count+1, serviceInfoList.size()); Assert.assertEquals(count+1, serviceInfoList.size());
} }
@ -126,6 +125,7 @@ public class ServiceListTest {
naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT, "c1"); naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT, "c2"); naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT, "c2");
TimeUnit.SECONDS.sleep(5);
Assert.assertEquals(count+1, serviceInfoList.size()); Assert.assertEquals(count+1, serviceInfoList.size());
} }