diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/core/GlobalConfig.java b/hango-api-plane-server/src/main/java/org/hango/cloud/core/GlobalConfig.java index 776a0cf5..e7733c6b 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/core/GlobalConfig.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/core/GlobalConfig.java @@ -21,6 +21,9 @@ public class GlobalConfig { @Value("${telnet.connect.timeout:3000}") private Integer telnetConnectTimeout; + @Value("${customDefaultRespCode:500}") + private int customDefaultRespCode; + public String getResourceNamespace() { return resourceNamespace; } @@ -40,4 +43,8 @@ public String getApiPlaneVersion() { public Integer getTelnetConnectTimeout() { return telnetConnectTimeout; } + + public int getCustomDefaultRespCode() { + return customDefaultRespCode; + } } diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/core/gateway/GatewayIstioModelEngine.java b/hango-api-plane-server/src/main/java/org/hango/cloud/core/gateway/GatewayIstioModelEngine.java index 197adf7e..3cc2c570 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/core/gateway/GatewayIstioModelEngine.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/core/gateway/GatewayIstioModelEngine.java @@ -121,6 +121,9 @@ public List translate(API api, boolean simple) { .map(FragmentHolder::getVirtualServiceFragment) .collect(Collectors.toList()); } + if (NumberUtils.INTEGER_ZERO.equals(api.getCustomDefaultRespCode())){ + api.setCustomDefaultRespCode(globalConfig.getCustomDefaultRespCode()); + } List rawVirtualServices = renderTwiceModelProcessor .process(apiVirtualService, api, new PortalVirtualServiceAPIDataHandler( diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/core/gateway/handler/APIDataHandler.java b/hango-api-plane-server/src/main/java/org/hango/cloud/core/gateway/handler/APIDataHandler.java index 38ac1b0e..3bc3f8c4 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/core/gateway/handler/APIDataHandler.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/core/gateway/handler/APIDataHandler.java @@ -85,6 +85,7 @@ public TemplateParams handleApi(API api) { .put(VIRTUAL_SERVICE_REQUEST_HEADERS, api.getRequestOperation()) .put(VIRTUAL_SERVICE_VIRTUAL_CLUSTER_NAME, api.getVirtualClusterName()) .put(VIRTUAL_SERVICE_VIRTUAL_CLUSTER_HEADERS, getVirtualClusterHeaders(api)) + .put(VIRTUAL_SERVICE_RESP_EXCEPTION_CODE, api.getCustomDefaultRespCode()) ; return handleApiMetaMap(api,tp); diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/core/template/TemplateConst.java b/hango-api-plane-server/src/main/java/org/hango/cloud/core/template/TemplateConst.java index e753e6d1..734727b9 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/core/template/TemplateConst.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/core/template/TemplateConst.java @@ -76,6 +76,9 @@ public interface TemplateConst { String VIRTUAL_SERVICE_STATS = "t_virtual_service_stats"; String VIRTUAL_SERVICE_DUBBO = "t_virtual_service_dubbo"; + String VIRTUAL_SERVICE_RESP_EXCEPTION_CODE ="t_virtual_service_resp_exception_code"; + + /** * ServiceInfo **/ diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/meta/API.java b/hango-api-plane-server/src/main/java/org/hango/cloud/meta/API.java index 4835c3da..218ce0ba 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/meta/API.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/meta/API.java @@ -225,6 +225,11 @@ public class API extends CommonModel { */ private Map metaMap; + private Long version; + + + private int customDefaultRespCode; + public Service getMirrorTraffic() { return mirrorTraffic; } @@ -529,4 +534,20 @@ public Map getMetaMap() { public void setMetaMap(Map metaMap) { this.metaMap = metaMap; } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } + + public int getCustomDefaultRespCode() { + return customDefaultRespCode; + } + + public void setCustomDefaultRespCode(int customDefaultRespCode) { + this.customDefaultRespCode = customDefaultRespCode; + } } diff --git a/hango-api-plane-server/src/main/resources/template/gateway/api/virtualServiceMeta.ftl b/hango-api-plane-server/src/main/resources/template/gateway/api/virtualServiceMeta.ftl index 7222afd4..4695bbbf 100644 --- a/hango-api-plane-server/src/main/resources/template/gateway/api/virtualServiceMeta.ftl +++ b/hango-api-plane-server/src/main/resources/template/gateway/api/virtualServiceMeta.ftl @@ -32,6 +32,9 @@ metadata: <#if t_virtual_service_dubbo_meta_service?has_content > proxy.upstreams.http.dubbo: + <#if t_virtual_service_resp_exception_code??> + resp_exception_code: ${t_virtual_service_resp_exception_code} + context: service: ${t_virtual_service_dubbo_meta_service} version: ${t_virtual_service_dubbo_meta_version}