全面使用nacos,舍弃zookeeper

pull/1/head
tanghc 5 years ago
parent c7451c84f9
commit d2fab766c4
  1. 2
      doc/docs/files/10110_预发布灰度发布.md
  2. 5
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java
  3. 46
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/EnvGrayFilter.java
  4. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/Orders.java
  5. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java
  6. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/BaseZuulConfiguration.java
  7. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/filter/BaseZuulFilter.java
  8. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/filter/PreEnvGrayFilter.java

@ -42,5 +42,5 @@ pre.domain=openpre.domain.com
参考类: 参考类:
- PreVersionDecisionFilter.java - PreEnvGrayFilter.java
- EnvironmentServerChooser.java - EnvironmentServerChooser.java

@ -1,6 +1,7 @@
package com.gitee.sop.gatewaycommon.gateway.configuration; package com.gitee.sop.gatewaycommon.gateway.configuration;
import com.gitee.sop.gatewaycommon.bean.ApiConfig; import com.gitee.sop.gatewaycommon.bean.ApiConfig;
import com.gitee.sop.gatewaycommon.gateway.filter.EnvGrayFilter;
import com.gitee.sop.gatewaycommon.gateway.filter.GatewayModifyResponseGatewayFilter; import com.gitee.sop.gatewaycommon.gateway.filter.GatewayModifyResponseGatewayFilter;
import com.gitee.sop.gatewaycommon.gateway.filter.LoadBalancerClientExtFilter; import com.gitee.sop.gatewaycommon.gateway.filter.LoadBalancerClientExtFilter;
import com.gitee.sop.gatewaycommon.gateway.filter.ParameterFormatterFilter; import com.gitee.sop.gatewaycommon.gateway.filter.ParameterFormatterFilter;
@ -110,4 +111,8 @@ public class BaseGatewayConfiguration extends AbstractConfiguration {
return new ParameterFormatterFilter(); return new ParameterFormatterFilter();
} }
@Bean
EnvGrayFilter envGrayFilter() {
return new EnvGrayFilter();
}
} }

@ -0,0 +1,46 @@
package com.gitee.sop.gatewaycommon.gateway.filter;
import com.gitee.sop.gatewaycommon.bean.TargetRoute;
import com.gitee.sop.gatewaycommon.gateway.ServerWebExchangeUtil;
import com.gitee.sop.gatewaycommon.manager.EnvGrayManager;
import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext;
import com.gitee.sop.gatewaycommon.param.ApiParam;
import com.gitee.sop.gatewaycommon.param.ParamNames;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
/**
* @author tanghc
*/
public class EnvGrayFilter implements GlobalFilter, Ordered {
@Autowired
private EnvGrayManager envGrayManager;
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ApiParam apiParam = ServerWebExchangeUtil.getApiParam(exchange);
String nameVersion = apiParam.fetchNameVersion();
TargetRoute targetRoute = RouteRepositoryContext.getRouteRepository().get(nameVersion);
if (targetRoute == null) {
return null;
}
String serviceId = targetRoute.getServiceRouteInfo().fetchServiceIdLowerCase();
// 如果服务在灰度阶段,返回一个灰度版本号
String version = envGrayManager.getVersion(serviceId, nameVersion);
if (version != null && envGrayManager.containsKey(serviceId, apiParam.fetchAppKey())) {
ServerWebExchange serverWebExchange = ServerWebExchangeUtil.addHeaders(exchange, httpHeaders -> httpHeaders.set(ParamNames.HEADER_VERSION_NAME, version));
return chain.filter(serverWebExchange);
}
return chain.filter(exchange);
}
@Override
public int getOrder() {
return Orders.ENV_GRAY_FILTER_ORDER;
}
}

@ -18,7 +18,7 @@ public class Orders {
/** 验证拦截器order */ /** 验证拦截器order */
public static final int LIMIT_FILTER_ORDER = PRE_ROUTE_PERMISSION_FILTER_ORDER + 100; public static final int LIMIT_FILTER_ORDER = PRE_ROUTE_PERMISSION_FILTER_ORDER + 100;
/** 决定版本号过滤器 */ /** 灰度发布过滤器 */
public static final int VERSION_DECISION_FILTER_ORDER = LIMIT_FILTER_ORDER + 100; public static final int ENV_GRAY_FILTER_ORDER = LIMIT_FILTER_ORDER + 100;
} }

@ -105,7 +105,7 @@ public class AbstractConfiguration implements ApplicationContextAware, Applicati
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
EnvGrayManager userKeyManager() { EnvGrayManager envGrayManager() {
return ApiConfig.getInstance().getUserKeyManager(); return ApiConfig.getInstance().getUserKeyManager();
} }

@ -12,7 +12,7 @@ import com.gitee.sop.gatewaycommon.zuul.filter.PreHttpServletRequestWrapperFilte
import com.gitee.sop.gatewaycommon.zuul.filter.PreLimitFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PreLimitFilter;
import com.gitee.sop.gatewaycommon.zuul.filter.PreParameterFormatterFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PreParameterFormatterFilter;
import com.gitee.sop.gatewaycommon.zuul.filter.PreValidateFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PreValidateFilter;
import com.gitee.sop.gatewaycommon.zuul.filter.PreVersionDecisionFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PreEnvGrayFilter;
import com.gitee.sop.gatewaycommon.zuul.filter.Servlet30WrapperFilterExt; import com.gitee.sop.gatewaycommon.zuul.filter.Servlet30WrapperFilterExt;
import com.gitee.sop.gatewaycommon.zuul.route.SopRouteLocator; import com.gitee.sop.gatewaycommon.zuul.route.SopRouteLocator;
import com.gitee.sop.gatewaycommon.zuul.route.ZuulRouteCache; import com.gitee.sop.gatewaycommon.zuul.route.ZuulRouteCache;
@ -119,8 +119,8 @@ public class BaseZuulConfiguration extends AbstractConfiguration {
* 决定版本号 * 决定版本号
*/ */
@Bean @Bean
PreVersionDecisionFilter preVersionDecisionFilter() { PreEnvGrayFilter preEnvGrayFilter() {
return new PreVersionDecisionFilter(); return new PreEnvGrayFilter();
} }
/** /**

@ -32,8 +32,8 @@ public abstract class BaseZuulFilter extends ZuulFilter {
/** 限流过滤 */ /** 限流过滤 */
public static final int PRE_LIMIT_FILTER_ORDER = PRE_ROUTE_PERMISSION_FILTER_ORDER + 100; public static final int PRE_LIMIT_FILTER_ORDER = PRE_ROUTE_PERMISSION_FILTER_ORDER + 100;
/** 决定版本号过滤器 */ /** 灰度发布过滤器 */
public static final int PRE_VERSION_DECISION_FILTER_ORDER = PRE_LIMIT_FILTER_ORDER + 100; public static final int PRE_ENV_GRAY_FILTER_ORDER = PRE_LIMIT_FILTER_ORDER + 100;
private Integer filterOrder; private Integer filterOrder;

@ -11,9 +11,11 @@ import com.netflix.zuul.exception.ZuulException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/** /**
* 灰度发布判断改变版本号
*
* @author tanghc * @author tanghc
*/ */
public class PreVersionDecisionFilter extends BaseZuulFilter { public class PreEnvGrayFilter extends BaseZuulFilter {
@Autowired @Autowired
private EnvGrayManager envGrayManager; private EnvGrayManager envGrayManager;
@ -25,7 +27,7 @@ public class PreVersionDecisionFilter extends BaseZuulFilter {
@Override @Override
protected int getFilterOrder() { protected int getFilterOrder() {
return PRE_VERSION_DECISION_FILTER_ORDER; return PRE_ENV_GRAY_FILTER_ORDER;
} }
@Override @Override
Loading…
Cancel
Save