Merge remote-tracking branch 'upstream/develop' into hotfix_169
合并远程develop分支
This commit is contained in:
commit
0a58348438
@ -16,7 +16,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -22,6 +22,8 @@ package com.alibaba.nacos.api;
|
|||||||
*/
|
*/
|
||||||
public class PropertyKeyConst {
|
public class PropertyKeyConst {
|
||||||
|
|
||||||
|
public final static String IS_USE_CLOUD_NAMESPACE_PARSING = "isUseCloudNamespaceParsing";
|
||||||
|
|
||||||
public final static String IS_USE_ENDPOINT_PARSING_RULE = "isUseEndpointParsingRule";
|
public final static String IS_USE_ENDPOINT_PARSING_RULE = "isUseEndpointParsingRule";
|
||||||
|
|
||||||
public final static String ENDPOINT = "endpoint";
|
public final static String ENDPOINT = "endpoint";
|
||||||
@ -50,6 +52,9 @@ public class PropertyKeyConst {
|
|||||||
|
|
||||||
public final static String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";
|
public final static String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the key value of some variable value from the system property
|
||||||
|
*/
|
||||||
public static class SystemEnv {
|
public static class SystemEnv {
|
||||||
|
|
||||||
public static final String ALIBABA_ALIWARE_ENDPOINT_PORT = "ALIBABA_ALIWARE_ENDPOINT_PORT";
|
public static final String ALIBABA_ALIWARE_ENDPOINT_PORT = "ALIBABA_ALIWARE_ENDPOINT_PORT";
|
||||||
@ -58,4 +63,5 @@ public class PropertyKeyConst {
|
|||||||
|
|
||||||
public static final String ALIBABA_ALIWARE_ENDPOINT_URL = "ALIBABA_ALIWARE_ENDPOINT_URL";
|
public static final String ALIBABA_ALIWARE_ENDPOINT_URL = "ALIBABA_ALIWARE_ENDPOINT_URL";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
package com.alibaba.nacos.api;
|
package com.alibaba.nacos.api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* <p>
|
||||||
|
* Support for reading the value of the specified variable from the -D parameter
|
||||||
|
* </P>
|
||||||
* Properties that are preferred to which in {@link PropertyKeyConst}
|
* Properties that are preferred to which in {@link PropertyKeyConst}
|
||||||
*
|
*
|
||||||
* @author pbting
|
* @author pbting
|
||||||
@ -27,5 +30,23 @@ public interface SystemPropertyKeyConst {
|
|||||||
|
|
||||||
String NAMING_WEB_CONTEXT = "nacos.naming.web.context";
|
String NAMING_WEB_CONTEXT = "nacos.naming.web.context";
|
||||||
|
|
||||||
String NACOS_NAMING_REQUEST_MODULE = "nacos.naming.request.module";
|
/**
|
||||||
|
* In the cloud (Alibaba Cloud or other cloud vendors) environment,
|
||||||
|
* whether to enable namespace resolution in the cloud environment.
|
||||||
|
* <p>
|
||||||
|
* The default is on.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
String IS_USE_CLOUD_NAMESPACE_PARSING = "nacos.use.cloud.namespace.parsing";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In the cloud environment, if the process level requires a globally uniform namespace,
|
||||||
|
* it can be specified with the -D parameter.
|
||||||
|
*/
|
||||||
|
String ANS_NAMESPACE = "ans.namespace";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is also supported by the -D parameter.
|
||||||
|
*/
|
||||||
|
String IS_USE_ENDPOINT_PARSING_RULE = "nacos.use.endpoint.parsing.rule";
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,8 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String DEFAULT_NAMESPACE_ID = "public";
|
public static final String DEFAULT_NAMESPACE_ID = "public";
|
||||||
|
|
||||||
|
public static final boolean DEFAULT_USE_CLOUD_NAMESPACE_PARSING = true;
|
||||||
|
|
||||||
public static final int WRITE_REDIRECT_CODE = 307;
|
public static final int WRITE_REDIRECT_CODE = 307;
|
||||||
|
|
||||||
public static final String SERVICE_INFO_SPLITER = "@@";
|
public static final String SERVICE_INFO_SPLITER = "@@";
|
||||||
|
@ -49,6 +49,13 @@ public @interface NacosConfigurationProperties {
|
|||||||
*/
|
*/
|
||||||
String dataId();
|
String dataId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if the config style is yaml
|
||||||
|
*
|
||||||
|
* @return default value is <code>false</code>
|
||||||
|
*/
|
||||||
|
boolean yaml() default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It indicates the properties of current doBind bean is auto-refreshed when Nacos configuration is changed.
|
* It indicates the properties of current doBind bean is auto-refreshed when Nacos configuration is changed.
|
||||||
*
|
*
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package com.alibaba.nacos.client.config;
|
package com.alibaba.nacos.client.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||||
|
import com.alibaba.nacos.api.SystemPropertyKeyConst;
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.api.config.ConfigService;
|
import com.alibaba.nacos.api.config.ConfigService;
|
||||||
import com.alibaba.nacos.api.config.listener.Listener;
|
import com.alibaba.nacos.api.config.listener.Listener;
|
||||||
@ -31,10 +32,10 @@ import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
|
|||||||
import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor;
|
import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor;
|
||||||
import com.alibaba.nacos.client.config.utils.ContentUtils;
|
import com.alibaba.nacos.client.config.utils.ContentUtils;
|
||||||
import com.alibaba.nacos.client.config.utils.ParamUtils;
|
import com.alibaba.nacos.client.config.utils.ParamUtils;
|
||||||
import com.alibaba.nacos.client.config.utils.TenantUtil;
|
|
||||||
import com.alibaba.nacos.client.utils.LogUtils;
|
import com.alibaba.nacos.client.utils.LogUtils;
|
||||||
import com.alibaba.nacos.client.utils.StringUtils;
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||||
|
import com.alibaba.nacos.client.utils.TenantUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -87,10 +88,16 @@ public class NacosConfigService implements ConfigService {
|
|||||||
private void initNamespace(Properties properties) {
|
private void initNamespace(Properties properties) {
|
||||||
String namespaceTmp = null;
|
String namespaceTmp = null;
|
||||||
|
|
||||||
|
String isUseCloudNamespaceParsing =
|
||||||
|
properties.getProperty(PropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING,
|
||||||
|
System.getProperty(SystemPropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING,
|
||||||
|
String.valueOf(Constants.DEFAULT_USE_CLOUD_NAMESPACE_PARSING)));
|
||||||
|
|
||||||
|
if (Boolean.valueOf(isUseCloudNamespaceParsing)) {
|
||||||
namespaceTmp = TemplateUtils.stringBlankAndThenExecute(namespaceTmp, new Callable<String>() {
|
namespaceTmp = TemplateUtils.stringBlankAndThenExecute(namespaceTmp, new Callable<String>() {
|
||||||
@Override
|
@Override
|
||||||
public String call() {
|
public String call() {
|
||||||
return TenantUtil.getUserTenant();
|
return TenantUtil.getUserTenantForAcm();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -101,6 +108,7 @@ public class NacosConfigService implements ConfigService {
|
|||||||
return StringUtils.isNotBlank(namespace) ? namespace : EMPTY;
|
return StringUtils.isNotBlank(namespace) ? namespace : EMPTY;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (StringUtils.isBlank(namespaceTmp)) {
|
if (StringUtils.isBlank(namespaceTmp)) {
|
||||||
namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||||
|
@ -22,8 +22,8 @@ import com.alibaba.nacos.api.exception.NacosException;
|
|||||||
import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
|
import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
|
||||||
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
|
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
|
||||||
import com.alibaba.nacos.client.config.utils.MD5;
|
import com.alibaba.nacos.client.config.utils.MD5;
|
||||||
import com.alibaba.nacos.client.config.utils.TenantUtil;
|
|
||||||
import com.alibaba.nacos.client.utils.LogUtils;
|
import com.alibaba.nacos.client.utils.LogUtils;
|
||||||
|
import com.alibaba.nacos.client.utils.TenantUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -236,7 +236,7 @@ public class CacheData {
|
|||||||
this.configFilterChainManager = configFilterChainManager;
|
this.configFilterChainManager = configFilterChainManager;
|
||||||
this.dataId = dataId;
|
this.dataId = dataId;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.tenant = TenantUtil.getUserTenant();
|
this.tenant = TenantUtil.getUserTenantForAcm();
|
||||||
listeners = new CopyOnWriteArrayList<ManagerListenerWrap>();
|
listeners = new CopyOnWriteArrayList<ManagerListenerWrap>();
|
||||||
this.isInitializing = true;
|
this.isInitializing = true;
|
||||||
this.content = loadCacheContentFromDiskLocal(name, dataId, group, tenant);
|
this.content = loadCacheContentFromDiskLocal(name, dataId, group, tenant);
|
||||||
|
@ -24,29 +24,19 @@ import com.alibaba.nacos.client.config.http.HttpAgent;
|
|||||||
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
|
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
|
||||||
import com.alibaba.nacos.client.config.utils.ContentUtils;
|
import com.alibaba.nacos.client.config.utils.ContentUtils;
|
||||||
import com.alibaba.nacos.client.config.utils.MD5;
|
import com.alibaba.nacos.client.config.utils.MD5;
|
||||||
import com.alibaba.nacos.client.config.utils.TenantUtil;
|
|
||||||
import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
||||||
import com.alibaba.nacos.client.utils.LogUtils;
|
import com.alibaba.nacos.client.utils.LogUtils;
|
||||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||||
import com.alibaba.nacos.client.utils.StringUtils;
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
|
import com.alibaba.nacos.client.utils.TenantUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
import java.util.concurrent.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.common.Constants.LINE_SEPARATOR;
|
import static com.alibaba.nacos.api.common.Constants.LINE_SEPARATOR;
|
||||||
@ -189,7 +179,7 @@ public class ClientWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CacheData getCache(String dataId, String group) {
|
public CacheData getCache(String dataId, String group) {
|
||||||
return getCache(dataId, group, TenantUtil.getUserTenant());
|
return getCache(dataId, group, TenantUtil.getUserTenantForAcm());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheData getCache(String dataId, String group, String tenant) {
|
public CacheData getCache(String dataId, String group, String tenant) {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package com.alibaba.nacos.client.config.impl;
|
package com.alibaba.nacos.client.config.impl;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||||
|
import com.alibaba.nacos.api.SystemPropertyKeyConst;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.client.config.impl.EventDispatcher.ServerlistChangeEvent;
|
import com.alibaba.nacos.client.config.impl.EventDispatcher.ServerlistChangeEvent;
|
||||||
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
|
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
|
||||||
@ -180,7 +181,13 @@ public class ServerListManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String endpointTmp = properties.getProperty(PropertyKeyConst.ENDPOINT);
|
String endpointTmp = properties.getProperty(PropertyKeyConst.ENDPOINT);
|
||||||
if (Boolean.valueOf(properties.getProperty(PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE, ParamUtil.USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE))) {
|
|
||||||
|
// Whether to enable domain name resolution rules
|
||||||
|
String isUseEndpointRuleParsing =
|
||||||
|
properties.getProperty(PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE,
|
||||||
|
System.getProperty(SystemPropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE,
|
||||||
|
String.valueOf(ParamUtil.USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE)));
|
||||||
|
if (Boolean.valueOf(isUseEndpointRuleParsing)) {
|
||||||
String endpointUrl = ParamUtil.parsingEndpointRule(endpointTmp);
|
String endpointUrl = ParamUtil.parsingEndpointRule(endpointTmp);
|
||||||
if (StringUtils.isNotBlank(endpointUrl)) {
|
if (StringUtils.isNotBlank(endpointUrl)) {
|
||||||
serverAddrsStr = "";
|
serverAddrsStr = "";
|
||||||
@ -352,7 +359,7 @@ public class ServerListManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不同环境的名称
|
* The name of the different environment
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
private String namespace = "";
|
private String namespace = "";
|
||||||
@ -362,7 +369,7 @@ public class ServerListManager {
|
|||||||
static public final String FIXED_NAME = "fixed";
|
static public final String FIXED_NAME = "fixed";
|
||||||
private int initServerlistRetryTimes = 5;
|
private int initServerlistRetryTimes = 5;
|
||||||
/**
|
/**
|
||||||
* 和其他server的连接超时和socket超时
|
* Connection timeout and socket timeout with other servers
|
||||||
*/
|
*/
|
||||||
static final int TIMEOUT = 5000;
|
static final int TIMEOUT = 5000;
|
||||||
|
|
||||||
@ -384,7 +391,7 @@ public class ServerListManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对地址列表排序,同机房优先。
|
* Sort the address list, with the same room priority.
|
||||||
*/
|
*/
|
||||||
class ServerAddressIterator implements Iterator<String> {
|
class ServerAddressIterator implements Iterator<String> {
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class NacosNamingMaintainService implements NamingMaintainService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init(Properties properties) {
|
private void init(Properties properties) {
|
||||||
namespace = InitUtils.initNamespace(properties);
|
namespace = InitUtils.initNamespaceForNaming(properties);
|
||||||
initServerAddr(properties);
|
initServerAddr(properties);
|
||||||
InitUtils.initWebRootContext();
|
InitUtils.initWebRootContext();
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public class NacosNamingService implements NamingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init(Properties properties) {
|
private void init(Properties properties) {
|
||||||
namespace = InitUtils.initNamespace(properties);
|
namespace = InitUtils.initNamespaceForNaming(properties);
|
||||||
initServerAddr(properties);
|
initServerAddr(properties);
|
||||||
InitUtils.initWebRootContext();
|
InitUtils.initWebRootContext();
|
||||||
initCacheDir();
|
initCacheDir();
|
||||||
|
@ -21,8 +21,8 @@ import com.alibaba.nacos.client.naming.cache.ConcurrentDiskUtil;
|
|||||||
import com.alibaba.nacos.client.naming.cache.DiskCache;
|
import com.alibaba.nacos.client.naming.cache.DiskCache;
|
||||||
import com.alibaba.nacos.client.naming.core.HostReactor;
|
import com.alibaba.nacos.client.naming.core.HostReactor;
|
||||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
|
||||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||||
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -20,7 +20,7 @@ import com.alibaba.nacos.api.common.Constants;
|
|||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
|
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
|
||||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -23,8 +23,8 @@ import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
|||||||
import com.alibaba.nacos.client.naming.backups.FailoverReactor;
|
import com.alibaba.nacos.client.naming.backups.FailoverReactor;
|
||||||
import com.alibaba.nacos.client.naming.cache.DiskCache;
|
import com.alibaba.nacos.client.naming.cache.DiskCache;
|
||||||
import com.alibaba.nacos.client.naming.net.NamingProxy;
|
import com.alibaba.nacos.client.naming.net.NamingProxy;
|
||||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
|
||||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||||
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
@ -17,7 +17,7 @@ package com.alibaba.nacos.client.naming.core;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.nacos.client.naming.utils.IoUtils;
|
import com.alibaba.nacos.client.naming.utils.IoUtils;
|
||||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
|
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
|
@ -17,7 +17,7 @@ package com.alibaba.nacos.client.naming.net;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.client.naming.utils.IoUtils;
|
import com.alibaba.nacos.client.naming.utils.IoUtils;
|
||||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
import com.google.common.net.HttpHeaders;
|
import com.google.common.net.HttpHeaders;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -32,6 +32,7 @@ import com.alibaba.nacos.client.config.impl.SpasAdapter;
|
|||||||
import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
||||||
import com.alibaba.nacos.client.naming.beat.BeatInfo;
|
import com.alibaba.nacos.client.naming.beat.BeatInfo;
|
||||||
import com.alibaba.nacos.client.naming.utils.*;
|
import com.alibaba.nacos.client.naming.utils.*;
|
||||||
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||||
import com.alibaba.nacos.common.util.HttpMethod;
|
import com.alibaba.nacos.common.util.HttpMethod;
|
||||||
import com.alibaba.nacos.common.util.UuidUtils;
|
import com.alibaba.nacos.common.util.UuidUtils;
|
||||||
@ -298,7 +299,9 @@ public class NamingProxy {
|
|||||||
|
|
||||||
public long sendBeat(BeatInfo beatInfo) {
|
public long sendBeat(BeatInfo beatInfo) {
|
||||||
try {
|
try {
|
||||||
NAMING_LOGGER.info("[BEAT] {} sending beat to server: {}", namespaceId, beatInfo.toString());
|
if (NAMING_LOGGER.isDebugEnabled()) {
|
||||||
|
NAMING_LOGGER.debug("[BEAT] {} sending beat to server: {}", namespaceId, beatInfo.toString());
|
||||||
|
}
|
||||||
Map<String, String> params = new HashMap<String, String>(4);
|
Map<String, String> params = new HashMap<String, String>(4);
|
||||||
params.put("beat", JSON.toJSONString(beatInfo));
|
params.put("beat", JSON.toJSONString(beatInfo));
|
||||||
params.put(CommonParams.NAMESPACE_ID, namespaceId);
|
params.put(CommonParams.NAMESPACE_ID, namespaceId);
|
||||||
|
@ -18,24 +18,56 @@ package com.alibaba.nacos.client.naming.utils;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||||
import com.alibaba.nacos.api.SystemPropertyKeyConst;
|
import com.alibaba.nacos.api.SystemPropertyKeyConst;
|
||||||
import com.alibaba.nacos.client.identify.CredentialService;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
import com.alibaba.nacos.client.utils.*;
|
||||||
import com.alibaba.nacos.client.utils.LogUtils;
|
|
||||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
|
||||||
import com.alibaba.nacos.client.utils.StringUtils;
|
|
||||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author liaochuntao
|
* @author liaochuntao
|
||||||
|
* @author deshao
|
||||||
*/
|
*/
|
||||||
public class InitUtils {
|
public class InitUtils {
|
||||||
|
|
||||||
public static final String initNamespace(Properties properties) {
|
/**
|
||||||
|
* Add a difference to the name naming. This method simply initializes the namespace for Naming.
|
||||||
|
* Config initialization is not the same, so it cannot be reused directly.
|
||||||
|
*
|
||||||
|
* @param properties
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final String initNamespaceForNaming(Properties properties) {
|
||||||
String tmpNamespace = null;
|
String tmpNamespace = null;
|
||||||
|
|
||||||
|
|
||||||
|
String isUseCloudNamespaceParsing =
|
||||||
|
properties.getProperty(PropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING,
|
||||||
|
System.getProperty(SystemPropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING,
|
||||||
|
String.valueOf(Constants.DEFAULT_USE_CLOUD_NAMESPACE_PARSING)));
|
||||||
|
|
||||||
|
if (Boolean.valueOf(isUseCloudNamespaceParsing)) {
|
||||||
|
|
||||||
|
tmpNamespace = TenantUtil.getUserTenantForAns();
|
||||||
|
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
||||||
|
@Override
|
||||||
|
public String call() {
|
||||||
|
String namespace = System.getProperty(SystemPropertyKeyConst.ANS_NAMESPACE);
|
||||||
|
LogUtils.NAMING_LOGGER.info("initializer namespace from System Property :" + namespace);
|
||||||
|
return namespace;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
||||||
|
@Override
|
||||||
|
public String call() {
|
||||||
|
String namespace = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE);
|
||||||
|
LogUtils.NAMING_LOGGER.info("initializer namespace from System Environment :" + namespace);
|
||||||
|
return namespace;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
||||||
@Override
|
@Override
|
||||||
public String call() {
|
public String call() {
|
||||||
@ -45,26 +77,7 @@ public class InitUtils {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(tmpNamespace) && properties != null) {
|
||||||
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
|
||||||
@Override
|
|
||||||
public String call() {
|
|
||||||
String namespace = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE);
|
|
||||||
LogUtils.NAMING_LOGGER.info("initializer namespace from System Environment :" + namespace);
|
|
||||||
return namespace;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
|
||||||
@Override
|
|
||||||
public String call() {
|
|
||||||
String namespace = CredentialService.getInstance().getCredential().getTenantId();
|
|
||||||
LogUtils.NAMING_LOGGER.info("initializer namespace from Credential Module " + namespace);
|
|
||||||
return namespace;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (com.alibaba.nacos.client.utils.StringUtils.isEmpty(tmpNamespace) && properties != null) {
|
|
||||||
tmpNamespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
tmpNamespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,13 +110,18 @@ public class InitUtils {
|
|||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
// 是否开启域名解析规则
|
// Whether to enable domain name resolution rules
|
||||||
boolean isUseEndpointParsingRule = Boolean.valueOf(properties.getProperty(PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE, ParamUtil.USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE));
|
String isUseEndpointRuleParsing =
|
||||||
|
properties.getProperty(PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE,
|
||||||
|
System.getProperty(SystemPropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE,
|
||||||
|
String.valueOf(ParamUtil.USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE)));
|
||||||
|
|
||||||
|
boolean isUseEndpointParsingRule = Boolean.valueOf(isUseEndpointRuleParsing);
|
||||||
String endpointUrl;
|
String endpointUrl;
|
||||||
if (isUseEndpointParsingRule) {
|
if (isUseEndpointParsingRule) {
|
||||||
// 获取设置的域名信息
|
// Get the set domain name information
|
||||||
endpointUrl = ParamUtil.parsingEndpointRule(properties.getProperty(PropertyKeyConst.ENDPOINT));
|
endpointUrl = ParamUtil.parsingEndpointRule(properties.getProperty(PropertyKeyConst.ENDPOINT));
|
||||||
if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(endpointUrl)) {
|
if (com.alibaba.nacos.client.utils.StringUtils.isBlank(endpointUrl)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
package com.alibaba.nacos.client.naming.utils;
|
package com.alibaba.nacos.client.naming.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.nacos.client.naming.utils;
|
package com.alibaba.nacos.client.naming.utils;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.client.utils.StringUtils;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
@ -1,163 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
|
||||||
*
|
|
||||||
* Licensed 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.alibaba.nacos.client.naming.utils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author nkorange
|
|
||||||
*/
|
|
||||||
public class StringUtils {
|
|
||||||
public static boolean isEmpty(String str) {
|
|
||||||
return str == null || str.length() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String EMPTY = "";
|
|
||||||
|
|
||||||
public static boolean equals(String str1, String str2) {
|
|
||||||
return str1 == null ? str2 == null : str1.equals(str2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String join(Collection collection, String separator) {
|
|
||||||
if (collection == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
Object[] objects = collection.toArray();
|
|
||||||
|
|
||||||
for (int i = 0; i < collection.size() - 1; i++) {
|
|
||||||
stringBuilder.append(objects[i].toString()).append(separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (collection.size() > 0) {
|
|
||||||
stringBuilder.append(objects[collection.size() - 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNotEmpty(String str) {
|
|
||||||
return !isEmpty(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String escapeJavaScript(String str) {
|
|
||||||
return escapeJavaStyleString(str, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String escapeJavaStyleString(String str, boolean escapeSingleQuotes, boolean escapeForwardSlash) {
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringWriter writer = new StringWriter(str.length() * 2);
|
|
||||||
escapeJavaStyleString(writer, str, escapeSingleQuotes, escapeForwardSlash);
|
|
||||||
return writer.toString();
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
// this should never ever happen while writing to a StringWriter
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String hex(char ch) {
|
|
||||||
return Integer.toHexString(ch).toUpperCase(Locale.ENGLISH);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote,
|
|
||||||
boolean escapeForwardSlash) throws IOException {
|
|
||||||
if (out == null) {
|
|
||||||
throw new IllegalArgumentException("The Writer must not be null");
|
|
||||||
}
|
|
||||||
if (str == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int sz;
|
|
||||||
sz = str.length();
|
|
||||||
for (int i = 0; i < sz; i++) {
|
|
||||||
char ch = str.charAt(i);
|
|
||||||
|
|
||||||
// handle unicode
|
|
||||||
if (ch > 0xfff) {
|
|
||||||
out.write("\\u" + hex(ch));
|
|
||||||
} else if (ch > 0xff) {
|
|
||||||
out.write("\\u0" + hex(ch));
|
|
||||||
} else if (ch > 0x7f) {
|
|
||||||
out.write("\\u00" + hex(ch));
|
|
||||||
} else if (ch < 32) {
|
|
||||||
switch (ch) {
|
|
||||||
case '\b':
|
|
||||||
out.write('\\');
|
|
||||||
out.write('b');
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
out.write('\\');
|
|
||||||
out.write('n');
|
|
||||||
break;
|
|
||||||
case '\t':
|
|
||||||
out.write('\\');
|
|
||||||
out.write('t');
|
|
||||||
break;
|
|
||||||
case '\f':
|
|
||||||
out.write('\\');
|
|
||||||
out.write('f');
|
|
||||||
break;
|
|
||||||
case '\r':
|
|
||||||
out.write('\\');
|
|
||||||
out.write('r');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (ch > 0xf) {
|
|
||||||
out.write("\\u00" + hex(ch));
|
|
||||||
} else {
|
|
||||||
out.write("\\u000" + hex(ch));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch (ch) {
|
|
||||||
case '\'':
|
|
||||||
if (escapeSingleQuote) {
|
|
||||||
out.write('\\');
|
|
||||||
}
|
|
||||||
out.write('\'');
|
|
||||||
break;
|
|
||||||
case '"':
|
|
||||||
out.write('\\');
|
|
||||||
out.write('"');
|
|
||||||
break;
|
|
||||||
case '\\':
|
|
||||||
out.write('\\');
|
|
||||||
out.write('\\');
|
|
||||||
break;
|
|
||||||
case '/':
|
|
||||||
if (escapeForwardSlash) {
|
|
||||||
out.write('\\');
|
|
||||||
}
|
|
||||||
out.write('/');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
out.write(ch);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -33,7 +33,7 @@ public class ParamUtil {
|
|||||||
|
|
||||||
private final static Logger LOGGER = LogUtils.logger(ParamUtil.class);
|
private final static Logger LOGGER = LogUtils.logger(ParamUtil.class);
|
||||||
|
|
||||||
public final static String USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE = "true";
|
public final static boolean USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE = true;
|
||||||
|
|
||||||
private static final Pattern PATTERN = Pattern.compile("\\$\\{[^}]+\\}");
|
private static final Pattern PATTERN = Pattern.compile("\\$\\{[^}]+\\}");
|
||||||
private static String defaultContextPath = "nacos";
|
private static String defaultContextPath = "nacos";
|
||||||
|
@ -15,7 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.nacos.client.utils;
|
package com.alibaba.nacos.client.utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string util
|
* string util
|
||||||
@ -26,6 +30,8 @@ public class StringUtils {
|
|||||||
|
|
||||||
public static final int INDEX_NOT_FOUND = -1;
|
public static final int INDEX_NOT_FOUND = -1;
|
||||||
|
|
||||||
|
public static final String EMPTY = "";
|
||||||
|
|
||||||
public static boolean isBlank(String str) {
|
public static boolean isBlank(String str) {
|
||||||
int strLen;
|
int strLen;
|
||||||
if (str == null || (strLen = str.length()) == 0) {
|
if (str == null || (strLen = str.length()) == 0) {
|
||||||
@ -92,4 +98,106 @@ public class StringUtils {
|
|||||||
|
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String escapeJavaScript(String str) {
|
||||||
|
return escapeJavaStyleString(str, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String escapeJavaStyleString(String str, boolean escapeSingleQuotes, boolean escapeForwardSlash) {
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
StringWriter writer = new StringWriter(str.length() * 2);
|
||||||
|
escapeJavaStyleString(writer, str, escapeSingleQuotes, escapeForwardSlash);
|
||||||
|
return writer.toString();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
// this should never ever happen while writing to a StringWriter
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String hex(char ch) {
|
||||||
|
return Integer.toHexString(ch).toUpperCase(Locale.ENGLISH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote,
|
||||||
|
boolean escapeForwardSlash) throws IOException {
|
||||||
|
if (out == null) {
|
||||||
|
throw new IllegalArgumentException("The Writer must not be null");
|
||||||
|
}
|
||||||
|
if (str == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int sz;
|
||||||
|
sz = str.length();
|
||||||
|
for (int i = 0; i < sz; i++) {
|
||||||
|
char ch = str.charAt(i);
|
||||||
|
|
||||||
|
// handle unicode
|
||||||
|
if (ch > 0xfff) {
|
||||||
|
out.write("\\u" + hex(ch));
|
||||||
|
} else if (ch > 0xff) {
|
||||||
|
out.write("\\u0" + hex(ch));
|
||||||
|
} else if (ch > 0x7f) {
|
||||||
|
out.write("\\u00" + hex(ch));
|
||||||
|
} else if (ch < 32) {
|
||||||
|
switch (ch) {
|
||||||
|
case '\b':
|
||||||
|
out.write('\\');
|
||||||
|
out.write('b');
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
out.write('\\');
|
||||||
|
out.write('n');
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
out.write('\\');
|
||||||
|
out.write('t');
|
||||||
|
break;
|
||||||
|
case '\f':
|
||||||
|
out.write('\\');
|
||||||
|
out.write('f');
|
||||||
|
break;
|
||||||
|
case '\r':
|
||||||
|
out.write('\\');
|
||||||
|
out.write('r');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (ch > 0xf) {
|
||||||
|
out.write("\\u00" + hex(ch));
|
||||||
|
} else {
|
||||||
|
out.write("\\u000" + hex(ch));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (ch) {
|
||||||
|
case '\'':
|
||||||
|
if (escapeSingleQuote) {
|
||||||
|
out.write('\\');
|
||||||
|
}
|
||||||
|
out.write('\'');
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
out.write('\\');
|
||||||
|
out.write('"');
|
||||||
|
break;
|
||||||
|
case '\\':
|
||||||
|
out.write('\\');
|
||||||
|
out.write('\\');
|
||||||
|
break;
|
||||||
|
case '/':
|
||||||
|
if (escapeForwardSlash) {
|
||||||
|
out.write('\\');
|
||||||
|
}
|
||||||
|
out.write('/');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
out.write(ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.alibaba.nacos.client.config.utils;
|
package com.alibaba.nacos.client.utils;
|
||||||
|
|
||||||
import com.alibaba.nacos.client.utils.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tenant Util
|
* Tenant Util
|
||||||
@ -24,20 +22,42 @@ import com.alibaba.nacos.client.utils.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public class TenantUtil {
|
public class TenantUtil {
|
||||||
|
|
||||||
private static String userTenant = "";
|
private static String userTenant;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
userTenant = System.getProperty("tenant.id", "");
|
userTenant = System.getProperty("tenant.id", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapt the way ACM gets tenant on the cloud.
|
||||||
|
* <p>
|
||||||
|
* Note the difference between getting and getting ANS.
|
||||||
|
* Since the processing logic on the server side is different, the default value returns differently.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getUserTenantForAcm() {
|
||||||
|
String tmp = userTenant;
|
||||||
|
|
||||||
if (StringUtils.isBlank(userTenant)) {
|
if (StringUtils.isBlank(userTenant)) {
|
||||||
userTenant = System.getProperty("acm.namespace", "");
|
tmp = System.getProperty("acm.namespace", "");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUserTenant() {
|
return tmp;
|
||||||
return userTenant;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setUserTenant(String userTenant) {
|
/**
|
||||||
TenantUtil.userTenant = userTenant;
|
* Adapt the way ANS gets tenant on the cloud.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getUserTenantForAns() {
|
||||||
|
String tmp = userTenant;
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(userTenant)) {
|
||||||
|
tmp = System.getProperty("ans.namespace");
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,48 +0,0 @@
|
|||||||
package com.alibaba.nacos.client.naming;
|
|
||||||
|
|
||||||
import com.alibaba.nacos.api.NacosFactory;
|
|
||||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
|
||||||
import com.alibaba.nacos.api.naming.NamingService;
|
|
||||||
import com.alibaba.nacos.api.naming.pojo.Service;
|
|
||||||
import com.alibaba.nacos.api.selector.ExpressionSelector;
|
|
||||||
import com.alibaba.nacos.api.selector.NoneSelector;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
|
||||||
|
|
||||||
|
|
||||||
public class NacosNamingServiceTest {
|
|
||||||
|
|
||||||
private NamingService nameService;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before() throws NacosException {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.put(PropertyKeyConst.SERVER_ADDR, "11.160.165.126:8848");
|
|
||||||
|
|
||||||
nameService = NacosFactory.createNamingService(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteService() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateService() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void registerInstance() throws NacosException {
|
|
||||||
nameService.registerInstance("nacos-api", "127.0.0.1", 8009);
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>nacos-console</artifactId>
|
<artifactId>nacos-console</artifactId>
|
||||||
<!--<packaging>war</packaging>-->
|
<!--<packaging>war</packaging>-->
|
||||||
|
@ -49,7 +49,7 @@ export default {
|
|||||||
* 检测属性是否正确
|
* 检测属性是否正确
|
||||||
*/
|
*/
|
||||||
validateProperties(str = '') {
|
validateProperties(str = '') {
|
||||||
const reg = /^[^=]+=[^=]+$/;
|
const reg = /^[^=]+=.+$/;
|
||||||
return str
|
return str
|
||||||
.replace('\n\r', '\n')
|
.replace('\n\r', '\n')
|
||||||
.split('\n')
|
.split('\n')
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class ServerListManager {
|
|||||||
GlobalExecutor.registerServerStatusReporter(new ServerStatusReporter(), 5000);
|
GlobalExecutor.registerServerStatusReporter(new ServerStatusReporter(), 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Server> refreshServerList() {
|
private List<Server> refreshServerList() {
|
||||||
|
|
||||||
List<Server> result = new ArrayList<>();
|
List<Server> result = new ArrayList<>();
|
||||||
|
|
||||||
@ -111,12 +111,12 @@ public class ServerListManager {
|
|||||||
|
|
||||||
String ip;
|
String ip;
|
||||||
int port;
|
int port;
|
||||||
if (serverList.get(0).contains(UtilsAndCommons.IP_PORT_SPLITER)) {
|
String server = serverList.get(i);
|
||||||
|
if (server.contains(UtilsAndCommons.IP_PORT_SPLITER)) {
|
||||||
ip = serverList.get(i).split(UtilsAndCommons.IP_PORT_SPLITER)[0];
|
ip = server.split(UtilsAndCommons.IP_PORT_SPLITER)[0];
|
||||||
port = Integer.parseInt(serverList.get(i).split(UtilsAndCommons.IP_PORT_SPLITER)[1]);
|
port = Integer.parseInt(server.split(UtilsAndCommons.IP_PORT_SPLITER)[1]);
|
||||||
} else {
|
} else {
|
||||||
ip = serverList.get(i);
|
ip = server;
|
||||||
port = RunningConfig.getServerPort();
|
port = RunningConfig.getServerPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,22 +148,24 @@ public class CatalogController {
|
|||||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||||
Constants.DEFAULT_NAMESPACE_ID);
|
Constants.DEFAULT_NAMESPACE_ID);
|
||||||
List<ServiceDetailInfo> serviceDetailInfoList = new ArrayList<>();
|
List<ServiceDetailInfo> serviceDetailInfoList = new ArrayList<>();
|
||||||
|
int pageNo = Integer.parseInt(WebUtils.required(request, "pageNo"));
|
||||||
|
int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
|
||||||
|
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
|
||||||
|
|
||||||
serviceManager
|
List<Service> serviceList = new ArrayList<>(8);
|
||||||
.getServiceMap(namespaceId)
|
serviceManager.getPagedService(namespaceId, pageNo, pageSize, keyword, StringUtils.EMPTY, serviceList);
|
||||||
.forEach(
|
|
||||||
(serviceName, service) -> {
|
|
||||||
|
|
||||||
|
for (Service service : serviceList) {
|
||||||
ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo();
|
ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo();
|
||||||
serviceDetailInfo.setServiceName(NamingUtils.getServiceName(serviceName));
|
serviceDetailInfo.setServiceName(NamingUtils.getServiceName(service.getName()));
|
||||||
serviceDetailInfo.setGroupName(NamingUtils.getGroupName(serviceName));
|
serviceDetailInfo.setGroupName(NamingUtils.getGroupName(service.getName()));
|
||||||
serviceDetailInfo.setMetadata(service.getMetadata());
|
serviceDetailInfo.setMetadata(service.getMetadata());
|
||||||
|
|
||||||
Map<String, ClusterInfo> clusterInfoMap = getStringClusterInfoMap(service);
|
Map<String, ClusterInfo> clusterInfoMap = getStringClusterInfoMap(service);
|
||||||
serviceDetailInfo.setClusterMap(clusterInfoMap);
|
serviceDetailInfo.setClusterMap(clusterInfoMap);
|
||||||
|
|
||||||
serviceDetailInfoList.add(serviceDetailInfo);
|
serviceDetailInfoList.add(serviceDetailInfo);
|
||||||
});
|
}
|
||||||
|
|
||||||
return serviceDetailInfoList;
|
return serviceDetailInfoList;
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,6 +31,7 @@ import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
|||||||
import com.alibaba.nacos.naming.push.PushService;
|
import com.alibaba.nacos.naming.push.PushService;
|
||||||
import com.alibaba.nacos.naming.web.CanDistro;
|
import com.alibaba.nacos.naming.web.CanDistro;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -96,6 +97,7 @@ public class HealthController {
|
|||||||
throw new IllegalArgumentException("Param 'healthy' is required.");
|
throw new IllegalArgumentException("Param 'healthy' is required.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
valid = BooleanUtils.toBoolean(healthyString);
|
||||||
|
|
||||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||||
// Only health check "none" need update health status with api
|
// Only health check "none" need update health status with api
|
||||||
|
@ -93,13 +93,9 @@ public class PushService {
|
|||||||
try {
|
try {
|
||||||
udpSocket = new DatagramSocket();
|
udpSocket = new DatagramSocket();
|
||||||
|
|
||||||
Receiver receiver;
|
Receiver receiver = new Receiver();
|
||||||
|
|
||||||
Thread inThread;
|
Thread inThread = new Thread(receiver);
|
||||||
|
|
||||||
receiver = new Receiver();
|
|
||||||
|
|
||||||
inThread = new Thread(receiver);
|
|
||||||
inThread.setDaemon(true);
|
inThread.setDaemon(true);
|
||||||
inThread.setName("com.alibaba.nacos.naming.push.receiver");
|
inThread.setName("com.alibaba.nacos.naming.push.receiver");
|
||||||
inThread.start();
|
inThread.start();
|
||||||
|
17
pom.xml
17
pom.xml
@ -21,7 +21,7 @@
|
|||||||
<inceptionYear>2018</inceptionYear>
|
<inceptionYear>2018</inceptionYear>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>Alibaba NACOS ${project.version}</name>
|
<name>Alibaba NACOS ${project.version}</name>
|
||||||
@ -36,7 +36,7 @@
|
|||||||
<url>git@github.com:alibaba/nacos.git</url>
|
<url>git@github.com:alibaba/nacos.git</url>
|
||||||
<connection>scm:git@github.com:alibaba/nacos.git</connection>
|
<connection>scm:git@github.com:alibaba/nacos.git</connection>
|
||||||
<developerConnection>scm:git@github.com:alibaba/nacos.git</developerConnection>
|
<developerConnection>scm:git@github.com:alibaba/nacos.git</developerConnection>
|
||||||
<tag>nacos-all-1.0.0</tag>
|
<tag>nacos-all-1.0.1</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<mailingLists>
|
<mailingLists>
|
||||||
@ -378,18 +378,6 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<distributionManagement>
|
|
||||||
<snapshotRepository>
|
|
||||||
<id>sona</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
</snapshotRepository>
|
|
||||||
<repository>
|
|
||||||
<id>sona</id>
|
|
||||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
|
|
||||||
</repository>
|
|
||||||
</distributionManagement>
|
|
||||||
|
|
||||||
</profile>
|
</profile>
|
||||||
<profile>
|
<profile>
|
||||||
<id>it-test</id>
|
<id>it-test</id>
|
||||||
@ -738,5 +726,6 @@
|
|||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
Loading…
Reference in New Issue
Block a user