Skip to content

Commit

Permalink
[ISSUE #3909] add domain's judgement (#3913)
Browse files Browse the repository at this point in the history
* add domain's judgement

* modify domain's judgement, can resolve = true

* remove judgement in 'if' code block

* replace Ip to IP in InetUtils

* log warn info when domain can not be resolved

* fix vaiable name
  • Loading branch information
horizonzy authored Oct 12, 2020
1 parent d6cc8ce commit c0496b3
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public Boolean publishConfig(HttpServletRequest request, HttpServletResponse res
.notifyConfigChange(new ConfigDataChangeEvent(true, dataId, group, tenant, time.getTime()));
}
ConfigTraceService
.logPersistenceEvent(dataId, group, tenant, requestIpApp, time.getTime(), InetUtils.getSelfIp(),
.logPersistenceEvent(dataId, group, tenant, requestIpApp, time.getTime(), InetUtils.getSelfIP(),
ConfigTraceService.PERSISTENCE_EVENT_PUB, content);
return true;
}
Expand Down Expand Up @@ -598,7 +598,7 @@ public RestResult<Map<String, Object>> importAndPublishConfig(HttpServletRequest
configInfo.getTenant(), time.getTime()));
ConfigTraceService
.logPersistenceEvent(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(),
requestIpApp, time.getTime(), InetUtils.getSelfIp(),
requestIpApp, time.getTime(), InetUtils.getSelfIP(),
ConfigTraceService.PERSISTENCE_EVENT_PUB, configInfo.getContent());
}
return ResultBuilder.buildSuccessResult("导入成功", saveResult);
Expand Down Expand Up @@ -684,7 +684,7 @@ public RestResult<Map<String, Object>> cloneConfig(HttpServletRequest request,
configInfo.getTenant(), time.getTime()));
ConfigTraceService
.logPersistenceEvent(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(),
requestIpApp, time.getTime(), InetUtils.getSelfIp(),
requestIpApp, time.getTime(), InetUtils.getSelfIP(),
ConfigTraceService.PERSISTENCE_EVENT_PUB, configInfo.getContent());
}
return ResultBuilder.buildSuccessResult("Clone Completed Successfully", saveResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getHealth() {
sb.append("master db (").append(dbStatus.split(":")[1]).append(") down. ");
}
if (!memberManager.isInIpList()) {
sb.append("server ip ").append(InetUtils.getSelfIp())
sb.append("server ip ").append(InetUtils.getSelfIP())
.append(" is not in the serverList of address server. ");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public boolean isSubInfoRecentlyCollected() {
*/
public boolean canCurrentServerOwnTheLock() {
boolean currentOwnerIsMe =
subInfoCollectLockOwner == null || InetUtils.getSelfIp().equals(subInfoCollectLockOwner);
subInfoCollectLockOwner == null || InetUtils.getSelfIP().equals(subInfoCollectLockOwner);

if (currentOwnerIsMe) {
return true;
Expand All @@ -115,7 +115,7 @@ public boolean canCurrentServerOwnTheLock() {
}

public String currentServer() {
return InetUtils.getSelfIp();
return InetUtils.getSelfIP();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public void run() {
}
} else {
// remove config info
persistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIp(), null);
persistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIP(), null);
LOGGER.warn(
"[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId="
+ group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void mergeAll() {
return;
}
for (ConfigInfoChanged item : persistService.findAllAggrGroup()) {
addMergeTask(item.getDataId(), item.getGroup(), item.getTenant(), InetUtils.getSelfIp());
addMergeTask(item.getDataId(), item.getGroup(), item.getTenant(), InetUtils.getSelfIP());
}
}

Expand Down Expand Up @@ -163,7 +163,7 @@ public void run() {
ContentUtils.truncateContent(cf.getContent()));
} else {
// remove
persistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIp(), null);
persistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIP(), null);
LOGGER.warn("[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId="
+ group);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean process(AbstractDelayTask task) {
ContentUtils.truncateContent(cf.getContent()));

ConfigTraceService
.logPersistenceEvent(dataId, group, tenant, null, time.getTime(), InetUtils.getSelfIp(),
.logPersistenceEvent(dataId, group, tenant, null, time.getTime(), InetUtils.getSelfIP(),
ConfigTraceService.PERSISTENCE_EVENT_MERGE, cf.getContent());
} else {
// remove
Expand All @@ -98,7 +98,7 @@ public boolean process(AbstractDelayTask task) {
"[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId=" + group);

ConfigTraceService
.logPersistenceEvent(dataId, group, tenant, null, time.getTime(), InetUtils.getSelfIp(),
.logPersistenceEvent(dataId, group, tenant, null, time.getTime(), InetUtils.getSelfIP(),
ConfigTraceService.PERSISTENCE_EVENT_REMOVE, null);
}
NotifyCenter.publishEvent(new ConfigDataChangeEvent(false, dataId, group, tenant, tag, time.getTime()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ private void executeAsyncInvoke() {
if (unHealthNeedDelay) {
// target ip is unhealthy, then put it in the notification list
ConfigTraceService.logNotifyEvent(task.getDataId(), task.getGroup(), task.getTenant(), null,
task.getLastModified(), InetUtils.getSelfIp(), ConfigTraceService.NOTIFY_EVENT_UNHEALTH,
task.getLastModified(), InetUtils.getSelfIP(), ConfigTraceService.NOTIFY_EVENT_UNHEALTH,
0, task.target);
// get delay time and set fail count to the task
asyncTaskExecute(task);
} else {
Header header = Header.newInstance();
header.addParam(NotifyService.NOTIFY_HEADER_LAST_MODIFIED, String.valueOf(task.getLastModified()));
header.addParam(NotifyService.NOTIFY_HEADER_OP_HANDLE_IP, InetUtils.getSelfIp());
header.addParam(NotifyService.NOTIFY_HEADER_OP_HANDLE_IP, InetUtils.getSelfIP());
if (task.isBeta) {
header.addParam("isBeta", "true");
}
Expand Down Expand Up @@ -168,13 +168,13 @@ public void onReceive(RestResult<String> result) {

if (result.ok()) {
ConfigTraceService.logNotifyEvent(task.getDataId(), task.getGroup(), task.getTenant(), null,
task.getLastModified(), InetUtils.getSelfIp(), ConfigTraceService.NOTIFY_EVENT_OK, delayed,
task.getLastModified(), InetUtils.getSelfIP(), ConfigTraceService.NOTIFY_EVENT_OK, delayed,
task.target);
} else {
LOGGER.error("[notify-error] target:{} dataId:{} group:{} ts:{} code:{}", task.target, task.getDataId(),
task.getGroup(), task.getLastModified(), result.getCode());
ConfigTraceService.logNotifyEvent(task.getDataId(), task.getGroup(), task.getTenant(), null,
task.getLastModified(), InetUtils.getSelfIp(), ConfigTraceService.NOTIFY_EVENT_ERROR, delayed,
task.getLastModified(), InetUtils.getSelfIP(), ConfigTraceService.NOTIFY_EVENT_ERROR, delayed,
task.target);

//get delay time and set fail count to the task
Expand All @@ -196,7 +196,7 @@ public void onError(Throwable ex) {
task.getGroup(), task.getLastModified(), ex.toString());
ConfigTraceService
.logNotifyEvent(task.getDataId(), task.getGroup(), task.getTenant(), null, task.getLastModified(),
InetUtils.getSelfIp(), ConfigTraceService.NOTIFY_EVENT_EXCEPTION, delayed, task.target);
InetUtils.getSelfIP(), ConfigTraceService.NOTIFY_EVENT_EXCEPTION, delayed, task.target);

//get delay time and set fail count to the task
asyncTaskExecute(task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ boolean notifyToDump(String dataId, String group, String tenant, long lastModifi
*/
List<String> headers = Arrays
.asList(NotifyService.NOTIFY_HEADER_LAST_MODIFIED, String.valueOf(lastModified),
NotifyService.NOTIFY_HEADER_OP_HANDLE_IP, InetUtils.getSelfIp());
NotifyService.NOTIFY_HEADER_OP_HANDLE_IP, InetUtils.getSelfIP());
String urlString = MessageFormat
.format(URL_PATTERN, serverIp, ApplicationUtils.getContextPath(), dataId, group);

RestResult<String> result = NotifyService.invokeURL(urlString, headers, Constants.ENCODE);
if (result.ok()) {
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, InetUtils.getSelfIp(),
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, InetUtils.getSelfIP(),
ConfigTraceService.NOTIFY_EVENT_OK, delayed, serverIp);

MetricsMonitor.getNotifyRtTimer().record(delayed, TimeUnit.MILLISECONDS);
Expand All @@ -89,15 +89,15 @@ boolean notifyToDump(String dataId, String group, String tenant, long lastModifi
MetricsMonitor.getConfigNotifyException().increment();
LOGGER.error("[notify-error] {}, {}, to {}, result {}",
new Object[] {dataId, group, serverIp, result.getCode()});
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, InetUtils.getSelfIp(),
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, InetUtils.getSelfIP(),
ConfigTraceService.NOTIFY_EVENT_ERROR, delayed, serverIp);
return false;
}
} catch (Exception e) {
MetricsMonitor.getConfigNotifyException().increment();
LOGGER.error("[notify-exception] " + dataId + ", " + group + ", to " + serverIp + ", " + e.toString());
LOGGER.debug("[notify-exception] " + dataId + ", " + group + ", to " + serverIp + ", " + e.toString(), e);
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, InetUtils.getSelfIp(),
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, InetUtils.getSelfIP(),
ConfigTraceService.NOTIFY_EVENT_EXCEPTION, delayed, serverIp);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void logPersistenceEvent(String dataId, String group, String tenan
// (md5)
String md5 = content == null ? null : MD5Utils.md5Hex(content, Constants.ENCODE);

LogUtil.TRACE_LOG.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIp(), dataId, group, tenant,
LogUtil.TRACE_LOG.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIP(), dataId, group, tenant,
requestIpAppName, ts, handleIp, "persist", type, -1, md5);
}

Expand Down Expand Up @@ -116,7 +116,7 @@ public static void logNotifyEvent(String dataId, String group, String tenant, St
}
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed] | ext
// (targetIp)
LogUtil.TRACE_LOG.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIp(), dataId, group, tenant,
LogUtil.TRACE_LOG.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIP(), dataId, group, tenant,
requestIpAppName, ts, handleIp, "notify", type, delayed, targetIp);
}

Expand All @@ -143,7 +143,7 @@ public static void logDumpEvent(String dataId, String group, String tenant, Stri
tenant = null;
}
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed] | length
LogUtil.TRACE_LOG.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIp(), dataId, group, tenant,
LogUtil.TRACE_LOG.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIP(), dataId, group, tenant,
requestIpAppName, ts, handleIp, "dump", type, delayed, length);
}

Expand All @@ -169,7 +169,7 @@ public static void logDumpAllEvent(String dataId, String group, String tenant, S
}
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed = -1]
LogUtil.TRACE_LOG
.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIp(), dataId, group, tenant, requestIpAppName,
.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIP(), dataId, group, tenant, requestIpAppName,
ts, handleIp, "dump-all", type, -1);
}

Expand All @@ -196,7 +196,7 @@ public static void logPullEvent(String dataId, String group, String tenant, Stri
}
//localIp | dataid | group | tenant| requestIpAppName| ts | event | type | [delayed] | ext(clientIp)
LogUtil.TRACE_LOG
.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIp(), dataId, group, tenant, requestIpAppName,
.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIP(), dataId, group, tenant, requestIpAppName,
ts, "pull", type, delayed, clientIp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public ServerMemberManager(ServletContext servletContext) throws Exception {
protected void init() throws NacosException {
Loggers.CORE.info("Nacos-related cluster resource initialization");
this.port = ApplicationUtils.getProperty("server.port", Integer.class, 8848);
this.localAddress = InetUtils.getSelfIp() + ":" + port;
this.localAddress = InetUtils.getSelfIP() + ":" + port;
this.self = MemberUtils.singleParse(this.localAddress);
this.self.setExtendVal(MemberMetaDataConstants.VERSION, VersionUtils.version);
serverList.put(self.getAddress(), self);
Expand Down Expand Up @@ -169,14 +169,14 @@ private void registerClusterEvent() {
NotifyCenter.registerSubscriber(new Subscriber<InetUtils.IPChangeEvent>() {
@Override
public void onEvent(InetUtils.IPChangeEvent event) {
String newAddress = event.getNewIp() + ":" + port;
String newAddress = event.getNewIP() + ":" + port;
ServerMemberManager.this.localAddress = newAddress;
ApplicationUtils.setLocalAddress(localAddress);

Member self = ServerMemberManager.this.self;
self.setIp(event.getNewIp());
self.setIp(event.getNewIP());

String oldAddress = event.getOldIp() + ":" + port;
String oldAddress = event.getOldIP() + ":" + port;
ServerMemberManager.this.serverList.remove(oldAddress);
ServerMemberManager.this.serverList.put(newAddress, self);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class StandaloneMemberLookup extends AbstractMemberLookup {
@Override
public void start() {
if (start.compareAndSet(false, true)) {
String url = InetUtils.getSelfIp() + ":" + ApplicationUtils.getPort();
String url = InetUtils.getSelfIP() + ":" + ApplicationUtils.getPort();
afterLookup(MemberUtils.readServerConf(Collections.singletonList(url)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void environmentPrepared(ConfigurableEnvironment environment) {
System.setProperty(MODE_PROPERTY_KEY_FUNCTION_MODE, ApplicationUtils.FUNCTION_MODE_NAMING);
}

System.setProperty(LOCAL_IP_PROPERTY_KEY, InetUtils.getSelfIp());
System.setProperty(LOCAL_IP_PROPERTY_KEY, InetUtils.getSelfIP());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class NetUtils {
* @return local server address
*/
public static String localServer() {
return InetUtils.getSelfIp() + UtilsAndCommons.IP_PORT_SPLITER + ApplicationUtils.getPort();
return InetUtils.getSelfIP() + UtilsAndCommons.IP_PORT_SPLITER + ApplicationUtils.getPort();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public static List<String> getPropertyList(String key) {

public static String getLocalAddress() {
if (StringUtils.isBlank(localAddress)) {
localAddress = InetUtils.getSelfIp() + ":" + getPort();
localAddress = InetUtils.getSelfIP() + ":" + getPort();
}
return localAddress;
}
Expand Down
Loading

0 comments on commit c0496b3

Please sign in to comment.