diff --git a/readme.md b/readme.md index ebda8d15cb..2f8cea5407 100644 --- a/readme.md +++ b/readme.md @@ -53,5 +53,9 @@ ## Contributing 关于 bk-cmdb 分支管理、issue 以及 pr 规范,请阅读 [bk-cmdb Contributing Guide](docs/CONTRIBUTING.md)。 +## FAQ + +https://github.com/Tencent/bk-cmdb/wiki/FAQ + ## License bk-cmdb 是基于 MIT 协议, 详细请参考 [LICENSE](LICENSE) 。 diff --git a/resources/errors/common/default/common.json b/resources/errors/common/default/common.json index 57563e2743..7a10d992ae 100644 --- a/resources/errors/common/default/common.json +++ b/resources/errors/common/default/common.json @@ -3,12 +3,12 @@ "1199001": "序列化JSON失败", "1199002": "HTTP请求失败", "1199003": "输入参数无效", - "1199004": "数据数据读取失败", + "1199004": "数据读取失败", "1199005": "输入内容为空", "1199006": "'%s' 数据参数校验不通过", "1199007": "'%s' 必须为字符串类型", "1199008": "'%s' 不可以被省略", - "1199009": "'%s' 参数必须是整形", + "1199009": "'%s' 参数必须是整型", "1199010": "'%s' 未赋值", "1199011": "'%s' 参数无效或不存在", "1199012": "唯一性校验不通过", diff --git a/resources/errors/english/en/apiserver_v2.json b/resources/errors/english/en/apiserver_v2.json new file mode 100644 index 0000000000..d61236fa63 --- /dev/null +++ b/resources/errors/english/en/apiserver_v2.json @@ -0,0 +1,11 @@ +{ + "1170001":"Business name must be 1-32 characters", + "1170002":"%s", + "1170003":"The length of the set name cannot exceed 24 bytes", + "1170004":"Each module ID must be a number", + "1170005":"Each set ID must be a number", + "1170006":"osType must be windows or linux", + "1170007":"Multi-module transfers cannot contain default module", + + "":"" +} \ No newline at end of file diff --git a/resources/errors/english/en/common.json b/resources/errors/english/en/common.json new file mode 100644 index 0000000000..623578b837 --- /dev/null +++ b/resources/errors/english/en/common.json @@ -0,0 +1,35 @@ +{ + "1199000": "Deserializing JSON data failed", + "1199001": "Serialized JSON failed", + "1199002": "HTTP request failed", + "1199003": "invalid input parameter", + "1199004": "Data read failed", + "1199005": "The input is empty", + "1199006": "'%s' data parameter verification does not pass", + "1199007": "'%s' must be a string type", + "1199008": "'%s' cannot be omitted", + "1199009": "'%s' parameters must be integral", + "1199010": "'%s' unassigned", + "1199011": "'%s' the parameter is invalid or does not exist", + "1199012": "uniqueness does not pass", + "1199013": "Failed to read Data field data", + "1199014": "Duplicate data", + "1199015": "Data out of bounds", + "1199016": "Field regular check failed", + "1199017": "Failed to query data", + "1199018": "New data failed", + "1199019": "No relevant data found", + "1199020": "Failed to update data", + "1199021": "Failed to delete data", + "1199022": "Dependent service [%s] did not start", + "1199024": "'%s' must be a string type", + "1199025": "'%s' must be boolean", + "1199026": "Configuration file missing [%s] configuration item", + "1199027": "'%s' authorization information query failed", + "1199028": "Field value check does not pass", + "1199029": "Function return value format problem", + "1199030": "HTTP POST parsing failed", + "1199031": "'%s' initialization failed", + + "":"" +} diff --git a/resources/errors/english/en/event_server.json b/resources/errors/english/en/event_server.json new file mode 100644 index 0000000000..67d648fa67 --- /dev/null +++ b/resources/errors/english/en/event_server.json @@ -0,0 +1,10 @@ +{ +      "1103000": "Failed to create instance", +      "1103001": "Delete Instance Failed", +      "1103002": "Failed to update instance", +      "1103003": "Failed to query instance data", +      "1103004": "Failed to create model", +      "1103005": "Delete Model Failed", +      "1103006": "Update model failed", +      "1103007": "Query Model Failed" + } \ No newline at end of file diff --git a/resources/errors/english/en/host_controller.json b/resources/errors/english/en/host_controller.json new file mode 100644 index 0000000000..903cc91d4f --- /dev/null +++ b/resources/errors/english/en/host_controller.json @@ -0,0 +1,21 @@ +{ + "1106000": "Failed to query host instance", + "1106002": "Failed to add new host instance", + "1106003":"Query Host Snapshot Failed", + "1106004": "Failed to transfer host module", + "1106005":"Failed to delete the host default cluster module", + "1106006": "Failed to get host module relationship", + "1106007": "The original host module relationship failed to be deleted", + "1106008":"Failed to get host already bound to relational module", + "1106009": "Failed to transfer host from resource pool", + "1106010":"The host has already belonged to another business. Please refresh the page and reselect the host to be assigned", + "1106011": "The host belongs to a module other than the idle machine", + "1106012": "Failed to transfer host to resource pool", + "1106013": "Newly added user-defined configuration", + "1106014":"Query Host Collection Failed", + "1106015": "Failed to create a host collection", + "1106016":"Failed to modify host collection", + "1106017": "Failed to modify host collections", + + "":"" +} \ No newline at end of file diff --git a/resources/errors/english/en/host_server.json b/resources/errors/english/en/host_server.json new file mode 100644 index 0000000000..1ef7a2a84f --- /dev/null +++ b/resources/errors/english/en/host_server.json @@ -0,0 +1,21 @@ +{ + "1106000": "Failed to query host instance", + "1106002": "Failed to add new host instance", + "1106003":"Query Host Snapshot Failed", + "1106004": "Failed to transfer host module", + "1106005":"Failed to delete the host default cluster module", + "1106006": "Failed to get host module relationship", + "1106007": "The original host module relationship failed to be deleted", + "1106008":"Failed to get host already bound to relational module", + "1106009": "Failed to transfer host from resource pool", + "1106010":"The host has already belonged to another business. Please refresh the page and reselect the host to be assigned", + "1106011": "The host belongs to a module other than the idle machine", + "1106012": "Failed to transfer host to resource pool", + "1106013": "Newly added user-defined configuration", + "1106014":"Query Host Collection Failed", + "1106015": "Failed to create a host collection", + "1106016":"Failed to modify host collection", + "1106017": "Failed to modify host collections", + + "":"" +} \ No newline at end of file diff --git a/resources/errors/english/en/migrate.json b/resources/errors/english/en/migrate.json new file mode 100644 index 0000000000..5623a2433f --- /dev/null +++ b/resources/errors/english/en/migrate.json @@ -0,0 +1,4 @@ +{ + "1105000":"Failed to migrate data", + "":"" +} diff --git a/resources/errors/english/en/object_controller.json b/resources/errors/english/en/object_controller.json new file mode 100644 index 0000000000..02d6be65f0 --- /dev/null +++ b/resources/errors/english/en/object_controller.json @@ -0,0 +1,11 @@ +{ + "1102000": "Attribute grouping failed to store", + "1102001": "Delete Attribute Grouping Failed", + "1102002": "Query Attribute Grouping Failed", + "1102003": "Update Attribute Grouping Failed", + "1102004": "The new instance failed", + "1102005": "Failed to update instance", + "1102006": "Delete Instance Failed", + "1102007": "Query instance failed", + "": "" + } \ No newline at end of file diff --git a/resources/errors/english/en/proc_controller.json b/resources/errors/english/en/proc_controller.json new file mode 100644 index 0000000000..3baa4004b7 --- /dev/null +++ b/resources/errors/english/en/proc_controller.json @@ -0,0 +1,6 @@ +{ + "1107001": "Remove process from module failed", + "1107002": "Failed to add process to module", + "1107003": "The query process failed", + "":"" +} \ No newline at end of file diff --git a/resources/errors/english/en/proc_server.json b/resources/errors/english/en/proc_server.json new file mode 100644 index 0000000000..f1da44bf5c --- /dev/null +++ b/resources/errors/english/en/proc_server.json @@ -0,0 +1,11 @@ +{ +     "1108001": "Query process details failed", +      "1108002": "Bind process model failed", +      "1108003": "Unlocking process model binding failed", +      "1108004": "Unlocking process model binding failed", +      "1108005": "The update process failed", +      "1108006": "The query process failed", +      "1108007": "Delete process failed", +      "1108008": "The creation process failed", +      "": "" + } \ No newline at end of file diff --git a/resources/errors/english/en/topo_server.json b/resources/errors/english/en/topo_server.json new file mode 100644 index 0000000000..735d44b4df --- /dev/null +++ b/resources/errors/english/en/topo_server.json @@ -0,0 +1,55 @@ +{ + "1101000": "Failed to create instance", + "1101001": "Delete Instance Failed", + "1101002": "Failed to update instance", + "1101003": "Querying instance data failed", + "1101004": "Failed to create model", + "1101005": "Delete Model Failed", + "1101006": "Update model failed", + "1101007": "Query model failed", + "1101008": "Failed to create a set", + "1101009": "Delete set Failed", + "1101010": "Failed to update set information", + "1101011": "Failed to query set information", + "1101013": "Failed to create model", + "1101014": "Delete Model Failed", + "1101015": "Update model failed", + "1101016": "Query model failed", + "1101017": "Failed to create a model instance", + "1101018": "Failed to delete model properties", + "1101019": "Failed to update model properties", + "1101020": "Query Model Property Failed", + "1101021": "Failed to create a model classification", + "1101022": "Delete Model Classification Failed", + "1101023": "Update model classification failed", + "1101024": "Query model classification failed", + "1101025": "Failed to create model attribute grouping", + "1101026": "Failed to delete model attribute grouping", + "1101027": "Failed to update model attribute grouping", + "1101028": "Query Model Attribute Grouping Failed", + "1101029": "There is a model under the category, not allowed to delete", + "1101030": "Having a host under the target", + "1001031": "Delete Business Failure", + "1001032": "Update business failed", + "1001033": "Query service failure", + "1001034": "Failed to create business", + "1001035": "Prohibition of deleting the built-in model", + "1001037": "Failed to create a mainline", + "1001038": "Delete Mainline Failed", + "1001039": "Failed to query the main line", + "1001040": "Query Model Topology Failed", + "1001041": "Creating a User Group", + "1001042": "Delete User Group", + "1001043": "Update User Grouping", + "1001044": "Query User Grouping", + "1001045": "Update user group permissions", + "1001046": "Query User Group Permissions", + "1001047": "Query User Rights", + "1001048": "Create Role Rights", + + "1101080": "The module does not exist, please refresh the page", + "":"" + + } + + \ No newline at end of file diff --git a/src/common/definitions.go b/src/common/definitions.go index 5d3fa0c41e..c5baae0425 100644 --- a/src/common/definitions.go +++ b/src/common/definitions.go @@ -1,15 +1,15 @@ /* * Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except + * 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 + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ - + package common const ( @@ -90,6 +90,13 @@ const ( BKInnerObjIDPlat = "plat" ) +// Revision +const ( + RevisionEnterprise = "enterprise" + RevisionCommunity = "community" + RevisionOpensource = "opensource" +) + const ( // BKDBIN the db operator BKDBIN = "$in" diff --git a/src/scene_server/admin_server/common/definitions.go b/src/scene_server/admin_server/common/definitions.go index fc00d179c1..6407cff03d 100644 --- a/src/scene_server/admin_server/common/definitions.go +++ b/src/scene_server/admin_server/common/definitions.go @@ -1,15 +1,15 @@ /* * Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except + * 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 + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ - + package models //common group @@ -29,9 +29,6 @@ const ( //host group info const ( - HostTopology = "topo" - HostTopologyName = "拓扑" - HostAutoFields = "auto" HostAutoFieldsName = "自动发现信息(需要安装agent)" ) diff --git a/src/scene_server/admin_server/migrate_service/ccapi.go b/src/scene_server/admin_server/migrate_service/ccapi.go index 1c75290549..896d8e054e 100644 --- a/src/scene_server/admin_server/migrate_service/ccapi.go +++ b/src/scene_server/admin_server/migrate_service/ccapi.go @@ -1,15 +1,15 @@ /* * Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except + * 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 + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ - + package ccapi import ( @@ -20,6 +20,7 @@ import ( "configcenter/src/common/http/httpserver" "configcenter/src/common/rdapi" "configcenter/src/common/types" + "sync" "time" // migrateCommon "configcenter/src/scene_server/admin_server/common" confCenter "configcenter/src/scene_server/admin_server/migrate_service/config" @@ -80,21 +81,15 @@ func (ccAPI *CCAPIServer) Start() error { errres := config["errors.res"] // configure center - go func() { - err := ccAPI.cfCenter.Start(confDir, errres) + err := ccAPI.cfCenter.Start(confDir, errres) + if err != nil { blog.Errorf("configure center module start failed!. err:%s", err.Error()) - chErr <- err - }() + return err + } //http server ccAPI.initHttpServ() - go func() { - err := ccAPI.httpServ.ListenAndServe() - blog.Error("http listen and serve failed! err:%s", err.Error()) - chErr <- err - }() - // load the errors resource if errorres, ok := config["errors.res"]; ok { if errif, err := errors.New(errorres); nil != err { @@ -121,13 +116,11 @@ func (ccAPI *CCAPIServer) Start() error { a.TopoAPI = rdapi.GetRdAddrSrvHandle(types.CC_MODULE_TOPO, a.AddrSrv) a.ProcAPI = rdapi.GetRdAddrSrvHandle(types.CC_MODULE_PROC, a.AddrSrv) - go func() { - err := a.GetDataCli(config, "mongodb") - if err != nil { - blog.Error("connect mongodb error exit! err:%s", err.Error()) - chErr <- err - } - }() + err = a.GetDataCli(config, "mongodb") + if err != nil { + blog.Error("connect mongodb error exit! err:%s", err.Error()) + return err + } go func() { err := ccAPI.rd.Start() @@ -135,6 +128,32 @@ func (ccAPI *CCAPIServer) Start() error { chErr <- err }() + waitfunc := func(f func() string, wg *sync.WaitGroup) { + for { + if f() != "" { + wg.Done() + return + } + time.Sleep(time.Millisecond * 500) + } + } + all := []string{ + types.CC_MODULE_PROC, + types.CC_MODULE_TOPO, + } + + wg := &sync.WaitGroup{} + for _, module := range all { + wg.Add(1) + go waitfunc(rdapi.GetRdAddrSrvHandle(module, a.AddrSrv), wg) + } + + go func() { + wg.Wait() + err := ccAPI.httpServ.ListenAndServe() + blog.Error("http listen and serve failed! err:%s", err.Error()) + chErr <- err + }() select { case err := <-chErr: blog.Error("exit! err:%s", err.Error()) diff --git a/src/scene_server/admin_server/migrate_service/config/conf.go b/src/scene_server/admin_server/migrate_service/config/conf.go index 59b2894ef5..dca9c1f34b 100644 --- a/src/scene_server/admin_server/migrate_service/config/conf.go +++ b/src/scene_server/admin_server/migrate_service/config/conf.go @@ -75,15 +75,17 @@ func (cc *ConfCenter) Start(confDir, errres string) error { return err } - for { - select { - case confEvn := <-languageEvent: - cc.dealLanguageEvent(confEvn.Data) - case <-cc.rootCtx.Done(): - blog.Warn("configure discover service done") - return nil + go func() { + for { + select { + case confEvn := <-languageEvent: + cc.dealLanguageEvent(confEvn.Data) + case <-cc.rootCtx.Done(): + blog.Warn("configure discover service done") + } } - } + }() + return nil } // Stop the configure center diff --git a/src/scene_server/admin_server/migrate_service/data/objAttDescData.go b/src/scene_server/admin_server/migrate_service/data/objAttDescData.go index 3a347c553f..9c44bb95cb 100644 --- a/src/scene_server/admin_server/migrate_service/data/objAttDescData.go +++ b/src/scene_server/admin_server/migrate_service/data/objAttDescData.go @@ -54,7 +54,7 @@ func AppRow() []*metadata.ObjectAttDes { //&metadata.ObjectAttDes{ObjKeyId: "app", PropertyID: "ParentID", PropertyName: "", IsRequired: common.BKFalse, IsOnly: common.BKFalse, PropertyType: common.FiledTypeInt, Option: ""}, } - if Distribution == "enterprise" { + if Distribution == common.RevisionEnterprise { dataRows = append(dataRows, &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "time_zone", PropertyName: "时区", IsRequired: true, IsOnly: false, Editable: false, PropertyGroup: groupBaseInfo, PropertyType: common.FieldTypeTimeZone, Option: "", IsReadOnly: true}, &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "language", PropertyName: "语言", IsRequired: true, IsOnly: false, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeEnum, Option: languageOption, IsReadOnly: true}, @@ -127,17 +127,16 @@ func HostRow() []*metadata.ObjectAttDes { &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_asset_id", PropertyName: "固资编号", IsRequired: false, IsOnly: false, Editable: false, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeSingleChar, Option: ""}, &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_sn", PropertyName: "设备SN", IsRequired: false, IsOnly: false, Editable: true, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeSingleChar, Option: ""}, &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_comment", PropertyName: "备注", IsRequired: false, IsOnly: false, Editable: true, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeLongChar, Option: ""}, - //拓扑分组 todo //自动发现分组 - &metadata.ObjectAttDes{ObjectID: objID, PropertyID: common.BKCloudIDField, PropertyName: "云区域", IsRequired: false, IsOnly: true, Editable: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeSingleAsst, Option: `{"value":"plat","label":"云区域"}`}, //common.FiledTypeInt, Option: "{}"}, + &metadata.ObjectAttDes{ObjectID: objID, PropertyID: common.BKCloudIDField, PropertyName: "云区域", IsRequired: false, IsOnly: true, Editable: false, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeSingleAsst, Option: `{"value":"plat","label":"云区域"}`}, //common.FiledTypeInt, Option: "{}"}, &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_host_name", PropertyName: "主机名称", IsRequired: false, IsOnly: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeSingleChar, Option: ""}, //&metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_host_type", PropertyName: "主机类型", IsRequired: false, IsOnly: false, Editable: false, PropertyType: common.FiledTypeEnum, Option: "[{\"name\":\"虚拟机\",\"type\":\"text\"},{\"name\":\"实体机\",\"type\":\"text\"},{\"name\":\"容器虚拟机\",\"type\":\"text\"}]"}, - &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_service_term", PropertyName: "质保年限", IsRequired: false, IsOnly: false, Editable: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeInt, Option: "{\"min\":\"1\",\"max\":\"10\"}"}, + &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_service_term", PropertyName: "质保年限", IsRequired: false, IsOnly: false, Editable: false, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeInt, Option: "{\"min\":\"1\",\"max\":\"10\"}"}, //&metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_level", PropertyName: "重要级别", IsRequired: false, IsOnly: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeEnum, Option: "[{\"name\":\"重要\", \"type\":\"text\"},{\"name\":\"非常重要\", \"type\":\"text\"},{\"name\":\"一般\", \"type\":\"text\"},{\"name\":\"不重要\", \"type\":\"text\"}]"}, //&metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_status", PropertyName: "运行状态", IsRequired: false, IsOnly: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeEnum, Option: "[{\"name\":\"离线\", \"type\":\"text\"},{\"name\":\"在线\", \"type\":\"text\"}]"}, //&metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_current_status", PropertyName: "当前状态", IsRequired: false, IsOnly: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeEnum, Option: "[{\"name\":\"运营中\", \"type\":\"text\"},{\"name\":\"故障\", \"type\":\"text\"},{\"name\":\"备用\", \"type\":\"text\"},{\"name\":\"重装中\", \"type\":\"text\"}]"}, - &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_sla", PropertyName: "SLA级别", IsRequired: false, IsOnly: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeEnum, Option: "[{\"name\":\"L1\", \"type\":\"text\"},{\"name\":\"L2\", \"type\":\"text\"},{\"name\":\"L3\", \"type\":\"text\"}]"}, + &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_sla", PropertyName: "SLA级别", IsRequired: false, IsOnly: false, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeEnum, Option: "[{\"name\":\"L1\", \"type\":\"text\"},{\"name\":\"L2\", \"type\":\"text\"},{\"name\":\"L3\", \"type\":\"text\"}]"}, &metadata.ObjectAttDes{ObjectID: objID, PropertyID: common.BKOSTypeField, PropertyName: "操作系统类型", IsRequired: false, IsOnly: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeEnum, Option: "[{\"name\":\"Linux\", \"type\":\"text\"},{\"name\":\"Windows\", \"type\":\"text\"}]"}, &metadata.ObjectAttDes{ObjectID: objID, PropertyID: common.BKOSNameField, PropertyName: "操作系统名称", IsRequired: false, IsOnly: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeSingleChar, Option: ""}, &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_os_version", PropertyName: "操作系统版本", IsRequired: false, IsOnly: false, PropertyGroup: groupAgent, PropertyType: common.FiledTypeSingleChar, Option: ""}, diff --git a/src/scene_server/admin_server/migrate_service/logics/bkdata.go b/src/scene_server/admin_server/migrate_service/logics/bkdata.go index 538502dcb1..87e5a91bf7 100644 --- a/src/scene_server/admin_server/migrate_service/logics/bkdata.go +++ b/src/scene_server/admin_server/migrate_service/logics/bkdata.go @@ -106,8 +106,12 @@ func addBKApp(req *restful.Request) error { appModelData[common.BKAppNameField] = common.BKAppName appModelData[common.BKMaintainersField] = "admin" - if data.Distribution == "enterprise" { + if data.Distribution == common.RevisionEnterprise { appModelData[common.BKTimeZoneField] = "Asia/Shanghai" + appModelData[common.BKLanguageField] = "中文" + } else { + delete(appModelData, common.BKTimeZoneField) + delete(appModelData, common.BKLanguageField) } byteParams, _ := json.Marshal(appModelData) diff --git a/src/scene_server/admin_server/migrate_service/logics/collections/property_group.go b/src/scene_server/admin_server/migrate_service/logics/collections/property_group.go index d2f1d74df7..d7769e39c4 100644 --- a/src/scene_server/admin_server/migrate_service/logics/collections/property_group.go +++ b/src/scene_server/admin_server/migrate_service/logics/collections/property_group.go @@ -1,15 +1,15 @@ /* * Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except + * 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 + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ - + package logics import ( diff --git a/src/scene_server/admin_server/migrate_service/logics/default_app_migrate.go b/src/scene_server/admin_server/migrate_service/logics/default_app_migrate.go index fadb473104..3ca3d2f0ad 100644 --- a/src/scene_server/admin_server/migrate_service/logics/default_app_migrate.go +++ b/src/scene_server/admin_server/migrate_service/logics/default_app_migrate.go @@ -1,24 +1,26 @@ /* * Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except + * 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 + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ - + package logics import ( "configcenter/src/common" - "configcenter/src/common/core/cc/api" "configcenter/src/common/blog" + "configcenter/src/common/core/cc/api" "configcenter/src/common/util" + "configcenter/src/scene_server/admin_server/migrate_service/data" "encoding/json" "errors" + "fmt" httpcli "configcenter/src/common/http/httpclient" @@ -48,6 +50,14 @@ func addDefaultApp(req *restful.Request, cc *api.APIResource, ownerID string) er params[common.BKMaintainersField] = "admin" params[common.BKProductPMField] = "admin" + if data.Distribution == common.RevisionEnterprise { + params[common.BKTimeZoneField] = "Asia/Shanghai" + params[common.BKLanguageField] = "中文" + } else { + delete(params, common.BKTimeZoneField) + delete(params, common.BKLanguageField) + } + byteParams, _ := json.Marshal(params) url := cc.TopoAPI() + "/topo/v1/app/default/" + ownerID blog.Info("migrate add default app url :%s", url) @@ -60,12 +70,12 @@ func addDefaultApp(req *restful.Request, cc *api.APIResource, ownerID string) er js, _ := simplejson.NewJson([]byte(reply)) output, _ := js.Map() - code, err := util.GetIntByInterface(output["bk_error_code"]) + code, err := util.GetIntByInterface(output[common.HTTPBKAPIErrorCode]) if err != nil { return errors.New(reply) } if 0 != code { - return errors.New(output["message"].(string)) + return errors.New(fmt.Sprint(output[common.HTTPBKAPIErrorMessage])) } return nil diff --git a/src/scene_server/admin_server/migrate_service/models/property_group.go b/src/scene_server/admin_server/migrate_service/models/property_group.go index b7c07c2090..68ac24546e 100644 --- a/src/scene_server/admin_server/migrate_service/models/property_group.go +++ b/src/scene_server/admin_server/migrate_service/models/property_group.go @@ -1,15 +1,15 @@ /* * Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except + * 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 + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ - + package models import ( @@ -97,7 +97,6 @@ func getPropertyGroupData(ownerID string) []*metadata.PropertyGroup { //host &metadata.PropertyGroup{ObjectID: common.BKInnerObjIDHost, GroupID: mCommon.BaseInfo, GroupName: mCommon.BaseInfoName, GroupIndex: 1, OwnerID: ownerID, IsDefault: true}, - &metadata.PropertyGroup{ObjectID: common.BKInnerObjIDHost, GroupID: mCommon.HostTopology, GroupName: mCommon.HostTopologyName, GroupIndex: 2, OwnerID: ownerID, IsDefault: true}, &metadata.PropertyGroup{ObjectID: common.BKInnerObjIDHost, GroupID: mCommon.HostAutoFields, GroupName: mCommon.HostAutoFieldsName, GroupIndex: 3, OwnerID: ownerID, IsDefault: true}, //proc diff --git a/src/scene_server/host_server/host_service/logics/host_log.go b/src/scene_server/host_server/host_service/logics/host_log.go index b894da1d43..f4c1c2487b 100644 --- a/src/scene_server/host_server/host_service/logics/host_log.go +++ b/src/scene_server/host_server/host_service/logics/host_log.go @@ -1,15 +1,15 @@ /* * Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except + * 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 + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ - + package logics import ( @@ -119,30 +119,9 @@ func (h *HostLog) getHostDetail(instID string) (interface{}, int) { return nil, common.CC_Err_Comm_Host_Get_FAIL } - // hostData := gHostData["data"].(map[string]interface{}) - ret := make(map[string]interface{}) - for key, val := range hostData { - if nil != val { - valArr, ok := val.([]interface{}) - if common.BKHostInnerIPField == key { - h.innerIP = val - } - if ok { - var refs []interface{} - for _, item := range valArr { - itemMap := item.(map[string]interface{}) - refs = append(refs, common.KvMap{"ref_id": itemMap["bk_inst_id"], "ref_name": itemMap["name"]}) - } - ret[key] = refs - } else { - ret[key] = val - } - } - } - - return ret, common.CCSuccess + return hostData, common.CCSuccess } func (h *HostLog) GetPreHostData() *metadata.Content { diff --git a/src/scene_server/host_server/host_service/logics/object.go b/src/scene_server/host_server/host_service/logics/object.go index c86e14da6c..1e420d0661 100644 --- a/src/scene_server/host_server/host_service/logics/object.go +++ b/src/scene_server/host_server/host_service/logics/object.go @@ -41,14 +41,18 @@ func GetSetIDByObjectCond(req *restful.Request, objURL string, objectCond []inte condition := make([]interface{}, 0) for _, i := range objectCond { condi := i.(map[string]interface{}) - value, ok := condi["value"].(float64) - if false == ok { + field, ok := condi["field"].(string) + if false == ok || field != common.BKInstIDField { + continue + } + value, err := util.GetIntByInterface(condi["value"]) + if nil != err { continue } - conc["field"] = common.BKParentStr + conc["field"] = common.BKInstParentStr conc["operator"] = condi["operator"] conc["value"] = condi["value"] - objectIDArr = append(objectIDArr, int(value)) + objectIDArr = append(objectIDArr, value) } condition = append(condition, conc) for { @@ -65,7 +69,7 @@ func GetSetIDByObjectCond(req *restful.Request, objURL string, objectCond []inte } conc = make(map[string]interface{}) condition = make([]interface{}, 0) - conc["field"] = common.BKParentStr + conc["field"] = common.BKInstParentStr conc["operator"] = common.BKDBIN conc["value"] = sObjectIDArr condition = append(condition, conc) @@ -80,7 +84,7 @@ func getObjectByParentID(req *restful.Request, valArr []int, objURL string) []in condition := make(map[string]interface{}) sCond := make(map[string]interface{}) condCell[common.BKDBIN] = valArr - sCond[common.BKParentStr] = condCell + sCond[common.BKInstParentStr] = condCell condition["condition"] = sCond bodyContent, _ := json.Marshal(condition) url := objURL + "/object/v1/insts/object/search" diff --git a/src/scene_server/proc_server/proc_service/actions/detail.go b/src/scene_server/proc_server/proc_service/actions/detail.go index ee1e1a9df7..7840783416 100644 --- a/src/scene_server/proc_server/proc_service/actions/detail.go +++ b/src/scene_server/proc_server/proc_service/actions/detail.go @@ -19,8 +19,11 @@ import ( httpcli "configcenter/src/common/http/httpclient" "configcenter/src/common/util" "encoding/json" + "fmt" "net/http" + "reflect" "strconv" + "strings" simplejson "github.com/bitly/go-simplejson" "github.com/emicklei/go-restful" @@ -114,6 +117,14 @@ func (cli *procAction) getProcDetail(req *restful.Request, ownerID string, appID return nil, err } procAttrArr := gProcAttr["data"].([]interface{}) + + rstmap, errorno := cli.getObjectAsst(common.BKInnerObjIDProc, ownerID) + if common.CCSuccess != errorno { + return nil, fmt.Errorf("get object asst faile") + } + + fmt.Printf("rst map : %v\n", rstmap) + reResult := make([]map[string]interface{}, 0) for _, i := range procAttrArr { attr := i.(map[string]interface{}) @@ -126,7 +137,287 @@ func (cli *procAction) getProcDetail(req *restful.Request, ownerID string, appID data[common.BKPropertyNameField] = attr[common.BKPropertyNameField] data[common.BKPropertyValueField] = proc[propertyID] + // key is the association object filed,val is association object id + if val, ok := rstmap[propertyID]; ok { + keyItemStr := fmt.Sprintf("%v", proc[propertyID]) + blog.Debug("keyitemstr:%s", keyItemStr) + retData, _, retErr := cli.getInstAsst(req, ownerID, val, strings.Split(keyItemStr, ","), nil) + if common.CCSuccess != retErr { + blog.Error("failed to get inst details") + } + data[common.BKPropertyValueField] = retData + } reResult = append(reResult, data) } return reResult, nil } + +// instNameAsst association inst name +type instNameAsst struct { + ID string `json:"id"` + ObjID string `json:"bk_obj_id"` + ObjIcon string `json:"bk_obj_icon"` + InstID int `json:"bk_inst_id"` + ObjectName string `json:"bk_obj_name"` + InstName string `json:"bk_inst_name"` +} + +// getObjectAsst read association objectid the return key is engilish property name, value is the objectid +func (cli *procAction) getObjectAsst(objID, ownerID string) (map[string]string, int) { + + rstmap := map[string]string{} + + // get module + cli.objcli.SetAddress(cli.CC.ObjCtrl()) + att := map[string]interface{}{} + att[common.BKObjIDField] = objID + att[common.BKOwnerIDField] = ownerID + searchData, jsErr := json.Marshal(att) + if nil != jsErr { + blog.Error("failed to marshal the data[%+v], error info is %s", searchData, jsErr.Error()) + return nil, common.CCErrCommJSONMarshalFailed + } + rests, restErr := cli.objcli.SearchMetaObjectAtt(searchData) + if nil != restErr { + blog.Error("failed to read the object att, error is %s ", restErr.Error()) + return nil, common.CCErrTopoInstSelectFailed + } + + // 组织模型名和对应的字段 + for _, item := range rests { + + switch item.PropertyType { + + case common.FiledTypeSingleAsst: + + asst := map[string]interface{}{} + asst["bk_object_att_id"] = item.PropertyID + asst[common.BKOwnerIDField] = item.OwnerID + asst[common.BKObjIDField] = item.ObjectID + + searchData, jsErr := json.Marshal(asst) + + if nil != jsErr { + blog.Error("failed to marshal the data[%+v], error info is %s", searchData, jsErr.Error()) + } + + asstRst, asstRstErr := cli.objcli.SearchMetaObjectAsst(searchData) + if nil != asstRstErr { + blog.Error("failed to read the object asst, error is %s ", asstRstErr.Error()) + return nil, common.CCErrTopoInstSelectFailed + } + + if len(asstRst) > 0 { // only one association map + rstmap[item.PropertyID] = asstRst[0].AsstObjID + } + + case common.FieldTypeMultiAsst: + + asst := map[string]interface{}{} + asst["bk_object_att_id"] = item.PropertyID + asst[common.BKOwnerIDField] = item.OwnerID + asst[common.BKObjIDField] = item.ObjectID + searchData, jsErr := json.Marshal(asst) + + if nil != jsErr { + blog.Error("failed to marshal the data[%+v], error info is %s", searchData, jsErr.Error()) + } + + asstRst, asstRstErr := cli.objcli.SearchMetaObjectAsst(searchData) + if nil != asstRstErr { + blog.Error("failed to read the object asst, error is %s ", asstRstErr.Error()) + return nil, common.CCErrTopoInstSelectFailed + } + + if len(asstRst) > 0 { // only association with one object by one filed + rstmap[item.PropertyID] = asstRst[0].AsstObjID + } + } + + } + + // rstmap: key is the bk_property_id value is the association object id + return rstmap, common.CCSuccess +} + +func (cli *procAction) getInstAsst(req *restful.Request, ownerID, objID string, ids []string, page map[string]interface{}) ([]instNameAsst, int, int) { + + tmpIDS := []int{} + for _, id := range ids { + tmpID, _ := strconv.Atoi(id) + tmpIDS = append(tmpIDS, tmpID) + } + + condition := make(map[string]interface{}) + searchParams := make(map[string]interface{}) + + searchParams["fields"] = "" + if val, ok := page["fields"]; ok { + searchParams["fields"] = val + } + searchParams["start"] = 0 + if val, ok := page["start"]; ok { + searchParams["start"] = val + } + searchParams["limit"] = common.BKDefaultLimit + if val, ok := page["limit"]; ok { + searchParams["limit"] = val + } + + var targetOBJ string + var instName string + var instID string + + targetPre := cli.CC.ObjCtrl() + "/object/v1/insts/" + switch objID { + case common.BKInnerObjIDHost: + targetOBJ = "" + instName = common.BKHostInnerIPField + instID = common.BKHostIDField + targetPre = cli.CC.HostCtrl() + "/host/v1/hosts" + if 0 != len(tmpIDS) { + condition[common.BKHostIDField] = map[string]interface{}{common.BKDBIN: tmpIDS} + } + case common.BKInnerObjIDApp: + targetOBJ = common.BKInnerObjIDApp + instName = common.BKAppNameField + instID = common.BKAppIDField + searchParams["sort"] = common.BKAppIDField + condition[common.BKOwnerIDField] = ownerID + if 0 != len(tmpIDS) { + condition[common.BKAppIDField] = map[string]interface{}{common.BKDBIN: tmpIDS} + } + case common.BKInnerObjIDSet: + targetOBJ = common.BKInnerObjIDSet + instID = common.BKSetIDField + instName = common.BKSetNameField + searchParams["sort"] = common.BKSetIDField + condition[common.BKSetIDField] = map[string]interface{}{common.BKDBIN: tmpIDS} + condition[common.BKOwnerIDField] = ownerID + case common.BKInnerObjIDModule: + targetOBJ = common.BKInnerObjIDModule + instID = common.BKModuleIDField + instName = common.BKModuleNameField + searchParams["sort"] = common.BKModuleIDField + condition[common.BKOwnerIDField] = ownerID + if 0 != len(tmpIDS) { + condition[common.BKModuleIDField] = map[string]interface{}{common.BKDBIN: tmpIDS} + } + case common.BKInnerObjIDPlat: + targetOBJ = common.BKInnerObjIDPlat + instID = common.BKCloudIDField + instName = common.BKCloudNameField + searchParams["sort"] = common.BKCloudIDField + if 0 != len(tmpIDS) { + condition[common.BKCloudIDField] = map[string]interface{}{common.BKDBIN: tmpIDS} + } + default: + targetOBJ = common.BKINnerObjIDObject + instName = common.BKInstNameField + instID = common.BKInstIDField + condition[common.BKOwnerIDField] = ownerID + condition[common.BKObjIDField] = objID + if 0 != len(tmpIDS) { + condition[common.BKInstIDField] = map[string]interface{}{common.BKDBIN: tmpIDS} + } + searchParams["sort"] = common.BKInstIDField + + } + + searchParams["condition"] = condition + + //search + sURL := targetPre + targetOBJ + "/search" + inputJSON, _ := json.Marshal(searchParams) + objRes, err := httpcli.ReqHttp(req, sURL, common.HTTPSelectPost, []byte(inputJSON)) + blog.Debug("search inst api(%s) detail params: %s ", sURL, string(inputJSON)) + if nil != err { + blog.Error("search inst defail failed, error: %v", err) + return nil, 0, common.CCErrCommJSONMarshalFailed + } + + js, err := simplejson.NewJson([]byte(objRes)) + if nil != err { + blog.Error("the input json is invalid, error info is %s", err.Error()) + return nil, 0, common.CCErrCommJSONUnmarshalFailed + } + + input, jsErr := js.Map() + if nil != jsErr { + blog.Error("the input json is invalid, error info is %s", jsErr.Error()) + return nil, 0, common.CCErrCommJSONUnmarshalFailed + } + + delArryFunc := func(s []string, i int) []string { + s[len(s)-1], s[i] = s[i], s[len(s)-1] + return s[:len(s)-1] + } + + rstName := []instNameAsst{} + + cnt := 0 + if data, ok := input["data"].(map[string]interface{}); ok { + + switch reflect.TypeOf(data["count"]).Kind() { + case reflect.String: + cnt, _ = strconv.Atoi(reflect.ValueOf(data["count"]).String()) + case reflect.Int: + cnt = int(reflect.ValueOf(data["count"]).Int()) + default: + blog.Warn("unknown the count type, value is %v type is %s", data["count"], reflect.TypeOf(data["count"]).Kind()) + } + + if info, infoOk := data["info"].([]interface{}); infoOk { + for _, infoItem := range info { + + if dataItem, dataItemOk := infoItem.(map[string]interface{}); dataItemOk { + + if dataItemVal, dataItemValOk := dataItem[instName]; dataItemValOk { + + // 提取实例名 + inst := instNameAsst{} + if dataItemValStr, convOk := dataItemVal.(string); convOk { + inst.InstName = dataItemValStr + inst.ObjID = objID + } + + // 删除已经存在的ID + if dataItemVal, dataItemValOk := dataItem[instID]; dataItemValOk { + + //fmt.Println(key, dataItemVal) + switch d := dataItemVal.(type) { + case json.Number: + if 0 != len(ids) { + for idx, key := range ids { + if val, err := d.Int64(); nil == err && key == strconv.Itoa(int(val)) { + //fmt.Println("key:", key, "val:", val) + inst.ID = ids[idx] + inst.InstID, _ = strconv.Atoi(ids[idx]) + ids = delArryFunc(ids, idx) + rstName = append(rstName, inst) + goto next + } + } + } else if val, err := d.Int64(); nil == err { + inst.ID = strconv.Itoa(int(val)) + inst.InstID = int(val) + rstName = append(rstName, inst) + } + + } + next: + } + + } + } + } + } + } + + // deal the other inst name + for _, id := range ids { + rstName = append(rstName, instNameAsst{ID: id}) + } + + return rstName, cnt, common.CCSuccess +} diff --git a/src/scene_server/proc_server/proc_service/actions/process.go b/src/scene_server/proc_server/proc_service/actions/process.go index dfaac65268..83a3f36a47 100644 --- a/src/scene_server/proc_server/proc_service/actions/process.go +++ b/src/scene_server/proc_server/proc_service/actions/process.go @@ -32,6 +32,7 @@ import ( "strconv" "strings" + api "configcenter/src/source_controller/api/object" simplejson "github.com/bitly/go-simplejson" "github.com/emicklei/go-restful" ) @@ -40,6 +41,7 @@ var process *procAction = &procAction{} type procAction struct { base.BaseAction + objcli *api.Client } func init() { @@ -48,6 +50,7 @@ func init() { actions.RegisterNewAction(actions.Action{Verb: common.HTTPSelectPost, Path: "/search/{bk_supplier_account}/{bk_biz_id}", Params: nil, Handler: process.SearchProcess}) actions.RegisterNewAction(actions.Action{Verb: common.HTTPUpdate, Path: "/{bk_supplier_account}/{bk_biz_id}/{bk_process_id}", Params: nil, Handler: process.UpdateProcess}) process.CreateAction() + process.objcli = api.NewClient("") } //UpdateProcess update process diff --git a/src/scene_server/topo_server/topo_service/actions/inst/inst.go b/src/scene_server/topo_server/topo_service/actions/inst/inst.go index e86cc4198b..84072e9be5 100644 --- a/src/scene_server/topo_server/topo_service/actions/inst/inst.go +++ b/src/scene_server/topo_server/topo_service/actions/inst/inst.go @@ -1127,21 +1127,9 @@ func (cli *instAction) getInstDeteilByCondition(req *restful.Request, objID stri blog.Debug("the return data:%+v", ret) if data, ok := ret["data"].(map[string]interface{}); ok { if info, infoOk := data["info"].([]interface{}); infoOk { - for _, infoItem := range info { - if dataItem, dataItemOk := infoItem.(map[string]interface{}); dataItemOk { - for k, v := range dataItem { - if assts, ok := v.([]instNameAsst); ok { - refs := []metadata.Ref{} - for _, ref := range assts { - refs = append(refs, metadata.Ref{ - RefID: ref.InstID, - RefName: ref.InstName, - }) - } - dataItem[k] = refs - } - } - return dataItem, common.CCSuccess + if len(info) > 0 && info[0] != nil { + if ret, ok := info[0].(map[string]interface{}); ok { + return ret, common.CCSuccess } } } diff --git a/src/scene_server/topo_server/topo_service/logics/object/object_attribute.go b/src/scene_server/topo_server/topo_service/logics/object/object_attribute.go index 6590f4521c..1721e45f03 100644 --- a/src/scene_server/topo_server/topo_service/logics/object/object_attribute.go +++ b/src/scene_server/topo_server/topo_service/logics/object/object_attribute.go @@ -1,15 +1,15 @@ /* * Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except + * 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 + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ - + package object import ( @@ -529,7 +529,7 @@ func (cli *objAttLogic) DeleteObjectAtt(attrID int, val []byte, errProxy errors. return itemsErr } else if 0 == len(items) { blog.Error("nothing to be delete, condition:%s", string(checkObjAttCondVal)) - // objatt对象已经不存在�� + // objatt not found return fmt.Errorf("nothing to be deleted, please the condition") } } @@ -543,6 +543,10 @@ func (cli *objAttLogic) DeleteObjectAtt(attrID int, val []byte, errProxy errors. return fmt.Errorf("nothing to be deleted, please check the condition") } + if objAtt.IsPre { + return fmt.Errorf("could not delete preset attribute") + } + objAsst[common.BKObjIDField] = objAtt.ObjectID objAsst[common.BKOwnerIDField] = objAtt.OwnerID objAsst["bk_object_att_id"] = objAtt.PropertyID diff --git a/src/ui/src/components/filter/screening.vue b/src/ui/src/components/filter/screening.vue index 0e02f2de3d..8ac288c933 100644 --- a/src/ui/src/components/filter/screening.vue +++ b/src/ui/src/components/filter/screening.vue @@ -203,55 +203,40 @@ exact: this.ip.exact, data: this.ipData }, - condition: [{ - 'bk_obj_id': 'host', - fields: [], - condition: [] - }, { - 'bk_obj_id': 'biz', - fields: [], - condition: [{ - field: 'default', - operator: '$ne', - value: 1 - }] - }, { - 'bk_obj_id': 'module', - fields: [], - condition: [] - }, { - 'bk_obj_id': 'set', - fields: [], - condition: [] - }] + condition: [] } Object.keys(this.localQueryColumnData).map(columnPropertyId => { let column = this.localQueryColumnData[columnPropertyId] let value = column.value if (value !== '' || (Array.isArray(value) && value.length)) { let property = this.getColumnProperty(columnPropertyId, column['bk_obj_id']) - filter.condition.forEach(({bk_obj_id: bkObjId, condition}) => { - if (bkObjId === column['bk_obj_id']) { - if (this.typeOfDate.indexOf(property['bk_property_type']) === -1) { - condition.push({ - field: column.field, - operator: column.operator, - value: column.value - }) - } else { - condition.push({ - field: column.field, - operator: '$gte', - value: column.value[0] - }) - condition.push({ - field: column.field, - operator: '$lte', - value: column.value[1] - }) - } + let condition = filter.condition.find(({bk_obj_id: bkObjId}) => bkObjId === column['bk_obj_id']) + if (!condition) { + condition = { + 'bk_obj_id': column['bk_obj_id'], + fields: [], + condition: [] } - }) + filter.condition.push(condition) + } + if (this.typeOfDate.indexOf(property['bk_property_type']) === -1) { + condition.condition.push({ + field: column.field, + operator: column.operator, + value: column.value + }) + } else { + condition.condition.push({ + field: column.field, + operator: '$gte', + value: column.value[0] + }) + condition.condition.push({ + field: column.field, + operator: '$lte', + value: column.value[1] + }) + } } }) return filter diff --git a/src/ui/src/components/object/attribute.vue b/src/ui/src/components/object/attribute.vue index bf9c5b44b5..d32b0a80cf 100644 --- a/src/ui/src/components/object/attribute.vue +++ b/src/ui/src/components/object/attribute.vue @@ -53,7 +53,7 @@ @change="clearFieldValue(property)"> {{property['bk_property_name']}} - +
- +
+ +