Skip to content
Merged
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
11 changes: 6 additions & 5 deletions api/dms/service/v1/db_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,12 @@ type ListDBServiceTipsReq struct {
}

type ListDBServiceTipItem struct {
Id string `json:"id"`
Name string `json:"name"`
Type string `json:"db_type"`
Host string `json:"host"`
Port string `json:"port"`
Id string `json:"id"`
Name string `json:"name"`
Type string `json:"db_type"`
Host string `json:"host"`
Port string `json:"port"`
EnvironmentTag *dmsCommonV1.EnvironmentTag `json:"environment_tag,omitempty"`
}

// swagger:model ListDBServiceTipsReply
Expand Down
4 changes: 3 additions & 1 deletion api/dms/service/v1/environment_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type CreateEnvironmentTagReq struct {
// swagger:ignore
ProjectUID string `param:"project_uid" json:"project_uid" validate:"required"`
Name string `json:"environment_name" validate:"required,min=1,max=50"`
Color string `json:"color" validate:"omitempty,max=32"`
}

// swagger:model
Expand All @@ -19,7 +20,8 @@ type UpdateEnvironmentTagReq struct {
// swagger:ignore
ProjectUID string `param:"project_uid" json:"project_uid" validate:"required"`

Name string `json:"environment_name" validate:"required,min=1,max=50"`
Name string `json:"environment_name" validate:"required,min=1,max=50"`
Color string `json:"color" validate:"omitempty,max=32"`
}

// swagger:parameters ListEnvironmentTags
Expand Down
4 changes: 2 additions & 2 deletions internal/apiserver/service/dms_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (ctl *DMSController) CreateEnvironmentTag(c echo.Context) error {
return NewErrResp(c, err, apiError.DMSServiceErr)
}

err = ctl.DMS.CreateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.Name)
err = ctl.DMS.CreateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.Name, req.Color)
if nil != err {
return NewErrResp(c, err, apiError.DMSServiceErr)
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (ctl *DMSController) UpdateEnvironmentTag(c echo.Context) error {
return NewErrResp(c, err, apiError.DMSServiceErr)
}

err = ctl.DMS.UpdateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.EnvironmentTagUID, req.Name)
err = ctl.DMS.UpdateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.EnvironmentTagUID, req.Name, req.Color)
if nil != err {
return NewErrResp(c, err, apiError.DMSServiceErr)
}
Expand Down
18 changes: 10 additions & 8 deletions internal/dms/biz/environment_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type EnvironmentTagRepo interface {
CreateEnvironmentTag(ctx context.Context, environmentTag *EnvironmentTag) error
UpdateEnvironmentTag(ctx context.Context, environmentTagName, environmentTagUID string) error
UpdateEnvironmentTag(ctx context.Context, environmentTagUID, environmentTagName, color string) error
DeleteEnvironmentTag(ctx context.Context, environmentTagUID string) error
GetEnvironmentTagByName(ctx context.Context, projectUid, name string) (bool, *EnvironmentTag, error)
GetEnvironmentTagByUID(ctx context.Context, uid string) (*EnvironmentTag, error)
Expand Down Expand Up @@ -39,9 +39,10 @@ type EnvironmentTag struct {
UID string
Name string
ProjectUID string
Color string
}

func (uc *EnvironmentTagUsecase) newEnvironmentTag(projectUid, tagName string) (*EnvironmentTag, error) {
func (uc *EnvironmentTagUsecase) newEnvironmentTag(projectUid, tagName, color string) (*EnvironmentTag, error) {
uid, err := pkgRand.GenStrUid()
if err != nil {
return nil, err
Expand All @@ -53,6 +54,7 @@ func (uc *EnvironmentTagUsecase) newEnvironmentTag(projectUid, tagName string) (
UID: uid,
Name: tagName,
ProjectUID: projectUid,
Color: color,
}, nil
}

Expand All @@ -66,7 +68,7 @@ func (uc *EnvironmentTagUsecase) InitDefaultEnvironmentTags(ctx context.Context,
}

for _, environmentTag := range defaultEnvironmentTags {
err = uc.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTag)
err = uc.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTag, "")
if err != nil {
uc.log.Errorf("create environment tag failed: %v", err)
return fmt.Errorf("create environment tag failed: %w", err)
Expand All @@ -75,7 +77,7 @@ func (uc *EnvironmentTagUsecase) InitDefaultEnvironmentTags(ctx context.Context,
return nil
}

func (uc *EnvironmentTagUsecase) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, tagName string) error {
func (uc *EnvironmentTagUsecase) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, tagName, color string) error {
// 检查项目是否归档/删除
if err := uc.projectUsecase.isProjectActive(ctx, projectUid); err != nil {
return fmt.Errorf("update db service error: %v", err)
Expand All @@ -96,7 +98,7 @@ func (uc *EnvironmentTagUsecase) CreateEnvironmentTag(ctx context.Context, proje
if exist {
return fmt.Errorf("the tag %s already exists in the current project", tagName)
}
environmentTag, err := uc.newEnvironmentTag(projectUid, tagName)
environmentTag, err := uc.newEnvironmentTag(projectUid, tagName, color)
if err != nil {
uc.log.Errorf("new environment tag failed: %v", err)
return err
Expand All @@ -109,7 +111,7 @@ func (uc *EnvironmentTagUsecase) CreateEnvironmentTag(ctx context.Context, proje
return nil
}

func (uc *EnvironmentTagUsecase) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagUID, environmentTagName string) error {
func (uc *EnvironmentTagUsecase) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagUID, environmentTagName, color string) error {
// 检查项目是否归档/删除
if err := uc.projectUsecase.isProjectActive(ctx, projectUid); err != nil {
return fmt.Errorf("update db service error: %v", err)
Expand All @@ -130,7 +132,7 @@ func (uc *EnvironmentTagUsecase) UpdateEnvironmentTag(ctx context.Context, proje
uc.log.Errorf("get environment tag failed: %v", err)
return err
}
err = uc.environmentTagRepo.UpdateEnvironmentTag(ctx, environmentTagUID, environmentTagName)
err = uc.environmentTagRepo.UpdateEnvironmentTag(ctx, environmentTagUID, environmentTagName, color)
if err != nil {
uc.log.Errorf("update environment tag failed: %v", err)
return err
Expand Down Expand Up @@ -206,7 +208,7 @@ func (uc *EnvironmentTagUsecase) GetOrCreateEnvironmentTag(ctx context.Context,
if exist {
return environmentTag, nil
}
newTag, err := uc.newEnvironmentTag(projectUid, tagName)
newTag, err := uc.newEnvironmentTag(projectUid, tagName, "")
if err != nil {
uc.log.Errorf("new environment tag failed: %v", err)
return nil, err
Expand Down
11 changes: 6 additions & 5 deletions internal/dms/service/db_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,12 @@ func (d *DMSService) ListDBServiceTips(ctx context.Context, req *dmsV1.ListDBSer
ret := make([]*dmsV1.ListDBServiceTipItem, 0, len(dbServices))
for _, item := range dbServices {
ret = append(ret, &dmsV1.ListDBServiceTipItem{
Id: item.UID,
Name: item.Name,
Host: item.Host,
Port: item.Port,
Type: item.DBType,
Id: item.UID,
Name: item.Name,
Host: item.Host,
Port: item.Port,
Type: item.DBType,
EnvironmentTag: item.EnvironmentTag,
})
}

Expand Down
13 changes: 7 additions & 6 deletions internal/dms/service/environment_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import (
dmsCommonV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
)

func (d *DMSService) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagName string) (err error) {
func (d *DMSService) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagName, color string) (err error) {
d.log.Infof("CreateEnvironmentTag.req=%v", environmentTagName)
defer func() {
d.log.Infof("CreateEnvironmentTag.req=%v;error=%v", environmentTagName, err)
}()

if err := d.EnvironmentTagUsecase.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagName); err != nil {
if err := d.EnvironmentTagUsecase.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagName, color); err != nil {
return fmt.Errorf("create environment tag failed: %w", err)
}

return nil
}

func (d *DMSService) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid string, environmentTagUID, environmentTagName string) (err error) {
func (d *DMSService) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid string, environmentTagUID, environmentTagName, color string) (err error) {
d.log.Infof("UpdateEnvironmentTag.req=%v", environmentTagName)
defer func() {
d.log.Infof("UpdateEnvironmentTag.req=%v;error=%v", environmentTagName, err)
}()

if err := d.EnvironmentTagUsecase.UpdateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagUID, environmentTagName); err != nil {
if err := d.EnvironmentTagUsecase.UpdateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagUID, environmentTagName, color); err != nil {
return fmt.Errorf("update environment tag failed: %w", err)
}
return nil
Expand Down Expand Up @@ -82,8 +82,9 @@ func (d *DMSService) ListEnvironmentTags(ctx context.Context, req *v1.ListEnviro
environmentTags := make([]*dmsCommonV1.EnvironmentTag, 0, len(bizEnvironmentTags))
for _, bizEnvironmentTag := range bizEnvironmentTags {
environmentTags = append(environmentTags, &dmsCommonV1.EnvironmentTag{
UID: bizEnvironmentTag.UID,
Name: bizEnvironmentTag.Name,
UID: bizEnvironmentTag.UID,
Name: bizEnvironmentTag.Name,
Color: bizEnvironmentTag.Color,
})
}
return &v1.ListEnvironmentTagsReply{
Expand Down
5 changes: 3 additions & 2 deletions internal/dms/storage/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ func convertModelDBService(ds *model.DBService) (*biz.DBService, error) {

if ds.EnvironmentTag != nil {
dbService.EnvironmentTag = &dmsCommonV1.EnvironmentTag{
UID: ds.EnvironmentTagUID,
Name: ds.EnvironmentTag.EnvironmentName,
UID: ds.EnvironmentTagUID,
Name: ds.EnvironmentTag.EnvironmentName,
Color: ds.EnvironmentTag.Color,
}
}

Expand Down
9 changes: 7 additions & 2 deletions internal/dms/storage/environment_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (repo *EnvironmentTagRepo) toModel(environmentTag *biz.EnvironmentTag) *mod
EnvironmentName: environmentTag.Name,
Model: model.Model{UID: environmentTag.UID},
ProjectUID: environmentTag.ProjectUID,
Color: environmentTag.Color,
}
}

Expand All @@ -38,6 +39,7 @@ func (repo *EnvironmentTagRepo) toBiz(environmentTag *model.EnvironmentTag) *biz
Name: environmentTag.EnvironmentName,
UID: environmentTag.UID,
ProjectUID: environmentTag.ProjectUID,
Color: environmentTag.Color,
}
}

Expand All @@ -50,9 +52,12 @@ func (repo *EnvironmentTagRepo) CreateEnvironmentTag(ctx context.Context, enviro
})
}

func (repo *EnvironmentTagRepo) UpdateEnvironmentTag(ctx context.Context, environmentTagUID, environmentTagName string) error {
func (repo *EnvironmentTagRepo) UpdateEnvironmentTag(ctx context.Context, environmentTagUID, environmentTagName, color string) error {
return transaction(repo.log, ctx, repo.db, func(tx *gorm.DB) error {
if err := tx.WithContext(ctx).Model(&model.EnvironmentTag{}).Where("uid = ?", environmentTagUID).Update("environment_name", environmentTagName).Error; err != nil {
if err := tx.WithContext(ctx).Model(&model.EnvironmentTag{}).Where("uid = ?", environmentTagUID).Updates(map[string]interface{}{
"environment_name": environmentTagName,
"color": color,
}).Error; err != nil {
return pkgErr.WrapStorageErr(repo.log, fmt.Errorf("failed to update environment tag: %v", err))
}
return nil
Expand Down
1 change: 1 addition & 0 deletions internal/dms/storage/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type EnvironmentTag struct {
Model
ProjectUID string `json:"project_uid" gorm:"size:32;column:project_uid;index:project_uid_name"`
EnvironmentName string `json:"environment_name" gorm:"not null;index:project_uid_name"`
Color string `json:"color" gorm:"size:32;column:color"`
}

type ExtraParameters struct {
Expand Down
5 changes: 3 additions & 2 deletions pkg/dms-common/api/dms/v1/db_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ type ListDBService struct {
type EnvironmentTag struct {
UID string `json:"uid,omitempty"`
// 环境属性标签最多50个字符
Name string `json:"name" validate:"max=50"`
Name string `json:"name" validate:"max=50"`
Color string `json:"color,omitempty" validate:"omitempty,max=32"`
}

type SQLEConfig struct {
Expand Down Expand Up @@ -206,7 +207,7 @@ type SQLQueryConfig struct {
AllowQueryWhenLessThanAuditLevel SQLAllowQueryAuditLevel `json:"allow_query_when_less_than_audit_level" enums:"normal,notice,warn,error" valid:"omitempty,oneof=normal notice warn error " example:"error"`
RuleTemplateName string `json:"rule_template_name"`
RuleTemplateID string `json:"rule_template_id"`
MaintenanceTimes []*MaintenanceTime `json:"maintenance_times"` // 允许执行非 DQL 的运维时间窗口,与数据源 maintenance_times 结构一致
MaintenanceTimes []*MaintenanceTime `json:"maintenance_times"` // 允许执行非 DQL 的运维时间窗口,与数据源 maintenance_times 结构一致
}

// swagger:model ListDBServiceReply
Expand Down