Skip to content

Commit b98e673

Browse files
Merge pull request #643 from actiontech/dms/feat-2983
Dms/feat 2983
2 parents fa090a0 + 8603397 commit b98e673

10 files changed

Lines changed: 48 additions & 33 deletions

File tree

api/dms/service/v1/db_service.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,12 @@ type ListDBServiceTipsReq struct {
264264
}
265265

266266
type ListDBServiceTipItem struct {
267-
Id string `json:"id"`
268-
Name string `json:"name"`
269-
Type string `json:"db_type"`
270-
Host string `json:"host"`
271-
Port string `json:"port"`
267+
Id string `json:"id"`
268+
Name string `json:"name"`
269+
Type string `json:"db_type"`
270+
Host string `json:"host"`
271+
Port string `json:"port"`
272+
EnvironmentTag *dmsCommonV1.EnvironmentTag `json:"environment_tag,omitempty"`
272273
}
273274

274275
// swagger:model ListDBServiceTipsReply

api/dms/service/v1/environment_tag.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type CreateEnvironmentTagReq struct {
1010
// swagger:ignore
1111
ProjectUID string `param:"project_uid" json:"project_uid" validate:"required"`
1212
Name string `json:"environment_name" validate:"required,min=1,max=50"`
13+
Color string `json:"color" validate:"omitempty,max=32"`
1314
}
1415

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

22-
Name string `json:"environment_name" validate:"required,min=1,max=50"`
23+
Name string `json:"environment_name" validate:"required,min=1,max=50"`
24+
Color string `json:"color" validate:"omitempty,max=32"`
2325
}
2426

2527
// swagger:parameters ListEnvironmentTags

internal/apiserver/service/dms_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (ctl *DMSController) CreateEnvironmentTag(c echo.Context) error {
109109
return NewErrResp(c, err, apiError.DMSServiceErr)
110110
}
111111

112-
err = ctl.DMS.CreateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.Name)
112+
err = ctl.DMS.CreateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.Name, req.Color)
113113
if nil != err {
114114
return NewErrResp(c, err, apiError.DMSServiceErr)
115115
}
@@ -160,7 +160,7 @@ func (ctl *DMSController) UpdateEnvironmentTag(c echo.Context) error {
160160
return NewErrResp(c, err, apiError.DMSServiceErr)
161161
}
162162

163-
err = ctl.DMS.UpdateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.EnvironmentTagUID, req.Name)
163+
err = ctl.DMS.UpdateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.EnvironmentTagUID, req.Name, req.Color)
164164
if nil != err {
165165
return NewErrResp(c, err, apiError.DMSServiceErr)
166166
}

internal/dms/biz/environment_tag.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
type EnvironmentTagRepo interface {
1212
CreateEnvironmentTag(ctx context.Context, environmentTag *EnvironmentTag) error
13-
UpdateEnvironmentTag(ctx context.Context, environmentTagName, environmentTagUID string) error
13+
UpdateEnvironmentTag(ctx context.Context, environmentTagUID, environmentTagName, color string) error
1414
DeleteEnvironmentTag(ctx context.Context, environmentTagUID string) error
1515
GetEnvironmentTagByName(ctx context.Context, projectUid, name string) (bool, *EnvironmentTag, error)
1616
GetEnvironmentTagByUID(ctx context.Context, uid string) (*EnvironmentTag, error)
@@ -39,9 +39,10 @@ type EnvironmentTag struct {
3939
UID string
4040
Name string
4141
ProjectUID string
42+
Color string
4243
}
4344

44-
func (uc *EnvironmentTagUsecase) newEnvironmentTag(projectUid, tagName string) (*EnvironmentTag, error) {
45+
func (uc *EnvironmentTagUsecase) newEnvironmentTag(projectUid, tagName, color string) (*EnvironmentTag, error) {
4546
uid, err := pkgRand.GenStrUid()
4647
if err != nil {
4748
return nil, err
@@ -53,6 +54,7 @@ func (uc *EnvironmentTagUsecase) newEnvironmentTag(projectUid, tagName string) (
5354
UID: uid,
5455
Name: tagName,
5556
ProjectUID: projectUid,
57+
Color: color,
5658
}, nil
5759
}
5860

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

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

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

112-
func (uc *EnvironmentTagUsecase) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagUID, environmentTagName string) error {
114+
func (uc *EnvironmentTagUsecase) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagUID, environmentTagName, color string) error {
113115
// 检查项目是否归档/删除
114116
if err := uc.projectUsecase.isProjectActive(ctx, projectUid); err != nil {
115117
return fmt.Errorf("update db service error: %v", err)
@@ -130,7 +132,7 @@ func (uc *EnvironmentTagUsecase) UpdateEnvironmentTag(ctx context.Context, proje
130132
uc.log.Errorf("get environment tag failed: %v", err)
131133
return err
132134
}
133-
err = uc.environmentTagRepo.UpdateEnvironmentTag(ctx, environmentTagUID, environmentTagName)
135+
err = uc.environmentTagRepo.UpdateEnvironmentTag(ctx, environmentTagUID, environmentTagName, color)
134136
if err != nil {
135137
uc.log.Errorf("update environment tag failed: %v", err)
136138
return err
@@ -206,7 +208,7 @@ func (uc *EnvironmentTagUsecase) GetOrCreateEnvironmentTag(ctx context.Context,
206208
if exist {
207209
return environmentTag, nil
208210
}
209-
newTag, err := uc.newEnvironmentTag(projectUid, tagName)
211+
newTag, err := uc.newEnvironmentTag(projectUid, tagName, "")
210212
if err != nil {
211213
uc.log.Errorf("new environment tag failed: %v", err)
212214
return nil, err

internal/dms/service/db_service.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,12 @@ func (d *DMSService) ListDBServiceTips(ctx context.Context, req *dmsV1.ListDBSer
715715
ret := make([]*dmsV1.ListDBServiceTipItem, 0, len(dbServices))
716716
for _, item := range dbServices {
717717
ret = append(ret, &dmsV1.ListDBServiceTipItem{
718-
Id: item.UID,
719-
Name: item.Name,
720-
Host: item.Host,
721-
Port: item.Port,
722-
Type: item.DBType,
718+
Id: item.UID,
719+
Name: item.Name,
720+
Host: item.Host,
721+
Port: item.Port,
722+
Type: item.DBType,
723+
EnvironmentTag: item.EnvironmentTag,
723724
})
724725
}
725726

internal/dms/service/environment_tag.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ import (
1010
dmsCommonV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
1111
)
1212

13-
func (d *DMSService) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagName string) (err error) {
13+
func (d *DMSService) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagName, color string) (err error) {
1414
d.log.Infof("CreateEnvironmentTag.req=%v", environmentTagName)
1515
defer func() {
1616
d.log.Infof("CreateEnvironmentTag.req=%v;error=%v", environmentTagName, err)
1717
}()
1818

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

2323
return nil
2424
}
2525

26-
func (d *DMSService) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid string, environmentTagUID, environmentTagName string) (err error) {
26+
func (d *DMSService) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid string, environmentTagUID, environmentTagName, color string) (err error) {
2727
d.log.Infof("UpdateEnvironmentTag.req=%v", environmentTagName)
2828
defer func() {
2929
d.log.Infof("UpdateEnvironmentTag.req=%v;error=%v", environmentTagName, err)
3030
}()
3131

32-
if err := d.EnvironmentTagUsecase.UpdateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagUID, environmentTagName); err != nil {
32+
if err := d.EnvironmentTagUsecase.UpdateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagUID, environmentTagName, color); err != nil {
3333
return fmt.Errorf("update environment tag failed: %w", err)
3434
}
3535
return nil
@@ -82,8 +82,9 @@ func (d *DMSService) ListEnvironmentTags(ctx context.Context, req *v1.ListEnviro
8282
environmentTags := make([]*dmsCommonV1.EnvironmentTag, 0, len(bizEnvironmentTags))
8383
for _, bizEnvironmentTag := range bizEnvironmentTags {
8484
environmentTags = append(environmentTags, &dmsCommonV1.EnvironmentTag{
85-
UID: bizEnvironmentTag.UID,
86-
Name: bizEnvironmentTag.Name,
85+
UID: bizEnvironmentTag.UID,
86+
Name: bizEnvironmentTag.Name,
87+
Color: bizEnvironmentTag.Color,
8788
})
8889
}
8990
return &v1.ListEnvironmentTagsReply{

internal/dms/storage/convert.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ func convertModelDBService(ds *model.DBService) (*biz.DBService, error) {
129129

130130
if ds.EnvironmentTag != nil {
131131
dbService.EnvironmentTag = &dmsCommonV1.EnvironmentTag{
132-
UID: ds.EnvironmentTagUID,
133-
Name: ds.EnvironmentTag.EnvironmentName,
132+
UID: ds.EnvironmentTagUID,
133+
Name: ds.EnvironmentTag.EnvironmentName,
134+
Color: ds.EnvironmentTag.Color,
134135
}
135136
}
136137

internal/dms/storage/environment_tag.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func (repo *EnvironmentTagRepo) toModel(environmentTag *biz.EnvironmentTag) *mod
3030
EnvironmentName: environmentTag.Name,
3131
Model: model.Model{UID: environmentTag.UID},
3232
ProjectUID: environmentTag.ProjectUID,
33+
Color: environmentTag.Color,
3334
}
3435
}
3536

@@ -38,6 +39,7 @@ func (repo *EnvironmentTagRepo) toBiz(environmentTag *model.EnvironmentTag) *biz
3839
Name: environmentTag.EnvironmentName,
3940
UID: environmentTag.UID,
4041
ProjectUID: environmentTag.ProjectUID,
42+
Color: environmentTag.Color,
4143
}
4244
}
4345

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

53-
func (repo *EnvironmentTagRepo) UpdateEnvironmentTag(ctx context.Context, environmentTagUID, environmentTagName string) error {
55+
func (repo *EnvironmentTagRepo) UpdateEnvironmentTag(ctx context.Context, environmentTagUID, environmentTagName, color string) error {
5456
return transaction(repo.log, ctx, repo.db, func(tx *gorm.DB) error {
55-
if err := tx.WithContext(ctx).Model(&model.EnvironmentTag{}).Where("uid = ?", environmentTagUID).Update("environment_name", environmentTagName).Error; err != nil {
57+
if err := tx.WithContext(ctx).Model(&model.EnvironmentTag{}).Where("uid = ?", environmentTagUID).Updates(map[string]interface{}{
58+
"environment_name": environmentTagName,
59+
"color": color,
60+
}).Error; err != nil {
5661
return pkgErr.WrapStorageErr(repo.log, fmt.Errorf("failed to update environment tag: %v", err))
5762
}
5863
return nil

internal/dms/storage/model/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ type EnvironmentTag struct {
9595
Model
9696
ProjectUID string `json:"project_uid" gorm:"size:32;column:project_uid;index:project_uid_name"`
9797
EnvironmentName string `json:"environment_name" gorm:"not null;index:project_uid_name"`
98+
Color string `json:"color" gorm:"size:32;column:color"`
9899
}
99100

100101
type ExtraParameters struct {

pkg/dms-common/api/dms/v1/db_service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ type ListDBService struct {
170170
type EnvironmentTag struct {
171171
UID string `json:"uid,omitempty"`
172172
// 环境属性标签最多50个字符
173-
Name string `json:"name" validate:"max=50"`
173+
Name string `json:"name" validate:"max=50"`
174+
Color string `json:"color,omitempty" validate:"omitempty,max=32"`
174175
}
175176

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

212213
// swagger:model ListDBServiceReply

0 commit comments

Comments
 (0)