Skip to content

Commit

Permalink
[ISSUE alibaba#8622] sub pr of 9356 - config and naming module (aliba…
Browse files Browse the repository at this point in the history
…ba#9455)

* [ISSUE alibaba#8622] resolve conflict

* [ISSUE alibaba#8622] fix unit test error
  • Loading branch information
onewe authored Nov 4, 2022
1 parent 46e6318 commit 82c2dea
Show file tree
Hide file tree
Showing 31 changed files with 246 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.alibaba.nacos.client.config.impl.ServerListManager;
import com.alibaba.nacos.client.config.utils.ContentUtils;
import com.alibaba.nacos.client.config.utils.ParamUtils;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.client.utils.ParamUtil;
import com.alibaba.nacos.client.utils.ValidatorUtils;
Expand Down Expand Up @@ -71,22 +72,23 @@ public class NacosConfigService implements ConfigService {
private final ConfigFilterChainManager configFilterChainManager;

public NacosConfigService(Properties properties) throws NacosException {
ValidatorUtils.checkInitParam(properties);
final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties);
ValidatorUtils.checkInitParam(clientProperties);

initNamespace(properties);
this.configFilterChainManager = new ConfigFilterChainManager(properties);
ServerListManager serverListManager = new ServerListManager(properties);
initNamespace(clientProperties);
this.configFilterChainManager = new ConfigFilterChainManager(clientProperties.asProperties());
ServerListManager serverListManager = new ServerListManager(clientProperties);
serverListManager.start();

this.worker = new ClientWorker(this.configFilterChainManager, serverListManager, properties);
this.worker = new ClientWorker(this.configFilterChainManager, serverListManager, clientProperties);
// will be deleted in 2.0 later versions
agent = new ServerHttpAgent(serverListManager);

}

private void initNamespace(Properties properties) {
private void initNamespace(NacosClientProperties properties) {
namespace = ParamUtil.parseNamespace(properties);
properties.put(PropertyKeyConst.NAMESPACE, namespace);
properties.setProperty(PropertyKeyConst.NAMESPACE, namespace);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.config.impl.ConfigHttpClientManager;
import com.alibaba.nacos.client.config.impl.ServerListManager;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.ContextPathUtil;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.client.utils.ParamUtil;
Expand Down Expand Up @@ -242,7 +243,7 @@ public ServerHttpAgent(ServerListManager mgr, Properties properties) {
}

public ServerHttpAgent(Properties properties) throws NacosException {
this.serverListMgr = new ServerListManager(properties);
this.serverListMgr = new ServerListManager(NacosClientProperties.PROTOTYPE.derive(properties));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
import com.alibaba.nacos.client.config.listener.impl.AbstractConfigChangeListener;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.client.utils.TenantUtil;
import com.alibaba.nacos.common.utils.MD5Utils;
Expand Down Expand Up @@ -62,7 +63,7 @@ public class CacheData {
static boolean initSnapshot;

static {
initSnapshot = Boolean.valueOf(System.getProperty("nacos.cache.data.init.snapshot", "true"));
initSnapshot = NacosClientProperties.PROTOTYPE.getBoolean("nacos.cache.data.init.snapshot", true);
LOGGER.info("nacos.cache.data.init.snapshot = {} ", initSnapshot);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.alibaba.nacos.api.remote.RemoteConstants;
import com.alibaba.nacos.api.remote.request.Request;
import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.plugin.auth.api.RequestResource;
import com.alibaba.nacos.client.config.common.GroupKey;
import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
Expand Down Expand Up @@ -75,7 +76,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
Expand Down Expand Up @@ -410,7 +410,7 @@ private String blank2defaultGroup(String group) {

@SuppressWarnings("PMD.ThreadPoolCreationRule")
public ClientWorker(final ConfigFilterChainManager configFilterChainManager, ServerListManager serverListManager,
final Properties properties) throws NacosException {
final NacosClientProperties properties) throws NacosException {
this.configFilterChainManager = configFilterChainManager;

init(properties);
Expand Down Expand Up @@ -457,7 +457,7 @@ private void refreshContentAndCheck(CacheData cacheData, boolean notify) {
}
}

private void init(Properties properties) {
private void init(NacosClientProperties properties) {

timeout = Math.max(ConvertUtils.toInt(properties.getProperty(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT),
Constants.CONFIG_LONG_POLL_TIMEOUT), Constants.MIN_CONFIG_LONG_POLL_TIMEOUT);
Expand Down Expand Up @@ -540,7 +540,7 @@ public class ConfigRpcTransportClient extends ConfigTransportClient {
*/
private static final long ALL_SYNC_INTERNAL = 5 * 60 * 1000L;

public ConfigRpcTransportClient(Properties properties, ServerListManager serverListManager) {
public ConfigRpcTransportClient(NacosClientProperties properties, ServerListManager serverListManager) {
super(properties, serverListManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.plugin.auth.api.RequestResource;
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
import com.alibaba.nacos.client.security.SecurityProxy;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void shutdown() throws NacosException {
securityProxy.shutdown();
}

public ConfigTransportClient(Properties properties, ServerListManager serverListManager) {
public ConfigTransportClient(NacosClientProperties properties, ServerListManager serverListManager) {

String encodeTmp = properties.getProperty(PropertyKeyConst.ENCODE);
if (StringUtils.isBlank(encodeTmp)) {
Expand All @@ -77,7 +78,7 @@ public ConfigTransportClient(Properties properties, ServerListManager serverList

this.tenant = properties.getProperty(PropertyKeyConst.NAMESPACE);
this.serverListManager = serverListManager;
this.properties = properties;
this.properties = properties.asProperties();
this.securityProxy = new SecurityProxy(serverListManager.getServerUrls(),
ConfigHttpClientManager.getInstance().getNacosRestTemplate());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.client.config.impl;

import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.common.cache.Cache;
import com.alibaba.nacos.common.cache.builder.CacheBuilder;
Expand Down Expand Up @@ -56,7 +57,7 @@ public class Limiter {

static {
try {
String limitTimeStr = System.getProperty(LIMIT_TIME_PROPERTY, String.valueOf(limit));
String limitTimeStr = NacosClientProperties.PROTOTYPE.getProperty(LIMIT_TIME_PROPERTY, String.valueOf(limit));
limit = Double.parseDouble(limitTimeStr);
LOGGER.info("limitTime:{}", limit);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alibaba.nacos.client.config.utils.ConcurrentDiskUtil;
import com.alibaba.nacos.client.config.utils.JvmUtil;
import com.alibaba.nacos.client.config.utils.SnapShotSwitch;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.common.utils.IoUtils;
import com.alibaba.nacos.common.utils.StringUtils;
Expand Down Expand Up @@ -58,12 +59,12 @@ public class LocalConfigInfoProcessor {
private static final String SNAPSHOT_FILE_CHILD_2 = "snapshot-tenant";

static {
LOCAL_FILEROOT_PATH =
System.getProperty("JM.LOG.PATH", System.getProperty("user.home")) + File.separator + "nacos"
+ File.separator + "config";
LOCAL_SNAPSHOT_PATH =
System.getProperty("JM.SNAPSHOT.PATH", System.getProperty("user.home")) + File.separator + "nacos"
+ File.separator + "config";
LOCAL_FILEROOT_PATH = NacosClientProperties.PROTOTYPE.getProperty("JM.LOG.PATH",
NacosClientProperties.PROTOTYPE.getProperty("user.home")) + File.separator + "nacos" + File.separator
+ "config";
LOCAL_SNAPSHOT_PATH = NacosClientProperties.PROTOTYPE.getProperty("JM.SNAPSHOT.PATH",
NacosClientProperties.PROTOTYPE.getProperty("user.home")) + File.separator + "nacos" + File.separator
+ "config";
LOGGER.info("LOCAL_SNAPSHOT_PATH:{}", LOCAL_SNAPSHOT_PATH);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.SystemPropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.ContextPathUtil;
import com.alibaba.nacos.client.utils.EnvUtil;
import com.alibaba.nacos.client.utils.LogUtils;
Expand Down Expand Up @@ -165,7 +166,8 @@ public ServerListManager(String endpoint, String namespace) throws NacosExceptio
this.isStarted = false;
Properties properties = new Properties();
properties.setProperty(PropertyKeyConst.ENDPOINT, endpoint);
this.endpoint = initEndpoint(properties);
final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties);
this.endpoint = initEndpoint(clientProperties);

if (StringUtils.isBlank(endpoint)) {
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, "endpoint is blank");
Expand All @@ -176,10 +178,10 @@ public ServerListManager(String endpoint, String namespace) throws NacosExceptio
}

this.name = initServerName(null);
initAddressServerUrl(properties);
initAddressServerUrl(clientProperties);
}

public ServerListManager(Properties properties) throws NacosException {
public ServerListManager(NacosClientProperties properties) throws NacosException {
this.isStarted = false;
this.serverAddrsStr = properties.getProperty(PropertyKeyConst.SERVER_ADDR);
String namespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
Expand Down Expand Up @@ -222,11 +224,11 @@ public ServerListManager(Properties properties) throws NacosException {

}

private String initServerName(Properties properties) {
private String initServerName(NacosClientProperties properties) {
String serverName;
//1.user define server name.
if (properties != null && properties.containsKey(PropertyKeyConst.SERVER_NAME)) {
serverName = properties.get(PropertyKeyConst.SERVER_NAME).toString();
serverName = properties.getProperty(PropertyKeyConst.SERVER_NAME);
} else {
// if fix url,use fix url join string.
if (isFixed) {
Expand All @@ -245,7 +247,7 @@ private String initServerName(Properties properties) {
return serverName;
}

private void initAddressServerUrl(Properties properties) {
private void initAddressServerUrl(NacosClientProperties properties) {
if (isFixed) {
return;
}
Expand All @@ -259,15 +261,15 @@ private void initAddressServerUrl(Properties properties) {
}
if (properties != null && properties.containsKey(PropertyKeyConst.ENDPOINT_QUERY_PARAMS)) {
addressServerUrlTem
.append(hasQueryString ? "&" : "?" + properties.get(PropertyKeyConst.ENDPOINT_QUERY_PARAMS));
.append(hasQueryString ? "&" : "?" + properties.getProperty(PropertyKeyConst.ENDPOINT_QUERY_PARAMS));

}

this.addressServerUrl = addressServerUrlTem.toString();
LOGGER.info("serverName = {}, address server url = {}", this.name, this.addressServerUrl);
}

private void initParam(Properties properties) {
private void initParam(NacosClientProperties properties) {
this.endpoint = initEndpoint(properties);

String contentPathTmp = properties.getProperty(PropertyKeyConst.CONTEXT_PATH);
Expand All @@ -280,10 +282,10 @@ private void initParam(Properties properties) {
}
}

private String initEndpoint(final Properties properties) {
private String initEndpoint(final NacosClientProperties properties) {

String endpointPortTmp = TemplateUtils
.stringEmptyAndThenExecute(System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_PORT),
.stringEmptyAndThenExecute(properties.getProperty(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_PORT),
() -> properties.getProperty(PropertyKeyConst.ENDPOINT_PORT));

if (StringUtils.isNotBlank(endpointPortTmp)) {
Expand All @@ -294,7 +296,7 @@ private String initEndpoint(final Properties properties) {

// Whether to enable domain name resolution rules
String isUseEndpointRuleParsing = properties.getProperty(PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE,
System.getProperty(SystemPropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE,
properties.getProperty(SystemPropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE,
String.valueOf(ParamUtil.USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE)));
if (Boolean.parseBoolean(isUseEndpointRuleParsing)) {
String endpointUrl = ParamUtil.parsingEndpointRule(endpointTmp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.client.config.utils;

import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.LogUtils;
import org.slf4j.Logger;

Expand Down Expand Up @@ -46,7 +47,7 @@ public static Boolean isMultiInstance() {
private static final String DEFAULT_IS_MULTI_INSTANCE = "false";

static {
String multiDeploy = System.getProperty(IS_MULTI_INSTANCE_PROPERTY, DEFAULT_IS_MULTI_INSTANCE);
String multiDeploy = NacosClientProperties.PROTOTYPE.getProperty(IS_MULTI_INSTANCE_PROPERTY, DEFAULT_IS_MULTI_INSTANCE);
if (TRUE.equals(multiDeploy)) {
isMultiInstance = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.alibaba.nacos.api.selector.AbstractSelector;
import com.alibaba.nacos.api.selector.ExpressionSelector;
import com.alibaba.nacos.api.selector.NoneSelector;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.naming.core.ServerListManager;
import com.alibaba.nacos.client.naming.remote.http.NamingHttpClientManager;
import com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy;
Expand Down Expand Up @@ -72,15 +73,16 @@ public NacosNamingMaintainService(Properties properties) throws NacosException {
}

private void init(Properties properties) throws NacosException {
ValidatorUtils.checkInitParam(properties);
namespace = InitUtils.initNamespaceForNaming(properties);
final NacosClientProperties nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties);
ValidatorUtils.checkInitParam(nacosClientProperties);
namespace = InitUtils.initNamespaceForNaming(nacosClientProperties);
InitUtils.initSerialization();
InitUtils.initWebRootContext(properties);
serverListManager = new ServerListManager(properties, namespace);
InitUtils.initWebRootContext(nacosClientProperties);
serverListManager = new ServerListManager(nacosClientProperties, namespace);
securityProxy = new SecurityProxy(serverListManager.getServerList(),
NamingHttpClientManager.getInstance().getNacosRestTemplate());
initSecurityProxy(properties);
serverProxy = new NamingHttpClientProxy(namespace, securityProxy, serverListManager, properties);
serverProxy = new NamingHttpClientProxy(namespace, securityProxy, serverListManager, nacosClientProperties);
}

private void initSecurityProxy(Properties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.api.naming.utils.NamingUtils;
import com.alibaba.nacos.api.selector.AbstractSelector;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.naming.cache.ServiceInfoHolder;
import com.alibaba.nacos.client.naming.core.Balancer;
import com.alibaba.nacos.client.naming.event.InstancesChangeEvent;
Expand Down Expand Up @@ -85,25 +86,27 @@ public NacosNamingService(Properties properties) throws NacosException {
}

private void init(Properties properties) throws NacosException {
ValidatorUtils.checkInitParam(properties);
this.namespace = InitUtils.initNamespaceForNaming(properties);
final NacosClientProperties nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties);

ValidatorUtils.checkInitParam(nacosClientProperties);
this.namespace = InitUtils.initNamespaceForNaming(nacosClientProperties);
InitUtils.initSerialization();
InitUtils.initWebRootContext(properties);
initLogName(properties);
InitUtils.initWebRootContext(nacosClientProperties);
initLogName(nacosClientProperties);

this.notifierEventScope = UUID.randomUUID().toString();
this.changeNotifier = new InstancesChangeNotifier(this.notifierEventScope);
NotifyCenter.registerToPublisher(InstancesChangeEvent.class, 16384);
NotifyCenter.registerSubscriber(changeNotifier);
this.serviceInfoHolder = new ServiceInfoHolder(namespace, this.notifierEventScope, properties);
this.clientProxy = new NamingClientProxyDelegate(this.namespace, serviceInfoHolder, properties, changeNotifier);
this.serviceInfoHolder = new ServiceInfoHolder(namespace, this.notifierEventScope, nacosClientProperties);
this.clientProxy = new NamingClientProxyDelegate(this.namespace, serviceInfoHolder, nacosClientProperties, changeNotifier);
}

private void initLogName(Properties properties) {
logName = System.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME);
private void initLogName(NacosClientProperties properties) {
logName = properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME);
if (StringUtils.isEmpty(logName)) {

if (properties != null && StringUtils
if (StringUtils
.isNotEmpty(properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME))) {
logName = properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME);
} else {
Expand Down
Loading

0 comments on commit 82c2dea

Please sign in to comment.