Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #8622] Properties has transformed NacosClientProperties #9356

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.client.auth.ram.identify;

import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -43,7 +44,7 @@ public final class CredentialService implements SpasCredentialLoader {

private CredentialService(String appName) {
if (appName == null) {
String value = System.getProperty(IdentifyConstants.PROJECT_NAME_PROPERTY);
String value = NacosClientProperties.PROTOTYPE.getProperty(IdentifyConstants.PROJECT_NAME_PROPERTY);
if (StringUtils.isNotEmpty(value)) {
appName = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.client.auth.ram.identify;

import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.common.executor.ExecutorFactory;
import com.alibaba.nacos.common.executor.NameThreadFactory;
Expand Down Expand Up @@ -113,7 +114,7 @@ private void loadCredential(boolean init) {
}
if (propertyPath == null || propertyPath.isEmpty()) {

String value = System.getProperty("spas.identity");
String value = NacosClientProperties.PROTOTYPE.getProperty("spas.identity");
if (StringUtils.isNotEmpty(value)) {
propertyPath = value;
}
Expand Down Expand Up @@ -157,8 +158,8 @@ private void loadCredential(boolean init) {
String tenantId = null;
if (propertiesIS == null) {
propertyPath = null;
accessKey = System.getenv(IdentifyConstants.ENV_ACCESS_KEY);
secretKey = System.getenv(IdentifyConstants.ENV_SECRET_KEY);
accessKey = NacosClientProperties.PROTOTYPE.getProperty(IdentifyConstants.ENV_ACCESS_KEY);
secretKey = NacosClientProperties.PROTOTYPE.getProperty(IdentifyConstants.ENV_SECRET_KEY);
if (accessKey == null && secretKey == null) {
if (init) {
SPAS_LOGGER.info("{} No credential found", appName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.client.auth.ram.identify;

import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.common.utils.StringUtils;

/**
Expand Down Expand Up @@ -56,27 +57,27 @@ private static class Singleton {
}

private StsConfig() {
String ramRoleName = System.getProperty(IdentifyConstants.RAM_ROLE_NAME_PROPERTY);
String ramRoleName = NacosClientProperties.PROTOTYPE.getProperty(IdentifyConstants.RAM_ROLE_NAME_PROPERTY);
if (!StringUtils.isBlank(ramRoleName)) {
setRamRoleName(ramRoleName);
}

String timeToRefreshInMillisecond = System.getProperty(IdentifyConstants.REFRESH_TIME_PROPERTY);
String timeToRefreshInMillisecond = NacosClientProperties.PROTOTYPE.getProperty(IdentifyConstants.REFRESH_TIME_PROPERTY);
if (!StringUtils.isBlank(timeToRefreshInMillisecond)) {
setTimeToRefreshInMillisecond(Integer.parseInt(timeToRefreshInMillisecond));
}

String securityCredentials = System.getProperty(IdentifyConstants.SECURITY_PROPERTY);
String securityCredentials = NacosClientProperties.PROTOTYPE.getProperty(IdentifyConstants.SECURITY_PROPERTY);
if (!StringUtils.isBlank(securityCredentials)) {
setSecurityCredentials(securityCredentials);
}

String securityCredentialsUrl = System.getProperty(IdentifyConstants.SECURITY_URL_PROPERTY);
String securityCredentialsUrl = NacosClientProperties.PROTOTYPE.getProperty(IdentifyConstants.SECURITY_URL_PROPERTY);
if (!StringUtils.isBlank(securityCredentialsUrl)) {
setSecurityCredentialsUrl(securityCredentialsUrl);
}

String cacheSecurityCredentials = System.getProperty(IdentifyConstants.SECURITY_CACHE_PROPERTY);
String cacheSecurityCredentials = NacosClientProperties.PROTOTYPE.getProperty(IdentifyConstants.SECURITY_CACHE_PROPERTY);
if (!StringUtils.isBlank(cacheSecurityCredentials)) {
setCacheSecurityCredentials(Boolean.parseBoolean(cacheSecurityCredentials));
}
Expand Down
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,25 @@ public class NacosConfigService implements ConfigService {
private final ConfigFilterChainManager configFilterChainManager;

public NacosConfigService(Properties properties) throws NacosException {
ValidatorUtils.checkInitParam(properties);

initNamespace(properties);
this.configFilterChainManager = new ConfigFilterChainManager(properties);
ServerListManager serverListManager = new ServerListManager(properties);
this(NacosClientProperties.PROTOTYPE.derive(properties));
}

public NacosConfigService(NacosClientProperties clientProperties) throws NacosException {
ValidatorUtils.checkInitParam(clientProperties);

initNamespace(clientProperties);
this.configFilterChainManager = new ConfigFilterChainManager(clientProperties);
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 @@ -21,6 +21,7 @@
import com.alibaba.nacos.api.config.filter.IConfigRequest;
import com.alibaba.nacos.api.config.filter.IConfigResponse;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.env.NacosClientProperties;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -36,10 +37,14 @@ public class ConfigFilterChainManager implements IConfigFilterChain {

private final List<IConfigFilter> filters = new ArrayList<>();

public ConfigFilterChainManager(Properties properties) {
public ConfigFilterChainManager(NacosClientProperties properties) {
Properties compatibleProperties = null;
if (properties != null) {
compatibleProperties = properties.asProperties();
}
ServiceLoader<IConfigFilter> configFilters = ServiceLoader.load(IConfigFilter.class);
for (IConfigFilter configFilter : configFilters) {
configFilter.init(properties);
configFilter.init(compatibleProperties);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能否转化为Properties? ConfigFilter是一个插件接口,最好不要改入参数

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我转成一个兼容 Properties 的 wrapper. client/src/main/java/com/alibaba/nacos/client/env/SearchablePropertiesWrapper.java

addFilter(configFilter);
}
}
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 @@ -241,7 +242,7 @@ public ServerHttpAgent(ServerListManager mgr, Properties properties) {
this.serverListMgr = mgr;
}

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

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 @@ -54,7 +55,7 @@ public abstract class ConfigTransportClient {

final ServerListManager serverListManager;

final Properties properties;
final NacosClientProperties properties;

private int maxRetry = 3;

Expand All @@ -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 Down Expand Up @@ -129,7 +130,8 @@ public void setExecutor(ScheduledExecutorService executor) {
* base start client.
*/
public void start() throws NacosException {
securityProxy.login(this.properties);
final Properties properties = this.properties.asProperties();
securityProxy.login(properties);
this.executor.scheduleWithFixedDelay(() -> securityProxy.login(properties), 0,
this.securityInfoRefreshIntervalMills, TimeUnit.MILLISECONDS);
startInternal();
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 @@ -59,10 +60,12 @@ public class LocalConfigInfoProcessor {

static {
LOCAL_FILEROOT_PATH =
System.getProperty("JM.LOG.PATH", System.getProperty("user.home")) + File.separator + "nacos"
NacosClientProperties.PROTOTYPE.getProperty("JM.LOG.PATH",
NacosClientProperties.PROTOTYPE.getProperty("user.home")) + File.separator + "nacos"
+ File.separator + "config";
LOCAL_SNAPSHOT_PATH =
System.getProperty("JM.SNAPSHOT.PATH", System.getProperty("user.home")) + File.separator + "nacos"
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
Loading