commit
fbb57c4450
@ -1,4 +1,4 @@
|
||||
## 1.0.0-RC2(Mar 22, 2019)
|
||||
## 1.0.0-RC4(Mar 22, 2019)
|
||||
* [#923] Nacos 1.0.0 compatible with nacos-client 0.6.2
|
||||
* [#938] Client beat processor task lost
|
||||
* [#946] Change default server mode to AP
|
||||
|
@ -97,9 +97,9 @@ Contributors are welcomed to join Nacos project. Please check [CONTRIBUTING](./C
|
||||
* users-nacos@googlegroups.com: Nacos usage general discussion.
|
||||
* dev-nacos@googlegroups.com: Nacos developer discussion (APIs, feature design, etc).
|
||||
* commits-nacos@googlegroups.com: Commits notice, very high frequency.
|
||||
* Join us from wechat. Welcome words: Nacos.
|
||||
* Join us from DingDing.
|
||||
|
||||
![cwex](http://acm-public.oss-cn-hangzhou.aliyuncs.com/xuc.png)
|
||||
![cwex](https://img.alicdn.com/tfs/TB1bpBlQmrqK1RjSZK9XXXyypXa-830-972.png_288x480q80.jpg)
|
||||
|
||||
|
||||
## Who is using
|
||||
|
@ -16,7 +16,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -22,6 +22,8 @@ package com.alibaba.nacos.api;
|
||||
*/
|
||||
public class PropertyKeyConst {
|
||||
|
||||
public final static String IS_USE_ENDPOINT_PARSING_RULE = "isUseEndpointParsingRule";
|
||||
|
||||
public final static String ENDPOINT = "endpoint";
|
||||
|
||||
public final static String ENDPOINT_PORT = "endpointPort";
|
||||
|
@ -138,6 +138,16 @@ public interface NamingService {
|
||||
*/
|
||||
void deregisterInstance(String serviceName, String groupName, String ip, int port, String clusterName) throws NacosException;
|
||||
|
||||
/**
|
||||
* deregister instance with full instance information
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param instance instance information
|
||||
* @throws NacosException
|
||||
*/
|
||||
void deregisterInstance(String serviceName, String groupName, Instance instance) throws NacosException;
|
||||
|
||||
/**
|
||||
* get all instances of a service
|
||||
*
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.api.naming;
|
||||
|
||||
/**
|
||||
* Some keys of metadata that are recognized by Nacos
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class PreservedMetadataKeys {
|
||||
|
||||
/**
|
||||
* The key to indicate the registry source of service instance, such as Dubbo, SpringCloud, etc.
|
||||
*/
|
||||
public static final String REGISTER_SOURCE = "preserved.register.source";
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -100,12 +100,6 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-annotations</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@ -119,6 +113,7 @@
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -82,7 +82,7 @@ public class NacosConfigService implements ConfigService {
|
||||
}
|
||||
|
||||
private void initNamespace(Properties properties) {
|
||||
String namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
String namespaceTmp = null;
|
||||
|
||||
namespaceTmp = TemplateUtils.stringBlankAndThenExecute(namespaceTmp, new Callable<String>() {
|
||||
@Override
|
||||
@ -98,6 +98,10 @@ public class NacosConfigService implements ConfigService {
|
||||
return StringUtils.isNotBlank(namespace) ? namespace : "";
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtils.isBlank(namespaceTmp)) {
|
||||
namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
}
|
||||
namespace = namespaceTmp;
|
||||
properties.put(PropertyKeyConst.NAMESPACE, namespace);
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
@ -102,7 +101,6 @@ public class ClientWorker {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
|
||||
void removeCache(String dataId, String group) {
|
||||
String groupKey = GroupKey.getKey(dataId, group);
|
||||
synchronized (cacheMap) {
|
||||
@ -115,7 +113,6 @@ public class ClientWorker {
|
||||
MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
|
||||
void removeCache(String dataId, String group, String tenant) {
|
||||
String groupKey = GroupKey.getKeyTenant(dataId, group, tenant);
|
||||
synchronized (cacheMap) {
|
||||
@ -128,7 +125,6 @@ public class ClientWorker {
|
||||
MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
|
||||
public CacheData addCacheDataIfAbsent(String dataId, String group) {
|
||||
CacheData cache = getCache(dataId, group);
|
||||
if (null != cache) {
|
||||
@ -163,7 +159,6 @@ public class ClientWorker {
|
||||
return cache;
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
|
||||
public CacheData addCacheDataIfAbsent(String dataId, String group, String tenant) {
|
||||
CacheData cache = getCache(dataId, group, tenant);
|
||||
if (null != cache) {
|
||||
|
@ -21,7 +21,6 @@ import com.alibaba.nacos.client.config.impl.EventDispatcher.ServerlistChangeEven
|
||||
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
|
||||
import com.alibaba.nacos.client.config.utils.IOUtils;
|
||||
import com.alibaba.nacos.client.utils.*;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -86,7 +85,9 @@ public class ServerListManager {
|
||||
public ServerListManager(String endpoint, String namespace) throws NacosException {
|
||||
isFixed = false;
|
||||
isStarted = false;
|
||||
endpoint = initEndpoint(endpoint);
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(PropertyKeyConst.ENDPOINT, endpoint);
|
||||
endpoint = initEndpoint(properties);
|
||||
|
||||
if (StringUtils.isBlank(endpoint)) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, "endpoint is blank");
|
||||
@ -109,7 +110,7 @@ public class ServerListManager {
|
||||
|
||||
public ServerListManager(Properties properties) throws NacosException {
|
||||
isStarted = false;
|
||||
String serverAddrsStr = properties.getProperty(PropertyKeyConst.SERVER_ADDR);
|
||||
serverAddrsStr = properties.getProperty(PropertyKeyConst.SERVER_ADDR);
|
||||
String namespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
initParam(properties);
|
||||
if (StringUtils.isNotEmpty(serverAddrsStr)) {
|
||||
@ -153,7 +154,7 @@ public class ServerListManager {
|
||||
}
|
||||
|
||||
private void initParam(Properties properties) {
|
||||
endpoint = initEndpoint(properties.getProperty(PropertyKeyConst.ENDPOINT));
|
||||
endpoint = initEndpoint(properties);
|
||||
|
||||
String contentPathTmp = properties.getProperty(PropertyKeyConst.CONTEXT_PATH);
|
||||
if (!StringUtils.isBlank(contentPathTmp)) {
|
||||
@ -165,19 +166,29 @@ public class ServerListManager {
|
||||
}
|
||||
}
|
||||
|
||||
private String initEndpoint(String endpointTmp) {
|
||||
String endpointPortTmp = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_PORT);
|
||||
private String initEndpoint(final Properties properties) {
|
||||
|
||||
String endpointPortTmp = TemplateUtils.stringEmptyAndThenExecute(System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_PORT), new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
return properties.getProperty(PropertyKeyConst.ENDPOINT_PORT);
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtils.isNotBlank(endpointPortTmp)) {
|
||||
endpointPort = Integer.parseInt(endpointPortTmp);
|
||||
}
|
||||
|
||||
return TemplateUtils.stringBlankAndThenExecute(endpointTmp, new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
String endpointUrl = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL);
|
||||
return StringUtils.isNotBlank(endpointUrl) ? endpointUrl : "";
|
||||
String endpointTmp = properties.getProperty(PropertyKeyConst.ENDPOINT);
|
||||
if (Boolean.valueOf(properties.getProperty(PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE, ParamUtil.USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE))) {
|
||||
String endpointUrl = ParamUtil.parsingEndpointRule(endpointPortTmp);
|
||||
if (StringUtils.isNotBlank(endpointUrl)) {
|
||||
serverAddrsStr = "";
|
||||
}
|
||||
});
|
||||
return endpointUrl;
|
||||
}
|
||||
|
||||
return StringUtils.isNotBlank(endpointTmp) ? endpointTmp : "";
|
||||
}
|
||||
|
||||
public synchronized void start() throws NacosException {
|
||||
@ -369,6 +380,7 @@ public class ServerListManager {
|
||||
|
||||
public String addressServerUrl;
|
||||
|
||||
private String serverAddrsStr;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -396,7 +408,6 @@ class ServerAddressIterator implements Iterator<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressFBWarnings("EQ_COMPARETO_USE_OBJECT_EQUALS")
|
||||
public int compareTo(RandomizedServerAddress other) {
|
||||
if (this.priority != other.priority) {
|
||||
return other.priority - this.priority;
|
||||
|
@ -34,9 +34,10 @@ import com.alibaba.nacos.client.naming.core.EventDispatcher;
|
||||
import com.alibaba.nacos.client.naming.core.HostReactor;
|
||||
import com.alibaba.nacos.client.naming.net.NamingProxy;
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
@ -86,9 +87,7 @@ public class NacosNamingService implements NamingService {
|
||||
}
|
||||
|
||||
private void init(Properties properties) {
|
||||
|
||||
serverList = properties.getProperty(PropertyKeyConst.SERVER_ADDR);
|
||||
|
||||
initNamespace(properties);
|
||||
initEndpoint(properties);
|
||||
initWebRootContext();
|
||||
@ -104,14 +103,11 @@ public class NacosNamingService implements NamingService {
|
||||
|
||||
private int initClientBeatThreadCount(Properties properties) {
|
||||
if (properties == null) {
|
||||
|
||||
return UtilAndComs.DEFAULT_CLIENT_BEAT_THREAD_COUNT;
|
||||
}
|
||||
|
||||
int clientBeatThreadCount = NumberUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_CLIENT_BEAT_THREAD_COUNT),
|
||||
return NumberUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_CLIENT_BEAT_THREAD_COUNT),
|
||||
UtilAndComs.DEFAULT_CLIENT_BEAT_THREAD_COUNT);
|
||||
|
||||
return clientBeatThreadCount;
|
||||
}
|
||||
|
||||
private int initPollingThreadCount(Properties properties) {
|
||||
@ -120,10 +116,8 @@ public class NacosNamingService implements NamingService {
|
||||
return UtilAndComs.DEFAULT_POLLING_THREAD_COUNT;
|
||||
}
|
||||
|
||||
int pollingThreadCount = NumberUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_POLLING_THREAD_COUNT),
|
||||
return NumberUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_POLLING_THREAD_COUNT),
|
||||
UtilAndComs.DEFAULT_POLLING_THREAD_COUNT);
|
||||
|
||||
return pollingThreadCount;
|
||||
}
|
||||
|
||||
private boolean isLoadCacheAtStart(Properties properties) {
|
||||
@ -155,30 +149,35 @@ public class NacosNamingService implements NamingService {
|
||||
}
|
||||
}
|
||||
|
||||
private void initEndpoint(Properties properties) {
|
||||
private void initEndpoint(final Properties properties) {
|
||||
if (properties == null) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
String endpointUrl = TemplateUtils.stringEmptyAndThenExecute(properties.getProperty(PropertyKeyConst.ENDPOINT), new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
return System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL);
|
||||
//这里通过 dubbo/sca 侧来初始化默认传入的是 true
|
||||
boolean isUseEndpointParsingRule = Boolean.valueOf(properties.getProperty(PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE, ParamUtil.USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE));
|
||||
String endpointUrl;
|
||||
if (isUseEndpointParsingRule) {
|
||||
endpointUrl = ParamUtil.parsingEndpointRule(properties.getProperty(PropertyKeyConst.ENDPOINT));
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(endpointUrl)) {
|
||||
serverList = "";
|
||||
}
|
||||
});
|
||||
} else {
|
||||
endpointUrl = properties.getProperty(PropertyKeyConst.ENDPOINT);
|
||||
}
|
||||
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isBlank(endpointUrl)) {
|
||||
if (StringUtils.isBlank(endpointUrl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String endpointPort = TemplateUtils.stringEmptyAndThenExecute(properties.getProperty(PropertyKeyConst.ENDPOINT_PORT), new Callable<String>() {
|
||||
String endpointPort = TemplateUtils.stringEmptyAndThenExecute(System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_PORT), new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
|
||||
return System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_PORT);
|
||||
return properties.getProperty(PropertyKeyConst.ENDPOINT_PORT);
|
||||
}
|
||||
});
|
||||
|
||||
endpointPort = TemplateUtils.stringEmptyAndThenExecute(endpointPort, new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
@ -192,10 +191,6 @@ public class NacosNamingService implements NamingService {
|
||||
private void initNamespace(Properties properties) {
|
||||
String tmpNamespace = null;
|
||||
|
||||
if (properties != null) {
|
||||
tmpNamespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
}
|
||||
|
||||
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
@ -224,6 +219,10 @@ public class NacosNamingService implements NamingService {
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtils.isEmpty(tmpNamespace) && properties != null) {
|
||||
tmpNamespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
}
|
||||
|
||||
tmpNamespace = TemplateUtils.stringEmptyAndThenExecute(tmpNamespace, new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
@ -283,16 +282,18 @@ public class NacosNamingService implements NamingService {
|
||||
@Override
|
||||
public void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException {
|
||||
|
||||
BeatInfo beatInfo = new BeatInfo();
|
||||
beatInfo.setServiceName(NamingUtils.getGroupedName(serviceName, groupName));
|
||||
beatInfo.setIp(instance.getIp());
|
||||
beatInfo.setPort(instance.getPort());
|
||||
beatInfo.setCluster(instance.getClusterName());
|
||||
beatInfo.setWeight(instance.getWeight());
|
||||
beatInfo.setMetadata(instance.getMetadata());
|
||||
beatInfo.setScheduled(false);
|
||||
if (instance.isEphemeral()) {
|
||||
BeatInfo beatInfo = new BeatInfo();
|
||||
beatInfo.setServiceName(NamingUtils.getGroupedName(serviceName, groupName));
|
||||
beatInfo.setIp(instance.getIp());
|
||||
beatInfo.setPort(instance.getPort());
|
||||
beatInfo.setCluster(instance.getClusterName());
|
||||
beatInfo.setWeight(instance.getWeight());
|
||||
beatInfo.setMetadata(instance.getMetadata());
|
||||
beatInfo.setScheduled(false);
|
||||
|
||||
beatReactor.addBeatInfo(NamingUtils.getGroupedName(serviceName, groupName), beatInfo);
|
||||
beatReactor.addBeatInfo(NamingUtils.getGroupedName(serviceName, groupName), beatInfo);
|
||||
}
|
||||
|
||||
serverProxy.registerService(NamingUtils.getGroupedName(serviceName, groupName), groupName, instance);
|
||||
}
|
||||
@ -314,8 +315,18 @@ public class NacosNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public void deregisterInstance(String serviceName, String groupName, String ip, int port, String clusterName) throws NacosException {
|
||||
beatReactor.removeBeatInfo(NamingUtils.getGroupedName(serviceName, groupName), ip, port);
|
||||
serverProxy.deregisterService(NamingUtils.getGroupedName(serviceName, groupName), ip, port, clusterName);
|
||||
Instance instance = new Instance();
|
||||
instance.setIp(ip);
|
||||
instance.setPort(port);
|
||||
instance.setClusterName(clusterName);
|
||||
|
||||
deregisterInstance(serviceName, groupName, instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregisterInstance(String serviceName, String groupName, Instance instance) throws NacosException {
|
||||
beatReactor.removeBeatInfo(NamingUtils.getGroupedName(serviceName, groupName), instance.getIp(), instance.getPort());
|
||||
serverProxy.deregisterService(NamingUtils.getGroupedName(serviceName, groupName), instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,6 @@ import com.alibaba.nacos.client.naming.cache.DiskCache;
|
||||
import com.alibaba.nacos.client.naming.net.NamingProxy;
|
||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
@ -267,7 +266,6 @@ public class HostReactor {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("NN_NAKED_NOTIFY")
|
||||
public void updateServiceNow(String serviceName, String clusters) {
|
||||
ServiceInfo oldService = getSerivceInfo0(serviceName, clusters);
|
||||
try {
|
||||
|
@ -187,17 +187,18 @@ public class NamingProxy {
|
||||
|
||||
}
|
||||
|
||||
public void deregisterService(String serviceName, String ip, int port, String clusterName) throws NacosException {
|
||||
public void deregisterService(String serviceName, Instance instance) throws NacosException {
|
||||
|
||||
NAMING_LOGGER.info("[DEREGISTER-SERVICE] {} deregistering service {} with instance: {}:{}@{}",
|
||||
namespaceId, serviceName, ip, port, clusterName);
|
||||
NAMING_LOGGER.info("[DEREGISTER-SERVICE] {} deregistering service {} with instance: {}",
|
||||
namespaceId, serviceName, instance);
|
||||
|
||||
final Map<String, String> params = new HashMap<String, String>(8);
|
||||
params.put(CommonParams.NAMESPACE_ID, namespaceId);
|
||||
params.put("ip", ip);
|
||||
params.put("port", String.valueOf(port));
|
||||
params.put(CommonParams.SERVICE_NAME, serviceName);
|
||||
params.put(CommonParams.CLUSTER_NAME, clusterName);
|
||||
params.put(CommonParams.CLUSTER_NAME, instance.getClusterName());
|
||||
params.put("ip", instance.getIp());
|
||||
params.put("port", String.valueOf(instance.getPort()));
|
||||
params.put("ephemeral", String.valueOf(instance.isEphemeral()));
|
||||
|
||||
reqAPI(UtilAndComs.NACOS_URL_INSTANCE, params, HttpMethod.DELETE);
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.naming.utils;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.channels.FileChannel;
|
||||
@ -163,7 +162,6 @@ public class IoUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("BIT_IOR_OF_SIGNED_BYTE")
|
||||
public static boolean isGzipStream(byte[] bytes) {
|
||||
|
||||
int minByteArraySize = 2;
|
||||
|
@ -15,11 +15,14 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.utils;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.client.config.impl.HttpSimpleClient;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* manage param tool
|
||||
@ -27,8 +30,12 @@ import java.util.Properties;
|
||||
* @author nacos
|
||||
*/
|
||||
public class ParamUtil {
|
||||
|
||||
private final static Logger LOGGER = LogUtils.logger(ParamUtil.class);
|
||||
|
||||
public final static String USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE = "false";
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile("\\$\\{[^}]+\\}");
|
||||
private static String defaultContextPath = "nacos";
|
||||
private static String defaultNodesPath = "serverlist";
|
||||
private static String appKey;
|
||||
@ -143,4 +150,46 @@ public class ParamUtil {
|
||||
ParamUtil.defaultNodesPath = defaultNodesPath;
|
||||
}
|
||||
|
||||
|
||||
public static String parsingEndpointRule(String endpointUrl) {
|
||||
// 配置文件中输入的话,以 ENV 中的优先,
|
||||
if (endpointUrl == null
|
||||
|| !PATTERN.matcher(endpointUrl).find()) {
|
||||
// skip retrieve from system property and retrieve directly from system env
|
||||
String endpointUrlSource = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL);
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(endpointUrlSource)) {
|
||||
endpointUrl = endpointUrlSource;
|
||||
}
|
||||
|
||||
return StringUtils.isNotBlank(endpointUrl) ? endpointUrl : "";
|
||||
}
|
||||
|
||||
endpointUrl = endpointUrl.substring(endpointUrl.indexOf("${") + 2,
|
||||
endpointUrl.lastIndexOf("}"));
|
||||
int defStartOf = endpointUrl.indexOf(":");
|
||||
String defaultEndpointUrl = null;
|
||||
if (defStartOf != -1) {
|
||||
defaultEndpointUrl = endpointUrl.substring(defStartOf + 1);
|
||||
endpointUrl = endpointUrl.substring(0, defStartOf);
|
||||
}
|
||||
|
||||
String endpointUrlSource = TemplateUtils.stringBlankAndThenExecute(System.getProperty(endpointUrl,
|
||||
System.getenv(endpointUrl)), new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
return System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isBlank(endpointUrlSource)) {
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(defaultEndpointUrl)) {
|
||||
endpointUrl = defaultEndpointUrl;
|
||||
}
|
||||
} else {
|
||||
endpointUrl = endpointUrlSource;
|
||||
}
|
||||
|
||||
return StringUtils.isNotBlank(endpointUrl) ? endpointUrl : "";
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* string util
|
||||
*
|
||||
@ -71,4 +73,23 @@ public class StringUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String join(Collection collection, String separator) {
|
||||
if (collection == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
Object[] objects = collection.toArray();
|
||||
|
||||
for (int i = 0; i < collection.size() - 1; i++) {
|
||||
stringBuilder.append(objects[i].toString()).append(separator);
|
||||
}
|
||||
|
||||
if (collection.size() > 0) {
|
||||
stringBuilder.append(objects[collection.size() - 1]);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -30,8 +30,9 @@ public class VersionUtils {
|
||||
|
||||
|
||||
static{
|
||||
InputStream in = null;
|
||||
try{
|
||||
InputStream in = VersionUtils.class.getClassLoader()
|
||||
in = VersionUtils.class.getClassLoader()
|
||||
.getResourceAsStream("nacos-version.txt");
|
||||
Properties props = new Properties();
|
||||
props.load(in);
|
||||
@ -41,6 +42,14 @@ public class VersionUtils {
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -117,10 +117,6 @@
|
||||
<artifactId>jcip-annotations</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
@ -157,16 +157,17 @@ public class DiskUtil {
|
||||
|
||||
static public String getConfig(String dataId, String group, String tenant)
|
||||
throws IOException {
|
||||
FileInputStream fis = null;
|
||||
File file = targetFile(dataId, group, tenant);
|
||||
if (file.exists()) {
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
return IOUtils.toString(fis, Constants.ENCODE);
|
||||
} catch (FileNotFoundException e) {
|
||||
return StringUtils.EMPTY;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(fis);
|
||||
}
|
||||
String content = IOUtils.toString(fis, Constants.ENCODE);
|
||||
return content;
|
||||
} else {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
@ -60,8 +60,6 @@ import com.alibaba.nacos.config.server.utils.PaginationHelper;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
/**
|
||||
* 数据库服务,提供ConfigInfo在数据库的存取<br> 3.0开始增加数据版本号, 并将物理删除改为逻辑删除<br> 3.0增加数据库切换功能
|
||||
*
|
||||
@ -2639,9 +2637,6 @@ public class PersistService {
|
||||
|
||||
try {
|
||||
jt.update(new PreparedStatementCreator() {
|
||||
@SuppressFBWarnings(value = {"OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE",
|
||||
"SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING"},
|
||||
justification = "findbugs does not trust jdbctemplate, sql is constant in practice")
|
||||
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
|
||||
PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
ps.setString(1, configInfo.getDataId());
|
||||
|
@ -22,7 +22,6 @@ import com.alibaba.nacos.config.server.service.DynamicDataSource;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.CannotGetJdbcConnectionException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@ -128,9 +127,6 @@ public class GroupCapacityPersistService {
|
||||
GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();
|
||||
PreparedStatementCreator preparedStatementCreator = new PreparedStatementCreator() {
|
||||
@Override
|
||||
@SuppressFBWarnings(value = {"OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE",
|
||||
"SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING"},
|
||||
justification = "findbugs does not trust jdbctemplate, sql is constant in practice")
|
||||
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
|
||||
PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
String group = capacity.getGroup();
|
||||
@ -306,9 +302,6 @@ public class GroupCapacityPersistService {
|
||||
try {
|
||||
PreparedStatementCreator preparedStatementCreator = new PreparedStatementCreator() {
|
||||
@Override
|
||||
@SuppressFBWarnings(value = {"OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE",
|
||||
"SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING"},
|
||||
justification = "findbugs does not trust jdbctemplate, sql is constant in practice")
|
||||
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
|
||||
PreparedStatement ps = connection.prepareStatement(
|
||||
"DELETE FROM group_capacity WHERE group_id = ?;");
|
||||
|
@ -21,7 +21,6 @@ import com.alibaba.nacos.config.server.service.DynamicDataSource;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.CannotGetJdbcConnectionException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@ -96,9 +95,6 @@ public class TenantCapacityPersistService {
|
||||
GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();
|
||||
PreparedStatementCreator preparedStatementCreator = new PreparedStatementCreator() {
|
||||
@Override
|
||||
@SuppressFBWarnings(value = {"OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE",
|
||||
"SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING"},
|
||||
justification = "findbugs does not trust jdbctemplate, sql is constant in practice")
|
||||
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
|
||||
PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
String tenant = tenantCapacity.getTenant();
|
||||
@ -257,9 +253,6 @@ public class TenantCapacityPersistService {
|
||||
try {
|
||||
PreparedStatementCreator preparedStatementCreator = new PreparedStatementCreator() {
|
||||
@Override
|
||||
@SuppressFBWarnings(value = {"OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE",
|
||||
"SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING"},
|
||||
justification = "findbugs does not trust jdbctemplate, sql is constant in practice")
|
||||
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
|
||||
PreparedStatement ps = connection.prepareStatement(
|
||||
"DELETE FROM tenant_capacity WHERE tenant_id = ?;");
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>nacos-console</artifactId>
|
||||
<!--<packaging>war</packaging>-->
|
||||
|
@ -65,7 +65,7 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
||||
# default current work dir
|
||||
server.tomcat.basedir=
|
||||
|
||||
nacos.naming.distro.taskDispatchThreadCount=10
|
||||
nacos.naming.distro.taskDispatchThreadCount=1
|
||||
nacos.naming.distro.taskDispatchPeriod=200
|
||||
nacos.naming.distro.batchSyncKeyCount=1000
|
||||
nacos.naming.distro.initDataRatio=0.9
|
||||
|
@ -161,7 +161,7 @@ module.exports = {
|
||||
'com.alibaba.nacos.page.newconfig.the_more_advanced': 'Group不能为空',
|
||||
'nacos.page.namespace.ACM_special_SecretKey_will_be_abandoned,_not_recommended_for_use4':
|
||||
'ACM专用SecretKey(即将废弃,不建议使用):',
|
||||
'com.alibaba.nacos.page.namespace.public': 'public(保留控件)',
|
||||
'com.alibaba.nacos.page.namespace.public': 'public(保留空间)',
|
||||
'com.alibaba.nacos.page.configsync.error': '错误',
|
||||
'nacos.page.namespace.AccessKey_recommended1': 'AccessKey(开发环境推荐):',
|
||||
'com.alibaba.nacos.page.pushTrajectory.configuration': '配置',
|
||||
|
@ -64,7 +64,7 @@ const I18N_CONF = {
|
||||
namespaceDelete: '删除',
|
||||
details: '详情',
|
||||
edit: '编辑',
|
||||
namespacePublic: 'public(保留控件)',
|
||||
namespacePublic: 'public(保留空间)',
|
||||
pubNoData: '没有数据',
|
||||
namespaceAdd: '新建命名空间',
|
||||
namespaceNames: '命名空间名称',
|
||||
|
@ -20,15 +20,17 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Nacos</title>
|
||||
|
||||
<link rel="shortcut icon" href="//www.aliyun.com/favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/console1412.css">
|
||||
<link rel="shortcut icon" href="//www.aliyun.com/favicon.ico" type="image/x-icon">
|
||||
<link rel="stylesheet" type="text/css" href="console-fe/public/css/bootstrap.css">
|
||||
<link rel="stylesheet" type="text/css" href="console-fe/public/css/console1412.css">
|
||||
<!-- 第三方css开始 -->
|
||||
<link rel="stylesheet" type="text/css" href="css/codemirror.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/merge.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/icon.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/font-awesome.css">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="console-fe/public/css/codemirror.css">
|
||||
<link rel="stylesheet" type="text/css" href="console-fe/public/css/merge.css">
|
||||
<link rel="stylesheet" type="text/css" href="console-fe/public/css/icon.css">
|
||||
<link rel="stylesheet" type="text/css" href="console-fe/public/css/font-awesome.css">
|
||||
<!-- 第三方css结束 -->
|
||||
<link href="css/main.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -37,18 +39,18 @@
|
||||
<div id="other"></div>
|
||||
|
||||
<!-- 第三方js开始 -->
|
||||
<script src="js/jquery.js"></script>
|
||||
<script src="js/codemirror.js"></script>
|
||||
<script src="js/javascript.js"></script>
|
||||
<script src="js/xml.js"></script>
|
||||
<script src="js/codemirror.addone.fullscreen.js"></script>
|
||||
<script src="js/codemirror.addone.lint.js"></script>
|
||||
<script src="js/codemirror.lib.json-lint.js"></script>
|
||||
<script src="js/codemirror.addone.json-lint.js"></script>
|
||||
<script src="js/codemirror.lib.clike-lint.js"></script>
|
||||
<script src="js/diff_match_patch.js"></script>
|
||||
<script src="js/merge.js"></script>
|
||||
<script src="js/loader.js"></script>
|
||||
<script src="console-fe/public/js/jquery.js"></script>
|
||||
<script src="console-fe/public/js/codemirror.js"></script>
|
||||
<script src="console-fe/public/js/javascript.js"></script>
|
||||
<script src="console-fe/public/js/xml.js"></script>
|
||||
<script src="console-fe/public/js/codemirror.addone.fullscreen.js"></script>
|
||||
<script src="console-fe/public/js/codemirror.addone.lint.js"></script>
|
||||
<script src="console-fe/public/js/codemirror.lib.json-lint.js"></script>
|
||||
<script src="console-fe/public/js/codemirror.addone.json-lint.js"></script>
|
||||
<script src="console-fe/public/js/codemirror.lib.clike-lint.js"></script>
|
||||
<script src="console-fe/public/js/diff_match_patch.js"></script>
|
||||
<script src="console-fe/public/js/merge.js"></script>
|
||||
<script src="console-fe/public/js/loader.js"></script>
|
||||
|
||||
<!-- 第三方js结束 -->
|
||||
<script type="text/javascript" src="js/main.js"></script></body>
|
||||
|
File diff suppressed because one or more lines are too long
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.alibaba.nacos.core.utils;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -34,8 +35,8 @@ public class PropertyUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(PropertyUtil.class);
|
||||
|
||||
static {
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
InputStream inputStream = null;
|
||||
String baseDir = System.getProperty("nacos.home");
|
||||
if (!StringUtils.isBlank(baseDir)) {
|
||||
inputStream = new FileInputStream(baseDir + "/conf/application.properties");
|
||||
@ -46,6 +47,8 @@ public class PropertyUtil {
|
||||
properties.load(inputStream);
|
||||
} catch (Exception e) {
|
||||
log.error("read property file error:" + e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,7 @@ 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.io.*;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -59,8 +56,7 @@ public class SystemUtils {
|
||||
public static final String FUNCTION_MODE_NAMING = "naming";
|
||||
|
||||
|
||||
|
||||
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean)ManagementFactory
|
||||
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory
|
||||
.getOperatingSystemMXBean();
|
||||
|
||||
/**
|
||||
@ -98,15 +94,15 @@ public class SystemUtils {
|
||||
}
|
||||
|
||||
public static float getLoad() {
|
||||
return (float)operatingSystemMXBean.getSystemLoadAverage();
|
||||
return (float) operatingSystemMXBean.getSystemLoadAverage();
|
||||
}
|
||||
|
||||
public static float getCPU() {
|
||||
return (float)operatingSystemMXBean.getSystemCpuLoad();
|
||||
return (float) operatingSystemMXBean.getSystemCpuLoad();
|
||||
}
|
||||
|
||||
public static float getMem() {
|
||||
return (float)(1 - (double)operatingSystemMXBean.getFreePhysicalMemorySize() / (double)operatingSystemMXBean
|
||||
return (float) (1 - (double) operatingSystemMXBean.getFreePhysicalMemorySize() / (double) operatingSystemMXBean
|
||||
.getTotalPhysicalMemorySize());
|
||||
}
|
||||
|
||||
@ -128,23 +124,31 @@ public class SystemUtils {
|
||||
|
||||
public static List<String> readClusterConf() throws IOException {
|
||||
List<String> instanceList = new ArrayList<String>();
|
||||
List<String> lines = IoUtils.readLines(
|
||||
new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)), UTF_8));
|
||||
String comment = "#";
|
||||
for (String line : lines) {
|
||||
String instance = line.trim();
|
||||
if (instance.startsWith(comment)) {
|
||||
// # it is ip
|
||||
continue;
|
||||
Reader reader = null;
|
||||
|
||||
try {
|
||||
reader = new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)), UTF_8);
|
||||
List<String> lines = IoUtils.readLines(reader);
|
||||
String comment = "#";
|
||||
for (String line : lines) {
|
||||
String instance = line.trim();
|
||||
if (instance.startsWith(comment)) {
|
||||
// # it is ip
|
||||
continue;
|
||||
}
|
||||
if (instance.contains(comment)) {
|
||||
// 192.168.71.52:8848 # Instance A
|
||||
instance = instance.substring(0, instance.indexOf(comment));
|
||||
instance = instance.trim();
|
||||
}
|
||||
instanceList.add(instance);
|
||||
}
|
||||
if (instance.contains(comment)) {
|
||||
// 192.168.71.52:8848 # Instance A
|
||||
instance = instance.substring(0, instance.indexOf(comment));
|
||||
instance = instance.trim();
|
||||
return instanceList;
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
instanceList.add(instance);
|
||||
}
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
public static void writeClusterConf(String content) throws IOException {
|
||||
|
@ -101,7 +101,6 @@ else
|
||||
JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
|
||||
fi
|
||||
|
||||
JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000"
|
||||
JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}"
|
||||
JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/nacos-server.jar"
|
||||
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
|
||||
|
@ -26,7 +26,7 @@ management.metrics.export.influx.enabled=false
|
||||
#management.metrics.export.influx.compressed=true
|
||||
|
||||
server.tomcat.accesslog.enabled=true
|
||||
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
||||
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
|
||||
# default current work dir
|
||||
server.tomcat.basedir=
|
||||
|
||||
@ -39,7 +39,7 @@ server.tomcat.basedir=
|
||||
|
||||
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
|
||||
|
||||
nacos.naming.distro.taskDispatchThreadCount=10
|
||||
nacos.naming.distro.taskDispatchThreadCount=1
|
||||
nacos.naming.distro.taskDispatchPeriod=200
|
||||
nacos.naming.distro.batchSyncKeyCount=1000
|
||||
nacos.naming.distro.initDataRatio=0.9
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -150,10 +150,6 @@
|
||||
<artifactId>jul-to-slf4j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-cmdb</artifactId>
|
||||
|
@ -17,7 +17,6 @@ package com.alibaba.nacos.naming.boot;
|
||||
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
@ -39,7 +38,6 @@ public class RunningConfig implements ApplicationListener<WebServerInitializedEv
|
||||
@Autowired
|
||||
private ServletContext servletContext;
|
||||
|
||||
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
|
||||
@Override
|
||||
public void onApplicationEvent(WebServerInitializedEvent event) {
|
||||
|
||||
|
@ -100,7 +100,9 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService
|
||||
|
||||
public volatile Notifier notifier = new Notifier();
|
||||
|
||||
private volatile Map<String, CopyOnWriteArrayList<RecordListener>> listeners = new ConcurrentHashMap<>();
|
||||
private Map<String, CopyOnWriteArrayList<RecordListener>> listeners = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<String, String> syncChecksumTasks = new ConcurrentHashMap<>(16);
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws Exception {
|
||||
@ -185,53 +187,69 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService
|
||||
return;
|
||||
}
|
||||
|
||||
listeners.remove(key);
|
||||
|
||||
notifier.addTask(key, ApplyAction.DELETE);
|
||||
}
|
||||
|
||||
public void onReceiveChecksums(Map<String, String> checksumMap, String server) {
|
||||
|
||||
List<String> toUpdateKeys = new ArrayList<>();
|
||||
List<String> toRemoveKeys = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : checksumMap.entrySet()) {
|
||||
if (distroMapper.responsible(KeyBuilder.getServiceName(entry.getKey()))) {
|
||||
// this key should not be sent from remote server:
|
||||
Loggers.EPHEMERAL.error("receive responsible key timestamp of " + entry.getKey() + " from " + server);
|
||||
// abort the procedure:
|
||||
return;
|
||||
}
|
||||
if (!dataStore.contains(entry.getKey()) ||
|
||||
dataStore.get(entry.getKey()).value == null ||
|
||||
!dataStore.get(entry.getKey()).value.getChecksum().equals(entry.getValue())) {
|
||||
toUpdateKeys.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for (String key : dataStore.keys()) {
|
||||
|
||||
if (!server.equals(distroMapper.mapSrv(KeyBuilder.getServiceName(key)))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!checksumMap.containsKey(key)) {
|
||||
toRemoveKeys.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
Loggers.EPHEMERAL.info("to remove keys: {}, to update keys: {}, source: {}", toRemoveKeys, toUpdateKeys, server);
|
||||
|
||||
for (String key : toRemoveKeys) {
|
||||
onRemove(key);
|
||||
}
|
||||
|
||||
if (toUpdateKeys.isEmpty()) {
|
||||
if (syncChecksumTasks.containsKey(server)) {
|
||||
// Already in process of this server:
|
||||
Loggers.EPHEMERAL.warn("sync checksum task already in process with {}", server);
|
||||
return;
|
||||
}
|
||||
|
||||
syncChecksumTasks.put(server, "1");
|
||||
|
||||
try {
|
||||
byte[] result = NamingProxy.getData(toUpdateKeys, server);
|
||||
processData(result);
|
||||
} catch (Exception e) {
|
||||
Loggers.EPHEMERAL.error("get data from " + server + " failed!", e);
|
||||
|
||||
List<String> toUpdateKeys = new ArrayList<>();
|
||||
List<String> toRemoveKeys = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : checksumMap.entrySet()) {
|
||||
if (distroMapper.responsible(KeyBuilder.getServiceName(entry.getKey()))) {
|
||||
// this key should not be sent from remote server:
|
||||
Loggers.EPHEMERAL.error("receive responsible key timestamp of " + entry.getKey() + " from " + server);
|
||||
// abort the procedure:
|
||||
return;
|
||||
}
|
||||
if (!dataStore.contains(entry.getKey()) ||
|
||||
dataStore.get(entry.getKey()).value == null ||
|
||||
!dataStore.get(entry.getKey()).value.getChecksum().equals(entry.getValue())) {
|
||||
toUpdateKeys.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for (String key : dataStore.keys()) {
|
||||
|
||||
if (!server.equals(distroMapper.mapSrv(KeyBuilder.getServiceName(key)))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!checksumMap.containsKey(key)) {
|
||||
toRemoveKeys.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
Loggers.EPHEMERAL.info("to remove keys: {}, to update keys: {}, source: {}", toRemoveKeys, toUpdateKeys, server);
|
||||
|
||||
for (String key : toRemoveKeys) {
|
||||
onRemove(key);
|
||||
}
|
||||
|
||||
if (toUpdateKeys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] result = NamingProxy.getData(toUpdateKeys, server);
|
||||
processData(result);
|
||||
} catch (Exception e) {
|
||||
Loggers.EPHEMERAL.error("get data from " + server + " failed!", e);
|
||||
}
|
||||
} finally {
|
||||
// Remove this 'in process' flag:
|
||||
syncChecksumTasks.remove(server);
|
||||
}
|
||||
|
||||
}
|
||||
@ -259,8 +277,9 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService
|
||||
|
||||
if (!listeners.containsKey(entry.getKey())) {
|
||||
// pretty sure the service not exist:
|
||||
if (ServerMode.AP.name().equals(switchDomain.getServerMode())) {
|
||||
if (switchDomain.isDefaultInstanceEphemeral()) {
|
||||
// create empty service
|
||||
Loggers.EPHEMERAL.info("creating service {}", entry.getKey());
|
||||
Service service = new Service();
|
||||
String serviceName = KeyBuilder.getServiceName(entry.getKey());
|
||||
String namespaceId = KeyBuilder.getNamespace(entry.getKey());
|
||||
@ -277,19 +296,24 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Datum<Instances>> entry : datumMap.entrySet()) {
|
||||
dataStore.put(entry.getKey(), entry.getValue());
|
||||
|
||||
if (!listeners.containsKey(entry.getKey())) {
|
||||
Loggers.EPHEMERAL.warn("listener not found: {}", entry.getKey());
|
||||
// Should not happen:
|
||||
Loggers.EPHEMERAL.warn("listener of {} not found.", entry.getKey());
|
||||
continue;
|
||||
}
|
||||
for (RecordListener listener : listeners.get(entry.getKey())) {
|
||||
try {
|
||||
|
||||
try {
|
||||
for (RecordListener listener : listeners.get(entry.getKey())) {
|
||||
listener.onChange(entry.getKey(), entry.getValue().value);
|
||||
} catch (Exception e) {
|
||||
Loggers.EPHEMERAL.error("notify " + listener + ", key: " + entry.getKey() + " failed.", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Loggers.EPHEMERAL.error("[NACOS-DISTRO] error while execute listener of key: {}", entry.getKey(), e);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Update data store if listener executed successfully:
|
||||
dataStore.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -384,12 +408,13 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService
|
||||
continue;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Loggers.EPHEMERAL.error("[NACOS-DISTRO] error while notifying listener of key: {} {}", datumKey, e);
|
||||
Loggers.EPHEMERAL.error("[NACOS-DISTRO] error while notifying listener of key: {}", datumKey, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (Loggers.EPHEMERAL.isDebugEnabled()) {
|
||||
Loggers.EPHEMERAL.debug("[NACOS-DISTRO] datum change notified, key: {}, listener count: {}", datumKey, count);
|
||||
Loggers.EPHEMERAL.debug("[NACOS-DISTRO] datum change notified, key: {}, listener count: {}, action: {}",
|
||||
datumKey, count, action.name());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Loggers.EPHEMERAL.error("[NACOS-DISTRO] Error while handling notifying task", e);
|
||||
|
@ -17,10 +17,7 @@ package com.alibaba.nacos.naming.consistency.ephemeral.distro;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.naming.cluster.servers.Server;
|
||||
import com.alibaba.nacos.naming.misc.GlobalConfig;
|
||||
import com.alibaba.nacos.naming.misc.GlobalExecutor;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.NetUtils;
|
||||
import com.alibaba.nacos.naming.misc.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -51,6 +48,13 @@ public class TaskDispatcher {
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
if (partitionConfig.getTaskDispatchThreadCount() > Runtime.getRuntime().availableProcessors()) {
|
||||
Loggers.EPHEMERAL.error("should not larger than {}, current is: {}",
|
||||
Runtime.getRuntime().availableProcessors(), partitionConfig.getTaskDispatchThreadCount());
|
||||
throw new RuntimeException("task dispatch thread count is too large!");
|
||||
}
|
||||
|
||||
for (int i = 0; i < partitionConfig.getTaskDispatchThreadCount(); i++) {
|
||||
TaskScheduler taskScheduler = new TaskScheduler(i);
|
||||
taskSchedulerList.add(taskScheduler);
|
||||
@ -58,12 +62,8 @@ public class TaskDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
public int mapTask(String key) {
|
||||
return Math.abs(key.hashCode()) % partitionConfig.getTaskDispatchThreadCount();
|
||||
}
|
||||
|
||||
public void addTask(String key) {
|
||||
taskSchedulerList.get(mapTask(key)).addTask(key);
|
||||
taskSchedulerList.get(UtilsAndCommons.shakeUp(key, partitionConfig.getTaskDispatchThreadCount())).addTask(key);
|
||||
}
|
||||
|
||||
public class TaskScheduler implements Runnable {
|
||||
@ -107,14 +107,16 @@ public class TaskDispatcher {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dataSize == 0) {
|
||||
keys = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(key)) {
|
||||
keys.add(key);
|
||||
dataSize++;
|
||||
}
|
||||
keys.add(key);
|
||||
dataSize++;
|
||||
|
||||
if (dataSize == partitionConfig.getBatchSyncKeyCount() ||
|
||||
(System.currentTimeMillis() - lastDispatchTime) > partitionConfig.getTaskDispatchPeriod()) {
|
||||
|
@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.consistency.persistent.raft;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.cluster.ServerStatus;
|
||||
import com.alibaba.nacos.naming.consistency.Datum;
|
||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||
import com.alibaba.nacos.naming.consistency.RecordListener;
|
||||
import com.alibaba.nacos.naming.consistency.persistent.PersistentConsistencyService;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
@ -38,6 +39,9 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
|
||||
@Autowired
|
||||
private RaftCore raftCore;
|
||||
|
||||
@Autowired
|
||||
private RaftPeerSet peers;
|
||||
|
||||
@Autowired
|
||||
private SwitchDomain switchDomain;
|
||||
|
||||
@ -54,7 +58,15 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
|
||||
@Override
|
||||
public void remove(String key) throws NacosException {
|
||||
try {
|
||||
if (KeyBuilder.matchInstanceListKey(key) && !raftCore.isLeader()) {
|
||||
Datum datum = new Datum();
|
||||
datum.key = key;
|
||||
raftCore.onDelete(datum.key, peers.getLeader());
|
||||
raftCore.unlistenAll(key);
|
||||
return;
|
||||
}
|
||||
raftCore.signalDelete(key);
|
||||
raftCore.unlistenAll(key);
|
||||
} catch (Exception e) {
|
||||
Loggers.RAFT.error("Raft remove failed.", e);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft remove failed, key:" + key);
|
||||
@ -92,7 +104,7 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
|
||||
|
||||
public void onRemove(Datum datum, RaftPeer source) throws NacosException {
|
||||
try {
|
||||
raftCore.onDelete(datum, source);
|
||||
raftCore.onDelete(datum.key, source);
|
||||
} catch (Exception e) {
|
||||
Loggers.RAFT.error("Raft onRemove failed.", e);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft onRemove failed, datum:" + datum + ", source: " + source);
|
||||
|
@ -213,7 +213,7 @@ public class RaftCore {
|
||||
|
||||
if (!latch.await(UtilsAndCommons.RAFT_PUBLISH_TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||
// only majority servers return success can we consider this update success
|
||||
Loggers.RAFT.info("data publish failed, caused failed to notify majority, key={}", key);
|
||||
Loggers.RAFT.error("data publish failed, caused failed to notify majority, key={}", key);
|
||||
throw new IllegalStateException("data publish failed, caused failed to notify majority, key=" + key);
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ public class RaftCore {
|
||||
json.put("datum", datum);
|
||||
json.put("source", peers.local());
|
||||
|
||||
onDelete(datum, peers.local());
|
||||
onDelete(datum.key, peers.local());
|
||||
|
||||
for (final String server : peers.allServersWithoutMySelf()) {
|
||||
String url = buildURL(server, API_ON_DEL);
|
||||
@ -317,7 +317,7 @@ public class RaftCore {
|
||||
Loggers.RAFT.info("data added/updated, key={}, term={}", datum.key, local.term);
|
||||
}
|
||||
|
||||
public void onDelete(Datum datum, RaftPeer source) throws Exception {
|
||||
public void onDelete(String datumKey, RaftPeer source) throws Exception {
|
||||
|
||||
RaftPeer local = peers.local();
|
||||
|
||||
@ -337,7 +337,7 @@ public class RaftCore {
|
||||
local.resetLeaderDue();
|
||||
|
||||
// do apply
|
||||
String key = datum.key;
|
||||
String key = datumKey;
|
||||
deleteDatum(key);
|
||||
|
||||
if (KeyBuilder.matchServiceMetaKey(key)) {
|
||||
@ -353,7 +353,7 @@ public class RaftCore {
|
||||
raftStore.updateTerm(local.term.get());
|
||||
}
|
||||
|
||||
Loggers.RAFT.info("data removed, key={}, term={}", datum.key, local.term);
|
||||
Loggers.RAFT.info("data removed, key={}, term={}", datumKey, local.term);
|
||||
|
||||
}
|
||||
|
||||
@ -667,41 +667,49 @@ public class RaftCore {
|
||||
return 1;
|
||||
}
|
||||
|
||||
List<Datum> datumList = JSON.parseObject(response.getResponseBody(), new TypeReference<List<Datum>>() {
|
||||
List<JSONObject> datumList = JSON.parseObject(response.getResponseBody(), new TypeReference<List<JSONObject>>() {
|
||||
});
|
||||
|
||||
for (Datum datum : datumList) {
|
||||
for (JSONObject datumJson : datumList) {
|
||||
OPERATE_LOCK.lock();
|
||||
Datum newDatum = null;
|
||||
try {
|
||||
|
||||
Datum oldDatum = getDatum(datum.key);
|
||||
Datum oldDatum = getDatum(datumJson.getString("key"));
|
||||
|
||||
if (oldDatum != null && datum.timestamp.get() <= oldDatum.timestamp.get()) {
|
||||
if (oldDatum != null && datumJson.getLongValue("timestamp") <= oldDatum.timestamp.get()) {
|
||||
Loggers.RAFT.info("[NACOS-RAFT] timestamp is smaller than that of mine, key: {}, remote: {}, local: {}",
|
||||
datum.key, datum.timestamp, oldDatum.timestamp);
|
||||
datumJson.getString("key"), datumJson.getLongValue("timestamp"), oldDatum.timestamp);
|
||||
continue;
|
||||
}
|
||||
|
||||
raftStore.write(datum);
|
||||
|
||||
if (KeyBuilder.matchServiceMetaKey(datum.key)) {
|
||||
if (KeyBuilder.matchServiceMetaKey(datumJson.getString("key"))) {
|
||||
Datum<Service> serviceDatum = new Datum<>();
|
||||
serviceDatum.key = datum.key;
|
||||
serviceDatum.timestamp.set(datum.timestamp.get());
|
||||
serviceDatum.value = JSON.parseObject(JSON.toJSONString(datum.value), Service.class);
|
||||
datum = serviceDatum;
|
||||
serviceDatum.key = datumJson.getString("key");
|
||||
serviceDatum.timestamp.set(datumJson.getLongValue("timestamp"));
|
||||
serviceDatum.value =
|
||||
JSON.parseObject(JSON.toJSONString(datumJson.getJSONObject("value")), Service.class);
|
||||
newDatum = serviceDatum;
|
||||
}
|
||||
|
||||
if (KeyBuilder.matchInstanceListKey(datum.key)) {
|
||||
if (KeyBuilder.matchInstanceListKey(datumJson.getString("key"))) {
|
||||
Datum<Instances> instancesDatum = new Datum<>();
|
||||
instancesDatum.key = datum.key;
|
||||
instancesDatum.timestamp.set(datum.timestamp.get());
|
||||
instancesDatum.value = JSON.parseObject(JSON.toJSONString(datum.value), Instances.class);
|
||||
datum = instancesDatum;
|
||||
instancesDatum.key = datumJson.getString("key");
|
||||
instancesDatum.timestamp.set(datumJson.getLongValue("timestamp"));
|
||||
instancesDatum.value =
|
||||
JSON.parseObject(JSON.toJSONString(datumJson.getJSONObject("value")), Instances.class);
|
||||
newDatum = instancesDatum;
|
||||
}
|
||||
|
||||
datums.put(datum.key, datum);
|
||||
notifier.addTask(datum.key, ApplyAction.CHANGE);
|
||||
if (newDatum == null || newDatum.value == null) {
|
||||
Loggers.RAFT.error("receive null datum: {}", datumJson);
|
||||
continue;
|
||||
}
|
||||
|
||||
raftStore.write(newDatum);
|
||||
|
||||
datums.put(newDatum.key, newDatum);
|
||||
notifier.addTask(newDatum.key, ApplyAction.CHANGE);
|
||||
|
||||
local.resetLeaderDue();
|
||||
|
||||
@ -715,10 +723,10 @@ public class RaftCore {
|
||||
raftStore.updateTerm(local.term.get());
|
||||
|
||||
Loggers.RAFT.info("data updated, key: {}, timestamp: {}, from {}, local term: {}",
|
||||
datum.key, datum.timestamp, JSON.toJSONString(remote), local.term);
|
||||
newDatum.key, newDatum.timestamp, JSON.toJSONString(remote), local.term);
|
||||
|
||||
} catch (Throwable e) {
|
||||
Loggers.RAFT.error("[RAFT-BEAT] failed to sync datum from leader, key: {} {}", datum.key, e);
|
||||
Loggers.RAFT.error("[RAFT-BEAT] failed to sync datum from leader, datum: {}", newDatum, e);
|
||||
} finally {
|
||||
OPERATE_LOCK.unlock();
|
||||
}
|
||||
@ -801,6 +809,10 @@ public class RaftCore {
|
||||
}
|
||||
}
|
||||
|
||||
public void unlistenAll(String key) {
|
||||
listeners.remove(key);
|
||||
}
|
||||
|
||||
public void setTerm(long term) {
|
||||
peers.setTerm(term);
|
||||
}
|
||||
@ -863,7 +875,6 @@ public class RaftCore {
|
||||
}
|
||||
|
||||
private void deleteDatum(String key) {
|
||||
|
||||
Datum deleted;
|
||||
try {
|
||||
deleted = datums.remove(URLDecoder.decode(key, "UTF-8"));
|
||||
@ -881,6 +892,10 @@ public class RaftCore {
|
||||
return initialized || !globalConfig.isDataWarmup();
|
||||
}
|
||||
|
||||
public int getNotifyTaskCount() {
|
||||
return notifier.getTaskSize();
|
||||
}
|
||||
|
||||
public class Notifier implements Runnable {
|
||||
|
||||
private ConcurrentHashMap<String, String> services = new ConcurrentHashMap<>(10 * 1024);
|
||||
@ -895,6 +910,9 @@ public class RaftCore {
|
||||
if (action == ApplyAction.CHANGE) {
|
||||
services.put(datumKey, StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
Loggers.RAFT.info("add task {}", datumKey);
|
||||
|
||||
tasks.add(Pair.with(datumKey, action));
|
||||
}
|
||||
|
||||
@ -920,6 +938,8 @@ public class RaftCore {
|
||||
|
||||
services.remove(datumKey);
|
||||
|
||||
Loggers.RAFT.info("remove task {}", datumKey);
|
||||
|
||||
int count = 0;
|
||||
|
||||
if (listeners.containsKey(KeyBuilder.SERVICE_META_KEY_PREFIX)) {
|
||||
@ -936,7 +956,7 @@ public class RaftCore {
|
||||
listener.onDelete(datumKey);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Loggers.RAFT.error("[NACOS-RAFT] error while notifying listener of key: {} {}", datumKey, e);
|
||||
Loggers.RAFT.error("[NACOS-RAFT] error while notifying listener of key: {}", datumKey, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -961,7 +981,7 @@ public class RaftCore {
|
||||
continue;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Loggers.RAFT.error("[NACOS-RAFT] error while notifying listener of key: {} {}", datumKey, e);
|
||||
Loggers.RAFT.error("[NACOS-RAFT] error while notifying listener of key: {}", datumKey, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.naming.consistency.ApplyAction;
|
||||
import com.alibaba.nacos.naming.consistency.Datum;
|
||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||
import com.alibaba.nacos.naming.core.Instance;
|
||||
import com.alibaba.nacos.naming.core.Instances;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
@ -37,6 +38,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -157,8 +159,34 @@ public class RaftStore {
|
||||
}
|
||||
|
||||
if (KeyBuilder.matchInstanceListKey(file.getName())) {
|
||||
return JSON.parseObject(json, new TypeReference<Datum<Instances>>() {
|
||||
});
|
||||
|
||||
Datum<Instances> instancesDatum;
|
||||
|
||||
try {
|
||||
instancesDatum = JSON.parseObject(json, new TypeReference<Datum<Instances>>() {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
JSONObject jsonObject = JSON.parseObject(json);
|
||||
instancesDatum = new Datum<>();
|
||||
instancesDatum.timestamp.set(jsonObject.getLongValue("timestamp"));
|
||||
|
||||
String key = jsonObject.getString("key");
|
||||
String serviceName = KeyBuilder.getServiceName(key);
|
||||
key = key.substring(0, key.indexOf(serviceName)) +
|
||||
Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName;
|
||||
|
||||
instancesDatum.key = key;
|
||||
instancesDatum.value = new Instances();
|
||||
instancesDatum.value.setInstanceList(JSON.parseObject(jsonObject.getString("value"),
|
||||
new TypeReference<List<Instance>>(){}));
|
||||
if (!instancesDatum.value.getInstanceList().isEmpty()) {
|
||||
for (Instance instance : instancesDatum.value.getInstanceList()) {
|
||||
instance.setEphemeral(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return instancesDatum;
|
||||
}
|
||||
|
||||
return JSON.parseObject(json, Datum.class);
|
||||
@ -208,6 +236,21 @@ public class RaftStore {
|
||||
fc.close();
|
||||
}
|
||||
}
|
||||
|
||||
// remove old format file:
|
||||
if (StringUtils.isNoneBlank(namespaceId)) {
|
||||
if (datum.key.contains(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER)) {
|
||||
String oldFormatKey =
|
||||
datum.key.replace(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER, StringUtils.EMPTY);
|
||||
|
||||
cacheFile = new File(cacheDir + File.separator + namespaceId + File.separator + encodeFileName(oldFormatKey));
|
||||
if (cacheFile.exists() && !cacheFile.delete()) {
|
||||
Loggers.RAFT.error("[RAFT-DELETE] failed to delete old format datum: {}, value: {}",
|
||||
datum.key, datum.value);
|
||||
throw new IllegalStateException("failed to delete old format datum: " + datum.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File[] listCaches() throws Exception {
|
||||
|
@ -24,6 +24,7 @@ import com.alibaba.nacos.naming.core.DistroMapper;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.push.ClientInfo;
|
||||
import com.alibaba.nacos.naming.web.CanDistro;
|
||||
import com.alibaba.nacos.naming.web.OverrideParameterRequestWrapper;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -138,6 +139,7 @@ public class ApiController extends InstanceController {
|
||||
agent, clusters, clientIP, udpPort, env, isCheck, app, tenant, healthyOnly);
|
||||
}
|
||||
|
||||
@CanDistro
|
||||
@RequestMapping("/clientBeat")
|
||||
public JSONObject clientBeat(HttpServletRequest request) throws Exception {
|
||||
OverrideParameterRequestWrapper requestWrapper = OverrideParameterRequestWrapper.buildRequest(request);
|
||||
|
@ -69,6 +69,7 @@ public class ClusterController {
|
||||
Loggers.SRV_LOG.warn("[UPDATE-CLUSTER] cluster not exist, will create it: {}, service: {}", clusterName, serviceName);
|
||||
cluster = new Cluster();
|
||||
cluster.setName(clusterName);
|
||||
cluster.setService(service);
|
||||
}
|
||||
|
||||
cluster.setDefCkport(NumberUtils.toInt(checkPort));
|
||||
@ -96,9 +97,8 @@ public class ClusterController {
|
||||
|
||||
cluster.setHealthChecker(abstractHealthChecker);
|
||||
cluster.setMetadata(UtilsAndCommons.parseMetadata(metadata));
|
||||
|
||||
cluster.init();
|
||||
service.getClusterMap().put(clusterName, cluster);
|
||||
|
||||
service.setLastModifiedMillis(System.currentTimeMillis());
|
||||
service.recalculateChecksum();
|
||||
service.validate();
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.controllers;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.nacos.core.utils.WebUtils;
|
||||
import com.alibaba.nacos.naming.cluster.ServerMode;
|
||||
@ -84,8 +85,8 @@ public class DistroController {
|
||||
String namespaceId = KeyBuilder.getNamespace(entry.getKey());
|
||||
String serviceName = KeyBuilder.getServiceName(entry.getKey());
|
||||
if (!serviceManager.containService(namespaceId, serviceName)
|
||||
&& ServerMode.AP.name().equals(switchDomain.getServerMode())) {
|
||||
serviceManager.createEmptyService(namespaceId, serviceName);
|
||||
&& switchDomain.isDefaultInstanceEphemeral()) {
|
||||
serviceManager.createEmptyService(namespaceId, serviceName, true);
|
||||
}
|
||||
consistencyService.onPut(entry.getKey(), entry.getValue().value);
|
||||
}
|
||||
@ -106,7 +107,9 @@ public class DistroController {
|
||||
|
||||
@RequestMapping(value = "/datum", method = RequestMethod.GET)
|
||||
public void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
String keys = WebUtils.required(request, "keys");
|
||||
|
||||
String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
|
||||
String keys = JSON.parseObject(entity).getString("keys");
|
||||
String keySplitter = ",";
|
||||
Map<String, Datum> datumMap = new HashMap<>(64);
|
||||
for (String key : keys.split(keySplitter)) {
|
||||
|
@ -25,20 +25,18 @@ import com.alibaba.nacos.naming.core.Instance;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckType;
|
||||
import com.alibaba.nacos.naming.misc.HttpClient;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.push.PushService;
|
||||
import com.alibaba.nacos.naming.web.CanDistro;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Health status related operation controller
|
||||
@ -68,57 +66,48 @@ public class HealthController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@CanDistro
|
||||
@RequestMapping(value = {"", "/instance"}, method = RequestMethod.PUT)
|
||||
public String update(HttpServletRequest request) throws Exception {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
String ip = WebUtils.required(request, "ip");
|
||||
int port = Integer.parseInt(WebUtils.required(request, "port"));
|
||||
boolean valid = Boolean.valueOf(WebUtils.required(request, "valid"));
|
||||
String clusterName = WebUtils.optional(request, CommonParams.CLUSTER_NAME
|
||||
, UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
|
||||
if (!distroMapper.responsible(serviceName)) {
|
||||
String server = distroMapper.mapSrv(serviceName);
|
||||
Loggers.EVT_LOG.info("I'm not responsible for " + serviceName + ", proxy it to " + server);
|
||||
Map<String, String> proxyParams = new HashMap<>(16);
|
||||
for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue()[0];
|
||||
proxyParams.put(key, value);
|
||||
}
|
||||
String ip = WebUtils.required(request, "ip");
|
||||
int port = Integer.parseInt(WebUtils.required(request, "port"));
|
||||
|
||||
if (!server.contains(UtilsAndCommons.IP_PORT_SPLITER)) {
|
||||
server = server + UtilsAndCommons.IP_PORT_SPLITER + RunningConfig.getServerPort();
|
||||
}
|
||||
boolean valid = false;
|
||||
|
||||
String url = "http://" + server + RunningConfig.getContextPath()
|
||||
+ UtilsAndCommons.NACOS_NAMING_CONTEXT + "/health";
|
||||
HttpClient.HttpResult httpResult = HttpClient.httpPost(url, null, proxyParams);
|
||||
String healthyString = WebUtils.optional(request, "healthy", StringUtils.EMPTY);
|
||||
if (StringUtils.isBlank(healthyString)) {
|
||||
healthyString = WebUtils.optional(request, "valid", StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
if (httpResult.code != HttpURLConnection.HTTP_OK) {
|
||||
throw new IllegalArgumentException("failed to proxy health update to " + server + ", service: " + serviceName);
|
||||
if (StringUtils.isBlank(healthyString)) {
|
||||
throw new IllegalArgumentException("Param 'healthy' is required.");
|
||||
}
|
||||
|
||||
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
// Only health check "none" need update health status with api
|
||||
if (HealthCheckType.NONE.name().equals(service.getClusterMap().get(clusterName).getHealthChecker().getType())) {
|
||||
for (Instance instance : service.allIPs(Lists.newArrayList(clusterName))) {
|
||||
if (instance.getIp().equals(ip) && instance.getPort() == port) {
|
||||
instance.setHealthy(valid);
|
||||
Loggers.EVT_LOG.info((valid ? "[IP-ENABLED]" : "[IP-DISABLED]") + " ips: "
|
||||
+ instance.getIp() + ":" + instance.getPort() + "@" + instance.getClusterName()
|
||||
+ ", service: " + serviceName + ", msg: update thought HealthController api");
|
||||
pushService.serviceChanged(namespaceId, service.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
// Only health check "none" need update health status with api
|
||||
if (HealthCheckType.NONE.name().equals(service.getClusterMap().get(clusterName).getHealthChecker().getType())) {
|
||||
for (Instance instance : service.allIPs(Lists.newArrayList(clusterName))) {
|
||||
if (instance.getIp().equals(ip) && instance.getPort() == port) {
|
||||
instance.setHealthy(valid);
|
||||
Loggers.EVT_LOG.info((valid ? "[IP-ENABLED]" : "[IP-DISABLED]") + " ips: "
|
||||
+ instance.getIp() + ":" + instance.getPort() + "@" + instance.getClusterName()
|
||||
+ ", service: " + serviceName + ", msg: update thought HealthController api");
|
||||
pushService.serviceChanged(namespaceId, service.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("health check mode 'client' and 'server' are not supported, service: " + serviceName);
|
||||
}
|
||||
throw new IllegalArgumentException("health check is still working, service: " + serviceName);
|
||||
}
|
||||
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
|
@ -112,6 +112,7 @@ public class InstanceController {
|
||||
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
Loggers.SRV_LOG.warn("remove instance from non-exist service: {}", serviceName);
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@ -120,6 +121,7 @@ public class InstanceController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@CanDistro
|
||||
@RequestMapping(value = "", method = RequestMethod.PUT)
|
||||
public String update(HttpServletRequest request) throws Exception {
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
@ -133,10 +135,10 @@ public class InstanceController {
|
||||
ClientInfo clientInfo = new ClientInfo(agent);
|
||||
|
||||
if (clientInfo.type == ClientInfo.ClientType.JAVA &&
|
||||
clientInfo.version.compareTo(VersionUtil.parseVersion("1.0.0")) < 0) {
|
||||
serviceManager.registerInstance(namespaceId, serviceName, parseInstance(request));
|
||||
} else {
|
||||
clientInfo.version.compareTo(VersionUtil.parseVersion("1.0.0")) >= 0) {
|
||||
serviceManager.updateInstance(namespaceId, serviceName, parseInstance(request));
|
||||
} else {
|
||||
serviceManager.registerInstance(namespaceId, serviceName, parseInstance(request));
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
@ -187,7 +189,8 @@ public class InstanceController {
|
||||
|
||||
List<Instance> ips = service.allIPs(clusters);
|
||||
if (ips == null || ips.isEmpty()) {
|
||||
throw new IllegalStateException("no ips found for cluster " + cluster + " in service " + serviceName);
|
||||
throw new NacosException(NacosException.NOT_FOUND,
|
||||
"no ips found for cluster " + cluster + " in service " + serviceName);
|
||||
}
|
||||
|
||||
for (Instance instance : ips) {
|
||||
@ -205,7 +208,7 @@ public class InstanceController {
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException("no matched ip found!");
|
||||
throw new NacosException(NacosException.NOT_FOUND, "no matched ip found!");
|
||||
}
|
||||
|
||||
@CanDistro
|
||||
@ -216,15 +219,15 @@ public class InstanceController {
|
||||
|
||||
result.put("clientBeatInterval", switchDomain.getClientBeatInterval());
|
||||
|
||||
// ignore client beat in CP mode:
|
||||
if (ServerMode.CP.name().equals(switchDomain.getServerMode())) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
String beat = WebUtils.required(request, "beat");
|
||||
RsInfo clientBeat = JSON.parseObject(beat, RsInfo.class);
|
||||
|
||||
if (!switchDomain.isDefaultInstanceEphemeral() && !clientBeat.isEphemeral()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(clientBeat.getCluster())) {
|
||||
clientBeat.setCluster(UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
}
|
||||
@ -323,16 +326,6 @@ public class InstanceController {
|
||||
throw new NacosException(NacosException.INVALID_PARAM, "instance format invalid:" + instance);
|
||||
}
|
||||
|
||||
if ((ServerMode.AP.name().equals(switchDomain.getServerMode()) && !instance.isEphemeral())) {
|
||||
throw new NacosException(NacosException.INVALID_PARAM, "wrong instance type: " + instance.isEphemeral()
|
||||
+ " in " + switchDomain.getServerMode() + " mode.");
|
||||
}
|
||||
|
||||
if ((ServerMode.CP.name().equals(switchDomain.getServerMode()) && instance.isEphemeral())) {
|
||||
throw new NacosException(NacosException.INVALID_PARAM, "wrong instance type: " + instance.isEphemeral()
|
||||
+ " in " + switchDomain.getServerMode() + " mode.");
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -341,12 +334,14 @@ public class InstanceController {
|
||||
String ip = WebUtils.required(request, "ip");
|
||||
String port = WebUtils.required(request, "port");
|
||||
String weight = WebUtils.optional(request, "weight", "1");
|
||||
String cluster = WebUtils.optional(request, CommonParams.CLUSTER_NAME, UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
String cluster = WebUtils.optional(request, CommonParams.CLUSTER_NAME, StringUtils.EMPTY);
|
||||
if (StringUtils.isBlank(cluster)) {
|
||||
cluster = WebUtils.optional(request, "cluster", UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
}
|
||||
boolean healthy = BooleanUtils.toBoolean(WebUtils.optional(request, "healthy", "true"));
|
||||
boolean enabled = BooleanUtils.toBoolean(WebUtils.optional(request, "enable", "true"));
|
||||
// If server running in CP mode, we set this flag to false:
|
||||
boolean ephemeral = BooleanUtils.toBoolean(WebUtils.optional(request, "ephemeral",
|
||||
String.valueOf(!ServerMode.CP.name().equals(switchDomain.getServerMode()))));
|
||||
String.valueOf(switchDomain.isDefaultInstanceEphemeral())));
|
||||
|
||||
Instance instance = new Instance();
|
||||
instance.setPort(Integer.parseInt(port));
|
||||
@ -369,6 +364,7 @@ public class InstanceController {
|
||||
public JSONObject doSrvIPXT(String namespaceId, String serviceName, String agent, String clusters, String clientIP, int udpPort,
|
||||
String env, boolean isCheck, String app, String tid, boolean healthyOnly) throws Exception {
|
||||
|
||||
ClientInfo clientInfo = new ClientInfo(agent);
|
||||
JSONObject result = new JSONObject();
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
|
||||
@ -412,8 +408,14 @@ public class InstanceController {
|
||||
Loggers.DEBUG_LOG.debug("no instance to serve for service: " + serviceName);
|
||||
}
|
||||
|
||||
if (clientInfo.type == ClientInfo.ClientType.JAVA &&
|
||||
clientInfo.version.compareTo(VersionUtil.parseVersion("1.0.0")) >= 0) {
|
||||
result.put("dom", serviceName);
|
||||
} else {
|
||||
result.put("dom", NamingUtils.getServiceName(serviceName));
|
||||
}
|
||||
|
||||
result.put("hosts", new JSONArray());
|
||||
result.put("dom", serviceName);
|
||||
result.put("name", serviceName);
|
||||
result.put("cacheMillis", cacheMillis);
|
||||
result.put("lastRefTime", System.currentTimeMillis());
|
||||
@ -459,8 +461,6 @@ public class InstanceController {
|
||||
|
||||
JSONArray hosts = new JSONArray();
|
||||
|
||||
ClientInfo clientInfo = new ClientInfo(agent);
|
||||
|
||||
for (Map.Entry<Boolean, List<Instance>> entry : ipMap.entrySet()) {
|
||||
List<Instance> ips = entry.getValue();
|
||||
|
||||
|
@ -23,6 +23,7 @@ import com.alibaba.nacos.core.utils.SystemUtils;
|
||||
import com.alibaba.nacos.core.utils.WebUtils;
|
||||
import com.alibaba.nacos.naming.cluster.ServerListManager;
|
||||
import com.alibaba.nacos.naming.cluster.ServerStatusManager;
|
||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftCore;
|
||||
import com.alibaba.nacos.naming.core.DistroMapper;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
@ -73,6 +74,9 @@ public class OperatorController {
|
||||
@Autowired
|
||||
private DistroMapper distroMapper;
|
||||
|
||||
@Autowired
|
||||
private RaftCore raftCore;
|
||||
|
||||
@RequestMapping("/push/state")
|
||||
public JSONObject pushState(HttpServletRequest request) {
|
||||
|
||||
@ -144,6 +148,7 @@ public class OperatorController {
|
||||
result.put("status", serverStatusManager.getServerStatus().name());
|
||||
result.put("serviceCount", serviceCount);
|
||||
result.put("instanceCount", ipCount);
|
||||
result.put("raftNotifyTaskCount", raftCore.getNotifyTaskCount());
|
||||
result.put("responsibleServiceCount", responsibleDomCount);
|
||||
result.put("responsibleInstanceCount", responsibleIPCount);
|
||||
result.put("cpu", SystemUtils.getCPU());
|
||||
|
@ -50,7 +50,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* HTTP interfaces for Raft consistency protocol. These interfaces should only be invoked by Nacos server itself.
|
||||
* Methods for Raft consistency protocol. These methods should only be invoked by Nacos server itself.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 1.0.0
|
||||
@ -83,7 +83,6 @@ public class RaftController {
|
||||
public JSONObject beat(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
String entity = new String(IoUtils.tryDecompress(request.getInputStream()), "UTF-8");
|
||||
// String value = Arrays.asList(entity).toArray(new String[1])[0];
|
||||
String value = URLDecoder.decode(entity, "UTF-8");
|
||||
value = URLDecoder.decode(value, "UTF-8");
|
||||
|
||||
@ -240,7 +239,6 @@ public class RaftController {
|
||||
response.setHeader("Content-Encode", "gzip");
|
||||
|
||||
String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
|
||||
// String value = Arrays.asList(entity).toArray(new String[1])[0];
|
||||
String value = URLDecoder.decode(entity, "UTF-8");
|
||||
value = URLDecoder.decode(value, "UTF-8");
|
||||
JSONObject jsonObject = JSON.parseObject(value);
|
||||
|
@ -31,6 +31,7 @@ import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.selector.LabelSelector;
|
||||
import com.alibaba.nacos.naming.selector.NoneSelector;
|
||||
import com.alibaba.nacos.naming.selector.Selector;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -39,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
|
||||
@ -105,15 +107,6 @@ public class ServiceController {
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("specified service not exist, serviceName : " + serviceName);
|
||||
}
|
||||
|
||||
if (!service.allIPs().isEmpty()) {
|
||||
throw new IllegalArgumentException("specified service has instances, serviceName : " + serviceName);
|
||||
}
|
||||
|
||||
serviceManager.easyRemoveService(namespaceId, serviceName);
|
||||
|
||||
return "ok";
|
||||
@ -299,13 +292,19 @@ public class ServiceController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/status", method = RequestMethod.POST)
|
||||
public String serviceStatus(HttpServletRequest request) {
|
||||
public String serviceStatus(HttpServletRequest request) throws Exception {
|
||||
|
||||
String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
|
||||
String value = URLDecoder.decode(entity, "UTF-8");
|
||||
JSONObject json = JSON.parseObject(value);
|
||||
|
||||
//format: service1@@checksum@@@service2@@checksum
|
||||
String statuses = WebUtils.required(request, "statuses");
|
||||
String serverIP = WebUtils.optional(request, "clientIP", "");
|
||||
String statuses = json.getString("statuses");
|
||||
String serverIP = json.getString("clientIP");
|
||||
|
||||
if (!serverListManager.contains(serverIP)) {
|
||||
throw new IllegalArgumentException("ip: " + serverIP + " is not in serverlist");
|
||||
throw new NacosException(NacosException.INVALID_PARAM,
|
||||
"ip: " + serverIP + " is not in serverlist");
|
||||
}
|
||||
|
||||
try {
|
||||
@ -345,7 +344,7 @@ public class ServiceController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/checksum", method = RequestMethod.PUT)
|
||||
public JSONObject checksum(HttpServletRequest request) {
|
||||
public JSONObject checksum(HttpServletRequest request) throws Exception {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
@ -353,7 +352,8 @@ public class ServiceController {
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("serviceName not found: " + serviceName);
|
||||
throw new NacosException(NacosException.NOT_FOUND,
|
||||
"serviceName not found: " + serviceName);
|
||||
}
|
||||
|
||||
service.recalculateChecksum();
|
||||
|
@ -54,6 +54,9 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement
|
||||
@JSONField(serialize = false)
|
||||
private Service service;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
private volatile boolean inited = false;
|
||||
|
||||
private Map<String, String> metadata = new ConcurrentHashMap<>();
|
||||
|
||||
public Cluster() {
|
||||
@ -61,6 +64,7 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement
|
||||
|
||||
public Cluster(String clusterName) {
|
||||
this.setName(clusterName);
|
||||
validate();
|
||||
}
|
||||
|
||||
public int getDefIPPort() {
|
||||
@ -87,12 +91,18 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement
|
||||
}
|
||||
|
||||
public void init() {
|
||||
if (inited) {
|
||||
return;
|
||||
}
|
||||
checkTask = new HealthCheckTask(this);
|
||||
HealthCheckReactor.scheduleCheck(checkTask);
|
||||
inited = true;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
checkTask.setCancelled(true);
|
||||
if (checkTask != null) {
|
||||
checkTask.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public HealthCheckTask getHealthCheckTask() {
|
||||
@ -105,6 +115,7 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement
|
||||
|
||||
public void setService(Service service) {
|
||||
this.service = service;
|
||||
this.setServiceName(service.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -181,7 +181,7 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
||||
}
|
||||
|
||||
if (ip == null) {
|
||||
throw new IllegalArgumentException("malfomed ip config: " + json);
|
||||
throw new IllegalArgumentException("malformed ip config: " + json);
|
||||
}
|
||||
|
||||
if (ip.getWeight() > MAX_WEIGHT_VALUE) {
|
||||
@ -195,7 +195,7 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
||||
}
|
||||
|
||||
if (!ip.validate()) {
|
||||
throw new IllegalArgumentException("malfomed ip config: " + json);
|
||||
throw new IllegalArgumentException("malformed ip config: " + json);
|
||||
}
|
||||
|
||||
return ip;
|
||||
|
@ -20,13 +20,16 @@ import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.pojo.Record;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Package of instance list
|
||||
@ -40,7 +43,7 @@ public class Instances implements Record {
|
||||
|
||||
private long lastCalculateTime = 0L;
|
||||
|
||||
private List<Instance> instanceList;
|
||||
private List<Instance> instanceList = new ArrayList<>();
|
||||
|
||||
public List<Instance> getInstanceList() {
|
||||
return instanceList;
|
||||
@ -71,7 +74,7 @@ public class Instances implements Record {
|
||||
Collections.sort(instanceList);
|
||||
for (Instance ip : instanceList) {
|
||||
String string = ip.getIp() + ":" + ip.getPort() + "_" + ip.getWeight() + "_"
|
||||
+ ip.isHealthy() + "_" + ip.getClusterName();
|
||||
+ ip.isHealthy() + "_" + ip.isEnabled() + "_" + ip.getClusterName() + "_" + convertMap2String(ip.getMetadata());
|
||||
sb.append(string);
|
||||
sb.append(",");
|
||||
}
|
||||
@ -86,4 +89,22 @@ public class Instances implements Record {
|
||||
}
|
||||
lastCalculateTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public String convertMap2String(Map<String, String> map) {
|
||||
|
||||
if (map == null || map.isEmpty()) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<String> keys = new ArrayList<>(map.keySet());
|
||||
Collections.sort(keys);
|
||||
for (String key : keys) {
|
||||
sb.append(key);
|
||||
sb.append(":");
|
||||
sb.append(map.get(key));
|
||||
sb.append(",");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ package com.alibaba.nacos.naming.core;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.nacos.naming.boot.SpringContext;
|
||||
import com.alibaba.nacos.naming.consistency.RecordListener;
|
||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||
import com.alibaba.nacos.naming.consistency.RecordListener;
|
||||
import com.alibaba.nacos.naming.healthcheck.ClientBeatCheckTask;
|
||||
import com.alibaba.nacos.naming.healthcheck.ClientBeatProcessor;
|
||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckReactor;
|
||||
@ -44,9 +44,9 @@ import java.util.*;
|
||||
* Service of Nacos server side
|
||||
* <p>
|
||||
* We introduce a 'service --> cluster --> instance' model, in which service stores a list of clusters,
|
||||
* which contains a list of instances.
|
||||
* which contain a list of instances.
|
||||
* <p>
|
||||
* This class inherits from Service in API module and stores some fields that do not expose to client.
|
||||
* This class inherits from Service in API module and stores some fields that do not have to expose to client.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
@ -154,14 +154,19 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
|
||||
Loggers.SRV_LOG.info("[NACOS-RAFT] datum is changed, key: {}, value: {}", key, value);
|
||||
|
||||
for (Instance ip : value.getInstanceList()) {
|
||||
for (Instance instance : value.getInstanceList()) {
|
||||
|
||||
if (ip.getWeight() > 10000.0D) {
|
||||
ip.setWeight(10000.0D);
|
||||
if (instance == null) {
|
||||
// Reject this abnormal instance list:
|
||||
throw new RuntimeException("got null instance " + key);
|
||||
}
|
||||
|
||||
if (ip.getWeight() < 0.01D && ip.getWeight() > 0.0D) {
|
||||
ip.setWeight(0.01D);
|
||||
if (instance.getWeight() > 10000.0D) {
|
||||
instance.setWeight(10000.0D);
|
||||
}
|
||||
|
||||
if (instance.getWeight() < 0.01D && instance.getWeight() > 0.0D) {
|
||||
instance.setWeight(0.01D);
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,6 +217,7 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
instance.getClusterName(), instance.toJSON());
|
||||
Cluster cluster = new Cluster(instance.getClusterName());
|
||||
cluster.setService(this);
|
||||
cluster.init();
|
||||
getClusterMap().put(instance.getClusterName(), cluster);
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.cluster.ServerListManager;
|
||||
import com.alibaba.nacos.naming.cluster.ServerMode;
|
||||
import com.alibaba.nacos.naming.cluster.servers.Server;
|
||||
import com.alibaba.nacos.naming.consistency.ConsistencyService;
|
||||
import com.alibaba.nacos.naming.consistency.Datum;
|
||||
@ -79,6 +78,8 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
@Autowired
|
||||
private PushService pushService;
|
||||
|
||||
private final Object putServiceLock = new Object();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
@ -155,16 +156,26 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
public void onDelete(String key) throws Exception {
|
||||
String namespace = KeyBuilder.getNamespace(key);
|
||||
String name = KeyBuilder.getServiceName(key);
|
||||
Service service = chooseServiceMap(namespace).remove(name);
|
||||
Service service = chooseServiceMap(namespace).get(name);
|
||||
Loggers.RAFT.info("[RAFT-NOTIFIER] datum is deleted, key: {}", key);
|
||||
|
||||
// check again:
|
||||
if (service != null && !service.allIPs().isEmpty()) {
|
||||
Loggers.SRV_LOG.warn("service not empty, key: {}", key);
|
||||
return;
|
||||
}
|
||||
|
||||
if (service != null) {
|
||||
service.destroy();
|
||||
consistencyService.remove(KeyBuilder.buildInstanceListKey(namespace, name, true));
|
||||
|
||||
consistencyService.remove(KeyBuilder.buildInstanceListKey(namespace, name, false));
|
||||
|
||||
consistencyService.unlisten(KeyBuilder.buildServiceMetaKey(namespace, name), service);
|
||||
Loggers.SRV_LOG.info("[DEAD-SERVICE] {}", service.toJSON());
|
||||
}
|
||||
|
||||
chooseServiceMap(namespace).remove(name);
|
||||
}
|
||||
|
||||
private class UpdatedServiceProcessor implements Runnable {
|
||||
@ -321,16 +332,28 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
}
|
||||
|
||||
public void easyRemoveService(String namespaceId, String serviceName) throws Exception {
|
||||
|
||||
Service service = getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("specified service not exist, serviceName : " + serviceName);
|
||||
}
|
||||
|
||||
if (!service.allIPs().isEmpty()) {
|
||||
throw new IllegalArgumentException("specified service has instances, serviceName : " + serviceName);
|
||||
}
|
||||
|
||||
consistencyService.remove(KeyBuilder.buildServiceMetaKey(namespaceId, serviceName));
|
||||
}
|
||||
|
||||
public void addOrReplaceService(Service service) throws Exception {
|
||||
public void addOrReplaceService(Service service) throws NacosException {
|
||||
consistencyService.put(KeyBuilder.buildServiceMetaKey(service.getNamespaceId(), service.getName()), service);
|
||||
}
|
||||
|
||||
public void createEmptyService(String namespaceId, String serviceName) throws NacosException {
|
||||
public void createEmptyService(String namespaceId, String serviceName, boolean local) throws NacosException {
|
||||
Service service = getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
|
||||
Loggers.SRV_LOG.info("creating empty service {}:{}", namespaceId, serviceName);
|
||||
service = new Service();
|
||||
service.setName(serviceName);
|
||||
service.setNamespaceId(namespaceId);
|
||||
@ -339,10 +362,14 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
service.setLastModifiedMillis(System.currentTimeMillis());
|
||||
service.recalculateChecksum();
|
||||
service.validate();
|
||||
putService(service);
|
||||
service.init();
|
||||
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), true), service);
|
||||
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), false), service);
|
||||
if (local) {
|
||||
putService(service);
|
||||
service.init();
|
||||
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), true), service);
|
||||
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), false), service);
|
||||
} else {
|
||||
addOrReplaceService(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -358,9 +385,7 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
*/
|
||||
public void registerInstance(String namespaceId, String serviceName, Instance instance) throws NacosException {
|
||||
|
||||
if (ServerMode.AP.name().equals(switchDomain.getServerMode())) {
|
||||
createEmptyService(namespaceId, serviceName);
|
||||
}
|
||||
createEmptyService(namespaceId, serviceName, instance.isEphemeral());
|
||||
|
||||
Service service = getService(namespaceId, serviceName);
|
||||
|
||||
@ -369,10 +394,6 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
"service not found, namespace: " + namespaceId + ", service: " + serviceName);
|
||||
}
|
||||
|
||||
if (service.allIPs().contains(instance)) {
|
||||
throw new NacosException(NacosException.INVALID_PARAM, "instance already exist: " + instance);
|
||||
}
|
||||
|
||||
addInstance(namespaceId, serviceName, instance.isEphemeral(), instance);
|
||||
}
|
||||
|
||||
@ -466,6 +487,7 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
if (!service.getClusterMap().containsKey(instance.getClusterName())) {
|
||||
Cluster cluster = new Cluster(instance.getClusterName());
|
||||
cluster.setService(service);
|
||||
cluster.init();
|
||||
service.getClusterMap().put(instance.getClusterName(), cluster);
|
||||
Loggers.SRV_LOG.warn("cluster: {} not found, ip: {}, will create new cluster with default configuration.",
|
||||
instance.getClusterName(), instance.toJSON());
|
||||
@ -522,7 +544,11 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
|
||||
public void putService(Service service) {
|
||||
if (!serviceMap.containsKey(service.getNamespaceId())) {
|
||||
serviceMap.put(service.getNamespaceId(), new ConcurrentHashMap<>(16));
|
||||
synchronized (putServiceLock) {
|
||||
if (!serviceMap.containsKey(service.getNamespaceId())) {
|
||||
serviceMap.put(service.getNamespaceId(), new ConcurrentHashMap<>(16));
|
||||
}
|
||||
}
|
||||
}
|
||||
serviceMap.get(service.getNamespaceId()).put(service.getName(), service);
|
||||
}
|
||||
|
@ -72,7 +72,9 @@ public class HealthCheckTask implements Runnable {
|
||||
if (distroMapper.responsible(cluster.getService().getName()) &&
|
||||
switchDomain.isHealthCheckEnabled(cluster.getService().getName())) {
|
||||
healthCheckProcessor.process(this);
|
||||
Loggers.EVT_LOG.debug("[HEALTH-CHECK] schedule health check task: {}", cluster.getService().getName());
|
||||
if (Loggers.EVT_LOG.isDebugEnabled()) {
|
||||
Loggers.EVT_LOG.debug("[HEALTH-CHECK] schedule health check task: {}", cluster.getService().getName());
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Loggers.SRV_LOG.error("[HEALTH-CHECK] error while process health check for {}:{}",
|
||||
|
@ -27,6 +27,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.*;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.entity.ContentType;
|
||||
@ -41,6 +43,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
@ -285,6 +288,29 @@ public class HttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
public static void asyncHttpGetLarge(String url, Map<String, String> headers, byte[] content, AsyncCompletionHandler handler) throws Exception {
|
||||
AsyncHttpClient.BoundRequestBuilder builder = asyncHttpClient.prepareGet(url);
|
||||
|
||||
if (!headers.isEmpty()) {
|
||||
for (String headerKey : headers.keySet()) {
|
||||
builder.setHeader(headerKey, headers.get(headerKey));
|
||||
}
|
||||
}
|
||||
|
||||
builder.setBody(content);
|
||||
|
||||
builder.setHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
builder.setHeader("Accept-Charset", "UTF-8");
|
||||
builder.setHeader("Accept-Encoding", "gzip");
|
||||
builder.setHeader("Content-Encoding", "gzip");
|
||||
|
||||
if (handler != null) {
|
||||
builder.execute(handler);
|
||||
} else {
|
||||
builder.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpResult httpPutLarge(String url, Map<String, String> headers, byte[] content) {
|
||||
try {
|
||||
HttpClientBuilder builder = HttpClients.custom();
|
||||
@ -313,6 +339,35 @@ public class HttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpResult httpGetLarge(String url, Map<String, String> headers, String content) {
|
||||
|
||||
try {
|
||||
HttpClientBuilder builder = HttpClients.custom();
|
||||
builder.setUserAgent(UtilsAndCommons.SERVER_VERSION);
|
||||
builder.setConnectionTimeToLive(500, TimeUnit.MILLISECONDS);
|
||||
|
||||
CloseableHttpClient httpClient = builder.build();
|
||||
HttpGetWithEntity httpGetWithEntity = new HttpGetWithEntity();
|
||||
httpGetWithEntity.setURI(new URI(url));
|
||||
|
||||
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||
httpGetWithEntity.setHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
httpGetWithEntity.setEntity(new StringEntity(content, ContentType.create("application/json", "UTF-8")));
|
||||
HttpResponse response = httpClient.execute(httpGetWithEntity);
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
HeaderElement[] headerElements = entity.getContentType().getElements();
|
||||
String charset = headerElements[0].getParameterByName("charset").getValue();
|
||||
|
||||
return new HttpResult(response.getStatusLine().getStatusCode(),
|
||||
IOUtils.toString(entity.getContent(), charset), Collections.<String, String>emptyMap());
|
||||
} catch (Exception e) {
|
||||
return new HttpResult(500, e.toString(), Collections.<String, String>emptyMap());
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpResult httpPostLarge(String url, Map<String, String> headers, String content) {
|
||||
try {
|
||||
HttpClientBuilder builder = HttpClients.custom();
|
||||
@ -427,6 +482,15 @@ public class HttpClient {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static Map<String, String> translateParameterMap(Map<String, String[]> parameterMap) {
|
||||
|
||||
Map<String, String> map = new HashMap<>(16);
|
||||
for (String key : parameterMap.keySet()) {
|
||||
map.put(key, parameterMap.get(key)[0]);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static class HttpResult {
|
||||
final public int code;
|
||||
final public String content;
|
||||
@ -442,4 +506,14 @@ public class HttpClient {
|
||||
return respHeaders.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static class HttpGetWithEntity extends HttpEntityEnclosingRequestBase {
|
||||
|
||||
public final static String METHOD_NAME = "GET";
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return METHOD_NAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,8 +79,8 @@ public class NamingProxy {
|
||||
|
||||
Map<String, String> params = new HashMap<>(8);
|
||||
params.put("keys", StringUtils.join(keys, ","));
|
||||
HttpClient.HttpResult result = HttpClient.httpGet("http://" + server + RunningConfig.getContextPath()
|
||||
+ UtilsAndCommons.NACOS_NAMING_CONTEXT + DATA_GET_URL, new ArrayList<>(), params);
|
||||
HttpClient.HttpResult result = HttpClient.httpGetLarge("http://" + server + RunningConfig.getContextPath()
|
||||
+ UtilsAndCommons.NACOS_NAMING_CONTEXT + DATA_GET_URL, new HashMap<>(8), JSON.toJSONString(params));
|
||||
|
||||
if (HttpURLConnection.HTTP_OK == result.code) {
|
||||
return result.content.getBytes();
|
||||
@ -236,4 +236,12 @@ public class NamingProxy {
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String key = "com.alibaba.nacos.naming.iplist.ephemeral.public##DEFAULT_GROUP@@test.10";
|
||||
List<String> keys = new ArrayList<>();
|
||||
keys.add(key);
|
||||
getData(keys, "11.239.112.161:8848");
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.misc;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.naming.boot.RunningConfig;
|
||||
import com.ning.http.client.AsyncCompletionHandler;
|
||||
import com.ning.http.client.Response;
|
||||
@ -49,7 +50,7 @@ public class ServiceStatusSynchronizer implements Synchronizer {
|
||||
}
|
||||
|
||||
try {
|
||||
HttpClient.asyncHttpPost(url, null, params, new AsyncCompletionHandler() {
|
||||
HttpClient.asyncHttpPostLarge(url, null, JSON.toJSONString(params), new AsyncCompletionHandler() {
|
||||
@Override
|
||||
public Integer onCompleted(Response response) throws Exception {
|
||||
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
|
||||
|
@ -89,7 +89,7 @@ public class SwitchDomain implements Record, Cloneable {
|
||||
|
||||
private String overriddenServerStatus = null;
|
||||
|
||||
private String serverMode = "AP";
|
||||
private boolean defaultInstanceEphemeral = true;
|
||||
|
||||
public boolean isEnableAuthentication() {
|
||||
return enableAuthentication;
|
||||
@ -342,12 +342,12 @@ public class SwitchDomain implements Record, Cloneable {
|
||||
this.overriddenServerStatus = overriddenServerStatus;
|
||||
}
|
||||
|
||||
public String getServerMode() {
|
||||
return serverMode;
|
||||
public boolean isDefaultInstanceEphemeral() {
|
||||
return defaultInstanceEphemeral;
|
||||
}
|
||||
|
||||
public void setServerMode(String serverMode) {
|
||||
this.serverMode = serverMode;
|
||||
public void setDefaultInstanceEphemeral(boolean defaultInstanceEphemeral) {
|
||||
this.defaultInstanceEphemeral = defaultInstanceEphemeral;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,5 +59,5 @@ public class SwitchEntry {
|
||||
public static final String PARAM_JSON = "json";
|
||||
|
||||
public static final String OVERRIDDEN_SERVER_STATUS = "overriddenServerStatus";
|
||||
public static final String SERVER_MODE = "serverMode";
|
||||
public static final String DEFAULT_INSTANCE_EPHEMERAL = "defaultInstanceEphemeral";
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ package com.alibaba.nacos.naming.misc;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.cluster.ServerMode;
|
||||
import com.alibaba.nacos.naming.consistency.ConsistencyService;
|
||||
import com.alibaba.nacos.naming.consistency.Datum;
|
||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||
@ -263,9 +262,9 @@ public class SwitchManager implements RecordListener<SwitchDomain> {
|
||||
switchDomain.setOverriddenServerStatus(status);
|
||||
}
|
||||
|
||||
if (entry.equals(SwitchEntry.SERVER_MODE)) {
|
||||
String mode = value;
|
||||
switchDomain.setServerMode(ServerMode.valueOf(mode).name());
|
||||
if (entry.equals(SwitchEntry.DEFAULT_INSTANCE_EPHEMERAL)) {
|
||||
String defaultEphemeral = value;
|
||||
switchDomain.setDefaultInstanceEphemeral(Boolean.parseBoolean(defaultEphemeral));
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
@ -308,7 +307,7 @@ public class SwitchManager implements RecordListener<SwitchDomain> {
|
||||
switchDomain.setPushCVersion(newSwitchDomain.getPushCVersion());
|
||||
switchDomain.setEnableAuthentication(newSwitchDomain.isEnableAuthentication());
|
||||
switchDomain.setOverriddenServerStatus(newSwitchDomain.getOverriddenServerStatus());
|
||||
switchDomain.setServerMode(newSwitchDomain.getServerMode());
|
||||
switchDomain.setDefaultInstanceEphemeral(newSwitchDomain.isDefaultInstanceEphemeral());
|
||||
}
|
||||
|
||||
public SwitchDomain getSwitchDomain() {
|
||||
|
@ -237,4 +237,34 @@ public class UtilsAndCommons {
|
||||
public static String assembleFullServiceName(String namespaceId, String serviceName) {
|
||||
return namespaceId + UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR + serviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据指定的字符串计算出一个0(含)到{@code upperLimit}(不含)之间的数字,本方法会试图让不同的字符串较均匀的分布在0到{@code upperLimit}之间。
|
||||
* (Provide a number between 0(include) and {@code upperLimit}(exclude) for the given {@code string}, the number will be nearly uniform distribution.)
|
||||
* <p>
|
||||
* <p>
|
||||
* 举个例子:假设有N个提供相同服务的服务器地址被存在一个数组中,为了实现负载均衡,可以根据调用者的名字决定使用哪个服务器。
|
||||
* (e.g. Assume there's an array which contains some IP of the servers provide the same service, the caller name can be used to choose the server to achieve load balance.)
|
||||
* <blockquote><pre>
|
||||
* String[] serverIps = new String[10];
|
||||
* int index = shakeUp("callerName", serverIps.length);
|
||||
* String targetServerIp = serverIps[index];
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param string 字符串。如果为null会固定返回0 (a string. the number 0 will be returned if it's null)
|
||||
* @param upperLimit 返回值的上限,必须为正整数(>0) (the upper limit of the returned number, must be a positive integer, which means > 0)
|
||||
* @return 0(含)到upperLimit(不含)之间的一个数字 (a number between 0(include) and upperLimit(exclude))
|
||||
* @throws IllegalArgumentException if the upper limit equals or less than 0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static int shakeUp(String string, int upperLimit) {
|
||||
if (upperLimit < 1) {
|
||||
throw new IllegalArgumentException("upper limit must be greater than 0");
|
||||
}
|
||||
if (string == null) {
|
||||
return 0;
|
||||
}
|
||||
return (string.hashCode() & Integer.MAX_VALUE) % upperLimit;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import com.alibaba.nacos.naming.misc.HttpClient;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.SwitchDomain;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@ -33,7 +32,10 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.security.AccessControlException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nacos
|
||||
@ -57,17 +59,24 @@ public class DistroFilter implements Filter {
|
||||
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("HRS_REQUEST_PARAMETER_TO_HTTP_HEADER")
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletRequest req = (HttpServletRequest) servletRequest;
|
||||
HttpServletResponse resp = (HttpServletResponse) servletResponse;
|
||||
|
||||
String urlString = req.getRequestURI() + "?" + req.getQueryString();
|
||||
String urlString = req.getRequestURI();
|
||||
|
||||
if (StringUtils.isNotBlank(req.getQueryString())) {
|
||||
urlString += "?" + req.getQueryString();
|
||||
}
|
||||
|
||||
try {
|
||||
String path = new URI(req.getRequestURI()).getPath();
|
||||
String serviceName = req.getParameter(CommonParams.SERVICE_NAME);
|
||||
// For client under 0.8.0:
|
||||
if (StringUtils.isBlank(serviceName)) {
|
||||
serviceName = req.getParameter("dom");
|
||||
}
|
||||
Method method = filterBase.getMethod(req.getMethod(), path);
|
||||
|
||||
if (method == null) {
|
||||
@ -96,7 +105,8 @@ public class DistroFilter implements Filter {
|
||||
headerList.add(req.getHeader(headerName));
|
||||
}
|
||||
HttpClient.HttpResult result =
|
||||
HttpClient.request("http://" + distroMapper.mapSrv(groupedServiceName) + urlString, headerList, new HashMap<>(2)
|
||||
HttpClient.request("http://" + distroMapper.mapSrv(groupedServiceName) + urlString, headerList,
|
||||
StringUtils.isBlank(req.getQueryString()) ? HttpClient.translateParameterMap(req.getParameterMap()) : new HashMap<>(2)
|
||||
, PROXY_CONNECT_TIMEOUT, PROXY_READ_TIMEOUT, "UTF-8", req.getMethod());
|
||||
|
||||
try {
|
||||
|
@ -26,7 +26,7 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
||||
# default current work dir
|
||||
server.tomcat.basedir=
|
||||
|
||||
nacos.naming.distro.taskDispatchThreadCount=10
|
||||
nacos.naming.distro.taskDispatchThreadCount=1
|
||||
nacos.naming.distro.taskDispatchPeriod=200
|
||||
nacos.naming.distro.batchSyncKeyCount=1000
|
||||
nacos.naming.distro.initDataRatio=0.9
|
||||
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.naming.consistency.ephemeral.distro;
|
||||
|
||||
import com.alibaba.nacos.naming.misc.GlobalConfig;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* @author jifengnan
|
||||
*/
|
||||
public class TaskDispatcherTest {
|
||||
|
||||
private TaskDispatcher taskDispatcher;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
taskDispatcher = new TaskDispatcher();
|
||||
GlobalConfig conf = new GlobalConfig();
|
||||
ReflectionTestUtils.setField(conf, "taskDispatchThreadCount", 3);
|
||||
ReflectionTestUtils.setField(taskDispatcher, "partitionConfig", conf);
|
||||
taskDispatcher.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddTask() {
|
||||
char[] chars = new char[]{2325, 9, 30, 12, 2};
|
||||
taskDispatcher.addTask(new String(chars));
|
||||
}
|
||||
}
|
@ -40,4 +40,16 @@ public class UtilsAndCommonsTest {
|
||||
|
||||
Assert.assertEquals("/nacos/v1/ns", DEFAULT_NACOS_NAMING_CONTEXT);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testShakeUpException() {
|
||||
UtilsAndCommons.shakeUp(null, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShakeUp() {
|
||||
Assert.assertEquals(0, UtilsAndCommons.shakeUp(null, 1));
|
||||
char[] chars = new char[]{2325, 9, 30, 12, 2};
|
||||
Assert.assertEquals(0, UtilsAndCommons.shakeUp(new String(chars), 1));
|
||||
}
|
||||
}
|
||||
|
12
pom.xml
12
pom.xml
@ -21,7 +21,7 @@
|
||||
<inceptionYear>2018</inceptionYear>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Alibaba NACOS ${project.version}</name>
|
||||
@ -94,8 +94,8 @@
|
||||
<maven.test.skip>false</maven.test.skip>
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
<!-- Compiler settings properties -->
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
|
||||
<!-- Exclude all generated code -->
|
||||
<sonar.jacoco.itReportPath>${project.basedir}/../test/target/jacoco-it.exec</sonar.jacoco.itReportPath>
|
||||
@ -696,12 +696,6 @@
|
||||
<version>1.9.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-annotations</artifactId>
|
||||
<version>3.1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.0.0-RC2</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -32,6 +32,8 @@ 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.api.naming.pojo.ListView;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.alibaba.nacos.config.server.utils.TimeoutUtils;
|
||||
import com.alibaba.nacos.naming.NamingApp;
|
||||
|
||||
import org.junit.After;
|
||||
@ -79,8 +81,6 @@ public class CPInstancesAPI_ITCase {
|
||||
public void setUp() throws Exception {
|
||||
String url = String.format("http://localhost:%d/", port);
|
||||
this.base = new URL(url);
|
||||
NamingBase.prepareServer(port, "UP", "CP");
|
||||
TimeUnit.SECONDS.sleep(5L);
|
||||
|
||||
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
|
||||
|
||||
@ -105,7 +105,7 @@ public class CPInstancesAPI_ITCase {
|
||||
* @TestStep :
|
||||
* @ExpectResult :
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void registerInstance_ephemeral_true() throws Exception {
|
||||
String serviceName = NamingBase.randomDomainName();
|
||||
namingServiceCreate(serviceName, TEST_NAMESPACE_1, TEST_GROUP_1);
|
||||
@ -116,6 +116,9 @@ public class CPInstancesAPI_ITCase {
|
||||
instance.setIp("11.11.11.11");
|
||||
instance.setPort(80);
|
||||
naming1.registerInstance(serviceName, TEST_GROUP_1, instance);
|
||||
TimeUnit.SECONDS.sleep(3L);
|
||||
naming1.deregisterInstance(serviceName, TEST_GROUP_1, instance);
|
||||
namingServiceDelete(serviceName, TEST_NAMESPACE_1, TEST_GROUP_1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,7 +157,8 @@ public class CPInstancesAPI_ITCase {
|
||||
instance.setIp("11.11.11.11");
|
||||
instance.setPort(80);
|
||||
naming1.registerInstance(serviceName, TEST_GROUP_1, instance);
|
||||
naming1.deregisterInstance(serviceName, TEST_GROUP_1, "11.11.11.11", 80, "c1");
|
||||
naming1.deregisterInstance(serviceName, TEST_GROUP_1, instance);
|
||||
TimeUnit.SECONDS.sleep(3L);
|
||||
|
||||
namingServiceDelete(serviceName, TEST_NAMESPACE_1, TEST_GROUP_1);
|
||||
}
|
||||
|
@ -165,10 +165,10 @@ public class NamingBase {
|
||||
}
|
||||
|
||||
public static void prepareServer(int localPort) {
|
||||
prepareServer(localPort, "UP", "AP");
|
||||
prepareServer(localPort, "UP");
|
||||
}
|
||||
|
||||
public static void prepareServer(int localPort, String status, String mode) {
|
||||
public static void prepareServer(int localPort, String status) {
|
||||
String url = "http://127.0.0.1:" + localPort + "/nacos/v1/ns/operator/switches?entry=overriddenServerStatus&value=" + status;
|
||||
List<String> headers = new ArrayList<String>();
|
||||
headers.add("User-Agent");
|
||||
@ -177,15 +177,5 @@ public class NamingBase {
|
||||
HttpClient.request(url, headers, new HashMap<String, String>(), "UTF-8", "PUT");
|
||||
|
||||
Assert.assertEquals(HttpStatus.SC_OK, result.code);
|
||||
|
||||
|
||||
url = "http://127.0.0.1:" + localPort + "/nacos/v1/ns/operator/switches?entry=serverMode&value=" + mode;
|
||||
headers = new ArrayList<String>();
|
||||
headers.add("User-Agent");
|
||||
headers.add("Nacos-Server");
|
||||
result =
|
||||
HttpClient.request(url, headers, new HashMap<String, String>(), "UTF-8", "PUT");
|
||||
|
||||
Assert.assertEquals(HttpStatus.SC_OK, result.code);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
||||
# default current work dir
|
||||
server.tomcat.basedir=
|
||||
|
||||
nacos.naming.distro.taskDispatchThreadCount=10
|
||||
nacos.naming.distro.taskDispatchThreadCount=1
|
||||
nacos.naming.distro.taskDispatchPeriod=200
|
||||
nacos.naming.distro.batchSyncKeyCount=1000
|
||||
nacos.naming.distro.initDataRatio=0.9
|
||||
|
Loading…
Reference in New Issue
Block a user