This commit is contained in:
commit
43a51c0f25
28
.github/ISSUE_TEMPLATE.md
vendored
Normal file
28
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
<!-- Here is for bug reports and feature requests ONLY!
|
||||
|
||||
If you're looking for help, please check our mail list、WeChat group and the Gitter room.
|
||||
|
||||
Please try to use English to describe your issue, or at least provide a snippet of English translation.
|
||||
我们鼓励使用英文,如果不能直接使用,可以使用翻译软件,您仍旧可以保留中文原文。
|
||||
-->
|
||||
|
||||
## Issue Description
|
||||
|
||||
Type: *bug report* or *feature request*
|
||||
|
||||
### Describe what happened (or what feature you want)
|
||||
|
||||
|
||||
### Describe what you expected to happen
|
||||
|
||||
|
||||
### How to reproduce it (as minimally and precisely as possible)
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
### Tell us your environment
|
||||
|
||||
|
||||
### Anything else we need to know?
|
43
.github/ISSUE_TEMPLATE/bug_report.md
vendored
43
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -1,43 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Describe this issue template's purpose here.
|
||||
|
||||
---
|
||||
|
||||
# Reporting bugs
|
||||
|
||||
If any part of the Nacos project has bugs or documentation mistakes, please let us know by [opening an issue](https://github.com/alibaba/nacos/issues/new). We treat bugs and mistakes very seriously and believe no issue is too small, anyOne is implement. Before creating a bug report, please check that an issue reporting the same problem does not already exist.
|
||||
|
||||
To make the bug report accurate and easy to understand, please try to create bug reports that are:
|
||||
|
||||
- Specific. Include as much details as possible: which version, what environment, what configuration, etc. If the bug is related to running the Nacos server, please attach the Nacos log (the starting log with Nacos configuration is especially important).
|
||||
|
||||
- Reproducible. Include the steps to reproduce the problem. We understand some issues might be hard to reproduce, please includes the steps that might lead to the problem. If possible, please attach the affected Nacos data dir and stack strace to the bug report.
|
||||
|
||||
- Unique. Do not duplicate existing bug report.
|
||||
|
||||
|
||||
It may be worthwhile to read [Elika Etemad’s article on filing good bug reports](http://fantasai.inkedblade.net/style/talks/filing-good-bugs/) before creating a bug report.
|
||||
|
||||
We might ask for further information to locate a bug. A duplicated bug report will be closed.
|
||||
|
||||
|
||||
|
||||
# 报告错误
|
||||
|
||||
如果Nacos项目的任何部分存在问题或文档问题,请通过[opening an issue](https://github.com/alibaba/nacos/issues/new)告诉我们。我们非常认真地对待错误和错误,在产品面前没有不重要的问题。不过在创建错误报告之前,请检查是否存在报告相同问题的issues。
|
||||
|
||||
为了使错误报告准确且易于理解,请尝试创建以下错误报告:
|
||||
|
||||
- 具体到细节。包括尽可能多的细节:哪个版本,什么环境,什么配置等。如果错误与运行Nacos服务器有关,请附加Nacos日志(具有Nacos配置的起始日志尤为重要)。
|
||||
|
||||
- 可复现。包括重现问题的步骤。我们理解某些问题可能难以重现,请包括可能导致问题的步骤。如果可能,请将受影响的Nacos数据目录和堆栈strace附加到错误报告中。
|
||||
|
||||
- 不重复。不要复制现有的错误报告。
|
||||
|
||||
在创建错误报告之前,最好阅读下[Elika Etemad关于提交好错误报告的文章](http://fantasai.inkedblade.net/style/talks/filing-good-bugs/),相信 会给你启发。
|
||||
|
||||
我们可能会要求您提供更多信息以查找错误。将关闭重复的错误报告。
|
||||
|
||||
[nacos-issue](https://github.com/alibaba/nacos/issues/new)
|
||||
[filing-good-bugs](http://fantasai.inkedblade.net/style/talks/filing-good-bugs/)
|
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -1,17 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
16
CHANGELOG.md
16
CHANGELOG.md
@ -1,3 +1,19 @@
|
||||
## 0.9.0(Feb 28, 2019)
|
||||
|
||||
* [#840] Nacos server adds startup mode to distinguish between config and naming.
|
||||
* [#762] Register instance returns failed when the health check mode is 'server' in standalone mode.
|
||||
* [#473] Nacos Cluster Mode kubernate Startup nacos.log error Log.
|
||||
* [#240] Log strong dependence problem.
|
||||
* [#824] getServicesOfServer throws exception if service list is empty.
|
||||
* [#802] Nacos server multi-boot mode support.
|
||||
* [#800] Nacos's client-to-server addressing mode document introduction.
|
||||
* [#768] The interval at which the heartbeat is sent in BeatReactor is not controlled by the server return value.
|
||||
* [#759] why instance can't auto-delete.
|
||||
* [#756] Format of instance and service should be validated.
|
||||
* [#720] Memory leak in PushService.
|
||||
* [#653] IoUtils under nacos-common-0.2.1-RC1.jar lacks "" judgment on encoding.
|
||||
* [#588] Client compatible to jdk1.6.
|
||||
|
||||
## 0.8.0(Jan 22, 2019) PRE-GA
|
||||
|
||||
* [#162] Support open metrics and prometheus
|
||||
|
@ -40,9 +40,9 @@ It is super easy to get started with your first project.
|
||||
|
||||
You can download the package from the [latest stable release](https://github.com/alibaba/nacos/releases).
|
||||
|
||||
Take release nacos-server-0.8.0.zip for example.
|
||||
Take release nacos-server-0.9.0.zip for example.
|
||||
```
|
||||
unzip nacos-server-0.8.0.zip
|
||||
unzip nacos-server-0.9.0.zip
|
||||
cd nacos/bin
|
||||
```
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -32,8 +32,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
<source>6</source>
|
||||
<target>6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -24,6 +24,8 @@ public class PropertyKeyConst {
|
||||
|
||||
public final static String ENDPOINT = "endpoint";
|
||||
|
||||
public final static String ENDPOINT_PORT = "endpointPort";
|
||||
|
||||
public final static String NAMESPACE = "namespace";
|
||||
|
||||
public final static String ACCESS_KEY = "accessKey";
|
||||
@ -39,7 +41,17 @@ public class PropertyKeyConst {
|
||||
public final static String ENCODE = "encode";
|
||||
|
||||
public final static String NAMING_LOAD_CACHE_AT_START = "namingLoadCacheAtStart";
|
||||
|
||||
public final static String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
|
||||
|
||||
public final static String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";
|
||||
|
||||
public static class SystemEnv {
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_PORT = "ALIBABA_ALIWARE_ENDPOINT_PORT";
|
||||
|
||||
public static final String ALIBABA_ALIWARE_NAMESPACE = "ALIBABA_ALIWARE_NAMESPACE";
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_URL = "ALIBABA_ALIWARE_ENDPOINT_URL";
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -113,4 +113,16 @@
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>6</source>
|
||||
<target>6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -73,19 +73,27 @@ public class NacosConfigService implements ConfigService {
|
||||
} else {
|
||||
encode = encodeTmp.trim();
|
||||
}
|
||||
String namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
if (StringUtils.isBlank(namespaceTmp)) {
|
||||
namespace = TenantUtil.getUserTenant();
|
||||
properties.put(PropertyKeyConst.NAMESPACE, namespace);
|
||||
} else {
|
||||
namespace = namespaceTmp;
|
||||
properties.put(PropertyKeyConst.NAMESPACE, namespace);
|
||||
}
|
||||
initNamespace(properties);
|
||||
agent = new MetricsHttpAgent(new ServerHttpAgent(properties));
|
||||
agent.start();
|
||||
worker = new ClientWorker(agent, configFilterChainManager);
|
||||
}
|
||||
|
||||
private void initNamespace(Properties properties) {
|
||||
String namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
|
||||
if (StringUtils.isBlank(namespaceTmp)) {
|
||||
namespaceTmp = TenantUtil.getUserTenant();
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(namespaceTmp)) {
|
||||
namespaceTmp = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE);
|
||||
}
|
||||
|
||||
namespace = namespaceTmp;
|
||||
properties.put(PropertyKeyConst.NAMESPACE, namespace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfig(String dataId, String group, long timeoutMs) throws NacosException {
|
||||
return getConfigInner(namespace, dataId, group, timeoutMs);
|
||||
|
@ -24,6 +24,7 @@ import com.alibaba.nacos.client.config.impl.ServerListManager;
|
||||
import com.alibaba.nacos.client.config.impl.SpasAdapter;
|
||||
import com.alibaba.nacos.client.config.utils.IOUtils;
|
||||
import com.alibaba.nacos.client.identify.STSConfig;
|
||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||
import com.alibaba.nacos.client.utils.JSONUtils;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
@ -41,6 +42,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Server Agent
|
||||
@ -197,29 +199,29 @@ public class ServerHttpAgent implements HttpAgent {
|
||||
|
||||
public ServerHttpAgent(ServerListManager mgr, Properties properties) {
|
||||
serverListMgr = mgr;
|
||||
String ak = properties.getProperty(PropertyKeyConst.ACCESS_KEY);
|
||||
if (StringUtils.isBlank(ak)) {
|
||||
accessKey = SpasAdapter.getAk();
|
||||
} else {
|
||||
accessKey = ak;
|
||||
}
|
||||
|
||||
String sk = properties.getProperty(PropertyKeyConst.SECRET_KEY);
|
||||
if (StringUtils.isBlank(sk)) {
|
||||
secretKey = SpasAdapter.getSk();
|
||||
} else {
|
||||
secretKey = sk;
|
||||
}
|
||||
init(properties);
|
||||
}
|
||||
|
||||
public ServerHttpAgent(Properties properties) throws NacosException {
|
||||
String encodeTmp = properties.getProperty(PropertyKeyConst.ENCODE);
|
||||
if (StringUtils.isBlank(encodeTmp)) {
|
||||
encode = Constants.ENCODE;
|
||||
} else {
|
||||
encode = encodeTmp.trim();
|
||||
}
|
||||
serverListMgr = new ServerListManager(properties);
|
||||
init(properties);
|
||||
}
|
||||
|
||||
private void init(Properties properties) {
|
||||
initEncode(properties);
|
||||
initAkSk(properties);
|
||||
}
|
||||
|
||||
private void initEncode(Properties properties) {
|
||||
encode = TemplateUtils.stringEmptyAndThenExecute(properties.getProperty(PropertyKeyConst.ENCODE), new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
return Constants.ENCODE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initAkSk(Properties properties) {
|
||||
String ak = properties.getProperty(PropertyKeyConst.ACCESS_KEY);
|
||||
if (StringUtils.isBlank(ak)) {
|
||||
accessKey = SpasAdapter.getAk();
|
||||
@ -273,8 +275,9 @@ public class ServerHttpAgent implements HttpAgent {
|
||||
}
|
||||
}
|
||||
String stsResponse = getSTSResponse();
|
||||
STSCredential stsCredentialTmp = (STSCredential)JSONUtils.deserializeObject(stsResponse,
|
||||
new TypeReference<STSCredential>() {});
|
||||
STSCredential stsCredentialTmp = (STSCredential) JSONUtils.deserializeObject(stsResponse,
|
||||
new TypeReference<STSCredential>() {
|
||||
});
|
||||
sTSCredential = stsCredentialTmp;
|
||||
LOGGER.info("[getSTSCredential] code:{}, accessKeyId:{}, lastUpdated:{}, expiration:{}", sTSCredential.getCode(),
|
||||
sTSCredential.getAccessKeyId(), sTSCredential.getLastUpdated(), sTSCredential.getExpiration());
|
||||
@ -291,7 +294,7 @@ public class ServerHttpAgent implements HttpAgent {
|
||||
int respCode;
|
||||
String response;
|
||||
try {
|
||||
conn = (HttpURLConnection)new URL(securityCredentialsUrl).openConnection();
|
||||
conn = (HttpURLConnection) new URL(securityCredentialsUrl).openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(ParamUtil.getConnectTimeout() > 100 ? ParamUtil.getConnectTimeout() : 100);
|
||||
conn.setReadTimeout(1000);
|
||||
|
@ -20,6 +20,7 @@ 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;
|
||||
import com.alibaba.nacos.client.config.utils.IOUtils;
|
||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||
import com.alibaba.nacos.client.utils.EnvUtil;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
@ -30,12 +31,8 @@ import org.slf4j.Logger;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -93,6 +90,8 @@ public class ServerListManager {
|
||||
public ServerListManager(String endpoint, String namespace) throws NacosException {
|
||||
isFixed = false;
|
||||
isStarted = false;
|
||||
endpoint = initEndpoint(endpoint);
|
||||
|
||||
if (StringUtils.isBlank(endpoint)) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, "endpoint is blank");
|
||||
}
|
||||
@ -158,10 +157,8 @@ public class ServerListManager {
|
||||
}
|
||||
|
||||
private void initParam(Properties properties) {
|
||||
String endpointTmp = properties.getProperty(PropertyKeyConst.ENDPOINT);
|
||||
if (!StringUtils.isBlank(endpointTmp)) {
|
||||
endpoint = endpointTmp;
|
||||
}
|
||||
endpoint = initEndpoint(properties.getProperty(PropertyKeyConst.ENDPOINT));
|
||||
|
||||
String contentPathTmp = properties.getProperty(PropertyKeyConst.CONTEXT_PATH);
|
||||
if (!StringUtils.isBlank(contentPathTmp)) {
|
||||
contentPath = contentPathTmp;
|
||||
@ -172,6 +169,20 @@ public class ServerListManager {
|
||||
}
|
||||
}
|
||||
|
||||
private String initEndpoint(String endpointTmp) {
|
||||
String endpointPortTmp = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_PORT);
|
||||
if (StringUtils.isNotEmpty(endpointPortTmp)) {
|
||||
endpointPort = Integer.parseInt(endpointPortTmp);
|
||||
}
|
||||
|
||||
return TemplateUtils.stringBlankAndThenExecute(endpointTmp, new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
return System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void start() throws NacosException {
|
||||
|
||||
if (isStarted || isFixed) {
|
||||
|
@ -15,20 +15,16 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.identify;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.Properties;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import com.alibaba.nacos.client.config.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.logger.Logger;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Credential Watcher
|
||||
*
|
||||
@ -95,14 +91,14 @@ public class CredentialWatcher {
|
||||
SpasLogger.info("[{}] {} is stopped", appName, this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
private void loadCredential(boolean init) {
|
||||
boolean logWarn = init;
|
||||
if (propertyPath == null) {
|
||||
URL url = ClassLoader.getSystemResource(Constants.PROPERTIES_FILENAME);
|
||||
if (url != null) {
|
||||
propertyPath = url.getPath();
|
||||
}
|
||||
if (propertyPath == null || propertyPath.isEmpty()) {
|
||||
private void loadCredential(boolean init) {
|
||||
boolean logWarn = init;
|
||||
if (propertyPath == null) {
|
||||
URL url = ClassLoader.getSystemResource(Constants.PROPERTIES_FILENAME);
|
||||
if (url != null) {
|
||||
propertyPath = url.getPath();
|
||||
}
|
||||
if (propertyPath == null || propertyPath.isEmpty()) {
|
||||
|
||||
String value = System.getProperty("spas.identity");
|
||||
if (StringUtils.isNotEmpty(value)) {
|
||||
@ -143,6 +139,7 @@ public class CredentialWatcher {
|
||||
|
||||
String accessKey = null;
|
||||
String secretKey = null;
|
||||
String tenantId = null;
|
||||
if (propertiesIS == null) {
|
||||
propertyPath = null;
|
||||
accessKey = System.getenv(Constants.ENV_ACCESS_KEY);
|
||||
@ -175,30 +172,29 @@ public class CredentialWatcher {
|
||||
SpasLogger.info(appName, "Load credential file " + propertyPath);
|
||||
}
|
||||
|
||||
if (!Constants.DOCKER_CREDENTIAL_PATH.equals(propertyPath)) {
|
||||
if (properties.containsKey(Constants.ACCESS_KEY)) {
|
||||
accessKey = properties.getProperty(Constants.ACCESS_KEY);
|
||||
}
|
||||
if (properties.containsKey(Constants.SECRET_KEY)) {
|
||||
secretKey = properties.getProperty(Constants.SECRET_KEY);
|
||||
}
|
||||
if (properties.containsKey(Constants.TENANT_ID)) {
|
||||
tenantId = properties.getProperty(Constants.TENANT_ID);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (properties.containsKey(Constants.DOCKER_ACCESS_KEY)) {
|
||||
accessKey = properties.getProperty(Constants.DOCKER_ACCESS_KEY);
|
||||
}
|
||||
if (properties.containsKey(Constants.DOCKER_SECRET_KEY)) {
|
||||
secretKey = properties.getProperty(Constants.DOCKER_SECRET_KEY);
|
||||
}
|
||||
if (!Constants.DOCKER_CREDENTIAL_PATH.equals(propertyPath)) {
|
||||
if (properties.containsKey(Constants.ACCESS_KEY)) {
|
||||
accessKey = properties.getProperty(Constants.ACCESS_KEY);
|
||||
}
|
||||
if (properties.containsKey(Constants.SECRET_KEY)) {
|
||||
secretKey = properties.getProperty(Constants.SECRET_KEY);
|
||||
}
|
||||
if (properties.containsKey(Constants.TENANT_ID)) {
|
||||
tenantId = properties.getProperty(Constants.TENANT_ID);
|
||||
}
|
||||
} else {
|
||||
if (properties.containsKey(Constants.DOCKER_ACCESS_KEY)) {
|
||||
accessKey = properties.getProperty(Constants.DOCKER_ACCESS_KEY);
|
||||
}
|
||||
if (properties.containsKey(Constants.DOCKER_SECRET_KEY)) {
|
||||
secretKey = properties.getProperty(Constants.DOCKER_SECRET_KEY);
|
||||
}
|
||||
|
||||
if (properties.containsKey(Constants.DOCKER_TENANT_ID)) {
|
||||
tenantId = properties.getProperty(Constants.DOCKER_TENANT_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (properties.containsKey(Constants.DOCKER_TENANT_ID)) {
|
||||
tenantId = properties.getProperty(Constants.DOCKER_TENANT_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (accessKey != null) {
|
||||
accessKey = accessKey.trim();
|
||||
@ -207,7 +203,11 @@ public class CredentialWatcher {
|
||||
secretKey = secretKey.trim();
|
||||
}
|
||||
|
||||
Credentials credential = new Credentials(accessKey, secretKey);
|
||||
if (tenantId != null) {
|
||||
tenantId = tenantId.trim();
|
||||
}
|
||||
|
||||
Credentials credential = new Credentials(accessKey, secretKey, tenantId);
|
||||
if (!credential.valid()) {
|
||||
SpasLogger.warn("1", "Credential file missing required property" + appName + "Credential file missing "
|
||||
+ Constants.ACCESS_KEY + " or " + Constants.SECRET_KEY);
|
||||
|
@ -23,7 +23,7 @@ import com.alibaba.nacos.common.util.ResourceUtils;
|
||||
import org.slf4j.impl.StaticLoggerBinder;
|
||||
|
||||
/**
|
||||
* Support for Logback version 0.9.19 or higher
|
||||
* Support for Logback version 1.0.8 or higher
|
||||
*
|
||||
* @author <a href="mailto:huangxiaoyu1018@gmail.com">hxy1991</a>
|
||||
* @since 0.9.0
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.alibaba.nacos.client.naming;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.SystemPropertyKeyConst;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
@ -24,6 +25,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.pojo.ListView;
|
||||
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
|
||||
import com.alibaba.nacos.api.selector.AbstractSelector;
|
||||
import com.alibaba.nacos.client.identify.CredentialService;
|
||||
import com.alibaba.nacos.client.naming.beat.BeatInfo;
|
||||
import com.alibaba.nacos.client.naming.beat.BeatReactor;
|
||||
import com.alibaba.nacos.client.naming.core.Balancer;
|
||||
@ -31,9 +33,10 @@ import com.alibaba.nacos.client.naming.core.EventDispatcher;
|
||||
import com.alibaba.nacos.client.naming.core.HostReactor;
|
||||
import com.alibaba.nacos.client.naming.net.NamingProxy;
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
@ -41,13 +44,13 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:zpf.073@gmail.com">nkorange</a>
|
||||
*/
|
||||
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
|
||||
public class NacosNamingService implements NamingService {
|
||||
|
||||
/**
|
||||
* Each Naming instance should have different namespace.
|
||||
*/
|
||||
@ -69,88 +72,181 @@ public class NacosNamingService implements NamingService {
|
||||
|
||||
private NamingProxy serverProxy;
|
||||
|
||||
private void init() {
|
||||
public NacosNamingService(String serverList) {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(PropertyKeyConst.SERVER_ADDR, serverList);
|
||||
|
||||
namespace = System.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
init(properties);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(namespace)) {
|
||||
namespace = UtilAndComs.DEFAULT_NAMESPACE_ID;
|
||||
public NacosNamingService(Properties properties) {
|
||||
|
||||
init(properties);
|
||||
}
|
||||
|
||||
private void init(Properties properties) {
|
||||
|
||||
serverList = properties.getProperty(PropertyKeyConst.SERVER_ADDR);
|
||||
|
||||
initNamespace(properties);
|
||||
initEndpoint(properties);
|
||||
initWebRootContext();
|
||||
initCacheDir();
|
||||
initLogName(properties);
|
||||
|
||||
eventDispatcher = new EventDispatcher();
|
||||
serverProxy = new NamingProxy(namespace, endpoint, serverList);
|
||||
serverProxy.setProperties(properties);
|
||||
beatReactor = new BeatReactor(serverProxy, clientBeatThreadCount(properties));
|
||||
hostReactor = new HostReactor(eventDispatcher, serverProxy, cacheDir, isLoadCacheAtStart(properties), pollingThreadCount(properties));
|
||||
}
|
||||
|
||||
private int clientBeatThreadCount(Properties properties) {
|
||||
if (properties == null) {
|
||||
|
||||
return UtilAndComs.DEFAULT_CLIENT_BEAT_THREAD_COUNT;
|
||||
}
|
||||
|
||||
int clientBeatThreadCount = NumberUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_CLIENT_BEAT_THREAD_COUNT),
|
||||
UtilAndComs.DEFAULT_CLIENT_BEAT_THREAD_COUNT);
|
||||
|
||||
return clientBeatThreadCount;
|
||||
}
|
||||
|
||||
private int pollingThreadCount(Properties properties) {
|
||||
if (properties == null) {
|
||||
|
||||
return UtilAndComs.DEFAULT_POLLING_THREAD_COUNT;
|
||||
}
|
||||
|
||||
int pollingThreadCount = NumberUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_POLLING_THREAD_COUNT),
|
||||
UtilAndComs.DEFAULT_POLLING_THREAD_COUNT);
|
||||
|
||||
return pollingThreadCount;
|
||||
}
|
||||
|
||||
private boolean isLoadCacheAtStart(Properties properties) {
|
||||
boolean loadCacheAtStart = false;
|
||||
if (properties != null && StringUtils.isNotEmpty(properties.getProperty(PropertyKeyConst.NAMING_LOAD_CACHE_AT_START))) {
|
||||
loadCacheAtStart = BooleanUtils.toBoolean(
|
||||
properties.getProperty(PropertyKeyConst.NAMING_LOAD_CACHE_AT_START));
|
||||
}
|
||||
|
||||
return loadCacheAtStart;
|
||||
}
|
||||
|
||||
private void initLogName(Properties properties) {
|
||||
logName = System.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME);
|
||||
if (StringUtils.isEmpty(logName)) {
|
||||
logName = "naming.log";
|
||||
}
|
||||
|
||||
if (properties != null && StringUtils.isNotEmpty(properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME))) {
|
||||
logName = properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME);
|
||||
} else {
|
||||
logName = "naming.log";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initCacheDir() {
|
||||
cacheDir = System.getProperty("com.alibaba.nacos.naming.cache.dir");
|
||||
if (StringUtils.isEmpty(cacheDir)) {
|
||||
cacheDir = System.getProperty("user.home") + "/nacos/naming/" + namespace;
|
||||
}
|
||||
}
|
||||
|
||||
public NacosNamingService(String serverList) {
|
||||
private void initEndpoint(Properties properties) {
|
||||
if (properties == null) {
|
||||
|
||||
this.serverList = serverList;
|
||||
init();
|
||||
eventDispatcher = new EventDispatcher();
|
||||
serverProxy = new NamingProxy(namespace, endpoint, serverList);
|
||||
beatReactor = new BeatReactor(serverProxy);
|
||||
hostReactor = new HostReactor(eventDispatcher, serverProxy, cacheDir);
|
||||
return;
|
||||
}
|
||||
|
||||
String endpointUrl = TemplateUtils.stringEmptyAndThenExecute(properties.getProperty(PropertyKeyConst.ENDPOINT), new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
return System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL);
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtils.isEmpty(endpointUrl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String endpointPort = TemplateUtils.stringEmptyAndThenExecute(properties.getProperty(PropertyKeyConst.ENDPOINT_PORT), new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
|
||||
return System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_PORT);
|
||||
}
|
||||
});
|
||||
endpointPort = TemplateUtils.stringEmptyAndThenExecute(endpointPort, new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
return "8080";
|
||||
}
|
||||
});
|
||||
|
||||
endpoint = endpointUrl + ":" + endpointPort;
|
||||
}
|
||||
|
||||
public NacosNamingService(Properties properties) {
|
||||
private void initNamespace(Properties properties) {
|
||||
String tmpNamespace = null;
|
||||
|
||||
init();
|
||||
|
||||
serverList = properties.getProperty(PropertyKeyConst.SERVER_ADDR);
|
||||
|
||||
if (StringUtils.isNotEmpty(properties.getProperty(PropertyKeyConst.NAMESPACE))) {
|
||||
namespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
if (properties != null) {
|
||||
tmpNamespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME))) {
|
||||
logName = properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME);
|
||||
}
|
||||
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
String namespace = System.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
LogUtils.NAMING_LOGGER.info("initializer namespace from System Property :" + namespace);
|
||||
return namespace;
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtils.isNotEmpty(properties.getProperty(PropertyKeyConst.ENDPOINT))) {
|
||||
endpoint = properties.getProperty(PropertyKeyConst.ENDPOINT) + ":" +
|
||||
properties.getProperty("address.server.port", "8080");
|
||||
}
|
||||
|
||||
initWebRootContext();
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
cacheDir = System.getProperty("user.home") + "/nacos/naming/" + namespace;
|
||||
|
||||
boolean loadCacheAtStart = false;
|
||||
if (StringUtils.isNotEmpty(properties.getProperty(PropertyKeyConst.NAMING_LOAD_CACHE_AT_START))) {
|
||||
loadCacheAtStart = BooleanUtils.toBoolean(
|
||||
properties.getProperty(PropertyKeyConst.NAMING_LOAD_CACHE_AT_START));
|
||||
}
|
||||
|
||||
int clientBeatThreadCount = NumberUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_CLIENT_BEAT_THREAD_COUNT),
|
||||
UtilAndComs.DEFAULT_CLIENT_BEAT_THREAD_COUNT);
|
||||
|
||||
int pollingThreadCount = NumberUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_POLLING_THREAD_COUNT),
|
||||
UtilAndComs.DEFAULT_POLLING_THREAD_COUNT);
|
||||
|
||||
eventDispatcher = new EventDispatcher();
|
||||
serverProxy = new NamingProxy(namespace, endpoint, serverList);
|
||||
beatReactor = new BeatReactor(serverProxy, clientBeatThreadCount);
|
||||
hostReactor = new HostReactor(eventDispatcher, serverProxy, cacheDir,
|
||||
loadCacheAtStart, pollingThreadCount);
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
return UtilAndComs.DEFAULT_NAMESPACE_ID;
|
||||
}
|
||||
});
|
||||
namespace = tmpNamespace;
|
||||
}
|
||||
|
||||
private void initWebRootContext() {
|
||||
// support the web context with ali-yun if the app deploy by EDAS
|
||||
String webContext = System.getProperties().getProperty(SystemPropertyKeyConst.NAMING_WEB_CONTEXT);
|
||||
String webContext = System.getProperty(SystemPropertyKeyConst.NAMING_WEB_CONTEXT);
|
||||
boolean isSetting = false;
|
||||
if (StringUtils.isNotEmpty(webContext)) {
|
||||
UtilAndComs.WEB_CONTEXT = webContext.indexOf("/") > -1 ? webContext
|
||||
: "/" + webContext;
|
||||
|
||||
isSetting = true;
|
||||
}
|
||||
|
||||
UtilAndComs.NACOS_URL_BASE = UtilAndComs.WEB_CONTEXT + "/v1/ns";
|
||||
UtilAndComs.NACOS_URL_INSTANCE = UtilAndComs.NACOS_URL_BASE + "/instance";
|
||||
if (isSetting) {
|
||||
UtilAndComs.NACOS_URL_BASE = UtilAndComs.WEB_CONTEXT + "/v1/ns";
|
||||
UtilAndComs.NACOS_URL_INSTANCE = UtilAndComs.NACOS_URL_BASE + "/instance";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -213,7 +309,8 @@ public class NacosNamingService implements NamingService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instance> getAllInstances(String serviceName, List<String> clusters, boolean subscribe) throws NacosException {
|
||||
public List<Instance> getAllInstances(String serviceName, List<String> clusters, boolean subscribe) throws
|
||||
NacosException {
|
||||
|
||||
ServiceInfo serviceInfo;
|
||||
if (subscribe) {
|
||||
@ -272,7 +369,8 @@ public class NacosNamingService implements NamingService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instance selectOneHealthyInstance(String serviceName, List<String> clusters, boolean subscribe) throws NacosException {
|
||||
public Instance selectOneHealthyInstance(String serviceName, List<String> clusters, boolean subscribe) throws
|
||||
NacosException {
|
||||
|
||||
if (subscribe) {
|
||||
return Balancer.RandomByWeight.selectHost(
|
||||
@ -311,7 +409,8 @@ public class NacosNamingService implements NamingService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListView<String> getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector) throws NacosException {
|
||||
public ListView<String> getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector) throws
|
||||
NacosException {
|
||||
return serverProxy.getServiceList(pageNo, pageSize, selector);
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class FailoverReactor {
|
||||
new DiskFileWriter().run();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
NAMING_LOGGER.error("NA", "failed to backup file on startup.", e);
|
||||
NAMING_LOGGER.error("[NA] failed to backup file on startup.", e);
|
||||
}
|
||||
|
||||
}
|
||||
@ -137,7 +137,7 @@ public class FailoverReactor {
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
NAMING_LOGGER.error("NA", "failed to read failover switch.", e);
|
||||
NAMING_LOGGER.error("[NA] failed to read failover switch.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,12 +182,12 @@ public class FailoverReactor {
|
||||
try {
|
||||
dom = JSON.parseObject(json, ServiceInfo.class);
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("NA", "error while parsing cached dom : " + json, e);
|
||||
NAMING_LOGGER.error("[NA] error while parsing cached dom : " + json, e);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("NA", "failed to read cache for dom: " + file.getName(), e);
|
||||
NAMING_LOGGER.error("[NA] failed to read cache for dom: " + file.getName(), e);
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
@ -202,7 +202,7 @@ public class FailoverReactor {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("NA", "failed to read cache file", e);
|
||||
NAMING_LOGGER.error("[NA] failed to read cache file", e);
|
||||
}
|
||||
|
||||
if (domMap.size() > 0) {
|
||||
|
@ -59,13 +59,13 @@ public class BeatReactor {
|
||||
}
|
||||
|
||||
public void addBeatInfo(String dom, BeatInfo beatInfo) {
|
||||
NAMING_LOGGER.info("BEAT", "adding beat: {} to beat map.", beatInfo);
|
||||
NAMING_LOGGER.info("[BEAT] adding beat: {} to beat map.", beatInfo);
|
||||
dom2Beat.put(buildKey(dom, beatInfo.getIp(), beatInfo.getPort()), beatInfo);
|
||||
MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size());
|
||||
}
|
||||
|
||||
public void removeBeatInfo(String dom, String ip, int port) {
|
||||
NAMING_LOGGER.info("BEAT", "removing beat: {}:{}:{} from beat map.", dom, ip, port);
|
||||
NAMING_LOGGER.info("[BEAT] removing beat: {}:{}:{} from beat map.", dom, ip, port);
|
||||
dom2Beat.remove(buildKey(dom, ip, port));
|
||||
MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size());
|
||||
}
|
||||
@ -88,7 +88,7 @@ public class BeatReactor {
|
||||
executorService.schedule(new BeatTask(beatInfo), 0, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("CLIENT-BEAT", "Exception while scheduling beat.", e);
|
||||
NAMING_LOGGER.error("[CLIENT-BEAT] Exception while scheduling beat.", e);
|
||||
} finally {
|
||||
executorService.schedule(this, clientBeatInterval, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class DiskCache {
|
||||
ConcurrentDiskUtil.writeFileContent(file, keyContentBuffer.toString(), Charset.defaultCharset().toString());
|
||||
|
||||
} catch (Throwable e) {
|
||||
NAMING_LOGGER.error("NA", "failed to write cache for dom:" + dom.getName(), e);
|
||||
NAMING_LOGGER.error("[NA] failed to write cache for dom:" + dom.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,11 +119,11 @@ public class DiskCache {
|
||||
ips.add(JSON.parseObject(json, Instance.class));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
NAMING_LOGGER.error("NA", "error while parsing cache file: " + json, e);
|
||||
NAMING_LOGGER.error("[NA] error while parsing cache file: " + json, e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("NA", "failed to read cache for dom: " + file.getName(), e);
|
||||
NAMING_LOGGER.error("[NA] failed to read cache for dom: " + file.getName(), e);
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
@ -143,7 +143,7 @@ public class DiskCache {
|
||||
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
NAMING_LOGGER.error("NA", "failed to read cache file", e);
|
||||
NAMING_LOGGER.error("[NA] failed to read cache file", e);
|
||||
}
|
||||
|
||||
return domMap;
|
||||
|
@ -58,7 +58,7 @@ public class EventDispatcher {
|
||||
|
||||
public void addListener(ServiceInfo serviceInfo, String clusters, EventListener listener) {
|
||||
|
||||
NAMING_LOGGER.info("LISTENER", "adding " + serviceInfo.getName() + " with " + clusters + " to listener map");
|
||||
NAMING_LOGGER.info("[LISTENER] adding " + serviceInfo.getName() + " with " + clusters + " to listener map");
|
||||
List<EventListener> observers = Collections.synchronizedList(new ArrayList<EventListener>());
|
||||
observers.add(listener);
|
||||
|
||||
@ -72,7 +72,7 @@ public class EventDispatcher {
|
||||
|
||||
public void removeListener(String serviceName, String clusters, EventListener listener) {
|
||||
|
||||
NAMING_LOGGER.info("LISTENER", "removing " + serviceName + " with " + clusters + " from listener map");
|
||||
NAMING_LOGGER.info("[LISTENER] removing " + serviceName + " with " + clusters + " from listener map");
|
||||
|
||||
List<EventListener> observers = observerMap.get(ServiceInfo.getKey(serviceName, clusters));
|
||||
if (observers != null) {
|
||||
@ -130,7 +130,7 @@ public class EventDispatcher {
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("NA", "notify error for service: "
|
||||
NAMING_LOGGER.error("[NA] notify error for service: "
|
||||
+ serviceInfo.getName() + ", clusters: " + serviceInfo.getClusters(), e);
|
||||
}
|
||||
}
|
||||
|
@ -241,8 +241,7 @@ public class HostReactor {
|
||||
try {
|
||||
serviceObj.wait(updateHoldInterval);
|
||||
} catch (InterruptedException e) {
|
||||
NAMING_LOGGER.error("[getServiceInfo]",
|
||||
"serviceName:" + serviceName + ", clusters:" + clusters, e);
|
||||
NAMING_LOGGER.error("[getServiceInfo] serviceName:" + serviceName + ", clusters:" + clusters, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -278,7 +277,7 @@ public class HostReactor {
|
||||
processServiceJSON(result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("NA", "failed to update serviceName: " + serviceName, e);
|
||||
NAMING_LOGGER.error("[NA] failed to update serviceName: " + serviceName, e);
|
||||
} finally {
|
||||
if (oldService != null) {
|
||||
synchronized (oldService) {
|
||||
@ -292,7 +291,7 @@ public class HostReactor {
|
||||
try {
|
||||
serverProxy.queryList(serviceName, clusters, pushReceiver.getUDPPort(), false);
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("NA", "failed to update serviceName: " + serviceName, e);
|
||||
NAMING_LOGGER.error("[NA] failed to update serviceName: " + serviceName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,7 +329,7 @@ public class HostReactor {
|
||||
|
||||
lastRefTime = serviceObj.getLastRefTime();
|
||||
} catch (Throwable e) {
|
||||
NAMING_LOGGER.warn("NA", "failed to update serviceName: " + serviceName, e);
|
||||
NAMING_LOGGER.warn("[NA] failed to update serviceName: " + serviceName, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class PushReceiver implements Runnable {
|
||||
|
||||
executorService.execute(this);
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("NA", "init udp socket failed", e);
|
||||
NAMING_LOGGER.error("[NA] init udp socket failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ public class PushReceiver implements Runnable {
|
||||
udpSocket.send(new DatagramPacket(ack.getBytes(Charset.forName("UTF-8")),
|
||||
ack.getBytes(Charset.forName("UTF-8")).length, packet.getSocketAddress()));
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("NA", "error while receiving push data", e);
|
||||
NAMING_LOGGER.error("[NA] error while receiving push data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
package com.alibaba.nacos.client.naming.net;
|
||||
|
||||
import com.alibaba.nacos.client.naming.utils.IoUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
|
||||
@ -30,7 +29,7 @@ import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static com.alibaba.nacos.client.utils.LogUtils.*;
|
||||
import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:zpf.073@gmail.com">nkorange</a>
|
||||
@ -96,11 +95,11 @@ public class HttpClient {
|
||||
+ InetAddress.getByName(conn.getURL().getHost()).getHostAddress());
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
NAMING_LOGGER.error("NA", "failed to request ", e1);
|
||||
NAMING_LOGGER.error("[NA] failed to request ", e1);
|
||||
//ignore
|
||||
}
|
||||
|
||||
NAMING_LOGGER.error("NA", "failed to request ", e);
|
||||
NAMING_LOGGER.error("[NA] failed to request ", e);
|
||||
|
||||
return new HttpResult(500, e.toString(), Collections.<String, String>emptyMap());
|
||||
} finally {
|
||||
|
@ -18,6 +18,7 @@ package com.alibaba.nacos.client.naming.net;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.SystemPropertyKeyConst;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
@ -26,31 +27,19 @@ import com.alibaba.nacos.api.naming.pojo.ListView;
|
||||
import com.alibaba.nacos.api.selector.AbstractSelector;
|
||||
import com.alibaba.nacos.api.selector.ExpressionSelector;
|
||||
import com.alibaba.nacos.api.selector.SelectorType;
|
||||
import com.alibaba.nacos.client.identify.CredentialService;
|
||||
import com.alibaba.nacos.client.config.impl.SpasAdapter;
|
||||
import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
||||
import com.alibaba.nacos.client.naming.SignUtil;
|
||||
import com.alibaba.nacos.client.naming.beat.BeatInfo;
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.IoUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.NetUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import com.alibaba.nacos.client.naming.utils.*;
|
||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||
import com.alibaba.nacos.common.util.HttpMethod;
|
||||
import com.alibaba.nacos.common.util.UuidUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||
|
||||
@ -77,15 +66,12 @@ public class NamingProxy {
|
||||
|
||||
private long vipSrvRefInterMillis = TimeUnit.SECONDS.toMillis(30);
|
||||
|
||||
private CredentialService credentialService = CredentialService.getInstance();
|
||||
|
||||
private ScheduledExecutorService executorService;
|
||||
private Properties properties;
|
||||
|
||||
public NamingProxy(String namespaceId, String endpoint, String serverList) {
|
||||
|
||||
this.namespaceId = namespaceId;
|
||||
this.endpoint = endpoint;
|
||||
|
||||
if (StringUtils.isNotEmpty(serverList)) {
|
||||
this.serverList = Arrays.asList(serverList.split(","));
|
||||
if (this.serverList.size() == 1) {
|
||||
@ -93,12 +79,15 @@ public class NamingProxy {
|
||||
}
|
||||
}
|
||||
|
||||
String serverPort = System.getProperties().getProperty(SystemPropertyKeyConst.NAMING_SERVER_PORT);
|
||||
if (StringUtils.isNotEmpty(serverPort)) {
|
||||
this.serverPort = Integer.valueOf(serverPort.trim());
|
||||
initRefreshSrvIfNeed();
|
||||
}
|
||||
|
||||
private void initRefreshSrvIfNeed() {
|
||||
if (StringUtils.isEmpty(endpoint)) {
|
||||
return;
|
||||
}
|
||||
|
||||
executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
||||
ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
@ -118,26 +107,17 @@ public class NamingProxy {
|
||||
refreshSrvIfNeed();
|
||||
}
|
||||
|
||||
public void setServerPort(int serverPort) {
|
||||
this.serverPort = serverPort;
|
||||
}
|
||||
|
||||
public List<String> getServerListFromEndpoint() {
|
||||
|
||||
try {
|
||||
String urlString = "http://" + endpoint + "/nacos/serverlist";
|
||||
|
||||
String nacosNamingMode = System.getProperty(SystemPropertyKeyConst.NACOS_NAMING_REQUEST_MODULE, "Naming");
|
||||
List<String> headers = builderHeaders();
|
||||
|
||||
List<String> headers = Arrays.asList("Client-Version", UtilAndComs.VERSION,
|
||||
"Accept-Encoding", "gzip,deflate,sdch", "Connection", "Keep-Alive",
|
||||
"RequestId", UuidUtils.generateUuid(), "Request-Module", nacosNamingMode);
|
||||
|
||||
HttpClient.HttpResult result = HttpClient.httpGet(urlString, headers, null,
|
||||
UtilAndComs.ENCODING);
|
||||
HttpClient.HttpResult result = HttpClient.httpGet(urlString, headers, null, UtilAndComs.ENCODING);
|
||||
if (HttpURLConnection.HTTP_OK != result.code) {
|
||||
throw new IOException("Error while requesting: " + urlString
|
||||
+ "'. Server returned: " + result.code);
|
||||
throw new IOException("Error while requesting: " + urlString + "'. Server returned: "
|
||||
+ result.code);
|
||||
}
|
||||
|
||||
String content = result.content;
|
||||
@ -206,41 +186,10 @@ public class NamingProxy {
|
||||
|
||||
}
|
||||
|
||||
private void checkTenant(Map<String, String> params) {
|
||||
String tenantId = credentialService.getCredential().getTenantId();
|
||||
if (tenantId == null || tenantId.trim().length() == 0) {
|
||||
return;
|
||||
}
|
||||
public void deregisterService(String serviceName, String ip, int port, String cluster) throws NacosException {
|
||||
|
||||
try {
|
||||
String tenantApp = System.getProperty("project.name");
|
||||
String tenantAk = credentialService.getCredential().getAccessKey();
|
||||
String tenantSK = credentialService.getCredential().getSecretKey();
|
||||
String signData = getSignData(params);
|
||||
String signature = SignUtil.sign(signData, tenantSK);
|
||||
params.put("signature", signature);
|
||||
params.put("data", signData);
|
||||
params.put("ak", tenantAk);
|
||||
params.put("app", tenantApp);
|
||||
params.put(Constants.REQUEST_PARAM_NAMESPACE_ID, tenantId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getSignData(Map<String, String> params) {
|
||||
String data = "";
|
||||
return params.containsKey("dom")
|
||||
? System.currentTimeMillis() + "@@" + (String) params.get("dom")
|
||||
: String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void deregisterService(String serviceName, String ip, int port, String cluster)
|
||||
throws NacosException {
|
||||
|
||||
NAMING_LOGGER.info("DEREGISTER-SERVICE",
|
||||
"{} deregistering service {} with instance: {}:{}@{}", namespaceId,
|
||||
serviceName, ip, port, cluster);
|
||||
NAMING_LOGGER.info("DEREGISTER-SERVICE", "{} deregistering service {} with instance: {}:{}@{}",
|
||||
namespaceId, serviceName, ip, port, cluster);
|
||||
|
||||
final Map<String, String> params = new HashMap<String, String>(8);
|
||||
params.put(Constants.REQUEST_PARAM_NAMESPACE_ID, namespaceId);
|
||||
@ -252,7 +201,8 @@ public class NamingProxy {
|
||||
reqAPI(UtilAndComs.NACOS_URL_INSTANCE, params, HttpMethod.DELETE);
|
||||
}
|
||||
|
||||
public String queryList(String serviceName, String clusters, int udpPort, boolean healthyOnly) throws NacosException {
|
||||
public String queryList(String serviceName, String clusters, int udpPort, boolean healthyOnly)
|
||||
throws NacosException {
|
||||
|
||||
final Map<String, String> params = new HashMap<String, String>(8);
|
||||
params.put(Constants.REQUEST_PARAM_NAMESPACE_ID, namespaceId);
|
||||
@ -311,7 +261,7 @@ public class NamingProxy {
|
||||
case none:
|
||||
break;
|
||||
case label:
|
||||
ExpressionSelector expressionSelector = (ExpressionSelector)selector;
|
||||
ExpressionSelector expressionSelector = (ExpressionSelector) selector;
|
||||
params.put("selector", JSON.toJSONString(expressionSelector));
|
||||
break;
|
||||
default:
|
||||
@ -332,7 +282,6 @@ public class NamingProxy {
|
||||
|
||||
public String reqAPI(String api, Map<String, String> params) throws NacosException {
|
||||
|
||||
|
||||
List<String> snapshot = serversFromEndpoint;
|
||||
if (!CollectionUtils.isEmpty(serverList)) {
|
||||
snapshot = serverList;
|
||||
@ -359,16 +308,14 @@ public class NamingProxy {
|
||||
throws NacosException {
|
||||
long start = System.currentTimeMillis();
|
||||
long end = 0;
|
||||
checkSignature(params);
|
||||
|
||||
List<String> headers = Arrays.asList("Client-Version", UtilAndComs.VERSION,
|
||||
"Accept-Encoding", "gzip,deflate,sdch",
|
||||
"Connection", "Keep-Alive",
|
||||
"RequestId", UuidUtils.generateUuid());
|
||||
List<String> headers = builderHeaders();
|
||||
|
||||
String url;
|
||||
|
||||
if (!curServer.contains(UtilAndComs.SERVER_ADDR_IP_SPLITER)) {
|
||||
curServer = curServer + UtilAndComs.SERVER_ADDR_IP_SPLITER + DEFAULT_SERVER_PORT;
|
||||
curServer = curServer + UtilAndComs.SERVER_ADDR_IP_SPLITER + serverPort;
|
||||
}
|
||||
|
||||
url = HttpClient.getPrefix() + curServer + api;
|
||||
@ -403,7 +350,6 @@ public class NamingProxy {
|
||||
public String reqAPI(String api, Map<String, String> params, List<String> servers, String method) {
|
||||
|
||||
params.put(Constants.REQUEST_PARAM_NAMESPACE_ID, getNamespaceId());
|
||||
checkTenant(params);
|
||||
|
||||
if (CollectionUtils.isEmpty(servers) && StringUtils.isEmpty(nacosDomain)) {
|
||||
throw new IllegalArgumentException("no server available");
|
||||
@ -440,7 +386,86 @@ public class NamingProxy {
|
||||
|
||||
}
|
||||
|
||||
private void checkSignature(Map<String, String> params) {
|
||||
String ak = getAccessKey();
|
||||
String sk = getSecretKey();
|
||||
if (StringUtils.isEmpty(ak) && StringUtils.isEmpty(sk)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String app = System.getProperty("project.name");
|
||||
String signData = getSignData(params.get("serviceName"));
|
||||
String signature = SignUtil.sign(signData, sk);
|
||||
params.put("signature", signature);
|
||||
params.put("data", signData);
|
||||
params.put("ak", ak);
|
||||
params.put("app", app);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> builderHeaders() {
|
||||
List<String> headers = Arrays.asList("Client-Version", UtilAndComs.VERSION,
|
||||
"Accept-Encoding", "gzip,deflate,sdch",
|
||||
"Connection", "Keep-Alive",
|
||||
"RequestId", UuidUtils.generateUuid(), "Request-Module", "Naming");
|
||||
return headers;
|
||||
}
|
||||
|
||||
private static String getSignData(String serviceName) {
|
||||
return StringUtils.isNotEmpty(serviceName)
|
||||
? System.currentTimeMillis() + "@@" + serviceName
|
||||
: String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public String getAccessKey() {
|
||||
if (properties == null) {
|
||||
|
||||
return SpasAdapter.getAk();
|
||||
}
|
||||
|
||||
return TemplateUtils.stringEmptyAndThenExecute(properties.getProperty(PropertyKeyConst.ACCESS_KEY), new Callable<String>() {
|
||||
|
||||
@Override
|
||||
public String call() {
|
||||
return SpasAdapter.getAk();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
if (properties == null) {
|
||||
|
||||
return SpasAdapter.getSk();
|
||||
}
|
||||
|
||||
return TemplateUtils.stringEmptyAndThenExecute(properties.getProperty(PropertyKeyConst.SECRET_KEY), new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
return SpasAdapter.getSk();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
setServerPort(DEFAULT_SERVER_PORT);
|
||||
}
|
||||
|
||||
public String getNamespaceId() {
|
||||
return namespaceId;
|
||||
}
|
||||
|
||||
public void setServerPort(int serverPort) {
|
||||
this.serverPort = serverPort;
|
||||
|
||||
String sp = System.getProperty(SystemPropertyKeyConst.NAMING_SERVER_PORT);
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(sp)) {
|
||||
this.serverPort = Integer.parseInt(sp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.client.naming;
|
||||
package com.alibaba.nacos.client.naming.utils;
|
||||
|
||||
import com.alibaba.nacos.client.identify.Base64;
|
||||
|
||||
@ -56,11 +56,11 @@ public class SignUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static enum SigningAlgorithm {
|
||||
public enum SigningAlgorithm {
|
||||
// Hmac SHA1 algorithm
|
||||
HmacSHA1;
|
||||
|
||||
private SigningAlgorithm() {
|
||||
SigningAlgorithm() {
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,11 @@ public class StringUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isNotBlank(String str) {
|
||||
|
||||
return !isBlank(str);
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(String str) {
|
||||
return !StringUtils.isEmpty(str);
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
*
|
||||
* 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.utils;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
* @date 2019-03-04 1:31 PM
|
||||
*/
|
||||
public class TemplateUtils {
|
||||
|
||||
public static final String stringEmptyAndThenExecute(String source, Callable<String> callable) {
|
||||
|
||||
if (StringUtils.isEmpty(source)) {
|
||||
|
||||
try {
|
||||
return callable.call();
|
||||
} catch (Exception e) {
|
||||
LogUtils.NAMING_LOGGER.error("string empty and then execute cause an exception.", e);
|
||||
}
|
||||
}
|
||||
|
||||
return source.trim();
|
||||
}
|
||||
|
||||
public static final String stringBlankAndThenExecute(String source, Callable<String> callable) {
|
||||
|
||||
if (StringUtils.isBlank(source)) {
|
||||
|
||||
try {
|
||||
return callable.call();
|
||||
} catch (Exception e) {
|
||||
LogUtils.NAMING_LOGGER.error("string empty and then execute cause an exception.", e);
|
||||
}
|
||||
}
|
||||
|
||||
return source.trim();
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -57,4 +57,16 @@
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>6</source>
|
||||
<target>6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.common.util;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author xingxuechao
|
||||
* on:2019/2/27 12:32 PM
|
||||
*/
|
||||
public class VersionUtils {
|
||||
|
||||
public static String VERSION;
|
||||
/**获取当前version*/
|
||||
public static final String VERSION_DEFAULT = "${project.version}";
|
||||
|
||||
|
||||
static{
|
||||
try{
|
||||
InputStream in = VersionUtils.class.getClassLoader()
|
||||
.getResourceAsStream("nacos-version.txt");
|
||||
Properties props = new Properties();
|
||||
props.load(in);
|
||||
String val = props.getProperty("version");
|
||||
if (val != null && !VERSION_DEFAULT.equals(val)) {
|
||||
VERSION = val;
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -1 +1 @@
|
||||
${pom.version}
|
||||
${project.version}
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
</parent>
|
||||
<artifactId>nacos-console</artifactId>
|
||||
<!--<packaging>war</packaging>-->
|
||||
@ -121,6 +121,13 @@
|
||||
<exclude>static/console-fe/.vscode/**</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>nacos-version.txt</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.console.controller;
|
||||
|
||||
|
||||
import com.alibaba.nacos.common.util.VersionUtils;
|
||||
import com.alibaba.nacos.core.utils.SystemUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xingxuechao
|
||||
* on:2019/2/27 11:17 AM
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/v1/console/server")
|
||||
public class ServerStateController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServerStateController.class);
|
||||
|
||||
|
||||
public static String VERSION ;
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "state", method = RequestMethod.GET)
|
||||
public ResponseEntity serverState() {
|
||||
Map<String,String> serverState = new HashMap<String, String>(3);
|
||||
serverState.put("standalone_mode",SystemUtils.STANDALONE_MODE ?
|
||||
SystemUtils.STANDALONE_MODE_ALONE : SystemUtils.STANDALONE_MODE_CLUSTER);
|
||||
|
||||
serverState.put("function_mode", SystemUtils.FUNCTION_MODE);
|
||||
serverState.put("version", VersionUtils.VERSION);
|
||||
|
||||
return ResponseEntity.ok().body(serverState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,3 +1,40 @@
|
||||
# spring
|
||||
|
||||
server.contextPath=/nacos
|
||||
server.servlet.contextPath=/nacos
|
||||
server.port=8848
|
||||
|
||||
nacos.cmdb.dumpTaskInterval=3600
|
||||
nacos.cmdb.eventTaskInterval=10
|
||||
nacos.cmdb.labelTaskInterval=300
|
||||
nacos.cmdb.loadDataAtStart=false
|
||||
|
||||
|
||||
# metrics for prometheus
|
||||
#management.endpoints.web.exposure.include=*
|
||||
|
||||
# metrics for elastic search
|
||||
management.metrics.export.elastic.enabled=false
|
||||
#management.metrics.export.elastic.host=http://localhost:9200
|
||||
|
||||
# metrics for influx
|
||||
management.metrics.export.influx.enabled=false
|
||||
#management.metrics.export.influx.db=springboot
|
||||
#management.metrics.export.influx.uri=http://localhost:8086
|
||||
#management.metrics.export.influx.auto-create-db=true
|
||||
#management.metrics.export.influx.consistency=one
|
||||
#management.metrics.export.influx.compressed=true
|
||||
|
||||
server.tomcat.accesslog.enabled=true
|
||||
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
||||
# default current work dir
|
||||
server.tomcat.basedir=
|
||||
|
||||
## spring security config
|
||||
### turn off security
|
||||
#spring.security.enabled=false
|
||||
#management.security=false
|
||||
#security.basic.enabled=false
|
||||
#nacos.security.ignore.urls=/**
|
||||
|
||||
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
|
||||
|
1
console/src/main/resources/nacos-version.txt
Executable file
1
console/src/main/resources/nacos-version.txt
Executable file
@ -0,0 +1 @@
|
||||
version=${project.version}
|
@ -18,3 +18,5 @@ export const LANGUAGE_SWITCH = 'LANGUAGE_SWITCH';
|
||||
// export const SUCCESS_RESULT_CODE = 'SUCCESS';
|
||||
|
||||
export const REDUX_DEVTOOLS = '__REDUX_DEVTOOLS_EXTENSION__';
|
||||
|
||||
export const GET_STATE = 'GET_STATE';
|
||||
|
@ -24,10 +24,8 @@ import { HashRouter, Route, Switch, Redirect } from 'react-router-dom';
|
||||
import { ConfigProvider, Loading } from '@alifd/next';
|
||||
|
||||
import './lib';
|
||||
import _menu from './menu';
|
||||
|
||||
import Layout from './layouts/MainLayout';
|
||||
import CookieHelp from './utils/cookie';
|
||||
import { LANGUAGE_KEY, REDUX_DEVTOOLS } from './constants';
|
||||
|
||||
import Login from './pages/Login';
|
||||
@ -114,7 +112,7 @@ class App extends React.Component {
|
||||
<HashRouter>
|
||||
<Switch>
|
||||
<Route path="/login" component={Login} />
|
||||
<Layout navList={_menu.data}>
|
||||
<Layout>
|
||||
{MENU.map(item => (
|
||||
<Route key={item.path} {...item} />
|
||||
))}
|
||||
|
@ -17,31 +17,38 @@ import PropTypes from 'prop-types';
|
||||
import { ConfigProvider, Icon } from '@alifd/next';
|
||||
import Header from './Header';
|
||||
import $ from 'jquery';
|
||||
import { setParams } from '../globalLib';
|
||||
import { connect } from 'react-redux';
|
||||
import { setParams } from '../globalLib';
|
||||
import { getState } from '../reducers/base';
|
||||
import _menu from '../menu';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
@withRouter
|
||||
@connect(state => ({ ...state.locale }))
|
||||
@connect(
|
||||
state => ({ ...state.locale, ...state.base }),
|
||||
{ getState }
|
||||
)
|
||||
@ConfigProvider.config
|
||||
class MainLayout extends React.Component {
|
||||
static displayName = 'MainLayout';
|
||||
|
||||
static propTypes = {
|
||||
navList: PropTypes.array,
|
||||
history: PropTypes.object,
|
||||
location: PropTypes.object,
|
||||
locale: PropTypes.object,
|
||||
children: PropTypes.any,
|
||||
version: PropTypes.any,
|
||||
functionMode: PropTypes.any,
|
||||
getState: PropTypes.func,
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.initNav = this.props.navList;
|
||||
this.deepNav = [];
|
||||
this.oneLevelNavArr = {}; // 平行导航map
|
||||
this.state = {
|
||||
navList: [..._menu.data],
|
||||
leftBarClose: false,
|
||||
showLink: null,
|
||||
navRow: [],
|
||||
@ -49,6 +56,11 @@ class MainLayout extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.getState();
|
||||
this.refreshNav();
|
||||
}
|
||||
|
||||
goBack() {
|
||||
this.props.history.goBack();
|
||||
}
|
||||
@ -232,6 +244,7 @@ class MainLayout extends React.Component {
|
||||
const hiddenClass = item.isExtend ? '' : 'hidden';
|
||||
return (
|
||||
<li
|
||||
style={{ display: item.enable ? 'block' : 'none' }}
|
||||
key={`${item.serviceName}`}
|
||||
data-spm-click={`gostr=/aliyun;locaid=${item.serviceName}`}
|
||||
id={`${item.serviceName}`}
|
||||
@ -256,7 +269,7 @@ class MainLayout extends React.Component {
|
||||
onClick={this.navTo.bind(this, `/${item.serviceName}`)}
|
||||
>
|
||||
<a
|
||||
href={'javascript:;'}
|
||||
href="javascript:;"
|
||||
id={`${item.serviceName}`}
|
||||
onClick={this.activeNav.bind(this, `nav${index}`)}
|
||||
>
|
||||
@ -297,13 +310,12 @@ class MainLayout extends React.Component {
|
||||
}
|
||||
|
||||
renderNav() {
|
||||
const { navList } = this.state;
|
||||
this.nacosLeftBarDom = document.getElementById('viewFramework-product-navbar');
|
||||
this.nacosBodyDom = document.getElementById('viewFramework-product-body');
|
||||
this.nacosToggleIconDom = document.getElementById('viewFramework-product-navbar-collapse');
|
||||
this.nacosOutDom = document.getElementById('page-header-mask');
|
||||
// let parentNav = this.initNav[0] || [];
|
||||
const defaultNav = '/configurationManagement';
|
||||
// let childrenNav = parentNav.children || [];
|
||||
this.props.history.listen(location => {
|
||||
if (this.preSimplePath && this.preSimplePath !== '/') {
|
||||
if (location.pathname.indexOf(this.preSimplePath) !== -1) {
|
||||
@ -366,7 +378,7 @@ class MainLayout extends React.Component {
|
||||
} else {
|
||||
this.setState({
|
||||
showLink: null,
|
||||
navRow: <ul>{this.nacosLoopNav(this.initNav)}</ul>,
|
||||
navRow: <ul>{this.nacosLoopNav(navList)}</ul>,
|
||||
});
|
||||
setTimeout(() => {
|
||||
const navid = navName;
|
||||
@ -376,17 +388,38 @@ class MainLayout extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
refreshNav() {
|
||||
const { navList } = this.state;
|
||||
const { functionMode } = this.props;
|
||||
this.setState(
|
||||
{
|
||||
navList: navList.map(item => {
|
||||
if (
|
||||
item.serviceName === 'configurationManagementVirtual' &&
|
||||
(functionMode === null || functionMode === 'config')
|
||||
) {
|
||||
item.enable = true;
|
||||
}
|
||||
if (
|
||||
item.serviceName === 'serviceManagementVirtual' &&
|
||||
(functionMode === null || functionMode === 'naming')
|
||||
) {
|
||||
item.enable = true;
|
||||
}
|
||||
return item;
|
||||
}),
|
||||
},
|
||||
() => this.setState({ navRow: this.nacosGetNav(navList) }, () => this.renderNav())
|
||||
);
|
||||
}
|
||||
|
||||
componentWillReceiveProps() {
|
||||
setTimeout(() => {
|
||||
const nav = this.props.navList || [];
|
||||
const navRow = this.nacosGetNav(nav);
|
||||
this.setState({ navRow }, () => this.renderNav());
|
||||
});
|
||||
setTimeout(() => this.refreshNav());
|
||||
}
|
||||
|
||||
render() {
|
||||
const { locale = {} } = this.props;
|
||||
const { nacosVersion, nacosName, doesNotExist } = locale;
|
||||
const { locale = {}, version } = this.props;
|
||||
const { nacosName, doesNotExist } = locale;
|
||||
const { showLink, navRow, leftBarClose, noChild } = this.state;
|
||||
return (
|
||||
<div className="viewFramework-product" style={{ top: 66 }}>
|
||||
@ -405,9 +438,13 @@ class MainLayout extends React.Component {
|
||||
{showLink}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ textIndent: 0 }} className={'product-nav-title'} title={nacosName}>
|
||||
<div
|
||||
style={{ textIndent: 0, display: !version ? 'none' : 'block' }}
|
||||
className={'product-nav-title'}
|
||||
title={nacosName}
|
||||
>
|
||||
<span>{nacosName}</span>
|
||||
<span style={{ marginLeft: 5 }}>{nacosVersion}</span>
|
||||
<span style={{ marginLeft: 5 }}>{version}</span>
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
|
@ -31,7 +31,6 @@ const I18N_CONF = {
|
||||
},
|
||||
MainLayout: {
|
||||
nacosName: 'NACOS',
|
||||
nacosVersion: '0.8.0',
|
||||
doesNotExist: 'The page you visit does not exist',
|
||||
configurationManagementVirtual: 'ConfigManagement',
|
||||
configurationManagement: 'Configurations',
|
||||
@ -110,6 +109,9 @@ const I18N_CONF = {
|
||||
protectThreshold: 'Protect Threshold',
|
||||
serviceName: 'Service Name',
|
||||
editService: 'Edit Service',
|
||||
healthCheckPatternService: 'Service',
|
||||
healthCheckPatternClient: 'Client',
|
||||
healthCheckPatternNone: 'None',
|
||||
},
|
||||
EditServiceDialog: {
|
||||
createService: 'Create Service',
|
||||
|
@ -31,7 +31,6 @@ const I18N_CONF = {
|
||||
},
|
||||
MainLayout: {
|
||||
nacosName: 'NACOS',
|
||||
nacosVersion: '0.8.0',
|
||||
doesNotExist: '您访问的页面不存在',
|
||||
configurationManagementVirtual: '配置管理',
|
||||
configurationManagement: '配置列表',
|
||||
@ -110,6 +109,9 @@ const I18N_CONF = {
|
||||
protectThreshold: '保护阈值',
|
||||
serviceName: '服务名',
|
||||
editService: '编辑服务',
|
||||
healthCheckPatternService: '服务端',
|
||||
healthCheckPatternClient: '客户端',
|
||||
healthCheckPatternNone: '禁止',
|
||||
},
|
||||
EditServiceDialog: {
|
||||
createService: '创建服务',
|
||||
|
@ -14,6 +14,7 @@
|
||||
module.exports = {
|
||||
data: [
|
||||
{
|
||||
enable: false,
|
||||
isExtend: true,
|
||||
name: '配置管理',
|
||||
title: '配置管理',
|
||||
@ -164,6 +165,7 @@ module.exports = {
|
||||
],
|
||||
},
|
||||
{
|
||||
enable: false,
|
||||
isExtend: true,
|
||||
name: '服务管理',
|
||||
title: '服务管理',
|
||||
@ -210,6 +212,7 @@ module.exports = {
|
||||
],
|
||||
},
|
||||
{
|
||||
enable: true,
|
||||
isExtend: false,
|
||||
name: '命名空间',
|
||||
title: '命名空间',
|
||||
|
@ -91,6 +91,11 @@ class ServiceDetail extends React.Component {
|
||||
const { locale = {} } = this.props;
|
||||
const { serviceName, loading, service = {}, clusters } = this.state;
|
||||
const { metadata = {}, selector = {} } = service;
|
||||
const healthCheckMap = {
|
||||
server: locale.healthCheckPatternService,
|
||||
client: locale.healthCheckPatternClient,
|
||||
none: locale.healthCheckPatternNone,
|
||||
};
|
||||
const metadataText = Object.keys(metadata)
|
||||
.map(key => `${key}=${metadata[key]}`)
|
||||
.join(',');
|
||||
@ -134,7 +139,7 @@ class ServiceDetail extends React.Component {
|
||||
<Input value={service.protectThreshold} readOnly />
|
||||
</FormItem>
|
||||
<FormItem label={`${locale.healthCheckPattern}:`}>
|
||||
<Input value={service.healthCheckMode} readOnly />
|
||||
<Input value={healthCheckMap[service.healthCheckMode]} readOnly />
|
||||
</FormItem>
|
||||
<FormItem label={`${locale.metadata}:`}>
|
||||
<Input value={metadataText} readOnly />
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import request from '../utils/request';
|
||||
import { GET_STATE } from '../constants';
|
||||
|
||||
const initialState = {
|
||||
version: null,
|
||||
standaloneMode: '',
|
||||
functionMode: '',
|
||||
};
|
||||
|
||||
const getState = () => dispatch =>
|
||||
request
|
||||
.get('v1/console/server/state')
|
||||
.then(res => {
|
||||
dispatch({
|
||||
type: GET_STATE,
|
||||
data: {
|
||||
version: res.version,
|
||||
standaloneMode: res.standalone_mode,
|
||||
functionMode: res.function_mode,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
dispatch({
|
||||
type: GET_STATE,
|
||||
data: {
|
||||
version: null,
|
||||
functionMode: null,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case GET_STATE:
|
||||
return { ...state, ...action.data };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export { getState };
|
@ -12,5 +12,6 @@
|
||||
*/
|
||||
|
||||
import locale from './locale';
|
||||
import base from './base';
|
||||
|
||||
export default { locale };
|
||||
export default { locale, base };
|
||||
|
@ -15,7 +15,6 @@ import fusionEnUS from '@alifd/next/lib/locale/en-us';
|
||||
import fusionZhCN from '@alifd/next/lib/locale/zh-cn';
|
||||
import I18N from '../locales';
|
||||
import { LANGUAGE_KEY, LANGUAGE_SWITCH } from '../constants';
|
||||
import CookieHelp from '../utils/cookie';
|
||||
|
||||
const enUS = Object.assign({}, fusionEnUS, I18N.enUS);
|
||||
const zhCN = Object.assign({}, fusionZhCN, I18N.zhCN);
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.core.listener;
|
||||
|
||||
import com.alibaba.nacos.core.utils.SystemUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@ -31,6 +32,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.alibaba.nacos.core.utils.SystemUtils.FUNCTION_MODE;
|
||||
import static com.alibaba.nacos.core.utils.SystemUtils.LOCAL_IP;
|
||||
import static com.alibaba.nacos.core.utils.SystemUtils.NACOS_HOME;
|
||||
import static com.alibaba.nacos.core.utils.SystemUtils.STANDALONE_MODE;
|
||||
@ -46,7 +48,9 @@ public class StartingSpringApplicationRunListener implements SpringApplicationRu
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(StartingSpringApplicationRunListener.class);
|
||||
|
||||
private static final String MODE_PROPERTY_KEY = "nacos.mode";
|
||||
private static final String MODE_PROPERTY_KEY_STAND_MODE = "nacos.mode";
|
||||
|
||||
private static final String MODE_PROPERTY_KEY_FUNCTION_MODE = "nacos.function.mode";
|
||||
|
||||
private static final String LOCAL_IP_PROPERTY_KEY = "nacos.local.ip";
|
||||
|
||||
@ -66,10 +70,18 @@ public class StartingSpringApplicationRunListener implements SpringApplicationRu
|
||||
@Override
|
||||
public void environmentPrepared(ConfigurableEnvironment environment) {
|
||||
if (STANDALONE_MODE) {
|
||||
System.setProperty(MODE_PROPERTY_KEY, "stand alone");
|
||||
System.setProperty(MODE_PROPERTY_KEY_STAND_MODE, "stand alone");
|
||||
} else {
|
||||
System.setProperty(MODE_PROPERTY_KEY, "cluster");
|
||||
System.setProperty(MODE_PROPERTY_KEY_STAND_MODE, "cluster");
|
||||
}
|
||||
if (FUNCTION_MODE == null) {
|
||||
System.setProperty(MODE_PROPERTY_KEY_FUNCTION_MODE, "All");
|
||||
} else if(SystemUtils.FUNCTION_MODE_CONFIG.equals(FUNCTION_MODE)){
|
||||
System.setProperty(MODE_PROPERTY_KEY_FUNCTION_MODE, SystemUtils.FUNCTION_MODE_CONFIG);
|
||||
} else if(SystemUtils.FUNCTION_MODE_NAMING.equals(FUNCTION_MODE)) {
|
||||
System.setProperty(MODE_PROPERTY_KEY_FUNCTION_MODE, SystemUtils.FUNCTION_MODE_NAMING);
|
||||
}
|
||||
|
||||
|
||||
System.setProperty(LOCAL_IP_PROPERTY_KEY, LOCAL_IP);
|
||||
}
|
||||
@ -96,7 +108,7 @@ public class StartingSpringApplicationRunListener implements SpringApplicationRu
|
||||
|
||||
logFilePath();
|
||||
|
||||
LOGGER.info("Nacos started successfully in {} mode.", System.getProperty(MODE_PROPERTY_KEY));
|
||||
LOGGER.info("Nacos started successfully in {} mode.", System.getProperty(MODE_PROPERTY_KEY_STAND_MODE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,6 +33,11 @@ public interface Constants {
|
||||
*/
|
||||
String STANDALONE_MODE_PROPERTY_NAME = "nacos.standalone";
|
||||
|
||||
/**
|
||||
* The System property name of Function mode
|
||||
*/
|
||||
String FUNCTION_MODE_PROPERTY_NAME = "nacos.functionMode";
|
||||
|
||||
/**
|
||||
* The System property name of prefer hostname over ip
|
||||
*/
|
||||
|
@ -27,13 +27,11 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.core.utils.Constants.PREFER_HOSTNAME_OVER_IP_PROPERTY_NAME;
|
||||
import static com.alibaba.nacos.core.utils.Constants.FUNCTION_MODE_PROPERTY_NAME;
|
||||
import static com.alibaba.nacos.core.utils.Constants.STANDALONE_MODE_PROPERTY_NAME;
|
||||
import static org.apache.commons.lang3.CharEncoding.UTF_8;
|
||||
|
||||
@ -49,6 +47,19 @@ public class SystemUtils {
|
||||
*/
|
||||
public static boolean STANDALONE_MODE = Boolean.getBoolean(STANDALONE_MODE_PROPERTY_NAME);
|
||||
|
||||
public static final String STANDALONE_MODE_ALONE = "standalone";
|
||||
public static final String STANDALONE_MODE_CLUSTER = "cluster";
|
||||
|
||||
/**
|
||||
* server
|
||||
*/
|
||||
public static String FUNCTION_MODE = System.getProperty(FUNCTION_MODE_PROPERTY_NAME);
|
||||
|
||||
public static final String FUNCTION_MODE_CONFIG = "config";
|
||||
public static final String FUNCTION_MODE_NAMING = "naming";
|
||||
|
||||
|
||||
|
||||
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean)ManagementFactory
|
||||
.getOperatingSystemMXBean();
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
,--.
|
||||
,--.'|
|
||||
,--,: : | Nacos ${application.version}
|
||||
,`--.'`| ' : ,---. Running in ${nacos.mode} mode
|
||||
,`--.'`| ' : ,---. Running in ${nacos.mode} mode, ${nacos.function.mode} function modules
|
||||
| : : | | ' ,'\ .--.--. Port: ${server.port}
|
||||
: | \ | : ,--.--. ,---. / / | / / ' Pid: ${pid}
|
||||
| : ' '; | / \ / \. ; ,. :| : /`./ Console: http://${nacos.local.ip}:${server.port}/nacos/index.html
|
||||
|
@ -17,11 +17,12 @@ set "JAVA=%JAVA_HOME%\bin\java.exe"
|
||||
setlocal
|
||||
|
||||
set BASE_DIR=%~dp0
|
||||
set BASE_DIR=%BASE_DIR:~0,-1%
|
||||
for %%d in (%BASE_DIR%) do set BASE_DIR=%%~dpd
|
||||
rem added double quotation marks to avoid the issue caused by the folder names containing spaces.
|
||||
rem removed the last 5 chars(which means \bin\) to get the base DIR.
|
||||
set BASE_DIR="%BASE_DIR:~0,-5%"
|
||||
|
||||
set DEFAULT_SEARCH_LOCATIONS="classpath:/,classpath:/config/,file:./,file:./config/"
|
||||
set CUSTOM_SEARCH_LOCATIONS=%DEFAULT_SEARCH_LOCATIONS%,file:%BASE_DIR%conf/
|
||||
set CUSTOM_SEARCH_LOCATIONS=%DEFAULT_SEARCH_LOCATIONS%,file:%BASE_DIR%/conf/
|
||||
|
||||
|
||||
|
||||
@ -37,7 +38,7 @@ if not "%2" == "cluster" (
|
||||
set "JAVA_OPT=%JAVA_OPT% -Xbootclasspath/a:%BASE_DIR%\plugins\cmdb"
|
||||
set "JAVA_OPT=%JAVA_OPT% -Dnacos.home=%BASE_DIR%"
|
||||
set "JAVA_OPT=%JAVA_OPT% -jar %BASE_DIR%\target\nacos-server.jar"
|
||||
set "JAVA_OPT=%JAVA_OPT% --spring.config.location="%CUSTOM_SEARCH_LOCATIONS%""
|
||||
set "JAVA_OPT=%JAVA_OPT% --logging.config="%BASE_DIR%/conf/nacos-logback.xml""
|
||||
set "JAVA_OPT=%JAVA_OPT% --spring.config.location=%CUSTOM_SEARCH_LOCATIONS%"
|
||||
set "JAVA_OPT=%JAVA_OPT% --logging.config=%BASE_DIR%/conf/nacos-logback.xml"
|
||||
|
||||
call "%JAVA%" %JAVA_OPT% %*
|
||||
|
@ -52,12 +52,14 @@ if [ -z "$JAVA_HOME" ]; then
|
||||
fi
|
||||
|
||||
export MODE="cluster"
|
||||
while getopts ":m:" opt
|
||||
export FUNCTION_MODE="all"
|
||||
while getopts ":m:f:" opt
|
||||
do
|
||||
case $opt in
|
||||
m)
|
||||
MODE=$OPTARG
|
||||
;;
|
||||
MODE=$OPTARG;;
|
||||
f)
|
||||
FUNCTION_MODE=$OPTARG;;
|
||||
?)
|
||||
echo "Unknown parameter"
|
||||
exit 1;;
|
||||
@ -83,6 +85,13 @@ else
|
||||
|
||||
fi
|
||||
|
||||
if [[ "${FUNCTION_MODE}" == "config" ]]; then
|
||||
JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=config"
|
||||
elif [[ "${FUNCTION_MODE}" == "naming" ]]; then
|
||||
JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=naming"
|
||||
fi
|
||||
|
||||
|
||||
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
|
||||
if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] ; then
|
||||
JAVA_OPT="${JAVA_OPT} -cp .:${BASE_DIR}/plugins/cmdb/*.jar"
|
||||
|
@ -37,4 +37,4 @@ server.tomcat.basedir=
|
||||
#security.basic.enabled=false
|
||||
#nacos.security.ignore.urls=/**
|
||||
|
||||
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**
|
||||
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -173,12 +173,12 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement
|
||||
if (responsible(ip)) {
|
||||
// do not update the ip validation status of updated ips
|
||||
// because the checker has the most precise result
|
||||
|
||||
// Only when ip is not marked, don't we update the health status of IP:
|
||||
if (!ip.isMarked()) {
|
||||
ip.setValid(oldIP.isValid());
|
||||
if (((VirtualClusterDomain)dom).getEnableHealthCheck() || ((VirtualClusterDomain)dom).getEnableClientBeat()) {
|
||||
// Only when ip is not marked, don't we update the health status of IP:
|
||||
if (!ip.isMarked()) {
|
||||
ip.setValid(oldIP.isValid());
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (ip.isValid() != oldIP.isValid()) {
|
||||
// ip validation status updated
|
||||
|
@ -24,7 +24,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class IpAddressInfo implements Serializable {
|
||||
|
||||
private boolean valid;
|
||||
private boolean valid;
|
||||
|
||||
private Map<String, String> metadata;
|
||||
|
||||
@ -34,7 +34,7 @@ public class IpAddressInfo implements Serializable {
|
||||
|
||||
private Double weight;
|
||||
|
||||
private boolean enabled;
|
||||
private boolean enabled;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
|
@ -268,7 +268,7 @@ public class RaftCore {
|
||||
|
||||
}
|
||||
|
||||
if (!latch.await(UtilsAndCommons.RAFT_PUBLISH_TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
if (!STANDALONE_MODE && !latch.await(UtilsAndCommons.RAFT_PUBLISH_TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
// only majority servers return success can we consider this update success
|
||||
Loggers.RAFT.info("data publish failed, caused failed to notify majority, key={}", key);
|
||||
throw new IllegalStateException("data publish failed, caused failed to notify majority, key=" + key);
|
||||
|
@ -526,6 +526,7 @@ public class ApiCommands {
|
||||
cluster = WebUtils.optional(request, "clusterName", UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
}
|
||||
boolean enabled = BooleanUtils.toBoolean(WebUtils.optional(request, "enable", "true"));
|
||||
boolean healthy = BooleanUtils.toBoolean(WebUtils.optional(request, "healthy", "true"));
|
||||
|
||||
IpAddress ipAddress = new IpAddress();
|
||||
ipAddress.setPort(Integer.parseInt(port));
|
||||
@ -533,6 +534,7 @@ public class ApiCommands {
|
||||
ipAddress.setWeight(Double.parseDouble(weight));
|
||||
ipAddress.setClusterName(cluster);
|
||||
ipAddress.setEnabled(enabled);
|
||||
ipAddress.setValid(healthy);
|
||||
|
||||
if (!ipAddress.validate()) {
|
||||
throw new IllegalArgumentException("malfomed ip config: " + ipAddress);
|
||||
|
2
pom.xml
2
pom.xml
@ -21,7 +21,7 @@
|
||||
<inceptionYear>2018</inceptionYear>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Alibaba NACOS ${project.version}</name>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.9.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
Loading…
Reference in New Issue
Block a user