Merge branch 'develop' into charset

This commit is contained in:
Fury Zhu 2019-06-27 18:50:57 +08:00 committed by GitHub
commit fac3dc8a23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
97 changed files with 878 additions and 362 deletions

1
.gitignore vendored
View File

@ -3,7 +3,6 @@
.project .project
.settings .settings
target target
.project
.idea .idea
.vscode .vscode
.DS_Store .DS_Store

View File

@ -91,6 +91,11 @@ public @interface NacosProperties {
*/ */
String MAX_RETRY = "maxRetry"; String MAX_RETRY = "maxRetry";
/**
* The property name of "enableRemoteSyncConfig"
*/
String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
/** /**
* The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code> * The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code>
*/ */
@ -146,6 +151,11 @@ public @interface NacosProperties {
*/ */
String MAX_RETRY_PLACEHOLDER = "${" + PREFIX + MAX_RETRY + ":}"; String MAX_RETRY_PLACEHOLDER = "${" + PREFIX + MAX_RETRY + ":}";
/**
* The placeholder of {@link NacosProperties#ENABLE_REMOTE_SYNC_CONFIG enableRemoteSyncConfig}, the value is <code>"${nacos.enableRemoteSyncConfig:}"</code>
*/
String ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER = "${" + PREFIX + ENABLE_REMOTE_SYNC_CONFIG + "}";
/** /**
* The property of "endpoint" * The property of "endpoint"
* *
@ -234,4 +244,12 @@ public @interface NacosProperties {
*/ */
String maxRetry() default MAX_RETRY_PLACEHOLDER; String maxRetry() default MAX_RETRY_PLACEHOLDER;
/**
* The property of "enableRemoteSyncConfig"
*
* @return empty as default value
* @see #ENABLE_REMOTE_SYNC_CONFIG
*/
String enableRemoteSyncConfig() default ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER;
} }

View File

@ -15,6 +15,8 @@
*/ */
package com.alibaba.nacos.api.common; package com.alibaba.nacos.api.common;
import java.util.concurrent.TimeUnit;
/** /**
* Constant * Constant
* *
@ -143,6 +145,12 @@ public class Constants {
public static final String DEFAULT_CLUSTER_NAME = "DEFAULT"; public static final String DEFAULT_CLUSTER_NAME = "DEFAULT";
public static final long DEFAULT_HEART_BEAT_TIMEOUT = TimeUnit.SECONDS.toMillis(15);
public static final long DEFAULT_IP_DELETE_TIMEOUT = TimeUnit.SECONDS.toMillis(30);
public static final long DEFAULT_HEART_BEAT_INTERVAL = TimeUnit.SECONDS.toMillis(5);
public static final String DEFAULT_NAMESPACE_ID = "public"; public static final String DEFAULT_NAMESPACE_ID = "public";
public static final boolean DEFAULT_USE_CLOUD_NAMESPACE_PARSING = true; public static final boolean DEFAULT_USE_CLOUD_NAMESPACE_PARSING = true;
@ -152,4 +160,6 @@ public class Constants {
public static final String SERVICE_INFO_SPLITER = "@@"; public static final String SERVICE_INFO_SPLITER = "@@";
public static final String NULL_STRING = "null"; public static final String NULL_STRING = "null";
public static final String NUMBER_PATTERN = "^\\d+$";
} }

View File

@ -42,7 +42,7 @@ public class ConfigFactory {
ConfigService vendorImpl = (ConfigService) constructor.newInstance(properties); ConfigService vendorImpl = (ConfigService) constructor.newInstance(properties);
return vendorImpl; return vendorImpl;
} catch (Throwable e) { } catch (Throwable e) {
throw new NacosException(-400, e.getMessage()); throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
} }
} }

View File

@ -15,6 +15,9 @@
*/ */
package com.alibaba.nacos.api.exception; package com.alibaba.nacos.api.exception;
import com.alibaba.nacos.api.common.Constants;
import org.apache.commons.lang3.StringUtils;
/** /**
* Nacos Exception * Nacos Exception
* *
@ -31,6 +34,8 @@ public class NacosException extends Exception {
private String errMsg; private String errMsg;
private Throwable causeThrowable;
public NacosException() { public NacosException() {
} }
@ -40,13 +45,32 @@ public class NacosException extends Exception {
this.errMsg = errMsg; this.errMsg = errMsg;
} }
public NacosException(int errCode, Throwable throwable) {
super(throwable);
this.errCode = errCode;
setCauseThrowable(throwable);
}
public NacosException(int errCode, String errMsg, Throwable throwable) {
super(errMsg, throwable);
this.errCode = errCode;
this.errMsg = errMsg;
setCauseThrowable(throwable);
}
public int getErrCode() { public int getErrCode() {
return errCode; return errCode;
} }
public String getErrMsg() { public String getErrMsg() {
if (!StringUtils.isBlank(this.errMsg)) {
return errMsg; return errMsg;
} }
if (this.causeThrowable != null) {
return causeThrowable.getMessage();
}
return Constants.NULL;
}
public void setErrCode(int errCode) { public void setErrCode(int errCode) {
this.errCode = errCode; this.errCode = errCode;
@ -56,9 +80,20 @@ public class NacosException extends Exception {
this.errMsg = errMsg; this.errMsg = errMsg;
} }
public void setCauseThrowable(Throwable throwable) {
this.causeThrowable = getCauseThrowable(throwable);
}
private Throwable getCauseThrowable(Throwable t) {
if (t.getCause() == null) {
return t;
}
return getCauseThrowable(t.getCause());
}
@Override @Override
public String toString() { public String toString() {
return "ErrCode:" + errCode + ",ErrMsg:" + errMsg; return "ErrCode:" + getErrCode() + ", ErrMsg:" + getErrMsg();
} }
/** /**

View File

@ -34,7 +34,7 @@ public class NamingFactory {
NamingService vendorImpl = (NamingService)constructor.newInstance(serverList); NamingService vendorImpl = (NamingService)constructor.newInstance(serverList);
return vendorImpl; return vendorImpl;
} catch (Throwable e) { } catch (Throwable e) {
throw new NacosException(-400, e.getMessage()); throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
} }
} }
@ -45,7 +45,7 @@ public class NamingFactory {
NamingService vendorImpl = (NamingService)constructor.newInstance(properties); NamingService vendorImpl = (NamingService)constructor.newInstance(properties);
return vendorImpl; return vendorImpl;
} catch (Throwable e) { } catch (Throwable e) {
throw new NacosException(-400, e.getMessage()); throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
} }
} }
} }

View File

@ -34,7 +34,7 @@ public class NamingMaintainFactory {
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(serverList); NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(serverList);
return vendorImpl; return vendorImpl;
} catch (Throwable e) { } catch (Throwable e) {
throw new NacosException(-400, e.getMessage()); throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
} }
} }
@ -45,7 +45,7 @@ public class NamingMaintainFactory {
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(properties); NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(properties);
return vendorImpl; return vendorImpl;
} catch (Throwable e) { } catch (Throwable e) {
throw new NacosException(-400, e.getMessage()); throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
} }
} }

View File

@ -19,12 +19,10 @@ import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.listener.EventListener; import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView; import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.api.naming.pojo.Service;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo; import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.api.selector.AbstractSelector; import com.alibaba.nacos.api.selector.AbstractSelector;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Naming Service * Naming Service

View File

@ -27,4 +27,10 @@ public class PreservedMetadataKeys {
* The key to indicate the registry source of service instance, such as Dubbo, SpringCloud, etc. * The key to indicate the registry source of service instance, such as Dubbo, SpringCloud, etc.
*/ */
public static final String REGISTER_SOURCE = "preserved.register.source"; public static final String REGISTER_SOURCE = "preserved.register.source";
public static final String HEART_BEAT_TIMEOUT = "preserved.heart.beat.timeout";
public static final String IP_DELETE_TIMEOUT = "preserved.ip.delete.timeout";
public static final String HEART_BEAT_INTERVAL = "preserved.heart.beat.interval";
} }

View File

@ -16,11 +16,15 @@
package com.alibaba.nacos.api.naming.pojo; package com.alibaba.nacos.api.naming.pojo;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static com.alibaba.nacos.api.common.Constants.NUMBER_PATTERN;
/** /**
* Instance * Instance
* *
@ -193,4 +197,27 @@ public class Instance {
return str1 == null ? str2 == null : str1.equals(str2); return str1 == null ? str2 == null : str1.equals(str2);
} }
public long getInstanceHeartBeatInterval() {
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.HEART_BEAT_INTERVAL, Constants.DEFAULT_HEART_BEAT_INTERVAL);
}
public long getInstanceHeartBeatTimeOut() {
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, Constants.DEFAULT_HEART_BEAT_TIMEOUT);
}
public long getIpDeleteTimeout() {
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.IP_DELETE_TIMEOUT, Constants.DEFAULT_IP_DELETE_TIMEOUT);
}
private long getMetaDataByKeyWithDefault( String key, long defaultValue) {
if (getMetadata() == null || getMetadata().isEmpty()) {
return defaultValue;
}
String value = getMetadata().get(key);
if (!StringUtils.isEmpty(value) && value.matches(NUMBER_PATTERN)) {
return Long.valueOf(value);
}
return defaultValue;
}
} }

View File

@ -111,6 +111,11 @@
<artifactId>simpleclient</artifactId> <artifactId>simpleclient</artifactId>
<version>0.5.0</version> <version>0.5.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

View File

@ -27,7 +27,6 @@ import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
import com.alibaba.nacos.client.config.http.HttpAgent; import com.alibaba.nacos.client.config.http.HttpAgent;
import com.alibaba.nacos.client.config.http.MetricsHttpAgent; import com.alibaba.nacos.client.config.http.MetricsHttpAgent;
import com.alibaba.nacos.client.config.http.ServerHttpAgent; import com.alibaba.nacos.client.config.http.ServerHttpAgent;
import com.alibaba.nacos.client.config.impl.CacheData;
import com.alibaba.nacos.client.config.impl.ClientWorker; import com.alibaba.nacos.client.config.impl.ClientWorker;
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult; import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor; import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor;

View File

@ -78,7 +78,7 @@ public class ServerHttpAgent implements HttpAgent {
newHeaders.addAll(headers); newHeaders.addAll(headers);
} }
HttpResult result = HttpSimpleClient.httpGet( HttpResult result = HttpSimpleClient.httpGet(
getUrl(currentServerAddr, path, isSSL), newHeaders, paramValues, encoding, getUrl(currentServerAddr, path), newHeaders, paramValues, encoding,
readTimeoutMs, isSSL); readTimeoutMs, isSSL);
if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR
|| result.code == HttpURLConnection.HTTP_BAD_GATEWAY || result.code == HttpURLConnection.HTTP_BAD_GATEWAY
@ -133,7 +133,7 @@ public class ServerHttpAgent implements HttpAgent {
} }
HttpResult result = HttpSimpleClient.httpPost( HttpResult result = HttpSimpleClient.httpPost(
getUrl(currentServerAddr, path, isSSL), newHeaders, paramValues, encoding, getUrl(currentServerAddr, path), newHeaders, paramValues, encoding,
readTimeoutMs, isSSL); readTimeoutMs, isSSL);
if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR
|| result.code == HttpURLConnection.HTTP_BAD_GATEWAY || result.code == HttpURLConnection.HTTP_BAD_GATEWAY
@ -186,7 +186,7 @@ public class ServerHttpAgent implements HttpAgent {
newHeaders.addAll(headers); newHeaders.addAll(headers);
} }
HttpResult result = HttpSimpleClient.httpDelete( HttpResult result = HttpSimpleClient.httpDelete(
getUrl(currentServerAddr, path, isSSL), newHeaders, paramValues, encoding, getUrl(currentServerAddr, path), newHeaders, paramValues, encoding,
readTimeoutMs, isSSL); readTimeoutMs, isSSL);
if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR
|| result.code == HttpURLConnection.HTTP_BAD_GATEWAY || result.code == HttpURLConnection.HTTP_BAD_GATEWAY
@ -223,12 +223,8 @@ public class ServerHttpAgent implements HttpAgent {
throw new ConnectException("no available server"); throw new ConnectException("no available server");
} }
private String getUrl(String serverAddr, String relativePath, boolean isSSL) { private String getUrl(String serverAddr, String relativePath) {
String httpPrefix = "http://"; return serverAddr + "/" + serverListMgr.getContentPath() + relativePath;
if (isSSL) {
httpPrefix = "https://";
}
return httpPrefix + serverAddr + "/" + serverListMgr.getContentPath() + relativePath;
} }
public static String getAppname() { public static String getAppname() {

View File

@ -237,7 +237,7 @@ public class ClientWorker {
"[%s] [sub-server] get server config exception, dataId=%s, group=%s, tenant=%s", agent.getName(), "[%s] [sub-server] get server config exception, dataId=%s, group=%s, tenant=%s", agent.getName(),
dataId, group, tenant); dataId, group, tenant);
LOGGER.error(message, e); LOGGER.error(message, e);
throw new NacosException(NacosException.SERVER_ERROR, e.getMessage()); throw new NacosException(NacosException.SERVER_ERROR, e);
} }
switch (result.code) { switch (result.code) {

View File

@ -33,11 +33,11 @@ import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.config.impl.EventDispatcher.ServerlistChangeEvent; import com.alibaba.nacos.client.config.impl.EventDispatcher.ServerlistChangeEvent;
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult; import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
import com.alibaba.nacos.client.config.utils.IOUtils; import com.alibaba.nacos.client.config.utils.IOUtils;
import com.alibaba.nacos.client.utils.EnvUtil;
import com.alibaba.nacos.client.utils.LogUtils; import com.alibaba.nacos.client.identify.Constants;
import com.alibaba.nacos.client.utils.ParamUtil; import com.alibaba.nacos.client.utils.*;
import com.alibaba.nacos.client.utils.StringUtils; import org.slf4j.Logger;
import com.alibaba.nacos.client.utils.TemplateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -49,6 +49,8 @@ import org.slf4j.Logger;
public class ServerListManager { public class ServerListManager {
private static final Logger LOGGER = LogUtils.logger(ServerListManager.class); private static final Logger LOGGER = LogUtils.logger(ServerListManager.class);
private static final String HTTPS = "https://";
private static final String HTTP = "http://";
public ServerListManager() { public ServerListManager() {
isFixed = false; isFixed = false;
@ -128,12 +130,16 @@ public class ServerListManager {
isFixed = true; isFixed = true;
List<String> serverAddrs = new ArrayList<String>(); List<String> serverAddrs = new ArrayList<String>();
String[] serverAddrsArr = serverAddrsStr.split(","); String[] serverAddrsArr = serverAddrsStr.split(",");
for (String serverAddr : serverAddrsArr) { for (String serverAddr: serverAddrsArr) {
if (serverAddr.startsWith(HTTPS) || serverAddr.startsWith(HTTP)) {
serverAddrs.add(serverAddr);
} else {
String[] serverAddrArr = serverAddr.split(":"); String[] serverAddrArr = serverAddr.split(":");
if (serverAddrArr.length == 1) { if (serverAddrArr.length == 1) {
serverAddrs.add(serverAddrArr[0] + ":" + ParamUtil.getDefaultServerPort()); serverAddrs.add(HTTP + serverAddrArr[0] + ":" + ParamUtil.getDefaultServerPort());
} else { } else {
serverAddrs.add(serverAddr); serverAddrs.add(HTTP + serverAddr);
}
} }
} }
serverUrls = serverAddrs; serverUrls = serverAddrs;
@ -325,6 +331,7 @@ public class ServerListManager {
String split = ""; String split = "";
for (String serverIp : serverIps) { for (String serverIp : serverIps) {
sb.append(split); sb.append(split);
serverIp = serverIp.replaceAll("http(s)?://", "");
sb.append(serverIp.replaceAll(":", "_")); sb.append(serverIp.replaceAll(":", "_"));
split = "-"; split = "-";
} }

View File

@ -24,5 +24,5 @@ public interface CredentialListener {
/** /**
* update Credential * update Credential
*/ */
public void onUpdateCredential(); void onUpdateCredential();
} }

View File

@ -26,12 +26,12 @@ public interface SpasCredential {
* *
* @return AccessKey * @return AccessKey
*/ */
public String getAccessKey(); String getAccessKey();
/** /**
* get SecretKey * get SecretKey
* *
* @return SecretKey * @return SecretKey
*/ */
public String getSecretKey(); String getSecretKey();
} }

View File

@ -19,6 +19,7 @@ import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
import com.alibaba.nacos.api.naming.listener.EventListener; import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView; import com.alibaba.nacos.api.naming.pojo.ListView;
@ -39,6 +40,7 @@ import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* @author nkorange * @author nkorange
@ -46,6 +48,7 @@ import java.util.*;
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule") @SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
public class NacosNamingService implements NamingService { public class NacosNamingService implements NamingService {
private static final String DEFAULT_PORT = "8080"; private static final String DEFAULT_PORT = "8080";
private static final long DEFAULT_HEART_BEAT_INTERVAL = TimeUnit.SECONDS.toMillis(5);
/** /**
* Each Naming instance should have different namespace. * Each Naming instance should have different namespace.
@ -193,6 +196,8 @@ public class NacosNamingService implements NamingService {
beatInfo.setWeight(instance.getWeight()); beatInfo.setWeight(instance.getWeight());
beatInfo.setMetadata(instance.getMetadata()); beatInfo.setMetadata(instance.getMetadata());
beatInfo.setScheduled(false); beatInfo.setScheduled(false);
long instanceInterval = instance.getInstanceHeartBeatInterval();
beatInfo.setPeriod(instanceInterval == 0 ? DEFAULT_HEART_BEAT_INTERVAL : instanceInterval);
beatReactor.addBeatInfo(NamingUtils.getGroupedName(serviceName, groupName), beatInfo); beatReactor.addBeatInfo(NamingUtils.getGroupedName(serviceName, groupName), beatInfo);
} }
@ -200,6 +205,7 @@ public class NacosNamingService implements NamingService {
serverProxy.registerService(NamingUtils.getGroupedName(serviceName, groupName), groupName, instance); serverProxy.registerService(NamingUtils.getGroupedName(serviceName, groupName), groupName, instance);
} }
@Override @Override
public void deregisterInstance(String serviceName, String ip, int port) throws NacosException { public void deregisterInstance(String serviceName, String ip, int port) throws NacosException {
deregisterInstance(serviceName, ip, port, Constants.DEFAULT_CLUSTER_NAME); deregisterInstance(serviceName, ip, port, Constants.DEFAULT_CLUSTER_NAME);

View File

@ -31,6 +31,8 @@ public class BeatInfo {
private String cluster; private String cluster;
private Map<String, String> metadata; private Map<String, String> metadata;
private volatile boolean scheduled; private volatile boolean scheduled;
private volatile long period;
private volatile boolean stopped;
@Override @Override
public String toString() { public String toString() {
@ -92,4 +94,20 @@ public class BeatInfo {
public void setScheduled(boolean scheduled) { public void setScheduled(boolean scheduled) {
this.scheduled = scheduled; this.scheduled = scheduled;
} }
public long getPeriod() {
return period;
}
public void setPeriod(long period) {
this.period = period;
}
public boolean isStopped() {
return stopped;
}
public void setStopped(boolean stopped) {
this.stopped = stopped;
}
} }

View File

@ -54,48 +54,27 @@ public class BeatReactor {
return thread; return thread;
} }
}); });
executorService.schedule(new BeatProcessor(), 0, TimeUnit.MILLISECONDS);
} }
public void addBeatInfo(String serviceName, BeatInfo beatInfo) { public void addBeatInfo(String serviceName, BeatInfo beatInfo) {
NAMING_LOGGER.info("[BEAT] adding beat: {} to beat map.", beatInfo); NAMING_LOGGER.info("[BEAT] adding beat: {} to beat map.", beatInfo);
dom2Beat.put(buildKey(serviceName, beatInfo.getIp(), beatInfo.getPort()), beatInfo); dom2Beat.put(buildKey(serviceName, beatInfo.getIp(), beatInfo.getPort()), beatInfo);
executorService.schedule(new BeatTask(beatInfo), 0, TimeUnit.MILLISECONDS);
MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size()); MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size());
} }
public void removeBeatInfo(String serviceName, String ip, int port) { public void removeBeatInfo(String serviceName, String ip, int port) {
NAMING_LOGGER.info("[BEAT] removing beat: {}:{}:{} from beat map.", serviceName, ip, port); NAMING_LOGGER.info("[BEAT] removing beat: {}:{}:{} from beat map.", serviceName, ip, port);
dom2Beat.remove(buildKey(serviceName, ip, port)); BeatInfo beatInfo = dom2Beat.remove(buildKey(serviceName, ip, port));
beatInfo.setStopped(true);
MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size()); MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size());
} }
public String buildKey(String serviceName, String ip, int port) { private String buildKey(String serviceName, String ip, int port) {
return serviceName + Constants.NAMING_INSTANCE_ID_SPLITTER return serviceName + Constants.NAMING_INSTANCE_ID_SPLITTER
+ ip + Constants.NAMING_INSTANCE_ID_SPLITTER + port; + ip + Constants.NAMING_INSTANCE_ID_SPLITTER + port;
} }
class BeatProcessor implements Runnable {
@Override
public void run() {
try {
for (Map.Entry<String, BeatInfo> entry : dom2Beat.entrySet()) {
BeatInfo beatInfo = entry.getValue();
if (beatInfo.isScheduled()) {
continue;
}
beatInfo.setScheduled(true);
executorService.schedule(new BeatTask(beatInfo), 0, TimeUnit.MILLISECONDS);
}
} catch (Exception e) {
NAMING_LOGGER.error("[CLIENT-BEAT] Exception while scheduling beat.", e);
} finally {
executorService.schedule(this, clientBeatInterval, TimeUnit.MILLISECONDS);
}
}
}
class BeatTask implements Runnable { class BeatTask implements Runnable {
BeatInfo beatInfo; BeatInfo beatInfo;
@ -107,10 +86,11 @@ public class BeatReactor {
@Override @Override
public void run() { public void run() {
long result = serverProxy.sendBeat(beatInfo); long result = serverProxy.sendBeat(beatInfo);
beatInfo.setScheduled(false); if (beatInfo.isStopped()) {
if (result > 0) { return;
clientBeatInterval = result;
} }
long nextTime = result > 0 ? result : beatInfo.getPeriod();
executorService.schedule(new BeatTask(beatInfo), nextTime, TimeUnit.MILLISECONDS);
} }
} }
} }

View File

@ -29,6 +29,7 @@ import com.alibaba.nacos.api.selector.AbstractSelector;
import com.alibaba.nacos.api.selector.ExpressionSelector; import com.alibaba.nacos.api.selector.ExpressionSelector;
import com.alibaba.nacos.api.selector.SelectorType; import com.alibaba.nacos.api.selector.SelectorType;
import com.alibaba.nacos.client.config.impl.SpasAdapter; import com.alibaba.nacos.client.config.impl.SpasAdapter;
import com.alibaba.nacos.client.identify.Constants;
import com.alibaba.nacos.client.monitor.MetricsMonitor; import com.alibaba.nacos.client.monitor.MetricsMonitor;
import com.alibaba.nacos.client.naming.beat.BeatInfo; import com.alibaba.nacos.client.naming.beat.BeatInfo;
import com.alibaba.nacos.client.naming.utils.*; import com.alibaba.nacos.client.naming.utils.*;
@ -397,12 +398,14 @@ public class NamingProxy {
List<String> headers = builderHeaders(); List<String> headers = builderHeaders();
String url; String url;
if (curServer.startsWith(UtilAndComs.HTTPS) || curServer.startsWith(UtilAndComs.HTTP)) {
url = curServer + api;
} else {
if (!curServer.contains(UtilAndComs.SERVER_ADDR_IP_SPLITER)) { if (!curServer.contains(UtilAndComs.SERVER_ADDR_IP_SPLITER)) {
curServer = curServer + UtilAndComs.SERVER_ADDR_IP_SPLITER + serverPort; curServer = curServer + UtilAndComs.SERVER_ADDR_IP_SPLITER + serverPort;
} }
url = HttpClient.getPrefix() + curServer + api; url = HttpClient.getPrefix() + curServer + api;
}
HttpClient.HttpResult result = HttpClient.request(url, headers, params, UtilAndComs.ENCODING, method); HttpClient.HttpResult result = HttpClient.request(url, headers, params, UtilAndComs.ENCODING, method);
end = System.currentTimeMillis(); end = System.currentTimeMillis();
@ -418,8 +421,8 @@ public class NamingProxy {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
throw new NacosException(NacosException.SERVER_ERROR, "failed to req API:" + HttpClient.getPrefix() + curServer throw new NacosException(NacosException.SERVER_ERROR, "failed to req API:"
+ api + ". code:" + curServer + api + ". code:"
+ result.code + " msg: " + result.content); + result.code + " msg: " + result.content);
} }

View File

@ -142,7 +142,7 @@ public class CollectionUtils {
return (coll == null || coll.isEmpty()); return (coll == null || coll.isEmpty());
} }
private static final int getFreq(final Object obj, final Map freqMap) { private static int getFreq(final Object obj, final Map freqMap) {
Integer count = (Integer)freqMap.get(obj); Integer count = (Integer)freqMap.get(obj);
if (count != null) { if (count != null) {
return count.intValue(); return count.intValue();

View File

@ -37,7 +37,7 @@ public class InitUtils {
* @param properties * @param properties
* @return * @return
*/ */
public static final String initNamespaceForNaming(Properties properties) { public static String initNamespaceForNaming(Properties properties) {
String tmpNamespace = null; String tmpNamespace = null;
@ -90,7 +90,7 @@ public class InitUtils {
return tmpNamespace; return tmpNamespace;
} }
public static final void initWebRootContext() { public static void initWebRootContext() {
// support the web context with ali-yun if the app deploy by EDAS // support the web context with ali-yun if the app deploy by EDAS
final String webContext = System.getProperty(SystemPropertyKeyConst.NAMING_WEB_CONTEXT); final String webContext = System.getProperty(SystemPropertyKeyConst.NAMING_WEB_CONTEXT);
TemplateUtils.stringNotEmptyAndThenExecute(webContext, new Runnable() { TemplateUtils.stringNotEmptyAndThenExecute(webContext, new Runnable() {
@ -105,7 +105,7 @@ public class InitUtils {
}); });
} }
public static final String initEndpoint(final Properties properties) { public static String initEndpoint(final Properties properties) {
if (properties == null) { if (properties == null) {
return ""; return "";

View File

@ -55,4 +55,9 @@ public class UtilAndComs {
public static final int DEFAULT_POLLING_THREAD_COUNT = Runtime.getRuntime() public static final int DEFAULT_POLLING_THREAD_COUNT = Runtime.getRuntime()
.availableProcessors() > 1 ? Runtime.getRuntime().availableProcessors() / 2 .availableProcessors() > 1 ? Runtime.getRuntime().availableProcessors() / 2
: 1; : 1;
public static final String HTTP = "http://";
public static final String HTTPS = "https://";
} }

View File

@ -23,7 +23,7 @@ import java.util.concurrent.Callable;
*/ */
public class TemplateUtils { public class TemplateUtils {
public static final void stringNotEmptyAndThenExecute(String source, Runnable runnable) { public static void stringNotEmptyAndThenExecute(String source, Runnable runnable) {
if (StringUtils.isNotEmpty(source)) { if (StringUtils.isNotEmpty(source)) {
@ -35,7 +35,7 @@ public class TemplateUtils {
} }
} }
public static final String stringEmptyAndThenExecute(String source, Callable<String> callable) { public static String stringEmptyAndThenExecute(String source, Callable<String> callable) {
if (StringUtils.isEmpty(source)) { if (StringUtils.isEmpty(source)) {
@ -49,7 +49,7 @@ public class TemplateUtils {
return source.trim(); return source.trim();
} }
public static final String stringBlankAndThenExecute(String source, Callable<String> callable) { public static String stringBlankAndThenExecute(String source, Callable<String> callable) {
if (StringUtils.isBlank(source)) { if (StringUtils.isBlank(source)) {

View File

@ -0,0 +1,57 @@
package com.alibaba.nacos.client;
import com.alibaba.nacos.client.naming.beat.BeatInfo;
import com.alibaba.nacos.client.naming.beat.BeatReactor;
import com.alibaba.nacos.client.naming.net.NamingProxy;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.concurrent.ScheduledThreadPoolExecutor;
/**
* @author caoyixiong
*/
@RunWith(MockitoJUnitRunner.class)
public class BeatReactorTest {
@Mock
private NamingProxy namingProxy;
@Test
public void test() throws NoSuchFieldException, IllegalAccessException, InterruptedException {
BeatReactor beatReactor = new BeatReactor(namingProxy);
BeatInfo beatInfo = new BeatInfo();
beatInfo.setServiceName("test");
beatInfo.setIp("11.11.11.11");
beatInfo.setPort(1234);
beatInfo.setCluster("clusterName");
beatInfo.setWeight(1);
beatInfo.setMetadata(new HashMap<String, String>());
beatInfo.setScheduled(false);
beatInfo.setPeriod(1000L);
Mockito.doReturn(0L).when(namingProxy).sendBeat(beatInfo);
beatReactor.addBeatInfo("testService", beatInfo);
Assert.assertEquals(1, getActiveThread(beatReactor));
Thread.sleep(1100L);
beatReactor.removeBeatInfo("testService", beatInfo.getIp(), beatInfo.getPort());
Thread.sleep(3100L);
Assert.assertEquals(0, getActiveThread(beatReactor));
}
private int getActiveThread(BeatReactor beatReactor) throws NoSuchFieldException, IllegalAccessException {
Field field = BeatReactor.class.getDeclaredField("executorService");
field.setAccessible(true);
ScheduledThreadPoolExecutor scheduledExecutorService = (ScheduledThreadPoolExecutor) field.get(beatReactor);
return scheduledExecutorService.getQueue().size();
}
}

View File

@ -17,11 +17,9 @@ package com.alibaba.nacos.client;
import com.alibaba.nacos.api.NacosFactory; import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.api.selector.ExpressionSelector;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;

View File

@ -34,36 +34,9 @@ import javax.servlet.http.HttpServletRequest;
@RequestMapping(UtilsAndCommons.NACOS_CMDB_CONTEXT + "/ops") @RequestMapping(UtilsAndCommons.NACOS_CMDB_CONTEXT + "/ops")
public class OperationController { public class OperationController {
@Autowired
private SwitchAndOptions switches;
@Autowired @Autowired
private CmdbProvider cmdbProvider; private CmdbProvider cmdbProvider;
@RequestMapping(value = "/switch", method = RequestMethod.PUT)
public String updateSwitch(HttpServletRequest request) throws Exception {
String entry = WebUtils.required(request, "entry");
String value = WebUtils.required(request, "value");
switch (entry) {
case "dumpTaskInterval":
switches.setDumpTaskInterval(Integer.parseInt(value));
break;
case "eventTaskInterval":
switches.setEventTaskInterval(Integer.parseInt(value));
break;
case "loadDataAtStart":
switches.setLoadDataAtStart(Boolean.parseBoolean(value));
break;
case "labelTaskInterval":
switches.setLabelTaskInterval(Integer.parseInt(value));
default:
break;
}
return "ok";
}
@RequestMapping(value = "/label", method = RequestMethod.GET) @RequestMapping(value = "/label", method = RequestMethod.GET)
public String queryLabel(HttpServletRequest request) throws Exception { public String queryLabel(HttpServletRequest request) throws Exception {
String entry = WebUtils.required(request, "entry"); String entry = WebUtils.required(request, "entry");

View File

@ -25,47 +25,31 @@ import org.springframework.stereotype.Component;
@Component @Component
public class SwitchAndOptions { public class SwitchAndOptions {
@Value("${nacos.cmdb.dumpTaskInterval}") @Value("${nacos.cmdb.dumpTaskInterval:3600}")
private int dumpTaskInterval; private int dumpTaskInterval;
@Value("${nacos.cmdb.eventTaskInterval}") @Value("${nacos.cmdb.eventTaskInterval:10}")
private int eventTaskInterval; private int eventTaskInterval;
@Value("${nacos.cmdb.labelTaskInterval}") @Value("${nacos.cmdb.labelTaskInterval:300}")
private int labelTaskInterval; private int labelTaskInterval;
@Value("${nacos.cmdb.loadDataAtStart}") @Value("${nacos.cmdb.loadDataAtStart:false}")
private boolean loadDataAtStart; private boolean loadDataAtStart;
public int getDumpTaskInterval() { public int getDumpTaskInterval() {
return dumpTaskInterval; return dumpTaskInterval;
} }
public void setDumpTaskInterval(int dumpTaskInterval) {
this.dumpTaskInterval = dumpTaskInterval;
}
public int getEventTaskInterval() { public int getEventTaskInterval() {
return eventTaskInterval; return eventTaskInterval;
} }
public void setEventTaskInterval(int eventTaskInterval) {
this.eventTaskInterval = eventTaskInterval;
}
public int getLabelTaskInterval() { public int getLabelTaskInterval() {
return labelTaskInterval; return labelTaskInterval;
} }
public void setLabelTaskInterval(int labelTaskInterval) {
this.labelTaskInterval = labelTaskInterval;
}
public boolean isLoadDataAtStart() { public boolean isLoadDataAtStart() {
return loadDataAtStart; return loadDataAtStart;
} }
public void setLoadDataAtStart(boolean loadDataAtStart) {
this.loadDataAtStart = loadDataAtStart;
}
} }

View File

@ -25,7 +25,6 @@ import org.springframework.stereotype.Service;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog; import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;

View File

@ -443,8 +443,6 @@ public class PersistService {
} }
} }
;
static final class TenantInfoRowMapper implements RowMapper<TenantInfo> { static final class TenantInfoRowMapper implements RowMapper<TenantInfo> {
@Override @Override
public TenantInfo mapRow(ResultSet rs, int rowNum) throws SQLException { public TenantInfo mapRow(ResultSet rs, int rowNum) throws SQLException {

View File

@ -113,7 +113,7 @@ public class EventDispatcher {
static final CopyOnWriteArrayList<Entry> LISTENER_HUB = new CopyOnWriteArrayList<Entry>(); static final CopyOnWriteArrayList<Entry> LISTENER_HUB = new CopyOnWriteArrayList<Entry>();
static public interface Event { public interface Event {
} }
static public abstract class AbstractEventListener { static public abstract class AbstractEventListener {

View File

@ -25,6 +25,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration @WebAppConfiguration
@ -45,11 +47,11 @@ public class AggrWhitelistTest {
list.add("com.taobao.tae.AppListOnGrid-*"); list.add("com.taobao.tae.AppListOnGrid-*");
service.compile(list); service.compile(list);
assertEquals(false, service.isAggrDataId("com.abc")); assertFalse(service.isAggrDataId("com.abc"));
assertEquals(false, service.isAggrDataId("com.taobao.jiuren")); assertFalse(service.isAggrDataId("com.taobao.jiuren"));
assertEquals(false, service.isAggrDataId("com.taobao.jiurenABC")); assertFalse(service.isAggrDataId("com.taobao.jiurenABC"));
assertEquals(true, service.isAggrDataId("com.taobao.jiuren.abc")); assertTrue(service.isAggrDataId("com.taobao.jiuren.abc"));
assertEquals(true, service.isAggrDataId("NS_NACOS_SUBSCRIPTION_TOPIC_abc")); assertTrue(service.isAggrDataId("NS_NACOS_SUBSCRIPTION_TOPIC_abc"));
assertEquals(true, service.isAggrDataId("com.taobao.tae.AppListOnGrid-abc")); assertTrue(service.isAggrDataId("com.taobao.tae.AppListOnGrid-abc"));
} }
} }

View File

@ -22,7 +22,6 @@ import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import javax.servlet.ServletContext;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -7,8 +7,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.*;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
@WebAppConfiguration @WebAppConfiguration

View File

@ -16,6 +16,8 @@
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -31,19 +33,19 @@ public class SimpleReadWriteLockTest {
@Test @Test
public void test_双重读锁_全部释放_加写锁() { public void test_双重读锁_全部释放_加写锁() {
SimpleReadWriteLock lock = new SimpleReadWriteLock(); SimpleReadWriteLock lock = new SimpleReadWriteLock();
assertEquals(true, lock.tryReadLock()); assertTrue(lock.tryReadLock());
assertEquals(true, lock.tryReadLock()); assertTrue(lock.tryReadLock());
lock.releaseReadLock(); lock.releaseReadLock();
lock.releaseReadLock(); lock.releaseReadLock();
assertEquals(true, lock.tryWriteLock()); assertTrue(lock.tryWriteLock());
} }
@Test @Test
public void test_加写锁() { public void test_加写锁() {
SimpleReadWriteLock lock = new SimpleReadWriteLock(); SimpleReadWriteLock lock = new SimpleReadWriteLock();
assertEquals(true, lock.tryWriteLock()); assertTrue(lock.tryWriteLock());
lock.releaseWriteLock(); lock.releaseWriteLock();
} }
@ -51,26 +53,26 @@ public class SimpleReadWriteLockTest {
public void test_双重写锁() { public void test_双重写锁() {
SimpleReadWriteLock lock = new SimpleReadWriteLock(); SimpleReadWriteLock lock = new SimpleReadWriteLock();
assertEquals(true, lock.tryWriteLock()); assertTrue(lock.tryWriteLock());
assertEquals(false, lock.tryWriteLock()); assertFalse(lock.tryWriteLock());
} }
@Test @Test
public void test_先读锁后写锁() { public void test_先读锁后写锁() {
SimpleReadWriteLock lock = new SimpleReadWriteLock(); SimpleReadWriteLock lock = new SimpleReadWriteLock();
assertEquals(true, lock.tryReadLock()); assertTrue(lock.tryReadLock());
assertEquals(false, lock.tryWriteLock()); assertFalse(lock.tryWriteLock());
} }
@Test @Test
public void test_双重读锁_释放一个_加写锁失败() { public void test_双重读锁_释放一个_加写锁失败() {
SimpleReadWriteLock lock = new SimpleReadWriteLock(); SimpleReadWriteLock lock = new SimpleReadWriteLock();
assertEquals(true, lock.tryReadLock()); assertTrue(lock.tryReadLock());
assertEquals(true, lock.tryReadLock()); assertTrue(lock.tryReadLock());
lock.releaseReadLock(); lock.releaseReadLock();
assertEquals(false, lock.tryWriteLock()); assertFalse(lock.tryWriteLock());
} }
} }

View File

@ -18,8 +18,7 @@ package com.alibaba.nacos.console.controller;
import com.alibaba.nacos.console.config.WebSecurityConfig; import com.alibaba.nacos.console.config.WebSecurityConfig;
import com.alibaba.nacos.config.server.model.RestResult; import com.alibaba.nacos.config.server.model.RestResult;
import com.alibaba.nacos.console.utils.JwtTokenUtils; import com.alibaba.nacos.console.utils.JwtTokenUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;

View File

@ -35,8 +35,6 @@ public class NamespaceAllInfo extends Namespace {
public NamespaceAllInfo() { public NamespaceAllInfo() {
} }
;
public NamespaceAllInfo(String namespace, String namespaceShowName, int quota, int configCount, int type, public NamespaceAllInfo(String namespace, String namespaceShowName, int quota, int configCount, int type,
String namespaceDesc) { String namespaceDesc) {
super(namespace, namespaceShowName, quota, configCount, type); super(namespace, namespaceShowName, quota, configCount, type);

View File

@ -65,10 +65,4 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir # default current work dir
server.tomcat.basedir= server.tomcat.basedir=
nacos.naming.distro.taskDispatchThreadCount=1
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=false
nacos.naming.expireInstance=true

View File

@ -20,3 +20,6 @@ export const LANGUAGE_SWITCH = 'LANGUAGE_SWITCH';
export const REDUX_DEVTOOLS = '__REDUX_DEVTOOLS_EXTENSION__'; export const REDUX_DEVTOOLS = '__REDUX_DEVTOOLS_EXTENSION__';
export const GET_STATE = 'GET_STATE'; export const GET_STATE = 'GET_STATE';
export const GET_SUBSCRIBERS = 'GET_SUBSCRIBERS';
export const REMOVE_SUBSCRIBERS = 'REMOVE_SUBSCRIBERS';

View File

@ -41,6 +41,7 @@ import ListeningToQuery from './pages/ConfigurationManagement/ListeningToQuery';
import ConfigurationManagement from './pages/ConfigurationManagement/ConfigurationManagement'; import ConfigurationManagement from './pages/ConfigurationManagement/ConfigurationManagement';
import ServiceList from './pages/ServiceManagement/ServiceList'; import ServiceList from './pages/ServiceManagement/ServiceList';
import ServiceDetail from './pages/ServiceManagement/ServiceDetail'; import ServiceDetail from './pages/ServiceManagement/ServiceDetail';
import SubscriberList from './pages/ServiceManagement/SubscriberList';
import ClusterNodeList from './pages/ClusterManagement/ClusterNodeList'; import ClusterNodeList from './pages/ClusterManagement/ClusterNodeList';
import reducers from './reducers'; import reducers from './reducers';
@ -82,6 +83,7 @@ const MENU = [
{ path: '/configurationManagement', component: ConfigurationManagement }, { path: '/configurationManagement', component: ConfigurationManagement },
{ path: '/serviceManagement', component: ServiceList }, { path: '/serviceManagement', component: ServiceList },
{ path: '/serviceDetail', component: ServiceDetail }, { path: '/serviceDetail', component: ServiceDetail },
{ path: '/subscriberList', component: SubscriberList },
{ path: '/clusterManagement', component: ClusterNodeList }, { path: '/clusterManagement', component: ClusterNodeList },
]; ];

View File

@ -83,7 +83,7 @@ class Header extends React.Component {
rel="noopener noreferrer" rel="noopener noreferrer"
> >
<img <img
src="img/TB118jPv_mWBKNjSZFBXXXxUFXa-2000-390.svg" src="img/logo-2000-390.svg"
className="logo" className="logo"
alt={siteConfig.name} alt={siteConfig.name}
title={siteConfig.name} title={siteConfig.name}

View File

@ -44,6 +44,7 @@ const I18N_CONF = {
listeningToQuery: 'Listening Query', listeningToQuery: 'Listening Query',
serviceManagementVirtual: 'ServiceManagement', serviceManagementVirtual: 'ServiceManagement',
serviceManagement: 'Service List', serviceManagement: 'Service List',
subscriberList: 'Subscribers',
serviceDetail: 'Service Details', serviceDetail: 'Service Details',
namespace: 'Namespace', namespace: 'Namespace',
clusterManagementVirtual: 'ClusterManagement', clusterManagementVirtual: 'ClusterManagement',
@ -92,6 +93,19 @@ const I18N_CONF = {
promptDelete: 'Do you want to delete the service?', promptDelete: 'Do you want to delete the service?',
create: 'Create Service', create: 'Create Service',
}, },
SubscriberList: {
subscriberList: 'Subscriber List',
serviceName: 'Service Name',
serviceNamePlaceholder: 'Enter Service Name',
groupName: 'Group Name',
groupNamePlaceholder: 'Enter Group Name',
query: 'Search',
pubNoData: 'No results found.',
address: 'Address',
clientVersion: 'Client Version',
appName: 'Application Name',
searchServiceNamePrompt: 'Service name required!',
},
ClusterNodeList: { ClusterNodeList: {
clusterNodeList: 'Node List', clusterNodeList: 'Node List',
nodeIp: 'NodeIp', nodeIp: 'NodeIp',

View File

@ -44,6 +44,7 @@ const I18N_CONF = {
listeningToQuery: '监听查询', listeningToQuery: '监听查询',
serviceManagementVirtual: '服务管理', serviceManagementVirtual: '服务管理',
serviceManagement: '服务列表', serviceManagement: '服务列表',
subscriberList: '订阅者列表',
serviceDetail: '服务详情', serviceDetail: '服务详情',
namespace: '命名空间', namespace: '命名空间',
clusterManagementVirtual: '集群管理', clusterManagementVirtual: '集群管理',
@ -92,6 +93,19 @@ const I18N_CONF = {
promptDelete: '确定要删除当前服务吗', promptDelete: '确定要删除当前服务吗',
create: '创建服务', create: '创建服务',
}, },
SubscriberList: {
subscriberList: '订阅者列表',
serviceName: '服务名称',
serviceNamePlaceholder: '请输入服务名称',
groupName: '分组名称',
groupNamePlaceholder: '请输入分组名称',
query: '查询',
pubNoData: '没有数据',
address: '地址',
clientVersion: '客户端版本',
appName: '应用名',
searchServiceNamePrompt: '请输入服务名称',
},
ClusterNodeList: { ClusterNodeList: {
clusterNodeList: '节点列表', clusterNodeList: '节点列表',
nodeIp: '节点Ip', nodeIp: '节点Ip',

View File

@ -209,6 +209,21 @@ module.exports = {
}, },
], ],
}, },
{
isExtend: false,
name: '订阅者列表',
title: '订阅者列表',
isVirtual: false,
projectName: 'nacos',
serviceName: 'subscriberList',
link: 'subscriberList',
hasFusion: true,
template: '',
registerName: 'com.alibaba.nacos.page.subscriberList',
useRouter: false,
id: 'subscriberList',
children: [],
},
], ],
}, },
{ {

View File

@ -109,13 +109,7 @@ class ClusterNodeList extends React.Component {
render() { render() {
const { locale = {} } = this.props; const { locale = {} } = this.props;
const { const { pubNoData, clusterNodeList, nodeIp, nodeIpPlaceholder, query } = locale;
pubNoData,
clusterNodeList,
nodeIp,
nodeIpPlaceholder,
query,
} = locale;
const { keyword, nowNamespaceName, nowNamespaceId } = this.state; const { keyword, nowNamespaceName, nowNamespaceId } = this.state;
const { init, getValue } = this.field; const { init, getValue } = this.field;
this.init = init; this.init = init;
@ -159,7 +153,9 @@ class ClusterNodeList extends React.Component {
<FormItem label=""> <FormItem label="">
<Button <Button
type="primary" type="primary"
onClick={() => this.setState({ currentPage: 1 }, () => this.queryClusterStateList())} onClick={() =>
this.setState({ currentPage: 1 }, () => this.queryClusterStateList())
}
style={{ marginRight: 10 }} style={{ marginRight: 10 }}
> >
{query} {query}

View File

@ -17,7 +17,6 @@ import { request } from '../../../globalLib';
import { Dialog, Form, Input, Switch, Select, Message, ConfigProvider } from '@alifd/next'; import { Dialog, Form, Input, Switch, Select, Message, ConfigProvider } from '@alifd/next';
import { DIALOG_FORM_LAYOUT, METADATA_SEPARATOR, METADATA_ENTER } from './constant'; import { DIALOG_FORM_LAYOUT, METADATA_SEPARATOR, METADATA_ENTER } from './constant';
import MonacoEditor from 'components/MonacoEditor'; import MonacoEditor from 'components/MonacoEditor';
import { replaceEnter, processMetaData } from 'utils/nacosutil';
@ConfigProvider.config @ConfigProvider.config
class EditClusterDialog extends React.Component { class EditClusterDialog extends React.Component {
@ -42,7 +41,9 @@ class EditClusterDialog extends React.Component {
show(_editCluster) { show(_editCluster) {
let editCluster = _editCluster; let editCluster = _editCluster;
const { metadata = {} } = editCluster; const { metadata = {} } = editCluster;
editCluster.metadataText = processMetaData(METADATA_ENTER)(metadata); if (Object.keys(metadata).length) {
editCluster.metadataText = JSON.stringify(metadata, null, '\t');
}
this.setState({ this.setState({
editCluster, editCluster,
editClusterDialogVisible: true, editClusterDialogVisible: true,
@ -69,7 +70,7 @@ class EditClusterDialog extends React.Component {
data: { data: {
serviceName, serviceName,
clusterName: name, clusterName: name,
metadata: replaceEnter(METADATA_SEPARATOR)(metadataText), metadata: metadataText,
checkPort: defaultCheckPort, checkPort: defaultCheckPort,
useInstancePort4Check: useIPPort4Check, useInstancePort4Check: useIPPort4Check,
healthChecker: JSON.stringify(healthChecker), healthChecker: JSON.stringify(healthChecker),
@ -163,7 +164,7 @@ class EditClusterDialog extends React.Component {
]} ]}
<Form.Item label={`${locale.metadata}:`}> <Form.Item label={`${locale.metadata}:`}>
<MonacoEditor <MonacoEditor
language={'properties'} language="json"
width={'100%'} width={'100%'}
height={200} height={200}
value={metadataText} value={metadataText}

View File

@ -17,7 +17,6 @@ import { request } from '../../../globalLib';
import { Dialog, Form, Input, Switch, Message, ConfigProvider } from '@alifd/next'; import { Dialog, Form, Input, Switch, Message, ConfigProvider } from '@alifd/next';
import { DIALOG_FORM_LAYOUT, METADATA_ENTER, METADATA_SEPARATOR } from './constant'; import { DIALOG_FORM_LAYOUT, METADATA_ENTER, METADATA_SEPARATOR } from './constant';
import MonacoEditor from 'components/MonacoEditor'; import MonacoEditor from 'components/MonacoEditor';
import { replaceEnter, processMetaData } from 'utils/nacosutil';
@ConfigProvider.config @ConfigProvider.config
class EditInstanceDialog extends React.Component { class EditInstanceDialog extends React.Component {
@ -45,7 +44,7 @@ class EditInstanceDialog extends React.Component {
let editInstance = _editInstance; let editInstance = _editInstance;
const { metadata = {} } = editInstance; const { metadata = {} } = editInstance;
if (Object.keys(metadata).length) { if (Object.keys(metadata).length) {
editInstance.metadataText = processMetaData(METADATA_ENTER)(metadata); editInstance.metadataText = JSON.stringify(metadata, null, '\t');
} }
this.setState({ editInstance, editInstanceDialogVisible: true }); this.setState({ editInstance, editInstanceDialogVisible: true });
} }
@ -68,7 +67,7 @@ class EditInstanceDialog extends React.Component {
ephemeral, ephemeral,
weight, weight,
enabled, enabled,
metadata: replaceEnter(METADATA_SEPARATOR)(metadataText), metadata: metadataText,
}, },
dataType: 'text', dataType: 'text',
beforeSend: () => openLoading(), beforeSend: () => openLoading(),
@ -127,7 +126,7 @@ class EditInstanceDialog extends React.Component {
</Form.Item> </Form.Item>
<Form.Item label={`${locale.metadata}:`}> <Form.Item label={`${locale.metadata}:`}>
<MonacoEditor <MonacoEditor
language={'properties'} language="json"
width={'100%'} width={'100%'}
height={200} height={200}
value={editInstance.metadataText} value={editInstance.metadataText}

View File

@ -17,7 +17,6 @@ import { request } from '../../../globalLib';
import { Dialog, Form, Input, Select, Message, ConfigProvider } from '@alifd/next'; import { Dialog, Form, Input, Select, Message, ConfigProvider } from '@alifd/next';
import { DIALOG_FORM_LAYOUT, METADATA_SEPARATOR, METADATA_ENTER } from './constant'; import { DIALOG_FORM_LAYOUT, METADATA_SEPARATOR, METADATA_ENTER } from './constant';
import MonacoEditor from 'components/MonacoEditor'; import MonacoEditor from 'components/MonacoEditor';
import { replaceEnter, processMetaData } from 'utils/nacosutil';
@ConfigProvider.config @ConfigProvider.config
class EditServiceDialog extends React.Component { class EditServiceDialog extends React.Component {
@ -44,7 +43,7 @@ class EditServiceDialog extends React.Component {
let editService = _editService; let editService = _editService;
const { metadata = {}, name } = editService; const { metadata = {}, name } = editService;
if (Object.keys(metadata).length) { if (Object.keys(metadata).length) {
editService.metadataText = processMetaData(METADATA_ENTER)(metadata); editService.metadataText = JSON.stringify(metadata, null, '\t');
} }
this.setState({ editService, editServiceDialogVisible: true, isCreate: !name }); this.setState({ editService, editServiceDialogVisible: true, isCreate: !name });
} }
@ -85,7 +84,7 @@ class EditServiceDialog extends React.Component {
serviceName: name, serviceName: name,
groupName: groupName || 'DEFAULT_GROUP', groupName: groupName || 'DEFAULT_GROUP',
protectThreshold, protectThreshold,
metadata: replaceEnter(METADATA_SEPARATOR)(metadataText), metadata: metadataText,
selector: JSON.stringify(selector), selector: JSON.stringify(selector),
}, },
dataType: 'text', dataType: 'text',
@ -181,7 +180,7 @@ class EditServiceDialog extends React.Component {
</Form.Item> </Form.Item>
<Form.Item label={`${locale.metadata}:`} {...formItemLayout}> <Form.Item label={`${locale.metadata}:`} {...formItemLayout}>
<MonacoEditor <MonacoEditor
language={'properties'} language="json"
width={'100%'} width={'100%'}
height={200} height={200}
value={metadataText} value={metadataText}

View File

@ -18,7 +18,7 @@ import { Input, Button, Card, ConfigProvider, Form, Loading, Message } from '@al
import EditServiceDialog from './EditServiceDialog'; import EditServiceDialog from './EditServiceDialog';
import EditClusterDialog from './EditClusterDialog'; import EditClusterDialog from './EditClusterDialog';
import InstanceTable from './InstanceTable'; import InstanceTable from './InstanceTable';
import { getParameter, processMetaData } from 'utils/nacosutil'; import { getParameter } from 'utils/nacosutil';
import MonacoEditor from 'components/MonacoEditor'; import MonacoEditor from 'components/MonacoEditor';
import { MONACO_READONLY_OPTIONS, METADATA_ENTER } from './constant'; import { MONACO_READONLY_OPTIONS, METADATA_ENTER } from './constant';
import './ServiceDetail.scss'; import './ServiceDetail.scss';
@ -95,7 +95,10 @@ class ServiceDetail extends React.Component {
const { locale = {} } = this.props; const { locale = {} } = this.props;
const { serviceName, groupName, loading, service = {}, clusters } = this.state; const { serviceName, groupName, loading, service = {}, clusters } = this.state;
const { metadata = {}, selector = {} } = service; const { metadata = {}, selector = {} } = service;
const metadataText = processMetaData(METADATA_ENTER)(metadata); let metadataText = '';
if (Object.keys(metadata).length) {
metadataText = JSON.stringify(metadata, null, '\t');
}
return ( return (
<div className="main-container service-detail"> <div className="main-container service-detail">
<Loading <Loading
@ -140,7 +143,7 @@ class ServiceDetail extends React.Component {
</FormItem> </FormItem>
<FormItem label={`${locale.metadata}:`}> <FormItem label={`${locale.metadata}:`}>
<MonacoEditor <MonacoEditor
language={'properties'} language="json"
width={'100%'} width={'100%'}
height={200} height={200}
value={metadataText} value={metadataText}

View File

@ -0,0 +1,217 @@
/*
* 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.
*/
import React from 'react';
import PropTypes from 'prop-types';
import {
Button,
Field,
Form,
Grid,
Input,
Loading,
Pagination,
Table,
Dialog,
Message,
ConfigProvider,
} from '@alifd/next';
import { connect } from 'react-redux';
import { getSubscribers, removeSubscribers } from '../../../reducers/subscribers';
import { request } from '../../../globalLib';
import RegionGroup from '../../../components/RegionGroup';
import './SubscriberList.scss';
const FormItem = Form.Item;
const { Row, Col } = Grid;
const { Column } = Table;
@connect(
state => ({ subscriberData: state.subscribers }),
{ getSubscribers, removeSubscribers }
)
@ConfigProvider.config
class SubscriberList extends React.Component {
static displayName = 'SubscriberList';
static propTypes = {
locale: PropTypes.object,
getSubscribers: PropTypes.func,
removeSubscribers: PropTypes.func,
subscriberData: PropTypes.object,
};
constructor(props) {
super(props);
this.state = {
loading: false,
total: 0,
pageSize: 10,
pageNo: 1,
search: {
serviceName: '',
groupName: '',
},
};
this.field = new Field(this);
}
openLoading() {
this.setState({ loading: true });
}
closeLoading() {
this.setState({ loading: false });
}
querySubscriberList() {
const { searchServiceNamePrompt } = this.props.locale;
const { search, pageSize, pageNo, nowNamespaceId = '' } = this.state;
if (!search.serviceName) {
Message.error(searchServiceNamePrompt);
return;
}
this.props.getSubscribers({
...search,
pageSize,
pageNo,
namespaceId: nowNamespaceId,
});
}
switchNamespace = () => {
this.setState({ search: { serviceName: '', groupName: '' } });
this.props.removeSubscribers();
};
setNowNameSpace = (nowNamespaceName, nowNamespaceId) =>
this.setState({
nowNamespaceName,
nowNamespaceId,
});
render() {
const { locale = {}, subscriberData = {} } = this.props;
const { count = 0, subscribers = [] } = subscriberData;
const {
pubNoData,
subscriberList,
serviceName,
serviceNamePlaceholder,
groupName,
groupNamePlaceholder,
query,
} = locale;
const { search, nowNamespaceName, nowNamespaceId } = this.state;
const { init, getValue } = this.field;
this.init = init;
this.getValue = getValue;
return (
<div className="main-container subscriber-list">
<Loading
shape="flower"
style={{
position: 'relative',
width: '100%',
}}
visible={this.state.loading}
tip="Loading..."
color="#333"
>
<div style={{ marginTop: -15 }}>
<RegionGroup
setNowNameSpace={this.setNowNameSpace}
namespaceCallBack={this.switchNamespace}
/>
</div>
<h3 className="page-title">
<span className="title-item">{subscriberList}</span>
<span className="title-item">|</span>
<span className="title-item">{nowNamespaceName}</span>
<span className="title-item">{nowNamespaceId}</span>
</h3>
<Row
className="demo-row"
style={{
marginBottom: 10,
padding: 0,
}}
>
<Col span="24">
<Form inline field={this.field}>
<FormItem label={serviceName}>
<Input
placeholder={serviceNamePlaceholder}
style={{ width: 200 }}
value={search.serviceName}
onChange={serviceName => this.setState({ search: { ...search, serviceName } })}
onPressEnter={() =>
this.setState({ pageNo: 1 }, () => this.querySubscriberList())
}
/>
</FormItem>
<FormItem label={groupName}>
<Input
placeholder={groupNamePlaceholder}
style={{ width: 200 }}
value={search.groupName}
onChange={groupName => this.setState({ search: { ...search, groupName } })}
onPressEnter={() =>
this.setState({ pageNo: 1 }, () => this.querySubscriberList())
}
/>
</FormItem>
<FormItem label="">
<Button
type="primary"
onClick={() => this.setState({ pageNo: 1 }, () => this.querySubscriberList())}
style={{ marginRight: 10 }}
>
{query}
</Button>
</FormItem>
</Form>
</Col>
</Row>
<Row style={{ padding: 0 }}>
<Col span="24" style={{ padding: 0 }}>
<Table dataSource={subscribers} locale={{ empty: pubNoData }}>
<Column title={locale.address} dataIndex="addrStr" />
<Column title={locale.clientVersion} dataIndex="agent" />
<Column title={locale.appName} dataIndex="app" />
</Table>
</Col>
</Row>
{count > this.state.pageSize && (
<div
style={{
marginTop: 10,
textAlign: 'right',
}}
>
<Pagination
current={this.state.pageNo}
total={count}
pageSize={this.state.pageSize}
onChange={pageNo => this.setState({ pageNo }, () => this.querySubscriberList())}
/>
</div>
)}
</Loading>
</div>
);
}
}
export default SubscriberList;

View File

@ -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.
*/
.subscriber-list {
.page-title {
height: 30px;
width: 100%;
line-height: 30px;
margin: 0 0 20px;
padding: 0 0 0 10px;
border-left: 3px solid #09c;
color: #ccc;
}
.title-item {
font-size: 14px;
color: #000;
margin-right: 8px;
}
}

View File

@ -0,0 +1,16 @@
/*
* 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.
*/
import SubscriberList from './SubscriberList';
export default SubscriberList;

View File

@ -13,5 +13,6 @@
import locale from './locale'; import locale from './locale';
import base from './base'; import base from './base';
import subscribers from './subscribers';
export default { locale, base }; export default { locale, base, subscribers };

View File

@ -0,0 +1,41 @@
/*
* 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.
*/
import request from '../utils/request';
import { GET_SUBSCRIBERS, REMOVE_SUBSCRIBERS } from '../constants';
const initialState = {
subscribers: {},
};
const getSubscribers = params => dispatch =>
request.get('v1/ns/service/subscribers', { params }).then(data => {
dispatch({
type: GET_SUBSCRIBERS,
data,
});
});
const removeSubscribers = () => dispatch => dispatch({ type: REMOVE_SUBSCRIBERS });
export default (state = initialState, action) => {
switch (action.type) {
case GET_SUBSCRIBERS:
return { ...state, ...action.data };
case REMOVE_SUBSCRIBERS:
return { ...state, subscribers: {} };
default:
return state;
}
};
export { getSubscribers, removeSubscribers };

View File

@ -46,31 +46,3 @@ export const getParameter = (search, name) => {
const [, value = ''] = hit.split('='); const [, value = ''] = hit.split('=');
return value; return value;
}; };
/**
* 将回车符和空格替换
* @param {*} separator 替换符
*/
export const replaceEnter = (separator = ',') => text => {
if (typeof text !== 'string') {
return text;
}
return text
.replace(/\r\n/g, separator)
.replace(/[\r\n]/g, separator)
.replace(/[\t\s]/g, '');
};
/**
* 处理metaData对象生成可显示对象
*/
export const processMetaData = (separator = ',') => (metadata = {}) => {
if (Object.prototype.toString.call(metadata) !== '[object Object]') {
return '';
}
return Object.keys(metadata)
.map(key => `${key}=${metadata[key]}`)
.join(separator);
};

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
ls ~/nvm || git clone https://github.com/creationix/nvm.git ~/nvm ls ~/nvm || git clone https://github.com/creationix/nvm.git ~/nvm
source ~/nvm/nvm.sh source ~/nvm/nvm.sh
nvm install v7.10.0 nvm install v7.10.0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -39,10 +39,8 @@ 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.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=1
nacos.naming.distro.taskDispatchPeriod=200 nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000 nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000 nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true nacos.naming.data.warmup=true
nacos.naming.expireInstance=true nacos.naming.expireInstance=true

View File

@ -19,7 +19,6 @@ import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.core.utils.SystemUtils; import com.alibaba.nacos.core.utils.SystemUtils;
import com.alibaba.nacos.naming.cluster.ServerListManager; import com.alibaba.nacos.naming.cluster.ServerListManager;
import com.alibaba.nacos.naming.cluster.ServerMode;
import com.alibaba.nacos.naming.cluster.ServerStatus; import com.alibaba.nacos.naming.cluster.ServerStatus;
import com.alibaba.nacos.naming.cluster.servers.Server; import com.alibaba.nacos.naming.cluster.servers.Server;
import com.alibaba.nacos.naming.cluster.transport.Serializer; import com.alibaba.nacos.naming.cluster.transport.Serializer;

View File

@ -51,7 +51,7 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
raftCore.signalPublish(key, value); raftCore.signalPublish(key, value);
} catch (Exception e) { } catch (Exception e) {
Loggers.RAFT.error("Raft put failed.", e); Loggers.RAFT.error("Raft put failed.", e);
throw new NacosException(NacosException.SERVER_ERROR, "Raft put failed, key:" + key + ", value:" + value); throw new NacosException(NacosException.SERVER_ERROR, "Raft put failed, key:" + key + ", value:" + value, e);
} }
} }
@ -69,7 +69,7 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
raftCore.unlistenAll(key); raftCore.unlistenAll(key);
} catch (Exception e) { } catch (Exception e) {
Loggers.RAFT.error("Raft remove failed.", e); Loggers.RAFT.error("Raft remove failed.", e);
throw new NacosException(NacosException.SERVER_ERROR, "Raft remove failed, key:" + key); throw new NacosException(NacosException.SERVER_ERROR, "Raft remove failed, key:" + key, e);
} }
} }
@ -98,7 +98,7 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
raftCore.onPublish(datum, source); raftCore.onPublish(datum, source);
} catch (Exception e) { } catch (Exception e) {
Loggers.RAFT.error("Raft onPut failed.", e); Loggers.RAFT.error("Raft onPut failed.", e);
throw new NacosException(NacosException.SERVER_ERROR, "Raft onPut failed, datum:" + datum + ", source: " + source); throw new NacosException(NacosException.SERVER_ERROR, "Raft onPut failed, datum:" + datum + ", source: " + source, e);
} }
} }
@ -107,7 +107,7 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
raftCore.onDelete(datum.key, source); raftCore.onDelete(datum.key, source);
} catch (Exception e) { } catch (Exception e) {
Loggers.RAFT.error("Raft onRemove failed.", e); Loggers.RAFT.error("Raft onRemove failed.", e);
throw new NacosException(NacosException.SERVER_ERROR, "Raft onRemove failed, datum:" + datum + ", source: " + source); throw new NacosException(NacosException.SERVER_ERROR, "Raft onRemove failed, datum:" + datum + ", source: " + source, e);
} }
} }
} }

View File

@ -124,7 +124,7 @@ public class RaftCore {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
datums = raftStore.loadDatums(notifier); raftStore.loadDatums(notifier, datums);
setTerm(NumberUtils.toLong(raftStore.loadMeta().getProperty("term"), 0L)); setTerm(NumberUtils.toLong(raftStore.loadMeta().getProperty("term"), 0L));

View File

@ -41,7 +41,7 @@ import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap;
/** /**
* @author nacos * @author nacos
@ -55,9 +55,8 @@ public class RaftStore {
private String cacheDir = UtilsAndCommons.DATA_BASE_DIR + File.separator + "data"; private String cacheDir = UtilsAndCommons.DATA_BASE_DIR + File.separator + "data";
public synchronized ConcurrentHashMap<String, Datum> loadDatums(RaftCore.Notifier notifier) throws Exception { public synchronized void loadDatums(RaftCore.Notifier notifier, ConcurrentMap<String, Datum> datums) throws Exception {
ConcurrentHashMap<String, Datum> datums = new ConcurrentHashMap<>(32);
Datum datum; Datum datum;
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
for (File cache : listCaches()) { for (File cache : listCaches()) {
@ -78,7 +77,6 @@ public class RaftStore {
} }
Loggers.RAFT.info("finish loading all datums, size: {} cost {} ms.", datums.size(), (System.currentTimeMillis() - start)); Loggers.RAFT.info("finish loading all datums, size: {} cost {} ms.", datums.size(), (System.currentTimeMillis() - start));
return datums;
} }
public synchronized Properties loadMeta() throws Exception { public synchronized Properties loadMeta() throws Exception {

View File

@ -16,14 +16,11 @@
package com.alibaba.nacos.naming.controllers; package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker; import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
import com.alibaba.nacos.core.utils.WebUtils; import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer;
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeerSet;
import com.alibaba.nacos.naming.core.Cluster; import com.alibaba.nacos.naming.core.Cluster;
import com.alibaba.nacos.naming.core.Service; import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.core.ServiceManager; import com.alibaba.nacos.naming.core.ServiceManager;
@ -31,8 +28,7 @@ import com.alibaba.nacos.naming.exception.NacosException;
import com.alibaba.nacos.naming.healthcheck.HealthCheckType; import com.alibaba.nacos.naming.healthcheck.HealthCheckType;
import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.pojo.ClusterStateView;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
@ -42,9 +38,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/** /**
* @author nkorange * @author nkorange

View File

@ -18,7 +18,6 @@ package com.alibaba.nacos.naming.controllers;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.alibaba.nacos.core.utils.WebUtils; import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.naming.cluster.ServerMode;
import com.alibaba.nacos.naming.cluster.transport.Serializer; import com.alibaba.nacos.naming.cluster.transport.Serializer;
import com.alibaba.nacos.naming.consistency.Datum; import com.alibaba.nacos.naming.consistency.Datum;
import com.alibaba.nacos.naming.consistency.KeyBuilder; import com.alibaba.nacos.naming.consistency.KeyBuilder;

View File

@ -22,7 +22,6 @@ import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.api.naming.utils.NamingUtils; import com.alibaba.nacos.api.naming.utils.NamingUtils;
import com.alibaba.nacos.core.utils.WebUtils; import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.naming.cluster.ServerMode;
import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.DistroMapper;
import com.alibaba.nacos.naming.core.Instance; import com.alibaba.nacos.naming.core.Instance;
import com.alibaba.nacos.naming.core.Service; import com.alibaba.nacos.naming.core.Service;
@ -263,7 +262,7 @@ public class InstanceController {
} }
service.processClientBeat(clientBeat); service.processClientBeat(clientBeat);
result.put("clientBeatInterval", instance.getInstanceHeartBeatInterval());
return result; return result;
} }

View File

@ -39,7 +39,6 @@ import com.alibaba.nacos.naming.web.NeedAuth;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;

View File

@ -376,6 +376,10 @@ public class ServiceController {
*/ */
@RequestMapping(value = "/subscribers", method = RequestMethod.GET) @RequestMapping(value = "/subscribers", method = RequestMethod.GET)
public JSONObject subscribers(HttpServletRequest request) { public JSONObject subscribers(HttpServletRequest request) {
int pageNo = NumberUtils.toInt(WebUtils.required(request, "pageNo"));
int pageSize = NumberUtils.toInt(WebUtils.required(request, "pageSize"));
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
Constants.DEFAULT_NAMESPACE_ID); Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
@ -385,7 +389,23 @@ public class ServiceController {
try { try {
List<Subscriber> subscribers = subscribeManager.getSubscribers(serviceName, namespaceId, aggregation); List<Subscriber> subscribers = subscribeManager.getSubscribers(serviceName, namespaceId, aggregation);
result.put("subscribers", subscribers);
int start = (pageNo - 1) * pageSize;
int end = start + pageSize;
int count = subscribers.size();
if (start < 0) {
start = 0;
}
if (end > count) {
end = count;
}
result.put("subscribers", subscribers.subList(start, end));
result.put("count", count);
return result; return result;
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@ -21,7 +21,6 @@ import com.alibaba.nacos.naming.boot.RunningConfig;
import com.alibaba.nacos.naming.cluster.ServerListManager; import com.alibaba.nacos.naming.cluster.ServerListManager;
import com.alibaba.nacos.naming.cluster.servers.Server; import com.alibaba.nacos.naming.cluster.servers.Server;
import com.alibaba.nacos.naming.misc.HttpClient; import com.alibaba.nacos.naming.misc.HttpClient;
import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.naming.misc.NetUtils; import com.alibaba.nacos.naming.misc.NetUtils;
import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.pojo.Subscriber; import com.alibaba.nacos.naming.pojo.Subscriber;

View File

@ -17,6 +17,8 @@ package com.alibaba.nacos.naming.healthcheck;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
import com.alibaba.nacos.naming.boot.RunningConfig; import com.alibaba.nacos.naming.boot.RunningConfig;
import com.alibaba.nacos.naming.boot.SpringContext; import com.alibaba.nacos.naming.boot.SpringContext;
import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.DistroMapper;
@ -26,9 +28,14 @@ import com.alibaba.nacos.naming.misc.*;
import com.alibaba.nacos.naming.push.PushService; import com.alibaba.nacos.naming.push.PushService;
import com.ning.http.client.AsyncCompletionHandler; import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.Response; import com.ning.http.client.Response;
import org.springframework.util.StringUtils;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.util.List; import java.util.List;
import java.util.Map;
import static com.alibaba.nacos.naming.misc.UtilsAndCommons.NUMBER_PATTERN;
/** /**
* Check and update statues of ephemeral instances, remove them if they have been expired. * Check and update statues of ephemeral instances, remove them if they have been expired.
@ -73,13 +80,13 @@ public class ClientBeatCheckTask implements Runnable {
// first set health status of instances: // first set health status of instances:
for (Instance instance : instances) { for (Instance instance : instances) {
if (System.currentTimeMillis() - instance.getLastBeat() > ClientBeatProcessor.CLIENT_BEAT_TIMEOUT) { if (System.currentTimeMillis() - instance.getLastBeat() > instance.getInstanceHeartBeatTimeOut()) {
if (!instance.isMarked()) { if (!instance.isMarked()) {
if (instance.isHealthy()) { if (instance.isHealthy()) {
instance.setHealthy(false); instance.setHealthy(false);
Loggers.EVT_LOG.info("{POS} {IP-DISABLED} valid: {}:{}@{}@{}, region: {}, msg: client timeout after {}, last beat: {}", Loggers.EVT_LOG.info("{POS} {IP-DISABLED} valid: {}:{}@{}@{}, region: {}, msg: client timeout after {}, last beat: {}",
instance.getIp(), instance.getPort(), instance.getClusterName(), service.getName(), instance.getIp(), instance.getPort(), instance.getClusterName(), service.getName(),
UtilsAndCommons.LOCALHOST_SITE, ClientBeatProcessor.CLIENT_BEAT_TIMEOUT, instance.getLastBeat()); UtilsAndCommons.LOCALHOST_SITE, instance.getInstanceHeartBeatTimeOut(), instance.getLastBeat());
getPushService().serviceChanged(service.getNamespaceId(), service.getName()); getPushService().serviceChanged(service.getNamespaceId(), service.getName());
} }
} }
@ -92,7 +99,7 @@ public class ClientBeatCheckTask implements Runnable {
// then remove obsolete instances: // then remove obsolete instances:
for (Instance instance : instances) { for (Instance instance : instances) {
if (System.currentTimeMillis() - instance.getLastBeat() > service.getIpDeleteTimeout()) { if (System.currentTimeMillis() - instance.getLastBeat() > instance.getIpDeleteTimeout()) {
// delete instance // delete instance
Loggers.SRV_LOG.info("[AUTO-DELETE-IP] service: {}, ip: {}", service.getName(), JSON.toJSONString(instance)); Loggers.SRV_LOG.info("[AUTO-DELETE-IP] service: {}, ip: {}", service.getName(), JSON.toJSONString(instance));
deleteIP(instance); deleteIP(instance);
@ -105,6 +112,7 @@ public class ClientBeatCheckTask implements Runnable {
} }
private void deleteIP(Instance instance) { private void deleteIP(Instance instance) {
try { try {

View File

@ -23,7 +23,6 @@ import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer; import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter; import com.alibaba.fastjson.serializer.SerializeWriter;
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker; import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -17,7 +17,6 @@ package com.alibaba.nacos.naming.healthcheck;
import com.alibaba.nacos.naming.core.Cluster; import com.alibaba.nacos.naming.core.Cluster;
import com.alibaba.nacos.naming.core.Instance; import com.alibaba.nacos.naming.core.Instance;
import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.naming.misc.SwitchDomain; import com.alibaba.nacos.naming.misc.SwitchDomain;
import com.alibaba.nacos.naming.monitor.MetricsMonitor; import com.alibaba.nacos.naming.monitor.MetricsMonitor;

View File

@ -27,22 +27,19 @@ import org.springframework.stereotype.Component;
@Component @Component
public class GlobalConfig { public class GlobalConfig {
@Value("${nacos.naming.distro.taskDispatchPeriod}") @Value("${nacos.naming.distro.taskDispatchPeriod:200}")
private int taskDispatchPeriod = 2000; private int taskDispatchPeriod = 2000;
@Value("${nacos.naming.distro.batchSyncKeyCount}") @Value("${nacos.naming.distro.batchSyncKeyCount:1000}")
private int batchSyncKeyCount = 1000; private int batchSyncKeyCount = 1000;
@Value("${nacos.naming.distro.syncRetryDelay}") @Value("${nacos.naming.distro.syncRetryDelay:5000}")
private long syncRetryDelay = 5000L; private long syncRetryDelay = 5000L;
@Value("${nacos.naming.distro.taskDispatchThreadCount}") @Value("${nacos.naming.data.warmup:false}")
private int taskDispatchThreadCount = Runtime.getRuntime().availableProcessors();
@Value("${nacos.naming.data.warmup}")
private boolean dataWarmup = false; private boolean dataWarmup = false;
@Value("${nacos.naming.expireInstance}") @Value("${nacos.naming.expireInstance:true}")
private boolean expireInstance = true; private boolean expireInstance = true;
public int getTaskDispatchPeriod() { public int getTaskDispatchPeriod() {
@ -57,10 +54,6 @@ public class GlobalConfig {
return syncRetryDelay; return syncRetryDelay;
} }
public int getTaskDispatchThreadCount() {
return taskDispatchThreadCount;
}
public boolean isDataWarmup() { public boolean isDataWarmup() {
return dataWarmup; return dataWarmup;
} }

View File

@ -19,7 +19,6 @@ import com.alibaba.nacos.common.util.HttpMethod;
import com.ning.http.client.AsyncCompletionHandler; import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig; import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.FluentStringsMap;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -28,7 +27,6 @@ import org.apache.http.*;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; 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.HttpPost;
import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
@ -36,7 +34,6 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import java.io.IOException; import java.io.IOException;

View File

@ -16,7 +16,6 @@
package com.alibaba.nacos.naming.misc; package com.alibaba.nacos.naming.misc;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.core.utils.SystemUtils;
import com.alibaba.nacos.naming.boot.RunningConfig; import com.alibaba.nacos.naming.boot.RunningConfig;
import com.ning.http.client.AsyncCompletionHandler; import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.Response; import com.ning.http.client.Response;

View File

@ -118,6 +118,8 @@ public class UtilsAndCommons {
public static final String DATA_BASE_DIR = NACOS_HOME + File.separator + "data" + File.separator + "naming"; public static final String DATA_BASE_DIR = NACOS_HOME + File.separator + "data" + File.separator + "naming";
public static final String NUMBER_PATTERN = "^\\d+$";
public static final ScheduledExecutorService SERVICE_SYNCHRONIZATION_EXECUTOR; public static final ScheduledExecutorService SERVICE_SYNCHRONIZATION_EXECUTOR;
public static final ScheduledExecutorService SERVICE_UPDATE_EXECUTOR; public static final ScheduledExecutorService SERVICE_UPDATE_EXECUTOR;

View File

@ -144,7 +144,7 @@ public class ClientInfo {
/** /**
* Unknown client type * Unknown client type
*/ */
UNKNOWN; UNKNOWN
} }
public static class ClientTypeDescription { public static class ClientTypeDescription {

View File

@ -16,11 +16,9 @@
package com.alibaba.nacos.naming.web; package com.alibaba.nacos.naming.web;
import com.alibaba.nacos.naming.acl.AuthChecker; import com.alibaba.nacos.naming.acl.AuthChecker;
import com.alibaba.nacos.naming.controllers.*;
import com.alibaba.nacos.naming.exception.NacosException;
import com.alibaba.nacos.naming.misc.SwitchDomain; import com.alibaba.nacos.naming.misc.SwitchDomain;
import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.*; import javax.servlet.*;
@ -30,8 +28,6 @@ import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import java.security.AccessControlException; import java.security.AccessControlException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/** /**
* @author nkorange * @author nkorange

View File

@ -17,7 +17,6 @@ package com.alibaba.nacos.naming.web;
import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.naming.boot.SpringContext;
import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.DistroMapper;
import com.alibaba.nacos.naming.misc.HttpClient; import com.alibaba.nacos.naming.misc.HttpClient;
import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.Loggers;

View File

@ -16,7 +16,6 @@
package com.alibaba.nacos.naming.web; package com.alibaba.nacos.naming.web;
import com.alibaba.nacos.common.util.HttpMethod; import com.alibaba.nacos.common.util.HttpMethod;
import com.alibaba.nacos.naming.cluster.ServerMode;
import com.alibaba.nacos.naming.cluster.ServerStatus; import com.alibaba.nacos.naming.cluster.ServerStatus;
import com.alibaba.nacos.naming.cluster.ServerStatusManager; import com.alibaba.nacos.naming.cluster.ServerStatusManager;
import com.alibaba.nacos.naming.misc.SwitchDomain; import com.alibaba.nacos.naming.misc.SwitchDomain;
@ -28,8 +27,6 @@ import javax.servlet.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map; import java.util.Map;
/** /**

View File

@ -25,12 +25,3 @@ 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
# default current work dir # default current work dir
server.tomcat.basedir= server.tomcat.basedir=
nacos.naming.distro.taskDispatchThreadCount=1
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
nacos.naming.expireInstance=true

View File

@ -16,7 +16,7 @@
package com.alibaba.nacos.naming.consistency.ephemeral.distro; package com.alibaba.nacos.naming.consistency.ephemeral.distro;
import com.alibaba.nacos.naming.misc.GlobalConfig; import com.alibaba.nacos.naming.misc.GlobalConfig;
import com.alibaba.nacos.naming.misc.Loggers;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;

View File

@ -16,8 +16,6 @@
package com.alibaba.nacos.naming.core; package com.alibaba.nacos.naming.core;
import com.alibaba.nacos.naming.boot.SpringContext; import com.alibaba.nacos.naming.boot.SpringContext;
import com.alibaba.nacos.naming.healthcheck.HealthCheckProcessorDelegate;
import com.alibaba.nacos.naming.misc.SwitchDomain;
import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.push.PushService; import com.alibaba.nacos.naming.push.PushService;
import org.junit.Assert; import org.junit.Assert;

View File

@ -0,0 +1,129 @@
package com.alibaba.nacos.naming.healthcheck;
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
import com.alibaba.nacos.core.utils.SystemUtils;
import com.alibaba.nacos.naming.core.*;
import com.alibaba.nacos.naming.misc.GlobalConfig;
import com.alibaba.nacos.naming.push.PushService;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author caoyixiong
*/
@RunWith(MockitoJUnitRunner.Silent.class)
public class ClientBeatCheckTaskTest {
@InjectMocks
@Spy
private ClientBeatCheckTask clientBeatCheckTask;
@Mock
private DistroMapper distroMapperSpy;
@Mock
private Service serviceSpy;
@Mock
private GlobalConfig globalConfig;
@Mock
private PushService pushService;
@Before
public void init() {
ReflectionTestUtils.setField(clientBeatCheckTask, "service", serviceSpy);
Mockito.doReturn(distroMapperSpy).when(clientBeatCheckTask).getDistroMapper();
Mockito.doReturn(globalConfig).when(clientBeatCheckTask).getGlobalConfig();
Mockito.doReturn(pushService).when(clientBeatCheckTask).getPushService();
}
@Test
public void testHeartBeatNotTimeout() {
List<Instance> instances = new ArrayList<>();
Instance instance = new Instance();
instance.setLastBeat(System.currentTimeMillis());
instance.setMarked(false);
instance.setHealthy(true);
Map<String, String> metadata = new HashMap<>();
metadata.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "1000000000");
instance.setMetadata(metadata);
instances.add(instance);
Mockito.when(serviceSpy.allIPs(true)).thenReturn(instances);
Mockito.doReturn("test").when(serviceSpy).getName();
Mockito.doReturn(true).when(distroMapperSpy).responsible(Mockito.anyString());
clientBeatCheckTask.run();
Assert.assertTrue(instance.isHealthy());
}
@Test
public void testHeartBeatTimeout() {
List<Instance> instances = new ArrayList<>();
Instance instance = new Instance();
instance.setLastBeat(System.currentTimeMillis() - 1000);
instance.setMarked(false);
instance.setHealthy(true);
Map<String, String> metadata = new HashMap<>();
metadata.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "10");
instance.setMetadata(metadata);
instances.add(instance);
Mockito.doReturn("test").when(serviceSpy).getName();
Mockito.doReturn(true).when(distroMapperSpy).responsible(Mockito.anyString());
Mockito.when(serviceSpy.allIPs(true)).thenReturn(instances);
clientBeatCheckTask.run();
Assert.assertFalse(instance.isHealthy());
}
@Test
public void testIpDeleteTimeOut() {
List<Instance> instances = new ArrayList<>();
Instance instance = new Instance();
instance.setLastBeat(System.currentTimeMillis());
instance.setMarked(true);
instance.setHealthy(true);
Map<String, String> metadata = new HashMap<>();
metadata.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT, "10");
instance.setMetadata(metadata);
instances.add(instance);
Mockito.doReturn(true).when(distroMapperSpy).responsible(null);
Mockito.doReturn(true).when(globalConfig).isExpireInstance();
Mockito.when(serviceSpy.allIPs(true)).thenReturn(instances);
clientBeatCheckTask.run();
}
@Test
public void testIpDeleteNotTimeOut() {
List<Instance> instances = new ArrayList<>();
Instance instance = new Instance();
instance.setLastBeat(System.currentTimeMillis());
instance.setMarked(true);
instance.setHealthy(true);
Map<String, String> metadata = new HashMap<>();
metadata.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT, "10000");
instance.setMetadata(metadata);
instances.add(instance);
Mockito.doReturn(true).when(distroMapperSpy).responsible(null);
Mockito.doReturn(true).when(globalConfig).isExpireInstance();
Mockito.when(serviceSpy.allIPs(true)).thenReturn(instances);
clientBeatCheckTask.run();
}
}

View File

@ -86,7 +86,7 @@ public class ConfigAPI_ITCase {
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertEquals(true, JSON.parseObject(result.content).getBoolean("data")); Assert.assertEquals(true, JSON.parseObject(result.content).getBoolean("data"));
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }
@ -108,7 +108,7 @@ public class ConfigAPI_ITCase {
Assert.assertTrue(result); Assert.assertTrue(result);
value = iconfig.getConfig(dataId, group, TIME_OUT); value = iconfig.getConfig(dataId, group, TIME_OUT);
System.out.println(value); System.out.println(value);
Assert.assertEquals(null, value); Assert.assertNull(value);
} }
/** /**
@ -133,7 +133,7 @@ public class ConfigAPI_ITCase {
Assert.assertTrue(true); Assert.assertTrue(true);
return; return;
} }
Assert.assertTrue(false); Assert.fail();
} }
/** /**
@ -218,7 +218,7 @@ public class ConfigAPI_ITCase {
Assert.assertTrue(true); Assert.assertTrue(true);
return; return;
} }
Assert.assertTrue(false); Assert.fail();
} }
/** /**
@ -251,7 +251,7 @@ public class ConfigAPI_ITCase {
Assert.assertTrue(true); Assert.assertTrue(true);
return; return;
} }
Assert.assertTrue(false); Assert.fail();
} }
/** /**
@ -283,7 +283,7 @@ public class ConfigAPI_ITCase {
Thread.sleep(TIME_OUT); Thread.sleep(TIME_OUT);
Assert.assertTrue(result); Assert.assertTrue(result);
String value = iconfig.getConfig(dataId, group, TIME_OUT); String value = iconfig.getConfig(dataId, group, TIME_OUT);
Assert.assertEquals(null, value); Assert.assertNull(value);
} }
/** /**
@ -310,7 +310,7 @@ public class ConfigAPI_ITCase {
Assert.assertTrue(true); Assert.assertTrue(true);
return; return;
} }
Assert.assertTrue(false); Assert.fail();
} }
/** /**
@ -366,7 +366,7 @@ public class ConfigAPI_ITCase {
public void nacos_addListener_2() { public void nacos_addListener_2() {
try { try {
iconfig.addListener(dataId, group, null); iconfig.addListener(dataId, group, null);
Assert.assertFalse(true); Assert.fail();
} catch (Exception e) { } catch (Exception e) {
Assert.assertFalse(false); Assert.assertFalse(false);
} }
@ -537,7 +537,7 @@ public class ConfigAPI_ITCase {
iconfig.addListener(dataId, group, new AbstractListener() { iconfig.addListener(dataId, group, new AbstractListener() {
@Override @Override
public void receiveConfigInfo(String configInfo) { public void receiveConfigInfo(String configInfo) {
Assert.assertTrue(false); Assert.fail();
} }
}); });
Thread.sleep(TIME_OUT); Thread.sleep(TIME_OUT);
@ -571,7 +571,7 @@ public class ConfigAPI_ITCase {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }
@ -653,7 +653,7 @@ public class ConfigAPI_ITCase {
Assert.assertEquals(content, JSON.parseObject(result.content).getString("content")); Assert.assertEquals(content, JSON.parseObject(result.content).getString("content"));
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }
@ -682,7 +682,7 @@ public class ConfigAPI_ITCase {
Assert.assertNotNull(JSON.parseObject(result.content).getString("data")); Assert.assertNotNull(JSON.parseObject(result.content).getString("data"));
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }
@ -713,7 +713,7 @@ public class ConfigAPI_ITCase {
result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT); result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }
@ -744,7 +744,7 @@ public class ConfigAPI_ITCase {
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertEquals(true, JSON.parseObject(result.content).getBoolean("data")); Assert.assertEquals(true, JSON.parseObject(result.content).getBoolean("data"));
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }
@ -773,7 +773,7 @@ public class ConfigAPI_ITCase {
Assert.assertTrue(JSON.parseObject(result.content).getIntValue("totalCount") >= 1); Assert.assertTrue(JSON.parseObject(result.content).getIntValue("totalCount") >= 1);
Assert.assertTrue(JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content").startsWith(content)); Assert.assertTrue(JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content").startsWith(content));
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }
@ -803,7 +803,7 @@ public class ConfigAPI_ITCase {
Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content")); Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content"));
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }
@ -829,11 +829,11 @@ public class ConfigAPI_ITCase {
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT); result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertTrue(JSON.parseObject(result.content).getIntValue("totalCount") == 1); Assert.assertEquals(1, JSON.parseObject(result.content).getIntValue("totalCount"));
Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content")); Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content"));
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }
@ -858,10 +858,10 @@ public class ConfigAPI_ITCase {
List<String> params = Arrays.asList("dataId", dataId, "group", group, "pageNo","1", "pageSize","10", "search", "accurate"); List<String> params = Arrays.asList("dataId", dataId, "group", group, "pageNo","1", "pageSize","10", "search", "accurate");
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, "utf-8", TIME_OUT); result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, "utf-8", TIME_OUT);
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertTrue(JSON.parseObject(result.content).getIntValue("totalCount") == 1); Assert.assertEquals(1, JSON.parseObject(result.content).getIntValue("totalCount"));
Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content")); Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content"));
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.fail();
} }
} }

View File

@ -20,20 +20,14 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.swing.text.View;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView; 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 com.alibaba.nacos.naming.NamingApp;
import org.junit.After; import org.junit.After;
@ -54,8 +48,6 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import static com.alibaba.nacos.test.naming.NamingBase.*; import static com.alibaba.nacos.test.naming.NamingBase.*;
import static org.junit.Assert.assertTrue;
/** /**
* @author nkorange * @author nkorange
*/ */

View File

@ -46,9 +46,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import static com.alibaba.nacos.client.naming.net.HttpClient.request;
import static com.alibaba.nacos.test.naming.NamingBase.*; import static com.alibaba.nacos.test.naming.NamingBase.*;
import static com.alibaba.nacos.test.naming.NamingBase.randomDomainName;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos", @SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos",

View File

@ -25,7 +25,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays; import java.util.Arrays;

View File

@ -16,7 +16,6 @@ import com.alibaba.nacos.api.naming.listener.NamingEvent;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView; import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.naming.NamingApp; import com.alibaba.nacos.naming.NamingApp;
import com.alibaba.nacos.naming.selector.Selector;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;

View File

@ -1,7 +1,6 @@
package com.alibaba.nacos.test.naming; package com.alibaba.nacos.test.naming;
import java.net.URL; import java.net.URL;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -13,11 +12,7 @@ import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.listener.Event;
import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.listener.NamingEvent;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.client.naming.NacosNamingService; import com.alibaba.nacos.client.naming.NacosNamingService;
import com.alibaba.nacos.naming.NamingApp; import com.alibaba.nacos.naming.NamingApp;

View File

@ -38,7 +38,6 @@ public class RandomUtils {
public static long getLongMoreThanZero() { public static long getLongMoreThanZero() {
long res; long res;
for(res = rd.nextLong(); res <= 0L; res = rd.nextLong()) { for(res = rd.nextLong(); res <= 0L; res = rd.nextLong()) {
;
} }
return res; return res;
@ -52,7 +51,6 @@ public class RandomUtils {
public static long getLongMoreThanZeroLessThan(long n) { public static long getLongMoreThanZeroLessThan(long n) {
long res; long res;
for(res = getLongLessThan(n); res <= 0L; res = getLongLessThan(n)) { for(res = getLongLessThan(n); res <= 0L; res = getLongLessThan(n)) {
;
} }
return res; return res;
@ -74,7 +72,6 @@ public class RandomUtils {
public static int getIntegerMoreThanZero() { public static int getIntegerMoreThanZero() {
int res; int res;
for(res = rd.nextInt(); res <= 0; res = rd.nextInt()) { for(res = rd.nextInt(); res <= 0; res = rd.nextInt()) {
;
} }
return res; return res;
@ -88,7 +85,6 @@ public class RandomUtils {
public static int getIntegerMoreThanZeroLessThan(int n) { public static int getIntegerMoreThanZeroLessThan(int n) {
int res; int res;
for(res = rd.nextInt(n); res == 0; res = rd.nextInt(n)) { for(res = rd.nextInt(n); res == 0; res = rd.nextInt(n)) {
;
} }
return res; return res;
@ -273,7 +269,6 @@ public class RandomUtils {
int[] source = new int[len]; int[] source = new int[len];
for(int i = min; i < min + len; source[i - min] = i++) { for(int i = min; i < min + len; source[i - min] = i++) {
;
} }
int[] result = new int[n]; int[] result = new int[n];

View File

@ -19,7 +19,7 @@ import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.naming.NamingApp; import com.alibaba.nacos.naming.NamingApp;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -28,7 +28,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.net.ServerSocket;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -89,7 +88,7 @@ public class SelectOneHealthyInstance_ITCase {
} }
} }
Assert.assertTrue(false); Assert.fail();
} }
/** /**
@ -108,7 +107,7 @@ public class SelectOneHealthyInstance_ITCase {
TimeUnit.SECONDS.sleep(2); TimeUnit.SECONDS.sleep(2);
Instance instance = naming.selectOneHealthyInstance(serviceName, Arrays.asList("c1")); Instance instance = naming.selectOneHealthyInstance(serviceName, Arrays.asList("c1"));
Assert.assertTrue(instance.getIp() != "1.1.1.1"); Assert.assertNotSame("1.1.1.1", instance.getIp());
Assert.assertTrue(instance.getPort() != 60002); Assert.assertTrue(instance.getPort() != 60002);
List<Instance> instancesGet = naming.getAllInstances(serviceName); List<Instance> instancesGet = naming.getAllInstances(serviceName);
@ -122,7 +121,7 @@ public class SelectOneHealthyInstance_ITCase {
} }
} }
Assert.assertTrue(false); Assert.fail();
} }
/** /**
@ -139,7 +138,7 @@ public class SelectOneHealthyInstance_ITCase {
TimeUnit.SECONDS.sleep(2); TimeUnit.SECONDS.sleep(2);
Instance instance = naming.selectOneHealthyInstance(serviceName, Arrays.asList("c1", "c2")); Instance instance = naming.selectOneHealthyInstance(serviceName, Arrays.asList("c1", "c2"));
Assert.assertTrue(instance.getIp() != "1.1.1.1"); Assert.assertNotSame("1.1.1.1", instance.getIp());
List<Instance> instancesGet = naming.getAllInstances(serviceName); List<Instance> instancesGet = naming.getAllInstances(serviceName);
@ -152,6 +151,6 @@ public class SelectOneHealthyInstance_ITCase {
} }
} }
Assert.assertTrue(false); Assert.fail();
} }
} }

View File

@ -196,6 +196,6 @@ public class SubscribeCluster_ITCase {
} }
} }
Assert.assertTrue(false); Assert.fail();
} }
} }

View File

@ -33,7 +33,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import static com.alibaba.nacos.test.naming.NamingBase.*; import static com.alibaba.nacos.test.naming.NamingBase.*;
@ -111,7 +110,7 @@ public class Unsubscribe_ITCase {
} }
} }
Assert.assertTrue(false); Assert.fail();
} }
/** /**
@ -154,7 +153,7 @@ public class Unsubscribe_ITCase {
} }
} }
Assert.assertTrue(false); Assert.fail();
} }
} }

View File

@ -18,11 +18,3 @@ server.tomcat.accesslog.enabled=false
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir # default current work dir
server.tomcat.basedir= server.tomcat.basedir=
nacos.naming.distro.taskDispatchThreadCount=1
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=false
nacos.naming.expireInstance=true