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
39 changes: 30 additions & 9 deletions docs/apidoc/apigw/open/en/create_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ Create Model (Permission: Create Model)

### Parameters

| Name | Type | Required | Description |
|----------------------|--------|----------|---------------------------------------------------------------------------------------|
| creator | string | No | Creator of this data |
| bk_classification_id | string | Yes | ID of the classification for the object model, can only be named with English letters |
| bk_obj_id | string | Yes | ID of the object model, can only be named with English letters |
| bk_obj_name | string | Yes | Name of the object model, used for display, can be in any language readable by humans |
| bk_obj_icon | string | No | ICON information of the object model, used for frontend display |
| obj_sort_number | int | No | Sorting order of the object model under the corresponding model group |
| Name | Type | Required | Description |
|----------------------|--------------|----------|---------------------------------------------------------------------------------------|
| creator | string | No | Creator of this data |
| bk_classification_id | string | Yes | ID of the classification for the object model, can only be named with English letters |
| bk_obj_id | string | Yes | ID of the object model, can only be named with English letters |
| bk_obj_name | string | Yes | Name of the object model, used for display, can be in any language readable by humans |
| bk_obj_icon | string | No | ICON information of the object model, used for frontend display |
| obj_sort_number | int | No | Sorting order of the object model under the corresponding model group |
| bk_labels | string array | No | Labels for model categorization and grouping, e.g. ["network"] |

### Request Example

Expand All @@ -22,7 +23,8 @@ Create Model (Permission: Create Model)
"bk_obj_name": "test",
"bk_obj_icon": "icon-cc-business",
"bk_obj_id": "test",
"obj_sort_number": 1
"obj_sort_number": 1,
"bk_labels": ["network"]
}
```

Expand All @@ -37,6 +39,7 @@ Create Model (Permission: Create Model)
"data": {
"description": "",
"bk_ishidden": false,
"bk_labels": ["network"],
Comment thread
elizabevil marked this conversation as resolved.
"bk_classification_id": "test",
"creator": "admin",
"bk_obj_name": "test",
Expand Down Expand Up @@ -64,3 +67,21 @@ Create Model (Permission: Create Model)
| message | string | Error message returned in case of request failure |
| permission | object | Permission information |
| data | object | Request return data |

#### data

| Name | Type | Description |
|----------------------|--------------------|-----------------------------------------------------|
| id | int | Data record ID |
| creator | string | Creator of this data |
| modifier | string | Last modifier of this data |
| create_time | string | Creation time |
| last_time | string | Update time |
| bk_supplier_account | string | Vendor account |
| bk_obj_id | string | Object model ID |
| bk_obj_name | string | Object model name |
| bk_obj_icon | string | ICON information of the object model |
| position | json object string | Coordinates used for front-end display |
| ispre | bool | Whether it is predefined, true or false |
| obj_sort_number | int | Sorting order of the object model under the model group |
| bk_labels | string array | Labels for model categorization and grouping |
24 changes: 14 additions & 10 deletions docs/apidoc/apigw/open/en/search_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ Query models based on optional conditions (Permission: Model View Permission)

### Parameters

| Name | Type | Required | Description |
|----------------------|--------|----------|-------------------------------------------------------------------------------------|
| creator | string | No | Creator of this data |
| modifier | string | No | Last modifier of this data |
| bk_classification_id | string | No | Classification ID of the object model, can only be named with alphabetical sequence |
| bk_obj_id | string | No | ID of the object model, can only be named with alphabetical sequence |
| bk_obj_name | string | No | Name of the object model, used for display, can be any language readable by humans |
| obj_sort_number | int | No | Sorting order of the object model under the corresponding model group |
| Name | Type | Required | Description |
|----------------------|--------------|----------|-------------------------------------------------------------------------------------|
| creator | string | No | Creator of this data |
| modifier | string | No | Last modifier of this data |
| bk_classification_id | string | No | Classification ID of the object model, can only be named with alphabetical sequence |
| bk_obj_id | string | No | ID of the object model, can only be named with alphabetical sequence |
| bk_obj_name | string | No | Name of the object model, used for display, can be any language readable by humans |
| obj_sort_number | int | No | Sorting order of the object model under the corresponding model group |
| bk_labels | string array | No | Labels for model categorization and grouping, e.g. ["network"] |

### Request Example

Expand All @@ -22,7 +23,8 @@ Query models based on optional conditions (Permission: Model View Permission)
"bk_classification_id": "test",
"bk_obj_id": "biz",
"bk_obj_name": "aaa",
"obj_sort_number": 1
"obj_sort_number": 1,
"bk_labels": ["network"]
}
```

Expand Down Expand Up @@ -50,7 +52,8 @@ Query models based on optional conditions (Permission: Model View Permission)
"bk_obj_name": "XXX",
"position": "{\"test_obj\":{\"x\":-253,\"y\":137}}",
"bk_supplier_account": "0",
"obj_sort_number": 1
"obj_sort_number": 1,
"bk_labels": ["env:production", "team:backend"]
}
]
}
Expand Down Expand Up @@ -83,3 +86,4 @@ Query models based on optional conditions (Permission: Model View Permission)
| position | json object string | Coordinates used for front-end display |
| description | string | Description of the data |
| obj_sort_number | int | Sorting order of the object model under the corresponding model group |
| bk_labels | string array | Labels for model categorization and grouping |
22 changes: 13 additions & 9 deletions docs/apidoc/apigw/open/zh/create_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

### 输入参数

| 参数名称 | 参数类型 | 必选 | 描述 |
|----------------------|--------|----|------------------------------|
| creator | string | 否 | 本条数据创建者 |
| bk_classification_id | string | 是 | 对象模型的分类ID,只能用英文字母序列命名 |
| bk_obj_id | string | 是 | 对象模型的ID,只能用英文字母序列命名 |
| bk_obj_name | string | 是 | 对象模型的名字,用于展示,可以使用人类可以阅读的任何语言 | |
| bk_obj_icon | string | 否 | 对象模型的ICON信息,用于前端显示 |
| obj_sort_number | int | 否 | 对象模型在所属模型分组下的排序序号 |
| 参数名称 | 参数类型 | 必选 | 描述 |
|----------------------|--------------|----|------------------------------|
| creator | string | 否 | 本条数据创建者 |
| bk_classification_id | string | 是 | 对象模型的分类ID,只能用英文字母序列命名 |
| bk_obj_id | string | 是 | 对象模型的ID,只能用英文字母序列命名 |
| bk_obj_name | string | 是 | 对象模型的名字,用于展示,可以使用人类可以阅读的任何语言 |
| bk_obj_icon | string | 否 | 对象模型的ICON信息,用于前端显示 |
| obj_sort_number | int | 否 | 对象模型在所属模型分组下的排序序号 |
| bk_labels | string array | 否 | 模型分类标签,如 ["network"] |

### 调用示例

Expand All @@ -22,7 +23,8 @@
"bk_obj_name": "test",
"bk_obj_icon": "icon-cc-business",
"bk_obj_id": "test",
"obj_sort_number": 1
"obj_sort_number": 1,
"bk_labels": ["network"]
}
```

Expand All @@ -37,6 +39,7 @@
"data": {
"description": "",
"bk_ishidden": false,
"bk_labels": ["network"],
"bk_classification_id": "test",
"creator": "admin",
"bk_obj_name": "test",
Expand Down Expand Up @@ -83,3 +86,4 @@
| position | json object string | 用于前端展示的坐标 |
| ispre | bool | 是否预定义, true or false |
| obj_sort_number | int | 对象模型在所属模型分组下的排序序号 |
| bk_labels | string array | 模型分类标签 |
24 changes: 14 additions & 10 deletions docs/apidoc/apigw/open/zh/search_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

### 输入参数

| 参数名称 | 参数类型 | 必选 | 描述 |
|----------------------|--------|----|------------------------------|
| creator | string | 否 | 本条数据创建者 |
| modifier | string | 否 | 本条数据的最后修改人员 |
| bk_classification_id | string | 否 | 对象模型的分类ID,只能用英文字母序列命名 |
| bk_obj_id | string | 否 | 对象模型的ID,只能用英文字母序列命名 |
| bk_obj_name | string | 否 | 对象模型的名字,用于展示,可以使用人类可以阅读的任何语言 |
| obj_sort_number | int | 否 | 对象模型在所属模型分组下的排序序号 |
| 参数名称 | 参数类型 | 必选 | 描述 |
|----------------------|--------------|----|------------------------------|
| creator | string | 否 | 本条数据创建者 |
| modifier | string | 否 | 本条数据的最后修改人员 |
| bk_classification_id | string | 否 | 对象模型的分类ID,只能用英文字母序列命名 |
| bk_obj_id | string | 否 | 对象模型的ID,只能用英文字母序列命名 |
| bk_obj_name | string | 否 | 对象模型的名字,用于展示,可以使用人类可以阅读的任何语言 |
| obj_sort_number | int | 否 | 对象模型在所属模型分组下的排序序号 |
| bk_labels | string array | 否 | 模型分类标签,如 ["network"] |

### 调用示例

Expand All @@ -22,7 +23,8 @@
"bk_classification_id": "test",
"bk_obj_id": "biz",
"bk_obj_name": "aaa",
"obj_sort_number": 1
"obj_sort_number": 1,
"bk_labels": ["network"]
}
```

Expand Down Expand Up @@ -50,7 +52,8 @@
"bk_obj_name": "XXX",
"position": "{\"test_obj\":{\"x\":-253,\"y\":137}}",
"bk_supplier_account": "0",
"obj_sort_number": 1
"obj_sort_number": 1,
"bk_labels": ["env:production", "team:backend"]
}
]
}
Expand Down Expand Up @@ -83,3 +86,4 @@
| position | json object string | 用于前端展示的坐标 |
| description | string | 数据的描述信息 |
| obj_sort_number | int | 对象模型在所属模型分组下的排序序号 |
| bk_labels | string array | 模型分类标签 |
1 change: 1 addition & 0 deletions docs/db/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
| bk_classification_id | String | 模型所属分组 |
| bk_obj_icon | String | 模型logo |
| bk_ishidden | Boolean | 是否是隐藏模型如进程、服务模型等 |
| bk_labels | []String | 模型标签 |
| ispre | Boolean | 是否为系统预置 |
| bk_ispaused | Boolean | 是否停用 |
| creator | String | 创建者 |
Expand Down
11 changes: 11 additions & 0 deletions src/common/index/collections/objdes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package collections

import (
"configcenter/src/common"
"configcenter/src/common/metadata"
"configcenter/src/storage/dal/types"

"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -54,6 +55,16 @@ var commObjDesIndexes = []types.Index{
common.BKObjNameField: map[string]string{common.BKDBType: "string"},
},
},
{
Name: common.CCLogicIndexNamePrefix + "bkLabels",
Keys: bson.D{{
metadata.ModelFieldLabels, 1},
},
Background: true,
Comment thread
elizabevil marked this conversation as resolved.
PartialFilterExpression: map[string]interface{}{
metadata.ModelFieldLabels: map[string]string{common.BKDBType: "array"},
},
},
}

// deprecated 未规范化前的索引,只允许删除不允许新加和修改,
Expand Down
7 changes: 7 additions & 0 deletions src/common/metadata/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const (
ModelFieldOwnerID = "bk_supplier_account"
// ModelFieldDescription TODO
ModelFieldDescription = "description"
// ModelFieldLabels is the database field name for model labels.
// Labels are a string array used for model categorization and grouping.
ModelFieldLabels = "bk_labels"
// ModelFieldCreator TODO
ModelFieldCreator = "creator"
// ModelFieldModifier TODO
Expand All @@ -70,6 +73,9 @@ type Object struct {
// 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"`

// Labels string array for model categorization and grouping.
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"`
Position string `field:"position" json:"position" bson:"position" mapstructure:"position"`
Expand Down Expand Up @@ -331,6 +337,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 @@ -125,4 +125,5 @@ import (
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202607141200"
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202607141510"
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202607141812"
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202607151020"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Comment thread
elizabevil marked this conversation as resolved.
* 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_202607151020

import (
Comment thread
elizabevil marked this conversation as resolved.
"context"

"configcenter/src/common"
"configcenter/src/common/blog"
"configcenter/src/common/metadata"
"configcenter/src/scene_server/admin_server/upgrader"
"configcenter/src/storage/dal"
dbtypes "configcenter/src/storage/dal/types"

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

// addObjLabelField add bk_labels field and index for object description table
func addObjLabelField(ctx context.Context, db dal.RDB, _ *upgrader.Config) error {
Comment thread
elizabevil marked this conversation as resolved.
if err := db.Table(common.BKTableNameObjDes).AddColumn(ctx, metadata.ModelFieldLabels,
make([]string, 0)); err != nil {
blog.Errorf("add bk_labels column failed, err: %v", err)
return err
}

bkLabelsIndex := dbtypes.Index{
Name: common.CCLogicIndexNamePrefix + "bkLabels",
Keys: bson.D{
{metadata.ModelFieldLabels, 1},
},
Background: true,
PartialFilterExpression: map[string]interface{}{
metadata.ModelFieldLabels: map[string]string{common.BKDBType: "array"},
},
}

existIndexes, err := db.Table(common.BKTableNameObjDes).Indexes(ctx)
if err != nil {
blog.Errorf("get obj des indexes failed, err: %v", err)
return err
}

for _, index := range existIndexes {
if index.Name == bkLabelsIndex.Name {
return nil
}
}

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

return nil
}
Loading