diff --git a/console/pom.xml b/console/pom.xml index 619a8aefb..efbe42494 100644 --- a/console/pom.xml +++ b/console/pom.xml @@ -41,7 +41,7 @@ com.alibaba.nacos - nacos-plugin-default-impl + nacos-default-plugin-all ${project.version} diff --git a/console/src/main/resources/application.properties b/console/src/main/resources/application.properties index 7373baa3c..a3629d911 100644 --- a/console/src/main/resources/application.properties +++ b/console/src/main/resources/application.properties @@ -144,19 +144,30 @@ nacos.core.auth.plugin.nacos.token.secret.key= #nacos.core.auth.ldap.case.sensitive=true #nacos.core.auth.ldap.ignore.partial.result.exception=false +#*************** Control Plugin Related Configurations ***************# +# plugin type +#nacos.plugin.control.manager.type=nacos + +# local control rule storage dir, default ${nacos.home}/data/connection and ${nacos.home}/data/tps +#nacos.plugin.control.rule.local.basedir=${nacos.home} + +# external control rule storage type, if exist +#nacos.plugin.control.rule.external.storage= + #*************** Config Change Plugin Related Configurations ***************# # webhook -nacos.core.config.plugin.webhook.enabled=false +#nacos.core.config.plugin.webhook.enabled=false # It is recommended to use EB https://help.aliyun.com/document_detail/413974.html -nacos.core.config.plugin.webhook.url=http://localhost:8080/webhook/send?token=*** +#nacos.core.config.plugin.webhook.url=http://localhost:8080/webhook/send?token=*** # The content push max capacity ,byte -nacos.core.config.plugin.webhook.contentMaxCapacity=102400 +#nacos.core.config.plugin.webhook.contentMaxCapacity=102400 + # whitelist -nacos.core.config.plugin.whitelist.enabled=false +#nacos.core.config.plugin.whitelist.enabled=false # The import file suffixs -nacos.core.config.plugin.whitelist.suffixs=xml,text,properties,yaml,html +#nacos.core.config.plugin.whitelist.suffixs=xml,text,properties,yaml,html # fileformatcheck,which validate the import file of type and content -nacos.core.config.plugin.fileformatcheck.enabled=false +#nacos.core.config.plugin.fileformatcheck.enabled=false #*************** Istio Related Configurations ***************# ### If turn on the MCP server: diff --git a/core/src/main/java/com/alibaba/nacos/core/control/SpringValueConfigsInitializer.java b/core/src/main/java/com/alibaba/nacos/core/control/SpringValueConfigsInitializer.java index f3f14bbca..3cf069f70 100644 --- a/core/src/main/java/com/alibaba/nacos/core/control/SpringValueConfigsInitializer.java +++ b/core/src/main/java/com/alibaba/nacos/core/control/SpringValueConfigsInitializer.java @@ -20,57 +20,37 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.control.configs.ControlConfigs; import com.alibaba.nacos.plugin.control.configs.ControlConfigsInitializer; import com.alibaba.nacos.sys.env.EnvUtil; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; /** * spring value for control configs. * * @author shiyiyue */ -@Component public class SpringValueConfigsInitializer implements ControlConfigsInitializer { - @Value("${nacos.plugin.control.tps.barrier.creator:nacos}") - private String tpsBarrierCreator = "nacos"; + private static final String PREFIX = "nacos.plugin.control."; - @Value("${nacos.plugin.control.tps.barrier.rule.creator:nacos}") - private String tpsRuleBarrierCreator = "nacos"; + private static final String CONNECTION_RUNTIME_EJECTOR = PREFIX + "connection.runtime.ejector"; - @Value("${nacos.plugin.control.connection.runtime.ejector:nacos}") - private String connectionRuntimeEjector = "nacos"; + private static final String CONTROL_MANAGER_TYPE = PREFIX + "manager.type"; - @Value("${nacos.plugin.control.connection.manager:nacos}") - private String connectionManager = "nacos"; + private static final String RULE_EXTERNAL_STORAGE = PREFIX + "rule.external.storage"; - @Value("${nacos.plugin.control.tps.manager:nacos}") - private String tpsManager = "nacos"; + private static final String LOCAL_RULE_STORAGE_BASE_DIR = PREFIX + "rule.local.basedir"; - @Value("${nacos.plugin.control.rule.external.storage:}") - private String ruleExternalStorage = ""; - - @Value("${nacos.plugin.control.rule.parser:nacos}") - private String ruleParser = "nacos"; - - @Value("${nacos.plugin.control.rule.local.basedir:}") - private String localRuleStorageBaseDir = ""; + private static final String DEFAULT_CONNECTION_RUNTIME_EJECTOR = "nacos"; @Override public void initialize(ControlConfigs controlConfigs) { - controlConfigs.setTpsManager(tpsManager); - controlConfigs.setTpsBarrierCreator(tpsBarrierCreator); - controlConfigs.setTpsRuleBarrierCreator(tpsRuleBarrierCreator); - - controlConfigs.setConnectionRuntimeEjector(connectionRuntimeEjector); - controlConfigs.setConnectionManager(connectionManager); - - controlConfigs.setRuleParser(ruleParser); + controlConfigs.setConnectionRuntimeEjector( + EnvUtil.getProperty(CONNECTION_RUNTIME_EJECTOR, DEFAULT_CONNECTION_RUNTIME_EJECTOR)); + String localRuleStorageBaseDir = EnvUtil.getProperty(LOCAL_RULE_STORAGE_BASE_DIR); if (StringUtils.isNotBlank(localRuleStorageBaseDir)) { controlConfigs.setLocalRuleStorageBaseDir(localRuleStorageBaseDir); } else { controlConfigs.setLocalRuleStorageBaseDir(EnvUtil.getNacosHome()); } - controlConfigs.setRuleExternalStorage(ruleExternalStorage); - + controlConfigs.setRuleExternalStorage(EnvUtil.getProperty(RULE_EXTERNAL_STORAGE)); + controlConfigs.setControlManagerType(EnvUtil.getProperty(CONTROL_MANAGER_TYPE)); } } diff --git a/core/src/main/java/com/alibaba/nacos/core/control/TpsControlConfig.java b/core/src/main/java/com/alibaba/nacos/core/control/TpsControlConfig.java index 1befdee96..9be3d2c51 100644 --- a/core/src/main/java/com/alibaba/nacos/core/control/TpsControlConfig.java +++ b/core/src/main/java/com/alibaba/nacos/core/control/TpsControlConfig.java @@ -30,7 +30,7 @@ public class TpsControlConfig { * tps control is enabled. * @return true/false. */ - public static final boolean isTpsControlEnabled() { + public static boolean isTpsControlEnabled() { return true; } } diff --git a/core/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.configs.ControlConfigsInitializer b/core/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.configs.ControlConfigsInitializer new file mode 100644 index 000000000..033752a61 --- /dev/null +++ b/core/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.configs.ControlConfigsInitializer @@ -0,0 +1,17 @@ +# +# Copyright 1999-2023 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. +# + +com.alibaba.nacos.core.control.SpringValueConfigsInitializer \ No newline at end of file diff --git a/distribution/conf/application.properties b/distribution/conf/application.properties index 996a82b54..61ab2ef32 100644 --- a/distribution/conf/application.properties +++ b/distribution/conf/application.properties @@ -172,6 +172,30 @@ nacos.core.auth.plugin.nacos.token.secret.key= #nacos.core.auth.ldap.case.sensitive=true #nacos.core.auth.ldap.ignore.partial.result.exception=false +#*************** Control Plugin Related Configurations ***************# +# plugin type +#nacos.plugin.control.manager.type=nacos + +# local control rule storage dir, default ${nacos.home}/data/connection and ${nacos.home}/data/tps +#nacos.plugin.control.rule.local.basedir=${nacos.home} + +# external control rule storage type, if exist +#nacos.plugin.control.rule.external.storage= + +#*************** Config Change Plugin Related Configurations ***************# +# webhook +#nacos.core.config.plugin.webhook.enabled=false +# It is recommended to use EB https://help.aliyun.com/document_detail/413974.html +#nacos.core.config.plugin.webhook.url=http://localhost:8080/webhook/send?token=*** +# The content push max capacity ,byte +#nacos.core.config.plugin.webhook.contentMaxCapacity=102400 + +# whitelist +#nacos.core.config.plugin.whitelist.enabled=false +# The import file suffixs +#nacos.core.config.plugin.whitelist.suffixs=xml,text,properties,yaml,html +# fileformatcheck,which validate the import file of type and content +#nacos.core.config.plugin.fileformatcheck.enabled=false #*************** Istio Related Configurations ***************# ### If turn on the MCP server: diff --git a/naming/src/test/java/com/alibaba/nacos/naming/push/v2/hook/NacosMonitorPushResultHookTest.java b/naming/src/test/java/com/alibaba/nacos/naming/push/v2/hook/NacosMonitorPushResultHookTest.java index 9533ed82d..90451aa51 100644 --- a/naming/src/test/java/com/alibaba/nacos/naming/push/v2/hook/NacosMonitorPushResultHookTest.java +++ b/naming/src/test/java/com/alibaba/nacos/naming/push/v2/hook/NacosMonitorPushResultHookTest.java @@ -21,6 +21,7 @@ import com.alibaba.nacos.api.naming.pojo.ServiceInfo; import com.alibaba.nacos.naming.monitor.MetricsMonitor; import com.alibaba.nacos.naming.pojo.Subscriber; import com.alibaba.nacos.plugin.control.tps.TpsControlManager; +import com.alibaba.nacos.sys.env.EnvUtil; import com.alibaba.nacos.sys.utils.ApplicationUtils; import org.junit.Before; import org.junit.Test; @@ -28,6 +29,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.mock.env.MockEnvironment; import java.util.ArrayList; @@ -63,6 +65,7 @@ public class NacosMonitorPushResultHookTest { @Before public void setUp() { + EnvUtil.setEnvironment(new MockEnvironment()); MetricsMonitor.resetAll(); serviceInfo.setHosts(new ArrayList<>()); subscriber.setIp("0.0.0.0"); diff --git a/naming/src/test/java/com/alibaba/nacos/naming/push/v2/task/PushExecuteTaskTest.java b/naming/src/test/java/com/alibaba/nacos/naming/push/v2/task/PushExecuteTaskTest.java index 6f462516e..f7723e2b2 100644 --- a/naming/src/test/java/com/alibaba/nacos/naming/push/v2/task/PushExecuteTaskTest.java +++ b/naming/src/test/java/com/alibaba/nacos/naming/push/v2/task/PushExecuteTaskTest.java @@ -26,6 +26,7 @@ import com.alibaba.nacos.naming.core.v2.pojo.Service; import com.alibaba.nacos.naming.monitor.MetricsMonitor; import com.alibaba.nacos.naming.pojo.Subscriber; import com.alibaba.nacos.naming.push.v2.NoRequiredRetryException; +import com.alibaba.nacos.sys.env.EnvUtil; import com.alibaba.nacos.sys.utils.ApplicationUtils; import org.junit.Before; import org.junit.Test; @@ -33,6 +34,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.mock.env.MockEnvironment; import java.util.Collections; import java.util.Optional; @@ -79,6 +81,7 @@ public class PushExecuteTaskTest { @Before public void setUp() { + EnvUtil.setEnvironment(new MockEnvironment()); MetricsMonitor.resetAll(); when(indexesManager.getAllClientsSubscribeService(service)).thenReturn(Collections.singletonList(clientId)); when(clientManager.getClient(clientId)).thenReturn(client); diff --git a/plugin-default-impl/nacos-default-auth-plugin/pom.xml b/plugin-default-impl/nacos-default-auth-plugin/pom.xml new file mode 100644 index 000000000..95b618c46 --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/pom.xml @@ -0,0 +1,58 @@ + + + + + + nacos-plugin-default-impl + com.alibaba.nacos + ${revision} + + 4.0.0 + + default-auth-plugin + nacos-default-auth-plugin ${project.version} + + + + com.alibaba.nacos + nacos-auth-plugin + + + com.alibaba.nacos + nacos-common + + + + com.alibaba.nacos + nacos-sys + provided + + + + com.alibaba.nacos + nacos-config + provided + + + + org.springframework.ldap + spring-ldap-core + + + \ No newline at end of file diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/CustomAuthenticationProvider.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/CustomAuthenticationProvider.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/CustomAuthenticationProvider.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/CustomAuthenticationProvider.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/JwtAuthenticationEntryPoint.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/JwtAuthenticationEntryPoint.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/JwtAuthenticationEntryPoint.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/JwtAuthenticationEntryPoint.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthConfig.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthConfig.java similarity index 98% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthConfig.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthConfig.java index 02ac08cb4..e0229e4d0 100644 --- a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthConfig.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthPluginService.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthPluginService.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthPluginService.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthPluginService.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProvider.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProvider.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProvider.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProvider.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthConfig.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthConfig.java similarity index 99% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthConfig.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthConfig.java index d3b096ad5..d538a7533 100644 --- a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthConfig.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2021 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthManager.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthManager.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthManager.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthPluginService.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthPluginService.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthPluginService.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosAuthPluginService.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosLdapContextSource.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosLdapContextSource.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosLdapContextSource.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/NacosLdapContextSource.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/AbstractAuthenticationManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/AbstractAuthenticationManager.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/AbstractAuthenticationManager.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/AbstractAuthenticationManager.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/AuthenticationManagerDelegator.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/AuthenticationManagerDelegator.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/AuthenticationManagerDelegator.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/AuthenticationManagerDelegator.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/DefaultAuthenticationManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/DefaultAuthenticationManager.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/DefaultAuthenticationManager.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/DefaultAuthenticationManager.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/IAuthenticationManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/IAuthenticationManager.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/IAuthenticationManager.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/IAuthenticationManager.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/LdapAuthenticationManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/LdapAuthenticationManager.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/LdapAuthenticationManager.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/authenticate/LdapAuthenticationManager.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/configuration/ConditionOnLdapAuth.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/configuration/ConditionOnLdapAuth.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/configuration/ConditionOnLdapAuth.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/configuration/ConditionOnLdapAuth.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthConstants.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthConstants.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthConstants.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthConstants.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthSystemTypes.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthSystemTypes.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthSystemTypes.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthSystemTypes.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/PermissionController.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/PermissionController.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/PermissionController.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/PermissionController.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/RoleController.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/RoleController.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/RoleController.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/RoleController.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/UserController.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/UserController.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/UserController.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/controller/UserController.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/filter/JwtAuthenticationTokenFilter.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/filter/JwtAuthenticationTokenFilter.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/filter/JwtAuthenticationTokenFilter.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/filter/JwtAuthenticationTokenFilter.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtParser.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtParser.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtParser.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtParser.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtPayload.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtPayload.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtPayload.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtPayload.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosSignatureAlgorithm.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosSignatureAlgorithm.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosSignatureAlgorithm.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosSignatureAlgorithm.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/AuthRowMapperManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/AuthRowMapperManager.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/AuthRowMapperManager.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/AuthRowMapperManager.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImpl.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImpl.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImpl.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImpl.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImpl.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImpl.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImpl.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImpl.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImpl.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImpl.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImpl.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImpl.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImpl.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImpl.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImpl.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImpl.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImpl.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImpl.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/PermissionInfo.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/PermissionInfo.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/PermissionInfo.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/PermissionInfo.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/PermissionPersistService.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/PermissionPersistService.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/PermissionPersistService.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/PermissionPersistService.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/RoleInfo.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/RoleInfo.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/RoleInfo.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/RoleInfo.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/RolePersistService.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/RolePersistService.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/RolePersistService.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/RolePersistService.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/User.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/User.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/User.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/User.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/UserPersistService.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/UserPersistService.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/UserPersistService.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/UserPersistService.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceImpl.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceImpl.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceImpl.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManager.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManager.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManager.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManagerDelegate.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManagerDelegate.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManagerDelegate.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManagerDelegate.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/CachedJwtTokenManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/CachedJwtTokenManager.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/CachedJwtTokenManager.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/CachedJwtTokenManager.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUser.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUser.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUser.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUser.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetails.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetails.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetails.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetails.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetailsServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetailsServiceImpl.java similarity index 97% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetailsServiceImpl.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetailsServiceImpl.java index fa9cb796c..2530cbf6c 100644 --- a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetailsServiceImpl.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserDetailsServiceImpl.java @@ -77,7 +77,7 @@ public class NacosUserDetailsServiceImpl implements UserDetailsService { } if (user == null) { - throw new UsernameNotFoundException(username); + throw new UsernameNotFoundException(String.format("User %s not found", username)); } return new NacosUserDetails(user); } diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/User.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/User.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/User.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/User.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64Decode.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64Decode.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64Decode.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64Decode.java diff --git a/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtil.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtil.java similarity index 100% rename from plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtil.java rename to plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtil.java diff --git a/plugin-default-impl/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService b/plugin-default-impl/nacos-default-auth-plugin/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService similarity index 85% rename from plugin-default-impl/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService rename to plugin-default-impl/nacos-default-auth-plugin/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService index 682a264ee..13d19d8fc 100644 --- a/plugin-default-impl/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService @@ -1,5 +1,5 @@ # -# Copyright 1999-2021 Alibaba Group Holding Ltd. +# Copyright 1999-2023 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. diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProviderTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProviderTest.java similarity index 99% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProviderTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProviderTest.java index 8f38797a3..cd22d25f5 100644 --- a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProviderTest.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/LdapAuthenticationProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2021 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/configuration/ConditionOnLdapAuthTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/configuration/ConditionOnLdapAuthTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/configuration/ConditionOnLdapAuthTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/configuration/ConditionOnLdapAuthTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/controller/UserControllerTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/controller/UserControllerTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/controller/UserControllerTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/controller/UserControllerTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtParserTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtParserTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtParserTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/jwt/NacosJwtParserTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImplTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImplTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImplTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImplTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImplTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImplTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImplTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImplTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImplTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImplTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImplTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImplTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImplTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImplTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImplTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImplTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImplTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImplTest.java similarity index 98% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImplTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImplTest.java index 6025580ee..ec4759235 100644 --- a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImplTest.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2021 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImplTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImplTest.java similarity index 98% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImplTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImplTest.java index 7c1c83e67..968da1ae6 100644 --- a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImplTest.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2021 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceImplTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceImplTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceImplTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceImplTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManagerDelegateTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManagerDelegateTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManagerDelegateTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/TokenManagerDelegateTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/CachedJwtTokenManagerTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/CachedJwtTokenManagerTest.java similarity index 100% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/CachedJwtTokenManagerTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/CachedJwtTokenManagerTest.java diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java similarity index 90% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java index 88188e68b..32f9fbc21 100644 --- a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2021 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -50,10 +50,10 @@ public class JwtTokenManagerTest { when(authConfigs.isAuthEnabled()).thenReturn(true); MockEnvironment mockEnvironment = new MockEnvironment(); mockEnvironment.setProperty(AuthConstants.TOKEN_SECRET_KEY, Base64.getEncoder().encodeToString( - "SecretKey0123$567890$234567890123456789012345678901234567890123456789".getBytes( - StandardCharsets.UTF_8))); - mockEnvironment.setProperty(AuthConstants.TOKEN_EXPIRE_SECONDS, - AuthConstants.DEFAULT_TOKEN_EXPIRE_SECONDS.toString()); + "SecretKey0123$567890$234567890123456789012345678901234567890123456789" + .getBytes(StandardCharsets.UTF_8))); + mockEnvironment + .setProperty(AuthConstants.TOKEN_EXPIRE_SECONDS, AuthConstants.DEFAULT_TOKEN_EXPIRE_SECONDS.toString()); EnvUtil.setEnvironment(mockEnvironment); jwtTokenManager = new JwtTokenManager(authConfigs); @@ -73,8 +73,8 @@ public class JwtTokenManagerTest { MockEnvironment mockEnvironment = new MockEnvironment(); mockEnvironment.setProperty(AuthConstants.TOKEN_SECRET_KEY, Base64.getEncoder().encodeToString(secretKey.getBytes(StandardCharsets.UTF_8))); - mockEnvironment.setProperty(AuthConstants.TOKEN_EXPIRE_SECONDS, - AuthConstants.DEFAULT_TOKEN_EXPIRE_SECONDS.toString()); + mockEnvironment + .setProperty(AuthConstants.TOKEN_EXPIRE_SECONDS, AuthConstants.DEFAULT_TOKEN_EXPIRE_SECONDS.toString()); EnvUtil.setEnvironment(mockEnvironment); @@ -119,8 +119,8 @@ public class JwtTokenManagerTest { MockEnvironment mockEnvironment = new MockEnvironment(); mockEnvironment.setProperty(AuthConstants.TOKEN_SECRET_KEY, Base64.getEncoder().encodeToString(secretKey.getBytes(StandardCharsets.UTF_8))); - mockEnvironment.setProperty(AuthConstants.TOKEN_EXPIRE_SECONDS, - AuthConstants.DEFAULT_TOKEN_EXPIRE_SECONDS.toString()); + mockEnvironment + .setProperty(AuthConstants.TOKEN_EXPIRE_SECONDS, AuthConstants.DEFAULT_TOKEN_EXPIRE_SECONDS.toString()); EnvUtil.setEnvironment(mockEnvironment); diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64DecodeTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64DecodeTest.java similarity index 96% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64DecodeTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64DecodeTest.java index e46499a10..ea3e7fc9e 100644 --- a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64DecodeTest.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/Base64DecodeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2021 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -26,6 +26,7 @@ import org.junit.Test; * @date 2023/8/8 */ public class Base64DecodeTest { + @Test public void testStandardDecode() { String origin = "aGVsbG8sbmFjb3MhdGVzdEJhc2U2NGVuY29kZQ=="; @@ -33,7 +34,7 @@ public class Base64DecodeTest { byte[] decodeOrigin = Base64Decode.decode(origin); Assert.assertArrayEquals(decodeOrigin, expectDecodeOrigin.getBytes()); } - + @Test public void testNotStandardDecode() { String notStandardOrigin = "SecretKey012345678901234567890123456789012345678901234567890123456789"; diff --git a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtilTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtilTest.java similarity index 97% rename from plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtilTest.java rename to plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtilTest.java index d0c98db5f..8c101329f 100644 --- a/plugin-default-impl/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtilTest.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordEncoderUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2021 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. diff --git a/plugin-default-impl/nacos-default-control-plugin/pom.xml b/plugin-default-impl/nacos-default-control-plugin/pom.xml new file mode 100644 index 000000000..26817dffb --- /dev/null +++ b/plugin-default-impl/nacos-default-control-plugin/pom.xml @@ -0,0 +1,42 @@ + + + + + + nacos-plugin-default-impl + com.alibaba.nacos + ${revision} + + 4.0.0 + + default-control-plugin + nacos-default-control-plugin ${project.version} + + + + com.alibaba.nacos + nacos-control-plugin + + + com.alibaba.nacos + nacos-common + + + + \ No newline at end of file diff --git a/plugin-default-impl/nacos-default-control-plugin/src/main/java/com/alibaba/nacos/plugin/control/impl/NacosConnectionControlManager.java b/plugin-default-impl/nacos-default-control-plugin/src/main/java/com/alibaba/nacos/plugin/control/impl/NacosConnectionControlManager.java new file mode 100644 index 000000000..f4dc1780c --- /dev/null +++ b/plugin-default-impl/nacos-default-control-plugin/src/main/java/com/alibaba/nacos/plugin/control/impl/NacosConnectionControlManager.java @@ -0,0 +1,72 @@ +/* + * Copyright 1999-2023 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.plugin.control.impl; + +import com.alibaba.nacos.common.utils.JacksonUtils; +import com.alibaba.nacos.plugin.control.Loggers; +import com.alibaba.nacos.plugin.control.connection.ConnectionControlManager; +import com.alibaba.nacos.plugin.control.connection.ConnectionMetricsCollector; +import com.alibaba.nacos.plugin.control.connection.request.ConnectionCheckRequest; +import com.alibaba.nacos.plugin.control.connection.response.ConnectionCheckCode; +import com.alibaba.nacos.plugin.control.connection.response.ConnectionCheckResponse; +import com.alibaba.nacos.plugin.control.connection.rule.ConnectionControlRule; + +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Nacos default control plugin implementation. + * + * @author shiyiyue + */ +public class NacosConnectionControlManager extends ConnectionControlManager { + + @Override + public String getName() { + return "nacos"; + } + + public NacosConnectionControlManager() { + super(); + } + + @Override + public void applyConnectionLimitRule(ConnectionControlRule connectionControlRule) { + super.connectionControlRule = connectionControlRule; + Loggers.CONTROL.info("Connection control rule updated to ->" + (this.connectionControlRule == null ? null + : JacksonUtils.toJson(this.connectionControlRule))); + Loggers.CONTROL.warn("Connection control updated, But connection control manager is no limit implementation."); + } + + @Override + public ConnectionCheckResponse check(ConnectionCheckRequest connectionCheckRequest) { + ConnectionCheckResponse connectionCheckResponse = new ConnectionCheckResponse(); + connectionCheckResponse.setSuccess(true); + connectionCheckResponse.setCode(ConnectionCheckCode.PASS_BY_TOTAL); + int totalCountLimit = connectionControlRule.getCountLimit(); + // Get total connection from metrics + Map metricsTotalCount = metricsCollectorList.stream().collect( + Collectors.toMap(ConnectionMetricsCollector::getName, ConnectionMetricsCollector::getTotalCount)); + int totalCount = metricsTotalCount.values().stream().mapToInt(Integer::intValue).sum(); + if (totalCount > totalCountLimit) { + connectionCheckResponse.setSuccess(false); + connectionCheckResponse.setCode(ConnectionCheckCode.DENY_BY_TOTAL_OVER); + } + return connectionCheckResponse; + } + +} diff --git a/plugin-default-impl/nacos-default-control-plugin/src/main/java/com/alibaba/nacos/plugin/control/impl/NacosControlManagerBuilder.java b/plugin-default-impl/nacos-default-control-plugin/src/main/java/com/alibaba/nacos/plugin/control/impl/NacosControlManagerBuilder.java new file mode 100644 index 000000000..2d9f90e96 --- /dev/null +++ b/plugin-default-impl/nacos-default-control-plugin/src/main/java/com/alibaba/nacos/plugin/control/impl/NacosControlManagerBuilder.java @@ -0,0 +1,44 @@ +/* + * Copyright 1999-2023 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.plugin.control.impl; + +import com.alibaba.nacos.plugin.control.connection.ConnectionControlManager; +import com.alibaba.nacos.plugin.control.spi.ControlManagerBuilder; +import com.alibaba.nacos.plugin.control.tps.TpsControlManager; + +/** + * Nacos default control plugin implementation. + * + * @author xiweng.yy + */ +public class NacosControlManagerBuilder implements ControlManagerBuilder { + + @Override + public String getName() { + return "nacos"; + } + + @Override + public ConnectionControlManager buildConnectionControlManager() { + return new NacosConnectionControlManager(); + } + + @Override + public TpsControlManager buildTpsControlManager() { + return new NacosTpsControlManager(); + } +} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/NacosTpsControlManager.java b/plugin-default-impl/nacos-default-control-plugin/src/main/java/com/alibaba/nacos/plugin/control/impl/NacosTpsControlManager.java similarity index 91% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/NacosTpsControlManager.java rename to plugin-default-impl/nacos-default-control-plugin/src/main/java/com/alibaba/nacos/plugin/control/impl/NacosTpsControlManager.java index 7f437bab6..fbeac1fef 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/NacosTpsControlManager.java +++ b/plugin-default-impl/nacos-default-control-plugin/src/main/java/com/alibaba/nacos/plugin/control/impl/NacosTpsControlManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,12 +14,13 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps.nacos; +package com.alibaba.nacos.plugin.control.impl; import com.alibaba.nacos.common.executor.ExecutorFactory; import com.alibaba.nacos.plugin.control.Loggers; -import com.alibaba.nacos.plugin.control.tps.TpsBarrier; -import com.alibaba.nacos.plugin.control.tps.TpsBarrierCreatorProxy; +import com.alibaba.nacos.plugin.control.tps.barrier.TpsBarrier; +import com.alibaba.nacos.plugin.control.tps.barrier.creator.DefaultNacosTpsBarrierCreator; +import com.alibaba.nacos.plugin.control.tps.barrier.creator.TpsBarrierCreator; import com.alibaba.nacos.plugin.control.tps.TpsControlManager; import com.alibaba.nacos.plugin.control.tps.TpsMetrics; import com.alibaba.nacos.plugin.control.tps.request.TpsCheckRequest; @@ -36,7 +37,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; /** - * nacos tps control manager. + * Nacos default control plugin implementation. * * @author shiyiyue */ @@ -55,15 +56,20 @@ public class NacosTpsControlManager extends TpsControlManager { protected ScheduledExecutorService executorService; public NacosTpsControlManager() { + super(); executorService = ExecutorFactory.newSingleScheduledExecutorService(r -> { Thread thread = new Thread(r, "nacos.plugin.tps.control.reporter"); thread.setDaemon(true); return thread; }); - startTpsReport(); } + @Override + protected TpsBarrierCreator buildTpsBarrierCreator() { + return new DefaultNacosTpsBarrierCreator(); + } + protected void startTpsReport() { executorService .scheduleWithFixedDelay(new NacosTpsControlManager.TpsMetricsReporter(), 0, 900, TimeUnit.MILLISECONDS); @@ -76,7 +82,7 @@ public class NacosTpsControlManager extends TpsControlManager { */ public synchronized void registerTpsPoint(String pointName) { if (!points.containsKey(pointName)) { - points.put(pointName, TpsBarrierCreatorProxy.getTpsBarrierCreator().createTpsBarrier(pointName)); + points.put(pointName, tpsBarrierCreator.createTpsBarrier(pointName)); if (rules.containsKey(pointName)) { points.get(pointName).applyRule(rules.get(pointName)); } else { diff --git a/plugin-default-impl/nacos-default-control-plugin/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.spi.ControlManagerBuilder b/plugin-default-impl/nacos-default-control-plugin/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.spi.ControlManagerBuilder new file mode 100644 index 000000000..a2d87fbac --- /dev/null +++ b/plugin-default-impl/nacos-default-control-plugin/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.spi.ControlManagerBuilder @@ -0,0 +1,17 @@ +# +# Copyright 1999-2023 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. +# + +com.alibaba.nacos.plugin.control.impl.NacosControlManagerBuilder \ No newline at end of file diff --git a/plugin-default-impl/nacos-default-plugin-all/pom.xml b/plugin-default-impl/nacos-default-plugin-all/pom.xml new file mode 100644 index 000000000..a20bce8c8 --- /dev/null +++ b/plugin-default-impl/nacos-default-plugin-all/pom.xml @@ -0,0 +1,42 @@ + + + + + + nacos-plugin-default-impl + com.alibaba.nacos + ${revision} + + 4.0.0 + + nacos-default-plugin-all + + + com.alibaba.nacos + default-auth-plugin + ${revision} + + + com.alibaba.nacos + default-control-plugin + ${revision} + + + + \ No newline at end of file diff --git a/plugin-default-impl/pom.xml b/plugin-default-impl/pom.xml index 02de89332..6b213a183 100644 --- a/plugin-default-impl/pom.xml +++ b/plugin-default-impl/pom.xml @@ -26,35 +26,12 @@ 4.0.0 nacos-plugin-default-impl - jar + pom nacos-plugin-default-impl ${project.version} https://nacos.io - - - - com.alibaba.nacos - nacos-auth-plugin - - - com.alibaba.nacos - nacos-common - - - - com.alibaba.nacos - nacos-sys - provided - - - - com.alibaba.nacos - nacos-config - provided - - - - org.springframework.ldap - spring-ldap-core - - + + nacos-default-control-plugin + nacos-default-auth-plugin + nacos-default-plugin-all + diff --git a/plugin/control/pom.xml b/plugin/control/pom.xml index 6433cdd5f..59126c31e 100644 --- a/plugin/control/pom.xml +++ b/plugin/control/pom.xml @@ -36,13 +36,7 @@ nacos-common provided - - - com.alibaba.nacos - nacos-sys - provided - - + \ No newline at end of file diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ControlManagerCenter.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ControlManagerCenter.java index ec46d2ab3..ef73eaab1 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ControlManagerCenter.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ControlManagerCenter.java @@ -18,18 +18,18 @@ package com.alibaba.nacos.plugin.control; import com.alibaba.nacos.common.notify.NotifyCenter; import com.alibaba.nacos.common.spi.NacosServiceLoader; +import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.control.configs.ControlConfigs; import com.alibaba.nacos.plugin.control.connection.ConnectionControlManager; -import com.alibaba.nacos.plugin.control.connection.nacos.NacosConnectionControlManager; +import com.alibaba.nacos.plugin.control.connection.DefaultConnectionControlManager; import com.alibaba.nacos.plugin.control.event.ConnectionLimitRuleChangeEvent; import com.alibaba.nacos.plugin.control.event.TpsControlRuleChangeEvent; -import com.alibaba.nacos.plugin.control.ruleactivator.RuleParser; -import com.alibaba.nacos.plugin.control.ruleactivator.RuleParserProxy; -import com.alibaba.nacos.plugin.control.ruleactivator.RuleStorageProxy; +import com.alibaba.nacos.plugin.control.rule.storage.RuleStorageProxy; +import com.alibaba.nacos.plugin.control.spi.ControlManagerBuilder; import com.alibaba.nacos.plugin.control.tps.TpsControlManager; -import com.alibaba.nacos.plugin.control.tps.nacos.NacosTpsControlManager; +import com.alibaba.nacos.plugin.control.tps.DefaultTpsControlManager; -import java.util.Collection; +import java.util.Optional; /** * control manager center. @@ -40,67 +40,70 @@ public class ControlManagerCenter { static volatile ControlManagerCenter instance = null; + private final RuleStorageProxy ruleStorageProxy; + private TpsControlManager tpsControlManager; private ConnectionControlManager connectionControlManager; - private RuleStorageProxy ruleStorageProxy; - - private void initConnectionManager() { - - Collection connectionControlManagers = NacosServiceLoader - .load(ConnectionControlManager.class); - String connectionManagerName = ControlConfigs.getInstance().getConnectionManager(); - - for (ConnectionControlManager connectionControlManagerInternal : connectionControlManagers) { - if (connectionControlManagerInternal.getName().equalsIgnoreCase(connectionManagerName)) { - Loggers.CONTROL.info("Found connection control manager of name={},class={}", connectionManagerName, - connectionControlManagerInternal.getClass().getSimpleName()); - connectionControlManager = connectionControlManagerInternal; - break; - } - } - if (connectionControlManager == null) { - Loggers.CONTROL.warn("Fail to connection control manager of name :" + connectionManagerName); - connectionControlManager = new NacosConnectionControlManager(); - } - - } - - private void initTpsControlManager() { - - Collection tpsControlManagers = NacosServiceLoader.load(TpsControlManager.class); - String tpsManagerName = ControlConfigs.getInstance().getTpsManager(); - - for (TpsControlManager tpsControlManagerInternal : tpsControlManagers) { - if (tpsControlManagerInternal.getName().equalsIgnoreCase(tpsManagerName)) { - Loggers.CONTROL.info("Found tps control manager of name={},class={}", tpsManagerName, - tpsControlManagerInternal.getClass().getSimpleName()); - tpsControlManager = tpsControlManagerInternal; - break; - } - } - if (tpsControlManager == null) { - Loggers.CONTROL.warn("Fail to found tps control manager of name :" + tpsManagerName); - tpsControlManager = new NacosTpsControlManager(); - } - - } - private ControlManagerCenter() { - initTpsControlManager(); - initConnectionManager(); - ruleStorageProxy = new RuleStorageProxy(); + ruleStorageProxy = RuleStorageProxy.getInstance(); + Optional controlManagerBuilder = findTargetControlManagerBuilder(); + if (controlManagerBuilder.isPresent()) { + initConnectionManager(controlManagerBuilder.get()); + initTpsControlManager(controlManagerBuilder.get()); + } else { + buildNoLimitControlManagers(); + } + } + + private void initConnectionManager(ControlManagerBuilder controlManagerBuilder) { + try { + connectionControlManager = controlManagerBuilder.buildConnectionControlManager(); + Loggers.CONTROL.info("Build connection control manager, class={}", + connectionControlManager.getClass().getCanonicalName()); + } catch (Exception e) { + Loggers.CONTROL.warn("Build connection control manager failed, use no limit manager replaced.", e); + connectionControlManager = new DefaultConnectionControlManager(); + } + } + + private void initTpsControlManager(ControlManagerBuilder controlManagerBuilder) { + try { + tpsControlManager = controlManagerBuilder.buildTpsControlManager(); + Loggers.CONTROL + .info("Build tps control manager, class={}", tpsControlManager.getClass().getCanonicalName()); + } catch (Exception e) { + Loggers.CONTROL.warn("Build tps control manager failed, use no limit manager replaced.", e); + tpsControlManager = new DefaultTpsControlManager(); + } + } + + private Optional findTargetControlManagerBuilder() { + String controlManagerType = ControlConfigs.getInstance().getControlManagerType(); + if (StringUtils.isEmpty(controlManagerType)) { + Loggers.CONTROL.info("Not configure type of control plugin, no limit control for current node."); + return Optional.empty(); + } + for (ControlManagerBuilder each : NacosServiceLoader.load(ControlManagerBuilder.class)) { + Loggers.CONTROL.info("Found control manager plugin of name={}", each.getName()); + if (controlManagerType.equalsIgnoreCase(each.getName())) { + return Optional.of(each); + } + } + Loggers.CONTROL.warn("Not found control manager plugin of name"); + return Optional.empty(); + } + + private void buildNoLimitControlManagers() { + connectionControlManager = new DefaultConnectionControlManager(); + tpsControlManager = new DefaultTpsControlManager(); } public RuleStorageProxy getRuleStorageProxy() { return ruleStorageProxy; } - public RuleParser getRuleParser() { - return RuleParserProxy.getInstance(); - } - public TpsControlManager getTpsControlManager() { return tpsControlManager; } diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/configs/ControlConfigs.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/configs/ControlConfigs.java index 361e6bb55..608b033da 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/configs/ControlConfigs.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/configs/ControlConfigs.java @@ -50,37 +50,13 @@ public class ControlConfigs { ControlConfigs.instance = instance; } - private String tpsBarrierCreator = "nacos"; - - private String tpsRuleBarrierCreator = "nacos"; - private String connectionRuntimeEjector = "nacos"; - private String connectionManager = "nacos"; - - private String tpsManager = "nacos"; - private String ruleExternalStorage = ""; - private String ruleParser = "nacos"; - private String localRuleStorageBaseDir = ""; - public String getTpsBarrierCreator() { - return tpsBarrierCreator; - } - - public void setTpsBarrierCreator(String tpsBarrierCreator) { - this.tpsBarrierCreator = tpsBarrierCreator; - } - - public String getTpsRuleBarrierCreator() { - return tpsRuleBarrierCreator; - } - - public void setTpsRuleBarrierCreator(String tpsRuleBarrierCreator) { - this.tpsRuleBarrierCreator = tpsRuleBarrierCreator; - } + private String controlManagerType = ""; public String getRuleExternalStorage() { return ruleExternalStorage; @@ -90,22 +66,6 @@ public class ControlConfigs { this.ruleExternalStorage = ruleExternalStorage; } - public String getRuleParser() { - return ruleParser; - } - - public void setRuleParser(String ruleParser) { - this.ruleParser = ruleParser; - } - - public String getConnectionManager() { - return connectionManager; - } - - public void setConnectionManager(String connectionManager) { - this.connectionManager = connectionManager; - } - public String getConnectionRuntimeEjector() { return connectionRuntimeEjector; } @@ -114,14 +74,6 @@ public class ControlConfigs { this.connectionRuntimeEjector = connectionRuntimeEjector; } - public String getTpsManager() { - return tpsManager; - } - - public void setTpsManager(String tpsManager) { - this.tpsManager = tpsManager; - } - public String getLocalRuleStorageBaseDir() { return localRuleStorageBaseDir; } @@ -129,4 +81,12 @@ public class ControlConfigs { public void setLocalRuleStorageBaseDir(String localRuleStorageBaseDir) { this.localRuleStorageBaseDir = localRuleStorageBaseDir; } + + public String getControlManagerType() { + return controlManagerType; + } + + public void setControlManagerType(String controlManagerType) { + this.controlManagerType = controlManagerType; + } } diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/ConnectionControlManager.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/ConnectionControlManager.java index f6737fc1f..026d05b78 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/ConnectionControlManager.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/ConnectionControlManager.java @@ -23,8 +23,9 @@ import com.alibaba.nacos.plugin.control.Loggers; import com.alibaba.nacos.plugin.control.connection.request.ConnectionCheckRequest; import com.alibaba.nacos.plugin.control.connection.response.ConnectionCheckResponse; import com.alibaba.nacos.plugin.control.connection.rule.ConnectionControlRule; -import com.alibaba.nacos.plugin.control.ruleactivator.RuleParserProxy; -import com.alibaba.nacos.plugin.control.ruleactivator.RuleStorageProxy; +import com.alibaba.nacos.plugin.control.rule.parser.ConnectionControlRuleParser; +import com.alibaba.nacos.plugin.control.rule.parser.NacosConnectionControlRuleParser; +import com.alibaba.nacos.plugin.control.rule.storage.RuleStorageProxy; import java.util.Collection; import java.util.Map; @@ -40,10 +41,26 @@ import java.util.stream.Collectors; @SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule") public abstract class ConnectionControlManager { + private final ConnectionControlRuleParser connectionControlRuleParser; + protected ConnectionControlRule connectionControlRule; protected Collection metricsCollectorList; + private ScheduledExecutorService executorService; + + public ConnectionControlManager() { + metricsCollectorList = NacosServiceLoader.load(ConnectionMetricsCollector.class); + Loggers.CONTROL.info("Load connection metrics collector,size={},{}", metricsCollectorList.size(), + metricsCollectorList); + this.connectionControlRuleParser = buildConnectionControlRuleParser(); + initConnectionRule(); + if (!metricsCollectorList.isEmpty()) { + initExecuteService(); + startConnectionMetricsReport(); + } + } + /** * get manager name. * @@ -51,18 +68,12 @@ public abstract class ConnectionControlManager { */ public abstract String getName(); - private ScheduledExecutorService executorService; + protected ConnectionControlRuleParser buildConnectionControlRuleParser() { + return new NacosConnectionControlRuleParser(); + } - public ConnectionControlManager() { - metricsCollectorList = NacosServiceLoader.load(ConnectionMetricsCollector.class); - Loggers.CONTROL.info("Load connection metrics collector,size={},{}", metricsCollectorList.size(), - metricsCollectorList); - initConnectionRule(); - if (!metricsCollectorList.isEmpty()) { - initExecuteService(); - startConnectionMetricsReport(); - } - + public ConnectionControlRuleParser getConnectionControlRuleParser() { + return connectionControlRuleParser; } private void initExecuteService() { @@ -73,10 +84,6 @@ public abstract class ConnectionControlManager { }); } - private void startConnectionMetricsReport() { - executorService.scheduleWithFixedDelay(new ConnectionMetricsReporter(), 0, 3000, TimeUnit.MILLISECONDS); - } - private void initConnectionRule() { RuleStorageProxy ruleStorageProxy = RuleStorageProxy.getInstance(); String localRuleContent = ruleStorageProxy.getLocalDiskStorage().getConnectionRule(); @@ -92,7 +99,7 @@ public abstract class ConnectionControlManager { } if (StringUtils.isNotBlank(localRuleContent)) { - connectionControlRule = RuleParserProxy.getInstance().parseConnectionRule(localRuleContent); + connectionControlRule = connectionControlRuleParser.parseRule(localRuleContent); Loggers.CONTROL.info("init connection rule end"); } else { @@ -101,6 +108,10 @@ public abstract class ConnectionControlManager { } } + private void startConnectionMetricsReport() { + executorService.scheduleWithFixedDelay(new ConnectionMetricsReporter(), 0, 3000, TimeUnit.MILLISECONDS); + } + public ConnectionControlRule getConnectionLimitRule() { return connectionControlRule; } diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/nacos/NacosConnectionControlManager.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/DefaultConnectionControlManager.java similarity index 80% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/nacos/NacosConnectionControlManager.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/DefaultConnectionControlManager.java index 4efa49a06..0f2c5d2d6 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/nacos/NacosConnectionControlManager.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/connection/DefaultConnectionControlManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,29 +14,28 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.connection.nacos; +package com.alibaba.nacos.plugin.control.connection; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.plugin.control.Loggers; -import com.alibaba.nacos.plugin.control.connection.ConnectionControlManager; import com.alibaba.nacos.plugin.control.connection.request.ConnectionCheckRequest; import com.alibaba.nacos.plugin.control.connection.response.ConnectionCheckCode; import com.alibaba.nacos.plugin.control.connection.response.ConnectionCheckResponse; import com.alibaba.nacos.plugin.control.connection.rule.ConnectionControlRule; /** - * connection control manager. + * default connection control manager, no limit control. * * @author shiyiyue */ -public class NacosConnectionControlManager extends ConnectionControlManager { +public class DefaultConnectionControlManager extends ConnectionControlManager { @Override public String getName() { - return "nacos"; + return "noLimit"; } - public NacosConnectionControlManager() { + public DefaultConnectionControlManager() { super(); } @@ -45,7 +44,7 @@ public class NacosConnectionControlManager extends ConnectionControlManager { super.connectionControlRule = connectionControlRule; Loggers.CONTROL.info("Connection control rule updated to ->" + (this.connectionControlRule == null ? null : JacksonUtils.toJson(this.connectionControlRule))); - + Loggers.CONTROL.warn("Connection control updated, But connection control manager is no limit implementation."); } @Override diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/ControlRuleChangeActivator.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/ControlRuleChangeActivator.java similarity index 81% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/ControlRuleChangeActivator.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/ControlRuleChangeActivator.java index 5984ac6be..9e8fb4c8b 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/ControlRuleChangeActivator.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/ControlRuleChangeActivator.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.ruleactivator; +package com.alibaba.nacos.plugin.control.rule; import com.alibaba.nacos.common.notify.Event; import com.alibaba.nacos.common.notify.NotifyCenter; @@ -22,9 +22,12 @@ import com.alibaba.nacos.common.notify.listener.Subscriber; import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.control.ControlManagerCenter; import com.alibaba.nacos.plugin.control.Loggers; +import com.alibaba.nacos.plugin.control.connection.ConnectionControlManager; import com.alibaba.nacos.plugin.control.connection.rule.ConnectionControlRule; import com.alibaba.nacos.plugin.control.event.ConnectionLimitRuleChangeEvent; import com.alibaba.nacos.plugin.control.event.TpsControlRuleChangeEvent; +import com.alibaba.nacos.plugin.control.rule.storage.RuleStorageProxy; +import com.alibaba.nacos.plugin.control.tps.TpsControlManager; import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule; import org.slf4j.Logger; @@ -46,14 +49,14 @@ public class ControlRuleChangeActivator { NotifyCenter.registerSubscriber(connectionRuleChangeSubscriber); } - class TpsRuleChangeSubscriber extends Subscriber { + static class TpsRuleChangeSubscriber extends Subscriber { @Override public void onEvent(TpsControlRuleChangeEvent event) { String pointName = event.getPointName(); LOGGER.info("Tps control rule change event receive,pointName={}, external={} ", pointName, event.isExternal()); - if (event == null || event.getPointName() == null) { + if (event.getPointName() == null) { return; } try { @@ -71,11 +74,11 @@ public class ControlRuleChangeActivator { } String tpsRuleContent = ruleStorageProxy.getLocalDiskStorage().getTpsRule(pointName); - + TpsControlManager tpsControlManager = ControlManagerCenter.getInstance().getTpsControlManager(); TpsControlRule tpsControlRule = StringUtils.isBlank(tpsRuleContent) ? new TpsControlRule() - : ControlManagerCenter.getInstance().getRuleParser().parseTpsRule(tpsRuleContent); + : tpsControlManager.getTpsControlRuleParser().parseRule(tpsRuleContent); - ControlManagerCenter.getInstance().getTpsControlManager().applyTpsRule(pointName, tpsControlRule); + tpsControlManager.applyTpsRule(pointName, tpsControlRule); } catch (Exception e) { LOGGER.warn("Tps control rule apply error ,error= ", e); @@ -89,7 +92,7 @@ public class ControlRuleChangeActivator { } } - class ConnectionRuleChangeSubscriber extends Subscriber { + static class ConnectionRuleChangeSubscriber extends Subscriber { @Override public void onEvent(ConnectionLimitRuleChangeEvent event) { @@ -112,15 +115,15 @@ public class ControlRuleChangeActivator { String limitRule = ruleStorageProxy.getLocalDiskStorage().getConnectionRule(); Loggers.CONTROL.info("start to apply connection rule content " + limitRule); - + ConnectionControlManager controlManager = ControlManagerCenter.getInstance() + .getConnectionControlManager(); ConnectionControlRule connectionControlRule = StringUtils.isBlank(limitRule) ? new ConnectionControlRule() - : ControlManagerCenter.getInstance().getRuleParser().parseConnectionRule(limitRule); + : controlManager.getConnectionControlRuleParser().parseRule(limitRule); Loggers.CONTROL.info("end to apply connection rule content "); if (connectionControlRule != null) { - ControlManagerCenter.getInstance().getConnectionControlManager() - .applyConnectionLimitRule(connectionControlRule); + controlManager.applyConnectionLimitRule(connectionControlRule); } else { LOGGER.info("Parse rule is null,Ignore illegal rule :{}", limitRule); } diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/ConnectionControlRuleParser.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/ConnectionControlRuleParser.java new file mode 100644 index 000000000..217d3439e --- /dev/null +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/ConnectionControlRuleParser.java @@ -0,0 +1,28 @@ +/* + * Copyright 1999-2023 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.plugin.control.rule.parser; + +import com.alibaba.nacos.plugin.control.connection.rule.ConnectionControlRule; + +/** + * Connection control rule parser. + * + * @author xiweng.yy + */ +public interface ConnectionControlRuleParser extends RuleParser { + +} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/NacosRuleParser.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/NacosConnectionControlRuleParser.java similarity index 59% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/NacosRuleParser.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/NacosConnectionControlRuleParser.java index 967f444f6..bbd2f815a 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/NacosRuleParser.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/NacosConnectionControlRuleParser.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,36 +14,23 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.ruleactivator; +package com.alibaba.nacos.plugin.control.rule.parser; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.control.connection.rule.ConnectionControlRule; -import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule; /** - * nacos rule parser. + * Nacos default connection control rule parser with json. * - * @author shiyiyue + * @author xiweng.yy */ -public class NacosRuleParser implements RuleParser { +public class NacosConnectionControlRuleParser implements ConnectionControlRuleParser { @Override - public TpsControlRule parseTpsRule(String ruleContent) { - - return StringUtils.isBlank(ruleContent) ? new TpsControlRule() - : JacksonUtils.toObj(ruleContent, TpsControlRule.class); - } - - @Override - public ConnectionControlRule parseConnectionRule(String ruleContent) { + public ConnectionControlRule parseRule(String ruleContent) { return StringUtils.isBlank(ruleContent) ? new ConnectionControlRule() : JacksonUtils.toObj(ruleContent, ConnectionControlRule.class); } - @Override - public String getName() { - return "nacos"; - } - } diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/NacosTpsControlRuleParser.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/NacosTpsControlRuleParser.java new file mode 100644 index 000000000..731d21221 --- /dev/null +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/NacosTpsControlRuleParser.java @@ -0,0 +1,36 @@ +/* + * Copyright 1999-2023 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.plugin.control.rule.parser; + +import com.alibaba.nacos.common.utils.JacksonUtils; +import com.alibaba.nacos.common.utils.StringUtils; +import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule; + +/** + * Nacos default tps control rule parser with json. + * + * @author xiweng.yy + */ +public class NacosTpsControlRuleParser implements TpsControlRuleParser { + + @Override + public TpsControlRule parseRule(String ruleContent) { + return StringUtils.isBlank(ruleContent) ? new TpsControlRule() + : JacksonUtils.toObj(ruleContent, TpsControlRule.class); + } + +} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/RuleParser.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/RuleParser.java new file mode 100644 index 000000000..4d49d2bdb --- /dev/null +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/RuleParser.java @@ -0,0 +1,33 @@ +/* + * Copyright 1999-2023 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.plugin.control.rule.parser; + +/** + * parse rule content from raw string. + * + * @author shiyiyue + */ +public interface RuleParser { + + /** + * Parse control rule. + * + * @param ruleContent rule raw string + * @return target rule + */ + R parseRule(String ruleContent); +} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/TpsControlRuleParser.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/TpsControlRuleParser.java new file mode 100644 index 000000000..a8865b350 --- /dev/null +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/parser/TpsControlRuleParser.java @@ -0,0 +1,28 @@ +/* + * Copyright 1999-2023 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.plugin.control.rule.parser; + +import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule; + +/** + * Tps control rule parser. + * + * @author xiweng.yy + */ +public interface TpsControlRuleParser extends RuleParser { + +} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/ExternalRuleStorage.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/ExternalRuleStorage.java similarity index 86% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/ExternalRuleStorage.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/ExternalRuleStorage.java index 744a883ef..58ff8f144 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/ExternalRuleStorage.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/ExternalRuleStorage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.ruleactivator; +package com.alibaba.nacos.plugin.control.rule.storage; /** * external rule storage. diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/LocalDiskRuleStorage.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/LocalDiskRuleStorage.java similarity index 81% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/LocalDiskRuleStorage.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/LocalDiskRuleStorage.java index c96f5d0de..85b3c07aa 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/LocalDiskRuleStorage.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/LocalDiskRuleStorage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,11 +14,12 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.ruleactivator; +package com.alibaba.nacos.plugin.control.rule.storage; import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.plugin.control.Loggers; -import com.alibaba.nacos.sys.env.EnvUtil; +import com.alibaba.nacos.plugin.control.utils.DiskUtils; +import com.alibaba.nacos.plugin.control.utils.EnvUtils; import org.slf4j.Logger; import java.io.File; @@ -37,30 +38,26 @@ public class LocalDiskRuleStorage implements RuleStorage { private static final Logger LOGGER = Loggers.CONTROL; - private String localRruleBaseDir = defaultBaseDir(); + private String localRuleBaseDir = defaultBaseDir(); private File checkTpsBaseDir() { - File baseDir = new File(localRruleBaseDir, "data" + File.separator + "tps" + File.separator); + File baseDir = new File(localRuleBaseDir, "data" + File.separator + "tps" + File.separator); if (!baseDir.exists()) { baseDir.mkdirs(); } return baseDir; } - public String getLocalRruleBaseDir() { - return localRruleBaseDir; - } - - public void setLocalRruleBaseDir(String localRruleBaseDir) { - this.localRruleBaseDir = localRruleBaseDir; + public void setLocalRuleBaseDir(String localRruleBaseDir) { + this.localRuleBaseDir = localRruleBaseDir; } private static String defaultBaseDir() { - return EnvUtil.getNacosHome(); + return EnvUtils.getNacosHome(); } private File getConnectionRuleFile() { - File baseDir = new File(localRruleBaseDir, "data" + File.separator + "connection" + File.separator); + File baseDir = new File(localRuleBaseDir, "data" + File.separator + "connection" + File.separator); if (!baseDir.exists()) { baseDir.mkdir(); } diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleStorage.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/RuleStorage.java similarity index 93% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleStorage.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/RuleStorage.java index 13fb90131..72c10bbd2 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleStorage.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/RuleStorage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.ruleactivator; +package com.alibaba.nacos.plugin.control.rule.storage; /** * rule storage. diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleStorageProxy.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/RuleStorageProxy.java similarity index 54% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleStorageProxy.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/RuleStorageProxy.java index 77d604520..8efbd8f9d 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleStorageProxy.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/rule/storage/RuleStorageProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,12 +14,14 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.ruleactivator; +package com.alibaba.nacos.plugin.control.rule.storage; import com.alibaba.nacos.common.spi.NacosServiceLoader; import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.control.Loggers; import com.alibaba.nacos.plugin.control.configs.ControlConfigs; +import com.alibaba.nacos.plugin.control.rule.ControlRuleChangeActivator; +import com.alibaba.nacos.plugin.control.spi.ExternalRuleStorageBuilder; import org.slf4j.Logger; import java.util.Collection; @@ -41,30 +43,40 @@ public class RuleStorageProxy { ControlRuleChangeActivator controlRuleChangeActivator = null; - public RuleStorageProxy() { - - Collection persistRuleActivators = NacosServiceLoader.load(ExternalRuleStorage.class); - String rulePersistActivator = ControlConfigs.getInstance().getRuleExternalStorage(); - - for (ExternalRuleStorage persistRuleActivator : persistRuleActivators) { - if (persistRuleActivator.getName().equalsIgnoreCase(rulePersistActivator)) { - LOGGER.info("Found persist rule storage of name :" + rulePersistActivator); - externalRuleStorage = persistRuleActivator; + private RuleStorageProxy() { + String externalStorageType = ControlConfigs.getInstance().getRuleExternalStorage(); + if (StringUtils.isNotEmpty(externalStorageType)) { + buildExternalStorage(externalStorageType); + } + initLocalStorage(); + controlRuleChangeActivator = new ControlRuleChangeActivator(); + } + + private void buildExternalStorage(String externalStorageType) { + Collection externalRuleStorageBuilders = NacosServiceLoader + .load(ExternalRuleStorageBuilder.class); + for (ExternalRuleStorageBuilder each : externalRuleStorageBuilders) { + LOGGER.info("Found persist rule storage of name : {}", externalStorageType); + if (externalStorageType.equalsIgnoreCase(each.getName())) { + try { + externalRuleStorage = each.buildExternalRuleStorage(); + } catch (Exception e) { + LOGGER.warn("Build external rule storage failed, the rules will not be persisted", e); + } + LOGGER.info("Build external rule storage of name {} finished", externalStorageType); break; } } - if (externalRuleStorage == null && StringUtils.isNotBlank(rulePersistActivator)) { - LOGGER.error("Fail to found persist rule storage of name :" + rulePersistActivator); + if (externalRuleStorage == null && StringUtils.isNotBlank(externalStorageType)) { + LOGGER.error("Fail to found persist rule storage of name : {}", externalStorageType); } - - //local disk storage. + } + + private void initLocalStorage() { localDiskRuleStorage = new LocalDiskRuleStorage(); if (StringUtils.isNotBlank(ControlConfigs.getInstance().getLocalRuleStorageBaseDir())) { - localDiskRuleStorage.setLocalRruleBaseDir(ControlConfigs.getInstance().getLocalRuleStorageBaseDir()); + localDiskRuleStorage.setLocalRuleBaseDir(ControlConfigs.getInstance().getLocalRuleStorageBaseDir()); } - - controlRuleChangeActivator = new ControlRuleChangeActivator(); - } public RuleStorage getLocalDiskStorage() { @@ -75,7 +87,7 @@ public class RuleStorageProxy { return externalRuleStorage; } - public static final RuleStorageProxy getInstance() { + public static RuleStorageProxy getInstance() { return INSTANCE; } } diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleParser.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleParser.java deleted file mode 100644 index f5db87e58..000000000 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleParser.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 1999-2020 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.plugin.control.ruleactivator; - -import com.alibaba.nacos.plugin.control.connection.rule.ConnectionControlRule; -import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule; - -/** - * parse rule content from raw string. - * - * @author shiyiyue - */ -public interface RuleParser { - - /** - * parse tps rule content. - * - * @param ruleContent ruleContent. - * @return - */ - TpsControlRule parseTpsRule(String ruleContent); - - /** - * parse connection rule. - * - * @param ruleContent ruleContent. - * @return - */ - ConnectionControlRule parseConnectionRule(String ruleContent); - - /** - * get name. - * - * @return - */ - String getName(); -} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleParserProxy.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleParserProxy.java deleted file mode 100644 index 09df07e48..000000000 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/RuleParserProxy.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 1999-2020 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.plugin.control.ruleactivator; - -import com.alibaba.nacos.common.spi.NacosServiceLoader; -import com.alibaba.nacos.plugin.control.Loggers; -import com.alibaba.nacos.plugin.control.configs.ControlConfigs; -import org.slf4j.Logger; - -import java.util.Collection; - -/** - * rule parser proxy. - * - * @author shiyiyue - */ -public class RuleParserProxy { - - private static final Logger LOGGER = Loggers.CONTROL; - - private static RuleParser instance; - - static { - Collection ruleParsers = NacosServiceLoader.load(RuleParser.class); - String ruleParserName = ControlConfigs.getInstance().getRuleParser(); - - for (RuleParser ruleParser : ruleParsers) { - if (ruleParser.getName().equalsIgnoreCase(ruleParserName)) { - LOGGER.info("Found rule parser of name={},class={}", ruleParserName, - ruleParser.getClass().getSimpleName()); - instance = ruleParser; - break; - } - } - if (instance == null) { - LOGGER.warn("Fail to rule parser of name :" + ruleParserName); - instance = new NacosRuleParser(); - } - } - - public static RuleParser getInstance() { - return instance; - } -} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/spi/ControlManagerBuilder.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/spi/ControlManagerBuilder.java new file mode 100644 index 000000000..0b604bbf3 --- /dev/null +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/spi/ControlManagerBuilder.java @@ -0,0 +1,49 @@ +/* + * Copyright 1999-2023 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.plugin.control.spi; + +import com.alibaba.nacos.plugin.control.connection.ConnectionControlManager; +import com.alibaba.nacos.plugin.control.tps.TpsControlManager; + +/** + * Nacos control plugin manager builder SPI. + * + * @author xiweng.yy + */ +public interface ControlManagerBuilder { + + /** + * Get plugin name. + * + * @return name of plugin + */ + String getName(); + + /** + * Build {@link ConnectionControlManager} implementation for current plugin. + * + * @return ConnectionControlManager implementation + */ + ConnectionControlManager buildConnectionControlManager(); + + /** + * Build {@link TpsControlManager} implementation for current plugin. + * + * @return TpsControlManager implementation + */ + TpsControlManager buildTpsControlManager(); +} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/spi/ExternalRuleStorageBuilder.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/spi/ExternalRuleStorageBuilder.java new file mode 100644 index 000000000..e7b8d74ef --- /dev/null +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/spi/ExternalRuleStorageBuilder.java @@ -0,0 +1,41 @@ +/* + * Copyright 1999-2023 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.plugin.control.spi; + +import com.alibaba.nacos.plugin.control.rule.storage.ExternalRuleStorage; + +/** + * Nacos control plugin external rule storage builder SPI. + * + * @author xiweng.yy + */ +public interface ExternalRuleStorageBuilder { + + /** + * Get plugin name. + * + * @return name of plugin + */ + String getName(); + + /** + * Build {@link ExternalRuleStorage} implementation for current plugin if necessary. + * + * @return ExternalRuleStorage implementation + */ + ExternalRuleStorage buildExternalRuleStorage(); +} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/DefaultTpsControlManager.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/DefaultTpsControlManager.java new file mode 100644 index 000000000..49bdd180f --- /dev/null +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/DefaultTpsControlManager.java @@ -0,0 +1,116 @@ +/* + * Copyright 1999-2023 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.plugin.control.tps; + +import com.alibaba.nacos.plugin.control.Loggers; +import com.alibaba.nacos.plugin.control.tps.barrier.TpsBarrier; +import com.alibaba.nacos.plugin.control.tps.barrier.creator.TpsBarrierCreator; +import com.alibaba.nacos.plugin.control.tps.barrier.creator.DefaultNacosTpsBarrierCreator; +import com.alibaba.nacos.plugin.control.tps.request.TpsCheckRequest; +import com.alibaba.nacos.plugin.control.tps.response.TpsCheckResponse; +import com.alibaba.nacos.plugin.control.tps.response.TpsResultCode; +import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * nacos tps control manager. + * + * @author shiyiyue + */ +public class DefaultTpsControlManager extends TpsControlManager { + + /** + * point name -> tps barrier. + */ + protected final Map points = new ConcurrentHashMap<>(16); + + /** + * point name -> tps control rule. + */ + protected final Map rules = new ConcurrentHashMap<>(16); + + public DefaultTpsControlManager() { + } + + @Override + protected TpsBarrierCreator buildTpsBarrierCreator() { + return new DefaultNacosTpsBarrierCreator(); + } + + /** + * apple tps rule. + * + * @param pointName pointName. + */ + public synchronized void registerTpsPoint(String pointName) { + if (!points.containsKey(pointName)) { + points.put(pointName, tpsBarrierCreator.createTpsBarrier(pointName)); + if (rules.containsKey(pointName)) { + points.get(pointName).applyRule(rules.get(pointName)); + } else { + initTpsRule(pointName); + } + } + Loggers.CONTROL + .warn("Tps point for {} registered, But tps control manager is no limit implementation.", pointName); + } + + /** + * apple tps rule. + * + * @param pointName pointName. + * @param rule rule. + */ + public synchronized void applyTpsRule(String pointName, TpsControlRule rule) { + if (rule == null) { + rules.remove(pointName); + } else { + rules.put(pointName, rule); + } + if (points.containsKey(pointName)) { + points.get(pointName).applyRule(rule); + } + Loggers.CONTROL.warn("Tps rule for point name {} updated, But tps control manager is no limit implementation.", + pointName); + } + + public Map getPoints() { + return points; + } + + public Map getRules() { + return rules; + } + + /** + * check tps result. + * + * @param tpsRequest TpsRequest. + * @return check current tps is allowed. + */ + public TpsCheckResponse check(TpsCheckRequest tpsRequest) { + return new TpsCheckResponse(true, TpsResultCode.CHECK_SKIP, "skip"); + + } + + @Override + public String getName() { + return "noLimit"; + } +} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsBarrierCreatorProxy.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsBarrierCreatorProxy.java deleted file mode 100644 index 963367f37..000000000 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsBarrierCreatorProxy.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 1999-2020 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.plugin.control.tps; - -import com.alibaba.nacos.common.spi.NacosServiceLoader; -import com.alibaba.nacos.plugin.control.Loggers; -import com.alibaba.nacos.plugin.control.configs.ControlConfigs; -import com.alibaba.nacos.plugin.control.tps.nacos.DefaultNacosTpsBarrierCreator; - -import java.util.Collection; - -/** - * tps barrier creator proxy. - * - * @author shiyiyue - */ -public class TpsBarrierCreatorProxy { - - static TpsBarrierCreator tpsBarrierCreator; - - static { - String tpsRuleBarrierCreator = null; - try { - tpsRuleBarrierCreator = ControlConfigs.getInstance().getTpsRuleBarrierCreator(); - Collection loadedCreators = NacosServiceLoader.load(TpsBarrierCreator.class); - for (TpsBarrierCreator barrierCreator : loadedCreators) { - if (tpsRuleBarrierCreator.equalsIgnoreCase(barrierCreator.getName())) { - Loggers.CONTROL.info("Found tps barrier creator of name : {}", tpsRuleBarrierCreator); - tpsBarrierCreator = barrierCreator; - break; - } - } - } catch (Throwable throwable) { - Loggers.CONTROL.warn("Fail to load tpsRuleBarrierCreator ", throwable); - } - if (tpsBarrierCreator == null) { - Loggers.CONTROL.warn("Fail to found tps barrier creator of name : {},use default local simple creator", - tpsRuleBarrierCreator); - tpsBarrierCreator = new DefaultNacosTpsBarrierCreator(); - } - } - - public static TpsBarrierCreator getTpsBarrierCreator() { - return tpsBarrierCreator; - } -} diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsControlManager.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsControlManager.java index adacfc241..1fe567b9d 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsControlManager.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsControlManager.java @@ -18,8 +18,11 @@ package com.alibaba.nacos.plugin.control.tps; import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.control.Loggers; -import com.alibaba.nacos.plugin.control.ruleactivator.RuleParserProxy; -import com.alibaba.nacos.plugin.control.ruleactivator.RuleStorageProxy; +import com.alibaba.nacos.plugin.control.rule.parser.NacosTpsControlRuleParser; +import com.alibaba.nacos.plugin.control.rule.parser.TpsControlRuleParser; +import com.alibaba.nacos.plugin.control.rule.storage.RuleStorageProxy; +import com.alibaba.nacos.plugin.control.tps.barrier.TpsBarrier; +import com.alibaba.nacos.plugin.control.tps.barrier.creator.TpsBarrierCreator; import com.alibaba.nacos.plugin.control.tps.request.TpsCheckRequest; import com.alibaba.nacos.plugin.control.tps.response.TpsCheckResponse; import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule; @@ -34,12 +37,22 @@ import java.util.Map; @SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule") public abstract class TpsControlManager { - /** - * apple tps rule. - * - * @param pointName pointName. - */ - public abstract void registerTpsPoint(String pointName); + private final TpsControlRuleParser tpsControlRuleParser; + + protected final TpsBarrierCreator tpsBarrierCreator; + + protected TpsControlManager() { + this.tpsControlRuleParser = buildTpsControlRuleParser(); + this.tpsBarrierCreator = buildTpsBarrierCreator(); + } + + public TpsControlRuleParser getTpsControlRuleParser() { + return tpsControlRuleParser; + } + + protected TpsControlRuleParser buildTpsControlRuleParser() { + return new NacosTpsControlRuleParser(); + } protected void initTpsRule(String pointName) { RuleStorageProxy ruleStorageProxy = RuleStorageProxy.getInstance(); @@ -56,13 +69,27 @@ public abstract class TpsControlManager { } if (StringUtils.isNotBlank(localRuleContent)) { - TpsControlRule tpsLimitRule = RuleParserProxy.getInstance().parseTpsRule(localRuleContent); + TpsControlRule tpsLimitRule = tpsControlRuleParser.parseRule(localRuleContent); this.applyTpsRule(pointName, tpsLimitRule); } else { Loggers.CONTROL.info("No tps control rule of {} found ", pointName, localRuleContent); } } + /** + * Build tps barrier creator to creator tps barrier for each point. + * + * @return TpsBarrierCreator implemetation for current plugin + */ + protected abstract TpsBarrierCreator buildTpsBarrierCreator(); + + /** + * apple tps rule. + * + * @param pointName pointName. + */ + public abstract void registerTpsPoint(String pointName); + /** * get points. * diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/NacosTpsBarrier.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/DefaultNacosTpsBarrier.java similarity index 91% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/NacosTpsBarrier.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/DefaultNacosTpsBarrier.java index b09f125b1..a2526d5af 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/NacosTpsBarrier.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/DefaultNacosTpsBarrier.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,10 +14,9 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps.nacos; +package com.alibaba.nacos.plugin.control.tps.barrier; import com.alibaba.nacos.plugin.control.Loggers; -import com.alibaba.nacos.plugin.control.tps.TpsBarrier; import com.alibaba.nacos.plugin.control.tps.request.BarrierCheckRequest; import com.alibaba.nacos.plugin.control.tps.request.TpsCheckRequest; import com.alibaba.nacos.plugin.control.tps.response.TpsCheckResponse; @@ -29,9 +28,9 @@ import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule; * * @author shiyiyue */ -public class NacosTpsBarrier extends TpsBarrier { +public class DefaultNacosTpsBarrier extends TpsBarrier { - public NacosTpsBarrier(String pointName) { + public DefaultNacosTpsBarrier(String pointName) { super(pointName); } diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/LocalSimpleCountRateCounter.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/LocalSimpleCountRateCounter.java similarity index 97% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/LocalSimpleCountRateCounter.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/LocalSimpleCountRateCounter.java index 5cad28dec..ff80406cd 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/LocalSimpleCountRateCounter.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/LocalSimpleCountRateCounter.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps.nacos; +package com.alibaba.nacos.plugin.control.tps.barrier; import java.util.ArrayList; import java.util.List; diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/LocalSimpleCountRuleBarrier.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/LocalSimpleCountRuleBarrier.java similarity index 91% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/LocalSimpleCountRuleBarrier.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/LocalSimpleCountRuleBarrier.java index a5593a2c8..65f28d047 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/LocalSimpleCountRuleBarrier.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/LocalSimpleCountRuleBarrier.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps.nacos; +package com.alibaba.nacos.plugin.control.tps.barrier; import java.util.concurrent.TimeUnit; diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/RateCounter.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/RateCounter.java similarity index 96% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/RateCounter.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/RateCounter.java index 46777ad9a..1bda5537a 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/RateCounter.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/RateCounter.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps.nacos; +package com.alibaba.nacos.plugin.control.tps.barrier; import java.util.concurrent.TimeUnit; diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/RuleBarrier.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/RuleBarrier.java similarity index 91% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/RuleBarrier.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/RuleBarrier.java index 9080b7398..96c928cf4 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/RuleBarrier.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/RuleBarrier.java @@ -14,9 +14,11 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps; +package com.alibaba.nacos.plugin.control.tps.barrier; import com.alibaba.nacos.common.utils.JacksonUtils; +import com.alibaba.nacos.plugin.control.tps.MonitorType; +import com.alibaba.nacos.plugin.control.tps.TpsMetrics; import com.alibaba.nacos.plugin.control.tps.request.BarrierCheckRequest; import com.alibaba.nacos.plugin.control.tps.response.TpsCheckResponse; import com.alibaba.nacos.plugin.control.tps.rule.RuleDetail; @@ -44,7 +46,7 @@ public abstract class RuleBarrier { /** * monitor/intercept. */ - private String monitorType = MonitorType.MONITOR.type; + private String monitorType = MonitorType.MONITOR.getType(); public String getRuleName() { return ruleName; @@ -94,7 +96,7 @@ public abstract class RuleBarrier { } public boolean isMonitorType() { - return MonitorType.MONITOR.type.equalsIgnoreCase(this.monitorType); + return MonitorType.MONITOR.getType().equalsIgnoreCase(this.monitorType); } public String getLimitMsg() { diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/SimpleCountRuleBarrier.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/SimpleCountRuleBarrier.java similarity index 95% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/SimpleCountRuleBarrier.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/SimpleCountRuleBarrier.java index aaf4c8392..406cdb746 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/SimpleCountRuleBarrier.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/SimpleCountRuleBarrier.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,9 +14,8 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps.nacos; +package com.alibaba.nacos.plugin.control.tps.barrier; -import com.alibaba.nacos.plugin.control.tps.RuleBarrier; import com.alibaba.nacos.plugin.control.tps.TpsMetrics; import com.alibaba.nacos.plugin.control.tps.request.BarrierCheckRequest; import com.alibaba.nacos.plugin.control.tps.response.TpsCheckResponse; diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsBarrier.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/TpsBarrier.java similarity index 51% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsBarrier.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/TpsBarrier.java index 6a3eb4fd1..750698b6f 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsBarrier.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/TpsBarrier.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,17 +14,14 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps; +package com.alibaba.nacos.plugin.control.tps.barrier; -import com.alibaba.nacos.common.spi.NacosServiceLoader; -import com.alibaba.nacos.plugin.control.Loggers; -import com.alibaba.nacos.plugin.control.configs.ControlConfigs; -import com.alibaba.nacos.plugin.control.tps.nacos.LocalSimpleCountBarrierCreator; +import com.alibaba.nacos.plugin.control.tps.barrier.creator.RuleBarrierCreator; +import com.alibaba.nacos.plugin.control.tps.barrier.creator.LocalSimpleCountBarrierCreator; import com.alibaba.nacos.plugin.control.tps.request.TpsCheckRequest; import com.alibaba.nacos.plugin.control.tps.response.TpsCheckResponse; import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule; -import java.util.Collection; import java.util.concurrent.TimeUnit; /** @@ -35,38 +32,16 @@ import java.util.concurrent.TimeUnit; @SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule") public abstract class TpsBarrier { + protected RuleBarrierCreator ruleBarrierCreator; + protected String pointName; protected RuleBarrier pointBarrier; public TpsBarrier(String pointName) { this.pointName = pointName; - pointBarrier = ruleBarrierCreator.createRuleBarrier(pointName, pointName, TimeUnit.SECONDS); - } - - protected static RuleBarrierCreator ruleBarrierCreator; - - static { - String tpsBarrierCreator = ControlConfigs.getInstance().getTpsBarrierCreator(); - Collection loadedCreators = NacosServiceLoader.load(RuleBarrierCreator.class); - for (RuleBarrierCreator barrierCreator : loadedCreators) { - if (tpsBarrierCreator.equalsIgnoreCase(barrierCreator.name())) { - Loggers.CONTROL.info("Found tps rule creator of name : {}", tpsBarrierCreator); - ruleBarrierCreator = barrierCreator; - break; - } - } - - if (ruleBarrierCreator == null) { - Loggers.CONTROL.warn("Fail to found tps rule creator of name : {},use default local simple creator", - tpsBarrierCreator); - ruleBarrierCreator = LocalSimpleCountBarrierCreator.getInstance(); - } - - } - - public static void setRuleBarrierCreator(RuleBarrierCreator ruleBarrierCreatorInstance) { - ruleBarrierCreator = ruleBarrierCreatorInstance; + this.ruleBarrierCreator = new LocalSimpleCountBarrierCreator(); + this.pointBarrier = ruleBarrierCreator.createRuleBarrier(pointName, pointName, TimeUnit.SECONDS); } /** diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/DefaultNacosTpsBarrierCreator.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/DefaultNacosTpsBarrierCreator.java similarity index 74% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/DefaultNacosTpsBarrierCreator.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/DefaultNacosTpsBarrierCreator.java index d9c2f7860..9ac3e17f3 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/DefaultNacosTpsBarrierCreator.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/DefaultNacosTpsBarrierCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps.nacos; +package com.alibaba.nacos.plugin.control.tps.barrier.creator; -import com.alibaba.nacos.plugin.control.tps.TpsBarrier; -import com.alibaba.nacos.plugin.control.tps.TpsBarrierCreator; +import com.alibaba.nacos.plugin.control.tps.barrier.TpsBarrier; +import com.alibaba.nacos.plugin.control.tps.barrier.DefaultNacosTpsBarrier; /** * default nacos tps barrier creator. @@ -33,6 +33,6 @@ public class DefaultNacosTpsBarrierCreator implements TpsBarrierCreator { @Override public TpsBarrier createTpsBarrier(String pointName) { - return new NacosTpsBarrier(pointName); + return new DefaultNacosTpsBarrier(pointName); } } diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/LocalSimpleCountBarrierCreator.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/LocalSimpleCountBarrierCreator.java similarity index 83% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/LocalSimpleCountBarrierCreator.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/LocalSimpleCountBarrierCreator.java index 6ad630eca..e2c51c791 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/nacos/LocalSimpleCountBarrierCreator.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/LocalSimpleCountBarrierCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps.nacos; +package com.alibaba.nacos.plugin.control.tps.barrier.creator; -import com.alibaba.nacos.plugin.control.tps.RuleBarrier; -import com.alibaba.nacos.plugin.control.tps.RuleBarrierCreator; +import com.alibaba.nacos.plugin.control.tps.barrier.RuleBarrier; +import com.alibaba.nacos.plugin.control.tps.barrier.LocalSimpleCountRuleBarrier; import java.util.concurrent.TimeUnit; diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/RuleBarrierCreator.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/RuleBarrierCreator.java similarity index 85% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/RuleBarrierCreator.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/RuleBarrierCreator.java index 669d45859..e3cbdf85f 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/RuleBarrierCreator.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/RuleBarrierCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,7 +14,9 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps; +package com.alibaba.nacos.plugin.control.tps.barrier.creator; + +import com.alibaba.nacos.plugin.control.tps.barrier.RuleBarrier; import java.util.concurrent.TimeUnit; diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsBarrierCreator.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/TpsBarrierCreator.java similarity index 83% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsBarrierCreator.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/TpsBarrierCreator.java index 525039da3..c0d22a54e 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/TpsBarrierCreator.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/tps/barrier/creator/TpsBarrierCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2020 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,7 +14,9 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.tps; +package com.alibaba.nacos.plugin.control.tps.barrier.creator; + +import com.alibaba.nacos.plugin.control.tps.barrier.TpsBarrier; /** * tps barrier creator. diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/DiskUtils.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/utils/DiskUtils.java similarity index 99% rename from plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/DiskUtils.java rename to plugin/control/src/main/java/com/alibaba/nacos/plugin/control/utils/DiskUtils.java index 6edcb8ed3..5156bdcf0 100644 --- a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/ruleactivator/DiskUtils.java +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/utils/DiskUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.plugin.control.ruleactivator; +package com.alibaba.nacos.plugin.control.utils; import com.alibaba.nacos.common.utils.ByteUtils; import org.apache.commons.io.FileUtils; diff --git a/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/utils/EnvUtils.java b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/utils/EnvUtils.java new file mode 100644 index 000000000..3fbd7dd28 --- /dev/null +++ b/plugin/control/src/main/java/com/alibaba/nacos/plugin/control/utils/EnvUtils.java @@ -0,0 +1,49 @@ +/* + * Copyright 1999-2023 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.plugin.control.utils; + +import com.alibaba.nacos.common.utils.StringUtils; + +import java.nio.file.Paths; + +/** + * Control plugin env utils. + * + * @author xiweng.yy + */ +public class EnvUtils { + + public static final String NACOS_HOME_KEY = "nacos.home"; + + private static final String NACOS_HOME_PROPERTY = "user.home"; + + private static final String NACOS_HOME_ADDITIONAL_FILEPATH = "nacos"; + + private static String nacosHomePath = null; + + public static String getNacosHome() { + if (StringUtils.isBlank(nacosHomePath)) { + String nacosHome = System.getProperty(NACOS_HOME_KEY); + if (StringUtils.isBlank(nacosHome)) { + nacosHome = Paths.get(System.getProperty(NACOS_HOME_PROPERTY), NACOS_HOME_ADDITIONAL_FILEPATH) + .toString(); + } + return nacosHome; + } + return nacosHomePath; + } +} diff --git a/plugin/control/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.ruleactivator.RuleParser b/plugin/control/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.ruleactivator.RuleParser deleted file mode 100644 index dcb416481..000000000 --- a/plugin/control/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.ruleactivator.RuleParser +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright 1999-2020 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. -# - -# -# -# Copyright 1999-2021 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. -# -# - -com.alibaba.nacos.plugin.control.ruleactivator.NacosRuleParser \ No newline at end of file diff --git a/plugin/control/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.RuleBarrierCreator b/plugin/control/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.RuleBarrierCreator deleted file mode 100644 index 48be53452..000000000 --- a/plugin/control/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.RuleBarrierCreator +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright 1999-2020 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. -# - -# -# -# Copyright 1999-2021 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. -# -# - -com.alibaba.nacos.plugin.control.tps.nacos.LocalSimpleCountBarrierCreator \ No newline at end of file diff --git a/plugin/control/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.TpsBarrierCreator b/plugin/control/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.TpsBarrierCreator deleted file mode 100644 index 5b0725dc4..000000000 --- a/plugin/control/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.TpsBarrierCreator +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright 1999-2020 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. -# - -# -# -# Copyright 1999-2021 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. -# -# - -com.alibaba.nacos.plugin.control.tps.nacos.DefaultNacosTpsBarrierCreator \ No newline at end of file diff --git a/plugin/control/src/test/java/com/alibaba/nacos/plugin/control/connection/NacosConnectionControlManagerTest.java b/plugin/control/src/test/java/com/alibaba/nacos/plugin/control/connection/DefaultConnectionControlManagerTest.java similarity index 88% rename from plugin/control/src/test/java/com/alibaba/nacos/plugin/control/connection/NacosConnectionControlManagerTest.java rename to plugin/control/src/test/java/com/alibaba/nacos/plugin/control/connection/DefaultConnectionControlManagerTest.java index 556dee195..9ee82ca6d 100644 --- a/plugin/control/src/test/java/com/alibaba/nacos/plugin/control/connection/NacosConnectionControlManagerTest.java +++ b/plugin/control/src/test/java/com/alibaba/nacos/plugin/control/connection/DefaultConnectionControlManagerTest.java @@ -16,7 +16,6 @@ package com.alibaba.nacos.plugin.control.connection; -import com.alibaba.nacos.plugin.control.connection.nacos.NacosConnectionControlManager; import com.alibaba.nacos.plugin.control.connection.request.ConnectionCheckRequest; import com.alibaba.nacos.plugin.control.connection.response.ConnectionCheckCode; import com.alibaba.nacos.plugin.control.connection.response.ConnectionCheckResponse; @@ -27,9 +26,9 @@ import org.junit.Test; /** * two fixed metrics, total 30, iptotal 15, detail is testa(total-20,iptotal-10),testb(total-10,iptotal-5). */ -public class NacosConnectionControlManagerTest { +public class DefaultConnectionControlManagerTest { - NacosConnectionControlManager connectionControlManager = new NacosConnectionControlManager(); + DefaultConnectionControlManager connectionControlManager = new DefaultConnectionControlManager(); @Test public void test() { diff --git a/plugin/control/src/test/java/com/alibaba/nacos/plugin/control/tps/NacosTpsBarrierTest.java b/plugin/control/src/test/java/com/alibaba/nacos/plugin/control/tps/DefaultNacosTpsBarrierTest.java similarity index 82% rename from plugin/control/src/test/java/com/alibaba/nacos/plugin/control/tps/NacosTpsBarrierTest.java rename to plugin/control/src/test/java/com/alibaba/nacos/plugin/control/tps/DefaultNacosTpsBarrierTest.java index 25d40a9c0..6658f4f25 100644 --- a/plugin/control/src/test/java/com/alibaba/nacos/plugin/control/tps/NacosTpsBarrierTest.java +++ b/plugin/control/src/test/java/com/alibaba/nacos/plugin/control/tps/DefaultNacosTpsBarrierTest.java @@ -16,8 +16,8 @@ package com.alibaba.nacos.plugin.control.tps; -import com.alibaba.nacos.plugin.control.tps.nacos.LocalSimpleCountBarrierCreator; -import com.alibaba.nacos.plugin.control.tps.nacos.NacosTpsBarrier; +import com.alibaba.nacos.plugin.control.tps.barrier.TpsBarrier; +import com.alibaba.nacos.plugin.control.tps.barrier.DefaultNacosTpsBarrier; import com.alibaba.nacos.plugin.control.tps.request.TpsCheckRequest; import com.alibaba.nacos.plugin.control.tps.response.TpsCheckResponse; import com.alibaba.nacos.plugin.control.tps.rule.RuleDetail; @@ -29,19 +29,14 @@ import org.junit.Test; import java.util.concurrent.TimeUnit; -public class NacosTpsBarrierTest { - - RuleBarrierCreator before; +public class DefaultNacosTpsBarrierTest { @Before public void setUp() { - before = TpsBarrier.ruleBarrierCreator; - TpsBarrier.ruleBarrierCreator = new LocalSimpleCountBarrierCreator(); } @After public void after() { - TpsBarrier.ruleBarrierCreator = before; } @Test @@ -57,7 +52,7 @@ public class NacosTpsBarrierTest { ruleDetail.setPeriod(TimeUnit.SECONDS); tpsControlRule.setPointRule(ruleDetail); - TpsBarrier tpsBarrier = new NacosTpsBarrier(testTpsBarrier); + TpsBarrier tpsBarrier = new DefaultNacosTpsBarrier(testTpsBarrier); tpsBarrier.applyRule(tpsControlRule); //test point keys diff --git a/plugin/control/src/test/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.RuleBarrierCreator b/plugin/control/src/test/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.barrier.creator.RuleBarrierCreator similarity index 93% rename from plugin/control/src/test/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.RuleBarrierCreator rename to plugin/control/src/test/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.barrier.creator.RuleBarrierCreator index 48be53452..a27cf5827 100644 --- a/plugin/control/src/test/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.RuleBarrierCreator +++ b/plugin/control/src/test/resources/META-INF/services/com.alibaba.nacos.plugin.control.tps.barrier.creator.RuleBarrierCreator @@ -32,4 +32,4 @@ # # -com.alibaba.nacos.plugin.control.tps.nacos.LocalSimpleCountBarrierCreator \ No newline at end of file +com.alibaba.nacos.plugin.control.tps.barrier.creator.LocalSimpleCountBarrierCreator \ No newline at end of file