diff --git a/api/src/main/java/com/alibaba/nacos/api/naming/utils/NamingUtils.java b/api/src/main/java/com/alibaba/nacos/api/naming/utils/NamingUtils.java
index 911219ae3..9faa8b40b 100644
--- a/api/src/main/java/com/alibaba/nacos/api/naming/utils/NamingUtils.java
+++ b/api/src/main/java/com/alibaba/nacos/api/naming/utils/NamingUtils.java
@@ -28,6 +28,9 @@ import com.alibaba.nacos.api.utils.StringUtils;
public class NamingUtils {
public static String getGroupedName(final String serviceName, final String groupName) {
+ if (StringUtils.isBlank(serviceName)) {
+ throw new IllegalArgumentException("Param 'serviceName' is illegal, serviceName is blank");
+ }
final String resultGroupedName = groupName + Constants.SERVICE_INFO_SPLITER + serviceName;
return resultGroupedName.intern();
}
diff --git a/api/src/main/resources/application.properties b/api/src/main/resources/application.properties
deleted file mode 100644
index 0b3684628..000000000
--- a/api/src/main/resources/application.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# 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.
-#
-version=${project.version}
diff --git a/auth/pom.xml b/auth/pom.xml
index a048b81cf..afd43988b 100644
--- a/auth/pom.xml
+++ b/auth/pom.xml
@@ -40,6 +40,10 @@
${project.groupId}nacos-common
+
+ ${project.groupId}
+ nacos-sys
+ org.springframework.boot
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/common/AuthConfigs.java b/auth/src/main/java/com/alibaba/nacos/auth/common/AuthConfigs.java
index 19638654b..721359b36 100644
--- a/auth/src/main/java/com/alibaba/nacos/auth/common/AuthConfigs.java
+++ b/auth/src/main/java/com/alibaba/nacos/auth/common/AuthConfigs.java
@@ -16,12 +16,11 @@
package com.alibaba.nacos.auth.common;
-import com.alibaba.nacos.auth.common.env.ReloadableConfigs;
import com.alibaba.nacos.common.JustForTest;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import io.jsonwebtoken.io.Decoders;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@@ -40,9 +39,6 @@ public class AuthConfigs {
@JustForTest
private static Boolean cachingEnabled = null;
- @Autowired
- private ReloadableConfigs reloadableConfigs;
-
/**
* secret key.
*/
@@ -93,7 +89,7 @@ public class AuthConfigs {
return BooleanUtils.toBoolean(enabled);
}
return BooleanUtils
- .toBoolean(reloadableConfigs.getProperties().getProperty("nacos.core.auth.enabled", "false"));
+ .toBoolean(ApplicationUtils.getProperty("nacos.core.auth.enabled", "false"));
}
/**
@@ -106,7 +102,7 @@ public class AuthConfigs {
return cachingEnabled;
}
return BooleanUtils
- .toBoolean(reloadableConfigs.getProperties().getProperty("nacos.core.auth.caching.enabled", "true"));
+ .toBoolean(ApplicationUtils.getProperty("nacos.core.auth.caching.enabled", "true"));
}
@JustForTest
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/common/env/ReloadableConfigs.java b/auth/src/main/java/com/alibaba/nacos/auth/common/env/ReloadableConfigs.java
deleted file mode 100644
index 6984ad52e..000000000
--- a/auth/src/main/java/com/alibaba/nacos/auth/common/env/ReloadableConfigs.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.auth.common.env;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * Reload application.properties.
- *
- * @author nkorange
- * @author mai.jh
- * @since 1.2.0
- */
-@Component
-public class ReloadableConfigs {
-
- private static final String FILE_PREFIX = "file:";
-
- private Properties properties;
-
- @Value("${spring.config.location:}")
- private String path;
-
- /**
- * Periodically load configuration file information.
- *
- * @throws IOException IOException
- */
- @Scheduled(fixedRate = 5000)
- public void reload() throws IOException {
- final Properties properties = new Properties();
- InputStream inputStream = null;
- if (StringUtils.isNotBlank(path) && path.contains(FILE_PREFIX)) {
- String[] paths = path.split(",");
- path = paths[paths.length - 1].substring(FILE_PREFIX.length());
- }
- try {
- inputStream = new FileInputStream(new File(path + "application.properties"));
- } catch (Exception ignore) {
- }
- if (inputStream == null) {
- inputStream = getClass().getResourceAsStream("/application.properties");
- }
- properties.load(inputStream);
- inputStream.close();
- this.properties = properties;
- }
-
- public final Properties getProperties() {
- return properties;
- }
-}
diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java
index fab00f032..93578dda9 100644
--- a/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java
+++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java
@@ -32,7 +32,6 @@ import com.alibaba.nacos.client.utils.ParamUtil;
import com.alibaba.nacos.client.utils.TenantUtil;
import com.alibaba.nacos.common.http.HttpRestResult;
import com.alibaba.nacos.common.lifecycle.Closeable;
-import com.alibaba.nacos.common.utils.ConcurrentHashSet;
import com.alibaba.nacos.common.utils.ConvertUtils;
import com.alibaba.nacos.common.utils.MD5Utils;
import com.alibaba.nacos.common.utils.StringUtils;
@@ -166,7 +165,6 @@ public class ClientWorker implements Closeable {
copy.remove(groupKey);
cacheMap.set(copy);
}
- reMakeCacheDataTaskId();
LOGGER.info("[{}] [unsubscribe] {}", this.agent.getName(), groupKey);
MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
@@ -179,38 +177,11 @@ public class ClientWorker implements Closeable {
copy.remove(groupKey);
cacheMap.set(copy);
}
- reMakeCacheDataTaskId();
LOGGER.info("[{}] [unsubscribe] {}", agent.getName(), groupKey);
MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
}
- /**
- * Remake cacheData taskId.
- */
- private void reMakeCacheDataTaskId() {
- int listenerSize = cacheMap.get().size();
- int remakeTaskId = (int) Math.ceil(listenerSize / ParamUtil.getPerTaskConfigSize());
- if (remakeTaskId < (int) currentLongingTaskCount) {
- for (int i = 0; i < remakeTaskId; i++) {
- int count = 0;
- for (String key : cacheMap.get().keySet()) {
- if (count == ParamUtil.getPerTaskConfigSize()) {
- break;
- }
- CacheData cacheData = cacheMap.get().get(key);
- cacheData.setTaskId(i);
- synchronized (cacheMap) {
- Map copy = new HashMap(this.cacheMap.get());
- copy.put(key, cacheData);
- cacheMap.set(copy);
- }
- count++;
- }
- }
- }
- }
-
/**
* Add cache data if absent.
*
@@ -277,8 +248,6 @@ public class ClientWorker implements Closeable {
cache.setInitializing(true);
} else {
cache = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);
- int taskId = cacheMap.get().size() / (int) ParamUtil.getPerTaskConfigSize();
- cache.setTaskId(taskId);
// fix issue # 1317
if (enableRemoteSyncConfig) {
String[] ct = getServerConfig(dataId, group, tenant, 3000L);
@@ -425,16 +394,11 @@ public class ClientWorker implements Closeable {
int longingTaskCount = (int) Math.ceil(listenerSize / ParamUtil.getPerTaskConfigSize());
if (longingTaskCount > currentLongingTaskCount) {
for (int i = (int) currentLongingTaskCount; i < longingTaskCount; i++) {
- taskIdSet.add(i);
// The task list is no order.So it maybe has issues when changing.
executorService.execute(new LongPollingRunnable(i));
}
- } else if (longingTaskCount < currentLongingTaskCount) {
- for (int i = longingTaskCount; i < (int) currentLongingTaskCount; i++) {
- taskIdSet.remove(i);
- }
+ currentLongingTaskCount = longingTaskCount;
}
- currentLongingTaskCount = longingTaskCount;
}
/**
@@ -692,9 +656,7 @@ public class ClientWorker implements Closeable {
}
inInitializingCacheList.clear();
- if (taskIdSet.contains(taskId)) {
- executorService.execute(this);
- }
+ executorService.execute(this);
} catch (Throwable e) {
@@ -723,11 +685,6 @@ public class ClientWorker implements Closeable {
private final AtomicReference
+
+ ${project.groupId}
+ nacos-sys
+ ${project.version}
+ javax.servlet
diff --git a/style/nacos-code-style-for-idea.xml b/style/nacos-code-style-for-idea.xml
index 28846f8ae..6bd63a113 100644
--- a/style/nacos-code-style-for-idea.xml
+++ b/style/nacos-code-style-for-idea.xml
@@ -139,6 +139,7 @@
+
diff --git a/sys/pom.xml b/sys/pom.xml
new file mode 100644
index 000000000..0ed61ee19
--- /dev/null
+++ b/sys/pom.xml
@@ -0,0 +1,90 @@
+
+
+
+
+
+ com.alibaba.nacos
+ nacos-all
+ 1.4.0-SNAPSHOT
+ ../pom.xml
+
+ 4.0.0
+
+ nacos-sys
+ jar
+ nacos-sys ${project.version}
+ http://nacos.io
+
+
+ UTF-8
+
+
+
+
+ ${project.groupId}
+ nacos-common
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.junit.vintage
+ junit-vintage-engine
+
+
+
+
+
+ junit
+ junit
+ test
+
+
+
+ org.springframework
+ spring-test
+
+
+
+ org.springframework.boot
+ spring-boot-test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 8
+
+
+
+
+
\ No newline at end of file
diff --git a/core/src/main/java/com/alibaba/nacos/core/utils/Constants.java b/sys/src/main/java/com/alibaba/nacos/sys/env/Constants.java
similarity index 98%
rename from core/src/main/java/com/alibaba/nacos/core/utils/Constants.java
rename to sys/src/main/java/com/alibaba/nacos/sys/env/Constants.java
index 00baab7a1..20addac2c 100644
--- a/core/src/main/java/com/alibaba/nacos/core/utils/Constants.java
+++ b/sys/src/main/java/com/alibaba/nacos/sys/env/Constants.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.alibaba.nacos.core.utils;
+package com.alibaba.nacos.sys.env;
/**
* Nacos common constants.
diff --git a/sys/src/main/java/com/alibaba/nacos/sys/env/NacosAutoRefreshPropertySourceLoader.java b/sys/src/main/java/com/alibaba/nacos/sys/env/NacosAutoRefreshPropertySourceLoader.java
new file mode 100644
index 000000000..a82919b54
--- /dev/null
+++ b/sys/src/main/java/com/alibaba/nacos/sys/env/NacosAutoRefreshPropertySourceLoader.java
@@ -0,0 +1,94 @@
+/*
+ * 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.sys.env;
+
+import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.common.JustForTest;
+import com.alibaba.nacos.sys.file.FileChangeEvent;
+import com.alibaba.nacos.sys.file.FileWatcher;
+import com.alibaba.nacos.sys.file.WatchFileCenter;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.boot.env.OriginTrackedMapPropertySource;
+import org.springframework.boot.env.PropertySourceLoader;
+import org.springframework.core.env.PropertySource;
+import org.springframework.core.io.Resource;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Support for configuring automatic refresh and loading into the Environment.
+ *
+ * @author liaochuntao
+ */
+public class NacosAutoRefreshPropertySourceLoader implements PropertySourceLoader {
+
+ private final Map properties = new ConcurrentHashMap<>(16);
+
+ private Resource holder = null;
+
+ @Override
+ public String[] getFileExtensions() {
+ return new String[] {"properties"};
+ }
+
+ @Override
+ public List> load(String name, Resource resource) throws IOException {
+ holder = resource;
+ Map tmp = loadProperties(resource);
+ properties.putAll(tmp);
+
+ try {
+ WatchFileCenter.registerWatcher(ApplicationUtils.getConfFilePath(), new FileWatcher() {
+ @Override
+ public void onChange(FileChangeEvent event) {
+ try {
+ Map tmp1 = loadProperties(holder);
+ properties.putAll(tmp1);
+ } catch (IOException ignore) {
+
+ }
+ }
+
+ @Override
+ public boolean interest(String context) {
+ return StringUtils.contains(context, "application.properties");
+ }
+ });
+ } catch (NacosException ignore) {
+
+ }
+
+ if (properties.isEmpty()) {
+ return Collections.emptyList();
+ }
+ return Collections.singletonList(new OriginTrackedMapPropertySource("nacos_application_conf", properties));
+ }
+
+ private Map loadProperties(Resource resource) throws IOException {
+ return new OriginTrackedPropertiesLoader(resource).load();
+ }
+
+ @JustForTest
+ protected Map getProperties() {
+ return properties;
+ }
+}
diff --git a/core/src/main/java/com/alibaba/nacos/core/env/NacosDefaultPropertySourceEnvironmentPostProcessor.java b/sys/src/main/java/com/alibaba/nacos/sys/env/NacosDefaultPropertySourceEnvironmentPostProcessor.java
similarity index 94%
rename from core/src/main/java/com/alibaba/nacos/core/env/NacosDefaultPropertySourceEnvironmentPostProcessor.java
rename to sys/src/main/java/com/alibaba/nacos/sys/env/NacosDefaultPropertySourceEnvironmentPostProcessor.java
index 026431ed6..ce9d156ef 100644
--- a/core/src/main/java/com/alibaba/nacos/core/env/NacosDefaultPropertySourceEnvironmentPostProcessor.java
+++ b/sys/src/main/java/com/alibaba/nacos/sys/env/NacosDefaultPropertySourceEnvironmentPostProcessor.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.alibaba.nacos.core.env;
+package com.alibaba.nacos.sys.env;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
@@ -34,8 +34,6 @@ import org.springframework.core.io.support.ResourcePropertySource;
import java.io.IOException;
-import static org.springframework.core.io.support.ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX;
-
/**
* A lowest precedence {@link EnvironmentPostProcessor} implementation to append Nacos default {@link PropertySource}
* with lowest order in {@link Environment}.
@@ -43,6 +41,7 @@ import static org.springframework.core.io.support.ResourcePatternResolver.CLASSP
* @author Mercy
* @since 0.2.2
*/
+@Deprecated
public class NacosDefaultPropertySourceEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
/**
@@ -56,7 +55,7 @@ public class NacosDefaultPropertySourceEnvironmentPostProcessor implements Envir
* @see ResourcePatternResolver#CLASSPATH_ALL_URL_PREFIX
*/
public static final String RESOURCE_LOCATION_PATTERN =
- CLASSPATH_ALL_URL_PREFIX + "META-INF/nacos-default.properties";
+ ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "META-INF/nacos-default.properties";
private static final String FILE_ENCODING = "UTF-8";
@@ -114,6 +113,6 @@ public class NacosDefaultPropertySourceEnvironmentPostProcessor implements Envir
@Override
public int getOrder() {
- return LOWEST_PRECEDENCE;
+ return Ordered.LOWEST_PRECEDENCE;
}
}
diff --git a/sys/src/main/java/com/alibaba/nacos/sys/env/OriginTrackedPropertiesLoader.java b/sys/src/main/java/com/alibaba/nacos/sys/env/OriginTrackedPropertiesLoader.java
new file mode 100644
index 000000000..47e77e1b9
--- /dev/null
+++ b/sys/src/main/java/com/alibaba/nacos/sys/env/OriginTrackedPropertiesLoader.java
@@ -0,0 +1,259 @@
+/*
+ * 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.sys.env;
+
+import org.springframework.boot.origin.Origin;
+import org.springframework.boot.origin.OriginTrackedValue;
+import org.springframework.boot.origin.TextResourceOrigin;
+import org.springframework.core.io.Resource;
+import org.springframework.util.Assert;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.nio.charset.StandardCharsets;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * copy from springboot to load properties file.
+ *
+ * @author liaochuntao
+ */
+@SuppressWarnings("PMD.UndefineMagicConstantRule")
+public class OriginTrackedPropertiesLoader {
+
+ private final Resource resource;
+
+ /**
+ * Create a new {@link OriginTrackedPropertiesLoader} instance.
+ *
+ * @param resource the resource of the {@code .properties} data
+ */
+ OriginTrackedPropertiesLoader(Resource resource) {
+ Assert.notNull(resource, "Resource must not be null");
+ this.resource = resource;
+ }
+
+ /**
+ * Load {@code .properties} data and return a map of {@code String} -> {@link OriginTrackedValue}.
+ *
+ * @return the loaded properties
+ * @throws IOException on read error
+ */
+ public Map load() throws IOException {
+ return load(true);
+ }
+
+ /**
+ * Load {@code .properties} data and return a map of {@code String} -> {@link OriginTrackedValue}.
+ *
+ * @param expandLists if list {@code name[]=a,b,c} shortcuts should be expanded
+ * @return the loaded properties
+ * @throws IOException on read error
+ */
+ public Map load(boolean expandLists) throws IOException {
+ try (OriginTrackedPropertiesLoader.CharacterReader reader = new CharacterReader(this.resource)) {
+ Map result = new LinkedHashMap<>();
+ StringBuilder buffer = new StringBuilder();
+ while (reader.read()) {
+ String key = loadKey(buffer, reader).trim();
+ if (expandLists && key.endsWith("[]")) {
+ key = key.substring(0, key.length() - 2);
+ int index = 0;
+ do {
+ OriginTrackedValue value = loadValue(buffer, reader, true);
+ put(result, key + "[" + (index++) + "]", value);
+ if (!reader.isEndOfLine()) {
+ reader.read();
+ }
+ } while (!reader.isEndOfLine());
+ } else {
+ OriginTrackedValue value = loadValue(buffer, reader, false);
+ put(result, key, value);
+ }
+ }
+ return result;
+ }
+ }
+
+ private void put(Map result, String key, OriginTrackedValue value) {
+ if (!key.isEmpty()) {
+ result.put(key, value);
+ }
+ }
+
+ private String loadKey(StringBuilder buffer, OriginTrackedPropertiesLoader.CharacterReader reader)
+ throws IOException {
+ buffer.setLength(0);
+ boolean previousWhitespace = false;
+ while (!reader.isEndOfLine()) {
+ if (reader.isPropertyDelimiter()) {
+ reader.read();
+ return buffer.toString();
+ }
+ if (!reader.isWhiteSpace() && previousWhitespace) {
+ return buffer.toString();
+ }
+ previousWhitespace = reader.isWhiteSpace();
+ buffer.append(reader.getCharacter());
+ reader.read();
+ }
+ return buffer.toString();
+ }
+
+ private OriginTrackedValue loadValue(StringBuilder buffer, OriginTrackedPropertiesLoader.CharacterReader reader,
+ boolean splitLists) throws IOException {
+ buffer.setLength(0);
+ while (reader.isWhiteSpace() && !reader.isEndOfLine()) {
+ reader.read();
+ }
+ TextResourceOrigin.Location location = reader.getLocation();
+ while (!reader.isEndOfLine() && !(splitLists && reader.isListDelimiter())) {
+ buffer.append(reader.getCharacter());
+ reader.read();
+ }
+ Origin origin = new TextResourceOrigin(this.resource, location);
+ return OriginTrackedValue.of(buffer.toString(), origin);
+ }
+
+ /**
+ * Reads characters from the source resource, taking care of skipping comments, handling multi-line values and
+ * tracking {@code '\'} escapes.
+ */
+ private static class CharacterReader implements Closeable {
+
+ private final String[] escapes = {"trnf", "\t\r\n\f"};
+
+ private final LineNumberReader reader;
+
+ private int columnNumber = -1;
+
+ private boolean escaped;
+
+ private int character;
+
+ CharacterReader(Resource resource) throws IOException {
+ this.reader = new LineNumberReader(
+ new InputStreamReader(resource.getInputStream(), StandardCharsets.ISO_8859_1));
+ }
+
+ @Override
+ public void close() throws IOException {
+ this.reader.close();
+ }
+
+ public boolean read() throws IOException {
+ return read(false);
+ }
+
+ public boolean read(boolean wrappedLine) throws IOException {
+ this.escaped = false;
+ this.character = this.reader.read();
+ this.columnNumber++;
+ if (this.columnNumber == 0) {
+ skipLeadingWhitespace();
+ if (!wrappedLine) {
+ skipComment();
+ }
+ }
+ if (this.character == '\\') {
+ this.escaped = true;
+ readEscaped();
+ } else if (this.character == '\n') {
+ this.columnNumber = -1;
+ }
+ return !isEndOfFile();
+ }
+
+ private void skipLeadingWhitespace() throws IOException {
+ while (isWhiteSpace()) {
+ this.character = this.reader.read();
+ this.columnNumber++;
+ }
+ }
+
+ private void skipComment() throws IOException {
+ if (this.character == '#' || this.character == '!') {
+ while (this.character != '\n' && this.character != -1) {
+ this.character = this.reader.read();
+ }
+ this.columnNumber = -1;
+ read();
+ }
+ }
+
+ private void readEscaped() throws IOException {
+ this.character = this.reader.read();
+ int escapeIndex = escapes[0].indexOf(this.character);
+ if (escapeIndex != -1) {
+ this.character = escapes[1].charAt(escapeIndex);
+ } else if (this.character == '\n') {
+ this.columnNumber = -1;
+ read(true);
+ } else if (this.character == 'u') {
+ readUnicode();
+ }
+ }
+
+ private void readUnicode() throws IOException {
+ this.character = 0;
+ for (int i = 0; i < 4; i++) {
+ int digit = this.reader.read();
+ if (digit >= '0' && digit <= '9') {
+ this.character = (this.character << 4) + digit - '0';
+ } else if (digit >= 'a' && digit <= 'f') {
+ this.character = (this.character << 4) + digit - 'a' + 10;
+ } else if (digit >= 'A' && digit <= 'F') {
+ this.character = (this.character << 4) + digit - 'A' + 10;
+ } else {
+ throw new IllegalStateException("Malformed \\uxxxx encoding.");
+ }
+ }
+ }
+
+ public boolean isWhiteSpace() {
+ return !this.escaped && (this.character == ' ' || this.character == '\t' || this.character == '\f');
+ }
+
+ public boolean isEndOfFile() {
+ return this.character == -1;
+ }
+
+ public boolean isEndOfLine() {
+ return this.character == -1 || (!this.escaped && this.character == '\n');
+ }
+
+ public boolean isListDelimiter() {
+ return !this.escaped && this.character == ',';
+ }
+
+ public boolean isPropertyDelimiter() {
+ return !this.escaped && (this.character == '=' || this.character == ':');
+ }
+
+ public char getCharacter() {
+ return (char) this.character;
+ }
+
+ public TextResourceOrigin.Location getLocation() {
+ return new TextResourceOrigin.Location(this.reader.getLineNumber(), this.columnNumber);
+ }
+
+ }
+}
diff --git a/core/src/main/java/com/alibaba/nacos/core/file/FileChangeEvent.java b/sys/src/main/java/com/alibaba/nacos/sys/file/FileChangeEvent.java
similarity index 98%
rename from core/src/main/java/com/alibaba/nacos/core/file/FileChangeEvent.java
rename to sys/src/main/java/com/alibaba/nacos/sys/file/FileChangeEvent.java
index 3cdabf500..e7f62f37e 100644
--- a/core/src/main/java/com/alibaba/nacos/core/file/FileChangeEvent.java
+++ b/sys/src/main/java/com/alibaba/nacos/sys/file/FileChangeEvent.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.alibaba.nacos.core.file;
+package com.alibaba.nacos.sys.file;
import java.io.Serializable;
diff --git a/core/src/main/java/com/alibaba/nacos/core/file/FileWatcher.java b/sys/src/main/java/com/alibaba/nacos/sys/file/FileWatcher.java
similarity index 97%
rename from core/src/main/java/com/alibaba/nacos/core/file/FileWatcher.java
rename to sys/src/main/java/com/alibaba/nacos/sys/file/FileWatcher.java
index b51b4526c..465a4984f 100644
--- a/core/src/main/java/com/alibaba/nacos/core/file/FileWatcher.java
+++ b/sys/src/main/java/com/alibaba/nacos/sys/file/FileWatcher.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.alibaba.nacos.core.file;
+package com.alibaba.nacos.sys.file;
import java.nio.file.WatchEvent;
import java.util.concurrent.Executor;
diff --git a/core/src/main/java/com/alibaba/nacos/core/file/WatchFileCenter.java b/sys/src/main/java/com/alibaba/nacos/sys/file/WatchFileCenter.java
similarity index 99%
rename from core/src/main/java/com/alibaba/nacos/core/file/WatchFileCenter.java
rename to sys/src/main/java/com/alibaba/nacos/sys/file/WatchFileCenter.java
index 97849bb91..7d6b1de3d 100644
--- a/core/src/main/java/com/alibaba/nacos/core/file/WatchFileCenter.java
+++ b/sys/src/main/java/com/alibaba/nacos/sys/file/WatchFileCenter.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.alibaba.nacos.core.file;
+package com.alibaba.nacos.sys.file;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.common.executor.ExecutorFactory;
@@ -176,7 +176,7 @@ public class WatchFileCenter {
}
this.callBackExecutor = ExecutorFactory
- .newSingleExecutorService(new NameThreadFactory("com.alibaba.nacos.core.file.watch-" + paths));
+ .newSingleExecutorService(new NameThreadFactory("com.alibaba.nacos.sys.file.watch-" + paths));
try {
WatchService service = FILE_SYSTEM.newWatchService();
diff --git a/core/src/main/java/com/alibaba/nacos/core/utils/ApplicationUtils.java b/sys/src/main/java/com/alibaba/nacos/sys/utils/ApplicationUtils.java
similarity index 94%
rename from core/src/main/java/com/alibaba/nacos/core/utils/ApplicationUtils.java
rename to sys/src/main/java/com/alibaba/nacos/sys/utils/ApplicationUtils.java
index 7b8004570..9b744b669 100644
--- a/core/src/main/java/com/alibaba/nacos/core/utils/ApplicationUtils.java
+++ b/sys/src/main/java/com/alibaba/nacos/sys/utils/ApplicationUtils.java
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-package com.alibaba.nacos.core.utils;
+package com.alibaba.nacos.sys.utils;
import com.alibaba.nacos.common.JustForTest;
import com.alibaba.nacos.common.utils.IoUtils;
import com.alibaba.nacos.common.utils.StringUtils;
+import com.alibaba.nacos.sys.env.Constants;
import com.sun.management.OperatingSystemMXBean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
@@ -53,9 +54,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
-import static com.alibaba.nacos.core.utils.Constants.FUNCTION_MODE_PROPERTY_NAME;
-import static com.alibaba.nacos.core.utils.Constants.STANDALONE_MODE_PROPERTY_NAME;
-
/**
* Nacos global tool class.
*
@@ -91,6 +89,9 @@ public class ApplicationUtils implements ApplicationContextInitializer getPropertyList(String key) {
+ List valueList = new ArrayList<>();
+
+ for (int i = 0; i < Integer.MAX_VALUE; i++) {
+ String value = environment.getProperty(key + "[" + i + "]");
+ if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
+ break;
+ }
+
+ valueList.add(value);
+ }
+
+ return valueList;
+ }
+
public static String getLocalAddress() {
if (StringUtils.isBlank(localAddress)) {
localAddress = InetUtils.getSelfIp() + ":" + getPort();
@@ -378,7 +394,7 @@ public class ApplicationUtils implements ApplicationContextInitializerThe details as to how the name of the file is constructed is
- * implementation dependent and therefore not specified. Where possible
- * the {@code prefix} and {@code suffix} are used to construct candidate
- * names in the same manner as the {@link
- * java.io.File#createTempFile(String,String,File)} method.
+ * implementation dependent and therefore not specified. Where possible the {@code prefix} and {@code suffix} are
+ * used to construct candidate names in the same manner as the {@link java.io.File#createTempFile(String, String, File)}
+ * method.
*
- *
- * @param dir
- * the path to directory in which to create the file
- * @param prefix
- * the prefix string to be used in generating the file's name;
- * may be {@code null}
- * @param suffix
- * the suffix string to be used in generating the file's name;
- * may be {@code null}, in which case "{@code .tmp}" is used
- *
- * @return the path to the newly created file that did not exist before
- * this method was invoked
- *
- * @throws IllegalArgumentException
- * if the prefix or suffix parameters cannot be used to generate
- * a candidate file name
- * @throws UnsupportedOperationException
- * if the array contains an attribute that cannot be set atomically
- * when creating the directory
- * @throws IOException
- * if an I/O error occurs or {@code dir} does not exist
- * @throws SecurityException
- * In the case of the default provider, and a security manager is
- * installed, the {@link SecurityManager#checkWrite(String) checkWrite}
- * method is invoked to check write access to the file.
+ * @param dir the path to directory in which to create the file
+ * @param prefix the prefix string to be used in generating the file's name; may be {@code null}
+ * @param suffix the suffix string to be used in generating the file's name; may be {@code null}, in which case
+ * "{@code .tmp}" is used
+ * @return the path to the newly created file that did not exist before this method was invoked
+ * @throws IllegalArgumentException if the prefix or suffix parameters cannot be used to generate a candidate
+ * file name
+ * @throws UnsupportedOperationException if the array contains an attribute that cannot be set atomically when
+ * creating the directory
+ * @throws IOException if an I/O error occurs or {@code dir} does not exist
+ * @throws SecurityException In the case of the default provider, and a security manager is installed,
+ * the {@link SecurityManager#checkWrite(String) checkWrite} method is invoked
+ * to check write access to the file.
*/
public static File createTmpFile(String dir, String prefix, String suffix) throws IOException {
return Files.createTempFile(Paths.get(dir), prefix, suffix).toFile();
}
/**
- * Creates an empty file in the default temporary-file directory, using
- * the given prefix and suffix to generate its name. The resulting {@code
- * Path} is associated with the default {@code FileSystem}.
+ * Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its
+ * name. The resulting {@code Path} is associated with the default {@code FileSystem}.
*
- * @param prefix
- * the prefix string to be used in generating the file's name;
- * may be {@code null}
- * @param suffix
- * the suffix string to be used in generating the file's name;
- * may be {@code null}, in which case "{@code .tmp}" is used
- *
- * @return the path to the newly created file that did not exist before
- * this method was invoked
- *
- * @throws IllegalArgumentException
- * if the prefix or suffix parameters cannot be used to generate
- * a candidate file name
- * @throws UnsupportedOperationException
- * if the array contains an attribute that cannot be set atomically
- * when creating the directory
- * @throws IOException
- * if an I/O error occurs or the temporary-file directory does not
- * exist
- * @throws SecurityException
- * In the case of the default provider, and a security manager is
- * installed, the {@link SecurityManager#checkWrite(String) checkWrite}
- * method is invoked to check write access to the file.
+ * @param prefix the prefix string to be used in generating the file's name; may be {@code null}
+ * @param suffix the suffix string to be used in generating the file's name; may be {@code null}, in which case
+ * "{@code .tmp}" is used
+ * @return the path to the newly created file that did not exist before this method was invoked
+ * @throws IllegalArgumentException if the prefix or suffix parameters cannot be used to generate a candidate
+ * file name
+ * @throws UnsupportedOperationException if the array contains an attribute that cannot be set atomically when
+ * creating the directory
+ * @throws IOException if an I/O error occurs or the temporary-file directory does not exist
+ * @throws SecurityException In the case of the default provider, and a security manager is installed,
+ * the {@link SecurityManager#checkWrite(String) checkWrite} method is invoked
+ * to check write access to the file.
*/
public static File createTmpFile(String prefix, String suffix) throws IOException {
return Files.createTempFile(prefix, suffix).toFile();
@@ -256,7 +228,7 @@ public final class DiskUtils {
* @param append write append mode
* @return write success
*/
- public static boolean writeFile(File file, byte[] content, boolean append) throws IOException {
+ public static boolean writeFile(File file, byte[] content, boolean append) {
try (FileChannel fileChannel = new FileOutputStream(file, append).getChannel()) {
ByteBuffer buffer = ByteBuffer.wrap(content);
fileChannel.write(buffer);
@@ -266,11 +238,9 @@ public final class DiskUtils {
String errMsg = ioe.getMessage();
if (NO_SPACE_CN.equals(errMsg) || NO_SPACE_EN.equals(errMsg) || errMsg.contains(DISK_QUATA_CN) || errMsg
.contains(DISK_QUATA_EN)) {
- LOGGER.warn("Disk full, suicide exits");
+ LOGGER.warn("磁盘满,自杀退出");
System.exit(0);
}
- } else {
- throw ioe;
}
}
return false;
@@ -309,24 +279,6 @@ public final class DiskUtils {
FileUtils.forceMkdir(new File(path));
}
- /**
- * force mkdir with path and {@link BiFunction}.
- *
- * @param path path
- * @param job {@link BiFunction}
- * @return {@link Throwable}
- */
- public static Throwable forceMkdir(String path, BiFunction job) {
- Throwable ex;
- try {
- FileUtils.forceMkdir(new File(path));
- ex = job.apply(null, null);
- } catch (IOException e) {
- ex = job.apply(null, e);
- }
- return ex;
- }
-
public static void forceMkdir(File file) throws IOException {
FileUtils.forceMkdir(file);
}
@@ -401,8 +353,8 @@ public final class DiskUtils {
*/
public static void compress(final String rootDir, final String sourceDir, final String outputFile,
final Checksum checksum) throws IOException {
- try (final FileOutputStream fos = new FileOutputStream(
- outputFile); final CheckedOutputStream cos = new CheckedOutputStream(fos, checksum);
+ try (final FileOutputStream fos = new FileOutputStream(outputFile);
+ final CheckedOutputStream cos = new CheckedOutputStream(fos, checksum);
final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(cos))) {
compressDirectoryToZipFile(rootDir, sourceDir, zos);
zos.flush();
@@ -422,8 +374,8 @@ public final class DiskUtils {
compressDirectoryToZipFile(rootDir, child, zos);
} else {
zos.putNextEntry(new ZipEntry(child));
- try (final FileInputStream fis = new FileInputStream(
- file); final BufferedInputStream bis = new BufferedInputStream(fis)) {
+ try (final FileInputStream fis = new FileInputStream(file);
+ final BufferedInputStream bis = new BufferedInputStream(fis)) {
IOUtils.copy(bis, zos);
}
}
@@ -442,16 +394,16 @@ public final class DiskUtils {
*/
public static void decompress(final String sourceFile, final String outputDir, final Checksum checksum)
throws IOException {
- try (final FileInputStream fis = new FileInputStream(
- sourceFile); final CheckedInputStream cis = new CheckedInputStream(fis, checksum);
+ try (final FileInputStream fis = new FileInputStream(sourceFile);
+ final CheckedInputStream cis = new CheckedInputStream(fis, checksum);
final ZipInputStream zis = new ZipInputStream(new BufferedInputStream(cis))) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
final String fileName = entry.getName();
final File entryFile = new File(Paths.get(outputDir, fileName).toString());
FileUtils.forceMkdir(entryFile.getParentFile());
- try (final FileOutputStream fos = new FileOutputStream(
- entryFile); final BufferedOutputStream bos = new BufferedOutputStream(fos)) {
+ try (final FileOutputStream fos = new FileOutputStream(entryFile);
+ final BufferedOutputStream bos = new BufferedOutputStream(fos)) {
IOUtils.copy(zis, bos);
bos.flush();
fos.getFD().sync();
@@ -468,11 +420,10 @@ public final class DiskUtils {
/**
* Returns an Iterator for the lines in a File.
*
- * This method opens an InputStream for the file.
- * When you have finished with the iterator you should close the stream
- * to free internal resources. This can be done by calling the
- * {@link org.apache.commons.io.LineIterator#close()} or
- * {@link org.apache.commons.io.LineIterator#closeQuietly(org.apache.commons.io.LineIterator)} method.
+ * This method opens an InputStream for the file. When you have finished with the iterator you should
+ * close the stream to free internal resources. This can be done by calling the {@link
+ * org.apache.commons.io.LineIterator#close()} or {@link org.apache.commons.io.LineIterator#closeQuietly(org.apache.commons.io.LineIterator)}
+ * method.
*
* The recommended usage pattern is:
*
@@ -487,12 +438,11 @@ public final class DiskUtils {
* }
*
*
- * If an exception occurs during the creation of the iterator, the
- * underlying stream is closed.
+ * If an exception occurs during the creation of the iterator, the underlying stream is closed.
*
*
- * @param file the file to open for input, must not be null
- * @param encoding the encoding to use, null means platform default
+ * @param file the file to open for input, must not be null
+ * @param encoding the encoding to use, null means platform default
* @return an Iterator of the lines in the file, never null
* @throws IOException in case of an I/O error (file closed)
* @since 1.2
@@ -504,20 +454,20 @@ public final class DiskUtils {
/**
* Returns an Iterator for the lines in a File using the default encoding for the VM.
*
- * @param file the file to open for input, must not be null
+ * @param file the file to open for input, must not be null
* @return an Iterator of the lines in the file, never null
* @throws IOException in case of an I/O error (file closed)
- * @since 1.3
* @see #lineIterator(File, String)
+ * @since 1.3
*/
public static LineIterator lineIterator(File file) throws IOException {
return new LineIterator(FileUtils.lineIterator(file, null));
}
public static class LineIterator implements AutoCloseable {
-
+
private final org.apache.commons.io.LineIterator target;
-
+
/**
* Constructs an iterator of the lines for a Reader.
*
@@ -526,7 +476,7 @@ public final class DiskUtils {
LineIterator(org.apache.commons.io.LineIterator target) {
this.target = target;
}
-
+
public boolean hasNext() {
return target.hasNext();
}
@@ -534,20 +484,20 @@ public final class DiskUtils {
public String next() {
return target.next();
}
-
+
public String nextLine() {
return target.nextLine();
}
-
+
@Override
public void close() {
target.close();
}
-
+
public void remove() {
target.remove();
}
-
+
public void forEachRemaining(Consumer super String> action) {
target.forEachRemaining(action);
}
diff --git a/core/src/main/java/com/alibaba/nacos/core/utils/InetUtils.java b/sys/src/main/java/com/alibaba/nacos/sys/utils/InetUtils.java
similarity index 64%
rename from core/src/main/java/com/alibaba/nacos/core/utils/InetUtils.java
rename to sys/src/main/java/com/alibaba/nacos/sys/utils/InetUtils.java
index e9241e825..93f6dc36d 100644
--- a/core/src/main/java/com/alibaba/nacos/core/utils/InetUtils.java
+++ b/sys/src/main/java/com/alibaba/nacos/sys/utils/InetUtils.java
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-package com.alibaba.nacos.core.utils;
+package com.alibaba.nacos.sys.utils;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.notify.SlowEvent;
+import com.alibaba.nacos.sys.env.Constants;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,13 +35,11 @@ import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import static com.alibaba.nacos.core.utils.Constants.IGNORED_INTERFACES;
-import static com.alibaba.nacos.core.utils.Constants.IP_ADDRESS;
-import static com.alibaba.nacos.core.utils.Constants.NACOS_SERVER_IP;
-import static com.alibaba.nacos.core.utils.Constants.PREFERRED_NETWORKS;
-import static com.alibaba.nacos.core.utils.Constants.PREFER_HOSTNAME_OVER_IP;
-import static com.alibaba.nacos.core.utils.Constants.SYSTEM_PREFER_HOSTNAME_OVER_IP;
-import static com.alibaba.nacos.core.utils.Constants.USE_ONLY_SITE_INTERFACES;
+import static com.alibaba.nacos.sys.env.Constants.IP_ADDRESS;
+import static com.alibaba.nacos.sys.env.Constants.NACOS_SERVER_IP;
+import static com.alibaba.nacos.sys.env.Constants.PREFER_HOSTNAME_OVER_IP;
+import static com.alibaba.nacos.sys.env.Constants.SYSTEM_PREFER_HOSTNAME_OVER_IP;
+import static com.alibaba.nacos.sys.env.Constants.USE_ONLY_SITE_INTERFACES;
/**
* Network card operation tool class.
@@ -63,75 +62,71 @@ public class InetUtils {
private static boolean preferHostnameOverIp = false;
- private static List preferredNetworks = new ArrayList();
+ private static final List PREFERRED_NETWORKS = new ArrayList();
- private static List ignoredInterfaces = new ArrayList();
+ private static final List IGNORED_INTERFACES = new ArrayList();
static {
NotifyCenter.registerToSharePublisher(IPChangeEvent.class);
- useOnlySiteLocalInterface = Boolean.parseBoolean(PropertyUtil.getProperty(USE_ONLY_SITE_INTERFACES));
+ useOnlySiteLocalInterface = Boolean.parseBoolean(ApplicationUtils.getProperty(USE_ONLY_SITE_INTERFACES));
- List networks = PropertyUtil.getPropertyList(PREFERRED_NETWORKS);
- preferredNetworks.addAll(networks);
+ List networks = ApplicationUtils.getPropertyList(Constants.PREFERRED_NETWORKS);
+ PREFERRED_NETWORKS.addAll(networks);
- List interfaces = PropertyUtil.getPropertyList(IGNORED_INTERFACES);
- ignoredInterfaces.addAll(interfaces);
+ List interfaces = ApplicationUtils.getPropertyList(Constants.IGNORED_INTERFACES);
+ IGNORED_INTERFACES.addAll(interfaces);
final long delayMs = Long.getLong("nacos.core.inet.auto-refresh", 30_000L);
Runnable ipAutoRefresh = new Runnable() {
@Override
public void run() {
- try {
- String nacosIp = System.getProperty(NACOS_SERVER_IP);
- if (StringUtils.isBlank(nacosIp)) {
- nacosIp = PropertyUtil.getProperty(IP_ADDRESS);
- }
-
- if (!StringUtils.isBlank(nacosIp) && !isIP(nacosIp)) {
- throw new RuntimeException("nacos address " + nacosIp + " is not ip");
- }
- String tmpSelfIp = nacosIp;
- if (StringUtils.isBlank(tmpSelfIp)) {
- preferHostnameOverIp = Boolean.getBoolean(SYSTEM_PREFER_HOSTNAME_OVER_IP);
-
- if (!preferHostnameOverIp) {
- preferHostnameOverIp = Boolean
- .parseBoolean(PropertyUtil.getProperty(PREFER_HOSTNAME_OVER_IP));
- }
-
- if (preferHostnameOverIp) {
- InetAddress inetAddress;
- try {
- inetAddress = InetAddress.getLocalHost();
- if (inetAddress.getHostName().equals(inetAddress.getCanonicalHostName())) {
- tmpSelfIp = inetAddress.getHostName();
- } else {
- tmpSelfIp = inetAddress.getCanonicalHostName();
- }
- } catch (UnknownHostException ignore) {
- LOG.warn("Unable to retrieve localhost");
- }
- } else {
- tmpSelfIp = Objects.requireNonNull(findFirstNonLoopbackAddress()).getHostAddress();
- }
- }
-
- if (!Objects.equals(selfIp, tmpSelfIp) && Objects.nonNull(selfIp)) {
- IPChangeEvent event = new IPChangeEvent();
- event.setOldIp(selfIp);
- event.setNewIp(tmpSelfIp);
- NotifyCenter.publishEvent(event);
- }
- selfIp = tmpSelfIp;
- } finally {
- GlobalExecutor.scheduleByCommon(this, delayMs);
+ String nacosIp = System.getProperty(NACOS_SERVER_IP);
+ if (StringUtils.isBlank(nacosIp)) {
+ nacosIp = ApplicationUtils.getProperty(IP_ADDRESS);
}
+
+ if (!StringUtils.isBlank(nacosIp) && !isIP(nacosIp)) {
+ throw new RuntimeException("nacos address " + nacosIp + " is not ip");
+ }
+ String tmpSelfIp = nacosIp;
+ if (StringUtils.isBlank(tmpSelfIp)) {
+ preferHostnameOverIp = Boolean.getBoolean(SYSTEM_PREFER_HOSTNAME_OVER_IP);
+
+ if (!preferHostnameOverIp) {
+ preferHostnameOverIp = Boolean
+ .parseBoolean(ApplicationUtils.getProperty(PREFER_HOSTNAME_OVER_IP));
+ }
+
+ if (preferHostnameOverIp) {
+ InetAddress inetAddress;
+ try {
+ inetAddress = InetAddress.getLocalHost();
+ if (inetAddress.getHostName().equals(inetAddress.getCanonicalHostName())) {
+ tmpSelfIp = inetAddress.getHostName();
+ } else {
+ tmpSelfIp = inetAddress.getCanonicalHostName();
+ }
+ } catch (UnknownHostException ignore) {
+ LOG.warn("Unable to retrieve localhost");
+ }
+ } else {
+ tmpSelfIp = Objects.requireNonNull(findFirstNonLoopbackAddress()).getHostAddress();
+ }
+ }
+
+ if (!Objects.equals(selfIp, tmpSelfIp) && Objects.nonNull(selfIp)) {
+ IPChangeEvent event = new IPChangeEvent();
+ event.setOldIp(selfIp);
+ event.setNewIp(tmpSelfIp);
+ NotifyCenter.publishEvent(event);
+ }
+ selfIp = tmpSelfIp;
}
};
- GlobalExecutor.runWithoutThread(ipAutoRefresh);
+ ipAutoRefresh.run();
}
public static String getSelfIp() {
@@ -196,10 +191,10 @@ public class InetUtils {
}
return siteLocalAddress;
}
- if (preferredNetworks.isEmpty()) {
+ if (PREFERRED_NETWORKS.isEmpty()) {
return true;
}
- for (String regex : preferredNetworks) {
+ for (String regex : PREFERRED_NETWORKS) {
final String hostAddress = address.getHostAddress();
if (hostAddress.matches(regex) || hostAddress.startsWith(regex)) {
return true;
@@ -210,7 +205,7 @@ public class InetUtils {
}
private static boolean ignoreInterface(String interfaceName) {
- for (String regex : ignoredInterfaces) {
+ for (String regex : IGNORED_INTERFACES) {
if (interfaceName.matches(regex)) {
LOG.debug("Ignoring interface: " + interfaceName);
return true;
diff --git a/core/src/main/resources/META-INF/nacos-default.properties b/sys/src/main/resources/META-INF/nacos-default.properties
similarity index 85%
rename from core/src/main/resources/META-INF/nacos-default.properties
rename to sys/src/main/resources/META-INF/nacos-default.properties
index 0eda3de14..6e081a98e 100644
--- a/core/src/main/resources/META-INF/nacos-default.properties
+++ b/sys/src/main/resources/META-INF/nacos-default.properties
@@ -32,5 +32,5 @@ spring.messages.encoding=UTF-8
## Exclude Spring Boot Auto-Configuration class(es)
spring.autoconfigure.exclude=\
-org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
-org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
+ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
+ org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
\ No newline at end of file
diff --git a/sys/src/main/resources/META-INF/spring.factories b/sys/src/main/resources/META-INF/spring.factories
new file mode 100644
index 000000000..71a4ccbfc
--- /dev/null
+++ b/sys/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,9 @@
+# PropertySource Loaders
+org.springframework.boot.env.PropertySourceLoader=\
+ com.alibaba.nacos.sys.env.NacosAutoRefreshPropertySourceLoader
+# EnvironmentPostProcessor
+org.springframework.boot.env.EnvironmentPostProcessor=\
+com.alibaba.nacos.sys.env.NacosDefaultPropertySourceEnvironmentPostProcessor
+# ApplicationContextInitializer
+org.springframework.context.ApplicationContextInitializer=\
+ com.alibaba.nacos.sys.utils.ApplicationUtils
\ No newline at end of file
diff --git a/sys/src/test/java/com/alibaba/nacos/sys/env/NacosAutoRefreshPropertySourceLoaderTest.java b/sys/src/test/java/com/alibaba/nacos/sys/env/NacosAutoRefreshPropertySourceLoaderTest.java
new file mode 100644
index 000000000..8d3720f9b
--- /dev/null
+++ b/sys/src/test/java/com/alibaba/nacos/sys/env/NacosAutoRefreshPropertySourceLoaderTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.sys.env;
+
+import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.common.utils.ByteUtils;
+import com.alibaba.nacos.common.utils.ThreadUtils;
+import com.alibaba.nacos.sys.file.FileChangeEvent;
+import com.alibaba.nacos.sys.file.FileWatcher;
+import com.alibaba.nacos.sys.file.WatchFileCenter;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.DiskUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.concurrent.CountDownLatch;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = NacosAutoRefreshPropertySourceLoaderTest.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
+public class NacosAutoRefreshPropertySourceLoaderTest {
+
+ @Autowired
+ private ConfigurableEnvironment environment;
+
+ private static String oldConfPath = "";
+
+ @BeforeClass
+ public static void before() throws URISyntaxException {
+ oldConfPath = ApplicationUtils.getConfFilePath();
+ ApplicationUtils.setConfFilePath(new File(ClassLoader.getSystemResource("application.properties").toURI()).getParent());
+ }
+
+ @AfterClass
+ public static void after() {
+ ApplicationUtils.setConfFilePath(oldConfPath);
+ }
+
+ @Test
+ public void testConfigFileAutoRefresh() throws URISyntaxException, InterruptedException, NacosException, IOException {
+ final URL url = ClassLoader.getSystemResource("application.properties");
+ ApplicationUtils.setContextPath(url.getPath());
+ final String val1 = environment.getProperty("name");
+ Assert.assertEquals("test-1", val1);
+ final File file = new File(url.toURI());
+ final String newKey = "nacos.config.refresh-" + System.currentTimeMillis();
+ final String newVal = System.currentTimeMillis() + "-lessspring";
+ DiskUtils.writeFile(file, ByteUtils.toBytes("\n" + newKey + "=" + newVal), true);
+ CountDownLatch latch = new CountDownLatch(1);
+ WatchFileCenter.registerWatcher(ApplicationUtils.getConfFilePath(), new FileWatcher() {
+ @Override
+ public void onChange(FileChangeEvent event) {
+ latch.countDown();
+ }
+
+ @Override
+ public boolean interest(String context) {
+ return StringUtils.contains(context, "application.properties");
+ }
+ });
+ latch.await();
+ ThreadUtils.sleep(10_000);
+ final String val2 = environment.getProperty(newKey);
+ Assert.assertEquals(newVal, val2);
+ }
+
+}
\ No newline at end of file
diff --git a/core/src/test/java/com/alibaba/nacos/core/env/NacosDefaultPropertySourceEnvironmentPostProcessorTest.java b/sys/src/test/java/com/alibaba/nacos/sys/env/NacosDefaultPropertySourceEnvironmentPostProcessorTest.java
similarity index 93%
rename from core/src/test/java/com/alibaba/nacos/core/env/NacosDefaultPropertySourceEnvironmentPostProcessorTest.java
rename to sys/src/test/java/com/alibaba/nacos/sys/env/NacosDefaultPropertySourceEnvironmentPostProcessorTest.java
index ef9846240..2223cf864 100644
--- a/core/src/test/java/com/alibaba/nacos/core/env/NacosDefaultPropertySourceEnvironmentPostProcessorTest.java
+++ b/sys/src/test/java/com/alibaba/nacos/sys/env/NacosDefaultPropertySourceEnvironmentPostProcessorTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.alibaba.nacos.core.env;
+package com.alibaba.nacos.sys.env;
import org.junit.Assert;
import org.junit.Test;
@@ -29,8 +29,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashSet;
-import static com.alibaba.nacos.core.env.NacosDefaultPropertySourceEnvironmentPostProcessor.PROPERTY_SOURCE_NAME;
-import static com.alibaba.nacos.core.env.NacosDefaultPropertySourceEnvironmentPostProcessor.RESOURCE_LOCATION_PATTERN;
+import static com.alibaba.nacos.sys.env.NacosDefaultPropertySourceEnvironmentPostProcessor.PROPERTY_SOURCE_NAME;
+import static com.alibaba.nacos.sys.env.NacosDefaultPropertySourceEnvironmentPostProcessor.RESOURCE_LOCATION_PATTERN;
import static java.util.Arrays.asList;
/**
diff --git a/sys/src/test/resources/application.properties b/sys/src/test/resources/application.properties
new file mode 100644
index 000000000..aaba4fabc
--- /dev/null
+++ b/sys/src/test/resources/application.properties
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+
+name=test-1
\ No newline at end of file
diff --git a/test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenter_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenter_ITCase.java
index 044e0e8ee..909fbe64e 100644
--- a/test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenter_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenter_ITCase.java
@@ -16,12 +16,12 @@
package com.alibaba.nacos.test.common;
-import com.alibaba.nacos.core.file.FileChangeEvent;
-import com.alibaba.nacos.core.file.FileWatcher;
-import com.alibaba.nacos.core.file.WatchFileCenter;
+import com.alibaba.nacos.sys.file.FileChangeEvent;
+import com.alibaba.nacos.sys.file.FileWatcher;
+import com.alibaba.nacos.sys.file.WatchFileCenter;
import com.alibaba.nacos.common.utils.ByteUtils;
import com.alibaba.nacos.common.utils.ConcurrentHashSet;
-import com.alibaba.nacos.core.utils.DiskUtils;
+import com.alibaba.nacos.sys.utils.DiskUtils;
import com.alibaba.nacos.common.utils.ThreadUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.AfterClass;
@@ -30,7 +30,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
-import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Set;
@@ -46,143 +45,138 @@ import java.util.function.Consumer;
* @author liaochuntao
*/
public class WatchFileCenter_ITCase {
-
- static final String path = Paths
- .get(System.getProperty("user.home"), "/watch_file_change_test").toString();
-
- final Object monitor = new Object();
-
- static final Executor executor = Executors.newFixedThreadPool(32);
-
- @BeforeClass
- public static void beforeCls() throws Exception {
- DiskUtils.deleteDirThenMkdir(path);
- }
-
- @AfterClass
- public static void afterCls() throws Exception {
- DiskUtils.deleteDirectory(path);
- }
-
- // The last file change must be notified
-
- @Test
- public void test_high_concurrency_modify() throws Exception {
- AtomicInteger count = new AtomicInteger(0);
- Set set = new ConcurrentHashSet<>();
-
- final String fileName = "test2_file_change";
- final File file = Paths.get(path, fileName).toFile();
-
- func(fileName, file, content -> {
- set.add(content);
- count.incrementAndGet();
- });
-
- ThreadUtils.sleep(5_000L);
- }
-
- @Test
- public void test_modify_file_much() throws Exception {
- final String fileName = "modify_file_much";
- final File file = Paths.get(path, fileName).toFile();
-
- CountDownLatch latch = new CountDownLatch(3);
- AtomicInteger count = new AtomicInteger(0);
-
- WatchFileCenter.registerWatcher(path, new FileWatcher() {
- @Override
- public void onChange(FileChangeEvent event) {
- try {
- System.out.println(event);
- System.out.println(DiskUtils.readFile(file));
- count.incrementAndGet();
- } finally {
- latch.countDown();
- }
- }
-
- @Override
- public boolean interest(String context) {
- return StringUtils.contains(context, fileName);
- }
- });
-
- for (int i = 0; i < 3; i ++) {
- DiskUtils.writeFile(file, ByteUtils.toBytes(("test_modify_file_" + i)), false);
- ThreadUtils.sleep(10_000L);
- }
-
- latch.await(10_000L, TimeUnit.MILLISECONDS);
-
- Assert.assertEquals(3, count.get());
- }
-
- @Test
- public void test_multi_file_modify() throws Exception {
- CountDownLatch latch = new CountDownLatch(10);
- for (int i = 0; i < 10; i++) {
- AtomicInteger count = new AtomicInteger(0);
- Set set = new ConcurrentHashSet<>();
-
- final String fileName = "test2_file_change_" + i;
- final File file = Paths.get(path, fileName).toFile();
-
- executor.execute(() -> {
- try {
- func(fileName, file, content -> {
- set.add(content);
- count.incrementAndGet();
- });
- } catch (Throwable ex) {
- ex.printStackTrace();
- } finally {
- latch.countDown();
- }
- });
- }
- latch.await(10_000L, TimeUnit.MILLISECONDS);
-
- ThreadUtils.sleep(5_000L);
- }
-
- private void func(final String fileName, final File file,
- final Consumer consumer) throws Exception {
- CountDownLatch latch = new CountDownLatch(100);
- DiskUtils.touch(file);
- WatchFileCenter.registerWatcher(path, new FileWatcher() {
- @Override
- public void onChange(FileChangeEvent event) {
- final File file = Paths.get(path, fileName).toFile();
- final String content = DiskUtils.readFile(file);
- consumer.accept(content);
- }
-
- @Override
- public boolean interest(String context) {
- return StringUtils.contains(context, fileName);
- }
- });
-
- final AtomicInteger id = new AtomicInteger(0);
- final AtomicReference finalContent = new AtomicReference<>(null);
- for (int i = 0; i < 100; i++) {
- executor.execute(() -> {
- final String j = fileName + "_" + id.incrementAndGet();
- try {
- final File file1 = Paths.get(path, fileName).toFile();
- synchronized (monitor) {
- finalContent.set(j);
- DiskUtils.writeFile(file1, j.getBytes(StandardCharsets.UTF_8),
- false);
- }
- } catch (IOException e) {
- Assert.fail(e.getMessage());
- } finally {
- latch.countDown();
- }
- });
- }
- }
-
+
+ static final String path = Paths.get(System.getProperty("user.home"), "/watch_file_change_test").toString();
+
+ final Object monitor = new Object();
+
+ static final Executor executor = Executors.newFixedThreadPool(32);
+
+ @BeforeClass
+ public static void beforeCls() throws Exception {
+ DiskUtils.deleteDirThenMkdir(path);
+ }
+
+ @AfterClass
+ public static void afterCls() throws Exception {
+ DiskUtils.deleteDirectory(path);
+ }
+
+ // The last file change must be notified
+
+ @Test
+ public void test_high_concurrency_modify() throws Exception {
+ AtomicInteger count = new AtomicInteger(0);
+ Set set = new ConcurrentHashSet<>();
+
+ final String fileName = "test2_file_change";
+ final File file = Paths.get(path, fileName).toFile();
+
+ func(fileName, file, content -> {
+ set.add(content);
+ count.incrementAndGet();
+ });
+
+ ThreadUtils.sleep(5_000L);
+ }
+
+ @Test
+ public void test_modify_file_much() throws Exception {
+ final String fileName = "modify_file_much";
+ final File file = Paths.get(path, fileName).toFile();
+
+ CountDownLatch latch = new CountDownLatch(3);
+ AtomicInteger count = new AtomicInteger(0);
+
+ WatchFileCenter.registerWatcher(path, new FileWatcher() {
+ @Override
+ public void onChange(FileChangeEvent event) {
+ try {
+ System.out.println(event);
+ System.out.println(DiskUtils.readFile(file));
+ count.incrementAndGet();
+ } finally {
+ latch.countDown();
+ }
+ }
+
+ @Override
+ public boolean interest(String context) {
+ return StringUtils.contains(context, fileName);
+ }
+ });
+
+ for (int i = 0; i < 3; i++) {
+ DiskUtils.writeFile(file, ByteUtils.toBytes(("test_modify_file_" + i)), false);
+ ThreadUtils.sleep(10_000L);
+ }
+
+ latch.await(10_000L, TimeUnit.MILLISECONDS);
+
+ Assert.assertEquals(3, count.get());
+ }
+
+ @Test
+ public void test_multi_file_modify() throws Exception {
+ CountDownLatch latch = new CountDownLatch(10);
+ for (int i = 0; i < 10; i++) {
+ AtomicInteger count = new AtomicInteger(0);
+ Set set = new ConcurrentHashSet<>();
+
+ final String fileName = "test2_file_change_" + i;
+ final File file = Paths.get(path, fileName).toFile();
+
+ executor.execute(() -> {
+ try {
+ func(fileName, file, content -> {
+ set.add(content);
+ count.incrementAndGet();
+ });
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ } finally {
+ latch.countDown();
+ }
+ });
+ }
+ latch.await(10_000L, TimeUnit.MILLISECONDS);
+
+ ThreadUtils.sleep(5_000L);
+ }
+
+ private void func(final String fileName, final File file, final Consumer consumer) throws Exception {
+ CountDownLatch latch = new CountDownLatch(100);
+ DiskUtils.touch(file);
+ WatchFileCenter.registerWatcher(path, new FileWatcher() {
+ @Override
+ public void onChange(FileChangeEvent event) {
+ final File file = Paths.get(path, fileName).toFile();
+ final String content = DiskUtils.readFile(file);
+ consumer.accept(content);
+ }
+
+ @Override
+ public boolean interest(String context) {
+ return StringUtils.contains(context, fileName);
+ }
+ });
+
+ final AtomicInteger id = new AtomicInteger(0);
+ final AtomicReference finalContent = new AtomicReference<>(null);
+ for (int i = 0; i < 100; i++) {
+ executor.execute(() -> {
+ final String j = fileName + "_" + id.incrementAndGet();
+ try {
+ final File file1 = Paths.get(path, fileName).toFile();
+ synchronized (monitor) {
+ finalContent.set(j);
+ DiskUtils.writeFile(file1, j.getBytes(StandardCharsets.UTF_8), false);
+ }
+ } finally {
+ latch.countDown();
+ }
+ });
+ }
+ }
+
}
diff --git a/test/src/test/java/com/alibaba/nacos/test/config/ConfigCleanUtils.java b/test/src/test/java/com/alibaba/nacos/test/config/ConfigCleanUtils.java
index ffc652a4e..5bb1081a2 100644
--- a/test/src/test/java/com/alibaba/nacos/test/config/ConfigCleanUtils.java
+++ b/test/src/test/java/com/alibaba/nacos/test/config/ConfigCleanUtils.java
@@ -17,7 +17,7 @@
package com.alibaba.nacos.test.config;
import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor;
-import com.alibaba.nacos.core.utils.DiskUtils;
+import com.alibaba.nacos.sys.utils.DiskUtils;
import java.io.IOException;
diff --git a/test/src/test/java/com/alibaba/nacos/test/config/ConfigDerbyImport_CITCase.java b/test/src/test/java/com/alibaba/nacos/test/config/ConfigDerbyImport_CITCase.java
index 0f14a13dc..b3c3a98c1 100644
--- a/test/src/test/java/com/alibaba/nacos/test/config/ConfigDerbyImport_CITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/config/ConfigDerbyImport_CITCase.java
@@ -23,11 +23,8 @@ import com.alibaba.nacos.common.utils.ByteUtils;
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.service.repository.PersistService;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
-import com.alibaba.nacos.core.utils.DiskUtils;
-import org.junit.AfterClass;
+import com.alibaba.nacos.sys.utils.DiskUtils;
import org.junit.Assert;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,7 +33,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.File;
-import java.nio.file.Paths;
import java.util.concurrent.CompletableFuture;
/**
diff --git a/test/src/test/java/com/alibaba/nacos/test/config/ConfigDerbyRaft_DITCase.java b/test/src/test/java/com/alibaba/nacos/test/config/ConfigDerbyRaft_DITCase.java
index 322494a4a..6afce7ee6 100644
--- a/test/src/test/java/com/alibaba/nacos/test/config/ConfigDerbyRaft_DITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/config/ConfigDerbyRaft_DITCase.java
@@ -32,7 +32,7 @@ import com.alibaba.nacos.consistency.cp.CPProtocol;
import com.alibaba.nacos.core.distributed.id.IdGeneratorManager;
import com.alibaba.nacos.core.distributed.raft.utils.JRaftConstants;
import com.alibaba.nacos.core.utils.GenericType;
-import com.alibaba.nacos.core.utils.InetUtils;
+import com.alibaba.nacos.sys.utils.InetUtils;
import com.alibaba.nacos.test.core.BaseClusterTest;
import org.junit.Assert;
diff --git a/test/src/test/java/com/alibaba/nacos/test/core/BaseClusterTest.java b/test/src/test/java/com/alibaba/nacos/test/core/BaseClusterTest.java
index c1f79663c..cf1c2fead 100644
--- a/test/src/test/java/com/alibaba/nacos/test/core/BaseClusterTest.java
+++ b/test/src/test/java/com/alibaba/nacos/test/core/BaseClusterTest.java
@@ -21,18 +21,17 @@ import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.common.http.HttpClientBeanHolder;
-import com.alibaba.nacos.common.http.NSyncHttpClient;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.notify.listener.Subscriber;
-import com.alibaba.nacos.core.utils.DiskUtils;
import com.alibaba.nacos.config.server.model.event.RaftDbErrorEvent;
import com.alibaba.nacos.config.server.service.repository.embedded.DistributedDatabaseOperateImpl;
import com.alibaba.nacos.consistency.cp.CPProtocol;
import com.alibaba.nacos.consistency.cp.MetadataKey;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
-import com.alibaba.nacos.core.utils.InetUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.DiskUtils;
+import com.alibaba.nacos.sys.utils.InetUtils;
import com.alibaba.nacos.test.base.HttpClient4Test;
import org.junit.AfterClass;
diff --git a/test/src/test/java/com/alibaba/nacos/test/core/InetUtils_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/core/InetUtils_ITCase.java
index 1b219072b..1e912809e 100644
--- a/test/src/test/java/com/alibaba/nacos/test/core/InetUtils_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/core/InetUtils_ITCase.java
@@ -19,7 +19,7 @@ package com.alibaba.nacos.test.core;
import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.notify.listener.Subscriber;
-import com.alibaba.nacos.core.utils.InetUtils;
+import com.alibaba.nacos.sys.utils.InetUtils;
import org.junit.Assert;
import org.junit.Test;
@@ -28,7 +28,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import static com.alibaba.nacos.core.utils.Constants.NACOS_SERVER_IP;
+import static com.alibaba.nacos.sys.env.Constants.NACOS_SERVER_IP;
+
/**
* @author liaochuntao
diff --git a/test/src/test/java/com/alibaba/nacos/test/core/SnowFlowerIdGenerator_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/core/SnowFlowerIdGenerator_ITCase.java
index 002695ecd..573b7c61c 100644
--- a/test/src/test/java/com/alibaba/nacos/test/core/SnowFlowerIdGenerator_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/core/SnowFlowerIdGenerator_ITCase.java
@@ -17,7 +17,7 @@
package com.alibaba.nacos.test.core;
import com.alibaba.nacos.core.distributed.id.SnowFlowerIdGenerator;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.core.env.StandardEnvironment;
diff --git a/test/src/test/java/com/alibaba/nacos/test/core/auth/NamingAuth_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/core/auth/NamingAuth_ITCase.java
index 8c959fbfa..707feea32 100644
--- a/test/src/test/java/com/alibaba/nacos/test/core/auth/NamingAuth_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/core/auth/NamingAuth_ITCase.java
@@ -21,7 +21,7 @@ import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.apache.http.HttpStatus;
import org.junit.After;
import org.junit.Assert;
diff --git a/test/src/test/java/com/alibaba/nacos/test/core/cluster/MemberLookup_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/core/cluster/MemberLookup_ITCase.java
index 485bd42fa..033343c99 100644
--- a/test/src/test/java/com/alibaba/nacos/test/core/cluster/MemberLookup_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/core/cluster/MemberLookup_ITCase.java
@@ -17,7 +17,6 @@
package com.alibaba.nacos.test.core.cluster;
import com.alibaba.nacos.api.exception.NacosException;
-import com.alibaba.nacos.core.utils.DiskUtils;
import com.alibaba.nacos.core.cluster.Member;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
import com.alibaba.nacos.core.cluster.lookup.AddressServerMemberLookup;
@@ -25,8 +24,9 @@ import com.alibaba.nacos.core.cluster.lookup.FileConfigMemberLookup;
import com.alibaba.nacos.core.cluster.lookup.LookupFactory;
import com.alibaba.nacos.core.cluster.MemberLookup;
import com.alibaba.nacos.core.cluster.lookup.StandaloneMemberLookup;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
-import com.alibaba.nacos.core.utils.InetUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.DiskUtils;
+import com.alibaba.nacos.sys.utils.InetUtils;
import com.alibaba.nacos.test.BaseTest;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
diff --git a/test/src/test/java/com/alibaba/nacos/test/core/cluster/ServerMemberManager_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/core/cluster/ServerMemberManager_ITCase.java
index 9579c742e..295571569 100644
--- a/test/src/test/java/com/alibaba/nacos/test/core/cluster/ServerMemberManager_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/core/cluster/ServerMemberManager_ITCase.java
@@ -24,8 +24,8 @@ import com.alibaba.nacos.core.cluster.MembersChangeEvent;
import com.alibaba.nacos.core.cluster.MemberUtils;
import com.alibaba.nacos.core.cluster.NodeState;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
-import com.alibaba.nacos.core.utils.Constants;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.env.Constants;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java
index 689822651..5053ee2c5 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java
@@ -22,7 +22,7 @@ import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.client.naming.NacosNamingService;
import com.alibaba.nacos.client.naming.beat.BeatInfo;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/ClientBeat_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/ClientBeat_ITCase.java
index 06e8adea3..6e5cefe02 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/ClientBeat_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/ClientBeat_ITCase.java
@@ -21,7 +21,7 @@ import com.alibaba.nacos.Nacos;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import com.alibaba.nacos.test.base.Params;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/DeregisterInstance_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/DeregisterInstance_ITCase.java
index cb873b2c8..179c007cc 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/DeregisterInstance_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/DeregisterInstance_ITCase.java
@@ -19,7 +19,7 @@ import com.alibaba.nacos.Nacos;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java
index 418e11b9a..1d4178bf8 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java
@@ -26,7 +26,7 @@ import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.listener.NamingEvent;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java
index 0ab4df760..047d40c23 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java
@@ -27,7 +27,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.Service;
import com.alibaba.nacos.api.selector.ExpressionSelector;
import com.alibaba.nacos.api.selector.NoneSelector;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import com.alibaba.nacos.test.BaseTest;
import org.junit.Assert;
import org.junit.Before;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java
index 0df3dbbc7..0227f3a60 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java
@@ -22,7 +22,7 @@ import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/SelectInstances_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/SelectInstances_ITCase.java
index a55c8afdb..4b78ef75f 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/SelectInstances_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/SelectInstances_ITCase.java
@@ -22,7 +22,7 @@ import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.api.selector.ExpressionSelector;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/SelectOneHealthyInstance_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/SelectOneHealthyInstance_ITCase.java
index f9331e46e..16104ebf0 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/SelectOneHealthyInstance_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/SelectOneHealthyInstance_ITCase.java
@@ -19,7 +19,7 @@ import com.alibaba.nacos.Nacos;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/ServiceListTest_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/ServiceListTest_ITCase.java
index 31963a4e7..4a58b3fed 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/ServiceListTest_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/ServiceListTest_ITCase.java
@@ -25,7 +25,7 @@ import com.alibaba.nacos.api.naming.listener.NamingEvent;
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.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/SubscribeCluster_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/SubscribeCluster_ITCase.java
index ff1a42f39..86c13f809 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/SubscribeCluster_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/SubscribeCluster_ITCase.java
@@ -22,7 +22,7 @@ import com.alibaba.nacos.api.naming.listener.Event;
import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.listener.NamingEvent;
import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/Unsubscribe_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/Unsubscribe_ITCase.java
index 11454bb2a..a04c200d7 100644
--- a/test/src/test/java/com/alibaba/nacos/test/naming/Unsubscribe_ITCase.java
+++ b/test/src/test/java/com/alibaba/nacos/test/naming/Unsubscribe_ITCase.java
@@ -22,7 +22,7 @@ import com.alibaba.nacos.api.naming.listener.Event;
import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.listener.NamingEvent;
import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.alibaba.nacos.core.utils.ApplicationUtils;
+import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;