Merge remote-tracking branch 'upstream/develop' into hotfix_169

合并远程develop分支
This commit is contained in:
yongchao9 2019-06-05 20:43:20 +08:00
commit 0a58348438
42 changed files with 328 additions and 356 deletions

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -22,6 +22,8 @@ package com.alibaba.nacos.api;
*/
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 ENDPOINT = "endpoint";
@ -50,6 +52,9 @@ public class PropertyKeyConst {
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 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";
}
}

View File

@ -16,6 +16,9 @@
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}
*
* @author pbting
@ -27,5 +30,23 @@ public interface SystemPropertyKeyConst {
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";
}

View File

@ -125,6 +125,8 @@ public class Constants {
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 String SERVICE_INFO_SPLITER = "@@";

View File

@ -49,6 +49,13 @@ public @interface NacosConfigurationProperties {
*/
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.
*

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.client.config;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.SystemPropertyKeyConst;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.ConfigService;
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.utils.ContentUtils;
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.StringUtils;
import com.alibaba.nacos.client.utils.TemplateUtils;
import com.alibaba.nacos.client.utils.TenantUtil;
import org.slf4j.Logger;
import java.io.IOException;
@ -87,10 +88,16 @@ public class NacosConfigService implements ConfigService {
private void initNamespace(Properties properties) {
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>() {
@Override
public String call() {
return TenantUtil.getUserTenant();
return TenantUtil.getUserTenantForAcm();
}
});
@ -101,6 +108,7 @@ public class NacosConfigService implements ConfigService {
return StringUtils.isNotBlank(namespace) ? namespace : EMPTY;
}
});
}
if (StringUtils.isBlank(namespaceTmp)) {
namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);

View File

@ -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.ConfigResponse;
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.TenantUtil;
import org.slf4j.Logger;
import java.util.ArrayList;
@ -236,7 +236,7 @@ public class CacheData {
this.configFilterChainManager = configFilterChainManager;
this.dataId = dataId;
this.group = group;
this.tenant = TenantUtil.getUserTenant();
this.tenant = TenantUtil.getUserTenantForAcm();
listeners = new CopyOnWriteArrayList<ManagerListenerWrap>();
this.isInitializing = true;
this.content = loadCacheContentFromDiskLocal(name, dataId, group, tenant);

View File

@ -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.utils.ContentUtils;
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.utils.LogUtils;
import com.alibaba.nacos.client.utils.ParamUtil;
import com.alibaba.nacos.client.utils.StringUtils;
import com.alibaba.nacos.client.utils.TenantUtil;
import org.slf4j.Logger;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
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.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
import static com.alibaba.nacos.api.common.Constants.LINE_SEPARATOR;
@ -189,7 +179,7 @@ public class ClientWorker {
}
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) {

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.client.config.impl;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.SystemPropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.config.impl.EventDispatcher.ServerlistChangeEvent;
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
@ -180,7 +181,13 @@ public class ServerListManager {
}
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);
if (StringUtils.isNotBlank(endpointUrl)) {
serverAddrsStr = "";
@ -352,7 +359,7 @@ public class ServerListManager {
}
/**
* 不同环境的名称
* The name of the different environment
*/
private String name;
private String namespace = "";
@ -362,7 +369,7 @@ public class ServerListManager {
static public final String FIXED_NAME = "fixed";
private int initServerlistRetryTimes = 5;
/**
* 和其他server的连接超时和socket超时
* Connection timeout and socket timeout with other servers
*/
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> {

View File

@ -60,7 +60,7 @@ public class NacosNamingMaintainService implements NamingMaintainService {
}
private void init(Properties properties) {
namespace = InitUtils.initNamespace(properties);
namespace = InitUtils.initNamespaceForNaming(properties);
initServerAddr(properties);
InitUtils.initWebRootContext();

View File

@ -79,7 +79,7 @@ public class NacosNamingService implements NamingService {
}
private void init(Properties properties) {
namespace = InitUtils.initNamespace(properties);
namespace = InitUtils.initNamespaceForNaming(properties);
initServerAddr(properties);
InitUtils.initWebRootContext();
initCacheDir();

View File

@ -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.core.HostReactor;
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.utils.StringUtils;
import java.io.BufferedReader;
import java.io.File;

View 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.ServiceInfo;
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.File;

View 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.cache.DiskCache;
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.utils.StringUtils;
import java.util.*;
import java.util.concurrent.*;

View File

@ -17,7 +17,7 @@ package com.alibaba.nacos.client.naming.core;
import com.alibaba.fastjson.JSON;
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.DatagramSocket;

View File

@ -17,7 +17,7 @@ package com.alibaba.nacos.client.naming.net;
import com.alibaba.nacos.api.common.Constants;
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 java.io.IOException;

View File

@ -32,6 +32,7 @@ import com.alibaba.nacos.client.config.impl.SpasAdapter;
import com.alibaba.nacos.client.monitor.MetricsMonitor;
import com.alibaba.nacos.client.naming.beat.BeatInfo;
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.common.util.HttpMethod;
import com.alibaba.nacos.common.util.UuidUtils;
@ -298,7 +299,9 @@ public class NamingProxy {
public long sendBeat(BeatInfo beatInfo) {
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);
params.put("beat", JSON.toJSONString(beatInfo));
params.put(CommonParams.NAMESPACE_ID, namespaceId);

View File

@ -18,24 +18,56 @@ package com.alibaba.nacos.client.naming.utils;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.SystemPropertyKeyConst;
import com.alibaba.nacos.client.identify.CredentialService;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
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 com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.client.utils.*;
import java.util.Properties;
import java.util.concurrent.Callable;
/**
* @author liaochuntao
* @author deshao
*/
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 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>() {
@Override
public String call() {
@ -45,26 +77,7 @@ public class InitUtils {
}
});
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) {
if (StringUtils.isEmpty(tmpNamespace) && properties != null) {
tmpNamespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
}
@ -97,13 +110,18 @@ public class InitUtils {
return "";
}
// 是否开启域名解析规则
boolean isUseEndpointParsingRule = 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)));
boolean isUseEndpointParsingRule = Boolean.valueOf(isUseEndpointRuleParsing);
String endpointUrl;
if (isUseEndpointParsingRule) {
// 获取设置的域名信息
// Get the set domain name information
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 "";
}
} else {

View File

@ -16,6 +16,8 @@
package com.alibaba.nacos.client.naming.utils;
import com.alibaba.nacos.client.utils.StringUtils;
import java.io.*;
import java.nio.channels.FileChannel;
import java.util.ArrayList;

View File

@ -15,6 +15,8 @@
*/
package com.alibaba.nacos.client.naming.utils;
import com.alibaba.nacos.client.utils.StringUtils;
import java.net.InetAddress;
import java.net.UnknownHostException;

View File

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

View File

@ -33,7 +33,7 @@ public class ParamUtil {
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 String defaultContextPath = "nacos";

View File

@ -15,7 +15,11 @@
*/
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.Locale;
/**
* string util
@ -26,6 +30,8 @@ public class StringUtils {
public static final int INDEX_NOT_FOUND = -1;
public static final String EMPTY = "";
public static boolean isBlank(String str) {
int strLen;
if (str == null || (strLen = str.length()) == 0) {
@ -92,4 +98,106 @@ public class StringUtils {
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;
}
}
}
}
}

View File

@ -13,9 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.client.config.utils;
import com.alibaba.nacos.client.utils.StringUtils;
package com.alibaba.nacos.client.utils;
/**
* Tenant Util
@ -24,20 +22,42 @@ import com.alibaba.nacos.client.utils.StringUtils;
*/
public class TenantUtil {
private static String userTenant = "";
private static String userTenant;
static {
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)) {
userTenant = System.getProperty("acm.namespace", "");
}
tmp = System.getProperty("acm.namespace", "");
}
public static String getUserTenant() {
return userTenant;
return tmp;
}
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;
}
}

View File

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

View File

@ -18,7 +18,7 @@
<parent>
<artifactId>nacos-all</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>1.0.0</version>
<version>1.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -17,7 +17,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</parent>
<artifactId>nacos-console</artifactId>
<!--<packaging>war</packaging>-->

View File

@ -49,7 +49,7 @@ export default {
* 检测属性是否正确
*/
validateProperties(str = '') {
const reg = /^[^=]+=[^=]+$/;
const reg = /^[^=]+=.+$/;
return str
.replace('\n\r', '\n')
.split('\n')

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -74,7 +74,7 @@ public class ServerListManager {
GlobalExecutor.registerServerStatusReporter(new ServerStatusReporter(), 5000);
}
public List<Server> refreshServerList() {
private List<Server> refreshServerList() {
List<Server> result = new ArrayList<>();
@ -111,12 +111,12 @@ public class ServerListManager {
String ip;
int port;
if (serverList.get(0).contains(UtilsAndCommons.IP_PORT_SPLITER)) {
ip = serverList.get(i).split(UtilsAndCommons.IP_PORT_SPLITER)[0];
port = Integer.parseInt(serverList.get(i).split(UtilsAndCommons.IP_PORT_SPLITER)[1]);
String server = serverList.get(i);
if (server.contains(UtilsAndCommons.IP_PORT_SPLITER)) {
ip = server.split(UtilsAndCommons.IP_PORT_SPLITER)[0];
port = Integer.parseInt(server.split(UtilsAndCommons.IP_PORT_SPLITER)[1]);
} else {
ip = serverList.get(i);
ip = server;
port = RunningConfig.getServerPort();
}

View File

@ -148,22 +148,24 @@ public class CatalogController {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
Constants.DEFAULT_NAMESPACE_ID);
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
.getServiceMap(namespaceId)
.forEach(
(serviceName, service) -> {
List<Service> serviceList = new ArrayList<>(8);
serviceManager.getPagedService(namespaceId, pageNo, pageSize, keyword, StringUtils.EMPTY, serviceList);
for (Service service : serviceList) {
ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo();
serviceDetailInfo.setServiceName(NamingUtils.getServiceName(serviceName));
serviceDetailInfo.setGroupName(NamingUtils.getGroupName(serviceName));
serviceDetailInfo.setServiceName(NamingUtils.getServiceName(service.getName()));
serviceDetailInfo.setGroupName(NamingUtils.getGroupName(service.getName()));
serviceDetailInfo.setMetadata(service.getMetadata());
Map<String, ClusterInfo> clusterInfoMap = getStringClusterInfoMap(service);
serviceDetailInfo.setClusterMap(clusterInfoMap);
serviceDetailInfoList.add(serviceDetailInfo);
});
}
return serviceDetailInfoList;
} else {

View File

@ -31,6 +31,7 @@ import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.push.PushService;
import com.alibaba.nacos.naming.web.CanDistro;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
@ -96,6 +97,7 @@ public class HealthController {
throw new IllegalArgumentException("Param 'healthy' is required.");
}
valid = BooleanUtils.toBoolean(healthyString);
Service service = serviceManager.getService(namespaceId, serviceName);
// Only health check "none" need update health status with api

View File

@ -93,13 +93,9 @@ public class PushService {
try {
udpSocket = new DatagramSocket();
Receiver receiver;
Receiver receiver = new Receiver();
Thread inThread;
receiver = new Receiver();
inThread = new Thread(receiver);
Thread inThread = new Thread(receiver);
inThread.setDaemon(true);
inThread.setName("com.alibaba.nacos.naming.push.receiver");
inThread.start();

17
pom.xml
View File

@ -21,7 +21,7 @@
<inceptionYear>2018</inceptionYear>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>pom</packaging>
<name>Alibaba NACOS ${project.version}</name>
@ -36,7 +36,7 @@
<url>git@github.com:alibaba/nacos.git</url>
<connection>scm:git@github.com:alibaba/nacos.git</connection>
<developerConnection>scm:git@github.com:alibaba/nacos.git</developerConnection>
<tag>nacos-all-1.0.0</tag>
<tag>nacos-all-1.0.1</tag>
</scm>
<mailingLists>
@ -378,18 +378,6 @@
</plugin>
</plugins>
</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>
<id>it-test</id>
@ -738,5 +726,6 @@
</dependencies>
</dependencyManagement>
</project>

View File

@ -17,7 +17,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>