Skip to content

Commit

Permalink
fix: fix gateway binding error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
trickMin committed Oct 16, 2023
1 parent 52e6644 commit 5304442
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public class CommonErrorCode extends ErrorCode {
public static final ErrorCode INVALID_LABEL = new ErrorCode(ErrorCodeEnum.INVALID_LABEL);
public static final ErrorCode NO_SUBSET_OF_SERVICE = new ErrorCode(ErrorCodeEnum.NO_SUBSET_OF_SERVICE);
public static final ErrorCode PROJECT_NOT_ASSOCIATED_GATEWAY = new ErrorCode(ErrorCodeEnum.PROJECT_NOT_ASSOCIATED_GATEWAY);
public static final ErrorCode GW_NOT_ASSOCIATED_DOMAIN = new ErrorCode(ErrorCodeEnum.GW_NOT_ASSOCIATED_DOMAIN);
public static final ErrorCode DESTINATION_GW_NOT_ASSOCIATED_DOMAIN = new ErrorCode(ErrorCodeEnum.DESTINATION_GW_NOT_ASSOCIATED_DOMAIN);
public static final ErrorCode CURRENT_GW_NOT_ASSOCIATED_DOMAIN = new ErrorCode(ErrorCodeEnum.CURRENT_GW_NOT_ASSOCIATED_DOMAIN);
public static final ErrorCode CANNOT_DELETE_VIRTUAL_GATEWAY = new ErrorCode(ErrorCodeEnum.CANNOT_DELETE_VIRTUAL_GATEWAY);
public static final ErrorCode ROUTE_HAS_TRAFFIC_MARK_RULES = new ErrorCode(ErrorCodeEnum.ROUTE_HAS_TRAFFIC_MARK_RULES);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public enum ErrorCodeEnum {
INVALID_PARAM_GW_TYPE("InvalidParamGwType", "Wrong Gateway Type.", "网关类型填写错误", 400),
PROJECT_NOT_ASSOCIATED_GATEWAY("ProjectNotAssociatedGateway", "The current project is not associated with the specified gateway.", "当前项目未关联指定网关,不允许发布", 400),

GW_NOT_ASSOCIATED_DOMAIN("GwNotAssociatedDomain", "The current gw not associated domain", "当前网关未绑定域名,不允许发布", 400),
DESTINATION_GW_NOT_ASSOCIATED_DOMAIN("DestinationGwNotAssociatedDomain", "The destination gw not associated domain", "目标网关未绑定域名,不允许发布", 400),
CURRENT_GW_NOT_ASSOCIATED_DOMAIN("CurrentGwNotAssociatedDomain", "The current gw not associated domain", "当前网关未绑定域名,不允许发布", 400),


MIRROR_BY_ROUTE_RULE("MirrorByRouteRule", "The service has been mirrored by route rule", "该服务已被路由流量镜像使用", 400),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public interface IPluginInfoService extends CommonService<PluginBindingInfo, Plu
*/
ErrorCode checkDescribePlugin(long virtualGwId);

/**
* 查询插件信息时的参数校验(列表&详情)
*
* @param virtualGwId 网关id
* @param copyPlugin 是否为拷贝插件场景
* @return 参数校验结果,当校验通过时返回 ErrorCodeEnum.Success
*/
ErrorCode checkDescribePlugin(long virtualGwId, boolean copyPlugin);

/**
* 校验删除参数
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public PluginBindingDto get(long id) {

@Override
public ErrorCode checkDescribePlugin(long virtualGwId) {
return checkDescribePlugin(virtualGwId, false);
}

@Override
public ErrorCode checkDescribePlugin(long virtualGwId, boolean copyPlugin) {
if (virtualGwId <= 0) {
// 获取插件getPluginInfo可以不传gwId,默认值为0,此处返回成功(后面会处理所有网关的场景)
return CommonErrorCode.SUCCESS;
Expand All @@ -101,8 +106,13 @@ public ErrorCode checkDescribePlugin(long virtualGwId) {
return CommonErrorCode.NO_SUCH_GATEWAY;
}
if (CollectionUtils.isEmpty(virtualGateway.getDomainInfos())){
logger.error("复制插件时,目前网关未绑定域名,不允许复制, vgId:{}", virtualGwId);
return CommonErrorCode.GW_NOT_ASSOCIATED_DOMAIN;
if (copyPlugin) {
logger.error("复制插件时,目前网关未绑定域名,不允许复制, vgId:{}", virtualGwId);
return CommonErrorCode.DESTINATION_GW_NOT_ASSOCIATED_DOMAIN;
} else {
logger.error("绑定插件时,目前网关未绑定域名,不允许复制, vgId:{}", virtualGwId);
return CommonErrorCode.CURRENT_GW_NOT_ASSOCIATED_DOMAIN;
}
}
return CommonErrorCode.SUCCESS;
}
Expand All @@ -119,7 +129,7 @@ public ErrorCode checkUnbindParam(long pluginBindingInfoId) {
@Override
public ErrorCode checkCopyGlobalPluginToGateway(CopyGlobalPluginDto copyGlobalPluginDto) {
// 检查目标网关是否存在
ErrorCode gwErrorCode = checkDescribePlugin(copyGlobalPluginDto.getVirtualGwId());
ErrorCode gwErrorCode = checkDescribePlugin(copyGlobalPluginDto.getVirtualGwId(), true);
if (!gwErrorCode.equals(CommonErrorCode.SUCCESS)) {
return gwErrorCode;
}
Expand Down Expand Up @@ -211,7 +221,7 @@ private ErrorCode checkBindingObjectType(PluginBindingDto pluginBindingDto){
List<String> hosts = domainInfoService.getHosts(bindingObjectId, virtualGwId);
if (CollectionUtils.isEmpty(hosts)) {
logger.info("绑定全局插件时指定的域名不存在! virtualGwId:{}, projectId:{}", virtualGwId, bindingObjectId);
return CommonErrorCode.GW_NOT_ASSOCIATED_DOMAIN;
return CommonErrorCode.CURRENT_GW_NOT_ASSOCIATED_DOMAIN;
}
break;
case HOST:
Expand Down

0 comments on commit 5304442

Please sign in to comment.