fix #367
This commit is contained in:
parent
e9bbe492bb
commit
15e0f30849
@ -16,7 +16,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -22,6 +22,8 @@ package com.alibaba.nacos.api;
|
|||||||
*/
|
*/
|
||||||
public class PropertyKeyConst {
|
public class PropertyKeyConst {
|
||||||
|
|
||||||
|
public final static String SERVER_PORT = "serverPort";
|
||||||
|
|
||||||
public final static String WEB_CONTEXT = "webContext";
|
public final static String WEB_CONTEXT = "webContext";
|
||||||
|
|
||||||
public final static String ENDPOINT = "endpoint";
|
public final static String ENDPOINT = "endpoint";
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -125,15 +125,7 @@ public class NacosNamingService implements NamingService {
|
|||||||
+ properties.getProperty("address.server.port", "8080");
|
+ properties.getProperty("address.server.port", "8080");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils
|
initWebRootContext();
|
||||||
.isNotEmpty(properties.getProperty(PropertyKeyConst.WEB_CONTEXT))) {
|
|
||||||
String tmpWebContext = properties.getProperty(PropertyKeyConst.WEB_CONTEXT);
|
|
||||||
UtilAndComs.WEB_CONTEXT = tmpWebContext.indexOf("/") > -1 ? tmpWebContext
|
|
||||||
: "/" + tmpWebContext;
|
|
||||||
|
|
||||||
UtilAndComs.NACOS_URL_BASE = UtilAndComs.WEB_CONTEXT + "/v1/ns";
|
|
||||||
UtilAndComs.NACOS_URL_INSTANCE = UtilAndComs.NACOS_URL_BASE + "/instance";
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheDir = System.getProperty("user.home") + "/nacos/naming/" + namespace;
|
cacheDir = System.getProperty("user.home") + "/nacos/naming/" + namespace;
|
||||||
|
|
||||||
@ -160,6 +152,18 @@ public class NacosNamingService implements NamingService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initWebRootContext() {
|
||||||
|
// support the web context with ali-yun if the app deploy by EDAS
|
||||||
|
String webContext = System.getProperties().getProperty(PropertyKeyConst.WEB_CONTEXT);
|
||||||
|
if (StringUtils.isNotEmpty(webContext)) {
|
||||||
|
UtilAndComs.WEB_CONTEXT = webContext.indexOf("/") > -1 ? webContext
|
||||||
|
: "/" + webContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
UtilAndComs.NACOS_URL_BASE = UtilAndComs.WEB_CONTEXT + "/v1/ns";
|
||||||
|
UtilAndComs.NACOS_URL_INSTANCE = UtilAndComs.NACOS_URL_BASE + "/instance";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerInstance(String serviceName, String ip, int port)
|
public void registerInstance(String serviceName, String ip, int port)
|
||||||
throws NacosException {
|
throws NacosException {
|
||||||
@ -234,8 +238,7 @@ public class NacosNamingService implements NamingService {
|
|||||||
if (subscribe) {
|
if (subscribe) {
|
||||||
serviceInfo = hostReactor.getServiceInfo(serviceName,
|
serviceInfo = hostReactor.getServiceInfo(serviceName,
|
||||||
StringUtils.join(clusters, ","));
|
StringUtils.join(clusters, ","));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(serviceName,
|
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(serviceName,
|
||||||
StringUtils.join(clusters, ","));
|
StringUtils.join(clusters, ","));
|
||||||
}
|
}
|
||||||
@ -272,8 +275,7 @@ public class NacosNamingService implements NamingService {
|
|||||||
if (subscribe) {
|
if (subscribe) {
|
||||||
serviceInfo = hostReactor.getServiceInfo(serviceName,
|
serviceInfo = hostReactor.getServiceInfo(serviceName,
|
||||||
StringUtils.join(clusters, ","));
|
StringUtils.join(clusters, ","));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(serviceName,
|
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(serviceName,
|
||||||
StringUtils.join(clusters, ","));
|
StringUtils.join(clusters, ","));
|
||||||
}
|
}
|
||||||
@ -304,8 +306,7 @@ public class NacosNamingService implements NamingService {
|
|||||||
if (subscribe) {
|
if (subscribe) {
|
||||||
return Balancer.RandomByWeight.selectHost(hostReactor
|
return Balancer.RandomByWeight.selectHost(hostReactor
|
||||||
.getServiceInfo(serviceName, StringUtils.join(clusters, ",")));
|
.getServiceInfo(serviceName, StringUtils.join(clusters, ",")));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return Balancer.RandomByWeight
|
return Balancer.RandomByWeight
|
||||||
.selectHost(hostReactor.getServiceInfoDirectlyFromServer(serviceName,
|
.selectHost(hostReactor.getServiceInfoDirectlyFromServer(serviceName,
|
||||||
StringUtils.join(clusters, ",")));
|
StringUtils.join(clusters, ",")));
|
||||||
|
@ -18,6 +18,7 @@ package com.alibaba.nacos.client.naming.net;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.TypeReference;
|
import com.alibaba.fastjson.TypeReference;
|
||||||
|
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
@ -49,6 +50,8 @@ public class NamingProxy {
|
|||||||
|
|
||||||
private static final int DEFAULT_SERVER_PORT = 8848;
|
private static final int DEFAULT_SERVER_PORT = 8848;
|
||||||
|
|
||||||
|
private int serverPort = DEFAULT_SERVER_PORT;
|
||||||
|
|
||||||
private String namespaceId;
|
private String namespaceId;
|
||||||
|
|
||||||
private String endpoint;
|
private String endpoint;
|
||||||
@ -71,6 +74,7 @@ public class NamingProxy {
|
|||||||
|
|
||||||
this.namespaceId = namespaceId;
|
this.namespaceId = namespaceId;
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(serverList)) {
|
if (StringUtils.isNotEmpty(serverList)) {
|
||||||
this.serverList = Arrays.asList(serverList.split(","));
|
this.serverList = Arrays.asList(serverList.split(","));
|
||||||
if (this.serverList.size() == 1) {
|
if (this.serverList.size() == 1) {
|
||||||
@ -78,6 +82,11 @@ public class NamingProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String serverPort = System.getProperties().getProperty(PropertyKeyConst.SERVER_PORT);
|
||||||
|
if (StringUtils.isNotEmpty(serverPort)) {
|
||||||
|
this.serverPort = Integer.valueOf(serverPort.trim());
|
||||||
|
}
|
||||||
|
|
||||||
executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
||||||
@Override
|
@Override
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
@ -98,6 +107,10 @@ public class NamingProxy {
|
|||||||
refreshSrvIfNeed();
|
refreshSrvIfNeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setServerPort(int serverPort) {
|
||||||
|
this.serverPort = serverPort;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getServerListFromEndpoint() {
|
public List<String> getServerListFromEndpoint() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -124,8 +137,7 @@ public class NamingProxy {
|
|||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,8 +168,7 @@ public class NamingProxy {
|
|||||||
|
|
||||||
serversFromEndpoint = list;
|
serversFromEndpoint = list;
|
||||||
lastSrvRefTime = System.currentTimeMillis();
|
lastSrvRefTime = System.currentTimeMillis();
|
||||||
}
|
} catch (Throwable e) {
|
||||||
catch (Throwable e) {
|
|
||||||
LogUtils.LOG.warn("failed to update server list", e);
|
LogUtils.LOG.warn("failed to update server list", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,8 +212,7 @@ public class NamingProxy {
|
|||||||
params.put("ak", tenantAk);
|
params.put("ak", tenantAk);
|
||||||
params.put("app", tenantApp);
|
params.put("app", tenantApp);
|
||||||
params.put(Constants.REQUEST_PARAM_NAMESPACE_ID, tenantId);
|
params.put(Constants.REQUEST_PARAM_NAMESPACE_ID, tenantId);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,8 +271,7 @@ public class NamingProxy {
|
|||||||
if (jsonObject != null) {
|
if (jsonObject != null) {
|
||||||
return jsonObject.getLong("clientBeatInterval");
|
return jsonObject.getLong("clientBeatInterval");
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
LogUtils.LOG.error("CLIENT-BEAT",
|
LogUtils.LOG.error("CLIENT-BEAT",
|
||||||
"failed to send beat: " + JSON.toJSONString(beatInfo), e);
|
"failed to send beat: " + JSON.toJSONString(beatInfo), e);
|
||||||
}
|
}
|
||||||
@ -274,8 +283,7 @@ public class NamingProxy {
|
|||||||
try {
|
try {
|
||||||
reqAPI(UtilAndComs.NACOS_URL_BASE + "/api/hello",
|
reqAPI(UtilAndComs.NACOS_URL_BASE + "/api/hello",
|
||||||
new HashMap<String, String>(2));
|
new HashMap<String, String>(2));
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +367,7 @@ public class NamingProxy {
|
|||||||
|
|
||||||
if (!curServer.contains(UtilAndComs.SERVER_ADDR_IP_SPLITER)) {
|
if (!curServer.contains(UtilAndComs.SERVER_ADDR_IP_SPLITER)) {
|
||||||
curServer = curServer + UtilAndComs.SERVER_ADDR_IP_SPLITER
|
curServer = curServer + UtilAndComs.SERVER_ADDR_IP_SPLITER
|
||||||
+ DEFAULT_SERVER_PORT;
|
+ serverPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
url = HttpClient.getPrefix() + curServer + api;
|
url = HttpClient.getPrefix() + curServer + api;
|
||||||
@ -410,8 +418,7 @@ public class NamingProxy {
|
|||||||
String server = servers.get(index);
|
String server = servers.get(index);
|
||||||
try {
|
try {
|
||||||
return callServer(api, params, server, method);
|
return callServer(api, params, server, method);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
LogUtils.LOG.error("NA",
|
LogUtils.LOG.error("NA",
|
||||||
"req api:" + api + " failed, server(" + server, e);
|
"req api:" + api + " failed, server(" + server, e);
|
||||||
}
|
}
|
||||||
@ -426,8 +433,7 @@ public class NamingProxy {
|
|||||||
for (int i = 0; i < UtilAndComs.REQUEST_DOMAIN_RETRY_COUNT; i++) {
|
for (int i = 0; i < UtilAndComs.REQUEST_DOMAIN_RETRY_COUNT; i++) {
|
||||||
try {
|
try {
|
||||||
return callServer(api, params, nacosDomain);
|
return callServer(api, params, nacosDomain);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
LogUtils.LOG.error("NA",
|
LogUtils.LOG.error("NA",
|
||||||
"req api:" + api + " failed, server(" + nacosDomain, e);
|
"req api:" + api + " failed, server(" + nacosDomain, e);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>nacos-console</artifactId>
|
<artifactId>nacos-console</artifactId>
|
||||||
<!--<packaging>war</packaging>-->
|
<!--<packaging>war</packaging>-->
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
3
pom.xml
3
pom.xml
@ -21,7 +21,7 @@
|
|||||||
<inceptionYear>2018</inceptionYear>
|
<inceptionYear>2018</inceptionYear>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>Alibaba NACOS ${project.version}</name>
|
<name>Alibaba NACOS ${project.version}</name>
|
||||||
@ -742,5 +742,6 @@
|
|||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-all</artifactId>
|
<artifactId>nacos-all</artifactId>
|
||||||
<version>0.8.0-SNAPSHOT</version>
|
<version>0.8.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
Loading…
Reference in New Issue
Block a user