Merge pull request #247 from hxy1991/master
[ISSUE #222] [ISSUE #231] [ISSUE #246]
This commit is contained in:
commit
30919083e8
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -18,5 +18,5 @@ Follow this checklist to help us incorporate your contribution quickly and easil
|
|||||||
* [ ] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body.
|
* [ ] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body.
|
||||||
* [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
|
* [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
|
||||||
* [ ] Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in [test module](https://github.com/alibaba/nacos/tree/master/test).
|
* [ ] Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in [test module](https://github.com/alibaba/nacos/tree/master/test).
|
||||||
* [ ] Run `mvn -B clean apache-rat:check findbugs:findbugs` to make sure basic checks pass. Run `mvn clean install -DskipITs` to make sure unit-test pass. Run `mvn clean test-compile failsafe:integration-test` to make sure integration-test pass.
|
* [ ] Run `mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true` to make sure basic checks pass. Run `mvn clean install -DskipITs` to make sure unit-test pass. Run `mvn clean test-compile failsafe:integration-test` to make sure integration-test pass.
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ before_install:
|
|||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then jdk_switcher use "$CUSTOM_JDK"; fi
|
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then jdk_switcher use "$CUSTOM_JDK"; fi
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- mvn -B clean apache-rat:check findbugs:findbugs
|
- mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
|
||||||
- mvn -Prelease-nacos clean install -U
|
- mvn -Prelease-nacos clean install -U
|
||||||
- mvn clean package -Pit-test
|
- mvn clean package -Pit-test
|
||||||
after_success:
|
after_success:
|
||||||
|
@ -18,17 +18,30 @@ package com.alibaba.nacos.common.util;
|
|||||||
|
|
||||||
import com.sun.management.OperatingSystemMXBean;
|
import com.sun.management.OperatingSystemMXBean;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.CharEncoding.UTF_8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nacos
|
* @author nacos
|
||||||
*/
|
*/
|
||||||
public class SystemUtils {
|
public class SystemUtils {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SystemUtils.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The System property name of Standalone mode
|
* The System property name of Standalone mode
|
||||||
*/
|
*/
|
||||||
@ -51,6 +64,25 @@ public class SystemUtils {
|
|||||||
|
|
||||||
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
||||||
|
|
||||||
|
public static final String LOCAL_IP = getHostAddress();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The key of nacos home.
|
||||||
|
*/
|
||||||
|
public static final String NACOS_HOME_KEY = "nacos.home";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The home of nacos.
|
||||||
|
*/
|
||||||
|
public static final String NACOS_HOME = getNacosHome();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The file path of cluster conf.
|
||||||
|
*/
|
||||||
|
public static final String CLUSTER_CONF_FILE_PATH = getClusterConfFilePath();
|
||||||
|
|
||||||
|
|
||||||
public static List<String> getIPsBySystemEnv(String key) {
|
public static List<String> getIPsBySystemEnv(String key) {
|
||||||
String env = getSystemEnv(key);
|
String env = getSystemEnv(key);
|
||||||
List<String> ips = new ArrayList<String>();
|
List<String> ips = new ArrayList<String>();
|
||||||
@ -61,8 +93,7 @@ public class SystemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getSystemEnv(String key) {
|
public static String getSystemEnv(String key) {
|
||||||
String env = System.getenv(key);
|
return System.getenv(key);
|
||||||
return env;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getLoad() {
|
public static float getLoad() {
|
||||||
@ -76,4 +107,58 @@ public class SystemUtils {
|
|||||||
public static float getMem() {
|
public static float getMem() {
|
||||||
return (float) (1 - (double) operatingSystemMXBean.getFreePhysicalMemorySize() / (double) operatingSystemMXBean.getTotalPhysicalMemorySize());
|
return (float) (1 - (double) operatingSystemMXBean.getFreePhysicalMemorySize() / (double) operatingSystemMXBean.getTotalPhysicalMemorySize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getHostAddress() {
|
||||||
|
String address = System.getProperty("nacos.server.ip");
|
||||||
|
if (StringUtils.isNotEmpty(address)) {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
address = "127.0.0.1";
|
||||||
|
|
||||||
|
try {
|
||||||
|
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||||
|
while (networkInterfaces.hasMoreElements()) {
|
||||||
|
NetworkInterface networkInterface = networkInterfaces.nextElement();
|
||||||
|
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
|
||||||
|
while (inetAddresses.hasMoreElements()) {
|
||||||
|
InetAddress ip = inetAddresses.nextElement();
|
||||||
|
// 兼容不规范网段
|
||||||
|
if (!ip.isLoopbackAddress() && !ip.getHostAddress().contains(":")) {
|
||||||
|
return ip.getHostAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("get local host address error", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getNacosHome() {
|
||||||
|
String nacosHome = System.getProperty(NACOS_HOME_KEY);
|
||||||
|
if (StringUtils.isBlank(nacosHome)) {
|
||||||
|
nacosHome = System.getProperty("user.home") + File.separator + "nacos";
|
||||||
|
}
|
||||||
|
return nacosHome;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getClusterConfFilePath() {
|
||||||
|
return NACOS_HOME + File.separator + "conf" + File.separator + "cluster.conf";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> readClusterConf() throws IOException {
|
||||||
|
try {
|
||||||
|
return IoUtils.readLines(
|
||||||
|
new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)), UTF_8));
|
||||||
|
} catch (IOException e){
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeClusterConf(String content) throws IOException {
|
||||||
|
IoUtils.writeStringToFile(new File(CLUSTER_CONF_FILE_PATH), content, UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,8 @@ import java.sql.Timestamp;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 软负载客户端发布数据专用控制器
|
* 软负载客户端发布数据专用控制器
|
||||||
*
|
*
|
||||||
@ -138,7 +140,7 @@ public class ConfigController {
|
|||||||
EventDispatcher.fireEvent(new ConfigDataChangeEvent(true, dataId, group, tenant, time.getTime()));
|
EventDispatcher.fireEvent(new ConfigDataChangeEvent(true, dataId, group, tenant, time.getTime()));
|
||||||
}
|
}
|
||||||
ConfigTraceService.logPersistenceEvent(dataId, group, tenant, requestIpApp, time.getTime(),
|
ConfigTraceService.logPersistenceEvent(dataId, group, tenant, requestIpApp, time.getTime(),
|
||||||
SystemConfig.LOCAL_IP, ConfigTraceService.PERSISTENCE_EVENT_PUB, content);
|
LOCAL_IP, ConfigTraceService.PERSISTENCE_EVENT_PUB, content);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import com.alibaba.nacos.config.server.constant.Constants;
|
|||||||
import com.alibaba.nacos.config.server.service.DataSourceService;
|
import com.alibaba.nacos.config.server.service.DataSourceService;
|
||||||
import com.alibaba.nacos.config.server.service.DynamicDataSource;
|
import com.alibaba.nacos.config.server.service.DynamicDataSource;
|
||||||
import com.alibaba.nacos.config.server.service.ServerListService;
|
import com.alibaba.nacos.config.server.service.ServerListService;
|
||||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -28,6 +27,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* health service
|
* health service
|
||||||
*
|
*
|
||||||
@ -72,7 +73,7 @@ public class HealthController {
|
|||||||
sb.append("地址服务器 down. ");
|
sb.append("地址服务器 down. ");
|
||||||
}
|
}
|
||||||
if (!ServerListService.isInIpList()) {
|
if (!ServerListService.isInIpList()) {
|
||||||
sb.append("server ").append(SystemConfig.LOCAL_IP).append(" 不在地址服务器的IP列表中. ");
|
sb.append("server ").append(LOCAL_IP).append(" 不在地址服务器的IP列表中. ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.nacos.config.server.model.app;
|
package com.alibaba.nacos.config.server.model.app;
|
||||||
|
|
||||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* app info
|
* app info
|
||||||
@ -92,8 +92,8 @@ public class ApplicationInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canCurrentServerOwnTheLock() {
|
public boolean canCurrentServerOwnTheLock() {
|
||||||
boolean currentOwnerIsMe = subInfoCollectLockOwner==null? true:SystemConfig.LOCAL_IP
|
boolean currentOwnerIsMe = subInfoCollectLockOwner == null || LOCAL_IP
|
||||||
.equals(subInfoCollectLockOwner);
|
.equals(subInfoCollectLockOwner);
|
||||||
|
|
||||||
if (currentOwnerIsMe) {
|
if (currentOwnerIsMe) {
|
||||||
return true;
|
return true;
|
||||||
@ -106,7 +106,7 @@ public class ApplicationInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String currentServer(){
|
public String currentServer(){
|
||||||
return SystemConfig.LOCAL_IP;
|
return LOCAL_IP;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.NACOS_HOME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 磁盘操作工具类。
|
* 磁盘操作工具类。
|
||||||
@ -40,22 +41,12 @@ import java.io.IOException;
|
|||||||
public class DiskUtil {
|
public class DiskUtil {
|
||||||
|
|
||||||
static final Logger logger = LoggerFactory.getLogger(DiskUtil.class);
|
static final Logger logger = LoggerFactory.getLogger(DiskUtil.class);
|
||||||
static String APP_HOME = System.getProperty("user.home") + File.separator + "nacos";
|
|
||||||
static final String BASE_DIR = File.separator + "data" + File.separator + "config-data";
|
static final String BASE_DIR = File.separator + "data" + File.separator + "config-data";
|
||||||
static final String TENANT_BASE_DIR = File.separator + "data" + File.separator + "tenant-config-data";
|
static final String TENANT_BASE_DIR = File.separator + "data" + File.separator + "tenant-config-data";
|
||||||
static final String BETA_DIR = File.separator + "data" + File.separator + "beta-data";
|
static final String BETA_DIR = File.separator + "data" + File.separator + "beta-data";
|
||||||
static final String TENANT_BETA_DIR = File.separator + "data" + File.separator + "tenant-beta-data";
|
static final String TENANT_BETA_DIR = File.separator + "data" + File.separator + "tenant-beta-data";
|
||||||
static final String TAG_DIR = File.separator + "data" + File.separator + "tag-data";
|
static final String TAG_DIR = File.separator + "data" + File.separator + "tag-data";
|
||||||
static final String TENANT_TAG_DIR = File.separator + "data" + File.separator + "tag-beta-data";
|
static final String TENANT_TAG_DIR = File.separator + "data" + File.separator + "tag-beta-data";
|
||||||
static String SERVERLIST_DIR = File.separator + "conf";
|
|
||||||
static String SERVERLIST_FILENAME = "cluster.conf";
|
|
||||||
|
|
||||||
static {
|
|
||||||
String nacosDir = System.getProperty("nacos.home");
|
|
||||||
if (!StringUtils.isBlank(nacosDir)) {
|
|
||||||
APP_HOME = nacosDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static public void saveHeartBeatToDisk(String heartBeatTime)
|
static public void saveHeartBeatToDisk(String heartBeatTime)
|
||||||
@ -122,9 +113,9 @@ public class DiskUtil {
|
|||||||
static public File targetFile(String dataId, String group, String tenant) {
|
static public File targetFile(String dataId, String group, String tenant) {
|
||||||
File file = null;
|
File file = null;
|
||||||
if (StringUtils.isBlank(tenant)) {
|
if (StringUtils.isBlank(tenant)) {
|
||||||
file = new File(APP_HOME, BASE_DIR);
|
file = new File(NACOS_HOME, BASE_DIR);
|
||||||
} else {
|
} else {
|
||||||
file = new File(APP_HOME, TENANT_BASE_DIR);
|
file = new File(NACOS_HOME, TENANT_BASE_DIR);
|
||||||
file = new File(file, tenant);
|
file = new File(file, tenant);
|
||||||
}
|
}
|
||||||
file = new File(file, group);
|
file = new File(file, group);
|
||||||
@ -138,9 +129,9 @@ public class DiskUtil {
|
|||||||
static public File targetBetaFile(String dataId, String group, String tenant) {
|
static public File targetBetaFile(String dataId, String group, String tenant) {
|
||||||
File file = null;
|
File file = null;
|
||||||
if (StringUtils.isBlank(tenant)) {
|
if (StringUtils.isBlank(tenant)) {
|
||||||
file = new File(APP_HOME, BETA_DIR);
|
file = new File(NACOS_HOME, BETA_DIR);
|
||||||
} else {
|
} else {
|
||||||
file = new File(APP_HOME, TENANT_BETA_DIR);
|
file = new File(NACOS_HOME, TENANT_BETA_DIR);
|
||||||
file = new File(file, tenant);
|
file = new File(file, tenant);
|
||||||
}
|
}
|
||||||
file = new File(file, group);
|
file = new File(file, group);
|
||||||
@ -154,9 +145,9 @@ public class DiskUtil {
|
|||||||
static public File targetTagFile(String dataId, String group, String tenant, String tag) {
|
static public File targetTagFile(String dataId, String group, String tenant, String tag) {
|
||||||
File file = null;
|
File file = null;
|
||||||
if (StringUtils.isBlank(tenant)) {
|
if (StringUtils.isBlank(tenant)) {
|
||||||
file = new File(APP_HOME, TAG_DIR);
|
file = new File(NACOS_HOME, TAG_DIR);
|
||||||
} else {
|
} else {
|
||||||
file = new File(APP_HOME, TENANT_TAG_DIR);
|
file = new File(NACOS_HOME, TENANT_TAG_DIR);
|
||||||
file = new File(file, tenant);
|
file = new File(file, tenant);
|
||||||
}
|
}
|
||||||
file = new File(file, group);
|
file = new File(file, group);
|
||||||
@ -188,7 +179,7 @@ public class DiskUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public File heartBeatFile() {
|
static public File heartBeatFile() {
|
||||||
return new File(APP_HOME, "status/heartBeat.txt");
|
return new File(NACOS_HOME, "status/heartBeat.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String relativePath(String dataId, String group) {
|
static public String relativePath(String dataId, String group) {
|
||||||
@ -196,13 +187,13 @@ public class DiskUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public void clearAll() {
|
static public void clearAll() {
|
||||||
File file = new File(APP_HOME, BASE_DIR);
|
File file = new File(NACOS_HOME, BASE_DIR);
|
||||||
if (FileUtils.deleteQuietly(file)) {
|
if (FileUtils.deleteQuietly(file)) {
|
||||||
LogUtil.defaultLog.info("clear all config-info success.");
|
LogUtil.defaultLog.info("clear all config-info success.");
|
||||||
} else {
|
} else {
|
||||||
LogUtil.defaultLog.warn("clear all config-info failed.");
|
LogUtil.defaultLog.warn("clear all config-info failed.");
|
||||||
}
|
}
|
||||||
File fileTenant = new File(APP_HOME, TENANT_BASE_DIR);
|
File fileTenant = new File(NACOS_HOME, TENANT_BASE_DIR);
|
||||||
if (FileUtils.deleteQuietly(fileTenant)) {
|
if (FileUtils.deleteQuietly(fileTenant)) {
|
||||||
LogUtil.defaultLog.info("clear all config-info-tenant success.");
|
LogUtil.defaultLog.info("clear all config-info-tenant success.");
|
||||||
} else {
|
} else {
|
||||||
@ -211,13 +202,13 @@ public class DiskUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public void clearAllBeta() {
|
static public void clearAllBeta() {
|
||||||
File file = new File(APP_HOME, BETA_DIR);
|
File file = new File(NACOS_HOME, BETA_DIR);
|
||||||
if (FileUtils.deleteQuietly(file)) {
|
if (FileUtils.deleteQuietly(file)) {
|
||||||
LogUtil.defaultLog.info("clear all config-info-beta success.");
|
LogUtil.defaultLog.info("clear all config-info-beta success.");
|
||||||
} else {
|
} else {
|
||||||
LogUtil.defaultLog.warn("clear all config-info-beta failed.");
|
LogUtil.defaultLog.warn("clear all config-info-beta failed.");
|
||||||
}
|
}
|
||||||
File fileTenant = new File(APP_HOME, TENANT_BETA_DIR);
|
File fileTenant = new File(NACOS_HOME, TENANT_BETA_DIR);
|
||||||
if (FileUtils.deleteQuietly(fileTenant)) {
|
if (FileUtils.deleteQuietly(fileTenant)) {
|
||||||
LogUtil.defaultLog.info("clear all config-info-beta-tenant success.");
|
LogUtil.defaultLog.info("clear all config-info-beta-tenant success.");
|
||||||
} else {
|
} else {
|
||||||
@ -226,34 +217,17 @@ public class DiskUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public void clearAllTag() {
|
static public void clearAllTag() {
|
||||||
File file = new File(APP_HOME, TAG_DIR);
|
File file = new File(NACOS_HOME, TAG_DIR);
|
||||||
if (FileUtils.deleteQuietly(file)) {
|
if (FileUtils.deleteQuietly(file)) {
|
||||||
LogUtil.defaultLog.info("clear all config-info-tag success.");
|
LogUtil.defaultLog.info("clear all config-info-tag success.");
|
||||||
} else {
|
} else {
|
||||||
LogUtil.defaultLog.warn("clear all config-info-tag failed.");
|
LogUtil.defaultLog.warn("clear all config-info-tag failed.");
|
||||||
}
|
}
|
||||||
File fileTenant = new File(APP_HOME, TENANT_TAG_DIR);
|
File fileTenant = new File(NACOS_HOME, TENANT_TAG_DIR);
|
||||||
if (FileUtils.deleteQuietly(fileTenant)) {
|
if (FileUtils.deleteQuietly(fileTenant)) {
|
||||||
LogUtil.defaultLog.info("clear all config-info-tag-tenant success.");
|
LogUtil.defaultLog.info("clear all config-info-tag-tenant success.");
|
||||||
} else {
|
} else {
|
||||||
LogUtil.defaultLog.warn("clear all config-info-tag-tenant failed.");
|
LogUtil.defaultLog.warn("clear all config-info-tag-tenant failed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getServerList() throws IOException {
|
|
||||||
FileInputStream fis = null;
|
|
||||||
File file = new File(APP_HOME, SERVERLIST_DIR);
|
|
||||||
file = new File(file, SERVERLIST_FILENAME);
|
|
||||||
if (file.exists()) {
|
|
||||||
try {
|
|
||||||
fis = new FileInputStream(file);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return StringUtils.EMPTY;
|
|
||||||
}
|
|
||||||
String content = IOUtils.toString(fis, Constants.ENCODE);
|
|
||||||
return content;
|
|
||||||
} else {
|
|
||||||
return StringUtils.EMPTY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.NACOS_HOME;
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.NACOS_HOME_KEY;
|
||||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,8 +54,6 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
|||||||
|
|
||||||
private static final String JDBC_DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver";
|
private static final String JDBC_DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver";
|
||||||
private static final String DERBY_BASE_DIR = "data" + File.separator + "derby-data";
|
private static final String DERBY_BASE_DIR = "data" + File.separator + "derby-data";
|
||||||
private static String appHome = System.getProperty("user.home") + File.separator + "nacos";
|
|
||||||
private static final String NACOS_HOME_KEY = "nacos.home";
|
|
||||||
private static final String USER_NAME = "nacos";
|
private static final String USER_NAME = "nacos";
|
||||||
private static final String PASSWORD = "nacos";
|
private static final String PASSWORD = "nacos";
|
||||||
|
|
||||||
@ -62,13 +62,9 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
|||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
String nacosBaseDir = System.getProperty(NACOS_HOME_KEY);
|
|
||||||
if (!StringUtils.isBlank(nacosBaseDir)) {
|
|
||||||
setAppHome(nacosBaseDir);
|
|
||||||
}
|
|
||||||
BasicDataSource ds = new BasicDataSource();
|
BasicDataSource ds = new BasicDataSource();
|
||||||
ds.setDriverClassName(JDBC_DRIVER_NAME);
|
ds.setDriverClassName(JDBC_DRIVER_NAME);
|
||||||
ds.setUrl("jdbc:derby:" + appHome + File.separator + DERBY_BASE_DIR + ";create=true");
|
ds.setUrl("jdbc:derby:" + NACOS_HOME + File.separator + DERBY_BASE_DIR + ";create=true");
|
||||||
ds.setUsername(USER_NAME);
|
ds.setUsername(USER_NAME);
|
||||||
ds.setPassword(PASSWORD);
|
ds.setPassword(PASSWORD);
|
||||||
ds.setInitialSize(20);
|
ds.setInitialSize(20);
|
||||||
@ -127,7 +123,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrentDBUrl() {
|
public String getCurrentDBUrl() {
|
||||||
return "jdbc:derby:" + appHome + File.separator + DERBY_BASE_DIR + ";create=true";
|
return "jdbc:derby:" + NACOS_HOME + File.separator + DERBY_BASE_DIR + ";create=true";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -151,7 +147,8 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
|||||||
URL url = classLoader.getResource(sqlFile);
|
URL url = classLoader.getResource(sqlFile);
|
||||||
sqlFileIn = url.openStream();
|
sqlFileIn = url.openStream();
|
||||||
} else {
|
} else {
|
||||||
File file = new File(System.getProperty(NACOS_HOME_KEY) + "/conf/schema.sql");
|
File file = new File(
|
||||||
|
System.getProperty(NACOS_HOME_KEY) + File.separator + "conf" + File.separator + "schema.sql");
|
||||||
sqlFileIn = new FileInputStream(file);
|
sqlFileIn = new FileInputStream(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,13 +202,4 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAppHome() {
|
|
||||||
return appHome;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setAppHome(String appHome) {
|
|
||||||
LocalDataSourceServiceImpl.appHome = appHome;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import com.alibaba.nacos.config.server.service.notify.NotifyService.HttpResult;
|
|||||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
|
import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
|
||||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
|
||||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -37,6 +36,7 @@ import org.springframework.boot.web.context.WebServerInitializedEvent;
|
|||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
@ -47,7 +47,9 @@ import java.util.*;
|
|||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.readClusterConf;
|
||||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||||
|
|
||||||
@ -150,7 +152,7 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Boolean isFirstIp() {
|
public static Boolean isFirstIp() {
|
||||||
return serverList.get(0).contains(SystemConfig.LOCAL_IP);
|
return serverList.get(0).contains(LOCAL_IP);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHealthCheck() {
|
public boolean isHealthCheck() {
|
||||||
@ -166,7 +168,7 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
|||||||
|
|
||||||
boolean isContainSelfIp = false;
|
boolean isContainSelfIp = false;
|
||||||
for (String ipPortTmp : newList) {
|
for (String ipPortTmp : newList) {
|
||||||
if (ipPortTmp.contains(SystemConfig.LOCAL_IP)) {
|
if (ipPortTmp.contains(LOCAL_IP)) {
|
||||||
isContainSelfIp = true;
|
isContainSelfIp = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -176,7 +178,7 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
|||||||
isInIpList = true;
|
isInIpList = true;
|
||||||
} else {
|
} else {
|
||||||
isInIpList = false;
|
isInIpList = false;
|
||||||
String selfAddr = getFormatServerAddr(SystemConfig.LOCAL_IP);
|
String selfAddr = getFormatServerAddr(LOCAL_IP);
|
||||||
newList.add(selfAddr);
|
newList.add(selfAddr);
|
||||||
fatalLog.error("########## [serverlist] self ip {} not in serverlist {}", selfAddr, newList);
|
fatalLog.error("########## [serverlist] self ip {} not in serverlist {}", selfAddr, newList);
|
||||||
}
|
}
|
||||||
@ -224,11 +226,9 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
|||||||
// 优先从文件读取服务列表
|
// 优先从文件读取服务列表
|
||||||
try {
|
try {
|
||||||
List<String> serverIps = new ArrayList<String>();
|
List<String> serverIps = new ArrayList<String>();
|
||||||
String serverIpsStr = DiskUtil.getServerList();
|
List<String> serverAddrLines = readClusterConf();
|
||||||
if (!StringUtils.isBlank(serverIpsStr)) {
|
if (!CollectionUtils.isEmpty(serverAddrLines)) {
|
||||||
String split = System.getProperty("line.separator");
|
for (String serverAddr : serverAddrLines) {
|
||||||
String[] serverAddrArr = serverIpsStr.split(split);
|
|
||||||
for (String serverAddr : serverAddrArr) {
|
|
||||||
if (StringUtils.isNotBlank(serverAddr.trim())) {
|
if (StringUtils.isNotBlank(serverAddr.trim())) {
|
||||||
serverIps.add(getFormatServerAddr(serverAddr));
|
serverIps.add(getFormatServerAddr(serverAddr));
|
||||||
}
|
}
|
||||||
@ -277,7 +277,7 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
List<String> serverIps = new ArrayList<String>();
|
List<String> serverIps = new ArrayList<String>();
|
||||||
serverIps.add(getFormatServerAddr(SystemConfig.LOCAL_IP));
|
serverIps.add(getFormatServerAddr(LOCAL_IP));
|
||||||
return serverIps;
|
return serverIps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ import java.util.Random;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||||
|
|
||||||
@ -354,7 +355,7 @@ public class DumpService {
|
|||||||
}
|
}
|
||||||
// 删除
|
// 删除
|
||||||
else {
|
else {
|
||||||
persistService.removeConfigInfo(dataId, group, tenant, SystemConfig.LOCAL_IP, null);
|
persistService.removeConfigInfo(dataId, group, tenant, LOCAL_IP, null);
|
||||||
log.warn("[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId=" + group);
|
log.warn("[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId=" + group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
|
|||||||
import com.alibaba.nacos.config.server.model.Page;
|
import com.alibaba.nacos.config.server.model.Page;
|
||||||
import com.alibaba.nacos.config.server.service.PersistService;
|
import com.alibaba.nacos.config.server.service.PersistService;
|
||||||
import com.alibaba.nacos.config.server.utils.ContentUtils;
|
import com.alibaba.nacos.config.server.utils.ContentUtils;
|
||||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
|
||||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -34,6 +33,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据聚合服务。
|
* 数据聚合服务。
|
||||||
@ -88,7 +88,7 @@ public class MergeDatumService {
|
|||||||
|
|
||||||
public void mergeAll() {
|
public void mergeAll() {
|
||||||
for (ConfigInfoChanged item : persistService.findAllAggrGroup()) {
|
for (ConfigInfoChanged item : persistService.findAllAggrGroup()) {
|
||||||
addMergeTask(item.getDataId(), item.getGroup(), item.getTenant(), SystemConfig.LOCAL_IP);
|
addMergeTask(item.getDataId(), item.getGroup(), item.getTenant(), LOCAL_IP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ public class MergeDatumService {
|
|||||||
}
|
}
|
||||||
// 删除
|
// 删除
|
||||||
else {
|
else {
|
||||||
persistService.removeConfigInfo(dataId, group, tenant, SystemConfig.LOCAL_IP, null);
|
persistService.removeConfigInfo(dataId, group, tenant, LOCAL_IP, null);
|
||||||
log.warn("[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId=" + group);
|
log.warn("[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId=" + group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import com.alibaba.nacos.config.server.service.PersistService;
|
|||||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||||
import com.alibaba.nacos.config.server.utils.ContentUtils;
|
import com.alibaba.nacos.config.server.utils.ContentUtils;
|
||||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
|
||||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -36,6 +35,7 @@ import java.sql.Timestamp;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge task processor
|
* Merge task processor
|
||||||
@ -81,7 +81,7 @@ public class MergeTaskProcessor implements TaskProcessor {
|
|||||||
log.info("[merge-ok] {}, {}, size={}, length={}, md5={}, content={}", dataId, group, datumList.size(),
|
log.info("[merge-ok] {}, {}, size={}, length={}, md5={}, content={}", dataId, group, datumList.size(),
|
||||||
cf.getContent().length(), cf.getMd5(), ContentUtils.truncateContent(cf.getContent()));
|
cf.getContent().length(), cf.getMd5(), ContentUtils.truncateContent(cf.getContent()));
|
||||||
|
|
||||||
ConfigTraceService.logPersistenceEvent(dataId, group, tenant, null, time.getTime(), SystemConfig.LOCAL_IP, ConfigTraceService.PERSISTENCE_EVENT_MERGE, cf.getContent());
|
ConfigTraceService.logPersistenceEvent(dataId, group, tenant, null, time.getTime(), LOCAL_IP, ConfigTraceService.PERSISTENCE_EVENT_MERGE, cf.getContent());
|
||||||
}
|
}
|
||||||
// 删除
|
// 删除
|
||||||
else {
|
else {
|
||||||
@ -94,7 +94,7 @@ public class MergeTaskProcessor implements TaskProcessor {
|
|||||||
log.warn("[merge-delete] delete config info because no datum. dataId=" + dataId
|
log.warn("[merge-delete] delete config info because no datum. dataId=" + dataId
|
||||||
+ ", groupId=" + group);
|
+ ", groupId=" + group);
|
||||||
|
|
||||||
ConfigTraceService.logPersistenceEvent(dataId, group, tenant, null, time.getTime(), SystemConfig.LOCAL_IP, ConfigTraceService.PERSISTENCE_EVENT_REMOVE, null);
|
ConfigTraceService.logPersistenceEvent(dataId, group, tenant, null, time.getTime(), LOCAL_IP, ConfigTraceService.PERSISTENCE_EVENT_REMOVE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventDispatcher.fireEvent(new ConfigDataChangeEvent(false, dataId, group, tenant, tag, time.getTime()));
|
EventDispatcher.fireEvent(new ConfigDataChangeEvent(false, dataId, group, tenant, tag, time.getTime()));
|
||||||
|
@ -44,6 +44,8 @@ import java.util.List;
|
|||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async notify service
|
* Async notify service
|
||||||
* @author Nacos
|
* @author Nacos
|
||||||
@ -132,7 +134,7 @@ public class AsyncNotifyService extends AbstractEventListener {
|
|||||||
&& ServerListService.getServerListUnhealth().contains(targetIp)) {
|
&& ServerListService.getServerListUnhealth().contains(targetIp)) {
|
||||||
// target ip 不健康,则放入通知列表中
|
// target ip 不健康,则放入通知列表中
|
||||||
ConfigTraceService.logNotifyEvent(task.getDataId(), task.getGroup(), task.getTenant(), null, task.getLastModified(),
|
ConfigTraceService.logNotifyEvent(task.getDataId(), task.getGroup(), task.getTenant(), null, task.getLastModified(),
|
||||||
SystemConfig.LOCAL_IP, ConfigTraceService.NOTIFY_EVENT_UNHEALTH, 0, task.target);
|
LOCAL_IP, ConfigTraceService.NOTIFY_EVENT_UNHEALTH, 0, task.target);
|
||||||
// get delay time and set fail count to the task
|
// get delay time and set fail count to the task
|
||||||
int delay = getDelayTime(task);
|
int delay = getDelayTime(task);
|
||||||
Queue<NotifySingleTask> queue = new LinkedList<NotifySingleTask>();
|
Queue<NotifySingleTask> queue = new LinkedList<NotifySingleTask>();
|
||||||
@ -143,7 +145,7 @@ public class AsyncNotifyService extends AbstractEventListener {
|
|||||||
HttpGet request = new HttpGet(task.url);
|
HttpGet request = new HttpGet(task.url);
|
||||||
request.setHeader(NotifyService.NOTIFY_HEADER_LAST_MODIFIED,
|
request.setHeader(NotifyService.NOTIFY_HEADER_LAST_MODIFIED,
|
||||||
String.valueOf(task.getLastModified()));
|
String.valueOf(task.getLastModified()));
|
||||||
request.setHeader(NotifyService.NOTIFY_HEADER_OP_HANDLE_IP, SystemConfig.LOCAL_IP);
|
request.setHeader(NotifyService.NOTIFY_HEADER_OP_HANDLE_IP, LOCAL_IP);
|
||||||
if (task.isBeta) {
|
if (task.isBeta) {
|
||||||
request.setHeader("isBeta", "true");
|
request.setHeader("isBeta", "true");
|
||||||
}
|
}
|
||||||
@ -175,7 +177,7 @@ public class AsyncNotifyService extends AbstractEventListener {
|
|||||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||||
ConfigTraceService.logNotifyEvent(task.getDataId(),
|
ConfigTraceService.logNotifyEvent(task.getDataId(),
|
||||||
task.getGroup(), task.getTenant(), null, task.getLastModified(),
|
task.getGroup(), task.getTenant(), null, task.getLastModified(),
|
||||||
SystemConfig.LOCAL_IP,
|
LOCAL_IP,
|
||||||
ConfigTraceService.NOTIFY_EVENT_OK, delayed,
|
ConfigTraceService.NOTIFY_EVENT_OK, delayed,
|
||||||
task.target);
|
task.target);
|
||||||
} else {
|
} else {
|
||||||
@ -185,7 +187,7 @@ public class AsyncNotifyService extends AbstractEventListener {
|
|||||||
response.getStatusLine().getStatusCode() });
|
response.getStatusLine().getStatusCode() });
|
||||||
ConfigTraceService.logNotifyEvent(task.getDataId(),
|
ConfigTraceService.logNotifyEvent(task.getDataId(),
|
||||||
task.getGroup(), task.getTenant(), null, task.getLastModified(),
|
task.getGroup(), task.getTenant(), null, task.getLastModified(),
|
||||||
SystemConfig.LOCAL_IP,
|
LOCAL_IP,
|
||||||
ConfigTraceService.NOTIFY_EVENT_ERROR, delayed,
|
ConfigTraceService.NOTIFY_EVENT_ERROR, delayed,
|
||||||
task.target);
|
task.target);
|
||||||
|
|
||||||
@ -218,7 +220,7 @@ public class AsyncNotifyService extends AbstractEventListener {
|
|||||||
+ ex.toString(), ex);
|
+ ex.toString(), ex);
|
||||||
ConfigTraceService.logNotifyEvent(task.getDataId(),
|
ConfigTraceService.logNotifyEvent(task.getDataId(),
|
||||||
task.getGroup(), task.getTenant(), null, task.getLastModified(),
|
task.getGroup(), task.getTenant(), null, task.getLastModified(),
|
||||||
SystemConfig.LOCAL_IP,
|
LOCAL_IP,
|
||||||
ConfigTraceService.NOTIFY_EVENT_EXCEPTION, delayed,
|
ConfigTraceService.NOTIFY_EVENT_EXCEPTION, delayed,
|
||||||
task.target);
|
task.target);
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import com.alibaba.nacos.config.server.service.ServerListService;
|
|||||||
import com.alibaba.nacos.config.server.service.notify.NotifyService.HttpResult;
|
import com.alibaba.nacos.config.server.service.notify.NotifyService.HttpResult;
|
||||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||||
import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
|
import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
|
||||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -31,6 +30,7 @@ import java.text.MessageFormat;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知服务。数据库变更后,通知所有server,包括自己,加载新数据。
|
* 通知服务。数据库变更后,通知所有server,包括自己,加载新数据。
|
||||||
@ -67,18 +67,18 @@ public class NotifyTaskProcessor implements TaskProcessor {
|
|||||||
// XXX 為了方便系统beta,不改变notify.do接口,新增lastModifed参数通过Http header传递
|
// XXX 為了方便系统beta,不改变notify.do接口,新增lastModifed参数通过Http header传递
|
||||||
List<String> headers = Arrays.asList(
|
List<String> headers = Arrays.asList(
|
||||||
NotifyService.NOTIFY_HEADER_LAST_MODIFIED, String.valueOf(lastModified),
|
NotifyService.NOTIFY_HEADER_LAST_MODIFIED, String.valueOf(lastModified),
|
||||||
NotifyService.NOTIFY_HEADER_OP_HANDLE_IP, SystemConfig.LOCAL_IP);
|
NotifyService.NOTIFY_HEADER_OP_HANDLE_IP, LOCAL_IP);
|
||||||
String urlString = MessageFormat.format(URL_PATTERN, serverIp, RunningConfigUtils.getContextPath(), dataId,
|
String urlString = MessageFormat.format(URL_PATTERN, serverIp, RunningConfigUtils.getContextPath(), dataId,
|
||||||
group);
|
group);
|
||||||
|
|
||||||
HttpResult result = NotifyService.invokeURL(urlString, headers, Constants.ENCODE);
|
HttpResult result = NotifyService.invokeURL(urlString, headers, Constants.ENCODE);
|
||||||
if (result.code == HttpStatus.SC_OK) {
|
if (result.code == HttpStatus.SC_OK) {
|
||||||
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, SystemConfig.LOCAL_IP, ConfigTraceService.NOTIFY_EVENT_OK, delayed, serverIp);
|
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, LOCAL_IP, ConfigTraceService.NOTIFY_EVENT_OK, delayed, serverIp);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
log.error("[notify-error] {}, {}, to {}, result {}", new Object[] { dataId, group,
|
log.error("[notify-error] {}, {}, to {}, result {}", new Object[] { dataId, group,
|
||||||
serverIp, result.code });
|
serverIp, result.code });
|
||||||
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, SystemConfig.LOCAL_IP, ConfigTraceService.NOTIFY_EVENT_ERROR, delayed, serverIp);
|
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, LOCAL_IP, ConfigTraceService.NOTIFY_EVENT_ERROR, delayed, serverIp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -86,7 +86,7 @@ public class NotifyTaskProcessor implements TaskProcessor {
|
|||||||
"[notify-exception] " + dataId + ", " + group + ", to " + serverIp + ", "
|
"[notify-exception] " + dataId + ", " + group + ", to " + serverIp + ", "
|
||||||
+ e.toString());
|
+ e.toString());
|
||||||
log.debug("[notify-exception] " + dataId + ", " + group + ", to " + serverIp + ", " + e.toString(), e);
|
log.debug("[notify-exception] " + dataId + ", " + group + ", to " + serverIp + ", " + e.toString(), e);
|
||||||
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, SystemConfig.LOCAL_IP, ConfigTraceService.NOTIFY_EVENT_EXCEPTION, delayed, serverIp);
|
ConfigTraceService.logNotifyEvent(dataId, group, tenant, null, lastModified, LOCAL_IP, ConfigTraceService.NOTIFY_EVENT_EXCEPTION, delayed, serverIp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,11 @@ package com.alibaba.nacos.config.server.service.trace;
|
|||||||
|
|
||||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||||
import com.alibaba.nacos.config.server.utils.MD5;
|
import com.alibaba.nacos.config.server.utils.MD5;
|
||||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config trace
|
* Config trace
|
||||||
* @author Nacos
|
* @author Nacos
|
||||||
@ -55,7 +57,7 @@ public class ConfigTraceService {
|
|||||||
}
|
}
|
||||||
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed = -1] | ext(md5)
|
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed = -1] | ext(md5)
|
||||||
String md5 = content == null ? null : MD5.getInstance().getMD5String(content);
|
String md5 = content == null ? null : MD5.getInstance().getMD5String(content);
|
||||||
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", SystemConfig.LOCAL_IP, dataId, group, tenant,
|
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", LOCAL_IP, dataId, group, tenant,
|
||||||
requestIpAppName, ts, handleIp, "persist", type, -1, md5);
|
requestIpAppName, ts, handleIp, "persist", type, -1, md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +70,7 @@ public class ConfigTraceService {
|
|||||||
tenant = null;
|
tenant = null;
|
||||||
}
|
}
|
||||||
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed] | ext(targetIp)
|
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed] | ext(targetIp)
|
||||||
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", SystemConfig.LOCAL_IP, dataId, group, tenant,
|
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", LOCAL_IP, dataId, group, tenant,
|
||||||
requestIpAppName, ts, handleIp, "notify", type, delayed, targetIp);
|
requestIpAppName, ts, handleIp, "notify", type, delayed, targetIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +83,7 @@ public class ConfigTraceService {
|
|||||||
tenant = null;
|
tenant = null;
|
||||||
}
|
}
|
||||||
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed] | length
|
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed] | length
|
||||||
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", SystemConfig.LOCAL_IP, dataId, group, tenant,
|
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", LOCAL_IP, dataId, group, tenant,
|
||||||
requestIpAppName, ts, handleIp, "dump", type, delayed, length);
|
requestIpAppName, ts, handleIp, "dump", type, delayed, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +96,7 @@ public class ConfigTraceService {
|
|||||||
tenant = null;
|
tenant = null;
|
||||||
}
|
}
|
||||||
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed = -1]
|
//localIp | dataid | group | tenant | requestIpAppName | ts | handleIp | event | type | [delayed = -1]
|
||||||
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", SystemConfig.LOCAL_IP, dataId, group, tenant,
|
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", LOCAL_IP, dataId, group, tenant,
|
||||||
requestIpAppName, ts, handleIp, "dump-all", type, -1);
|
requestIpAppName, ts, handleIp, "dump-all", type, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +109,7 @@ public class ConfigTraceService {
|
|||||||
tenant = null;
|
tenant = null;
|
||||||
}
|
}
|
||||||
//localIp | dataid | group | tenant| requestIpAppName| ts | event | type | [delayed] | ext(clientIp)
|
//localIp | dataid | group | tenant| requestIpAppName| ts | event | type | [delayed] | ext(clientIp)
|
||||||
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", SystemConfig.LOCAL_IP, dataId, group, tenant,
|
LogUtil.traceLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", LOCAL_IP, dataId, group, tenant,
|
||||||
requestIpAppName, ts, "pull", type, delayed, clientIp);
|
requestIpAppName, ts, "pull", type, delayed, clientIp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos;
|
package com.alibaba.nacos;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||||
@ -28,7 +27,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
|
|||||||
@ServletComponentScan
|
@ServletComponentScan
|
||||||
public class Nacos {
|
public class Nacos {
|
||||||
|
|
||||||
public static void main(String[] args) throws UnknownHostException {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Nacos.class, args);
|
SpringApplication.run(Nacos.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -64,4 +64,13 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -25,6 +25,13 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.LOCAL_IP;
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.NACOS_HOME;
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.readClusterConf;
|
||||||
import static org.springframework.boot.context.logging.LoggingApplicationListener.CONFIG_PROPERTY;
|
import static org.springframework.boot.context.logging.LoggingApplicationListener.CONFIG_PROPERTY;
|
||||||
import static org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX;
|
import static org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX;
|
||||||
|
|
||||||
@ -40,6 +47,10 @@ public class LoggingSpringApplicationRunListener implements SpringApplicationRun
|
|||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(LoggingSpringApplicationRunListener.class);
|
private static final Logger logger = LoggerFactory.getLogger(LoggingSpringApplicationRunListener.class);
|
||||||
|
|
||||||
|
private static final String MODE_PROPERTY_KEY = "nacos.mode";
|
||||||
|
|
||||||
|
private static final String LOCAL_IP_PROPERTY_KEY = "nacos.local.ip";
|
||||||
|
|
||||||
private final SpringApplication application;
|
private final SpringApplication application;
|
||||||
|
|
||||||
private final String[] args;
|
private final String[] args;
|
||||||
@ -64,11 +75,32 @@ public class LoggingSpringApplicationRunListener implements SpringApplicationRun
|
|||||||
DEFAULT_NACOS_LOGBACK_LOCATION);
|
DEFAULT_NACOS_LOGBACK_LOCATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (STANDALONE_MODE) {
|
||||||
|
System.setProperty(MODE_PROPERTY_KEY, "stand alone");
|
||||||
|
} else {
|
||||||
|
System.setProperty(MODE_PROPERTY_KEY, "cluster");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.setProperty(LOCAL_IP_PROPERTY_KEY, LOCAL_IP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextPrepared(ConfigurableApplicationContext context) {
|
public void contextPrepared(ConfigurableApplicationContext context) {
|
||||||
|
System.out.printf("Log files: %s/logs/%n", NACOS_HOME);
|
||||||
|
System.out.printf("Conf files: %s/conf/%n", NACOS_HOME);
|
||||||
|
System.out.printf("Data files: %s/data/%n", NACOS_HOME);
|
||||||
|
|
||||||
|
if (!STANDALONE_MODE) {
|
||||||
|
try {
|
||||||
|
List<String> clusterConf = readClusterConf();
|
||||||
|
System.out.printf("The server IP list of Nacos is %s%n", clusterConf);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("read cluster conf fail", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# Nacos Default Properties
|
# Nacos Default Properties
|
||||||
|
|
||||||
|
nacos.version=${project.version}
|
||||||
|
|
||||||
## Web Server
|
## Web Server
|
||||||
server.servlet.contextPath=/nacos
|
server.servlet.contextPath=/nacos
|
||||||
server.port=8848
|
server.port=8848
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
,--.
|
,--.
|
||||||
,--.'|
|
,--.'|
|
||||||
,--,: : | Version: 0.4.0
|
,--,: : | Nacos ${nacos.version}
|
||||||
,`--.'`| ' : ,---. Port: 8848
|
,`--.'`| ' : ,---. Running in ${nacos.mode} mode
|
||||||
| : : | | ' ,'\ .--.--. Console: http://localhost:8848/nacos/index.html
|
| : : | | ' ,'\ .--.--. Port: 8848
|
||||||
: | \ | : ,--.--. ,---. / / | / / '
|
: | \ | : ,--.--. ,---. / / | / / ' Pid: ${pid}
|
||||||
| : ' '; | / \ / \. ; ,. :| : /`./
|
| : ' '; | / \ / \. ; ,. :| : /`./ Console: http://${nacos.local.ip}:8848/nacos/index.html
|
||||||
' ' ;. ;.--. .-. | / / '' | |: :| : ;_ https://nacos.io
|
' ' ;. ;.--. .-. | / / '' | |: :| : ;_
|
||||||
| | | \ | \__\/: . .. ' / ' | .; : \ \ `.
|
| | | \ | \__\/: . .. ' / ' | .; : \ \ `. https://nacos.io
|
||||||
' : | ; .' ," .--.; |' ; :__| : | `----. \
|
' : | ; .' ," .--.; |' ; :__| : | `----. \
|
||||||
| | '`--' / / ,. |' | '.'|\ \ / / /`--' /
|
| | '`--' / / ,. |' | '.'|\ \ / / /`--' /
|
||||||
' : | ; : .' \ : : `----' '--'. /
|
' : | ; : .' \ : : `----' '--'. /
|
||||||
|
@ -79,6 +79,7 @@ public class NacosDefaultPropertySourceEnvironmentPostProcessorTest {
|
|||||||
public void testDefaultPropertyNames() {
|
public void testDefaultPropertyNames() {
|
||||||
|
|
||||||
assertPropertyNames(
|
assertPropertyNames(
|
||||||
|
"nacos.version",
|
||||||
"server.servlet.contextPath",
|
"server.servlet.contextPath",
|
||||||
"server.port",
|
"server.port",
|
||||||
"server.tomcat.uri-encoding",
|
"server.tomcat.uri-encoding",
|
||||||
|
@ -67,6 +67,7 @@ if [ ! -f "${BASE_DIR}/logs/start.log" ]; then
|
|||||||
touch "${BASE_DIR}/logs/start.log"
|
touch "${BASE_DIR}/logs/start.log"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "$JAVA ${JAVA_OPT}"
|
||||||
nohup $JAVA ${JAVA_OPT} > ${BASE_DIR}/logs/start.log 2>&1 &
|
echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/start.log 2>&1 &
|
||||||
|
nohup $JAVA ${JAVA_OPT} >> ${BASE_DIR}/logs/start.log 2>&1 &
|
||||||
echo "nacos is starting,you can check the ${BASE_DIR}/logs/start.log"
|
echo "nacos is starting,you can check the ${BASE_DIR}/logs/start.log"
|
@ -19,7 +19,6 @@ import com.alibaba.nacos.common.util.SystemUtils;
|
|||||||
import com.alibaba.nacos.naming.boot.RunningConfig;
|
import com.alibaba.nacos.naming.boot.RunningConfig;
|
||||||
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -31,7 +30,9 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.CLUSTER_CONF_FILE_PATH;
|
||||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.readClusterConf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nacos
|
* @author nacos
|
||||||
@ -157,9 +158,9 @@ public class NamingProxy {
|
|||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
// read nacos config if necessary.
|
// read nacos config if necessary.
|
||||||
try {
|
try {
|
||||||
result = FileUtils.readLines(UtilsAndCommons.getConfFile(), "UTF-8");
|
result = readClusterConf();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Loggers.SRV_LOG.warn("failed to get config: " + UtilsAndCommons.getConfFilePath(), e);
|
Loggers.SRV_LOG.warn("failed to get config: " + CLUSTER_CONF_FILE_PATH, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Loggers.DEBUG_LOG.debug("REFRESH-SERVER-LIST1", result);
|
Loggers.DEBUG_LOG.debug("REFRESH-SERVER-LIST1", result);
|
||||||
|
@ -26,7 +26,6 @@ import com.alibaba.nacos.naming.exception.NacosException;
|
|||||||
import com.alibaba.nacos.naming.healthcheck.JsonAdapter;
|
import com.alibaba.nacos.naming.healthcheck.JsonAdapter;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
@ -36,12 +35,6 @@ import java.util.concurrent.*;
|
|||||||
*/
|
*/
|
||||||
public class UtilsAndCommons {
|
public class UtilsAndCommons {
|
||||||
|
|
||||||
private static final String NACOS_CONF_DIR_PATH = System.getProperty("user.home") + "/conf";
|
|
||||||
|
|
||||||
private static final String NACOS_CONF_FILE_NAME = "cluster.conf";
|
|
||||||
|
|
||||||
private static String NACOS_CONF_FILE_PATH = NACOS_CONF_DIR_PATH + File.separator + NACOS_CONF_FILE_NAME;
|
|
||||||
|
|
||||||
public static final String NACOS_SERVER_CONTEXT = "/nacos";
|
public static final String NACOS_SERVER_CONTEXT = "/nacos";
|
||||||
|
|
||||||
public static final String NACOS_SERVER_VERSION = "/v1";
|
public static final String NACOS_SERVER_VERSION = "/v1";
|
||||||
@ -131,12 +124,6 @@ public class UtilsAndCommons {
|
|||||||
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteMapNullValue.getMask();
|
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteMapNullValue.getMask();
|
||||||
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteNullNumberAsZero.getMask();
|
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteNullNumberAsZero.getMask();
|
||||||
|
|
||||||
String nacosHome = System.getProperty("nacos.home");
|
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(nacosHome)) {
|
|
||||||
NACOS_CONF_FILE_PATH = nacosHome + File.separator + "conf" + File.separator + NACOS_CONF_FILE_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
DOMAIN_SYNCHRONIZATION_EXECUTOR
|
DOMAIN_SYNCHRONIZATION_EXECUTOR
|
||||||
= new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
= new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
||||||
@Override
|
@Override
|
||||||
@ -206,14 +193,6 @@ public class UtilsAndCommons {
|
|||||||
return strBuilder.toString();
|
return strBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getConfFilePath() {
|
|
||||||
return NACOS_CONF_FILE_PATH;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getConfFile() {
|
|
||||||
return new File(getConfFilePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String getIPListStoreKey(Domain dom) {
|
public static String getIPListStoreKey(Domain dom) {
|
||||||
return UtilsAndCommons.IPADDRESS_DATA_ID_PRE + dom.getName();
|
return UtilsAndCommons.IPADDRESS_DATA_ID_PRE + dom.getName();
|
||||||
|
@ -26,17 +26,16 @@ import java.io.FileOutputStream;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import static com.alibaba.nacos.common.util.SystemUtils.NACOS_HOME;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import static com.alibaba.nacos.common.util.SystemUtils.NACOS_HOME_KEY;
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nacos
|
* @author nacos
|
||||||
*/
|
*/
|
||||||
public class RaftStore {
|
public class RaftStore {
|
||||||
|
|
||||||
private static String BASE_DIR = System.getProperty("user.home") + File.separator + "nacos" + File.separator + "raft";
|
private static String BASE_DIR = NACOS_HOME + File.separator + "raft";
|
||||||
|
|
||||||
private static String META_FILE_NAME;
|
private static String META_FILE_NAME;
|
||||||
|
|
||||||
@ -46,9 +45,8 @@ public class RaftStore {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
String nacosHome = System.getProperty("nacos.home");
|
if (StringUtils.isNotBlank(System.getProperty(NACOS_HOME_KEY))) {
|
||||||
if (StringUtils.isNotBlank(nacosHome)) {
|
BASE_DIR = NACOS_HOME + File.separator + "data" + File.separator + "naming";
|
||||||
BASE_DIR = nacosHome + File.separator + "data" + File.separator + "naming";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
META_FILE_NAME = BASE_DIR + File.separator + "meta.properties";
|
META_FILE_NAME = BASE_DIR + File.separator + "meta.properties";
|
||||||
|
@ -21,7 +21,6 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.alibaba.fastjson.TypeReference;
|
import com.alibaba.fastjson.TypeReference;
|
||||||
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
|
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Service;
|
import com.alibaba.nacos.api.naming.pojo.Service;
|
||||||
import com.alibaba.nacos.common.util.IoUtils;
|
|
||||||
import com.alibaba.nacos.common.util.Md5Utils;
|
import com.alibaba.nacos.common.util.Md5Utils;
|
||||||
import com.alibaba.nacos.common.util.SystemUtils;
|
import com.alibaba.nacos.common.util.SystemUtils;
|
||||||
import com.alibaba.nacos.naming.boot.RunningConfig;
|
import com.alibaba.nacos.naming.boot.RunningConfig;
|
||||||
@ -69,6 +68,9 @@ import java.util.concurrent.locks.Condition;
|
|||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.readClusterConf;
|
||||||
|
import static com.alibaba.nacos.common.util.SystemUtils.writeClusterConf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Old API entry
|
* Old API entry
|
||||||
*
|
*
|
||||||
@ -2028,8 +2030,7 @@ public class ApiCommands {
|
|||||||
|
|
||||||
if (SwitchEntry.ACTION_ADD.equals(action)) {
|
if (SwitchEntry.ACTION_ADD.equals(action)) {
|
||||||
|
|
||||||
List<String> oldList =
|
List<String> oldList = readClusterConf();
|
||||||
IoUtils.readLines(new InputStreamReader(new FileInputStream(UtilsAndCommons.getConfFile()), "UTF-8"));
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (String ip : oldList) {
|
for (String ip : oldList) {
|
||||||
sb.append(ip).append("\r\n");
|
sb.append(ip).append("\r\n");
|
||||||
@ -2039,7 +2040,7 @@ public class ApiCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Loggers.SRV_LOG.info("[UPDATE-CLUSTER] new ips:" + sb.toString());
|
Loggers.SRV_LOG.info("[UPDATE-CLUSTER] new ips:" + sb.toString());
|
||||||
IoUtils.writeStringToFile(UtilsAndCommons.getConfFile(), sb.toString(), "utf-8");
|
writeClusterConf(sb.toString());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2050,7 +2051,7 @@ public class ApiCommands {
|
|||||||
sb.append(ip).append("\r\n");
|
sb.append(ip).append("\r\n");
|
||||||
}
|
}
|
||||||
Loggers.SRV_LOG.info("[UPDATE-CLUSTER] new ips:" + sb.toString());
|
Loggers.SRV_LOG.info("[UPDATE-CLUSTER] new ips:" + sb.toString());
|
||||||
IoUtils.writeStringToFile(UtilsAndCommons.getConfFile(), sb.toString(), "utf-8");
|
writeClusterConf(sb.toString());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2061,8 +2062,7 @@ public class ApiCommands {
|
|||||||
removeIps.add(ip);
|
removeIps.add(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> oldList =
|
List<String> oldList = readClusterConf();
|
||||||
IoUtils.readLines(new InputStreamReader(new FileInputStream(UtilsAndCommons.getConfFile()), "utf-8"));
|
|
||||||
|
|
||||||
Iterator<String> iterator = oldList.iterator();
|
Iterator<String> iterator = oldList.iterator();
|
||||||
|
|
||||||
@ -2079,15 +2079,14 @@ public class ApiCommands {
|
|||||||
sb.append(ip).append("\r\n");
|
sb.append(ip).append("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
IoUtils.writeStringToFile(UtilsAndCommons.getConfFile(), sb.toString(), "utf-8");
|
writeClusterConf(sb.toString());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SwitchEntry.ACTION_VIEW.equals(action)) {
|
if (SwitchEntry.ACTION_VIEW.equals(action)) {
|
||||||
|
|
||||||
List<String> oldList =
|
List<String> oldList = readClusterConf();
|
||||||
IoUtils.readLines(new InputStreamReader(new FileInputStream(UtilsAndCommons.getConfFile()), "utf-8"));
|
|
||||||
result.put("list", oldList);
|
result.put("list", oldList);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user