fix(region): avoid set multi resources tags failed

This commit is contained in:
Qu Xuan
2021-04-25 18:04:54 +08:00
parent d62d6704a4
commit ea8638b0cd
6 changed files with 33 additions and 10 deletions
+2 -2
View File
@@ -840,7 +840,7 @@ func DeleteBucketCORS(ibucket ICloudBucket, id []string) ([]SBucketCORSRule, err
return deletedRules, nil
}
func SetBucketTags(iBucket ICloudBucket, tags map[string]string) (TagsUpdateInfo, error) {
func SetBucketTags(ctx context.Context, iBucket ICloudBucket, mangerId string, tags map[string]string) (TagsUpdateInfo, error) {
ret := TagsUpdateInfo{}
old, err := iBucket.GetTags()
if err != nil {
@@ -853,5 +853,5 @@ func SetBucketTags(iBucket ICloudBucket, tags map[string]string) (TagsUpdateInfo
if !ret.IsChanged() {
return ret, nil
}
return ret, iBucket.SetTags(tags, true)
return ret, SetTags(ctx, iBucket, mangerId, tags, true)
}
+19 -1
View File
@@ -14,7 +14,16 @@
package cloudprovider
import "reflect"
import (
"context"
"reflect"
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
)
const (
SET_TAGS = "set-tags"
)
type TagsUpdateInfo struct {
OldTags map[string]string
@@ -24,3 +33,12 @@ type TagsUpdateInfo struct {
func (t TagsUpdateInfo) IsChanged() bool {
return !reflect.DeepEqual(t.OldTags, t.NewTags)
}
func SetTags(ctx context.Context, res ICloudResource, managerId string, tags map[string]string, replace bool) error {
// 避免同时设置多个资源标签出现以下错误
// Code=ResourceInUse.TagDuplicate, Message=tagKey-tagValue have exists., RequestId=e87714c0-e50b-4241-b79d-32897437174d
lockman.LockRawObject(ctx, SET_TAGS, managerId)
defer lockman.ReleaseRawObject(ctx, SET_TAGS, managerId)
return res.SetTags(tags, replace)
}