Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 补充腾讯云没加vendor、region过滤条件的请求, 并补充region索引 #1216

Open
wants to merge 1 commit into
base: v1.7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions cmd/cloud-server/service/application/handlers/base_cvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,31 @@ import (
"hcm/pkg/api/core"
corecvm "hcm/pkg/api/core/cloud/cvm"
"hcm/pkg/criteria/enumor"
"hcm/pkg/runtime/filter"
"hcm/pkg/dal/dao/tools"
"hcm/pkg/tools/slice"
)

// ListCvm 查询主机列表
func (a *BaseApplicationHandler) ListCvm(
vendor enumor.Vendor, accountID string, cloudCvmIDs []string,
vendor enumor.Vendor, accountID, region string, cloudCvmIDs []string,
) ([]corecvm.BaseCvm, error) {
reqFilter := &filter.Expression{
Op: filter.And,
Rules: []filter.RuleFactory{
filter.AtomRule{Field: "vendor", Op: filter.Equal.Factory(), Value: vendor},
filter.AtomRule{Field: "account_id", Op: filter.Equal.Factory(), Value: accountID},
filter.AtomRule{Field: "cloud_id", Op: filter.In.Factory(), Value: cloudCvmIDs},
},
}
// 查询
resp, err := a.Client.DataService().Global.Cvm.ListCvm(
a.Cts.Kit,
&core.ListReq{
Filter: reqFilter,
Page: &core.BasePage{Count: false, Start: 0, Limit: uint(len(cloudCvmIDs))},
},
)
if err != nil {
return nil, err
}

return resp.Details, nil
result := make([]corecvm.BaseCvm, 0)
for _, ids := range slice.Split(cloudCvmIDs, int(core.DefaultMaxPageLimit)) {
listReq := &core.ListReq{
Filter: tools.ExpressionAnd(
tools.RuleEqual("vendor", vendor),
tools.RuleEqual("account_id", accountID),
tools.RuleIn("cloud_id", ids),
tools.RuleEqual("region", region),
),
Page: core.NewDefaultBasePage(),
}
resp, err := a.Client.DataService().Global.Cvm.ListCvm(a.Cts.Kit, listReq)
if err != nil {
return nil, err
}
result = append(result, resp.Details...)
}
return result, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ import (

// ListSecurityGroup 查询安全组列表
func (a *BaseApplicationHandler) ListSecurityGroup(
vendor enumor.Vendor, accountID string, cloudSecurityGroupIDs []string,
vendor enumor.Vendor, accountID, region string, cloudSecurityGroupIDs []string,
) ([]corecloud.BaseSecurityGroup, error) {

reqFilter := &filter.Expression{
Op: filter.And,
Rules: []filter.RuleFactory{
filter.AtomRule{Field: "vendor", Op: filter.Equal.Factory(), Value: vendor},
filter.AtomRule{Field: "account_id", Op: filter.Equal.Factory(), Value: accountID},
filter.AtomRule{Field: "cloud_id", Op: filter.In.Factory(), Value: cloudSecurityGroupIDs},
filter.AtomRule{Field: "region", Op: filter.Equal.Factory(), Value: region},
},
}
// 查询
Expand Down
6 changes: 3 additions & 3 deletions cmd/cloud-server/service/application/handlers/base_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ import (
)

// GetSubnet 查询子网
func (a *BaseApplicationHandler) GetSubnet(
vendor enumor.Vendor, accountID, cloudVpcID, cloudSubnetID string,
) (*corecloud.BaseSubnet, error) {
func (a *BaseApplicationHandler) GetSubnet(vendor enumor.Vendor, accountID, cloudVpcID, cloudSubnetID,
region string) (*corecloud.BaseSubnet, error) {
reqFilter := &filter.Expression{
Op: filter.And,
Rules: []filter.RuleFactory{
filter.AtomRule{Field: "vendor", Op: filter.Equal.Factory(), Value: vendor},
filter.AtomRule{Field: "account_id", Op: filter.Equal.Factory(), Value: accountID},
filter.AtomRule{Field: "cloud_vpc_id", Op: filter.Equal.Factory(), Value: cloudVpcID},
filter.AtomRule{Field: "cloud_id", Op: filter.Equal.Factory(), Value: cloudSubnetID},
filter.AtomRule{Field: "region", Op: filter.Equal.Factory(), Value: region},
},
}
// 查询
Expand Down
3 changes: 2 additions & 1 deletion cmd/cloud-server/service/application/handlers/base_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

// GetVpc 查询VPC
func (a *BaseApplicationHandler) GetVpc(vendor enumor.Vendor, accountID, cloudVpcID string) (
func (a *BaseApplicationHandler) GetVpc(vendor enumor.Vendor, accountID, cloudVpcID, region string) (
*corecloud.BaseVpc, error) {

reqFilter := &filter.Expression{
Expand All @@ -40,6 +40,7 @@ func (a *BaseApplicationHandler) GetVpc(vendor enumor.Vendor, accountID, cloudVp
filter.AtomRule{Field: "vendor", Op: filter.Equal.Factory(), Value: vendor},
filter.AtomRule{Field: "account_id", Op: filter.Equal.Factory(), Value: accountID},
filter.AtomRule{Field: "cloud_id", Op: filter.Equal.Factory(), Value: cloudVpcID},
filter.AtomRule{Field: "region", Op: filter.Equal.Factory(), Value: region},
},
}
// 查询
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ func (a *ApplicationOfCreateAwsCvm) renderNetwork() ([]formItem, error) {
formItems := make([]formItem, 0)

// VPC
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID)
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID, req.Region)
if err != nil {
return formItems, err
}
formItems = append(formItems, formItem{Label: "VPC", Value: vpcInfo.Name})

// 子网
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID)
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID, req.Region)
if err != nil {
return formItems, err
}
Expand All @@ -165,7 +165,7 @@ func (a *ApplicationOfCreateAwsCvm) renderNetwork() ([]formItem, error) {
formItems = append(formItems, formItem{Label: "所属的蓝鲸云区域", Value: bkCloudAreaName})

// 安全组
securityGroups, err := a.ListSecurityGroup(a.Vendor(), req.AccountID, req.CloudSecurityGroupIDs)
securityGroups, err := a.ListSecurityGroup(a.Vendor(), req.AccountID, req.Region, req.CloudSecurityGroupIDs)
securityGroupNames := make([]string, 0, len(req.CloudSecurityGroupIDs))
for _, s := range securityGroups {
securityGroupNames = append(securityGroupNames, s.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (a *ApplicationOfCreateAwsCvm) Deliver() (enumor.ApplicationStatus, map[str
func (a *ApplicationOfCreateAwsCvm) assignToBiz(cloudCvmIDs []string) ([]string, error) {
req := a.req
// 云ID查询主机
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, cloudCvmIDs)
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, req.Region, cloudCvmIDs)
if err != nil {
return []string{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ func (a *ApplicationOfCreateAzureCvm) renderNetwork() ([]formItem, error) {
formItems := make([]formItem, 0)

// VPC
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID)
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID, req.Region)
if err != nil {
return formItems, err
}
formItems = append(formItems, formItem{Label: "VPC", Value: vpcInfo.Name})

// 子网
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID)
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID, req.Region)
if err != nil {
return formItems, err
}
Expand All @@ -167,7 +167,7 @@ func (a *ApplicationOfCreateAzureCvm) renderNetwork() ([]formItem, error) {
formItems = append(formItems, formItem{Label: "所属的蓝鲸云区域", Value: bkCloudAreaName})

// 安全组
securityGroups, err := a.ListSecurityGroup(a.Vendor(), req.AccountID, req.CloudSecurityGroupIDs)
securityGroups, err := a.ListSecurityGroup(a.Vendor(), req.AccountID, req.Region, req.CloudSecurityGroupIDs)
securityGroupNames := make([]string, 0, len(req.CloudSecurityGroupIDs))
for _, s := range securityGroups {
securityGroupNames = append(securityGroupNames, s.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (a *ApplicationOfCreateAzureCvm) Deliver() (enumor.ApplicationStatus, map[s
func (a *ApplicationOfCreateAzureCvm) assignToBiz(cloudCvmIDs []string) ([]string, error) {
req := a.req
// 云ID查询主机
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, cloudCvmIDs)
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, req.Region, cloudCvmIDs)
if err != nil {
return []string{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ func (a *ApplicationOfCreateGcpCvm) renderNetwork() ([]formItem, error) {
formItems := make([]formItem, 0)

// VPC
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID)
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID, req.Region)
if err != nil {
return formItems, err
}
formItems = append(formItems, formItem{Label: "VPC", Value: vpcInfo.Name})

// 子网
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID)
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID, req.Region)
if err != nil {
return formItems, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (a *ApplicationOfCreateGcpCvm) Deliver() (enumor.ApplicationStatus, map[str
func (a *ApplicationOfCreateGcpCvm) assignToBiz(cloudCvmIDs []string) ([]string, error) {
req := a.req
// 云ID查询主机
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, cloudCvmIDs)
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, req.Region, cloudCvmIDs)
if err != nil {
return []string{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ func (a *ApplicationOfCreateHuaWeiCvm) renderNetwork() ([]formItem, error) {
formItems := make([]formItem, 0)

// VPC
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID)
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID, req.Region)
if err != nil {
return formItems, err
}
formItems = append(formItems, formItem{Label: "VPC", Value: vpcInfo.Name})

// 子网
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID)
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID, req.Region)
if err != nil {
return formItems, err
}
Expand All @@ -172,7 +172,7 @@ func (a *ApplicationOfCreateHuaWeiCvm) renderNetwork() ([]formItem, error) {
formItems = append(formItems, formItem{Label: "所属的蓝鲸云区域", Value: bkCloudAreaName})

// 安全组
securityGroups, err := a.ListSecurityGroup(a.Vendor(), req.AccountID, req.CloudSecurityGroupIDs)
securityGroups, err := a.ListSecurityGroup(a.Vendor(), req.AccountID, req.Region, req.CloudSecurityGroupIDs)
securityGroupNames := make([]string, 0, len(req.CloudSecurityGroupIDs))
for _, s := range securityGroups {
securityGroupNames = append(securityGroupNames, s.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (a *ApplicationOfCreateHuaWeiCvm) Deliver() (enumor.ApplicationStatus, map[
func (a *ApplicationOfCreateHuaWeiCvm) assignToBiz(cloudCvmIDs []string) ([]string, error) {
req := a.req
// 云ID查询主机
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, cloudCvmIDs)
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, req.Region, cloudCvmIDs)
if err != nil {
return []string{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ func (a *ApplicationOfCreateTCloudCvm) renderNetwork() ([]formItem, error) {
formItems := make([]formItem, 0)

// VPC
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID)
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, req.CloudVpcID, req.Region)
if err != nil {
return formItems, err
}
formItems = append(formItems, formItem{Label: "VPC", Value: vpcInfo.Name})

// 子网
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID)
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, req.CloudVpcID, req.CloudSubnetID, req.Region)
if err != nil {
return formItems, err
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func (a *ApplicationOfCreateTCloudCvm) renderNetwork() ([]formItem, error) {
formItems = append(formItems, formItem{Label: "所属的蓝鲸云区域", Value: bkCloudAreaName})

// 安全组
securityGroups, err := a.ListSecurityGroup(a.Vendor(), req.AccountID, req.CloudSecurityGroupIDs)
securityGroups, err := a.ListSecurityGroup(a.Vendor(), req.AccountID, req.Region, req.CloudSecurityGroupIDs)
securityGroupNames := make([]string, 0, len(req.CloudSecurityGroupIDs))
for _, s := range securityGroups {
securityGroupNames = append(securityGroupNames, s.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (a *ApplicationOfCreateTCloudCvm) Deliver() (enumor.ApplicationStatus, map[
func (a *ApplicationOfCreateTCloudCvm) assignToBiz(cloudCvmIDs []string) ([]string, error) {
req := a.req
// 云ID查询主机
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, cloudCvmIDs)
cvmInfo, err := a.ListCvm(a.Vendor(), req.AccountID, req.Region, cloudCvmIDs)
if err != nil {
return []string{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func (a *ApplicationOfCreateAwsDisk) Deliver() (status enumor.ApplicationStatus,
}

return logics.CheckResultAndAssign(a.Cts.Kit, a.Client.DataService(), result, uint32(a.req.DiskCount),
a.req.BkBizID, a.Audit)
a.req.BkBizID, a.Audit, a.req.Region, enumor.Aws)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func (a *ApplicationOfCreateAzureDisk) Deliver() (status enumor.ApplicationStatu
}

return logics.CheckResultAndAssign(a.Cts.Kit, a.Client.DataService(), result, uint32(a.req.DiskCount),
a.req.BkBizID, a.Audit)
a.req.BkBizID, a.Audit, a.req.Region, enumor.Azure)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func (a *ApplicationOfCreateGcpDisk) Deliver() (status enumor.ApplicationStatus,
}

return logics.CheckResultAndAssign(a.Cts.Kit, a.Client.DataService(), result, uint32(a.req.DiskCount),
a.req.BkBizID, a.Audit)
a.req.BkBizID, a.Audit, a.req.Region, enumor.Gcp)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func (a *ApplicationOfCreateHuaWeiDisk) Deliver() (enumor.ApplicationStatus, map
}

return logics.CheckResultAndAssign(a.Cts.Kit, a.Client.DataService(), result, uint32(a.req.DiskCount),
a.req.BkBizID, a.Audit)
a.req.BkBizID, a.Audit, a.req.Region, enumor.HuaWei)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (

// CheckResultAndAssign ...
func CheckResultAndAssign(kt *kit.Kit, cli *dataservice.Client, result *hcproto.BatchCreateResult,
diskCount uint32, bkBizID int64,
audit audit.Interface) (enumor.ApplicationStatus, map[string]interface{}, error) {
diskCount uint32, bkBizID int64, audit audit.Interface, region string, vendor enumor.Vendor) (
enumor.ApplicationStatus, map[string]interface{}, error) {

deliverDetail := map[string]interface{}{"result": result}

Expand All @@ -53,7 +53,11 @@ func CheckResultAndAssign(kt *kit.Kit, cli *dataservice.Client, result *hcproto.
}

listReq := &core.ListReq{
Filter: tools.ContainersExpression("cloud_id", result.SuccessCloudIDs),
Filter: tools.ExpressionAnd(
tools.RuleIn("cloud_id", result.SuccessCloudIDs),
tools.RuleEqual("region", region),
tools.RuleEqual("vendor", vendor),
),
Page: core.NewDefaultBasePage(),
Fields: []string{"id"},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func (a *ApplicationOfCreateTCloudDisk) Deliver() (enumor.ApplicationStatus, map
}

return logics.CheckResultAndAssign(a.Cts.Kit, a.Client.DataService(), result, a.req.DiskCount,
a.req.BkBizID, a.Audit)
a.req.BkBizID, a.Audit, a.req.Region, enumor.TCloud)
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (a *ApplicationOfCreateTCloudLB) renderNetwork() ([]formItem, error) {
// VPC
vpcName := "未指定-默认VPC"
if req.CloudVpcID != nil {
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, cvt.PtrToVal(req.CloudVpcID))
vpcInfo, err := a.GetVpc(a.Vendor(), req.AccountID, cvt.PtrToVal(req.CloudVpcID), req.Region)
if err != nil {
return formItems, err
}
Expand All @@ -174,7 +174,7 @@ func (a *ApplicationOfCreateTCloudLB) renderNetwork() ([]formItem, error) {
if req.CloudVpcID != nil && req.CloudSubnetID != nil {
// 子网
subnetInfo, err := a.GetSubnet(a.Vendor(), req.AccountID, cvt.PtrToVal(req.CloudVpcID),
cvt.PtrToVal(req.CloudSubnetID))
cvt.PtrToVal(req.CloudSubnetID), req.Region)
if err != nil {
return formItems, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,13 @@ func (svc *lbSvc) initFlowAddTargetByLbID(kt *kit.Kit, accountID, lbID string,
func (svc *lbSvc) convTCloudAddTargetReq(kt *kit.Kit, targets []*dataproto.TargetBaseReq, lbID, targetGroupID,
accountID string) (*hcproto.TCloudBatchOperateTargetReq, error) {

instMap, err := svc.getInstWithTargetMap(kt, targets)
tg, err := svc.getTargetGroupByID(kt, targetGroupID)
if err != nil {
logs.Errorf("get target group by id failed, err: %v, tgID: %s, rid: %s", err, targetGroupID, kt.Rid)
return nil, err
}

instMap, err := svc.getInstWithTargetMap(kt, targets, tg.Region, tg.Vendor)
if err != nil {
return nil, err
}
Expand All @@ -337,8 +343,8 @@ func (svc *lbSvc) convTCloudAddTargetReq(kt *kit.Kit, targets []*dataproto.Targe
return rsReq, nil
}

func (svc *lbSvc) getInstWithTargetMap(kt *kit.Kit, targets []*dataproto.TargetBaseReq) (
map[string]corecvm.BaseCvm, error) {
func (svc *lbSvc) getInstWithTargetMap(kt *kit.Kit, targets []*dataproto.TargetBaseReq, region string,
vendor enumor.Vendor) (map[string]corecvm.BaseCvm, error) {

cloudCvmIDs := make([]string, 0)
for _, item := range targets {
Expand All @@ -351,8 +357,12 @@ func (svc *lbSvc) getInstWithTargetMap(kt *kit.Kit, targets []*dataproto.TargetB
cvmMap := make(map[string]corecvm.BaseCvm)
if len(cloudCvmIDs) > 0 {
cvmReq := &core.ListReq{
Filter: tools.ContainersExpression("cloud_id", cloudCvmIDs),
Page: core.NewDefaultBasePage(),
Filter: tools.ExpressionAnd(
tools.RuleIn("cloud_id", cloudCvmIDs),
tools.RuleEqual("region", region),
tools.RuleEqual("vendor", vendor),
),
Page: core.NewDefaultBasePage(),
}
cvmList, err := svc.client.DataService().Global.Cvm.ListCvm(kt, cvmReq)
if err != nil {
Expand Down
Loading