Skip to content

Commit 60bce7e

Browse files
committed
Merge branch 'v3.5.x' of https://github.com/Tencent/bk-cmdb into v3.5.x
2 parents 0be7043 + fe2bdc0 commit 60bce7e

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

src/scene_server/admin_server/imports.go

+1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ import (
6464
_ "configcenter/src/scene_server/admin_server/upgrader/x19.10.22.02"
6565
_ "configcenter/src/scene_server/admin_server/upgrader/x19.10.22.03"
6666
_ "configcenter/src/scene_server/admin_server/upgrader/x20.01.13.01"
67+
_ "configcenter/src/scene_server/admin_server/upgrader/x20.02.17.01"
6768
)

src/scene_server/admin_server/upgrader/x19.05.16.01/upgrade_service_template.go

+13
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,18 @@ func upgradeServiceTemplate(ctx context.Context, db dal.RDB, conf *upgrader.Conf
235235
return err
236236
}
237237

238+
procName := ""
239+
if oldInst.ProcessName != nil {
240+
procName = *oldInst.ProcessName
241+
}
242+
if procName == "" && oldInst.FuncName != nil {
243+
procName = *oldInst.FuncName
244+
}
245+
238246
procTemplate := ProcessTemplate{
239247
Metadata: metadata.NewMetadata(bizID),
240248
ID: int64(procTemplateID),
249+
ProcessName: procName,
241250
ServiceTemplateID: serviceTemplate.ID,
242251
Property: procInstToProcTemplate(oldInst),
243252
Creator: conf.User,
@@ -387,6 +396,10 @@ func procInstToProcTemplate(inst Process) *metadata.ProcessProperty {
387396
if inst.FuncName != nil && len(*inst.FuncName) > 0 {
388397
template.FuncName.Value = inst.FuncName
389398
template.FuncName.AsDefaultValue = &True
399+
} else if inst.ProcessName != nil && len(*inst.ProcessName) > 0 {
400+
// FuncName empty, try use ProcessName
401+
template.FuncName.Value = inst.ProcessName
402+
template.FuncName.AsDefaultValue = &True
390403
}
391404
if inst.WorkPath != nil && len(*inst.WorkPath) > 0 {
392405
template.WorkPath.Value = inst.WorkPath
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making 蓝鲸 available.
3+
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
4+
* Licensed under the MIT License (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
* http://opensource.org/licenses/MIT
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9+
* either express or implied. See the License for the specific language governing permissions and
10+
* limitations under the License.
11+
*/
12+
13+
package x20_02_17_01
14+
15+
import (
16+
"context"
17+
"fmt"
18+
"time"
19+
20+
"configcenter/src/common"
21+
"configcenter/src/common/blog"
22+
"configcenter/src/common/metadata"
23+
"configcenter/src/scene_server/admin_server/upgrader"
24+
"configcenter/src/storage/dal"
25+
)
26+
27+
type ProcessTemplate struct {
28+
Metadata metadata.Metadata `field:"metadata" json:"metadata" bson:"metadata"`
29+
30+
ID int64 `field:"id" json:"id,omitempty" bson:"id"`
31+
ProcessName string `field:"bk_process_name" json:"bk_process_name" bson:"bk_process_name"`
32+
// the service template's, which this process template belongs to.
33+
ServiceTemplateID int64 `field:"service_template_id" json:"service_template_id" bson:"service_template_id"`
34+
35+
// stores a process instance's data includes all the process's
36+
// properties's value.
37+
Property *metadata.ProcessProperty `field:"property" json:"property,omitempty" bson:"property"`
38+
39+
Creator string `field:"creator" json:"creator,omitempty" bson:"creator"`
40+
Modifier string `field:"modifier" json:"modifier,omitempty" bson:"modifier"`
41+
CreateTime time.Time `field:"create_time" json:"create_time,omitempty" bson:"create_time"`
42+
LastTime time.Time `field:"last_time" json:"last_time,omitempty" bson:"last_time"`
43+
SupplierAccount string `field:"bk_supplier_account" json:"bk_supplier_account,omitempty" bson:"bk_supplier_account"`
44+
}
45+
46+
func fixProcTemplateProcName(ctx context.Context, db dal.RDB, conf *upgrader.Config) error {
47+
48+
conds := map[string]interface{}{
49+
"$or": []interface{}{
50+
map[string]string{"property.bk_func_name.value": ""},
51+
map[string]interface{}{"property.bk_func_name.value": map[string]interface{}{"$exists": false}},
52+
},
53+
}
54+
55+
rows := make([]ProcessTemplate, 0)
56+
if err := db.Table(common.BKTableNameProcessTemplate).Find(conds).All(ctx, &rows); err != nil {
57+
blog.ErrorJSON("find process template bk_process_name empty error. err:%s", err.Error())
58+
return err
59+
}
60+
61+
for _, row := range rows {
62+
updateCond := map[string]interface{}{
63+
"id": row.ID,
64+
}
65+
if row.Property == nil {
66+
blog.ErrorJSON("fix process template id:%v, process template property empty, raw info:%s", row.ID, row)
67+
return fmt.Errorf("fix process template id:%v, process template property empty", row.ID)
68+
}
69+
if row.Property.ProcessName.Value == nil {
70+
blog.ErrorJSON("fix process template id:%v, bk_process_name empty, raw info:%s", row.ID, row)
71+
return fmt.Errorf("fix process template id:%v, bk_process_name empty", row.ID)
72+
}
73+
doc := map[string]interface{}{
74+
"property.bk_func_name.value": *row.Property.ProcessName.Value,
75+
"property.bk_func_name.as_default_value": true,
76+
}
77+
if row.ProcessName == "" {
78+
doc["bk_process_name"] = *row.Property.ProcessName.Value
79+
}
80+
if err := db.Table(common.BKTableNameProcessTemplate).Update(ctx, updateCond, doc); err != nil {
81+
blog.ErrorJSON("fix process template id:%v, update db error. condition:%s, doc:%s, err:%s", updateCond, doc, err.Error())
82+
return fmt.Errorf("fix process template id:%v, update db error. err:%s", row.ID, err.Error())
83+
}
84+
}
85+
86+
return nil
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making 蓝鲸 available.
3+
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
4+
* Licensed under the MIT License (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
* http://opensource.org/licenses/MIT
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9+
* either express or implied. See the License for the specific language governing permissions and
10+
* limitations under the License.
11+
*/
12+
13+
package x20_02_17_01
14+
15+
import (
16+
"context"
17+
18+
"configcenter/src/common/blog"
19+
"configcenter/src/scene_server/admin_server/upgrader"
20+
"configcenter/src/storage/dal"
21+
)
22+
23+
func init() {
24+
upgrader.RegistUpgrader("x20_02_17_01", upgrade)
25+
}
26+
27+
func upgrade(ctx context.Context, db dal.RDB, conf *upgrader.Config) (err error) {
28+
if err := fixProcTemplateProcName(ctx, db, conf); err != nil {
29+
blog.Errorf("upgrade to version x20_02_17_01 failed, updateNonePropertyGroup failed, err: %+v", err)
30+
return err
31+
}
32+
33+
return nil
34+
}

0 commit comments

Comments
 (0)