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: CLB Excel导入-四层监听器绑定RS --story=11958949 #1072

Open
wants to merge 2 commits into
base: feat-loadbalancer
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
77 changes: 75 additions & 2 deletions cmd/cloud-server/logics/load-balancer/import_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ package lblogic
import (
"encoding/json"
"fmt"

actionlb "hcm/cmd/task-server/logics/action/load-balancer"
taskCore "hcm/pkg/api/core/task"
"hcm/pkg/api/data-service/task"
"hcm/pkg/api/hc-service/sync"
ts "hcm/pkg/api/task-server"
"hcm/pkg/async/action"
Expand All @@ -31,6 +34,7 @@ import (
"hcm/pkg/criteria/enumor"
tableasync "hcm/pkg/dal/table/async"
"hcm/pkg/kit"
"hcm/pkg/logs"
)

// ImportExecutor 导入执行器
Expand Down Expand Up @@ -65,8 +69,8 @@ func NewImportExecutor(operationType OperationType, dataCli *dataservice.Client,
return newCreateLayer7ListenerExecutor(dataCli, taskCli, vendor, bkBizID, accountID, regionIDs), nil
//case CreateUrlRule:
// return newCreateUrlRuleExecutor(dataCli, taskCli, vendor, bkBizID, accountID, regionIDs), nil
//case Layer4ListenerBindRs:
// return newLayer4ListenerBindRSExecutor(dataCli, taskCli, vendor, bkBizID, accountID, regionIDs), nil
case Layer4ListenerBindRs:
return newLayer4ListenerBindRSExecutor(dataCli, taskCli, vendor, bkBizID, accountID, regionIDs), nil
//case Layer7ListenerBindRs:
// return newLayer7ListenerBindRSExecutor(dataCli, taskCli, vendor, bkBizID, accountID, regionIDs), nil
default:
Expand All @@ -90,3 +94,72 @@ func buildSyncClbFlowTask(lbCloudID, accountID, region string, generator func()
}
return tmpTask
}

func createTaskManagement(kt *kit.Kit, cli *dataservice.Client, bkBizID int64, vendor enumor.Vendor, accountID string,
regionIDs []string, source enumor.TaskManagementSource, operation enumor.TaskOperation) (string, error) {

taskManagementCreateReq := &task.CreateManagementReq{
Items: []task.CreateManagementField{
{
BkBizID: bkBizID,
Source: source,
Vendor: vendor,
AccountID: accountID,
Resource: enumor.TaskManagementResClb,
State: enumor.TaskManagementRunning,
Operations: []enumor.TaskOperation{operation},
Extension: &taskCore.ManagementExt{RegionIDs: regionIDs},
},
},
}

result, err := cli.Global.TaskManagement.Create(kt, taskManagementCreateReq)
if err != nil {
return "", err
}
if len(result.IDs) == 0 {
return "", fmt.Errorf("create task management failed")
}
return result.IDs[0], nil
}

func updateTaskManagement(kt *kit.Kit, cli *dataservice.Client, taskID string, flowIDs []string) error {

if len(flowIDs) == 0 {
return nil
}
updateItem := task.UpdateTaskManagementField{
ID: taskID,
FlowIDs: flowIDs,
}
updateReq := &task.UpdateManagementReq{
Items: []task.UpdateTaskManagementField{updateItem},
}
err := cli.Global.TaskManagement.Update(kt, updateReq)
if err != nil {
logs.Errorf("update task management failed, err: %v, rid: %s", err, kt.Rid)
return err
}
return nil
}

func updateTaskDetailState(kt *kit.Kit, cli *dataservice.Client, state enumor.TaskDetailState, ids []string) error {
if len(ids) == 0 {
return nil
}
updateItems := make([]task.UpdateTaskDetailField, 0, len(ids))
for _, id := range ids {
updateItems = append(updateItems, task.UpdateTaskDetailField{
ID: id,
State: state,
})
}
updateDetailsReq := &task.UpdateDetailReq{
Items: updateItems,
}
err := cli.Global.TaskDetail.Update(kt, updateDetailsReq)
if err != nil {
return err
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func NewImportPreviewExecutor(operationType OperationType, service *dataservice.
return newCreateLayer7ListenerPreviewExecutor(service, vendor, bkBizID, accountID, regionIDs), nil
//case CreateUrlRule:
// return newCreateUrlRulePreviewExecutor(service, vendor, bkBizID, accountID, regionIDs), nil
//case Layer4ListenerBindRs:
// return newLayer4ListenerBindRSPreviewExecutor(service, vendor, bkBizID, accountID, regionIDs), nil
case Layer4ListenerBindRs:
return newLayer4ListenerBindRSPreviewExecutor(service, vendor, bkBizID, accountID, regionIDs), nil
//case Layer7ListenerBindRs:
// return newLayer7ListenerBindRSPreviewExecutor(service, vendor, bkBizID, accountID, regionIDs), nil
default:
Expand Down
Loading