This commit is contained in:
pbting 2019-02-14 18:00:01 +08:00
parent e9bbe492bb
commit 15e0f30849
15 changed files with 705 additions and 695 deletions

View File

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

View File

@ -22,6 +22,8 @@ package com.alibaba.nacos.api;
*/
public class PropertyKeyConst {
public final static String SERVER_PORT = "serverPort";
public final static String WEB_CONTEXT = "webContext";
public final static String ENDPOINT = "endpoint";

View File

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

View File

@ -125,15 +125,7 @@ public class NacosNamingService implements NamingService {
+ properties.getProperty("address.server.port", "8080");
}
if (StringUtils
.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";
}
initWebRootContext();
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
public void registerInstance(String serviceName, String ip, int port)
throws NacosException {
@ -234,8 +238,7 @@ public class NacosNamingService implements NamingService {
if (subscribe) {
serviceInfo = hostReactor.getServiceInfo(serviceName,
StringUtils.join(clusters, ","));
}
else {
} else {
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(serviceName,
StringUtils.join(clusters, ","));
}
@ -272,8 +275,7 @@ public class NacosNamingService implements NamingService {
if (subscribe) {
serviceInfo = hostReactor.getServiceInfo(serviceName,
StringUtils.join(clusters, ","));
}
else {
} else {
serviceInfo = hostReactor.getServiceInfoDirectlyFromServer(serviceName,
StringUtils.join(clusters, ","));
}
@ -304,8 +306,7 @@ public class NacosNamingService implements NamingService {
if (subscribe) {
return Balancer.RandomByWeight.selectHost(hostReactor
.getServiceInfo(serviceName, StringUtils.join(clusters, ",")));
}
else {
} else {
return Balancer.RandomByWeight
.selectHost(hostReactor.getServiceInfoDirectlyFromServer(serviceName,
StringUtils.join(clusters, ",")));

View File

@ -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.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.pojo.Instance;
@ -49,6 +50,8 @@ public class NamingProxy {
private static final int DEFAULT_SERVER_PORT = 8848;
private int serverPort = DEFAULT_SERVER_PORT;
private String namespaceId;
private String endpoint;
@ -71,6 +74,7 @@ public class NamingProxy {
this.namespaceId = namespaceId;
this.endpoint = endpoint;
if (StringUtils.isNotEmpty(serverList)) {
this.serverList = Arrays.asList(serverList.split(","));
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() {
@Override
public Thread newThread(Runnable r) {
@ -98,6 +107,10 @@ public class NamingProxy {
refreshSrvIfNeed();
}
public void setServerPort(int serverPort) {
this.serverPort = serverPort;
}
public List<String> getServerListFromEndpoint() {
try {
@ -124,8 +137,7 @@ public class NamingProxy {
return list;
}
catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
@ -156,8 +168,7 @@ public class NamingProxy {
serversFromEndpoint = list;
lastSrvRefTime = System.currentTimeMillis();
}
catch (Throwable e) {
} catch (Throwable e) {
LogUtils.LOG.warn("failed to update server list", e);
}
}
@ -201,8 +212,7 @@ public class NamingProxy {
params.put("ak", tenantAk);
params.put("app", tenantApp);
params.put(Constants.REQUEST_PARAM_NAMESPACE_ID, tenantId);
}
catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}
@ -261,8 +271,7 @@ public class NamingProxy {
if (jsonObject != null) {
return jsonObject.getLong("clientBeatInterval");
}
}
catch (Exception e) {
} catch (Exception e) {
LogUtils.LOG.error("CLIENT-BEAT",
"failed to send beat: " + JSON.toJSONString(beatInfo), e);
}
@ -274,8 +283,7 @@ public class NamingProxy {
try {
reqAPI(UtilAndComs.NACOS_URL_BASE + "/api/hello",
new HashMap<String, String>(2));
}
catch (Exception e) {
} catch (Exception e) {
return false;
}
@ -359,7 +367,7 @@ public class NamingProxy {
if (!curServer.contains(UtilAndComs.SERVER_ADDR_IP_SPLITER)) {
curServer = curServer + UtilAndComs.SERVER_ADDR_IP_SPLITER
+ DEFAULT_SERVER_PORT;
+ serverPort;
}
url = HttpClient.getPrefix() + curServer + api;
@ -410,8 +418,7 @@ public class NamingProxy {
String server = servers.get(index);
try {
return callServer(api, params, server, method);
}
catch (Exception e) {
} catch (Exception e) {
LogUtils.LOG.error("NA",
"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++) {
try {
return callServer(api, params, nacosDomain);
}
catch (Exception e) {
} catch (Exception e) {
LogUtils.LOG.error("NA",
"req api:" + api + " failed, server(" + nacosDomain, e);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@
<inceptionYear>2018</inceptionYear>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.8.0-SNAPSHOT</version>
<version>0.8.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Alibaba NACOS ${project.version}</name>
@ -742,5 +742,6 @@
</dependencies>
</dependencyManagement>
</project>

View File

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