Skip to content
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
6 changes: 5 additions & 1 deletion src/common/metadata/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const (
ModelFieldOwnerID = "bk_supplier_account"
// ModelFieldDescription TODO
ModelFieldDescription = "description"
// ModelFieldLabels TODO
ModelFieldLabels = "bk_labels"
// ModelFieldCreator TODO
ModelFieldCreator = "creator"
// ModelFieldModifier TODO
Expand All @@ -68,7 +70,8 @@ type Object struct {
ObjectName string `field:"bk_obj_name" json:"bk_obj_name" bson:"bk_obj_name" mapstructure:"bk_obj_name"`

// IsHidden front-end don't display the object if IsHidden is true
IsHidden bool `field:"bk_ishidden" json:"bk_ishidden" bson:"bk_ishidden" mapstructure:"bk_ishidden"`
IsHidden bool `field:"bk_ishidden" json:"bk_ishidden" bson:"bk_ishidden" mapstructure:"bk_ishidden"`
Labels []string `field:"bk_labels" json:"bk_labels" bson:"bk_labels" mapstructure:"bk_labels"`

IsPre bool `field:"ispre" json:"ispre" bson:"ispre" mapstructure:"ispre"`
IsPaused bool `field:"bk_ispaused" json:"bk_ispaused" bson:"bk_ispaused" mapstructure:"bk_ispaused"`
Expand Down Expand Up @@ -331,6 +334,7 @@ type YamlObject struct {
ObjectName string `json:"bk_obj_name" yaml:"bk_obj_name"`
ObjIcon string `json:"bk_obj_icon" yaml:"bk_obj_icon"`
IsPre bool `json:"ispre" yaml:"ispre"`
Labels []string `json:"bk_labels" yaml:"bk_labels"`
ObjSortNumber int64 `json:"obj_sort_number" yaml:"obj_sort_number"`
ClsID string `json:"bk_classification_id" yaml:"bk_classification_id"`
ClsName string `json:"bk_classification_name" yaml:"bk_classification_name"`
Expand Down
1 change: 1 addition & 0 deletions src/scene_server/admin_server/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@ import (
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202410100930"
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202502101200"
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202603231000"
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202604101200"
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202605111642"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Tencent is pleased to support the open source community by making
* 蓝鲸智云 - 配置平台 (BlueKing - Configuration System) available.
* Copyright (C) 2017 Tencent. 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 http://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.
* We undertake not to change the open source license (MIT license) applicable
* to the current version of the project delivered to anyone in the future.
*/

package y3_14_202604101200

import (
"configcenter/src/common"
"configcenter/src/common/blog"
"configcenter/src/common/mapstr"
"configcenter/src/common/metadata"
"configcenter/src/scene_server/admin_server/upgrader"
"configcenter/src/storage/dal"
"configcenter/src/storage/dal/types"
"context"

"go.mongodb.org/mongo-driver/bson"
)

// addObjLabelField add field 'bk_labels' to object labels ,default:[]string
func addObjLabelField(ctx context.Context, db dal.RDB, _ *upgrader.Config) error {
cond := bson.M{
common.BKDBOR: bson.A{
bson.M{metadata.ModelFieldLabels: bson.M{
common.BKDBExists: false,
}},
bson.M{metadata.ModelFieldLabels: nil},
},
}
doc := mapstr.MapStr{
metadata.ModelFieldLabels: make([]string, 0),
}
if err := db.Table(common.BKTableNameObjDes).Update(ctx, cond, doc); err != nil {
blog.ErrorJSON("failed to add object labels value of field %s to true, err: %s",
metadata.ModelFieldLabels, err)
return err
}
objLabelIndex := types.Index{
Keys: bson.D{
{metadata.ModelFieldLabels, 1},
},
Name: common.CCLogicIndexNamePrefix + "obj_labels",
Unique: false,
Background: true,
}

err := db.Table(common.BKTableNameObjDes).CreateIndex(ctx, objLabelIndex)
if err != nil && !db.IsDuplicatedError(err) {
blog.Errorf("create obj labels index %+v failed, err: %v", objLabelIndex, err)
return err
}

return nil
}
42 changes: 42 additions & 0 deletions src/scene_server/admin_server/upgrader/y3.14.202604101200/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Tencent is pleased to support the open source community by making
* 蓝鲸智云 - 配置平台 (BlueKing - Configuration System) available.
* Copyright (C) 2017 Tencent. 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 http://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.
* We undertake not to change the open source license (MIT license) applicable
* to the current version of the project delivered to anyone in the future.
*/

package y3_14_202604101200

import (
"context"

"configcenter/src/common/blog"
"configcenter/src/scene_server/admin_server/upgrader"
"configcenter/src/storage/dal"
)

func init() {
upgrader.RegistUpgrader("y3.14.202604101200", upgrade)
}

func upgrade(ctx context.Context, db dal.RDB, conf *upgrader.Config) (err error) {

blog.Infof("start execute y3.14.202604101200")
err = addObjLabelField(ctx, db, conf)
if err != nil {
blog.Errorf("upgrade y3.14.202604101200 add object labels field failed, error: %v", err)
return err
}
blog.Infof("execute y3.14.202604101200, add object labels field success!")

return nil
}
8 changes: 6 additions & 2 deletions src/scene_server/topo_server/logics/model/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ func (o *object) createObjectParamCheck(kit *rest.Kit, data mapstr.MapStr) (*met
"rid: %s", obj.ObjSortNumber, kit.Rid)
return nil, kit.CCError.CCError(common.CCErrCommParamsInvalid)
}

if len(obj.Labels) == 0 {
obj.Labels = make([]string, 0)
}
return obj, nil
}

Expand Down Expand Up @@ -660,7 +662,9 @@ func (o *object) isValid(kit *rest.Kit, isUpdate bool, data mapstr.MapStr) (*met
return nil, kit.CCError.New(common.CCErrCommParamsIsInvalid,
fmt.Sprintf("'%s' the built-in object id, please use a new one", obj.ObjectID))
}

if len(obj.Labels) == 0 {
obj.Labels = make([]string, 0)
}
obj.OwnerID = kit.SupplierAccount
return obj, nil
}
Expand Down