diff --git a/sermant-backend/src/main/java/io/sermant/backend/common/conf/CommonConst.java b/sermant-backend/src/main/java/io/sermant/backend/common/conf/CommonConst.java index b46dd58c80..97945d43b0 100644 --- a/sermant-backend/src/main/java/io/sermant/backend/common/conf/CommonConst.java +++ b/sermant-backend/src/main/java/io/sermant/backend/common/conf/CommonConst.java @@ -133,6 +133,16 @@ public class CommonConst { + "> throwable: %s " + System.lineSeparator() + "--- " + System.lineSeparator(); + /** + * Service name for global configuration + */ + public static final String GLOBAL_CONFIGURATION_SERVICE_NAME = "ALL_SERVICE"; + + /** + * Default regular expression for configuration item Group + */ + public static final String CONFIGURATION_DEFAULT_PATTERN = "^(app=[^&]*+&environment=[^&]*+(&service=[^&]*)?)?$"; + private CommonConst() { } diff --git a/sermant-backend/src/main/java/io/sermant/backend/common/conf/DynamicConfig.java b/sermant-backend/src/main/java/io/sermant/backend/common/conf/DynamicConfig.java new file mode 100644 index 0000000000..f1e5017aaf --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/common/conf/DynamicConfig.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.common.conf; + +import lombok.Getter; +import lombok.Setter; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +/** + * Configuration class for dynamic configuration function + * + * @author zhp + * @since 2024-05-21 + */ +@Configuration +@Getter +@Setter +@Component +public class DynamicConfig { + /** + * Connection address of configuration center + */ + @Value("${dynamic.config.serverAddress}") + private String serverAddress; + + /** + * Type of Configuration Center + */ + @Value("${dynamic.config.dynamicConfigType}") + private String dynamicConfigType; + + /** + * Request timeout + */ + @Value("${dynamic.config.requestTimeout}") + private long requestTimeout; + + /** + * Connection timeout + */ + @Value("${dynamic.config.connectTimeout}") + private long connectTimeout; + + /** + * Session timeout + */ + @Value("${dynamic.config.timeout}") + private int timeout; + + /** + * Authorized switch + */ + @Value("${dynamic.config.enableAuth}") + private boolean enableAuth; + + /** + * userName, used for configuration center connection authorization + */ + @Value("${dynamic.config.userName}") + private String userName; + + /** + * password, used for configuration center connection authorization + */ + @Value("${dynamic.config.password}") + private String password; + + /** + * Encryption and decryption keys for passwords + */ + @Value("${dynamic.config.secretKey}") + private String secretKey; + + /** + * Namespaces, only used by the nacos configuration center + */ + @Value("${dynamic.config.namespace}") + private String namespace = "default"; + + /** + * Switch for configuration management + */ + @Value("${dynamic.config.dynamicConfigEnable}") + private boolean dynamicConfigEnable; +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/entity/config/PluginType.java b/sermant-backend/src/main/java/io/sermant/backend/entity/config/PluginType.java new file mode 100644 index 0000000000..d013c3f201 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/entity/config/PluginType.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.entity.config; + +import io.sermant.backend.handler.config.DatabaseWriteProhibitionPluginHandler; +import io.sermant.backend.handler.config.FlowControlPluginHandler; +import io.sermant.backend.handler.config.LoadbalancerPluginHandler; +import io.sermant.backend.handler.config.MqConsumeProhibitionPluginHandler; +import io.sermant.backend.handler.config.OtherPluginHandler; +import io.sermant.backend.handler.config.PluginConfigHandler; +import io.sermant.backend.handler.config.RemovalPluginHandler; +import io.sermant.backend.handler.config.RouterPluginHandler; +import io.sermant.backend.handler.config.ServiceRegistryPluginHandler; +import io.sermant.backend.handler.config.SpringBootRegistryPluginHandler; +import io.sermant.backend.handler.config.TagTransmissionPluginHandler; +import lombok.Getter; + +import java.util.Optional; + +/** + * Plugin type + * + * @author zhp + * @since 2024-05-16 + */ +@Getter +public enum PluginType { + /** + * Label routing plugin + */ + ROUTER("router", new RouterPluginHandler()), + + /** + * Springboot registration plugin + */ + SPRINGBOOT_REGISTRY("springboot-registry", new SpringBootRegistryPluginHandler()), + + /** + * Register migration plugin + */ + SERVICE_REGISTRY("service-registry", new ServiceRegistryPluginHandler()), + + /** + * flowcontrol plugin + */ + FLOW_CONTROL("flowcontrol", new FlowControlPluginHandler()), + + /** + * Outlier instance removal plugin + */ + REMOVAL("removal", new RemovalPluginHandler()), + + /** + * Load balancing plugin + */ + LOADBALANCER("loadbalancer", new LoadbalancerPluginHandler()), + + /** + * Traffic tag transparency plugin + */ + TAG_TRANSMISSION("tag-transmission", new TagTransmissionPluginHandler()), + + /** + * Message queue prohibited consumption plugin + */ + MQ_CONSUME_PROHIBITION("mq-consume-prohibition", new MqConsumeProhibitionPluginHandler()), + + /** + * Database write prohibited plugin + */ + DATABASE_WRITE_PROHIBITION("database-write-prohibition", new DatabaseWriteProhibitionPluginHandler()), + + /** + * other plugin + */ + OTHER("other", new OtherPluginHandler()); + + private final String pluginName; + + private final PluginConfigHandler handler; + + PluginType(String pluginName, PluginConfigHandler handler) { + this.pluginName = pluginName; + this.handler = handler; + } + + /** + * Obtain plugin type based on plugin name + * + * @param pluginName plugin name + * @return plugin type + */ + public static Optional getPluginType(String pluginName) { + for (PluginType pluginType : PluginType.values()) { + if (pluginType.pluginName.equals(pluginName)) { + return Optional.of(pluginType); + } + } + return Optional.empty(); + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/DatabaseWriteProhibitionPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/DatabaseWriteProhibitionPluginHandler.java new file mode 100644 index 0000000000..8724a87299 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/DatabaseWriteProhibitionPluginHandler.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.common.conf.CommonConst; +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +import java.util.Map; + +/** + * Database Write Prohibition plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class DatabaseWriteProhibitionPluginHandler extends PluginConfigHandler { + private static final String GLOBAL_CONFIGURATION_NAME = "sermant.database.write.globalConfig"; + + private static final String SERVICE_CONFIGURATION_NAME_PREFIX = "sermant.database.write."; + + private static final String PATTERN = "^(app=[^&]*+&environment=[^&]*+(&zone=[^&]*)?)?$"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + Map map = parseGroup(group); + ConfigInfo configInfo = new ConfigInfo(); + if (StringUtils.equals(key, GLOBAL_CONFIGURATION_NAME)) { + configInfo.setServiceName(CommonConst.GLOBAL_CONFIGURATION_SERVICE_NAME); + } else if (key.startsWith(SERVICE_CONFIGURATION_NAME_PREFIX)) { + configInfo.setServiceName(key.replace(SERVICE_CONFIGURATION_NAME_PREFIX, "")); + } + configInfo.setAppName(map.get(APP_KEY)); + configInfo.setEnvironment(map.get(ENVIRONMENT_KEY)); + configInfo.setZone(map.get(ZONE_KEY)); + configInfo.setKey(key); + configInfo.setGroup(group); + configInfo.setPluginType(PluginType.DATABASE_WRITE_PROHIBITION.getPluginName()); + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + if (StringUtils.isBlank(key) || StringUtils.isBlank(group)) { + return false; + } + if (!group.matches(PATTERN)) { + return false; + } + return key.equals(GLOBAL_CONFIGURATION_NAME) || key.startsWith(SERVICE_CONFIGURATION_NAME_PREFIX); + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/FlowControlPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/FlowControlPluginHandler.java new file mode 100644 index 0000000000..e454248251 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/FlowControlPluginHandler.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +import java.util.Map; + +/** + * Flow control plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class FlowControlPluginHandler extends PluginConfigHandler { + private static final String[] CONFIGURATION_NAME_PREFIX_ARRAY = {"servicecomb.rateLimiting.", + "servicecomb.matchGroup.", "servicecomb.circuitBreaker.", "servicecomb.bulkhead.", + "servicecomb.faultInjection.", "servicecomb.retry.", "servicecomb.system."}; + + private static final String PATTERN = "^service=[^&]*$"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + Map map = parseGroup(group); + ConfigInfo configInfo = new ConfigInfo(); + configInfo.setServiceName(map.get(SERVICE_KEY)); + configInfo.setKey(key); + configInfo.setGroup(group); + configInfo.setPluginType(PluginType.FLOW_CONTROL.getPluginName()); + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + if (StringUtils.isBlank(key) || StringUtils.isBlank(group)) { + return false; + } + if (!group.matches(PATTERN)) { + return false; + } + for (String name : CONFIGURATION_NAME_PREFIX_ARRAY) { + if (key.startsWith(name)) { + return true; + } + } + return false; + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/LoadbalancerPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/LoadbalancerPluginHandler.java new file mode 100644 index 0000000000..a37b0f75e2 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/LoadbalancerPluginHandler.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.common.conf.CommonConst; +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +/** + * Spring boot registry plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class LoadbalancerPluginHandler extends PluginConfigHandler { + private static final String TRAFFIC_MARKERS_CONFIGURATION_NAME_PREFIX = "servicecomb.matchGroup."; + + private static final String LOADBALANCER_RULES_CONFIGURATION_NAME_PREFIX = "servicecomb.loadbalance."; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + ConfigInfo configInfo = super.parsePluginInfo(key, group); + if (StringUtils.isEmpty(configInfo.getServiceName())) { + configInfo.setServiceName(CommonConst.GLOBAL_CONFIGURATION_SERVICE_NAME); + } + configInfo.setPluginType(PluginType.LOADBALANCER.getPluginName()); + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + if (StringUtils.isBlank(key) || StringUtils.isBlank(group)) { + return false; + } + if (!group.matches(CommonConst.CONFIGURATION_DEFAULT_PATTERN)) { + return false; + } + return key.startsWith(TRAFFIC_MARKERS_CONFIGURATION_NAME_PREFIX) + || key.startsWith(LOADBALANCER_RULES_CONFIGURATION_NAME_PREFIX); + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/MqConsumeProhibitionPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/MqConsumeProhibitionPluginHandler.java new file mode 100644 index 0000000000..e2ff42ebe7 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/MqConsumeProhibitionPluginHandler.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.common.conf.CommonConst; +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +import java.util.Map; + +/** + * Mq Consume Prohibition plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class MqConsumeProhibitionPluginHandler extends PluginConfigHandler { + private static final String GLOBAL_CONFIGURATION_NAME = "sermant.mq.consume.globalConfig"; + + private static final String SERVICE_CONFIGURATION_NAME_PREFIX = "sermant.mq.consume."; + + private static final String PATTERN = "^(app=[^&]*+&environment=[^&]*+(&zone=[^&]*)?)?$"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + ConfigInfo configInfo = new ConfigInfo(); + Map map = parseGroup(group); + configInfo.setAppName(map.get(APP_KEY)); + configInfo.setEnvironment(map.get(ENVIRONMENT_KEY)); + configInfo.setKey(key); + configInfo.setGroup(group); + configInfo.setZone(map.get(ZONE_KEY)); + configInfo.setPluginType(PluginType.MQ_CONSUME_PROHIBITION.getPluginName()); + if (StringUtils.equals(key, GLOBAL_CONFIGURATION_NAME)) { + configInfo.setServiceName(CommonConst.GLOBAL_CONFIGURATION_SERVICE_NAME); + return configInfo; + } + if (key.startsWith(SERVICE_CONFIGURATION_NAME_PREFIX)) { + configInfo.setServiceName(key.replace(SERVICE_CONFIGURATION_NAME_PREFIX, "")); + } + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + if (StringUtils.isBlank(key) || StringUtils.isBlank(group)) { + return false; + } + if (!group.matches(PATTERN)) { + return false; + } + return key.equals(GLOBAL_CONFIGURATION_NAME) || key.startsWith(SERVICE_CONFIGURATION_NAME_PREFIX); + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/OtherPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/OtherPluginHandler.java new file mode 100644 index 0000000000..4de0199c71 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/OtherPluginHandler.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +/** + * Other plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class OtherPluginHandler extends PluginConfigHandler { + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + ConfigInfo configInfo = new ConfigInfo(); + configInfo.setKey(key); + configInfo.setGroup(group); + configInfo.setPluginType(PluginType.OTHER.getPluginName()); + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + return StringUtils.isNotBlank(key) && StringUtils.isNotBlank(group); + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/PluginConfigHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/PluginConfigHandler.java new file mode 100644 index 0000000000..3ee7e032ba --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/PluginConfigHandler.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.entity.config.ConfigInfo; + +import java.util.HashMap; +import java.util.Map; + +/** + * plugin Handler + * + * @author zhp + * @since 2024-05-16 + */ +public abstract class PluginConfigHandler { + /** + * The key for the application name + */ + protected static final String APP_KEY = "app"; + + /** + * The key for the environment + */ + protected static final String ENVIRONMENT_KEY = "environment"; + + /** + * The key for the service name + */ + protected static final String SERVICE_KEY = "service"; + + /** + * The key for the zone name + */ + protected static final String ZONE_KEY = "zone"; + + private static final String GROUP_SPLIT = "&"; + + private static final String GROUP_CONNECT = "="; + + /** + * Parse plugin information, extract application name, service name, and environment name from group and key + * information + * + * @param key Configuration Item Name + * @param group Configuration item group name + * @return configuration information + */ + public ConfigInfo parsePluginInfo(String key, String group) { + Map map = parseGroup(group); + ConfigInfo configInfo = new ConfigInfo(); + configInfo.setAppName(map.get(APP_KEY)); + configInfo.setEnvironment(map.get(ENVIRONMENT_KEY)); + configInfo.setServiceName(map.get(SERVICE_KEY)); + configInfo.setKey(key); + configInfo.setGroup(group); + return configInfo; + } + + /** + * Verify if the configuration item is the current plugin configuration + * + * @param key Configuration Item Name + * @param group Configuration item group name + * @return Verification results + */ + public abstract boolean verifyConfiguration(String key, String group); + + /** + * Parsing group information + * + * @param group Configuration item group name + * @return Parsed information + */ + Map parseGroup(String group) { + Map map = new HashMap<>(); + String[] parts = group.split(GROUP_SPLIT); + for (String part : parts) { + String[] keyValue = part.split(GROUP_CONNECT); + if (keyValue.length > 1) { + map.put(keyValue[0], keyValue[1]); + } + } + return map; + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/RemovalPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/RemovalPluginHandler.java new file mode 100644 index 0000000000..508a5cc07f --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/RemovalPluginHandler.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.common.conf.CommonConst; +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +import java.util.Map; + +/** + * Outlier instance removal plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class RemovalPluginHandler extends PluginConfigHandler { + private static final String CONFIGURATION_NAME = "sermant.removal.config"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + Map map = parseGroup(group); + ConfigInfo configInfo = new ConfigInfo(); + configInfo.setAppName(map.get(APP_KEY)); + if (StringUtils.isEmpty(map.get(SERVICE_KEY))) { + configInfo.setServiceName(CommonConst.GLOBAL_CONFIGURATION_SERVICE_NAME); + } else { + configInfo.setServiceName(map.get(SERVICE_KEY)); + } + configInfo.setEnvironment(map.get(ENVIRONMENT_KEY)); + configInfo.setKey(key); + configInfo.setGroup(group); + configInfo.setPluginType(PluginType.REMOVAL.getPluginName()); + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + if (StringUtils.isBlank(key) || StringUtils.isBlank(group)) { + return false; + } + if (!group.matches(CommonConst.CONFIGURATION_DEFAULT_PATTERN)) { + return false; + } + return key.equals(CONFIGURATION_NAME); + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/RouterPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/RouterPluginHandler.java new file mode 100644 index 0000000000..9e67e4994e --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/RouterPluginHandler.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.common.conf.CommonConst; +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +import java.util.Map; + +/** + * Router plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class RouterPluginHandler extends PluginConfigHandler { + private static final String GLOBAL_CONFIGURATION_NAME = "servicecomb.globalRouteRule"; + + private static final String SERVICE_CONFIGURATION_NAME_PREFIX = "servicecomb.routeRule."; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + Map map = parseGroup(group); + ConfigInfo configInfo = new ConfigInfo(); + configInfo.setAppName(map.get(APP_KEY)); + configInfo.setEnvironment(map.get(ENVIRONMENT_KEY)); + if (StringUtils.equals(key, GLOBAL_CONFIGURATION_NAME)) { + configInfo.setServiceName(CommonConst.GLOBAL_CONFIGURATION_SERVICE_NAME); + } else if (key.startsWith(SERVICE_CONFIGURATION_NAME_PREFIX)) { + configInfo.setServiceName(key.replace(SERVICE_CONFIGURATION_NAME_PREFIX, "")); + } + configInfo.setKey(key); + configInfo.setGroup(group); + configInfo.setPluginType(PluginType.ROUTER.getPluginName()); + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + if (StringUtils.isBlank(key) || StringUtils.isBlank(group)) { + return false; + } + if (!group.matches(CommonConst.CONFIGURATION_DEFAULT_PATTERN)) { + return false; + } + return key.equals(GLOBAL_CONFIGURATION_NAME) || key.startsWith(SERVICE_CONFIGURATION_NAME_PREFIX); + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/ServiceRegistryPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/ServiceRegistryPluginHandler.java new file mode 100644 index 0000000000..bbe538fd45 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/ServiceRegistryPluginHandler.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.common.conf.CommonConst; +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +/** + * Service Registry plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class ServiceRegistryPluginHandler extends PluginConfigHandler { + private static final String CONFIGURATION_NAME = "sermant.agent.registry"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + ConfigInfo configInfo = super.parsePluginInfo(key, group); + if (StringUtils.isEmpty(configInfo.getServiceName())) { + configInfo.setServiceName(CommonConst.GLOBAL_CONFIGURATION_SERVICE_NAME); + } + configInfo.setPluginType(PluginType.SERVICE_REGISTRY.getPluginName()); + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + if (StringUtils.isBlank(key) || StringUtils.isBlank(group)) { + return false; + } + if (!group.matches(CommonConst.CONFIGURATION_DEFAULT_PATTERN)) { + return false; + } + return key.equals(CONFIGURATION_NAME); + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/SpringBootRegistryPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/SpringBootRegistryPluginHandler.java new file mode 100644 index 0000000000..6428f4b644 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/SpringBootRegistryPluginHandler.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.common.conf.CommonConst; +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +/** + * Spring boot registry plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class SpringBootRegistryPluginHandler extends PluginConfigHandler { + private static final String CONFIGURATION_NAME = "sermant.plugin.registry"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + ConfigInfo configInfo = super.parsePluginInfo(key,group); + if (StringUtils.isEmpty(configInfo.getServiceName())) { + configInfo.setServiceName(CommonConst.GLOBAL_CONFIGURATION_SERVICE_NAME); + } + configInfo.setPluginType(PluginType.SPRINGBOOT_REGISTRY.getPluginName()); + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + if (StringUtils.isBlank(key) || StringUtils.isBlank(group)) { + return false; + } + if (!group.matches(CommonConst.CONFIGURATION_DEFAULT_PATTERN)) { + return false; + } + return key.equals(CONFIGURATION_NAME); + } +} diff --git a/sermant-backend/src/main/java/io/sermant/backend/handler/config/TagTransmissionPluginHandler.java b/sermant-backend/src/main/java/io/sermant/backend/handler/config/TagTransmissionPluginHandler.java new file mode 100644 index 0000000000..e33cf0d957 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/TagTransmissionPluginHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2024-2024 Sermant Authors. All rights reserved. + * + * 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 io.sermant.backend.handler.config; + +import io.sermant.backend.common.conf.CommonConst; +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; + +import org.apache.commons.lang.StringUtils; + +/** + * Tag Transmission plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class TagTransmissionPluginHandler extends PluginConfigHandler { + private static final String CONFIGURATION_GROUP_NAME = "sermant/tag-transmission-plugin"; + + private static final String CONFIGURATION_KEY_NAME = "tag-config"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + ConfigInfo configInfo = new ConfigInfo(); + configInfo.setKey(key); + configInfo.setGroup(group); + configInfo.setServiceName(CommonConst.GLOBAL_CONFIGURATION_SERVICE_NAME); + configInfo.setPluginType(PluginType.TAG_TRANSMISSION.getPluginName()); + return configInfo; + } + + @Override + public boolean verifyConfiguration(String key, String group) { + if (StringUtils.isBlank(key) || StringUtils.isBlank(group)) { + return false; + } + return group.equals(CONFIGURATION_GROUP_NAME) && key.equals(CONFIGURATION_KEY_NAME); + } +} diff --git a/sermant-backend/src/main/resources/application.properties b/sermant-backend/src/main/resources/application.properties index 11fac7e624..6ef48afe34 100644 --- a/sermant-backend/src/main/resources/application.properties +++ b/sermant-backend/src/main/resources/application.properties @@ -36,3 +36,16 @@ database.fixedDelay=10000 # Session expiration time(s) session.expire=60 + +# Dynamic config service configuration +dynamic.config.dynamicConfigEnable=true +dynamic.config.namespace=default +dynamic.config.timeout=30000 +dynamic.config.serverAddress=127.0.0.1:2181 +dynamic.config.dynamicConfigType=ZOOKEEPER +dynamic.config.connectTimeout=1000 +dynamic.config.enableAuth=false +dynamic.config.userName= +dynamic.config.password= +dynamic.config.secretKey= +dynamic.config.requestTimeout=3000 diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/DatabaseWriteProhibitionPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/DatabaseWriteProhibitionPluginHandlerTest.java new file mode 100644 index 0000000000..ca9136db36 --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/DatabaseWriteProhibitionPluginHandlerTest.java @@ -0,0 +1,53 @@ +package io.sermant.backend.handler.config.handler; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.DatabaseWriteProhibitionPluginHandler; +import io.sermant.backend.handler.config.PluginConfigHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class DatabaseWriteProhibitionPluginHandlerTest { + private static final String DEFAULT_APP_NAME = "default"; + + private static final String DEFAULT_ENVIRONMENT_NAME = "prod"; + + private static final String DEFAULT_ZONE_NAME = "gz"; + + private static final String DEFAULT_SERVICE_NAME = "provider"; + + private static final String DEFAULT_GROUP = "app=default&environment=prod&zone=gz"; + + private static final String ERROR_GROUP = "app=default&envi="; + + private static final String ERROR_KEY = "testKey"; + + private static final String SERVICE_CONFIGURATION_NAME = "sermant.database.write.provider"; + + private static final String GLOBAL_CONFIGURATION_NAME = "sermant.database.write.globalConfig"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new DatabaseWriteProhibitionPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(SERVICE_CONFIGURATION_NAME, DEFAULT_GROUP); + Assert.assertEquals(configInfo.getAppName(), DEFAULT_APP_NAME); + Assert.assertEquals(configInfo.getEnvironment(), DEFAULT_ENVIRONMENT_NAME); + Assert.assertEquals(configInfo.getZone(), DEFAULT_ZONE_NAME); + Assert.assertEquals(configInfo.getServiceName(), DEFAULT_SERVICE_NAME); + Assert.assertEquals(configInfo.getKey(), SERVICE_CONFIGURATION_NAME); + Assert.assertEquals(configInfo.getGroup(), DEFAULT_GROUP); + Assert.assertEquals(configInfo.getPluginType(), PluginType.DATABASE_WRITE_PROHIBITION.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new DatabaseWriteProhibitionPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(SERVICE_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(GLOBAL_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(SERVICE_CONFIGURATION_NAME, ERROR_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(ERROR_KEY, DEFAULT_GROUP)); + } +} \ No newline at end of file diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/FlowControlPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/FlowControlPluginHandlerTest.java new file mode 100644 index 0000000000..2e6a5b1c7b --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/FlowControlPluginHandlerTest.java @@ -0,0 +1,59 @@ +package io.sermant.backend.handler.config.handler; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.FlowControlPluginHandler; +import io.sermant.backend.handler.config.PluginConfigHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class FlowControlPluginHandlerTest { + private static final String DEFAULT_SERVICE_NAME = "provider"; + + private static final String DEFAULT_GROUP = "service=provider"; + + private static final String ERROR_GROUP = "service=provider&app=default"; + + private static final String ERROR_KEY = "testKey"; + + private static final String RATE_LIMIT_CONFIGURATION_NAME = "servicecomb.rateLimiting.test"; + + private static final String BULKHEAD_CONFIGURATION_NAME = "servicecomb.bulkhead.test"; + + private static final String MATCH_GROUP_CONFIGURATION_NAME = "servicecomb.matchGroup.test"; + + private static final String CIRCUIT_BREAKER_CONFIGURATION_NAME = "servicecomb.circuitBreaker.bulkhead"; + + private static final String FAULT_INJECTION_CONFIGURATION_NAME = "servicecomb.faultInjection.test"; + + private static final String RETRY_CONFIGURATION_NAME = "servicecomb.retry.test"; + + private static final String SYSTEM_CONFIGURATION_NAME = "servicecomb.system.bulkhead"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new FlowControlPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(RATE_LIMIT_CONFIGURATION_NAME, DEFAULT_GROUP); + Assert.assertEquals(configInfo.getServiceName(), DEFAULT_SERVICE_NAME); + Assert.assertEquals(configInfo.getKey(), RATE_LIMIT_CONFIGURATION_NAME); + Assert.assertEquals(configInfo.getGroup(), DEFAULT_GROUP); + Assert.assertEquals(configInfo.getPluginType(), PluginType.FLOW_CONTROL.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new FlowControlPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(RATE_LIMIT_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(BULKHEAD_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(MATCH_GROUP_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(CIRCUIT_BREAKER_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(FAULT_INJECTION_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(RETRY_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(SYSTEM_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(RATE_LIMIT_CONFIGURATION_NAME, ERROR_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(ERROR_KEY, DEFAULT_GROUP)); + } +} \ No newline at end of file diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/LoadbalancerPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/LoadbalancerPluginHandlerTest.java new file mode 100644 index 0000000000..03fb2a91a3 --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/LoadbalancerPluginHandlerTest.java @@ -0,0 +1,51 @@ +package io.sermant.backend.handler.config.handler; + + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.LoadbalancerPluginHandler; +import io.sermant.backend.handler.config.PluginConfigHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class LoadbalancerPluginHandlerTest { + private static final String DEFAULT_APP_NAME = "default"; + + private static final String DEFAULT_ENVIRONMENT_NAME = "prod"; + + private static final String DEFAULT_SERVICE_NAME = "provider"; + + private static final String DEFAULT_GROUP = "app=default&environment=prod&service=provider"; + + private static final String ERROR_GROUP = "app=default&env=prod&service=provider"; + + private static final String ERROR_KEY = "testKey"; + + private static final String MATCH_GROUP_CONFIGURATION_NAME = "servicecomb.matchGroup.test"; + + private static final String LOADBALANCER_CONFIGURATION_NAME = "servicecomb.loadbalance.test"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new LoadbalancerPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(MATCH_GROUP_CONFIGURATION_NAME, DEFAULT_GROUP); + Assert.assertEquals(configInfo.getAppName(), DEFAULT_APP_NAME); + Assert.assertEquals(configInfo.getEnvironment(), DEFAULT_ENVIRONMENT_NAME); + Assert.assertEquals(configInfo.getServiceName(), DEFAULT_SERVICE_NAME); + Assert.assertEquals(configInfo.getKey(), MATCH_GROUP_CONFIGURATION_NAME); + Assert.assertEquals(configInfo.getGroup(), DEFAULT_GROUP); + Assert.assertEquals(configInfo.getPluginType(), PluginType.LOADBALANCER.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new LoadbalancerPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(MATCH_GROUP_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(LOADBALANCER_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(MATCH_GROUP_CONFIGURATION_NAME, ERROR_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(ERROR_KEY, DEFAULT_GROUP)); + } +} \ No newline at end of file diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/MqConsumeProhibitionPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/MqConsumeProhibitionPluginHandlerTest.java new file mode 100644 index 0000000000..b748b7852f --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/MqConsumeProhibitionPluginHandlerTest.java @@ -0,0 +1,53 @@ +package io.sermant.backend.handler.config.handler; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.MqConsumeProhibitionPluginHandler; +import io.sermant.backend.handler.config.PluginConfigHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class MqConsumeProhibitionPluginHandlerTest { + private static final String DEFAULT_APP_NAME = "default"; + + private static final String DEFAULT_ENVIRONMENT_NAME = "prod"; + + private static final String DEFAULT_ZONE_NAME = "gz"; + + private static final String DEFAULT_SERVICE_NAME = "provider"; + + private static final String DEFAULT_GROUP = "app=default&environment=prod&zone=gz"; + + private static final String ERROR_GROUP = "app=default&env=prod&zone=gz"; + + private static final String ERROR_KEY = "testKey"; + + private static final String SERVICE_CONFIGURATION_NAME = "sermant.mq.consume.provider"; + + private static final String GLOBAL_CONFIGURATION_NAME = "sermant.mq.consume.globalConfig"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new MqConsumeProhibitionPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(SERVICE_CONFIGURATION_NAME, DEFAULT_GROUP); + Assert.assertEquals(configInfo.getAppName(), DEFAULT_APP_NAME); + Assert.assertEquals(configInfo.getEnvironment(), DEFAULT_ENVIRONMENT_NAME); + Assert.assertEquals(configInfo.getZone(), DEFAULT_ZONE_NAME); + Assert.assertEquals(configInfo.getServiceName(), DEFAULT_SERVICE_NAME); + Assert.assertEquals(configInfo.getKey(), SERVICE_CONFIGURATION_NAME); + Assert.assertEquals(configInfo.getGroup(), DEFAULT_GROUP); + Assert.assertEquals(configInfo.getPluginType(), PluginType.MQ_CONSUME_PROHIBITION.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new MqConsumeProhibitionPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(SERVICE_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(GLOBAL_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(SERVICE_CONFIGURATION_NAME, ERROR_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(ERROR_KEY, DEFAULT_GROUP)); + } +} \ No newline at end of file diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/OtherPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/OtherPluginHandlerTest.java new file mode 100644 index 0000000000..f56100908f --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/OtherPluginHandlerTest.java @@ -0,0 +1,32 @@ +package io.sermant.backend.handler.config.handler; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.OtherPluginHandler; +import io.sermant.backend.handler.config.PluginConfigHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class OtherPluginHandlerTest { + private static final String DEFAULT_KEY = "sermant.database.write.provider"; + + private static final String DEFAULT_GROUP = "app=default&environment=prod&zone=gz"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new OtherPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(DEFAULT_KEY, DEFAULT_GROUP); + Assert.assertEquals(configInfo.getKey(), DEFAULT_KEY); + Assert.assertEquals(configInfo.getGroup(), DEFAULT_GROUP); + Assert.assertEquals(configInfo.getPluginType(), PluginType.OTHER.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new OtherPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(DEFAULT_KEY, DEFAULT_GROUP)); + } +} \ No newline at end of file diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/RemovalPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/RemovalPluginHandlerTest.java new file mode 100644 index 0000000000..e98f68315e --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/RemovalPluginHandlerTest.java @@ -0,0 +1,44 @@ +package io.sermant.backend.handler.config.handler; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.PluginConfigHandler; +import io.sermant.backend.handler.config.RemovalPluginHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class RemovalPluginHandlerTest { + private static final String DEFAULT_APP_NAME = "default"; + + private static final String DEFAULT_ENVIRONMENT_NAME = "prod"; + + private static final String DEFAULT_GROUP = "app=default&environment=prod"; + + private static final String ERROR_GROUP = "app=default&env=prod"; + + private static final String ERROR_KEY = "testKey"; + + private static final String CONFIGURATION_NAME = "sermant.removal.config"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new RemovalPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(CONFIGURATION_NAME, DEFAULT_GROUP); + Assert.assertEquals(configInfo.getAppName(), DEFAULT_APP_NAME); + Assert.assertEquals(configInfo.getEnvironment(), DEFAULT_ENVIRONMENT_NAME); + Assert.assertEquals(configInfo.getKey(), CONFIGURATION_NAME); + Assert.assertEquals(configInfo.getGroup(), DEFAULT_GROUP); + Assert.assertEquals(configInfo.getPluginType(), PluginType.REMOVAL.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new RemovalPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(CONFIGURATION_NAME, ERROR_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(ERROR_KEY, DEFAULT_GROUP)); + } +} \ No newline at end of file diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/RouterPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/RouterPluginHandlerTest.java new file mode 100644 index 0000000000..66fafa3924 --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/RouterPluginHandlerTest.java @@ -0,0 +1,50 @@ +package io.sermant.backend.handler.config.handler; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.PluginConfigHandler; +import io.sermant.backend.handler.config.RouterPluginHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class RouterPluginHandlerTest { + private static final String DEFAULT_APP_NAME = "default"; + + private static final String DEFAULT_ENVIRONMENT_NAME = "prod"; + + private static final String DEFAULT_SERVICE_NAME = "provider"; + + private static final String DEFAULT_GROUP = "app=default&environment=prod"; + + private static final String ERROR_GROUP = "app=default&env=prod"; + + private static final String ERROR_KEY = "testKey"; + + private static final String SERVICE_CONFIGURATION_NAME = "servicecomb.routeRule.provider"; + + private static final String GLOBAL_CONFIGURATION_NAME = "servicecomb.globalRouteRule"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new RouterPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(SERVICE_CONFIGURATION_NAME, DEFAULT_GROUP); + Assert.assertEquals(configInfo.getAppName(), DEFAULT_APP_NAME); + Assert.assertEquals(configInfo.getEnvironment(), DEFAULT_ENVIRONMENT_NAME); + Assert.assertEquals(configInfo.getServiceName(), DEFAULT_SERVICE_NAME); + Assert.assertEquals(configInfo.getKey(), SERVICE_CONFIGURATION_NAME); + Assert.assertEquals(configInfo.getGroup(), DEFAULT_GROUP); + Assert.assertEquals(configInfo.getPluginType(), PluginType.ROUTER.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new RouterPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(SERVICE_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertTrue(handler.verifyConfiguration(GLOBAL_CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(SERVICE_CONFIGURATION_NAME, ERROR_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(ERROR_KEY, DEFAULT_GROUP)); + } +} \ No newline at end of file diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/ServiceRegistryPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/ServiceRegistryPluginHandlerTest.java new file mode 100644 index 0000000000..285dd2fb07 --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/ServiceRegistryPluginHandlerTest.java @@ -0,0 +1,47 @@ +package io.sermant.backend.handler.config.handler; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.PluginConfigHandler; +import io.sermant.backend.handler.config.ServiceRegistryPluginHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class ServiceRegistryPluginHandlerTest { + private static final String DEFAULT_APP_NAME = "default"; + + private static final String DEFAULT_ENVIRONMENT_NAME = "prod"; + + private static final String DEFAULT_SERVICE_NAME = "provider"; + + private static final String DEFAULT_GROUP = "app=default&environment=prod&service=provider"; + + private static final String ERROR_GROUP = "app=default&env=prod&service=provider"; + + private static final String ERROR_KEY = "testKey"; + + private static final String CONFIGURATION_NAME = "sermant.agent.registry"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new ServiceRegistryPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(CONFIGURATION_NAME, DEFAULT_GROUP); + Assert.assertEquals(configInfo.getAppName(), DEFAULT_APP_NAME); + Assert.assertEquals(configInfo.getEnvironment(), DEFAULT_ENVIRONMENT_NAME); + Assert.assertEquals(configInfo.getServiceName(), DEFAULT_SERVICE_NAME); + Assert.assertEquals(configInfo.getKey(), CONFIGURATION_NAME); + Assert.assertEquals(configInfo.getGroup(), DEFAULT_GROUP); + Assert.assertEquals(configInfo.getPluginType(), PluginType.SERVICE_REGISTRY.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new ServiceRegistryPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(CONFIGURATION_NAME, ERROR_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(ERROR_KEY, DEFAULT_GROUP)); + } +} \ No newline at end of file diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/SpringBootRegistryPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/SpringBootRegistryPluginHandlerTest.java new file mode 100644 index 0000000000..a08038865a --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/SpringBootRegistryPluginHandlerTest.java @@ -0,0 +1,47 @@ +package io.sermant.backend.handler.config.handler; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.PluginConfigHandler; +import io.sermant.backend.handler.config.SpringBootRegistryPluginHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class SpringBootRegistryPluginHandlerTest { + private static final String DEFAULT_APP_NAME = "default"; + + private static final String DEFAULT_ENVIRONMENT_NAME = "prod"; + + private static final String DEFAULT_SERVICE_NAME = "provider"; + + private static final String DEFAULT_GROUP = "app=default&environment=prod&service=provider"; + + private static final String ERROR_GROUP = "app=default&env=prod&service=provider"; + + private static final String ERROR_KEY = "testKey"; + + private static final String CONFIGURATION_NAME = "sermant.plugin.registry"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new SpringBootRegistryPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(CONFIGURATION_NAME, DEFAULT_GROUP); + Assert.assertEquals(configInfo.getAppName(), DEFAULT_APP_NAME); + Assert.assertEquals(configInfo.getEnvironment(), DEFAULT_ENVIRONMENT_NAME); + Assert.assertEquals(configInfo.getServiceName(), DEFAULT_SERVICE_NAME); + Assert.assertEquals(configInfo.getKey(), CONFIGURATION_NAME); + Assert.assertEquals(configInfo.getGroup(), DEFAULT_GROUP); + Assert.assertEquals(configInfo.getPluginType(), PluginType.SPRINGBOOT_REGISTRY.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new SpringBootRegistryPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(CONFIGURATION_NAME, DEFAULT_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(CONFIGURATION_NAME, ERROR_GROUP)); + Assert.assertFalse(handler.verifyConfiguration(ERROR_KEY, DEFAULT_GROUP)); + } +} \ No newline at end of file diff --git a/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/TagTransmissionPluginHandlerTest.java b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/TagTransmissionPluginHandlerTest.java new file mode 100644 index 0000000000..fdb4a2c260 --- /dev/null +++ b/sermant-backend/src/test/java/io/sermant/backend/handler/config/handler/TagTransmissionPluginHandlerTest.java @@ -0,0 +1,38 @@ +package io.sermant.backend.handler.config.handler; + +import io.sermant.backend.entity.config.ConfigInfo; +import io.sermant.backend.entity.config.PluginType; +import io.sermant.backend.handler.config.PluginConfigHandler; +import io.sermant.backend.handler.config.TagTransmissionPluginHandler; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class TagTransmissionPluginHandlerTest { + private static final String CONFIGURATION_GROUP_NAME = "sermant/tag-transmission-plugin"; + + private static final String CONFIGURATION_KEY_NAME = "tag-config"; + + private static final String ERROR_KEY = "testKey"; + + private static final String ERROR_GROUP = "app=default&env=prod&service=provider"; + + @Test + public void parsePluginInfo() { + PluginConfigHandler handler = new TagTransmissionPluginHandler(); + ConfigInfo configInfo = handler.parsePluginInfo(CONFIGURATION_KEY_NAME, CONFIGURATION_GROUP_NAME); + Assert.assertEquals(configInfo.getKey(), CONFIGURATION_KEY_NAME); + Assert.assertEquals(configInfo.getGroup(), CONFIGURATION_GROUP_NAME); + Assert.assertEquals(configInfo.getPluginType(), PluginType.TAG_TRANSMISSION.getPluginName()); + } + + @Test + public void verifyConfiguration() { + PluginConfigHandler handler = new TagTransmissionPluginHandler(); + Assert.assertTrue(handler.verifyConfiguration(CONFIGURATION_KEY_NAME, CONFIGURATION_GROUP_NAME)); + Assert.assertFalse(handler.verifyConfiguration(ERROR_KEY, CONFIGURATION_GROUP_NAME)); + Assert.assertFalse(handler.verifyConfiguration(CONFIGURATION_KEY_NAME, ERROR_GROUP)); + } +} \ No newline at end of file