pull/1/head
tanghc 5 years ago
parent bbd4e55c6a
commit 90fdbbccf2
  1. 8
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/LimitApi.java
  2. 1
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitParam.java
  3. 4
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/RouteVO.java
  4. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/RouteDefinition.java
  5. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ServiceRouteInfo.java
  6. 4
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RouteService.java
  7. 2
      sop-admin/sop-admin-server/src/main/resources/public/index.html
  8. 1
      sop-admin/sop-admin-server/src/main/resources/public/static/js/chunk-9b31c83a.355cc725.js
  9. 1
      sop-admin/sop-admin-server/src/main/resources/public/static/js/chunk-9b31c83a.50cacf29.js
  10. 12
      sop-admin/sop-admin-vue/src/views/service/route.vue
  11. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/AbstractTargetRoute.java
  12. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteDefinition.java
  13. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ServiceRouteInfo.java
  14. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/TargetRoute.java
  15. 7
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteCache.java
  16. 13
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java
  17. 7
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayTargetRoute.java
  18. 8
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/BaseRouteCache.java
  19. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/BaseParamBuilder.java
  20. 30
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java
  21. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/ApiValidator.java
  22. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulRouteCache.java
  23. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulTargetRoute.java
  24. 4
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceApiInfo.java
  25. 16
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceRouteInfoBuilder.java
  26. 2
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/RouteDefinition.java
  27. 2
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/ServiceRouteInfo.java
  28. 10
      sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbRouteConfigManager.java

@ -9,7 +9,7 @@ import com.gitee.fastmybatis.core.query.Query;
import com.gitee.sop.adminserver.api.service.param.LimitParam;
import com.gitee.sop.adminserver.api.service.param.RouteSearchParam;
import com.gitee.sop.adminserver.api.service.result.LimitVO;
import com.gitee.sop.adminserver.bean.GatewayRouteDefinition;
import com.gitee.sop.adminserver.bean.RouteDefinition;
import com.gitee.sop.adminserver.bean.RouteConfigDto;
import com.gitee.sop.adminserver.common.BizException;
import com.gitee.sop.adminserver.common.LimitEnum;
@ -51,7 +51,7 @@ public class LimitApi {
@Api(name = "route.limit.list")
@ApiDocMethod(description = "限流列表", elementClass = LimitVO.class)
List<LimitVO> listLimit(RouteSearchParam param) throws Exception {
List<GatewayRouteDefinition> routeDefinitionList = routeService.getRouteDefinitionList(param);
List<RouteDefinition> routeDefinitionList = routeService.getRouteDefinitionList(param);
if (CollectionUtils.isEmpty(routeDefinitionList)) {
return Collections.emptyList();
}
@ -74,10 +74,10 @@ public class LimitApi {
return gatewayRouteDefinitions;
}
private List<String> getRouteIdList(List<GatewayRouteDefinition> routeDefinitionList) {
private List<String> getRouteIdList(List<RouteDefinition> routeDefinitionList) {
return routeDefinitionList
.stream()
.map(GatewayRouteDefinition::getId)
.map(RouteDefinition::getId)
.collect(Collectors.toList());
}

@ -1,7 +1,6 @@
package com.gitee.sop.adminserver.api.service.param;
import com.gitee.easyopen.doc.annotation.ApiDocField;
import com.gitee.sop.adminserver.bean.GatewayRouteDefinition;
import lombok.Data;
import javax.validation.constraints.NotBlank;

@ -1,7 +1,7 @@
package com.gitee.sop.adminserver.api.service.result;
import com.gitee.sop.adminserver.api.isv.result.RoleVO;
import com.gitee.sop.adminserver.bean.GatewayRouteDefinition;
import com.gitee.sop.adminserver.bean.RouteDefinition;
import lombok.Getter;
import lombok.Setter;
@ -12,6 +12,6 @@ import java.util.List;
*/
@Getter
@Setter
public class RouteVO extends GatewayRouteDefinition {
public class RouteVO extends RouteDefinition {
private List<RoleVO> roles;
}

@ -11,7 +11,7 @@ import java.util.List;
* @author tanghc
*/
@Data
public class GatewayRouteDefinition {
public class RouteDefinition {
/**
* 路由的Id
*/

@ -23,7 +23,7 @@ public class ServiceRouteInfo {
private String description;
@JSONField(serialize = false)
private List<GatewayRouteDefinition> routeDefinitionList;
private List<RouteDefinition> routeDefinitionList;
/** 是否是自定义服务,1:是,0:否 */
private int custom;

@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.ConfigService;
import com.gitee.sop.adminserver.api.service.param.RouteSearchParam;
import com.gitee.sop.adminserver.bean.GatewayRouteDefinition;
import com.gitee.sop.adminserver.bean.RouteDefinition;
import com.gitee.sop.adminserver.bean.NacosConfigs;
import com.gitee.sop.adminserver.bean.ServiceRouteInfo;
import org.apache.commons.lang.StringUtils;
@ -24,7 +24,7 @@ public class RouteService {
@NacosInjected
private ConfigService configService;
public List<GatewayRouteDefinition> getRouteDefinitionList(RouteSearchParam param) throws Exception {
public List<RouteDefinition> getRouteDefinitionList(RouteSearchParam param) throws Exception {
String serviceId = param.getServiceId();
if (StringUtils.isBlank(serviceId)) {
return Collections.emptyList();

@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=favicon.ico><title>SOP Admin</title><link href=static/css/chunk-elementUI.81cf475c.css rel=stylesheet><link href=static/css/chunk-libs.3dfb7769.css rel=stylesheet><link href=static/css/app.4f0872ef.css rel=stylesheet></head><body><noscript><strong>We're sorry but SOP Admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script>(function(e){function n(n){for(var r,c,o=n[0],f=n[1],i=n[2],l=0,h=[];l<o.length;l++)c=o[l],u[c]&&h.push(u[c][0]),u[c]=0;for(r in f)Object.prototype.hasOwnProperty.call(f,r)&&(e[r]=f[r]);d&&d(n);while(h.length)h.shift()();return a.push.apply(a,i||[]),t()}function t(){for(var e,n=0;n<a.length;n++){for(var t=a[n],r=!0,c=1;c<t.length;c++){var o=t[c];0!==u[o]&&(r=!1)}r&&(a.splice(n--,1),e=f(f.s=t[0]))}return e}var r={},c={runtime:0},u={runtime:0},a=[];function o(e){return f.p+"static/js/"+({}[e]||e)+"."+{"chunk-238a81e9":"5955f13d","chunk-25908fca":"b2f0b665","chunk-2d2085ef":"7c741493","chunk-2d221c34":"c8ef105a","chunk-37401378":"4e39ec9b","chunk-510c5a69":"93406082","chunk-6f78c9fe":"f1ed64fa","chunk-73b2dcec":"14f248eb","chunk-9b31c83a":"355cc725","chunk-9f479afe":"c1cbb02b","chunk-ea2e58a4":"f3f85b0e"}[e]+".js"}function f(n){if(r[n])return r[n].exports;var t=r[n]={i:n,l:!1,exports:{}};return e[n].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.e=function(e){var n=[],t={"chunk-238a81e9":1,"chunk-25908fca":1,"chunk-37401378":1,"chunk-510c5a69":1,"chunk-73b2dcec":1,"chunk-9b31c83a":1,"chunk-ea2e58a4":1};c[e]?n.push(c[e]):0!==c[e]&&t[e]&&n.push(c[e]=new Promise(function(n,t){for(var r="static/css/"+({}[e]||e)+"."+{"chunk-238a81e9":"e8e2beee","chunk-25908fca":"89ab33e8","chunk-2d2085ef":"31d6cfe0","chunk-2d221c34":"31d6cfe0","chunk-37401378":"a43114f3","chunk-510c5a69":"5e48e29a","chunk-6f78c9fe":"31d6cfe0","chunk-73b2dcec":"99cf6327","chunk-9b31c83a":"3b12267b","chunk-9f479afe":"31d6cfe0","chunk-ea2e58a4":"d10599db"}[e]+".css",u=f.p+r,a=document.getElementsByTagName("link"),o=0;o<a.length;o++){var i=a[o],l=i.getAttribute("data-href")||i.getAttribute("href");if("stylesheet"===i.rel&&(l===r||l===u))return n()}var h=document.getElementsByTagName("style");for(o=0;o<h.length;o++){i=h[o],l=i.getAttribute("data-href");if(l===r||l===u)return n()}var d=document.createElement("link");d.rel="stylesheet",d.type="text/css",d.onload=n,d.onerror=function(n){var r=n&&n.target&&n.target.src||u,a=new Error("Loading CSS chunk "+e+" failed.\n("+r+")");a.code="CSS_CHUNK_LOAD_FAILED",a.request=r,delete c[e],d.parentNode.removeChild(d),t(a)},d.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(d)}).then(function(){c[e]=0}));var r=u[e];if(0!==r)if(r)n.push(r[2]);else{var a=new Promise(function(n,t){r=u[e]=[n,t]});n.push(r[2]=a);var i,l=document.createElement("script");l.charset="utf-8",l.timeout=120,f.nc&&l.setAttribute("nonce",f.nc),l.src=o(e),i=function(n){l.onerror=l.onload=null,clearTimeout(h);var t=u[e];if(0!==t){if(t){var r=n&&("load"===n.type?"missing":n.type),c=n&&n.target&&n.target.src,a=new Error("Loading chunk "+e+" failed.\n("+r+": "+c+")");a.type=r,a.request=c,t[1](a)}u[e]=void 0}};var h=setTimeout(function(){i({type:"timeout",target:l})},12e4);l.onerror=l.onload=i,document.head.appendChild(l)}return Promise.all(n)},f.m=e,f.c=r,f.d=function(e,n,t){f.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,n){if(1&n&&(e=f(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)f.d(t,r,function(n){return e[n]}.bind(null,r));return t},f.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return f.d(n,"a",n),n},f.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},f.p="",f.oe=function(e){throw console.error(e),e};var i=window["webpackJsonp"]=window["webpackJsonp"]||[],l=i.push.bind(i);i.push=n,i=i.slice();for(var h=0;h<i.length;h++)n(i[h]);var d=l;t()})([]);</script><script src=static/js/chunk-elementUI.8ebdfbab.js></script><script src=static/js/chunk-libs.9cf9cc40.js></script><script src=static/js/app.4f45e42d.js></script></body></html>
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=favicon.ico><title>SOP Admin</title><link href=static/css/chunk-elementUI.81cf475c.css rel=stylesheet><link href=static/css/chunk-libs.3dfb7769.css rel=stylesheet><link href=static/css/app.4f0872ef.css rel=stylesheet></head><body><noscript><strong>We're sorry but SOP Admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script>(function(e){function n(n){for(var r,c,o=n[0],f=n[1],i=n[2],l=0,h=[];l<o.length;l++)c=o[l],u[c]&&h.push(u[c][0]),u[c]=0;for(r in f)Object.prototype.hasOwnProperty.call(f,r)&&(e[r]=f[r]);d&&d(n);while(h.length)h.shift()();return a.push.apply(a,i||[]),t()}function t(){for(var e,n=0;n<a.length;n++){for(var t=a[n],r=!0,c=1;c<t.length;c++){var o=t[c];0!==u[o]&&(r=!1)}r&&(a.splice(n--,1),e=f(f.s=t[0]))}return e}var r={},c={runtime:0},u={runtime:0},a=[];function o(e){return f.p+"static/js/"+({}[e]||e)+"."+{"chunk-238a81e9":"5955f13d","chunk-25908fca":"b2f0b665","chunk-2d2085ef":"7c741493","chunk-2d221c34":"c8ef105a","chunk-37401378":"4e39ec9b","chunk-510c5a69":"93406082","chunk-6f78c9fe":"f1ed64fa","chunk-73b2dcec":"14f248eb","chunk-9b31c83a":"50cacf29","chunk-9f479afe":"c1cbb02b","chunk-ea2e58a4":"f3f85b0e"}[e]+".js"}function f(n){if(r[n])return r[n].exports;var t=r[n]={i:n,l:!1,exports:{}};return e[n].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.e=function(e){var n=[],t={"chunk-238a81e9":1,"chunk-25908fca":1,"chunk-37401378":1,"chunk-510c5a69":1,"chunk-73b2dcec":1,"chunk-9b31c83a":1,"chunk-ea2e58a4":1};c[e]?n.push(c[e]):0!==c[e]&&t[e]&&n.push(c[e]=new Promise(function(n,t){for(var r="static/css/"+({}[e]||e)+"."+{"chunk-238a81e9":"e8e2beee","chunk-25908fca":"89ab33e8","chunk-2d2085ef":"31d6cfe0","chunk-2d221c34":"31d6cfe0","chunk-37401378":"a43114f3","chunk-510c5a69":"5e48e29a","chunk-6f78c9fe":"31d6cfe0","chunk-73b2dcec":"99cf6327","chunk-9b31c83a":"3b12267b","chunk-9f479afe":"31d6cfe0","chunk-ea2e58a4":"d10599db"}[e]+".css",u=f.p+r,a=document.getElementsByTagName("link"),o=0;o<a.length;o++){var i=a[o],l=i.getAttribute("data-href")||i.getAttribute("href");if("stylesheet"===i.rel&&(l===r||l===u))return n()}var h=document.getElementsByTagName("style");for(o=0;o<h.length;o++){i=h[o],l=i.getAttribute("data-href");if(l===r||l===u)return n()}var d=document.createElement("link");d.rel="stylesheet",d.type="text/css",d.onload=n,d.onerror=function(n){var r=n&&n.target&&n.target.src||u,a=new Error("Loading CSS chunk "+e+" failed.\n("+r+")");a.code="CSS_CHUNK_LOAD_FAILED",a.request=r,delete c[e],d.parentNode.removeChild(d),t(a)},d.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(d)}).then(function(){c[e]=0}));var r=u[e];if(0!==r)if(r)n.push(r[2]);else{var a=new Promise(function(n,t){r=u[e]=[n,t]});n.push(r[2]=a);var i,l=document.createElement("script");l.charset="utf-8",l.timeout=120,f.nc&&l.setAttribute("nonce",f.nc),l.src=o(e),i=function(n){l.onerror=l.onload=null,clearTimeout(h);var t=u[e];if(0!==t){if(t){var r=n&&("load"===n.type?"missing":n.type),c=n&&n.target&&n.target.src,a=new Error("Loading chunk "+e+" failed.\n("+r+": "+c+")");a.type=r,a.request=c,t[1](a)}u[e]=void 0}};var h=setTimeout(function(){i({type:"timeout",target:l})},12e4);l.onerror=l.onload=i,document.head.appendChild(l)}return Promise.all(n)},f.m=e,f.c=r,f.d=function(e,n,t){f.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,n){if(1&n&&(e=f(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)f.d(t,r,function(n){return e[n]}.bind(null,r));return t},f.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return f.d(n,"a",n),n},f.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},f.p="",f.oe=function(e){throw console.error(e),e};var i=window["webpackJsonp"]=window["webpackJsonp"]||[],l=i.push.bind(i);i.push=n,i=i.slice();for(var h=0;h<i.length;h++)n(i[h]);var d=l;t()})([]);</script><script src=static/js/chunk-elementUI.8ebdfbab.js></script><script src=static/js/chunk-libs.9cf9cc40.js></script><script src=static/js/app.4f45e42d.js></script></body></html>

@ -84,19 +84,10 @@
<el-table-column
prop="name"
label="接口名 (版本号)"
width="200"
>
<template slot-scope="scope">
{{ scope.row.name + (scope.row.version ? ' (' + scope.row.version + ')' : '') }}
</template>
</el-table-column>
<el-table-column
prop="uri"
label="LoadBalance"
width="350"
>
<template slot-scope="scope">
{{ scope.row.uri + scope.row.path }}
{{ scope.row.name + (scope.row.version ? ' (' + scope.row.version + ')' : '') }}
</template>
</el-table-column>
<el-table-column
@ -141,7 +132,6 @@
</el-table-column>
<el-table-column
label="操作"
fixed="right"
width="100"
>
<template slot-scope="scope">

@ -6,10 +6,10 @@ package com.gitee.sop.gatewaycommon.bean;
public abstract class AbstractTargetRoute<T> implements TargetRoute<T> {
private ServiceRouteInfo serviceRouteInfo;
private GatewayRouteDefinition routeDefinition;
private RouteDefinition routeDefinition;
private T targetRoute;
public AbstractTargetRoute(ServiceRouteInfo serviceRouteInfo, GatewayRouteDefinition routeDefinition, T targetRoute) {
public AbstractTargetRoute(ServiceRouteInfo serviceRouteInfo, RouteDefinition routeDefinition, T targetRoute) {
this.serviceRouteInfo = serviceRouteInfo;
this.routeDefinition = routeDefinition;
this.targetRoute = targetRoute;
@ -21,7 +21,7 @@ public abstract class AbstractTargetRoute<T> implements TargetRoute<T> {
}
@Override
public GatewayRouteDefinition getRouteDefinition() {
public RouteDefinition getRouteDefinition() {
return routeDefinition;
}

@ -9,7 +9,7 @@ import java.util.List;
* @author tanghc
*/
@Data
public class GatewayRouteDefinition {
public class RouteDefinition {
/**
* 路由的Id接口名+版本号确保此id全局唯一
*/

@ -30,7 +30,7 @@ public class ServiceRouteInfo {
*/
private String md5;
private List<GatewayRouteDefinition> routeDefinitionList;
private List<RouteDefinition> routeDefinitionList;
public String fetchServiceIdLowerCase() {
return serviceId.toLowerCase();

@ -17,7 +17,7 @@ public interface TargetRoute<T> {
*
* @return 返回微服务路由对象
*/
GatewayRouteDefinition getRouteDefinition();
RouteDefinition getRouteDefinition();
/**
* 返回网关路由对象

@ -2,14 +2,13 @@ package com.gitee.sop.gatewaycommon.gateway.route;
import com.gitee.sop.gatewaycommon.bean.GatewayFilterDefinition;
import com.gitee.sop.gatewaycommon.bean.GatewayPredicateDefinition;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import com.gitee.sop.gatewaycommon.manager.BaseRouteCache;
import com.gitee.sop.gatewaycommon.manager.RouteRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.cloud.gateway.filter.FilterDefinition;
import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;
import org.springframework.cloud.gateway.route.RouteDefinition;
import java.net.URI;
import java.util.ArrayList;
@ -26,8 +25,8 @@ public class GatewayRouteCache extends BaseRouteCache<GatewayTargetRoute> {
}
@Override
protected GatewayTargetRoute buildRouteDefinition(ServiceRouteInfo serviceRouteInfo, GatewayRouteDefinition gatewayRouteDefinition) {
RouteDefinition routeDefinition = new RouteDefinition();
protected GatewayTargetRoute buildRouteDefinition(ServiceRouteInfo serviceRouteInfo, RouteDefinition gatewayRouteDefinition) {
org.springframework.cloud.gateway.route.RouteDefinition routeDefinition = new org.springframework.cloud.gateway.route.RouteDefinition();
routeDefinition.setId(gatewayRouteDefinition.getId());
routeDefinition.setUri(URI.create(gatewayRouteDefinition.getUri() + "#" + gatewayRouteDefinition.getPath()));
routeDefinition.setOrder(gatewayRouteDefinition.getOrder());

@ -1,13 +1,12 @@
package com.gitee.sop.gatewaycommon.gateway.route;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.TargetRoute;
import com.gitee.sop.gatewaycommon.manager.RouteRepository;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.gateway.event.PredicateArgsEvent;
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionRepository;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
@ -38,8 +37,8 @@ public class GatewayRouteRepository implements ApplicationEventPublisherAware,
private ApplicationEventPublisher publisher;
@Override
public Flux<RouteDefinition> getRouteDefinitions() {
List<RouteDefinition> list = routes.values().parallelStream()
public Flux<org.springframework.cloud.gateway.route.RouteDefinition> getRouteDefinitions() {
List<org.springframework.cloud.gateway.route.RouteDefinition> list = routes.values().parallelStream()
.map(TargetRoute::getTargetRouteDefinition)
.filter(routeDefinition -> !routeDefinition.getId().contains("_first.route_"))
.collect(Collectors.toList());
@ -47,7 +46,7 @@ public class GatewayRouteRepository implements ApplicationEventPublisherAware,
}
@Override
public Mono<Void> save(Mono<RouteDefinition> route) {
public Mono<Void> save(Mono<org.springframework.cloud.gateway.route.RouteDefinition> route) {
return null;
}
@ -77,7 +76,7 @@ public class GatewayRouteRepository implements ApplicationEventPublisherAware,
*/
@Override
public String add(GatewayTargetRoute targetRoute) {
GatewayRouteDefinition baseRouteDefinition = targetRoute.getRouteDefinition();
RouteDefinition baseRouteDefinition = targetRoute.getRouteDefinition();
routes.put(baseRouteDefinition.getId(), targetRoute);
this.publisher.publishEvent(new RefreshRoutesEvent(this));
return "success";
@ -85,7 +84,7 @@ public class GatewayRouteRepository implements ApplicationEventPublisherAware,
@Override
public void update(GatewayTargetRoute targetRoute) {
GatewayRouteDefinition baseRouteDefinition = targetRoute.getRouteDefinition();
RouteDefinition baseRouteDefinition = targetRoute.getRouteDefinition();
routes.put(baseRouteDefinition.getId(), targetRoute);
}

@ -1,16 +1,15 @@
package com.gitee.sop.gatewaycommon.gateway.route;
import com.gitee.sop.gatewaycommon.bean.AbstractTargetRoute;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import org.springframework.cloud.gateway.route.RouteDefinition;
/**
* @author tanghc
*/
public class GatewayTargetRoute extends AbstractTargetRoute<RouteDefinition> {
public class GatewayTargetRoute extends AbstractTargetRoute<org.springframework.cloud.gateway.route.RouteDefinition> {
public GatewayTargetRoute(ServiceRouteInfo serviceRouteInfo, GatewayRouteDefinition routeDefinition, RouteDefinition targetRoute) {
public GatewayTargetRoute(ServiceRouteInfo serviceRouteInfo, RouteDefinition routeDefinition, org.springframework.cloud.gateway.route.RouteDefinition targetRoute) {
super(serviceRouteInfo, routeDefinition, targetRoute);
}
}

@ -1,6 +1,6 @@
package com.gitee.sop.gatewaycommon.manager;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import com.gitee.sop.gatewaycommon.bean.TargetRoute;
import lombok.extern.slf4j.Slf4j;
@ -31,7 +31,7 @@ public abstract class BaseRouteCache<T extends TargetRoute> implements RouteLoad
* @param gatewayRouteDefinition 路由对象
* @return 返回目标路由对象
*/
protected abstract T buildRouteDefinition(ServiceRouteInfo serviceRouteInfo, GatewayRouteDefinition gatewayRouteDefinition);
protected abstract T buildRouteDefinition(ServiceRouteInfo serviceRouteInfo, RouteDefinition gatewayRouteDefinition);
public BaseRouteCache(RouteRepository<T> routeRepository) {
this.routeRepository = routeRepository;
@ -47,8 +47,8 @@ public abstract class BaseRouteCache<T extends TargetRoute> implements RouteLoad
return;
}
serviceIdMd5Map.put(serviceId, newMd5);
List<GatewayRouteDefinition> routeDefinitionList = serviceRouteInfo.getRouteDefinitionList();
for (GatewayRouteDefinition gatewayRouteDefinition : routeDefinitionList) {
List<RouteDefinition> routeDefinitionList = serviceRouteInfo.getRouteDefinitionList();
for (RouteDefinition gatewayRouteDefinition : routeDefinitionList) {
T routeDefinition = this.buildRouteDefinition(serviceRouteInfo, gatewayRouteDefinition);
routeRepository.add(routeDefinition);
}

@ -1,6 +1,6 @@
package com.gitee.sop.gatewaycommon.param;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.TargetRoute;
import com.gitee.sop.gatewaycommon.manager.RouteRepository;
import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext;
@ -64,8 +64,8 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
String nameVersion = Optional.ofNullable(apiParam.fetchNameVersion()).orElse(String.valueOf(System.currentTimeMillis()));
TargetRoute targetRoute = routeRepository.get(nameVersion);
Integer ignoreValidate = Optional.ofNullable(targetRoute)
.map(t -> t.getRouteDefinition())
.map(GatewayRouteDefinition::getIgnoreValidate)
.map(TargetRoute::getRouteDefinition)
.map(RouteDefinition::getIgnoreValidate)
// 默认不忽略
.orElse(BooleanUtils.toInteger(false));
apiParam.setIgnoreValidate(BooleanUtils.toBoolean(ignoreValidate));

@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.gitee.sop.gatewaycommon.bean.ApiConfig;
import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.bean.ErrorDefinition;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.Isv;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import com.gitee.sop.gatewaycommon.bean.SopConstants;
@ -39,18 +39,18 @@ public abstract class BaseExecutorAdapter<T, R> implements ResultExecutor<T, R>
private static final ErrorMeta ISP_BIZ_ERROR = ErrorEnum.BIZ_ERROR.getErrorMeta();
private static final ErrorMeta ISV_MISSING_METHOD_META = ErrorEnum.ISV_MISSING_METHOD.getErrorMeta();
public static final String GATEWAY_CODE_NAME = "code";
public static final String GATEWAY_MSG_NAME = "msg";
public static final String ARRAY_START = "[";
public static final String ARRAY_END = "]";
public static final String ROOT_JSON = "{'items':%s}".replace("'", "\"");
public static final String ERROR_METHOD = "error";
private static final String GATEWAY_CODE_NAME = "code";
private static final String GATEWAY_MSG_NAME = "msg";
private static final String ARRAY_START = "[";
private static final String ARRAY_END = "]";
private static final String ROOT_JSON = "{'items':%s}".replace("'", "\"");
private static final String ERROR_METHOD = "error";
/**
* 获取业务方约定的返回码
*
* @param t
* @param t request
* @return 返回返回码
*/
public abstract int getResponseStatus(T t);
@ -58,15 +58,15 @@ public abstract class BaseExecutorAdapter<T, R> implements ResultExecutor<T, R>
/**
* 获取微服务端的错误信息
*
* @param t
* @return
* @param t request
* @return 返回错误信息
*/
public abstract String getResponseErrorMessage(T t);
/**
* 返回Api参数
*
* @param t
* @param t request
* @return 返回api参数
*/
public abstract Map<String, Object> getApiParam(T t);
@ -139,7 +139,7 @@ public abstract class BaseExecutorAdapter<T, R> implements ResultExecutor<T, R>
return defaultSetting;
}
ApiInfo apiInfo = this.getApiInfo(request);
GatewayRouteDefinition baseRouteDefinition = apiInfo.gatewayRouteDefinition;
RouteDefinition baseRouteDefinition = apiInfo.gatewayRouteDefinition;
return Optional.ofNullable(baseRouteDefinition)
.map(routeDefinition -> {
int mergeResult = baseRouteDefinition.getMergeResult();
@ -160,8 +160,8 @@ public abstract class BaseExecutorAdapter<T, R> implements ResultExecutor<T, R>
.map(ServiceRouteInfo::getServiceId)
.orElse(SopConstants.UNKNOWN_SERVICE);
GatewayRouteDefinition baseRouteDefinition = Optional.ofNullable(targetRoute)
.map(route -> route.getRouteDefinition())
RouteDefinition baseRouteDefinition = Optional.ofNullable(targetRoute)
.map(TargetRoute::getRouteDefinition)
.orElse(null);
ApiInfo apiInfo = new ApiInfo();
@ -276,7 +276,7 @@ public abstract class BaseExecutorAdapter<T, R> implements ResultExecutor<T, R>
private String name;
private String version;
private String serviceId;
private GatewayRouteDefinition gatewayRouteDefinition;
private RouteDefinition gatewayRouteDefinition;
}
enum ErrorType {

@ -2,7 +2,7 @@ package com.gitee.sop.gatewaycommon.validate;
import com.gitee.sop.gatewaycommon.bean.ApiConfig;
import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.Isv;
import com.gitee.sop.gatewaycommon.bean.RouteConfig;
import com.gitee.sop.gatewaycommon.bean.TargetRoute;
@ -215,7 +215,7 @@ public class ApiValidator implements Validator {
protected void checkPermission(ApiParam apiParam) {
String routeId = apiParam.fetchNameVersion();
TargetRoute targetRoute = RouteRepositoryContext.getRouteRepository().get(routeId);
GatewayRouteDefinition routeDefinition = targetRoute.getRouteDefinition();
RouteDefinition routeDefinition = targetRoute.getRouteDefinition();
boolean needCheckPermission = BooleanUtils.toBoolean(routeDefinition.getPermission());
if (needCheckPermission) {
String appKey = apiParam.fetchAppKey();

@ -1,6 +1,6 @@
package com.gitee.sop.gatewaycommon.zuul.route;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import com.gitee.sop.gatewaycommon.manager.BaseRouteCache;
import com.gitee.sop.gatewaycommon.manager.RouteRepository;
@ -20,7 +20,7 @@ public class ZuulRouteCache extends BaseRouteCache<ZuulTargetRoute> {
}
@Override
protected ZuulTargetRoute buildRouteDefinition(ServiceRouteInfo serviceRouteInfo, GatewayRouteDefinition gatewayRouteDefinition) {
protected ZuulTargetRoute buildRouteDefinition(ServiceRouteInfo serviceRouteInfo, RouteDefinition gatewayRouteDefinition) {
Route route = new Route(
gatewayRouteDefinition.getId()
, gatewayRouteDefinition.getPath()

@ -1,7 +1,7 @@
package com.gitee.sop.gatewaycommon.zuul.route;
import com.gitee.sop.gatewaycommon.bean.AbstractTargetRoute;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import lombok.Getter;
import org.springframework.cloud.netflix.zuul.filters.Route;
@ -12,7 +12,7 @@ import org.springframework.cloud.netflix.zuul.filters.Route;
@Getter
public class ZuulTargetRoute extends AbstractTargetRoute<Route> {
public ZuulTargetRoute(ServiceRouteInfo serviceRouteInfo, GatewayRouteDefinition routeDefinition, Route targetRoute) {
public ZuulTargetRoute(ServiceRouteInfo serviceRouteInfo, RouteDefinition routeDefinition, Route targetRoute) {
super(serviceRouteInfo, routeDefinition, targetRoute);
}
}

@ -1,6 +1,6 @@
package com.gitee.sop.servercommon.bean;
import com.gitee.sop.servercommon.route.GatewayRouteDefinition;
import com.gitee.sop.servercommon.route.RouteDefinition;
import lombok.Data;
import java.util.List;
@ -12,7 +12,7 @@ import java.util.List;
public class ServiceApiInfo {
private String serviceId;
private List<ApiMeta> apis;
private List<GatewayRouteDefinition> routeDefinitionList;
private List<RouteDefinition> routeDefinitionList;
@Data
public static class ApiMeta {

@ -3,7 +3,7 @@ package com.gitee.sop.servercommon.manager;
import com.alibaba.fastjson.JSON;
import com.gitee.sop.servercommon.bean.ServiceApiInfo;
import com.gitee.sop.servercommon.route.GatewayPredicateDefinition;
import com.gitee.sop.servercommon.route.GatewayRouteDefinition;
import com.gitee.sop.servercommon.route.RouteDefinition;
import com.gitee.sop.servercommon.route.ServiceRouteInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
@ -59,10 +59,10 @@ public class ServiceRouteInfoBuilder {
*/
protected ServiceRouteInfo buildServiceGatewayInfo(ServiceApiInfo serviceApiInfo) {
List<ServiceApiInfo.ApiMeta> apis = serviceApiInfo.getApis();
List<GatewayRouteDefinition> routeDefinitionList = new ArrayList<>(apis.size());
List<RouteDefinition> routeDefinitionList = new ArrayList<>(apis.size());
routeDefinitionList.add(this.buildReadBodyRouteDefinition(serviceApiInfo));
for (ServiceApiInfo.ApiMeta apiMeta : apis) {
GatewayRouteDefinition gatewayRouteDefinition = this.buildGatewayRouteDefinition(serviceApiInfo, apiMeta);
RouteDefinition gatewayRouteDefinition = this.buildGatewayRouteDefinition(serviceApiInfo, apiMeta);
routeDefinitionList.add(gatewayRouteDefinition);
}
ServiceRouteInfo serviceRouteInfo = new ServiceRouteInfo();
@ -79,7 +79,7 @@ public class ServiceRouteInfoBuilder {
* @param routeDefinitionList 路由列表
* @return 返回MD5
*/
protected String buildMd5(List<GatewayRouteDefinition> routeDefinitionList) {
protected String buildMd5(List<RouteDefinition> routeDefinitionList) {
List<String> routeIdList = routeDefinitionList.stream()
.map(JSON::toJSONString)
.sorted()
@ -88,8 +88,8 @@ public class ServiceRouteInfoBuilder {
return DigestUtils.md5DigestAsHex(md5Source.getBytes(StandardCharsets.UTF_8));
}
protected GatewayRouteDefinition buildGatewayRouteDefinition(ServiceApiInfo serviceApiInfo, ServiceApiInfo.ApiMeta apiMeta) {
GatewayRouteDefinition gatewayRouteDefinition = new GatewayRouteDefinition();
protected RouteDefinition buildGatewayRouteDefinition(ServiceApiInfo serviceApiInfo, ServiceApiInfo.ApiMeta apiMeta) {
RouteDefinition gatewayRouteDefinition = new RouteDefinition();
// 唯一id规则:接口名 + 版本号
String routeId = apiMeta.fetchNameVersion();
this.checkPath(routeId, "接口定义(" + routeId + ")不能有斜杠字符'/'");
@ -119,8 +119,8 @@ public class ServiceRouteInfoBuilder {
*
* @return 返回路由定义
*/
protected GatewayRouteDefinition buildReadBodyRouteDefinition(ServiceApiInfo serviceApiInfo) {
GatewayRouteDefinition readBodyRouteDefinition = this.buildGatewayRouteDefinition(serviceApiInfo, FIRST_API_META);
protected RouteDefinition buildReadBodyRouteDefinition(ServiceApiInfo serviceApiInfo) {
RouteDefinition readBodyRouteDefinition = this.buildGatewayRouteDefinition(serviceApiInfo, FIRST_API_META);
readBodyRouteDefinition.setOrder(Integer.MIN_VALUE);
readBodyRouteDefinition.setPredicates(this.buildPredicates(FIRST_API_META));

@ -9,7 +9,7 @@ import java.util.List;
* @author tanghc
*/
@Data
public class GatewayRouteDefinition {
public class RouteDefinition {
/**
* 路由的Id接口名+版本号确保此id全局唯一
*/

@ -31,6 +31,6 @@ public class ServiceRouteInfo {
private String md5;
@JSONField(serialize = false)
private List<GatewayRouteDefinition> routeDefinitionList;
private List<RouteDefinition> routeDefinitionList;
}

@ -7,7 +7,7 @@ import com.gitee.fastmybatis.core.query.Query;
import com.gitee.sop.gateway.mapper.ConfigRouteBaseMapper;
import com.gitee.sop.gateway.mapper.ConfigRouteLimitMapper;
import com.gitee.sop.gatewaycommon.bean.ChannelMsg;
import com.gitee.sop.gatewaycommon.bean.GatewayRouteDefinition;
import com.gitee.sop.gatewaycommon.bean.RouteDefinition;
import com.gitee.sop.gatewaycommon.bean.NacosConfigs;
import com.gitee.sop.gatewaycommon.bean.RouteConfig;
import com.gitee.sop.gatewaycommon.bean.TargetRoute;
@ -47,7 +47,6 @@ public class DbRouteConfigManager extends DefaultRouteConfigManager {
Query query = new Query();
configRouteBaseMapper.list(query)
.stream()
.forEach(configRouteBase -> {
String key = configRouteBase.getRouteId();
putVal(key, configRouteBase);
@ -56,14 +55,13 @@ public class DbRouteConfigManager extends DefaultRouteConfigManager {
protected void loadAllRoute() {
Collection<? extends TargetRoute> targetRoutes = RouteRepositoryContext.getRouteRepository().getAll();
targetRoutes.stream()
.forEach(targetRoute -> {
GatewayRouteDefinition routeDefinition = targetRoute.getRouteDefinition();
targetRoutes.forEach(targetRoute -> {
RouteDefinition routeDefinition = targetRoute.getRouteDefinition();
initRouteConfig(routeDefinition);
});
}
protected void initRouteConfig(GatewayRouteDefinition routeDefinition) {
protected void initRouteConfig(RouteDefinition routeDefinition) {
String routeId = routeDefinition.getId();
RouteConfig routeConfig = newRouteConfig();
routeConfig.setRouteId(routeId);

Loading…
Cancel
Save