forked from alibaba/nacos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix address server mode cannot be obtained application.properties And…
… synchronize the properties value(alibaba#3509)
- Loading branch information
qm0123
committed
Aug 4, 2020
1 parent
df4b006
commit 95ad77d
Showing
4 changed files
with
59 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,30 +43,30 @@ | |
* @author <a href="mailto:[email protected]">liaochuntao</a> | ||
*/ | ||
public class AddressServerMemberLookup extends AbstractMemberLookup { | ||
|
||
private final GenericType<RestResult<String>> genericType = new GenericType<RestResult<String>>() { | ||
}; | ||
|
||
public String domainName; | ||
|
||
public String addressPort; | ||
|
||
public String addressUrl; | ||
|
||
public String envIdUrl; | ||
|
||
public String addressServerUrl; | ||
|
||
private volatile boolean isAddressServerHealth = true; | ||
|
||
private int addressServerFailCount = 0; | ||
|
||
private int maxFailCount = 12; | ||
|
||
private NSyncHttpClient syncHttpClient = HttpClientManager.getSyncHttpClient(); | ||
|
||
private volatile boolean shutdown = false; | ||
|
||
@Override | ||
public void start() throws NacosException { | ||
if (start.compareAndSet(false, true)) { | ||
|
@@ -75,28 +75,33 @@ public void start() throws NacosException { | |
run(); | ||
} | ||
} | ||
|
||
private void initAddressSys() { | ||
String envDomainName = System.getenv("address_server_domain"); | ||
if (StringUtils.isBlank(envDomainName)) { | ||
domainName = System.getProperty("address.server.domain", "jmenv.tbsite.net"); | ||
domainName = ApplicationUtils.getProperty("address.server.domain", "jmenv.tbsite.net"); | ||
} else { | ||
domainName = envDomainName; | ||
} | ||
String envAddressPort = System.getenv("address_server_port"); | ||
if (StringUtils.isBlank(envAddressPort)) { | ||
addressPort = System.getProperty("address.server.port", "8080"); | ||
addressPort = ApplicationUtils.getProperty("address.server.port", "8080"); | ||
} else { | ||
addressPort = envAddressPort; | ||
} | ||
addressUrl = System.getProperty("address.server.url", ApplicationUtils.getContextPath() + "/" + "serverlist"); | ||
String envAddressUrl = System.getenv("address_server_url"); | ||
if (StringUtils.isBlank(envAddressUrl)) { | ||
addressUrl = ApplicationUtils.getProperty("address.server.url", ApplicationUtils.getContextPath() + "/" + "serverlist"); | ||
} else { | ||
addressUrl = envAddressUrl; | ||
} | ||
addressServerUrl = "http://" + domainName + ":" + addressPort + addressUrl; | ||
envIdUrl = "http://" + domainName + ":" + addressPort + "/env"; | ||
|
||
Loggers.CORE.info("ServerListService address-server port:" + addressPort); | ||
Loggers.CORE.info("ADDRESS_SERVER_URL:" + addressServerUrl); | ||
} | ||
|
||
@SuppressWarnings("PMD.UndefineMagicConstantRule") | ||
private void run() throws NacosException { | ||
// With the address server, you need to perform a synchronous member node pull at startup | ||
|
@@ -117,15 +122,15 @@ private void run() throws NacosException { | |
if (!success) { | ||
throw new NacosException(NacosException.SERVER_ERROR, ex); | ||
} | ||
|
||
GlobalExecutor.scheduleByCommon(new AddressServerSyncTask(), 5_000L); | ||
} | ||
|
||
@Override | ||
public void destroy() throws NacosException { | ||
shutdown = true; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> info() { | ||
Map<String, Object> info = new HashMap<>(4); | ||
|
@@ -135,7 +140,7 @@ public Map<String, Object> info() { | |
info.put("addressServerFailCount", addressServerFailCount); | ||
return info; | ||
} | ||
|
||
private void syncFromAddressUrl() throws Exception { | ||
RestResult<String> result = syncHttpClient | ||
.get(addressServerUrl, Header.EMPTY, Query.EMPTY, genericType.getType()); | ||
|
@@ -158,9 +163,9 @@ private void syncFromAddressUrl() throws Exception { | |
Loggers.CLUSTER.error("[serverlist] failed to get serverlist, error code {}", result.getCode()); | ||
} | ||
} | ||
|
||
class AddressServerSyncTask implements Runnable { | ||
|
||
@Override | ||
public void run() { | ||
if (shutdown) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters