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:
commit
980e2a62ef
@ -83,6 +83,7 @@ class NameSpaceList extends React.Component {
|
||||
切换namespace
|
||||
* */
|
||||
changeNameSpace(ns, nsName) {
|
||||
localStorage.setItem('namespace', ns);
|
||||
this.setnamespace(ns || '');
|
||||
setParams({
|
||||
namespace: ns || '',
|
||||
@ -140,6 +141,7 @@ class NameSpaceList extends React.Component {
|
||||
}
|
||||
window.namespaceShowName = namespaceShowName;
|
||||
setParams('namespace', nownamespace || '');
|
||||
localStorage.setItem('namespace', nownamespace);
|
||||
// setParams('namespaceShowName', namespaceShowName);
|
||||
this.props.setNowNameSpace && this.props.setNowNameSpace(namespaceShowName, nownamespace);
|
||||
this.setState({
|
||||
@ -191,8 +193,8 @@ class NameSpaceList extends React.Component {
|
||||
|
||||
return (
|
||||
<div
|
||||
className={namespaceList.length > 0 ? 'namespacewrapper' : ''}
|
||||
style={namespaceList.length > 0 ? namespacestyle : {}}
|
||||
className={namespaceList.length ? 'namespacewrapper' : ''}
|
||||
style={namespaceList.length ? namespacestyle : {}}
|
||||
>
|
||||
{}
|
||||
{title ? (
|
||||
|
@ -217,6 +217,7 @@ const aliwareIntl = (function(_global) {
|
||||
this.nowData = nowData;
|
||||
this.setMomentLocale(this.currentLanguageCode);
|
||||
}
|
||||
|
||||
let aliwareLocal = aliwareGetCookieByKeyName('aliyun_lang') || 'zh';
|
||||
let aliwareLocalSite = aliwareGetCookieByKeyName('aliyun_country') || 'cn';
|
||||
aliwareLocal = aliwareLocal.toLowerCase();
|
||||
@ -473,6 +474,7 @@ const request = (function(_global) {
|
||||
return serviceObj;
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* 添加中间件函数
|
||||
* @param {*function} callback 回调函数
|
||||
@ -485,6 +487,7 @@ const request = (function(_global) {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理中间件
|
||||
* @param {*Object} config ajax请求配置信息
|
||||
@ -504,6 +507,7 @@ const request = (function(_global) {
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理自定义url
|
||||
* @param {*Object} config ajax请求配置信息
|
||||
@ -594,6 +598,10 @@ const request = (function(_global) {
|
||||
// 处理后置中间件
|
||||
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(
|
||||
Object.assign({}, config, {
|
||||
type: config.type,
|
||||
@ -621,6 +629,7 @@ const request = (function(_global) {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 暴露方法
|
||||
Request.handleCustomService = handleCustomService;
|
||||
Request.handleMiddleWare = handleMiddleWare;
|
||||
|
@ -64,8 +64,8 @@ class EditClusterDialog extends React.Component {
|
||||
healthChecker,
|
||||
} = this.state.editCluster;
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'v1/ns/cluster/update',
|
||||
method: 'PUT',
|
||||
url: 'v1/ns/cluster',
|
||||
data: {
|
||||
serviceName,
|
||||
clusterName: name,
|
||||
|
@ -58,8 +58,8 @@ class EditInstanceDialog extends React.Component {
|
||||
const { serviceName, clusterName, getInstanceList, openLoading, closeLoading } = this.props;
|
||||
const { ip, port, weight, enabled, metadataText } = this.state.editInstance;
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'v1/ns/instance/update',
|
||||
method: 'PUT',
|
||||
url: 'v1/ns/instance',
|
||||
data: { serviceName, clusterName, ip, port, weight, enable: enabled, metadata: metadataText },
|
||||
dataType: 'text',
|
||||
beforeSend: () => openLoading(),
|
||||
|
@ -57,7 +57,7 @@ class EditServiceDialog extends React.Component {
|
||||
const editService = Object.assign({}, this.state.editService);
|
||||
const { name, protectThreshold, healthCheckMode, metadataText, selector } = editService;
|
||||
request({
|
||||
method: isCreate ? 'PUT' : 'POST',
|
||||
method: isCreate ? 'POST' : 'PUT',
|
||||
url: 'v1/ns/service',
|
||||
data: {
|
||||
serviceName: name,
|
||||
|
@ -80,8 +80,8 @@ class InstanceTable extends React.Component {
|
||||
const newVal = Object.assign({}, instance);
|
||||
newVal.list[index].enabled = !enabled;
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'v1/ns/instance/update',
|
||||
method: 'PUT',
|
||||
url: 'v1/ns/instance',
|
||||
data: {
|
||||
serviceName,
|
||||
clusterName,
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -50,6 +50,10 @@ public class WebUtils {
|
||||
|
||||
String value = req.getParameter(key);
|
||||
|
||||
if (StringUtils.isBlank(value)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
String encoding = req.getParameter("encoding");
|
||||
if (!StringUtils.isEmpty(encoding)) {
|
||||
try {
|
||||
|
@ -305,7 +305,7 @@ public class RaftCore {
|
||||
local.resetLeaderDue();
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -352,7 +352,7 @@ public class RaftCore {
|
||||
String key = datum.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()) {
|
||||
//set leader term:
|
||||
@ -511,8 +511,8 @@ public class RaftCore {
|
||||
JSONObject element = new JSONObject();
|
||||
String key;
|
||||
|
||||
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID)) {
|
||||
key = (datum.key).split(UtilsAndCommons.DOMAINS_DATA_ID)[1];
|
||||
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
|
||||
key = (datum.key).split(UtilsAndCommons.DOMAINS_DATA_ID_PRE)[1];
|
||||
element.put("key", UtilsAndCommons.RAFT_DOM_PRE + key);
|
||||
} else if (datum.key.startsWith(UtilsAndCommons.IPADDRESS_DATA_ID_PRE)) {
|
||||
key = (datum.key).split(UtilsAndCommons.IPADDRESS_DATA_ID_PRE)[1];
|
||||
@ -641,7 +641,7 @@ public class RaftCore {
|
||||
|
||||
if (key.startsWith(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)) {
|
||||
int index = key.indexOf(UtilsAndCommons.RAFT_IPLIST_PRE);
|
||||
datumKey = UtilsAndCommons.IPADDRESS_DATA_ID_PRE + key.substring(index + UtilsAndCommons.RAFT_IPLIST_PRE.length());
|
||||
@ -703,7 +703,7 @@ public class RaftCore {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID) ||
|
||||
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE) ||
|
||||
UtilsAndCommons.INSTANCE_LIST_PERSISTED) {
|
||||
RaftStore.write(datum);
|
||||
}
|
||||
@ -711,7 +711,7 @@ public class RaftCore {
|
||||
datums.put(datum.key, datum);
|
||||
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()) {
|
||||
getLeader().term.set(remote.term.get());
|
||||
local.term.set(getLeader().term.get());
|
||||
@ -902,10 +902,8 @@ public class RaftCore {
|
||||
private void deleteDatum(String key) {
|
||||
Datum deleted = datums.remove(key);
|
||||
if (deleted != null) {
|
||||
if (key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID)) {
|
||||
RaftStore.delete(deleted);
|
||||
}
|
||||
notifier.addTask(deleted, ApplyAction.DELETE);
|
||||
notifier.addTask(deleted, Notifier.ApplyAction.DELETE);
|
||||
Loggers.RAFT.info("datum deleted, key: {}", key);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.alibaba.nacos.naming.consistency.persistent.simpleraft;
|
||||
|
||||
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.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.monitor.MetricsMonitor;
|
||||
@ -129,7 +130,28 @@ public class RaftStore {
|
||||
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) {
|
||||
Loggers.RAFT.warn("waning: failed to deserialize key: {}", file.getName());
|
||||
throw e;
|
||||
@ -144,28 +166,35 @@ public class RaftStore {
|
||||
|
||||
String namespaceId = null;
|
||||
|
||||
Datum writeDatum = new Datum();
|
||||
writeDatum.key = datum.key;
|
||||
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("\\.");
|
||||
if (datum.key.contains(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)) {
|
||||
String[] segments = datum.key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0].split("\\.");
|
||||
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 oldCacheFile = null;
|
||||
|
||||
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 {
|
||||
oldCacheFile = new File(CACHE_DIR + File.separator + encodeFileName(writeDatum.key));
|
||||
cacheFile = new File(CACHE_DIR + File.separator + UtilsAndCommons.getDefaultNamespaceId() + File.separator + encodeFileName(writeDatum.key));
|
||||
cacheFile = new File(CACHE_DIR + File.separator + encodeFileName(datum.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()) {
|
||||
@ -175,7 +204,7 @@ public class RaftStore {
|
||||
}
|
||||
|
||||
FileChannel fc = null;
|
||||
ByteBuffer data = ByteBuffer.wrap(JSON.toJSONString(writeDatum).getBytes("UTF-8"));
|
||||
ByteBuffer data = ByteBuffer.wrap(JSON.toJSONString(datum).getBytes("UTF-8"));
|
||||
|
||||
try {
|
||||
fc = new FileOutputStream(cacheFile, false).getChannel();
|
||||
@ -206,13 +235,49 @@ public class RaftStore {
|
||||
}
|
||||
|
||||
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);
|
||||
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 {
|
||||
File file = new File(META_FILE_NAME);
|
||||
if (!file.exists() && !file.getParentFile().mkdirs() && !file.createNewFile()) {
|
||||
|
@ -32,9 +32,9 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author nacos
|
||||
*/
|
||||
@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;
|
||||
|
||||
@ -235,12 +235,12 @@ public class SwitchDomain implements Domain, DataListener {
|
||||
|
||||
@Override
|
||||
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
|
||||
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
|
||||
|
@ -60,7 +60,7 @@ public class UtilsAndCommons {
|
||||
|
||||
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.";
|
||||
|
||||
@ -82,7 +82,7 @@ public class UtilsAndCommons {
|
||||
|
||||
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_TAG_DOM_PRE = "tag.meta";
|
||||
static public final String RAFT_TAG_IPLIST_PRE = "tag.iplist.";
|
||||
@ -228,10 +228,10 @@ public class UtilsAndCommons {
|
||||
|
||||
public static String getDomStoreKey(Domain dom) {
|
||||
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();
|
||||
}
|
||||
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 {
|
||||
|
@ -24,6 +24,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.ServiceManager;
|
||||
import com.alibaba.nacos.naming.core.VirtualClusterDomain;
|
||||
|
@ -527,6 +527,177 @@ public class RestAPI_ITCase {
|
||||
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) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
@ -48,7 +48,7 @@ import static com.alibaba.nacos.test.naming.NamingBase.verifyInstanceList;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class ServiceListTest {
|
||||
public class ServiceList_ITCase {
|
||||
|
||||
private NamingService naming;
|
||||
|
||||
@ -92,7 +92,6 @@ public class ServiceListTest {
|
||||
Assert.assertTrue(verifyInstanceList(instances, naming.getAllInstances(serviceName)));
|
||||
serviceInfoList = naming.getSubscribeServices();
|
||||
|
||||
System.out.println("dfdfdfd = " + serviceInfoList);
|
||||
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, "c2");
|
||||
TimeUnit.SECONDS.sleep(5);
|
||||
|
||||
Assert.assertEquals(count+1, serviceInfoList.size());
|
||||
}
|
Loading…
Reference in New Issue
Block a user