Merge branch 'develop' into master
This commit is contained in:
commit
0867117e3f
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,7 +3,6 @@
|
||||
.project
|
||||
.settings
|
||||
target
|
||||
.project
|
||||
.idea
|
||||
.vscode
|
||||
.DS_Store
|
||||
|
19
.travis.yml
19
.travis.yml
@ -12,17 +12,22 @@ language: java
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# On OSX, run with default JDK only.
|
||||
# - os: osx
|
||||
# On Linux, run with specific JDKs only.
|
||||
- os: linux
|
||||
env: CUSTOM_JDK="oraclejdk8"
|
||||
# On OSX, run with default JDK only.
|
||||
# - os: osx
|
||||
# On Linux, run with specific JDKs only.
|
||||
- os: linux
|
||||
env: CUSTOM_JDK="oraclejdk8"
|
||||
|
||||
jdk:
|
||||
- openjdk10
|
||||
- openjdk9
|
||||
- openjdk8
|
||||
|
||||
before_install:
|
||||
- echo 'MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -XX:MaxPermSize=512m -XX:+BytecodeVerificationLocal"' >> ~/.mavenrc
|
||||
- cat ~/.mavenrc
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export JAVA_HOME=$(/usr/libexec/java_home); fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then jdk_switcher use "$CUSTOM_JDK"; fi
|
||||
# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export JAVA_HOME=$(/usr/libexec/java_home); fi
|
||||
# - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then jdk_switcher use "$CUSTOM_JDK"; fi
|
||||
|
||||
script:
|
||||
- mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
|
||||
|
@ -46,12 +46,14 @@ public class PropertyKeyConst {
|
||||
|
||||
public final static String ENCODE = "encode";
|
||||
|
||||
public final static String CONFIG_LONG_POLL_TIMEOUT = "config.long-poll.timeout";
|
||||
public final static String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout";
|
||||
|
||||
public final static String CONFIG_RETRY_TIME = "config.retry.time";
|
||||
public final static String CONFIG_RETRY_TIME = "configRetryTime";
|
||||
|
||||
public final static String MAX_RETRY = "maxRetry";
|
||||
|
||||
public final static String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
|
||||
|
||||
public final static String NAMING_LOAD_CACHE_AT_START = "namingLoadCacheAtStart";
|
||||
|
||||
public final static String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
|
||||
|
@ -76,6 +76,21 @@ public @interface NacosProperties {
|
||||
*/
|
||||
String ENCODE = "encode";
|
||||
|
||||
/**
|
||||
* The property name of "long-poll.timeout"
|
||||
*/
|
||||
String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout";
|
||||
|
||||
/**
|
||||
* The property name of "config.retry.time"
|
||||
*/
|
||||
String CONFIG_RETRY_TIME = "configRetryTime";
|
||||
|
||||
/**
|
||||
* The property name of "maxRetry"
|
||||
*/
|
||||
String MAX_RETRY = "maxRetry";
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code>
|
||||
*/
|
||||
@ -116,6 +131,21 @@ public @interface NacosProperties {
|
||||
*/
|
||||
String ENCODE_PLACEHOLDER = "${" + PREFIX + ENCODE + ":UTF-8}";
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#CONFIG_LONG_POLL_TIMEOUT configLongPollTimeout}, the value is <code>"${nacos.configLongPollTimeout:}"</code>
|
||||
*/
|
||||
String CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER = "${" + PREFIX + CONFIG_LONG_POLL_TIMEOUT + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#CONFIG_RETRY_TIME configRetryTime}, the value is <code>"${nacos.configRetryTime:}"</code>
|
||||
*/
|
||||
String CONFIG_RETRY_TIME_PLACEHOLDER = "${" + PREFIX + CONFIG_RETRY_TIME + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#MAX_RETRY maxRetry}, the value is <code>"${nacos.maxRetry:}"</code>
|
||||
*/
|
||||
String MAX_RETRY_PLACEHOLDER = "${" + PREFIX + MAX_RETRY + ":}";
|
||||
|
||||
/**
|
||||
* The property of "endpoint"
|
||||
*
|
||||
@ -180,4 +210,28 @@ public @interface NacosProperties {
|
||||
*/
|
||||
String encode() default ENCODE_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "configLongPollTimeout"
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER
|
||||
*/
|
||||
String configLongPollTimeout() default CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "configRetryTime"
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CONFIG_RETRY_TIME_PLACEHOLDER
|
||||
*/
|
||||
String configRetryTime() default CONFIG_RETRY_TIME_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "maxRetry"
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #MAX_RETRY
|
||||
*/
|
||||
String maxRetry() default MAX_RETRY_PLACEHOLDER;
|
||||
|
||||
}
|
||||
|
@ -36,6 +36,23 @@ public interface ConfigService {
|
||||
*/
|
||||
String getConfig(String dataId, String group, long timeoutMs) throws NacosException;
|
||||
|
||||
/**
|
||||
* Get config and register Listener
|
||||
*
|
||||
* If you want to pull it yourself when the program starts to get the configuration for the first time,
|
||||
* and the registered Listener is used for future configuration updates, you can keep the original
|
||||
* code unchanged, just add the system parameter: enableRemoteSyncConfig = "true" ( But there is network overhead);
|
||||
* therefore we recommend that you use this interface directly
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param timeoutMs read timeout
|
||||
* @param listener {@link Listener}
|
||||
* @return config value
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener) throws NacosException;
|
||||
|
||||
/**
|
||||
* Add a listener to the configuration, after the server modified the
|
||||
* configuration, the client will use the incoming listener callback.
|
||||
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 = the "License"");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
/**
|
||||
* @author liaochuntao
|
||||
* @date 2019-06-14 21:12
|
||||
**/
|
||||
public enum ConfigType {
|
||||
|
||||
/**
|
||||
* config type is "properties"
|
||||
*/
|
||||
PROPERTIES("properties"),
|
||||
|
||||
/**
|
||||
* config type is "xml"
|
||||
*/
|
||||
XML("xml"),
|
||||
|
||||
/**
|
||||
* config type is "json"
|
||||
*/
|
||||
JSON("json"),
|
||||
|
||||
/**
|
||||
* config type is "text"
|
||||
*/
|
||||
TEXT("text"),
|
||||
|
||||
/**
|
||||
* config type is "html"
|
||||
*/
|
||||
HTML("html"),
|
||||
|
||||
/**
|
||||
* config type is "yaml"
|
||||
*/
|
||||
YAML("yaml");
|
||||
|
||||
String type;
|
||||
|
||||
ConfigType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import com.alibaba.nacos.api.annotation.NacosProperties;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.ConfigType;
|
||||
import com.alibaba.nacos.api.config.convert.NacosConfigConverter;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
@ -48,6 +49,13 @@ public @interface NacosConfigListener {
|
||||
*/
|
||||
String dataId();
|
||||
|
||||
/**
|
||||
* Nacos Config type
|
||||
*
|
||||
* @return "properties"
|
||||
*/
|
||||
ConfigType type() default ConfigType.PROPERTIES;
|
||||
|
||||
/**
|
||||
* Specify {@link NacosConfigConverter Nacos configuraion convertor} class to convert target type instance.
|
||||
*
|
||||
|
@ -18,6 +18,7 @@ package com.alibaba.nacos.api.config.annotation;
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.annotation.NacosProperties;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.ConfigType;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@ -54,7 +55,7 @@ public @interface NacosConfigurationProperties {
|
||||
*
|
||||
* @return default value is <code>false</code>
|
||||
*/
|
||||
boolean yaml() default false;
|
||||
ConfigType type() default ConfigType.PROPERTIES;
|
||||
|
||||
/**
|
||||
* It indicates the properties of current doBind bean is auto-refreshed when Nacos configuration is changed.
|
||||
|
@ -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.pojo.Instance;
|
||||
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.selector.AbstractSelector;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Naming Service
|
||||
|
@ -193,6 +193,7 @@ public abstract class AbstractHealthChecker implements Cloneable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tcp clone() throws CloneNotSupportedException {
|
||||
Tcp config = new Tcp();
|
||||
config.setType(this.type);
|
||||
|
@ -122,6 +122,13 @@ public class NacosConfigService implements ConfigService {
|
||||
return getConfigInner(namespace, dataId, group, timeoutMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener) throws NacosException {
|
||||
String content = getConfig(dataId, group, timeoutMs);
|
||||
worker.addTenantListenersWithContent(dataId, group, content, Arrays.asList(listener));
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(String dataId, String group, Listener listener) throws NacosException {
|
||||
worker.addTenantListeners(dataId, group, Arrays.asList(listener));
|
||||
@ -166,6 +173,7 @@ public class NacosConfigService implements ConfigService {
|
||||
content = worker.getServerConfig(dataId, group, tenant, timeoutMs);
|
||||
|
||||
cr.setContent(content);
|
||||
|
||||
configFilterChainManager.doFilter(null, cr);
|
||||
content = cr.getContent();
|
||||
|
||||
|
@ -91,9 +91,9 @@ public class ServerHttpAgent implements HttpAgent {
|
||||
return result;
|
||||
}
|
||||
} catch (ConnectException ce) {
|
||||
LOGGER.error("[NACOS ConnectException httpGet] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
|
||||
LOGGER.error("[NACOS ConnectException httpGet] currentServerAddr:{}, err : {}", serverListMgr.getCurrentServerAddr(), ce.getMessage());
|
||||
} catch (SocketTimeoutException stoe) {
|
||||
LOGGER.error("[NACOS SocketTimeoutException httpGet] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
|
||||
LOGGER.error("[NACOS SocketTimeoutException httpGet] currentServerAddr:{}, err : {}", serverListMgr.getCurrentServerAddr(), stoe.getMessage());
|
||||
} catch (IOException ioe) {
|
||||
LOGGER.error("[NACOS IOException httpGet] currentServerAddr: " + serverListMgr.getCurrentServerAddr(), ioe);
|
||||
throw ioe;
|
||||
@ -138,7 +138,7 @@ public class ServerHttpAgent implements HttpAgent {
|
||||
if (result.code == HttpURLConnection.HTTP_INTERNAL_ERROR
|
||||
|| result.code == HttpURLConnection.HTTP_BAD_GATEWAY
|
||||
|| result.code == HttpURLConnection.HTTP_UNAVAILABLE) {
|
||||
LOGGER.error("[NACOS ConnectException httpPost] currentServerAddr: {}, httpCode: {}",
|
||||
LOGGER.error("[NACOS ConnectException] currentServerAddr: {}, httpCode: {}",
|
||||
currentServerAddr, result.code);
|
||||
} else {
|
||||
// Update the currently available server addr
|
||||
@ -146,10 +146,9 @@ public class ServerHttpAgent implements HttpAgent {
|
||||
return result;
|
||||
}
|
||||
} catch (ConnectException ce) {
|
||||
LOGGER.error("[NACOS ConnectException httpPost] currentServerAddr: {}", currentServerAddr);
|
||||
LOGGER.error("[NACOS ConnectException httpPost] currentServerAddr: {}, err : {}", currentServerAddr, ce.getMessage());
|
||||
} catch (SocketTimeoutException stoe) {
|
||||
LOGGER.error("[NACOS SocketTimeoutException httpPost] currentServerAddr: {}, err : {}",
|
||||
currentServerAddr, stoe.getMessage());
|
||||
LOGGER.error("[NACOS SocketTimeoutException httpPost] currentServerAddr: {}, err : {}", currentServerAddr, stoe.getMessage());
|
||||
} catch (IOException ioe) {
|
||||
LOGGER.error("[NACOS IOException httpPost] currentServerAddr: " + currentServerAddr, ioe);
|
||||
throw ioe;
|
||||
@ -200,9 +199,9 @@ public class ServerHttpAgent implements HttpAgent {
|
||||
return result;
|
||||
}
|
||||
} catch (ConnectException ce) {
|
||||
LOGGER.error("[NACOS ConnectException httpDelete] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
|
||||
LOGGER.error("[NACOS ConnectException httpDelete] currentServerAddr:{}, err : {}", serverListMgr.getCurrentServerAddr(), ce.getMessage());
|
||||
} catch (SocketTimeoutException stoe) {
|
||||
LOGGER.error("[NACOS SocketTimeoutException httpDelete] currentServerAddr:{}", serverListMgr.getCurrentServerAddr());
|
||||
LOGGER.error("[NACOS SocketTimeoutException httpDelete] currentServerAddr:{}, err : {}", serverListMgr.getCurrentServerAddr(), stoe.getMessage());
|
||||
} catch (IOException ioe) {
|
||||
LOGGER.error("[NACOS IOException httpDelete] currentServerAddr: " + serverListMgr.getCurrentServerAddr(), ioe);
|
||||
throw ioe;
|
||||
@ -426,6 +425,7 @@ public class ServerHttpAgent implements HttpAgent {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "STSCredential{" +
|
||||
"accessKeyId='" + accessKeyId + '\'' +
|
||||
|
@ -66,6 +66,7 @@ public class CacheData {
|
||||
|
||||
/**
|
||||
* Add listener
|
||||
* if CacheData already set new content, Listener should init lastCallMd5 by CacheData.md5
|
||||
*
|
||||
* @param listener listener
|
||||
*/
|
||||
@ -73,7 +74,7 @@ public class CacheData {
|
||||
if (null == listener) {
|
||||
throw new IllegalArgumentException("listener is null");
|
||||
}
|
||||
ManagerListenerWrap wrap = new ManagerListenerWrap(listener);
|
||||
ManagerListenerWrap wrap = new ManagerListenerWrap(listener, md5);
|
||||
if (listeners.addIfAbsent(wrap)) {
|
||||
LOGGER.info("[{}] [add-listener] ok, tenant={}, dataId={}, group={}, cnt={}", name, tenant, dataId, group,
|
||||
listeners.size());
|
||||
@ -167,6 +168,7 @@ public class CacheData {
|
||||
final Listener listener = listenerWrap.listener;
|
||||
|
||||
Runnable job = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClassLoader myClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
ClassLoader appClassLoader = listener.getClass().getClassLoader();
|
||||
@ -290,6 +292,11 @@ class ManagerListenerWrap {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
ManagerListenerWrap(Listener listener, String md5) {
|
||||
this.listener = listener;
|
||||
this.lastCallMd5 = md5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (null == obj || obj.getClass() != getClass()) {
|
||||
|
@ -82,7 +82,7 @@ public class ClientWorker {
|
||||
}
|
||||
}
|
||||
|
||||
public void addTenantListeners(String dataId, String group, List<? extends Listener> listeners) {
|
||||
public void addTenantListeners(String dataId, String group, List<? extends Listener> listeners) throws NacosException {
|
||||
group = null2defaultGroup(group);
|
||||
String tenant = agent.getTenant();
|
||||
CacheData cache = addCacheDataIfAbsent(dataId, group, tenant);
|
||||
@ -91,6 +91,16 @@ public class ClientWorker {
|
||||
}
|
||||
}
|
||||
|
||||
public void addTenantListenersWithContent(String dataId, String group, String content, List<? extends Listener> listeners) throws NacosException {
|
||||
group = null2defaultGroup(group);
|
||||
String tenant = agent.getTenant();
|
||||
CacheData cache = addCacheDataIfAbsent(dataId, group, tenant);
|
||||
cache.setContent(content);
|
||||
for (Listener listener : listeners) {
|
||||
cache.addListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTenantListener(String dataId, String group, Listener listener) {
|
||||
group = null2defaultGroup(group);
|
||||
String tenant = agent.getTenant();
|
||||
@ -161,13 +171,12 @@ public class ClientWorker {
|
||||
return cache;
|
||||
}
|
||||
|
||||
public CacheData addCacheDataIfAbsent(String dataId, String group, String tenant) {
|
||||
public CacheData addCacheDataIfAbsent(String dataId, String group, String tenant) throws NacosException {
|
||||
CacheData cache = getCache(dataId, group, tenant);
|
||||
if (null != cache) {
|
||||
return cache;
|
||||
}
|
||||
String key = GroupKey.getKeyTenant(dataId, group, tenant);
|
||||
cache = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);
|
||||
synchronized (cacheMap) {
|
||||
CacheData cacheFromMap = getCache(dataId, group, tenant);
|
||||
// multiple listeners on the same dataid+group and race condition,so
|
||||
@ -177,6 +186,13 @@ public class ClientWorker {
|
||||
cache = cacheFromMap;
|
||||
// reset so that server not hang this check
|
||||
cache.setInitializing(true);
|
||||
} else {
|
||||
cache = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);
|
||||
// fix issue # 1317
|
||||
if (enableRemoteSyncConfig) {
|
||||
String content = getServerConfig(dataId, group, tenant, 3000L);
|
||||
cache.setContent(content);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, CacheData> copy = new HashMap<String, CacheData>(cacheMap.get());
|
||||
@ -457,10 +473,12 @@ public class ClientWorker {
|
||||
|
||||
private void init(Properties properties) {
|
||||
|
||||
timeout = Math.max(NumberUtils.toInt(String.valueOf(properties.get(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT)),
|
||||
timeout = Math.max(NumberUtils.toInt(properties.getProperty(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT),
|
||||
Constants.CONFIG_LONG_POLL_TIMEOUT), Constants.MIN_CONFIG_LONG_POLL_TIMEOUT);
|
||||
|
||||
taskPenaltyTime = NumberUtils.toInt(String.valueOf(properties.get(PropertyKeyConst.CONFIG_RETRY_TIME)), Constants.CONFIG_RETRY_TIME);
|
||||
taskPenaltyTime = NumberUtils.toInt(properties.getProperty(PropertyKeyConst.CONFIG_RETRY_TIME), Constants.CONFIG_RETRY_TIME);
|
||||
|
||||
enableRemoteSyncConfig = Boolean.parseBoolean(properties.getProperty(PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG));
|
||||
}
|
||||
|
||||
class LongPollingRunnable implements Runnable {
|
||||
@ -559,4 +577,5 @@ public class ClientWorker {
|
||||
private long timeout;
|
||||
private double currentLongingTaskCount = 0;
|
||||
private int taskPenaltyTime;
|
||||
private boolean enableRemoteSyncConfig = false;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ public class TimerService {
|
||||
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||
static ScheduledExecutorService scheduledExecutor = Executors
|
||||
.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setName("com.alibaba.nacos.client.Timer");
|
||||
|
@ -85,6 +85,7 @@ public final class CredentialService implements SpasCredentialLoader {
|
||||
LOGGER.info("[{}] {} is freed", appName, this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Credentials getCredential() {
|
||||
Credentials localCredential = credentials;
|
||||
if (localCredential.valid()) {
|
||||
|
@ -38,6 +38,7 @@ public class Credentials implements SpasCredential {
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
@ -46,6 +47,7 @@ public class Credentials implements SpasCredential {
|
||||
this.accessKey = accessKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public class FailoverReactor {
|
||||
String failover = ConcurrentDiskUtil.getFileContent(failoverDir + UtilAndComs.FAILOVER_SWITCH,
|
||||
Charset.defaultCharset().toString());
|
||||
if (!StringUtils.isEmpty(failover)) {
|
||||
List<String> lines = Arrays.asList(failover.split(DiskCache.getLineSeperator()));
|
||||
List<String> lines = Arrays.asList(failover.split(DiskCache.getLineSeparator()));
|
||||
|
||||
for (String line : lines) {
|
||||
String line1 = line.trim();
|
||||
@ -212,6 +212,7 @@ public class FailoverReactor {
|
||||
}
|
||||
|
||||
class DiskFileWriter extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
Map<String, ServiceInfo> map = hostReactor.getServiceInfoMap();
|
||||
for (Map.Entry<String, ServiceInfo> entry : map.entrySet()) {
|
||||
|
@ -71,9 +71,8 @@ public class DiskCache {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getLineSeperator() {
|
||||
String lineSeparator = System.getProperty("line.separator");
|
||||
return lineSeparator;
|
||||
public static String getLineSeparator() {
|
||||
return System.getProperty("line.separator");
|
||||
}
|
||||
|
||||
public static Map<String, ServiceInfo> read(String cacheDir) {
|
||||
@ -82,7 +81,7 @@ public class DiskCache {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
File[] files = makeSureCacheDirExists(cacheDir).listFiles();
|
||||
if (files == null) {
|
||||
if (files == null || files.length == 0) {
|
||||
return domMap;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class Balancer {
|
||||
public static class RandomByWeight {
|
||||
|
||||
public static List<Instance> selectAll(ServiceInfo serviceInfo) {
|
||||
List<Instance> hosts = nothing(serviceInfo);
|
||||
List<Instance> hosts = serviceInfo.getHosts();
|
||||
|
||||
if (CollectionUtils.isEmpty(hosts)) {
|
||||
throw new IllegalStateException("no host to srv for serviceInfo: " + serviceInfo.getName());
|
||||
@ -59,10 +59,6 @@ public class Balancer {
|
||||
|
||||
return getHostByRandomWeight(hosts);
|
||||
}
|
||||
|
||||
public static List<Instance> nothing(ServiceInfo serviceInfo) {
|
||||
return serviceInfo.getHosts();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,7 +87,6 @@ public class Balancer {
|
||||
NAMING_LOGGER.debug("for (Host host : hosts)");
|
||||
vipChooser.refresh(hostsWithWeight);
|
||||
NAMING_LOGGER.debug("vipChooser.refresh");
|
||||
Instance host = vipChooser.randomWithWeight();
|
||||
return host;
|
||||
return vipChooser.randomWithWeight();
|
||||
}
|
||||
}
|
||||
|
@ -140,9 +140,7 @@ public class HostReactor {
|
||||
|
||||
if (!oldHostMap.containsKey(key)) {
|
||||
newHosts.add(host);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Instance> entry : oldHostMap.entrySet()) {
|
||||
@ -154,7 +152,6 @@ public class HostReactor {
|
||||
|
||||
if (!newHostMap.containsKey(key)) {
|
||||
remvHosts.add(host);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class PushReceiver implements Runnable {
|
||||
|
||||
private ScheduledExecutorService executorService;
|
||||
|
||||
public static final int UDP_MSS = 64 * 1024;
|
||||
private static final int UDP_MSS = 64 * 1024;
|
||||
|
||||
private DatagramSocket udpSocket;
|
||||
|
||||
|
@ -31,10 +31,12 @@ public class GenericPoller<T> implements Poller<T> {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
return items.get(Math.abs(index.getAndIncrement() % items.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Poller<T> refresh(List<T> items) {
|
||||
return new GenericPoller<T>(items);
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ public final class JvmRandom extends Random {
|
||||
* @param seed ignored
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setSeed(long seed) {
|
||||
if (this.constructed) {
|
||||
throw new UnsupportedOperationException();
|
||||
@ -75,6 +76,7 @@ public final class JvmRandom extends Random {
|
||||
* @return Nothing, this method always throws an UnsupportedOperationException.
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
@Override
|
||||
public synchronized double nextGaussian() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@ -85,6 +87,7 @@ public final class JvmRandom extends Random {
|
||||
* @param byteArray ignored
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
@Override
|
||||
public void nextBytes(byte[] byteArray) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@ -95,6 +98,7 @@ public final class JvmRandom extends Random {
|
||||
*
|
||||
* @return the random int
|
||||
*/
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return nextInt(Integer.MAX_VALUE);
|
||||
}
|
||||
@ -107,6 +111,7 @@ public final class JvmRandom extends Random {
|
||||
* @return the random int
|
||||
* @throws IllegalArgumentException when <code>n <= 0</code>
|
||||
*/
|
||||
@Override
|
||||
public int nextInt(int n) {
|
||||
return SHARED_RANDOM.nextInt(n);
|
||||
}
|
||||
@ -117,6 +122,7 @@ public final class JvmRandom extends Random {
|
||||
*
|
||||
* @return the random long
|
||||
*/
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return nextLong(Long.MAX_VALUE);
|
||||
}
|
||||
@ -158,6 +164,7 @@ public final class JvmRandom extends Random {
|
||||
*
|
||||
* @return the random boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return SHARED_RANDOM.nextBoolean();
|
||||
}
|
||||
@ -168,6 +175,7 @@ public final class JvmRandom extends Random {
|
||||
*
|
||||
* @return the random float
|
||||
*/
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return SHARED_RANDOM.nextFloat();
|
||||
}
|
||||
@ -177,6 +185,7 @@ public final class JvmRandom extends Random {
|
||||
*
|
||||
* @return the random double
|
||||
*/
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return SHARED_RANDOM.nextDouble();
|
||||
}
|
||||
|
@ -146,6 +146,7 @@ public class ThreadLocalRandom extends Random {
|
||||
* The actual ThreadLocal
|
||||
*/
|
||||
private static final ThreadLocal<ThreadLocalRandom> localRandom = new ThreadLocal<ThreadLocalRandom>() {
|
||||
@Override
|
||||
protected ThreadLocalRandom initialValue() {
|
||||
return new ThreadLocalRandom();
|
||||
}
|
||||
@ -165,6 +166,7 @@ public class ThreadLocalRandom extends Random {
|
||||
*
|
||||
* @throws UnsupportedOperationException always
|
||||
*/
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
if (initialized) {
|
||||
throw new UnsupportedOperationException();
|
||||
@ -172,6 +174,7 @@ public class ThreadLocalRandom extends Random {
|
||||
rnd = (seed ^ multiplier) & mask;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int next(int bits) {
|
||||
rnd = (rnd * multiplier + addend) & mask;
|
||||
return (int)(rnd >>> (48 - bits));
|
||||
|
@ -17,11 +17,9 @@ package com.alibaba.nacos.client;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
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.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.pojo.ListView;
|
||||
import com.alibaba.nacos.api.selector.ExpressionSelector;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -34,36 +34,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@RequestMapping(UtilsAndCommons.NACOS_CMDB_CONTEXT + "/ops")
|
||||
public class OperationController {
|
||||
|
||||
@Autowired
|
||||
private SwitchAndOptions switches;
|
||||
|
||||
@Autowired
|
||||
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)
|
||||
public String queryLabel(HttpServletRequest request) throws Exception {
|
||||
String entry = WebUtils.required(request, "entry");
|
||||
|
@ -25,47 +25,31 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class SwitchAndOptions {
|
||||
|
||||
@Value("${nacos.cmdb.dumpTaskInterval}")
|
||||
@Value("${nacos.cmdb.dumpTaskInterval:3600}")
|
||||
private int dumpTaskInterval;
|
||||
|
||||
@Value("${nacos.cmdb.eventTaskInterval}")
|
||||
@Value("${nacos.cmdb.eventTaskInterval:10}")
|
||||
private int eventTaskInterval;
|
||||
|
||||
@Value("${nacos.cmdb.labelTaskInterval}")
|
||||
@Value("${nacos.cmdb.labelTaskInterval:300}")
|
||||
private int labelTaskInterval;
|
||||
|
||||
@Value("${nacos.cmdb.loadDataAtStart}")
|
||||
@Value("${nacos.cmdb.loadDataAtStart:false}")
|
||||
private boolean loadDataAtStart;
|
||||
|
||||
public int getDumpTaskInterval() {
|
||||
return dumpTaskInterval;
|
||||
}
|
||||
|
||||
public void setDumpTaskInterval(int dumpTaskInterval) {
|
||||
this.dumpTaskInterval = dumpTaskInterval;
|
||||
}
|
||||
|
||||
public int getEventTaskInterval() {
|
||||
return eventTaskInterval;
|
||||
}
|
||||
|
||||
public void setEventTaskInterval(int eventTaskInterval) {
|
||||
this.eventTaskInterval = eventTaskInterval;
|
||||
}
|
||||
|
||||
public int getLabelTaskInterval() {
|
||||
return labelTaskInterval;
|
||||
}
|
||||
|
||||
public void setLabelTaskInterval(int labelTaskInterval) {
|
||||
this.labelTaskInterval = labelTaskInterval;
|
||||
}
|
||||
|
||||
public boolean isLoadDataAtStart() {
|
||||
return loadDataAtStart;
|
||||
}
|
||||
|
||||
public void setLoadDataAtStart(boolean loadDataAtStart) {
|
||||
this.loadDataAtStart = loadDataAtStart;
|
||||
}
|
||||
}
|
||||
|
@ -54,8 +54,6 @@ public class CmdbProvider implements CmdbReader, CmdbWriter {
|
||||
|
||||
private Set<String> entityTypeSet = new HashSet<>();
|
||||
|
||||
private List<EntityEvent> eventList = new ArrayList<>();
|
||||
|
||||
private long eventTimestamp = System.currentTimeMillis();
|
||||
|
||||
public CmdbProvider() throws NacosException {
|
||||
|
@ -31,25 +31,29 @@ import java.util.zip.GZIPInputStream;
|
||||
public class IoUtils {
|
||||
|
||||
public static byte[] tryDecompress(InputStream raw) throws Exception {
|
||||
|
||||
GZIPInputStream gis = null;
|
||||
ByteArrayOutputStream out = null;
|
||||
try {
|
||||
GZIPInputStream gis
|
||||
= new GZIPInputStream(raw);
|
||||
ByteArrayOutputStream out
|
||||
= new ByteArrayOutputStream();
|
||||
|
||||
gis = new GZIPInputStream(raw);
|
||||
out = new ByteArrayOutputStream();
|
||||
IOUtils.copy(gis, out);
|
||||
|
||||
return out.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
if (gis != null) {
|
||||
gis.close();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static private BufferedReader toBufferedReader(Reader reader) {
|
||||
return reader instanceof BufferedReader ? (BufferedReader)reader : new BufferedReader(
|
||||
return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(
|
||||
reader);
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,7 @@ public final class TaskManager implements TaskManagerMBean {
|
||||
|
||||
class ProcessRunnable implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!TaskManager.this.closed.get()) {
|
||||
try {
|
||||
@ -248,6 +249,7 @@ public final class TaskManager implements TaskManagerMBean {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTaskInfos() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String taskType : this.taskProcessors.keySet()) {
|
||||
|
@ -94,6 +94,7 @@ public class ConfigInfoBase implements Serializable, Comparable<ConfigInfoBase>
|
||||
writer.write(this.content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ConfigInfoBase o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
|
@ -54,6 +54,7 @@ public class GroupKey extends GroupKey2 {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return dataId + "+" + group;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;
|
||||
|
||||
@ -82,8 +81,6 @@ class PrintMemoryTask implements Runnable {
|
||||
|
||||
class NotifyTaskQueueMonitorTask implements Runnable {
|
||||
final private AsyncNotifyService notifySingleService;
|
||||
private AtomicInteger notifyTask = new AtomicInteger();
|
||||
|
||||
|
||||
NotifyTaskQueueMonitorTask(AsyncNotifyService notifySingleService) {
|
||||
this.notifySingleService = notifySingleService;
|
||||
|
@ -16,7 +16,6 @@
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -31,11 +30,9 @@ import static com.alibaba.nacos.core.utils.SystemUtils.STANDALONE_MODE;
|
||||
@Component
|
||||
public class DynamicDataSource implements ApplicationContextAware {
|
||||
|
||||
@Autowired
|
||||
private PropertyUtil propertyUtil;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
@ -47,7 +44,7 @@ public class DynamicDataSource implements ApplicationContextAware {
|
||||
public DataSourceService getDataSource() {
|
||||
DataSourceService dataSourceService = null;
|
||||
|
||||
if (STANDALONE_MODE && !propertyUtil.isStandaloneUseMysql()) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
dataSourceService = (DataSourceService)applicationContext.getBean("localDataSourceService");
|
||||
} else {
|
||||
dataSourceService = (DataSourceService)applicationContext.getBean("basicDataSourceService");
|
||||
|
@ -22,7 +22,6 @@ import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -62,9 +61,6 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
private JdbcTemplate jt;
|
||||
private TransactionTemplate tjt;
|
||||
|
||||
@Autowired
|
||||
private PropertyUtil propertyUtil;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
BasicDataSource ds = new BasicDataSource();
|
||||
@ -90,7 +86,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
tm.setDataSource(ds);
|
||||
tjt.setTimeout(5000);
|
||||
|
||||
if (STANDALONE_MODE && !propertyUtil.isStandaloneUseMysql()) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
@ -371,6 +371,7 @@ public class LongPollingService extends AbstractEventListener {
|
||||
@Override
|
||||
public void run() {
|
||||
asyncTimeoutFuture = scheduler.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
getRetainIps().put(ClientLongPolling.this.ip, System.currentTimeMillis());
|
||||
|
@ -94,6 +94,7 @@ public class PersistService {
|
||||
|
||||
static final class ConfigInfoWrapperRowMapper implements
|
||||
RowMapper<ConfigInfoWrapper> {
|
||||
@Override
|
||||
public ConfigInfoWrapper mapRow(ResultSet rs, int rowNum)
|
||||
throws SQLException {
|
||||
ConfigInfoWrapper info = new ConfigInfoWrapper();
|
||||
@ -128,6 +129,7 @@ public class PersistService {
|
||||
|
||||
static final class ConfigInfoBetaWrapperRowMapper implements
|
||||
RowMapper<ConfigInfoBetaWrapper> {
|
||||
@Override
|
||||
public ConfigInfoBetaWrapper mapRow(ResultSet rs, int rowNum)
|
||||
throws SQLException {
|
||||
ConfigInfoBetaWrapper info = new ConfigInfoBetaWrapper();
|
||||
@ -163,6 +165,7 @@ public class PersistService {
|
||||
|
||||
static final class ConfigInfoTagWrapperRowMapper implements
|
||||
RowMapper<ConfigInfoTagWrapper> {
|
||||
@Override
|
||||
public ConfigInfoTagWrapper mapRow(ResultSet rs, int rowNum)
|
||||
throws SQLException {
|
||||
ConfigInfoTagWrapper info = new ConfigInfoTagWrapper();
|
||||
@ -198,6 +201,7 @@ public class PersistService {
|
||||
|
||||
static final class ConfigInfoRowMapper implements
|
||||
RowMapper<ConfigInfo> {
|
||||
@Override
|
||||
public ConfigInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigInfo info = new ConfigInfo();
|
||||
|
||||
@ -227,6 +231,7 @@ public class PersistService {
|
||||
|
||||
static final class ConfigKeyRowMapper implements
|
||||
RowMapper<ConfigKey> {
|
||||
@Override
|
||||
public ConfigKey mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigKey info = new ConfigKey();
|
||||
|
||||
@ -239,6 +244,7 @@ public class PersistService {
|
||||
}
|
||||
|
||||
static final class ConfigAdvanceInfoRowMapper implements RowMapper<ConfigAdvanceInfo> {
|
||||
@Override
|
||||
public ConfigAdvanceInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigAdvanceInfo info = new ConfigAdvanceInfo();
|
||||
info.setCreateTime(rs.getTimestamp("gmt_modified").getTime());
|
||||
@ -255,6 +261,7 @@ public class PersistService {
|
||||
}
|
||||
|
||||
static final class ConfigAllInfoRowMapper implements RowMapper<ConfigAllInfo> {
|
||||
@Override
|
||||
public ConfigAllInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigAllInfo info = new ConfigAllInfo();
|
||||
info.setDataId(rs.getString("data_id"));
|
||||
@ -291,6 +298,7 @@ public class PersistService {
|
||||
|
||||
static final class ConfigInfo4BetaRowMapper implements
|
||||
RowMapper<ConfigInfo4Beta> {
|
||||
@Override
|
||||
public ConfigInfo4Beta mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigInfo4Beta info = new ConfigInfo4Beta();
|
||||
|
||||
@ -320,6 +328,7 @@ public class PersistService {
|
||||
|
||||
static final class ConfigInfo4TagRowMapper implements
|
||||
RowMapper<ConfigInfo4Tag> {
|
||||
@Override
|
||||
public ConfigInfo4Tag mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigInfo4Tag info = new ConfigInfo4Tag();
|
||||
|
||||
@ -349,6 +358,7 @@ public class PersistService {
|
||||
|
||||
static final class ConfigInfoBaseRowMapper implements
|
||||
RowMapper<ConfigInfoBase> {
|
||||
@Override
|
||||
public ConfigInfoBase mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigInfoBase info = new ConfigInfoBase();
|
||||
|
||||
@ -371,6 +381,7 @@ public class PersistService {
|
||||
|
||||
static final class ConfigInfoAggrRowMapper implements
|
||||
RowMapper<ConfigInfoAggr> {
|
||||
@Override
|
||||
public ConfigInfoAggr mapRow(ResultSet rs, int rowNum)
|
||||
throws SQLException {
|
||||
ConfigInfoAggr info = new ConfigInfoAggr();
|
||||
@ -385,6 +396,7 @@ public class PersistService {
|
||||
}
|
||||
|
||||
static final class ConfigInfoChangedRowMapper implements RowMapper<ConfigInfoChanged> {
|
||||
@Override
|
||||
public ConfigInfoChanged mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigInfoChanged info = new ConfigInfoChanged();
|
||||
info.setDataId(rs.getString("data_id"));
|
||||
@ -395,6 +407,7 @@ public class PersistService {
|
||||
}
|
||||
|
||||
static final class ConfigHistoryRowMapper implements RowMapper<ConfigHistoryInfo> {
|
||||
@Override
|
||||
public ConfigHistoryInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigHistoryInfo configHistoryInfo = new ConfigHistoryInfo();
|
||||
configHistoryInfo.setId(rs.getLong("nid"));
|
||||
@ -411,6 +424,7 @@ public class PersistService {
|
||||
}
|
||||
|
||||
static final class ConfigHistoryDetailRowMapper implements RowMapper<ConfigHistoryInfo> {
|
||||
@Override
|
||||
public ConfigHistoryInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ConfigHistoryInfo configHistoryInfo = new ConfigHistoryInfo();
|
||||
configHistoryInfo.setId(rs.getLong("nid"));
|
||||
@ -432,6 +446,7 @@ public class PersistService {
|
||||
;
|
||||
|
||||
static final class TenantInfoRowMapper implements RowMapper<TenantInfo> {
|
||||
@Override
|
||||
public TenantInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
TenantInfo info = new TenantInfo();
|
||||
info.setTenantId(rs.getString("tenant_id"));
|
||||
@ -442,6 +457,7 @@ public class PersistService {
|
||||
}
|
||||
|
||||
static final class UserRowMapper implements RowMapper<User> {
|
||||
@Override
|
||||
public User mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
User user = new User();
|
||||
user.setUsername(rs.getString("username"));
|
||||
@ -799,6 +815,7 @@ public class PersistService {
|
||||
|
||||
try {
|
||||
this.jt.update(sql, new PreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(PreparedStatement ps) throws SQLException {
|
||||
int index = 1;
|
||||
ps.setString(index++, dataId);
|
||||
@ -822,6 +839,7 @@ public class PersistService {
|
||||
|
||||
try {
|
||||
this.jt.update(sql, new PreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(PreparedStatement ps) throws SQLException {
|
||||
int index = 1;
|
||||
ps.setString(index++, dataId);
|
||||
@ -2637,6 +2655,7 @@ public class PersistService {
|
||||
|
||||
try {
|
||||
jt.update(new PreparedStatementCreator() {
|
||||
@Override
|
||||
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
|
||||
PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
ps.setString(1, configInfo.getDataId());
|
||||
|
@ -319,10 +319,12 @@ public class AsyncNotifyService extends AbstractEventListener {
|
||||
// this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFailCount(int count) {
|
||||
this.failCount = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFailCount() {
|
||||
return failCount;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public class SimpleFlowData {
|
||||
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||
private ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setName("nacos flow control thread");
|
||||
@ -52,6 +53,7 @@ public class SimpleFlowData {
|
||||
}
|
||||
timer.scheduleAtFixedRate(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
rotateSlot();
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ public class SimpleIPFlowData {
|
||||
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||
private ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setName("nacos ip flow control thread");
|
||||
@ -49,6 +50,7 @@ public class SimpleIPFlowData {
|
||||
|
||||
class DefaultIPFlowDataManagerTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
rotateSlot();
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -34,8 +33,6 @@ public class DiskServiceUnitTest {
|
||||
|
||||
private DiskUtil diskService;
|
||||
|
||||
private ServletContext servletContext;
|
||||
|
||||
private File tempFile;
|
||||
|
||||
private String path;
|
||||
|
@ -7,8 +7,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
@WebAppConfiguration
|
||||
|
@ -18,8 +18,7 @@ package com.alibaba.nacos.console.controller;
|
||||
import com.alibaba.nacos.console.config.WebSecurityConfig;
|
||||
import com.alibaba.nacos.config.server.model.RestResult;
|
||||
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.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
|
@ -65,10 +65,4 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
||||
# default current work dir
|
||||
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
|
||||
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
@ -19,7 +19,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Nacos</title>
|
||||
<link rel="shortcut icon" href="//www.aliyun.com/favicon.ico" type="image/x-icon" />
|
||||
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/console1412.css">
|
||||
<!-- 第三方css开始 -->
|
||||
|
@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
ls ~/nvm || git clone https://github.com/creationix/nvm.git ~/nvm
|
||||
source ~/nvm/nvm.sh
|
||||
nvm install v7.10.0
|
||||
|
@ -3631,6 +3631,18 @@ glob@^7.0.0, glob@^7.0.3, glob@^7.1.2, glob@^7.1.3, glob@~7.1.1:
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
glob@^7.0.5:
|
||||
version "7.1.4"
|
||||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
|
||||
integrity sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==
|
||||
dependencies:
|
||||
fs.realpath "^1.0.0"
|
||||
inflight "^1.0.4"
|
||||
inherits "2"
|
||||
minimatch "^3.0.4"
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
global-modules@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-1.0.0.tgz#6d770f0eb523ac78164d72b5e71a8877265cc3ea"
|
||||
@ -8312,6 +8324,14 @@ yallist@^3.0.0, yallist@^3.0.2:
|
||||
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9"
|
||||
integrity sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==
|
||||
|
||||
yamljs@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/yamljs/-/yamljs-0.3.0.tgz#dc060bf267447b39f7304e9b2bfbe8b5a7ddb03b"
|
||||
integrity sha512-C/FsVVhht4iPQYXOInoxUM/1ELSf9EsgKH34FofQOp6hwCPrW4vG4w5++TED3xRUo8gD7l0P1J1dLlDYzODsTQ==
|
||||
dependencies:
|
||||
argparse "^1.0.7"
|
||||
glob "^7.0.5"
|
||||
|
||||
yargs-parser@^11.1.1:
|
||||
version "11.1.1"
|
||||
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-11.1.1.tgz#879a0865973bca9f6bab5cbdf3b1c67ec7d3bcf4"
|
||||
|
@ -20,7 +20,7 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Nacos</title>
|
||||
|
||||
<link rel="shortcut icon" href="//www.aliyun.com/favicon.ico" type="image/x-icon">
|
||||
<link rel="shortcut icon" href="console-fe/public/img/favicon.ico" type="image/x-icon">
|
||||
<link rel="stylesheet" type="text/css" href="console-fe/public/css/bootstrap.css">
|
||||
<link rel="stylesheet" type="text/css" href="console-fe/public/css/console1412.css">
|
||||
<!-- 第三方css开始 -->
|
||||
|
@ -114,8 +114,7 @@ public class InetUtils {
|
||||
log.info("Testing interface: " + ifc.getDisplayName());
|
||||
if (ifc.getIndex() < lowest || result == null) {
|
||||
lowest = ifc.getIndex();
|
||||
}
|
||||
else if (result != null) {
|
||||
} else if (result != null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class SystemUtils {
|
||||
/**
|
||||
* Standalone mode or not
|
||||
*/
|
||||
public static boolean STANDALONE_MODE = Boolean.getBoolean(STANDALONE_MODE_PROPERTY_NAME);
|
||||
public static final boolean STANDALONE_MODE = Boolean.getBoolean(STANDALONE_MODE_PROPERTY_NAME);
|
||||
|
||||
public static final String STANDALONE_MODE_ALONE = "standalone";
|
||||
public static final String STANDALONE_MODE_CLUSTER = "cluster";
|
||||
@ -50,7 +50,7 @@ public class SystemUtils {
|
||||
/**
|
||||
* server
|
||||
*/
|
||||
public static String FUNCTION_MODE = System.getProperty(FUNCTION_MODE_PROPERTY_NAME);
|
||||
public static final String FUNCTION_MODE = System.getProperty(FUNCTION_MODE_PROPERTY_NAME);
|
||||
|
||||
public static final String FUNCTION_MODE_CONFIG = "config";
|
||||
public static final String FUNCTION_MODE_NAMING = "naming";
|
||||
|
@ -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.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
|
||||
|
@ -56,7 +56,7 @@ public class ServerListManager {
|
||||
|
||||
private Set<String> liveSites = new HashSet<>();
|
||||
|
||||
public final String LOCALHOST_SITE = UtilsAndCommons.UNKNOWN_SITE;
|
||||
private final static String LOCALHOST_SITE = UtilsAndCommons.UNKNOWN_SITE;
|
||||
|
||||
private long lastHealthServerMillis = 0L;
|
||||
|
||||
|
@ -27,6 +27,8 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.commons.lang3.CharEncoding.UTF_8;
|
||||
|
||||
/**
|
||||
* Use FastJSON to serialize data
|
||||
*
|
||||
@ -44,7 +46,7 @@ public class FastJsonSerializer implements Serializer {
|
||||
@Override
|
||||
public <T> T deserialize(byte[] data, Class<T> clazz) {
|
||||
try {
|
||||
return JSON.parseObject(new String(data, "UTF-8"), clazz);
|
||||
return JSON.parseObject(new String(data, UTF_8), clazz);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
@ -53,7 +55,7 @@ public class FastJsonSerializer implements Serializer {
|
||||
@Override
|
||||
public <T> T deserialize(byte[] data, TypeReference<T> clazz) {
|
||||
try {
|
||||
String dataString = new String(data, "UTF-8");
|
||||
String dataString = new String(data, UTF_8);
|
||||
return JSON.parseObject(dataString, clazz);
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.error("deserialize data failed.", e);
|
||||
@ -64,7 +66,7 @@ public class FastJsonSerializer implements Serializer {
|
||||
@Override
|
||||
public <T extends Record> Map<String, Datum<T>> deserializeMap(byte[] data, Class<T> clazz) {
|
||||
try {
|
||||
String dataString = new String(data, "UTF-8");
|
||||
String dataString = new String(data, UTF_8);
|
||||
Map<String, JSONObject> dataMap = JSON.parseObject(dataString, new TypeReference<Map<String, JSONObject>>() {
|
||||
});
|
||||
|
||||
|
@ -19,7 +19,6 @@ import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.core.utils.SystemUtils;
|
||||
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.servers.Server;
|
||||
import com.alibaba.nacos.naming.cluster.transport.Serializer;
|
||||
|
@ -123,7 +123,7 @@ public class RaftCore {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
datums = raftStore.loadDatums(notifier);
|
||||
raftStore.loadDatums(notifier, datums);
|
||||
|
||||
setTerm(NumberUtils.toLong(raftStore.loadMeta().getProperty("term"), 0L));
|
||||
|
||||
|
@ -40,7 +40,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* @author nacos
|
||||
@ -54,9 +54,8 @@ public class RaftStore {
|
||||
|
||||
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;
|
||||
long start = System.currentTimeMillis();
|
||||
for (File cache : listCaches()) {
|
||||
@ -77,7 +76,6 @@ public class RaftStore {
|
||||
}
|
||||
|
||||
Loggers.RAFT.info("finish loading all datums, size: {} cost {} ms.", datums.size(), (System.currentTimeMillis() - start));
|
||||
return datums;
|
||||
}
|
||||
|
||||
public synchronized Properties loadMeta() throws Exception {
|
||||
|
@ -16,14 +16,11 @@
|
||||
package com.alibaba.nacos.naming.controllers;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.naming.CommonParams;
|
||||
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
|
||||
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.Service;
|
||||
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.misc.Loggers;
|
||||
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.StringUtils;
|
||||
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 javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nkorange
|
||||
|
@ -18,7 +18,6 @@ package com.alibaba.nacos.naming.controllers;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.nacos.core.utils.WebUtils;
|
||||
import com.alibaba.nacos.naming.cluster.ServerMode;
|
||||
import com.alibaba.nacos.naming.cluster.transport.Serializer;
|
||||
import com.alibaba.nacos.naming.consistency.Datum;
|
||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||
|
@ -22,7 +22,6 @@ import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.naming.CommonParams;
|
||||
import com.alibaba.nacos.api.naming.utils.NamingUtils;
|
||||
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.Instance;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
@ -373,7 +372,11 @@ public class InstanceController {
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
|
||||
if (service == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "service not found: " + serviceName);
|
||||
if (Loggers.DEBUG_LOG.isDebugEnabled()) {
|
||||
Loggers.DEBUG_LOG.debug("no instance to serve for service: " + serviceName);
|
||||
}
|
||||
result.put("hosts", new JSONArray());
|
||||
return result;
|
||||
}
|
||||
|
||||
checkIfDisabled(service);
|
||||
|
@ -39,7 +39,6 @@ import com.alibaba.nacos.naming.web.NeedAuth;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@ -28,6 +28,7 @@ import com.alibaba.nacos.naming.core.*;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.pojo.Subscriber;
|
||||
import com.alibaba.nacos.naming.selector.LabelSelector;
|
||||
import com.alibaba.nacos.naming.selector.NoneSelector;
|
||||
import com.alibaba.nacos.naming.selector.Selector;
|
||||
@ -40,7 +41,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
|
||||
@ -62,6 +62,9 @@ public class ServiceController {
|
||||
@Autowired
|
||||
private ServerListManager serverListManager;
|
||||
|
||||
@Autowired
|
||||
private SubscribeManager subscribeManager;
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||
public String create(HttpServletRequest request) throws Exception {
|
||||
|
||||
@ -365,6 +368,31 @@ public class ServiceController {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* get subscriber list
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/subscribers", method = RequestMethod.GET)
|
||||
public JSONObject subscribers(HttpServletRequest request) {
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
boolean aggregation = Boolean.valueOf(WebUtils.optional(request, "aggregation", String.valueOf(Boolean.TRUE)));
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
try {
|
||||
List<Subscriber> subscribers = subscribeManager.getSubscribers(serviceName, namespaceId, aggregation);
|
||||
result.put("subscribers", subscribers);
|
||||
return result;
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<String> filterInstanceMetadata(String namespaceId, List<String> serviceNames, String key, String value) {
|
||||
|
||||
List<String> filteredServiceNames = new ArrayList<>();
|
||||
|
@ -34,7 +34,7 @@ import java.util.regex.Pattern;
|
||||
public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance implements Comparable {
|
||||
|
||||
private static final double MAX_WEIGHT_VALUE = 10000.0D;
|
||||
private static final double MIN_POSTIVE_WEIGHT_VALUE = 0.01D;
|
||||
private static final double MIN_POSITIVE_WEIGHT_VALUE = 0.01D;
|
||||
private static final double MIN_WEIGHT_VALUE = 0.00D;
|
||||
|
||||
private volatile long lastBeat = System.currentTimeMillis();
|
||||
@ -48,13 +48,13 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
||||
|
||||
private String app;
|
||||
|
||||
public static final Pattern IP_PATTERN
|
||||
private static final Pattern IP_PATTERN
|
||||
= Pattern.compile("(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}):?(\\d{1,5})?");
|
||||
|
||||
public static final Pattern ONLY_DIGIT_AND_DOT
|
||||
private static final Pattern ONLY_DIGIT_AND_DOT
|
||||
= Pattern.compile("(\\d|\\.)+");
|
||||
|
||||
public static final String SPLITER = "_";
|
||||
private static final String SPLITER = "_";
|
||||
|
||||
public Instance() {
|
||||
}
|
||||
@ -191,8 +191,8 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
||||
ip.setWeight(MAX_WEIGHT_VALUE);
|
||||
}
|
||||
|
||||
if (ip.getWeight() < MIN_POSTIVE_WEIGHT_VALUE && ip.getWeight() > MIN_WEIGHT_VALUE) {
|
||||
ip.setWeight(MIN_POSTIVE_WEIGHT_VALUE);
|
||||
if (ip.getWeight() < MIN_POSITIVE_WEIGHT_VALUE && ip.getWeight() > MIN_WEIGHT_VALUE) {
|
||||
ip.setWeight(MIN_POSITIVE_WEIGHT_VALUE);
|
||||
} else if (ip.getWeight() < MIN_WEIGHT_VALUE) {
|
||||
ip.setWeight(0.0D);
|
||||
}
|
||||
|
@ -427,6 +427,7 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
recalculateChecksum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChecksum() {
|
||||
if (StringUtils.isEmpty(checksum)) {
|
||||
recalculateChecksum();
|
||||
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.naming.core;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.api.naming.CommonParams;
|
||||
import com.alibaba.nacos.naming.boot.RunningConfig;
|
||||
import com.alibaba.nacos.naming.cluster.ServerListManager;
|
||||
import com.alibaba.nacos.naming.cluster.servers.Server;
|
||||
import com.alibaba.nacos.naming.misc.HttpClient;
|
||||
import com.alibaba.nacos.naming.misc.NetUtils;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.pojo.Subscriber;
|
||||
import com.alibaba.nacos.naming.pojo.Subscribers;
|
||||
import com.alibaba.nacos.naming.push.PushService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Nicholas
|
||||
* @since 1.0.1
|
||||
*/
|
||||
@Service
|
||||
public class SubscribeManager {
|
||||
|
||||
private static final String SUBSCRIBER_ON_SYNC_URL = "/service/subscribers";
|
||||
|
||||
@Autowired
|
||||
private PushService pushService;
|
||||
|
||||
@Autowired
|
||||
private ServerListManager serverListManager;
|
||||
|
||||
|
||||
private List<Subscriber> getSubscribers(String serviceName, String namespaceId) {
|
||||
return pushService.getClients(serviceName, namespaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param serviceName
|
||||
* @param namespaceId
|
||||
* @param aggregation
|
||||
* @return
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public List<Subscriber> getSubscribers(String serviceName, String namespaceId, boolean aggregation) throws InterruptedException {
|
||||
if (aggregation) {
|
||||
// size = 1 means only myself in the list, we need at least one another server alive:
|
||||
if (serverListManager.getHealthyServers().size() <= 1) {
|
||||
return getSubscribers(serviceName, namespaceId);
|
||||
}
|
||||
|
||||
List<Subscriber> subscriberList = new ArrayList<Subscriber>();
|
||||
// try sync data from remote server:
|
||||
for (Server server : serverListManager.getHealthyServers()) {
|
||||
|
||||
Map<String, String> paramValues = new HashMap<>(128);
|
||||
paramValues.put(CommonParams.SERVICE_NAME, serviceName);
|
||||
paramValues.put(CommonParams.NAMESPACE_ID, namespaceId);
|
||||
paramValues.put("aggregation", String.valueOf(Boolean.FALSE));
|
||||
if (NetUtils.localServer().equals(server.getKey())) {
|
||||
subscriberList.addAll(getSubscribers(serviceName, namespaceId));
|
||||
}
|
||||
|
||||
HttpClient.HttpResult result = HttpClient.httpGet("http://" + server.getKey() + RunningConfig.getContextPath()
|
||||
+ UtilsAndCommons.NACOS_NAMING_CONTEXT + SUBSCRIBER_ON_SYNC_URL, new ArrayList<>(), paramValues);
|
||||
|
||||
if (HttpURLConnection.HTTP_OK == result.code) {
|
||||
Subscribers subscribers = (Subscribers) JSONObject.parseObject(result.content, Subscribers.class);
|
||||
subscriberList.addAll(subscribers.getSubscribers());
|
||||
}
|
||||
return subscriberList.stream().filter(distinctByKey(Subscriber::toString)).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
} else {
|
||||
// local server
|
||||
return getSubscribers(serviceName, namespaceId);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
|
||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>(128);
|
||||
return object -> seen.putIfAbsent(keyExtractor.apply(object), Boolean.TRUE) == null;
|
||||
}
|
||||
}
|
@ -55,7 +55,7 @@ public class HttpHealthCheckProcessor implements HealthCheckProcessor {
|
||||
|
||||
private static AsyncHttpClient asyncHttpClient;
|
||||
|
||||
public static final int CONNECT_TIMEOUT_MS = 500;
|
||||
private static final int CONNECT_TIMEOUT_MS = 500;
|
||||
|
||||
static {
|
||||
try {
|
||||
|
@ -23,7 +23,6 @@ import com.alibaba.fastjson.serializer.JSONSerializer;
|
||||
import com.alibaba.fastjson.serializer.ObjectSerializer;
|
||||
import com.alibaba.fastjson.serializer.SerializeWriter;
|
||||
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
@ -143,6 +143,7 @@ public class RsInfo {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ package com.alibaba.nacos.naming.healthcheck;
|
||||
|
||||
import com.alibaba.nacos.naming.core.Cluster;
|
||||
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.SwitchDomain;
|
||||
import com.alibaba.nacos.naming.monitor.MetricsMonitor;
|
||||
@ -59,13 +58,13 @@ public class TcpSuperSenseProcessor implements HealthCheckProcessor, Runnable {
|
||||
/**
|
||||
* this value has been carefully tuned, do not modify unless you're confident
|
||||
*/
|
||||
public static final int NIO_THREAD_COUNT = Runtime.getRuntime().availableProcessors() <= 1 ?
|
||||
private static final int NIO_THREAD_COUNT = Runtime.getRuntime().availableProcessors() <= 1 ?
|
||||
1 : Runtime.getRuntime().availableProcessors() / 2;
|
||||
|
||||
/**
|
||||
* because some hosts doesn't support keep-alive connections, disabled temporarily
|
||||
*/
|
||||
public static final long TCP_KEEP_ALIVE_MILLIS = 0;
|
||||
private static final long TCP_KEEP_ALIVE_MILLIS = 0;
|
||||
|
||||
private static ScheduledExecutorService TCP_CHECK_EXECUTOR
|
||||
= new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
||||
@ -111,7 +110,6 @@ public class TcpSuperSenseProcessor implements HealthCheckProcessor, Runnable {
|
||||
if (CollectionUtils.isEmpty(ips)) {
|
||||
return;
|
||||
}
|
||||
Service service = task.getCluster().getService();
|
||||
|
||||
for (Instance ip : ips) {
|
||||
|
||||
|
@ -27,22 +27,19 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class GlobalConfig {
|
||||
|
||||
@Value("${nacos.naming.distro.taskDispatchPeriod}")
|
||||
@Value("${nacos.naming.distro.taskDispatchPeriod:200}")
|
||||
private int taskDispatchPeriod = 2000;
|
||||
|
||||
@Value("${nacos.naming.distro.batchSyncKeyCount}")
|
||||
@Value("${nacos.naming.distro.batchSyncKeyCount:1000}")
|
||||
private int batchSyncKeyCount = 1000;
|
||||
|
||||
@Value("${nacos.naming.distro.syncRetryDelay}")
|
||||
@Value("${nacos.naming.distro.syncRetryDelay:5000}")
|
||||
private long syncRetryDelay = 5000L;
|
||||
|
||||
@Value("${nacos.naming.distro.taskDispatchThreadCount}")
|
||||
private int taskDispatchThreadCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
@Value("${nacos.naming.data.warmup}")
|
||||
@Value("${nacos.naming.data.warmup:false}")
|
||||
private boolean dataWarmup = false;
|
||||
|
||||
@Value("${nacos.naming.expireInstance}")
|
||||
@Value("${nacos.naming.expireInstance:true}")
|
||||
private boolean expireInstance = true;
|
||||
|
||||
public int getTaskDispatchPeriod() {
|
||||
@ -57,10 +54,6 @@ public class GlobalConfig {
|
||||
return syncRetryDelay;
|
||||
}
|
||||
|
||||
public int getTaskDispatchThreadCount() {
|
||||
return taskDispatchThreadCount;
|
||||
}
|
||||
|
||||
public boolean isDataWarmup() {
|
||||
return dataWarmup;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import com.alibaba.nacos.common.util.HttpMethod;
|
||||
import com.ning.http.client.AsyncCompletionHandler;
|
||||
import com.ning.http.client.AsyncHttpClient;
|
||||
import com.ning.http.client.AsyncHttpClientConfig;
|
||||
import com.ning.http.client.FluentStringsMap;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
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.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.entity.ContentType;
|
||||
@ -36,7 +34,6 @@ import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -54,15 +51,13 @@ import java.util.zip.GZIPInputStream;
|
||||
* @author nacos
|
||||
*/
|
||||
public class HttpClient {
|
||||
public static final int TIME_OUT_MILLIS = 10000;
|
||||
public static final int CON_TIME_OUT_MILLIS = 5000;
|
||||
private static final int TIME_OUT_MILLIS = 10000;
|
||||
private static final int CON_TIME_OUT_MILLIS = 5000;
|
||||
|
||||
private static AsyncHttpClient asyncHttpClient;
|
||||
|
||||
private static CloseableHttpClient postClient;
|
||||
|
||||
private static PoolingHttpClientConnectionManager connectionManager;
|
||||
|
||||
static {
|
||||
AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
|
||||
builder.setMaximumConnectionsTotal(-1);
|
||||
|
@ -16,7 +16,6 @@
|
||||
package com.alibaba.nacos.naming.misc;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.core.utils.SystemUtils;
|
||||
import com.alibaba.nacos.naming.boot.RunningConfig;
|
||||
import com.ning.http.client.AsyncCompletionHandler;
|
||||
import com.ning.http.client.Response;
|
||||
|
@ -134,7 +134,6 @@ public class PerformanceLoggerThread {
|
||||
try {
|
||||
int serviceCount = serviceManager.getServiceCount();
|
||||
int ipCount = serviceManager.getInstanceCount();
|
||||
long maxPushMaxCost = getMaxPushCost();
|
||||
long maxPushCost = getMaxPushCost();
|
||||
long avgPushCost = getAvgPushCost();
|
||||
|
||||
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.naming.pojo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author nicholas
|
||||
* @version $Id: Subscriber.java, v 0.1 2019-05-28 下午10:47 nicholas Exp $$
|
||||
*/
|
||||
public class Subscriber implements Serializable {
|
||||
|
||||
private String addrStr;
|
||||
|
||||
private String agent;
|
||||
|
||||
private String app;
|
||||
|
||||
private String ip;
|
||||
|
||||
private String namespaceId;
|
||||
|
||||
private String serviceName;
|
||||
|
||||
public Subscriber(String addrStr, String agent, String app, String ip, String namespaceId, String serviceName) {
|
||||
this.addrStr = addrStr;
|
||||
this.agent = agent;
|
||||
this.app = app;
|
||||
this.ip = ip;
|
||||
this.namespaceId = namespaceId;
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
public String getAddrStr() {
|
||||
return addrStr;
|
||||
}
|
||||
|
||||
public void setAddrStr(String addrStr) {
|
||||
this.addrStr = addrStr;
|
||||
}
|
||||
|
||||
public String getAgent() {
|
||||
return agent;
|
||||
}
|
||||
|
||||
public void setAgent(String agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
public String getApp() {
|
||||
return app;
|
||||
}
|
||||
|
||||
public void setApp(String app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getNamespaceId() {
|
||||
return namespaceId;
|
||||
}
|
||||
|
||||
public void setNamespaceId(String namespaceId) {
|
||||
this.namespaceId = namespaceId;
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.naming.pojo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nicholas
|
||||
* @version $Id: Subscribers.java, v 0.1 2019-05-28 下午10:47 nicholas Exp $$
|
||||
*/
|
||||
public class Subscribers implements Serializable {
|
||||
|
||||
private List<Subscriber> subscribers;
|
||||
|
||||
public List<Subscriber> getSubscribers() {
|
||||
return subscribers;
|
||||
}
|
||||
|
||||
public void setSubscribers(List<Subscriber> subscribers) {
|
||||
this.subscribers = subscribers;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.SwitchDomain;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.pojo.Subscriber;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.codehaus.jackson.util.VersionUtil;
|
||||
@ -46,7 +47,7 @@ public class PushService {
|
||||
@Autowired
|
||||
private SwitchDomain switchDomain;
|
||||
|
||||
public static final long ACK_TIMEOUT_NANOS = TimeUnit.SECONDS.toNanos(10L);
|
||||
private static final long ACK_TIMEOUT_NANOS = TimeUnit.SECONDS.toNanos(10L);
|
||||
|
||||
private static final int MAX_RETRY_TIMES = 1;
|
||||
|
||||
@ -133,7 +134,7 @@ public class PushService {
|
||||
String tenant,
|
||||
String app) {
|
||||
|
||||
PushClient client = new PushService.PushClient(namespaceId,
|
||||
PushClient client = new PushClient(namespaceId,
|
||||
serviceName,
|
||||
clusters,
|
||||
agent,
|
||||
@ -166,6 +167,19 @@ public class PushService {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Subscriber> getClients(String serviceName, String namespaceId) {
|
||||
String serviceKey = UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName);
|
||||
ConcurrentMap<String, PushClient> clientConcurrentMap = clientMap.get(serviceKey);
|
||||
if (Objects.isNull(clientConcurrentMap)) {
|
||||
return null;
|
||||
}
|
||||
List<Subscriber> clients = new ArrayList<Subscriber>();
|
||||
clientConcurrentMap.forEach((key, client) -> {
|
||||
clients.add(new Subscriber(client.getAddrStr(),client.getAgent(),client.getApp(),client.getIp(),namespaceId,serviceName));
|
||||
});
|
||||
return clients;
|
||||
}
|
||||
|
||||
public static void removeClientIfZombie() {
|
||||
|
||||
int size = 0;
|
||||
|
@ -16,11 +16,9 @@
|
||||
package com.alibaba.nacos.naming.web;
|
||||
|
||||
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.UtilsAndCommons;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.*;
|
||||
@ -30,8 +28,6 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.security.AccessControlException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* @author nkorange
|
||||
|
@ -17,7 +17,6 @@ package com.alibaba.nacos.naming.web;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
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.misc.HttpClient;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
|
@ -73,6 +73,7 @@ public class OverrideParameterRequestWrapper extends HttpServletRequestWrapper {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getParameterValues(String name) {
|
||||
return params.get(name);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
package com.alibaba.nacos.naming.web;
|
||||
|
||||
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.ServerStatusManager;
|
||||
import com.alibaba.nacos.naming.misc.SwitchDomain;
|
||||
@ -28,8 +27,6 @@ import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -25,12 +25,3 @@ server.tomcat.accesslog.enabled=true
|
||||
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
||||
# default current work dir
|
||||
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
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.distro;
|
||||
|
||||
import com.alibaba.nacos.naming.misc.GlobalConfig;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
@ -148,4 +148,20 @@ public class InstanceControllerTest extends BaseTest {
|
||||
Assert.assertEquals(8888, host.getIntValue("port"));
|
||||
Assert.assertEquals(2.0, host.getDoubleValue("weight"), 0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNullServiceInstances() throws Exception {
|
||||
Mockito.when(serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, TEST_SERVICE_NAME)).thenReturn(null);
|
||||
|
||||
MockHttpServletRequestBuilder builder =
|
||||
MockMvcRequestBuilders.get(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance/list")
|
||||
.param("serviceName", TEST_SERVICE_NAME);
|
||||
|
||||
MockHttpServletResponse response = mockmvc.perform(builder).andReturn().getResponse();
|
||||
String actualValue = response.getContentAsString();
|
||||
JSONObject result = JSON.parseObject(actualValue);
|
||||
|
||||
JSONArray hosts = result.getJSONArray("hosts");
|
||||
Assert.assertEquals(hosts.size(), 0);
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,6 @@
|
||||
package com.alibaba.nacos.naming.core;
|
||||
|
||||
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.push.PushService;
|
||||
import org.junit.Assert;
|
||||
|
@ -0,0 +1,97 @@
|
||||
package com.alibaba.nacos.naming.core;
|
||||
|
||||
import com.alibaba.nacos.naming.BaseTest;
|
||||
import com.alibaba.nacos.naming.cluster.ServerListManager;
|
||||
import com.alibaba.nacos.naming.cluster.servers.Server;
|
||||
import com.alibaba.nacos.naming.pojo.Subscriber;
|
||||
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.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Nicholas
|
||||
*/
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class SubscribeManagerTest extends BaseTest {
|
||||
|
||||
@Mock
|
||||
private SubscribeManager subscribeManager;
|
||||
|
||||
@Mock
|
||||
private PushService pushService;
|
||||
|
||||
@Mock
|
||||
private ServerListManager serverListManager;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
super.before();
|
||||
subscribeManager = new SubscribeManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSubscribersWithFalse() {
|
||||
String serviceName = "test";
|
||||
String namespaceId = "public";
|
||||
boolean aggregation = Boolean.FALSE;
|
||||
try {
|
||||
List<Subscriber> clients = new ArrayList<Subscriber>();
|
||||
Subscriber subscriber = new Subscriber("127.0.0.1:8080", "test", "app", "127.0.0.1", namespaceId, serviceName);
|
||||
clients.add(subscriber);
|
||||
Mockito.when(pushService.getClients(Mockito.anyString(), Mockito.anyString())).thenReturn(clients);
|
||||
List<Subscriber> list = subscribeManager.getSubscribers(serviceName, namespaceId, aggregation);
|
||||
Assert.assertNotNull(list);
|
||||
Assert.assertEquals(1, list.size());
|
||||
Assert.assertEquals("public", list.get(0).getNamespaceId());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSubscribersWithTrue() {
|
||||
String serviceName = "test";
|
||||
String namespaceId = "public";
|
||||
boolean aggregation = Boolean.TRUE;
|
||||
try {
|
||||
List<Subscriber> clients = new ArrayList<Subscriber>();
|
||||
Subscriber subscriber = new Subscriber("127.0.0.1:8080", "test", "app", "127.0.0.1", namespaceId, serviceName);
|
||||
clients.add(subscriber);
|
||||
|
||||
List<Server> healthyServers = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i <= 2; i++) {
|
||||
Server server = new Server();
|
||||
server.setIp("127.0.0.1");
|
||||
server.setServePort(8080 + i);
|
||||
server.setAlive(Boolean.TRUE);
|
||||
server.setAdWeight(10);
|
||||
server.setLastRefTime(System.currentTimeMillis());
|
||||
server.setLastRefTimeStr(String.valueOf(System.currentTimeMillis()));
|
||||
server.setSite("site");
|
||||
server.setWeight(1);
|
||||
healthyServers.add(server);
|
||||
}
|
||||
|
||||
Mockito.when(serverListManager.getHealthyServers()).thenReturn(healthyServers);
|
||||
//Mockito.doReturn(3).when(serverListManager.getHealthyServers().size());
|
||||
List<Subscriber> list = subscribeManager.getSubscribers(serviceName, namespaceId, aggregation);
|
||||
Assert.assertNotNull(list);
|
||||
Assert.assertEquals(2, list.size());
|
||||
Assert.assertEquals("public", list.get(0).getNamespaceId());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.alibaba.nacos.naming.pojo;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Nicholas
|
||||
*/
|
||||
public class SubscriberTest {
|
||||
|
||||
@Test
|
||||
public void subscriberBeanTest() {
|
||||
Subscriber subscriber = new Subscriber("127.0.0.1:8080", "agent", "app", "127.0.0.1", "public", "test");
|
||||
subscriber.setAddrStr("127.0.0.1:8080");
|
||||
subscriber.setIp("127.0.0.1");
|
||||
subscriber.setApp("app");
|
||||
subscriber.setAgent("agent");
|
||||
subscriber.setNamespaceId("public");
|
||||
subscriber.setServiceName("test");
|
||||
|
||||
subscriber.getAddrStr();
|
||||
subscriber.getIp();
|
||||
subscriber.getAgent();
|
||||
subscriber.getApp();
|
||||
subscriber.getNamespaceId();
|
||||
subscriber.getServiceName();
|
||||
|
||||
Subscribers subscribers = new Subscribers();
|
||||
List<Subscriber> subscriberList = new ArrayList<>();
|
||||
subscriberList.add(subscriber);
|
||||
subscribers.setSubscribers(subscriberList);
|
||||
subscribers.getSubscribers();
|
||||
|
||||
Assert.assertNotNull(subscriberList);
|
||||
Assert.assertEquals(1, subscriberList.size());
|
||||
Assert.assertEquals("127.0.0.1:8080", subscriberList.get(0).getAddrStr());
|
||||
Assert.assertEquals("127.0.0.1", subscriberList.get(0).getIp());
|
||||
Assert.assertEquals("app", subscriberList.get(0).getApp());
|
||||
Assert.assertEquals("agent", subscriberList.get(0).getAgent());
|
||||
Assert.assertEquals("public", subscriberList.get(0).getNamespaceId());
|
||||
Assert.assertEquals("test", subscriberList.get(0).getServiceName());
|
||||
}
|
||||
}
|
@ -435,6 +435,96 @@ public class ConfigAPI_ITCase {
|
||||
iconfig.removeListener(dataId, group, ml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @TCDescription : nacos_在主动拉取配置后并注册Listener,在更新配置后才触发Listener监听事件(使用特定接口)
|
||||
* @TestStep : TODO Test steps
|
||||
* @ExpectResult : TODO expect results
|
||||
* @author xiaochun.xxc
|
||||
* @since 3.6.8
|
||||
*/
|
||||
@Test
|
||||
public void nacos_addListener_5() throws InterruptedException, NacosException {
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
final String content = "test-abc";
|
||||
final String newContent = "new-test-def";
|
||||
boolean result = iconfig.publishConfig(dataId, group, content);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
Listener ml = new AbstractListener() {
|
||||
@Override
|
||||
public void receiveConfigInfo(String configInfo) {
|
||||
count.incrementAndGet();
|
||||
System.out.println("Listener receive : [" + configInfo + "]");
|
||||
Assert.assertEquals(content, newContent);
|
||||
}
|
||||
};
|
||||
|
||||
String receiveContent = iconfig.getConfigAndSignListener(dataId, group, 1000, ml);
|
||||
System.out.println(receiveContent);
|
||||
|
||||
result = iconfig.publishConfig(dataId, group, newContent);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
Assert.assertEquals(content, receiveContent);
|
||||
Thread.sleep(2000);
|
||||
|
||||
Assert.assertEquals(1, count.get());
|
||||
iconfig.removeListener(dataId, group, ml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @TCDescription : nacos_在主动拉取配置后并注册Listener,在更新配置后才触发Listener监听事件(进行配置参数设置)
|
||||
* @TestStep : TODO Test steps
|
||||
* @ExpectResult : TODO expect results
|
||||
* @author xiaochun.xxc
|
||||
* @since 3.6.8
|
||||
*/
|
||||
@Test
|
||||
public void nacos_addListener_6() throws InterruptedException, NacosException {
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1"+":"+port);
|
||||
properties.put(PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG, "true");
|
||||
ConfigService iconfig = NacosFactory.createConfigService(properties);
|
||||
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
final String content = "test-abc";
|
||||
final String newContent = "new-test-def";
|
||||
boolean result = iconfig.publishConfig(dataId, group, content);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
Listener ml = new AbstractListener() {
|
||||
@Override
|
||||
public void receiveConfigInfo(String configInfo) {
|
||||
count.incrementAndGet();
|
||||
System.out.println("Listener receive : [" + configInfo + "]");
|
||||
Assert.assertEquals(content, newContent);
|
||||
}
|
||||
};
|
||||
|
||||
iconfig.addListener(dataId, group, ml);
|
||||
|
||||
String receiveContent = iconfig.getConfig(dataId, group, 1000);
|
||||
|
||||
System.out.println(receiveContent);
|
||||
|
||||
result = iconfig.publishConfig(dataId, group, newContent);
|
||||
Assert.assertTrue(result);
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
receiveContent = iconfig.getConfig(dataId, group, 1000);
|
||||
|
||||
Assert.assertEquals(newContent, receiveContent);
|
||||
|
||||
Assert.assertEquals(1, count.get());
|
||||
iconfig.removeListener(dataId, group, ml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @TCDescription : nacos_正常移除监听器
|
||||
* @TestStep : TODO Test steps
|
||||
|
@ -51,7 +51,8 @@ public class ConfigLongPoll_ITCase {
|
||||
Properties properties = new Properties();
|
||||
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:" + port);
|
||||
properties.put(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT, "20000");
|
||||
properties.put(PropertyKeyConst.CONFIG_RETRY_TIME, 3000);
|
||||
properties.put(PropertyKeyConst.CONFIG_RETRY_TIME, "3000");
|
||||
properties.put(PropertyKeyConst.MAX_RETRY, "5");
|
||||
configService = NacosFactory.createConfigService(properties);
|
||||
}
|
||||
|
||||
@ -82,7 +83,7 @@ public class ConfigLongPoll_ITCase {
|
||||
}
|
||||
});
|
||||
|
||||
TimeUnit.SECONDS.sleep(30);
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
|
||||
}
|
||||
|
||||
|
@ -20,20 +20,14 @@ import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.swing.text.View;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
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.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.pojo.ListView;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.alibaba.nacos.config.server.utils.TimeoutUtils;
|
||||
import com.alibaba.nacos.naming.NamingApp;
|
||||
|
||||
import org.junit.After;
|
||||
@ -54,8 +48,6 @@ import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import static com.alibaba.nacos.test.naming.NamingBase.*;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author nkorange
|
||||
*/
|
||||
|
@ -46,9 +46,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
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.randomDomainName;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos",
|
||||
|
@ -25,7 +25,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -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.ListView;
|
||||
import com.alibaba.nacos.naming.NamingApp;
|
||||
import com.alibaba.nacos.naming.selector.Selector;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.alibaba.nacos.test.naming;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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.naming.NamingFactory;
|
||||
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.ListView;
|
||||
import com.alibaba.nacos.client.naming.NacosNamingService;
|
||||
import com.alibaba.nacos.naming.NamingApp;
|
||||
|
||||
|
@ -19,7 +19,7 @@ import com.alibaba.nacos.api.naming.NamingFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.naming.NamingApp;
|
||||
import org.junit.After;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.net.ServerSocket;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -33,7 +33,6 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.alibaba.nacos.test.naming.NamingBase.*;
|
||||
|
||||
|
@ -18,11 +18,3 @@ server.tomcat.accesslog.enabled=false
|
||||
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
||||
# default current work dir
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user