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 18a0543e..38ac1b0e 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 @@ -1,24 +1,34 @@ package org.hango.cloud.core.gateway.handler; +import com.fasterxml.jackson.core.JsonProcessingException; +import me.snowdrop.istio.api.networking.v1alpha3.VirtualService; +import org.apache.commons.lang3.StringEscapeUtils; import org.hango.cloud.core.gateway.handler.meta.UriMatchMeta; import org.hango.cloud.core.template.TemplateParams; import org.hango.cloud.meta.API; +import org.hango.cloud.meta.CRDMetaEnum; import org.hango.cloud.meta.PairMatch; import org.hango.cloud.meta.UriMatch; +import org.hango.cloud.meta.dto.DubboInfoDto; import org.hango.cloud.util.CommonUtil; import org.hango.cloud.util.PriorityUtil; -import org.apache.commons.lang3.StringEscapeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import static org.hango.cloud.core.template.TemplateConst.*; public abstract class APIDataHandler implements DataHandler { + private static final Logger logger = LoggerFactory.getLogger(APIDataHandler.class); + @Override public List handle(API api) { TemplateParams tp = handleApi(api); @@ -75,11 +85,82 @@ 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_STATS, api.getStatsMeta()); + ; + + return handleApiMetaMap(api,tp); + } + + /** + * 处理VirtualService metadata 数据 + * + * @param api 上层输入的API数据 + * @param tp 模板参数 + * @return TemplateParams + */ + private TemplateParams handleApiMetaMap(API api, TemplateParams tp) { + if (CollectionUtils.isEmpty(api.getMetaMap())) { + return tp; + } + Iterator> iterator = api.getMetaMap().entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry next = iterator.next(); + handleApiMeta(next.getKey(), next.getValue(), tp); + } + return tp; + } + /** + * 处理VirtualService metadata 数据 + * + * @param name 上层输入的metadata类型 + * @param value 上层输入的metadata数据 + * @param tp 模板参数 + * @return TemplateParams + */ + private TemplateParams handleApiMeta(String name, String value, TemplateParams tp) { + CRDMetaEnum metaEnum = CRDMetaEnum.get(VirtualService.class, name); + if (metaEnum == null) { + logger.warn("find null meta enum ,please check input content , target class is {} , name is {} ", VirtualService.class, name); + return tp; + } + try { + switch (metaEnum) { + case VIRTUAL_SERVICE_STATS_META: + tp.put(metaEnum.getTemplateName(), metaEnum.getTransData(value)); + break; + case VIRTUAL_SERVICE_DUBBO_META: + handleDubboMeta(tp, metaEnum.getTransData(value)); + break; + default: + break; + } + } catch (JsonProcessingException e) { + logger.warn("meta content parse failed , errMsg is {}", e.getMessage()); + } return tp; } + /** + * 将Dubbo meta 元数据信息加入模板参数中 + * + * @param tp 模板参数 + * @param info dubbo meta信息 + * @return TemplateParams + */ + private TemplateParams handleDubboMeta(TemplateParams tp, DubboInfoDto info) { + tp.put(VIRTUAL_SERVICE_DUBBO_META_SERVICE, info.getInterfaceName()) + .put(VIRTUAL_SERVICE_DUBBO_META_VERSION, info.getVersion()) + .put(VIRTUAL_SERVICE_DUBBO_META_METHOD, info.getMethod()) + .put(VIRTUAL_SERVICE_DUBBO_META_GROUP, info.getGroup()) + .put(VIRTUAL_SERVICE_DUBBO_META_SOURCE, info.getParamSource()) + .put(VIRTUAL_SERVICE_DUBBO_META_PARAMS, info.getParams()) + .put(VIRTUAL_SERVICE_DUBBO_META_ATTACHMENTS, info.getDubboAttachment()) + ; + return tp; + } + + + protected String getOrDefault(String value, String defaultValue) { return StringUtils.isEmpty(value) ? defaultValue : value; } 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 16a09b92..e753e6d1 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 @@ -74,6 +74,7 @@ public interface TemplateConst { String VIRTUAL_SERVICE_MIRROR_SUBSET = "t_virtual_service_mirror_subset"; String VIRTUAL_SERVICE_MIRROR_YAML = "t_virtual_service_mirror_yaml"; String VIRTUAL_SERVICE_STATS = "t_virtual_service_stats"; + String VIRTUAL_SERVICE_DUBBO = "t_virtual_service_dubbo"; /** * ServiceInfo @@ -265,4 +266,15 @@ public interface TemplateConst { * */ + /** + * Dubbo Meta 相关信息 + */ + String VIRTUAL_SERVICE_DUBBO_META_SERVICE ="t_virtual_service_dubbo_meta_service"; + String VIRTUAL_SERVICE_DUBBO_META_VERSION ="t_virtual_service_dubbo_meta_version"; + String VIRTUAL_SERVICE_DUBBO_META_METHOD ="t_virtual_service_dubbo_meta_method"; + String VIRTUAL_SERVICE_DUBBO_META_GROUP ="t_virtual_service_dubbo_meta_group"; + String VIRTUAL_SERVICE_DUBBO_META_SOURCE ="t_virtual_service_dubbo_meta_source"; + String VIRTUAL_SERVICE_DUBBO_META_PARAMS ="t_virtual_service_dubbo_meta_params"; + String VIRTUAL_SERVICE_DUBBO_META_ATTACHMENTS ="t_virtual_service_dubbo_meta_attachments"; + } 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 e129c32c..4835c3da 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 @@ -2,6 +2,7 @@ import java.util.List; +import java.util.Map; public class API extends CommonModel { @@ -170,9 +171,59 @@ public class API extends CommonModel { private Service mirrorTraffic; /** - * 路由指标,为空不开启 + * meta数据传输集 + * Map + * mata_type meta类型 + * + * @see CRDMetaEnum + * mata_type: 路由meta数据类型 + * meta_data: 路由meta数据值,使用JSON传输 + * eg. + * { + * "DubboMeta": { + * "ObjectType": "route", + * "ObjectId": 259, + * "Params": [ + * { + * "Key": "str", + * "Value": "java.lang.String", + * "GenericInfo": ".dataA:com.demo.B,.dataAA:com.demo.B,.dataA.dataB:com.demo.C,.dataAA.dataB:com.demo.C", + * "Required": false, + * "DefaultValue": "sdfsdfs", + * "_formTableKey": 1660649073793, + * "index": 0 + * }, + * { + * "Key": "wer", + * "Value": "java.lang.Integer", + * "GenericInfo": null, + * "Required": true, + * "DefaultValue": null, + * "_formTableKey": 1660649073793 + * } + * ], + * "Method": "echoStrAndInt", + * "CustomParamMapping": true, + * "ParamSource": "body", + * "Attachment": [ + * { + * "ClientParamName": "xcvxcv", + * "Description": "cxvxcv", + * "ParamPosition": "Header", + * "ServerParamName": "cvcv", + * "distinctName": "Headerxcvxcv", + * "_formTableKey": 1660648830195 + * } + * ], + * "MethodWorks": true + * }, + * "StatsMeta": [ + * "/test", + * "/test1" + * ] + * } */ - private List statsMeta; + private Map metaMap; public Service getMirrorTraffic() { return mirrorTraffic; @@ -471,11 +522,11 @@ public void setVirtualClusterHeaders(List virtualClusterHeaders) { this.virtualClusterHeaders = virtualClusterHeaders; } - public List getStatsMeta() { - return statsMeta; + public Map getMetaMap() { + return metaMap; } - public void setStatsMeta(final List statsMeta) { - this.statsMeta = statsMeta; + public void setMetaMap(Map metaMap) { + this.metaMap = metaMap; } } diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/meta/CRDMetaEnum.java b/hango-api-plane-server/src/main/java/org/hango/cloud/meta/CRDMetaEnum.java new file mode 100644 index 00000000..e57db0cd --- /dev/null +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/meta/CRDMetaEnum.java @@ -0,0 +1,98 @@ +package org.hango.cloud.meta; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.fabric8.kubernetes.api.model.KubernetesResource; +import me.snowdrop.istio.api.networking.v1alpha3.VirtualService; +import org.hango.cloud.core.template.TemplateConst; +import org.hango.cloud.meta.dto.DubboInfoDto; +import org.hango.cloud.meta.dto.DubboMetaDto; + +import java.util.List; +import java.util.Map; + + +/** + * @author zhangbj + * @version 1.0 + * @Type + * @Desc 自定义资源meta枚举 + * @date 2022/8/16 + */ +public enum CRDMetaEnum { + + VIRTUAL_SERVICE_STATS_META(VirtualService.class, "StatsMeta", TemplateConst.VIRTUAL_SERVICE_STATS, new TypeReference>() { + }), + VIRTUAL_SERVICE_DUBBO_META(VirtualService.class, "DubboMeta", TemplateConst.VIRTUAL_SERVICE_DUBBO, new TypeReference() { + }), + ; + + + private Class target; + + private String name; + + private String templateName; + + private TypeReference transModel; + + CRDMetaEnum(Class target, String name, String templateName, TypeReference transModel) { + this.target = target; + this.name = name; + this.templateName = templateName; + this.transModel = transModel; + } + + public TypeReference getTransModel() { + return transModel; + } + + public void setTransModel(TypeReference transModel) { + this.transModel = transModel; + } + + public Class getTarget() { + return target; + } + + public String getName() { + return name; + } + + public String getTemplateName() { + return templateName; + } + + /** + * 通过名称获取模板名称 + * + * @return + */ + public static CRDMetaEnum get(Class target, String name) { + for (CRDMetaEnum value : values()) { + if (value.target.equals(target) && value.name.equals(name)) { + return value; + } + } + return null; + + } + + /** + * 获取上层传输的Meta信息内容 + * + * @param content + * @param + * @return + * @throws JsonProcessingException + */ + public T getTransData(String content) throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + return ((T) objectMapper.readValue(content, this.transModel)); + + } + +} diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/meta/dto/DubboInfoDto.java b/hango-api-plane-server/src/main/java/org/hango/cloud/meta/dto/DubboInfoDto.java new file mode 100644 index 00000000..280a7dfa --- /dev/null +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/meta/dto/DubboInfoDto.java @@ -0,0 +1,472 @@ +package org.hango.cloud.meta.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.util.CollectionUtils; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author zhangbj + * @version 1.0 + * @Type + * @Desc + * @date 2020/12/2 + */ +public class DubboInfoDto { + + /** + * 方法 + */ + @JsonProperty(value = "Method") + @NotEmpty + private String method; + + /** + * 关联ID + */ + @JsonProperty(value = "ObjectId") + @NotNull + private Long objectId; + + /** + * 关联类型,api/route 默认路由 route + */ + @JsonProperty(value = "ObjectType") + private String objectType; + + /** + * 接口名 + */ + @JsonProperty(value = "InterfaceName") + private String interfaceName; + + /** + * 版本 + */ + @JsonProperty(value = "Version") + private String version; + + /** + * 是否开启自定义参数映射开关, 目前只支持开启 + */ + @JsonProperty(value = "CustomParamMapping") + private boolean customParamMapping; + + /** + * 分组 + */ + @JsonProperty(value = "Group") + private String group; + /** + * <形参名>:<类型名> + * Dubbo参数 + */ + @JsonProperty(value = "Params") + private List params = new ArrayList<>(); + + + /** + * 参数来源,支持query和body两种参数来源配置 + */ + @JsonProperty(value = "ParamSource") + @Pattern(regexp = "query|body") + private String paramSource; + + /** + * dubbo attachmentInfo + */ + @JsonProperty(value = "Attachment") + private List dubboAttachment; + + /** + * 方法是否有效 + */ + @JsonProperty(value = "MethodWorks") + private Boolean methodWorks; + + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public List getParams() { + return params; + } + + public void setParams(List params) { + this.params = params; + } + + public String getParamSource() { + return paramSource; + } + + public void setParamSource(String paramSource) { + this.paramSource = paramSource; + } + + public List getDubboAttachment() { + return dubboAttachment; + } + + public void setDubboAttachment(List dubboAttachment) { + this.dubboAttachment = dubboAttachment; + } + + public String getParamToStr() { + if (CollectionUtils.isEmpty(params)) { + return null; + } + StringBuilder builder = new StringBuilder(); + for (DubboParam param : params) { + builder.append(param.getKey()).append(":").append(param.getValue()).append(";"); + } + return builder.substring(0, builder.lastIndexOf(";")); + } + + public Long getObjectId() { + return objectId; + } + + public void setObjectId(Long objectId) { + this.objectId = objectId; + } + + public String getObjectType() { + return objectType; + } + + public void setObjectType(String objectType) { + this.objectType = objectType; + } + + public String getInterfaceName() { + return interfaceName; + } + + public void setInterfaceName(String interfaceName) { + this.interfaceName = interfaceName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public boolean getCustomParamMapping() { + return customParamMapping; + } + + public void setCustomParamMapping(boolean customParamMapping) { + this.customParamMapping = customParamMapping; + } + + public Boolean getMethodWorks() { + return methodWorks; + } + + public void setMethodWorks(Boolean methodWorks) { + this.methodWorks = methodWorks; + } + + public static class DubboMeta { + + /** + * 方法 + */ + private String method; + + + /** + * 接口名 + */ + private String interfaceName; + + /** + * 版本 + */ + private String version; + + /** + * 分组 + */ + private String group; + /** + * <形参名>:<类型名> + * Dubbo参数 + */ + private List params; + + /** + * 是否开启自定义参数映射开关, 默认false + */ + private boolean customParamMapping; + + /** + * 参数来源,支持:query和body三种参数来源配置 + */ + private String paramSource; + + /** + * dubbo attachment信息 + */ + private List attachmentInfo; + + /** + * dubbo 泛型信息 + */ + private String genericInfo; + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public String getInterfaceName() { + return interfaceName; + } + + public void setInterfaceName(String interfaceName) { + this.interfaceName = interfaceName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public List getParams() { + return params; + } + + public void setParams(List params) { + this.params = params; + } + + public boolean getCustomParamMapping() { + return customParamMapping; + } + + public void setCustomParamMapping(boolean customParamMapping) { + this.customParamMapping = customParamMapping; + } + + public String getParamSource() { + return paramSource; + } + + public void setParamSource(String paramSource) { + this.paramSource = paramSource; + } + + public List getAttachmentInfo() { + return attachmentInfo; + } + + public void setAttachmentInfo(List attachmentInfo) { + this.attachmentInfo = attachmentInfo; + } + + public String getGenericInfo() { + return genericInfo; + } + + public void setGenericInfo(String genericInfo) { + this.genericInfo = genericInfo; + } + } + + public static class DubboParam { + /** + * key + */ + @JsonProperty(value = "Key") + private String key; + /** + * value + */ + @JsonProperty(value = "Value") + private String value; + + @JsonProperty(value = "Required") + private boolean required; + + @JsonProperty(value = "DefaultValue") + private Object defaultValue; + + @JsonProperty(value = "GenericInfo") + private String genericInfo; + + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public boolean isRequired() { + return required; + } + + public void setRequired(boolean required) { + this.required = required; + } + + public Object getDefaultValue() { + return defaultValue; + } + + public Object getDefaultJsonValue() throws JsonProcessingException { + if (defaultValue == null) { + return null; + } + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.writeValueAsString(defaultValue); + } + + public void setDefaultValue(Object defaultValue) { + this.defaultValue = defaultValue; + } + + public String getGenericInfo() { + return genericInfo; + } + + public Map getGenericMap() { + if (StringUtils.isBlank(genericInfo)) { + return null; + } + Map map = Maps.newHashMap(); + String[] generics = StringUtils.split(genericInfo, ","); + for (String genericStr : generics) { + String[] generic = StringUtils.split(genericStr, ":"); + if (generic.length != 2) { + continue; + } + map.put(generic[0], generic[1]); + } + return map; + } + + public void setGenericInfo(String genericInfo) { + this.genericInfo = genericInfo; + } + } + + + public static class DubboAttachmentDto { + /** + * attachment位置 Header/Cookie + */ + @JsonProperty(value = "ParamPosition") + private String paramPosition; + /** + * 客户端参数名称 + */ + @JsonProperty(value = "ClientParamName") + private String clientParamName; + + /** + * 服务端参数名称 + */ + @JsonProperty(value = "ServerParamName") + private String serverParamName; + + /** + * 备注信息 + */ + @JsonProperty(value = "Description") + private String description; + + public String getParamPosition() { + return paramPosition; + } + + public void setParamPosition(String paramPosition) { + this.paramPosition = paramPosition; + } + + public String getClientParamName() { + return clientParamName; + } + + public void setClientParamName(String clientParamName) { + this.clientParamName = clientParamName; + } + + public String getServerParamName() { + return serverParamName; + } + + public void setServerParamName(String serverParamName) { + this.serverParamName = serverParamName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDistinctName() { + return paramPosition + clientParamName; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } + } +} diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/meta/dto/PortalAPIDTO.java b/hango-api-plane-server/src/main/java/org/hango/cloud/meta/dto/PortalAPIDTO.java index b1ddc46a..6e8f0a1c 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/meta/dto/PortalAPIDTO.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/meta/dto/PortalAPIDTO.java @@ -1,11 +1,13 @@ package org.hango.cloud.meta.dto; import com.fasterxml.jackson.annotation.JsonProperty; +import org.hango.cloud.meta.CRDMetaEnum; import org.hibernate.validator.constraints.NotEmpty; import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.util.List; +import java.util.Map; public class PortalAPIDTO { @@ -138,8 +140,61 @@ public class PortalAPIDTO { @JsonProperty(value = "MirrorTraffic") private PortalMirrorTrafficDto mirrorTrafficDto; - @JsonProperty(value = "StatsMeta") - private List statsMeta; + /** + * meta数据传输集 + * Map + * mata_type meta类型 + * + * @see CRDMetaEnum + * mata_type: 路由meta数据类型 + * meta_data: 路由meta数据值,使用JSON传输 + * eg. + * { + * "DubboMeta": { + * "ObjectType": "route", + * "ObjectId": 259, + * "Params": [ + * { + * "Key": "str", + * "Value": "java.lang.String", + * "GenericInfo": ".dataA:com.demo.B,.dataAA:com.demo.B,.dataA.dataB:com.demo.C,.dataAA.dataB:com.demo.C", + * "Required": false, + * "DefaultValue": "sdfsdfs", + * "_formTableKey": 1660649073793, + * "index": 0 + * }, + * { + * "Key": "wer", + * "Value": "java.lang.Integer", + * "GenericInfo": null, + * "Required": true, + * "DefaultValue": null, + * "_formTableKey": 1660649073793 + * } + * ], + * "Method": "echoStrAndInt", + * "CustomParamMapping": true, + * "ParamSource": "body", + * "Attachment": [ + * { + * "ClientParamName": "xcvxcv", + * "Description": "cxvxcv", + * "ParamPosition": "Header", + * "ServerParamName": "cvcv", + * "distinctName": "Headerxcvxcv", + * "_formTableKey": 1660648830195 + * } + * ], + * "MethodWorks": true + * }, + * "StatsMeta": [ + * "/test", + * "/test1" + * ] + * } + */ + @JsonProperty(value = "MetaMap") + private Map metaMap; public PortalMirrorTrafficDto getMirrorTrafficDto() { return mirrorTrafficDto; @@ -309,11 +364,11 @@ public void setVirtualClusterDTO(VirtualClusterDTO virtualClusterDTO) { this.virtualClusterDTO = virtualClusterDTO; } - public List getStatsMeta() { - return statsMeta; + public Map getMetaMap() { + return metaMap; } - public void setStatsMeta(final List statsMeta) { - this.statsMeta = statsMeta; + public void setMetaMap(Map metaMap) { + this.metaMap = metaMap; } } diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/util/Const.java b/hango-api-plane-server/src/main/java/org/hango/cloud/util/Const.java index 2d69d033..04661bdd 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/util/Const.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/util/Const.java @@ -1,7 +1,10 @@ package org.hango.cloud.util; +import com.google.common.collect.Maps; + import java.util.Arrays; import java.util.List; +import java.util.Map; public interface Const { diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/util/Trans.java b/hango-api-plane-server/src/main/java/org/hango/cloud/util/Trans.java index 326ecef6..2c36a39b 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/util/Trans.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/util/Trans.java @@ -86,9 +86,7 @@ public static API portalAPI2API(PortalAPIDTO portalAPI) { mirrorTraffic.setSubset(mirrorTrafficDto.getSubset()); api.setMirrorTraffic(mirrorTraffic); } - if (!CollectionUtils.isEmpty(portalAPI.getStatsMeta())){ - api.setStatsMeta(portalAPI.getStatsMeta()); - } + api.setMetaMap(portalAPI.getMetaMap()); return api; } 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 9f8dcacf..7222afd4 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 @@ -28,4 +28,44 @@ metadata: <#list t_virtual_service_stats as stats_meta> - ${stats_meta} + + +<#if t_virtual_service_dubbo_meta_service?has_content > + proxy.upstreams.http.dubbo: + context: + service: ${t_virtual_service_dubbo_meta_service} + version: ${t_virtual_service_dubbo_meta_version} + method: ${t_virtual_service_dubbo_meta_method} + group: ${t_virtual_service_dubbo_meta_group} + source: ${(t_virtual_service_dubbo_meta_source=="body")?string('HTTP_BODY','HTTP_QUERY')} + <#if t_virtual_service_dubbo_meta_params?has_content> + parameters: + <#list t_virtual_service_dubbo_meta_params as p> + - type: ${p.value} + name: ${p.key} + required: ${p.required?c} + <#if p.defaultValue ??> + default: '${p.defaultJsonValue}' + + <#if p.genericMap?has_content> + generic: + <#list p.genericMap as k,v> + - path: ${k} + type: ${v} + + + + + <#if t_virtual_service_dubbo_meta_attachments?has_content> + attachments: + <#list t_virtual_service_dubbo_meta_attachments as a> + - name: ${a.serverParamName} + <#if a.paramPosition == "Header"> + header: ${a.clientParamName} + <#elseif a.paramPosition == "Cookie"> + cookie: ${a.clientParamName} + + + + ignore_null_map_pair: false \ No newline at end of file diff --git a/package.sh b/package.sh new file mode 100644 index 00000000..eccd0ccb --- /dev/null +++ b/package.sh @@ -0,0 +1,25 @@ +#!/bin/bash +mvn clean package -Dmaven.test.skip=true +dates=`date +%s` +echo $dates + +MODULE=api-plane +branch=$(git symbolic-ref --short -q HEAD) +commit=$(git rev-parse --short HEAD) +dates=`date +%s` +tag=$(git show-ref --tags| grep $commit | awk -F"[/]" '{print $3}') +if [ -z $tag ] +then + export TAG=$branch-$commit +else + export TAG=$tag +fi +if ! git diff-index --quiet HEAD --; then + TAG=$TAG-$dates +fi + +docker login -u staff.qingzhou@service.netease.com -p Qingzhou4321 hub.c.163.com + +docker build -f hango-api-plane-server/Dockerfile -t hub.c.163.com/qingzhou/$MODULE:$TAG . + +docker push hub.c.163.com/qingzhou/$MODULE:$TAG \ No newline at end of file