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..6a630504a9 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/common/conf/DynamicConfig.java @@ -0,0 +1,69 @@ +/* + * 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; + +/** + * Dynamically configured configuration classes + * + * @author zhp + * @since 2024-05-21 + */ +@Configuration +@Getter +@Setter +@Component +public class DynamicConfig { + @Value("${dynamic.config.serverAddress}") + private String serverAddress; + + @Value("${dynamic.config.dynamicConfigType}") + private String dynamicConfigType; + + @Value("${dynamic.config.requestTimeout}") + private long requestTimeout; + + @Value("${dynamic.config.connectTimeout}") + private long connectTimeout; + + @Value("${dynamic.config.timeout}") + private int timeout; + + @Value("${dynamic.config.enableAuth}") + private boolean enableAuth; + + @Value("${dynamic.config.userName}") + private String userName; + + @Value("${dynamic.config.password}") + private String password; + + @Value("${dynamic.config.secretKey}") + private String secretKey; + + @Value("${dynamic.config.namespace}") + private String namespace = "default"; + + @Value("${dynamic.config.dynamicConfigEnable}") + private boolean dynamicConfigEnable; +} 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..6c8ffcca87 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/DatabaseWriteProhibitionPluginHandler.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; + +/** + * 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) && 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..147104c16b --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/LoadbalancerPluginHandler.java @@ -0,0 +1,55 @@ +/* + * 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; + +/** + * 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."; + + private static final String PATTERN = "^(app=[^&]*(&environment=[^&]*)?(&service=[^&]*)?)?$"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + ConfigInfo configInfo = super.parsePluginInfo(key, group); + 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(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..5954f6fc95 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/MqConsumeProhibitionPluginHandler.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; + +/** + * 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) && 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..2c63df7af7 --- /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 + */ + public static final String APP_KEY = "app"; + + /** + * The key for the environment + */ + public static final String ENVIRONMENT_KEY = "environment"; + + /** + * The key for the service name + */ + public static final String SERVICE_KEY = "service"; + + /** + * The key for the zone name + */ + public 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..f150282ae9 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/RemovalPluginHandler.java @@ -0,0 +1,60 @@ +/* + * 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; + +/** + * 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"; + + private static final String PATTERN = "^(app=[^&]*(&environment=[^&]*)?(&service=[^&]*)?)?$"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + Map map = parseGroup(group); + ConfigInfo configInfo = new ConfigInfo(); + configInfo.setAppName(map.get(APP_KEY)); + 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(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..fa69808ff6 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/RouterPluginHandler.java @@ -0,0 +1,64 @@ +/* + * 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; + +/** + * 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."; + + private static final String PATTERN = "^(app=[^&]*(&environment=[^&]*)?(&service=[^&]*)?)?$"; + + @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) && 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(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..2b2fa0d5a4 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/ServiceRegistryPluginHandler.java @@ -0,0 +1,52 @@ +/* + * 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; + +/** + * Service Registry plugin handler + * + * @author zhp + * @since 2024-05-16 + */ +public class ServiceRegistryPluginHandler extends PluginConfigHandler { + private static final String CONFIGURATION_NAME = "sermant.agent.registry"; + + private static final String PATTERN = "^(app=[^&]*(&environment=[^&]*)?(&service=[^&]*)?)?$"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + ConfigInfo configInfo = super.parsePluginInfo(key,group); + 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(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..e35dd25bd8 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/SpringBootRegistryPluginHandler.java @@ -0,0 +1,52 @@ +/* + * 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; + +/** + * 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"; + + private static final String PATTERN = "^(app=[^&]*(&environment=[^&]*)?(&service=[^&]*)?)?$"; + + @Override + public ConfigInfo parsePluginInfo(String key, String group) { + ConfigInfo configInfo = super.parsePluginInfo(key,group); + 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(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..b8d0aaf709 --- /dev/null +++ b/sermant-backend/src/main/java/io/sermant/backend/handler/config/TagTransmissionPluginHandler.java @@ -0,0 +1,51 @@ +/* + * 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; + +/** + * 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.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..8150221ff3 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=false +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..c380949082 --- /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&env=prod&zone=gz"; + + 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