-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backend): dbconfig增加转移业务api #9043
- Loading branch information
Showing
9 changed files
with
145 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
dbm-services/common/db-config/internal/handler/simple/change_bk_biz_id.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package simple | ||
|
||
import ( | ||
"bk-dbconfig/internal/api" | ||
"bk-dbconfig/internal/handler" | ||
"bk-dbconfig/internal/service/simpleconfig" | ||
|
||
"github.com/gin-gonic/gin" | ||
|
||
"dbm-services/common/go-pubpkg/validate" | ||
) | ||
|
||
// ChangeBizBizId godoc | ||
// | ||
// @Summary 修改集群的业务 | ||
// @Description 修改集群的业务归属 | ||
// @Tags config_version | ||
// @Accept json | ||
// @Produce json | ||
// @Param body body api.ChangeBkBizIdReq true "change bk_biz_id for clusters" | ||
// @Success 200 {object} api.ChangeBkBizIdResp | ||
// @Failure 400 {object} api.HTTPClientErrResp | ||
// @Router /bkconfig/v1/version/change_bk_biz_id [post] | ||
func (cf *Config) ChangeBizBizId(ctx *gin.Context) { | ||
var r api.ChangeBkBizIdReq | ||
var resp *api.ChangeBkBizIdResp | ||
var err error | ||
if err = ctx.BindJSON(&r); err != nil { | ||
handler.SendResponse(ctx, err, nil) | ||
return | ||
} | ||
if err := validate.GoValidateStruct(r, false); err != nil { | ||
handler.SendResponse(ctx, err, nil) | ||
return | ||
} | ||
//r.ClusterDomains = cmutil.UniqueStrings(r.ClusterDomains) | ||
if resp, err = simpleconfig.ChangeBkBizId(&r, ""); err != nil { | ||
handler.SendResponse(ctx, err, nil) | ||
return | ||
} | ||
resp.ClusterReceived = len(r.ClusterDomains) | ||
handler.SendResponse(ctx, nil, resp) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
dbm-services/common/db-config/internal/service/simpleconfig/change_bk_biz_id.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. | ||
// Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
// Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations under the License. | ||
|
||
package simpleconfig | ||
|
||
import ( | ||
"bk-dbconfig/internal/api" | ||
"bk-dbconfig/internal/repository/model" | ||
"bk-dbconfig/pkg/constvar" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
// ChangeBkBizId 修改集群的业务 id | ||
// 返回影响 tb_config_versioned 表的记录数 | ||
func ChangeBkBizId(r *api.ChangeBkBizIdReq, opUser string) (*api.ChangeBkBizIdResp, error) { | ||
var rowsAffected int64 | ||
txErr := model.DB.Self.Transaction(func(tx *gorm.DB) error { | ||
updateVersioned := tx.Model(&model.ConfigVersionedModel{}). | ||
Where("bk_biz_id = ? and level_value in ? and level_name = ?", | ||
r.BKBizID, r.ClusterDomains, constvar.LevelCluster). | ||
Update("bk_biz_id", r.NewBKBizID) | ||
if err := updateVersioned.Error; err != nil { | ||
return err | ||
} else { | ||
rowsAffected = updateVersioned.RowsAffected | ||
} | ||
|
||
updateConfigNode := tx.Model(&model.ConfigModel{}). | ||
Where("bk_biz_id = ? and level_value in ? and level_name = ?", | ||
r.BKBizID, r.ClusterDomains, constvar.LevelCluster). | ||
Update("bk_biz_id", r.NewBKBizID) | ||
if err := updateConfigNode.Error; err != nil { | ||
return err | ||
} | ||
|
||
updateFileNode := tx.Model(&model.ConfigFileNodeModel{}). | ||
Where("bk_biz_id = ? and level_value in ? and level_name = ?", | ||
r.BKBizID, r.ClusterDomains, constvar.LevelCluster). | ||
Update("bk_biz_id", r.NewBKBizID) | ||
if err := updateFileNode.Error; err != nil { | ||
return err | ||
} | ||
return nil | ||
}) | ||
|
||
if txErr == nil { | ||
return &api.ChangeBkBizIdResp{ClustersAffected: rowsAffected}, nil | ||
} | ||
return nil, txErr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters