Merge pull request #628 from alibaba/feature_multi_tenant

Feature multi tenant
This commit is contained in:
Fury Zhu 2019-01-16 15:08:55 +08:00 committed by GitHub
commit 07d92f6174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 1946 additions and 1875 deletions

View File

@ -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 ? (

View File

@ -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;

View File

@ -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,

View File

@ -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(),

View File

@ -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,

View File

@ -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

View File

@ -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 {

View File

@ -27,7 +27,6 @@ import com.alibaba.nacos.naming.exception.NacosException;
import com.alibaba.nacos.naming.healthcheck.HealthCheckMode;
import com.alibaba.nacos.naming.misc.Switch;
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.raft.RaftCore;
import com.alibaba.nacos.naming.selector.LabelSelector;
import com.alibaba.nacos.naming.selector.NoneSelector;
import com.alibaba.nacos.naming.selector.Selector;
@ -144,9 +143,6 @@ public class ServiceController {
res.put("selector", domain.getSelector());
res.put("instanceTimestamp", RaftCore.getDatum(UtilsAndCommons.getIPListStoreKey(domain)).timestamp.get());
res.put("serviceTimestamp", RaftCore.getDatum(UtilsAndCommons.getDomStoreKey(domain)).timestamp.get());
return res;
}

View File

@ -606,12 +606,12 @@ public class DomainsManager {
final RaftListener raftListener = new RaftListener() {
@Override
public boolean interests(String key) {
return StringUtils.startsWith(key, UtilsAndCommons.DOMAINS_DATA_ID);
return StringUtils.startsWith(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE);
}
@Override
public boolean matchUnlistenKey(String key) {
return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID + ".*");
return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE + "*");
}
@SuppressFBWarnings("JLM_JSR166_LOCK_MONITORENTER")
@ -656,7 +656,7 @@ public class DomainsManager {
@Override
public void onDelete(String key, String value) throws Exception {
String domKey = StringUtils.removeStart(key, UtilsAndCommons.DOMAINS_DATA_ID + ".");
String domKey = StringUtils.removeStart(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE);
String namespace = domKey.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0];
String name = domKey.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1];
Domain dom = chooseDomMap(namespace).remove(name);

View File

@ -18,7 +18,6 @@ package com.alibaba.nacos.naming.core;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.naming.healthcheck.ClientBeatCheckTask;
import com.alibaba.nacos.naming.healthcheck.ClientBeatProcessor;
import com.alibaba.nacos.naming.healthcheck.HealthCheckReactor;
@ -29,8 +28,8 @@ import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.push.PushService;
import com.alibaba.nacos.naming.raft.RaftCore;
import com.alibaba.nacos.naming.raft.RaftListener;
import com.alibaba.nacos.naming.selector.Selector;
import com.alibaba.nacos.naming.selector.NoneSelector;
import com.alibaba.nacos.naming.selector.Selector;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.lang3.RandomStringUtils;

View File

@ -24,11 +24,9 @@ import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.*;
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@ -36,7 +34,6 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HttpContext;
import java.io.IOException;
import java.io.InputStream;

View File

@ -48,12 +48,12 @@ public class Switch {
RaftCore.listen(new RaftListener() {
@Override
public boolean interests(String key) {
return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID + ".00-00---000-VIPSRV_SWITCH_DOMAIN-000---00-00");
return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE + UtilsAndCommons.SWITCH_DOMAIN_NAME);
}
@Override
public boolean matchUnlistenKey(String key) {
return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID + ".00-00---000-VIPSRV_SWITCH_DOMAIN-000---00-00");
return StringUtils.equals(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE + UtilsAndCommons.SWITCH_DOMAIN_NAME);
}
@Override

View File

@ -31,7 +31,8 @@ import java.util.concurrent.TimeUnit;
* @author nacos
*/
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;
@ -236,12 +237,12 @@ public class SwitchDomain implements Domain, RaftListener {
@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

View File

@ -20,7 +20,6 @@ import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
import com.alibaba.nacos.naming.core.Domain;
import com.alibaba.nacos.naming.core.VirtualClusterDomain;
@ -61,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.";
@ -69,6 +68,8 @@ public class UtilsAndCommons {
public static final String TAG_DOMAINS_DATA_ID = "com.alibaba.nacos.naming.domains.tag.meta";
public static final String SWITCH_DOMAIN_NAME = "00-00---000-VIPSRV_SWITCH_DOMAIN-000---00-00";
static public final String CIDR_REGEX = "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/[0-9]+";
static public final String UNKNOWN_SITE = "unknown";
@ -79,7 +80,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.";
@ -225,10 +226,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 {

View File

@ -25,7 +25,6 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

View File

@ -15,7 +15,10 @@
*/
package com.alibaba.nacos.naming.raft;
import java.util.concurrent.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
/**
* @author nacos

View File

@ -354,7 +354,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);
}
@ -411,7 +411,7 @@ public class RaftCore {
String key = params.getString("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:
@ -570,8 +570,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];
@ -699,7 +699,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());
@ -761,7 +761,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);
}
@ -769,7 +769,7 @@ public class RaftCore {
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());
@ -962,9 +962,7 @@ public class RaftCore {
private static 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, Notifier.ApplyAction.DELETE);
Loggers.RAFT.info("datum deleted, key: {}", key);
}

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.naming.raft;
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;
@ -61,11 +62,11 @@ public class RaftStore {
for (File cache : listCaches()) {
if (cache.isDirectory() && cache.listFiles() != null) {
for (File datumFile : cache.listFiles()) {
readDatum(datumFile);
readDatum(datumFile, cache.getName());
}
continue;
}
readDatum(cache);
readDatum(cache, StringUtils.EMPTY);
}
// load meta
@ -93,14 +94,14 @@ public class RaftStore {
if (!StringUtils.equals(decodeFileName(cache.getName()), key)) {
continue;
}
readDatum(cache);
readDatum(cache, StringUtils.EMPTY);
}
Loggers.RAFT.info("finish loading datum, key: {} cost {} ms.",
key, (System.currentTimeMillis() - start));
}
public synchronized static void readDatum(File file) throws IOException {
public synchronized static void readDatum(File file, String namespaceId) throws IOException {
ByteBuffer buffer;
FileChannel fc = null;
@ -115,6 +116,26 @@ public class RaftStore {
}
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());
@ -130,28 +151,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()) {
@ -161,7 +189,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();
@ -192,13 +220,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 static void updateTerm(long term) throws Exception {
File file = new File(META_FILE_NAME);
if (!file.exists() && !file.getParentFile().mkdirs() && !file.createNewFile()) {

View File

@ -17,8 +17,8 @@ package com.alibaba.nacos.naming.selector;
import com.alibaba.nacos.api.cmdb.pojo.PreservedEntityTypes;
import com.alibaba.nacos.api.selector.SelectorType;
import com.alibaba.nacos.api.selector.ExpressionSelector;
import com.alibaba.nacos.api.selector.SelectorType;
import com.alibaba.nacos.cmdb.service.CmdbReader;
import com.alibaba.nacos.naming.boot.SpringContext;
import com.alibaba.nacos.naming.core.IpAddress;
@ -26,7 +26,10 @@ import com.alibaba.nacos.naming.exception.NacosException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* A selector to implement a so called same-label-prior rule for service discovery.

View File

@ -22,7 +22,6 @@ import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter;
import com.alibaba.nacos.api.selector.AbstractSelector;
import com.alibaba.nacos.api.selector.SelectorType;
import org.apache.commons.lang3.StringUtils;

View File

@ -17,11 +17,9 @@ package com.alibaba.nacos.naming.view;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.naming.pojo.Cluster;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.Service;
import java.util.List;
import java.util.Map;
/**
* @author <a href="mailto:zpf.073@gmail.com">nkorange</a>

View File

@ -1463,13 +1463,13 @@ public class ApiCommands {
lock.lock();
String entry = WebUtils.required(request, "entry");
Datum datum = RaftCore.getDatum(UtilsAndCommons.DOMAINS_DATA_ID + ".00-00---000-VIPSRV_SWITCH_DOMAIN-000---00-00");
Datum datum = RaftCore.getDatum(UtilsAndCommons.DOMAINS_DATA_ID_PRE + UtilsAndCommons.SWITCH_DOMAIN_NAME);
SwitchDomain switchDomain = null;
if (datum != null) {
switchDomain = JSON.parseObject(datum.value, SwitchDomain.class);
} else {
Loggers.SRV_LOG.warn("datum: {}.00-00---000-VIPSRV_SWITCH_DOMAIN-000---00-00 is null", UtilsAndCommons.DOMAINS_DATA_ID);
Loggers.SRV_LOG.warn("datum: {}{} is null", UtilsAndCommons.DOMAINS_DATA_ID_PRE, UtilsAndCommons.SWITCH_DOMAIN_NAME);
}
if (SwitchEntry.BATCH.equals(entry)) {

View File

@ -18,7 +18,6 @@ package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.naming.BaseTest;
import com.alibaba.nacos.naming.core.Cluster;
import com.alibaba.nacos.naming.core.IpAddress;

View File

@ -22,7 +22,9 @@ package com.alibaba.nacos.naming.web;
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.VirtualClusterDomain;
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
@ -42,8 +44,6 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.naming.core.DomainsManager;
import java.util.ArrayList;
import java.util.List;