Skip to content

Commit

Permalink
Merge pull request #1240 from luanwenfei-venus/develop_issue_1235
Browse files Browse the repository at this point in the history
修正插件获取PluginService及PluginConfig的方法
  • Loading branch information
Sherlockhan authored Jul 6, 2023
2 parents df5dad9 + 5680849 commit 3fb63d0
Show file tree
Hide file tree
Showing 54 changed files with 203 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import com.huawei.dynamic.config.init.DynamicConfigInitializer;

import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.Ordered;
Expand All @@ -44,7 +44,7 @@ public class DynamicProperties {
@PostConstruct
public void init() {
ClientMeta.INSTANCE.setServiceName(serviceName);
final DynamicConfigInitializer service = ServiceManager.getService(DynamicConfigInitializer.class);
final DynamicConfigInitializer service = PluginServiceManager.getPluginService(DynamicConfigInitializer.class);
service.doStart();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;

import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -43,7 +43,8 @@ public ExecuteContext before(ExecuteContext context) throws Exception {
public ExecuteContext after(ExecuteContext context) {
Object logStartupInfo = context.getMemberFieldValue("logStartupInfo");
if ((logStartupInfo instanceof Boolean) && (Boolean) logStartupInfo && INIT.compareAndSet(false, true)) {
final FlowControlInitServiceImpl service = ServiceManager.getService(FlowControlInitServiceImpl.class);
final FlowControlInitServiceImpl service = PluginServiceManager.getPluginService(
FlowControlInitServiceImpl.class);
service.doStart();
}
return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.Interceptor;
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;

import io.github.resilience4j.retry.RetryConfig;

Expand Down Expand Up @@ -110,9 +110,9 @@ protected final DubboService chooseDubboService() {
lock.lock();
try {
if (flowControlConfig.getFlowFramework() == FlowFramework.SENTINEL) {
dubboService = ServiceManager.getService(DubboSenService.class);
dubboService = PluginServiceManager.getPluginService(DubboSenService.class);
} else {
dubboService = ServiceManager.getService(DubboRest4jService.class);
dubboService = PluginServiceManager.getPluginService(DubboRest4jService.class);
}
} finally {
lock.unlock();
Expand All @@ -131,9 +131,9 @@ protected final HttpService chooseHttpService() {
lock.lock();
try {
if (flowControlConfig.getFlowFramework() == FlowFramework.SENTINEL) {
httpService = ServiceManager.getService(HttpSenService.class);
httpService = PluginServiceManager.getPluginService(HttpSenService.class);
} else {
httpService = ServiceManager.getService(HttpRest4jService.class);
httpService = PluginServiceManager.getPluginService(HttpRest4jService.class);
}
} finally {
lock.unlock();
Expand All @@ -145,10 +145,10 @@ protected final HttpService chooseHttpService() {
/**
* 创建重试方法
*
* @param obj 增强类
* @param method 目标方法
* @param obj 增强类
* @param method 目标方法
* @param allArguments 方法参数
* @param result 默认结果
* @param result 默认结果
* @return 方法
*/
protected final Supplier<Object> createRetryFunc(Object obj, Method method, Object[] allArguments, Object result) {
Expand All @@ -168,16 +168,16 @@ protected final Supplier<Object> createRetryFunc(Object obj, Method method, Obje
/**
* 进行重试前的判断,若不满足条件直接返回, 防止多调用一次宿主应用接口
*
* @param retry 重试执行器
* @param result 结果
* @param retry 重试执行器
* @param result 结果
* @param throwable 第一次执行异常信息
* @return 是否核对通过
*/
protected final boolean needRetry(io.github.resilience4j.retry.Retry retry, Object result, Throwable throwable) {
final long interval = retry.getRetryConfig().getIntervalBiFunction().apply(1, null);
final RetryConfig retryConfig = retry.getRetryConfig();
boolean isNeedRetry = isMatchResult(result, retryConfig.getResultPredicate()) || isTargetException(throwable,
retryConfig.getExceptionPredicate());
retryConfig.getExceptionPredicate());
if (isNeedRetry) {
try {
// 按照第一次等待时间等待
Expand Down Expand Up @@ -240,7 +240,7 @@ public ExecuteContext onThrow(ExecuteContext context) throws Exception {
*/
protected final boolean canInjectClusterInvoker(String className) {
boolean isClusterLoader =
APACHE_DUBBO_CLUSTER_CLASS_NAME.equals(className) || ALIBABA_DUBBO_CLUSTER_CLASS_NAME.equals(className);
APACHE_DUBBO_CLUSTER_CLASS_NAME.equals(className) || ALIBABA_DUBBO_CLUSTER_CLASS_NAME.equals(className);
return isClusterLoader && !REFUSE_REPLACE_INVOKER.equals(flowControlConfig.getRetryClusterInvoker());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.huaweicloud.loadbalancer.service.RuleConverter;
import com.huaweicloud.sermant.core.common.LoggerFactory;
import com.huaweicloud.sermant.core.plugin.service.PluginService;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.service.dynamicconfig.common.DynamicConfigEvent;
import com.huaweicloud.sermant.core.utils.StringUtils;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class RuleManagerTest {
@Test
public void testResolve() {
Mockito.mockStatic(ServiceManager.class)
.when(() -> ServiceManager.getService(RuleConverter.class))
.when(() -> PluginServiceManager.getPluginService(RuleConverter.class))
.thenReturn(new YamlRuleConverter());
final AtomicBoolean isNotify = new AtomicBoolean();
RuleManager.INSTANCE.addRuleListener((rule, event) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @since 2022-11-02
*/
public class MonitorUtil {
private static final MonitorServiceConfig CONFIG = PluginConfigManager.getConfig(MonitorServiceConfig.class);
private static final MonitorServiceConfig CONFIG = PluginConfigManager.getPluginConfig(MonitorServiceConfig.class);

private MonitorUtil() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.huawei.monitor.service.MetricReportService;

import com.huaweicloud.sermant.core.common.LoggerFactory;
import com.huaweicloud.sermant.core.config.ConfigManager;
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager;
import com.huaweicloud.sermant.core.plugin.service.PluginService;
import com.huaweicloud.sermant.core.utils.StringUtils;

Expand All @@ -42,7 +42,7 @@ public class MetricServiceImpl implements PluginService {
@Override
public void start() {
LOGGER.info("start monitor service");
MonitorServiceConfig config = ConfigManager.getConfig(MonitorServiceConfig.class);
MonitorServiceConfig config = PluginConfigManager.getPluginConfig(MonitorServiceConfig.class);
if (config == null || StringUtils.isEmpty(config.getReportType()) || !config.isEnableStartService()) {
LOGGER.info("monitor switch is close, not start monitor");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.huawei.monitor.service.MetricReportService;

import com.huaweicloud.sermant.core.common.LoggerFactory;
import com.huaweicloud.sermant.core.config.ConfigManager;
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager;
import com.huaweicloud.sermant.core.utils.AesUtil;
import com.huaweicloud.sermant.core.utils.StringUtils;

Expand Down Expand Up @@ -52,7 +52,7 @@ public class PrometheusMetricServiceImpl implements MetricReportService {

@Override
public void startMonitorServer() {
MonitorServiceConfig monitorServiceConfig = ConfigManager.getConfig(MonitorServiceConfig.class);
MonitorServiceConfig monitorServiceConfig = PluginConfigManager.getPluginConfig(MonitorServiceConfig.class);
if (StringUtils.isBlank(monitorServiceConfig.getAddress()) || monitorServiceConfig.getPort() == 0) {
LOGGER.info("monitor config missing address or port");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.huaweicloud.sermant.router.dubbo.handler;

import com.huaweicloud.sermant.core.common.LoggerFactory;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.common.constants.RouterConstant;
import com.huaweicloud.sermant.router.common.utils.CollectionUtils;
import com.huaweicloud.sermant.router.dubbo.service.LaneContextFilterService;
Expand Down Expand Up @@ -45,7 +45,7 @@ public class LaneContextFilterHandler extends AbstractContextFilterHandler {
* 构造方法
*/
public LaneContextFilterHandler() {
laneContextFilterService = ServiceManager.getService(LaneContextFilterService.class);
laneContextFilterService = PluginServiceManager.getPluginService(LaneContextFilterService.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.core.utils.LogUtils;
import com.huaweicloud.sermant.router.dubbo.service.AbstractDirectoryService;

Expand All @@ -35,7 +35,7 @@ public class AbstractDirectoryInterceptor extends AbstractInterceptor {
* 构造方法
*/
public AbstractDirectoryInterceptor() {
abstractDirectoryService = ServiceManager.getService(AbstractDirectoryService.class);
abstractDirectoryService = PluginServiceManager.getPluginService(AbstractDirectoryService.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.dubbo.service.ClusterUtilsService;

/**
Expand All @@ -34,7 +34,7 @@ public class ClusterUtilsInterceptor extends AbstractInterceptor {
* 构造方法
*/
public ClusterUtilsInterceptor() {
clusterUtilsService = ServiceManager.getService(ClusterUtilsService.class);
clusterUtilsService = PluginServiceManager.getPluginService(ClusterUtilsService.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.common.handler.Handler;
import com.huaweicloud.sermant.router.common.utils.CollectionUtils;
import com.huaweicloud.sermant.router.common.utils.ThreadLocalUtils;
Expand Down Expand Up @@ -52,7 +52,7 @@ public ContextFilterInterceptor() {
handlers.add(new LaneContextFilterHandler());
handlers.add(new RouteContextFilterHandler());
handlers.sort(Comparator.comparingInt(Handler::getOrder));
configService = ServiceManager.getService(DubboConfigService.class);
configService = PluginServiceManager.getPluginService(DubboConfigService.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.common.constants.RouterConstant;
import com.huaweicloud.sermant.router.dubbo.cache.DubboCache;
import com.huaweicloud.sermant.router.dubbo.service.DubboConfigService;
Expand All @@ -40,7 +40,7 @@ public class SpringApplicationInterceptor extends AbstractInterceptor {
* 构造方法
*/
public SpringApplicationInterceptor() {
configService = ServiceManager.getService(DubboConfigService.class);
configService = PluginServiceManager.getPluginService(DubboConfigService.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class RuleUtils {

private static final int ONO_HUNDRED = 100;

private static final RouterConfig ROUTER_CONFIG = PluginConfigManager.getConfig(RouterConfig.class);
private static final RouterConfig ROUTER_CONFIG = PluginConfigManager.getPluginConfig(RouterConfig.class);

private RuleUtils() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.huaweicloud.sermant.router.spring.handler;

import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.spring.service.SpringConfigService;

import java.util.List;
Expand All @@ -35,7 +35,7 @@ public abstract class AbstractMappingHandler extends AbstractHandler {
* 构造方法
*/
public AbstractMappingHandler() {
configService = ServiceManager.getService(SpringConfigService.class);
configService = PluginServiceManager.getPluginService(SpringConfigService.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.huaweicloud.sermant.router.spring.handler;

import com.huaweicloud.sermant.core.common.LoggerFactory;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.common.constants.RouterConstant;
import com.huaweicloud.sermant.router.common.utils.CollectionUtils;
import com.huaweicloud.sermant.router.spring.service.LaneService;
Expand All @@ -44,7 +44,7 @@ public class LaneMappingHandler extends AbstractMappingHandler {
* 构造方法
*/
public LaneMappingHandler() {
laneService = ServiceManager.getService(LaneService.class);
laneService = PluginServiceManager.getPluginService(LaneService.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.huaweicloud.sermant.router.spring.handler;

import com.huaweicloud.sermant.core.common.LoggerFactory;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.common.constants.RouterConstant;
import com.huaweicloud.sermant.router.common.utils.CollectionUtils;
import com.huaweicloud.sermant.router.spring.service.LaneService;
Expand All @@ -44,7 +44,7 @@ public class LaneRequestTagHandler extends AbstractRequestTagHandler {
* 构造方法
*/
public LaneRequestTagHandler() {
laneService = ServiceManager.getService(LaneService.class);
laneService = PluginServiceManager.getPluginService(LaneService.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.common.request.RequestData;
import com.huaweicloud.sermant.router.common.request.RequestTag;
import com.huaweicloud.sermant.router.common.utils.CollectionUtils;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class BaseLoadBalancerInterceptor extends AbstractInterceptor {
* 构造方法
*/
public BaseLoadBalancerInterceptor() {
loadBalancerService = ServiceManager.getService(LoadBalancerService.class);
loadBalancerService = PluginServiceManager.getPluginService(LoadBalancerService.class);
canLoadZuul = canLoadZuul();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.core.utils.ReflectUtils;
import com.huaweicloud.sermant.router.common.config.RouterConfig;
import com.huaweicloud.sermant.router.common.constants.RouterConstant;
Expand All @@ -47,7 +47,7 @@ public class DiscoveryManagerInterceptor extends AbstractInterceptor {
* 构造方法
*/
public DiscoveryManagerInterceptor() {
configService = ServiceManager.getService(SpringConfigService.class);
configService = PluginServiceManager.getPluginService(SpringConfigService.class);
routerConfig = PluginConfigManager.getPluginConfig(RouterConfig.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.common.config.RouterConfig;
import com.huaweicloud.sermant.router.common.constants.RouterConstant;
import com.huaweicloud.sermant.router.spring.cache.AppCache;
Expand All @@ -44,7 +44,7 @@ public class EurekaHttpClientInterceptor extends AbstractInterceptor {
*/
public EurekaHttpClientInterceptor() {
routerConfig = PluginConfigManager.getPluginConfig(RouterConfig.class);
configService = ServiceManager.getService(SpringConfigService.class);
configService = PluginServiceManager.getPluginService(SpringConfigService.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager;
import com.huaweicloud.sermant.router.common.request.RequestData;
import com.huaweicloud.sermant.router.common.utils.ThreadLocalUtils;
import com.huaweicloud.sermant.router.spring.service.LoadBalancerService;
Expand All @@ -38,7 +38,7 @@ public class NopInstanceFilterInterceptor extends AbstractInterceptor {
* 构造方法
*/
public NopInstanceFilterInterceptor() {
loadBalancerService = ServiceManager.getService(LoadBalancerService.class);
loadBalancerService = PluginServiceManager.getPluginService(LoadBalancerService.class);
}

@Override
Expand Down
Loading

0 comments on commit 3fb63d0

Please sign in to comment.