Skip to content

Commit cc6d05b

Browse files
Merge pull request #8215 from TencentBlueKing/v3.11.x
Merge branch v3.11.x into v3.13.x
2 parents 8f85d0a + 4d57116 commit cc6d05b

File tree

6 files changed

+95
-48
lines changed

6 files changed

+95
-48
lines changed

src/apimachinery/coreservice/transaction/client.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ func (t *txn) AutoRunTxn(ctx context.Context, h http.Header, run func() error, o
108108
// do next retry
109109
}
110110

111-
blog.Warnf("retry transaction exceeds maximum count, **skip**, app code: %s, rid: %s", appCode, rid)
112-
113-
return nil
111+
blog.Errorf("retry transaction exceeds maximum count, **skip**, app code: %s, rid: %s", appCode, rid)
112+
return ccErr.New(common.CCErrCommCommitTransactionFailed, "retry transaction exceeds maximum count")
114113
}
115114

116115
type transaction struct {

src/apiserver/service/url.go

-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ func (u *URLPath) WithTopo(req *restful.Request) (isHit bool) {
111111
from, to, isHit = rootPath, topoRoot, true
112112
case kubeURLRegexp.MatchString(string(*u)):
113113
from, to, isHit = rootPath, topoRoot, true
114-
case topoURLRegexp.MatchString(string(*u)):
115-
from, to, isHit = rootPath, topoRoot, true
116114

117115
default:
118116
isHit = false

src/scene_server/proc_server/service/servicetemplate.go

+55-39
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
package service
1414

1515
import (
16-
"encoding/json"
17-
"fmt"
1816
"reflect"
19-
"sort"
2017
"strconv"
2118
"strings"
2219

@@ -168,7 +165,8 @@ func (ps *ProcServer) GetServiceTemplate(ctx *rest.Contexts) {
168165
templateIDStr := ctx.Request.PathParameter(common.BKServiceTemplateIDField)
169166
templateID, err := strconv.ParseInt(templateIDStr, 10, 64)
170167
if err != nil {
171-
ctx.RespErrorCodeF(common.CCErrCommParamsInvalid, "create service template failed, err: %v", common.BKServiceTemplateIDField, err)
168+
ctx.RespErrorCodeF(common.CCErrCommParamsInvalid, "create service template failed, err: %v",
169+
common.BKServiceTemplateIDField, err)
172170
return
173171
}
174172
template, err := ps.CoreAPI.CoreService().Process().GetServiceTemplate(ctx.Kit.Ctx, ctx.Kit.Header, templateID)
@@ -185,10 +183,12 @@ func (ps *ProcServer) GetServiceTemplateDetail(ctx *rest.Contexts) {
185183
templateIDStr := ctx.Request.PathParameter(common.BKServiceTemplateIDField)
186184
templateID, err := strconv.ParseInt(templateIDStr, 10, 64)
187185
if err != nil {
188-
ctx.RespErrorCodeF(common.CCErrCommParamsInvalid, "create service template failed, err: %v", common.BKServiceTemplateIDField, err)
186+
ctx.RespErrorCodeF(common.CCErrCommParamsInvalid, "create service template failed, err: %v",
187+
common.BKServiceTemplateIDField, err)
189188
return
190189
}
191-
templateDetail, err := ps.CoreAPI.CoreService().Process().GetServiceTemplateWithStatistics(ctx.Kit.Ctx, ctx.Kit.Header, templateID)
190+
templateDetail, err := ps.CoreAPI.CoreService().Process().GetServiceTemplateWithStatistics(ctx.Kit.Ctx,
191+
ctx.Kit.Header, templateID)
192192
if err != nil {
193193
ctx.RespWithError(err, common.CCErrCommHTTPDoRequestFailed, "get service template failed, err: %v", err)
194194
return
@@ -424,8 +424,9 @@ func (ps *ProcServer) ExecServiceTemplateHostApplyRule(ctx *rest.Contexts) {
424424
ctx.RespEntity(nil)
425425
}
426426

427-
func (s *ProcServer) getUpdateDataStrByApplyRule(kit *rest.Kit, rules []metadata.CreateHostApplyRuleOption) (
428-
string, errors.CCErrorCoder) {
427+
func (s *ProcServer) getUpdateDataByApplyRule(kit *rest.Kit, rules []metadata.CreateHostApplyRuleOption) (
428+
map[string]interface{}, errors.CCErrorCoder) {
429+
429430
attributeIDs := make([]int64, 0)
430431
attrIDMap := make(map[int64]struct{})
431432
for _, rule := range rules {
@@ -449,51 +450,61 @@ func (s *ProcServer) getUpdateDataStrByApplyRule(kit *rest.Kit, rules []metadata
449450
attrRes, err := s.CoreAPI.CoreService().Model().ReadModelAttr(kit.Ctx, kit.Header, common.BKInnerObjIDHost, attCond)
450451
if err != nil {
451452
blog.Errorf("read model attr failed, err: %v, attrCond: %#v, rid: %s", err, attCond, kit.Rid)
452-
return "", kit.CCError.CCError(common.CCErrCommHTTPDoRequestFailed)
453+
return nil, kit.CCError.CCError(common.CCErrCommHTTPDoRequestFailed)
453454
}
454455

455456
attrMap := make(map[int64]string)
456457
for _, attr := range attrRes.Info {
457458
attrMap[attr.ID] = attr.PropertyID
458459
}
459460

460-
fields := make([]string, len(rules))
461+
updateData := make(map[string]interface{})
461462

462-
for index, field := range rules {
463-
value, _ := json.Marshal(field.PropertyValue)
464-
fields[index] = fmt.Sprintf(`"%s":%s`, attrMap[field.AttributeID], string(value))
463+
for _, field := range rules {
464+
updateData[attrMap[field.AttributeID]] = field.PropertyValue
465465
}
466466

467-
sort.Strings(fields)
468-
return "{" + strings.Join(fields, ",") + "}", nil
467+
return updateData, nil
469468
}
470469

471-
func generateCondition(dataStr string, hostIDs []int64) (map[string]interface{}, map[string]interface{}) {
472-
data := make(map[string]interface{})
473-
_ = json.Unmarshal([]byte(dataStr), &data)
470+
func generateCondition(kit *rest.Kit, data map[string]interface{}, hostIDs []int64) (map[string]interface{},
471+
errors.CCErrorCoder) {
474472

475473
cond := make([]map[string]interface{}, 0)
476474

477475
for key, value := range data {
476+
// host special field is array type
477+
if util.InArray(key, metadata.HostSpecialFields) {
478+
valueStr, ok := value.(string)
479+
if !ok {
480+
blog.Errorf("host special field %s value %v is not string type, rid: %s", key, value, kit.Rid)
481+
return nil, kit.CCError.CCErrorf(common.CCErrCommParamsNeedString, key)
482+
}
483+
value = strings.Split(valueStr, ",")
484+
}
478485
cond = append(cond, map[string]interface{}{
479486
key: map[string]interface{}{common.BKDBNE: value},
480487
})
481488
}
489+
482490
mergeCond := map[string]interface{}{
483491
common.BKHostIDField: map[string]interface{}{common.BKDBIN: hostIDs},
484492
common.BKDBOR: cond,
485493
}
486-
return mergeCond, data
494+
return mergeCond, nil
487495
}
488496

489497
func (s *ProcServer) updateHostAttributes(kit *rest.Kit, planResult *metadata.HostApplyServiceTemplateOption,
490498
hostIDs []int64) errors.CCErrorCoder {
491499

492-
dataStr, err := s.getUpdateDataStrByApplyRule(kit, planResult.AdditionalRules)
500+
data, err := s.getUpdateDataByApplyRule(kit, planResult.AdditionalRules)
501+
if err != nil {
502+
return err
503+
}
504+
mergeCond, err := generateCondition(kit, data, hostIDs)
493505
if err != nil {
494506
return err
495507
}
496-
mergeCond, data := generateCondition(dataStr, hostIDs)
497508
counts, cErr := s.Engine.CoreAPI.CoreService().Count().GetCountByFilter(kit.Ctx, kit.Header,
498509
common.BKTableNameBaseHost, []map[string]interface{}{mergeCond})
499510
if cErr != nil {
@@ -744,7 +755,8 @@ func (ps *ProcServer) UpdateServiceTemplate(ctx *rest.Contexts) {
744755
var tpl *metadata.ServiceTemplate
745756
txnErr := ps.Engine.CoreAPI.CoreService().Txn().AutoRunTxn(ctx.Kit.Ctx, ctx.Kit.Header, func() error {
746757
var err error
747-
tpl, err = ps.CoreAPI.CoreService().Process().UpdateServiceTemplate(ctx.Kit.Ctx, ctx.Kit.Header, option.ID, updateParam)
758+
tpl, err = ps.CoreAPI.CoreService().Process().UpdateServiceTemplate(ctx.Kit.Ctx, ctx.Kit.Header, option.ID,
759+
updateParam)
748760
if err != nil {
749761
blog.Errorf("update service template failed, err: %v", err)
750762
return err
@@ -988,19 +1000,18 @@ func (ps *ProcServer) ListServiceTemplates(ctx *rest.Contexts) {
9881000
func (ps *ProcServer) FindServiceTemplateCountInfo(ctx *rest.Contexts) {
9891001
bizID, err := strconv.ParseInt(ctx.Request.PathParameter(common.BKAppIDField), 10, 64)
9901002
if err != nil {
991-
blog.Errorf("FindServiceTemplateCountInfo failed, parse bk_biz_id error, err: %s, rid: %s", err, ctx.Kit.Rid)
1003+
blog.Errorf("parse bk_biz_id error, err: %v, rid: %s", err, ctx.Kit.Rid)
9921004
ctx.RespAutoError(ctx.Kit.CCError.CCErrorf(common.CCErrCommParamsIsInvalid, "bk_biz_id"))
9931005
return
9941006
}
9951007

9961008
input := new(metadata.FindServiceTemplateCountInfoOption)
997-
if err := ctx.DecodeInto(input); nil != err {
1009+
if err := ctx.DecodeInto(input); err != nil {
9981010
ctx.RespAutoError(err)
9991011
return
10001012
}
10011013

1002-
rawErr := input.Validate()
1003-
if rawErr.ErrCode != 0 {
1014+
if rawErr := input.Validate(); rawErr.ErrCode != 0 {
10041015
ctx.RespAutoError(rawErr.ToCCError(ctx.Kit.CCError))
10051016
return
10061017
}
@@ -1015,38 +1026,44 @@ func (ps *ProcServer) FindServiceTemplateCountInfo(ctx *rest.Contexts) {
10151026
}
10161027

10171028
// process templates reference count
1018-
processTemplateCounts, err := ps.CoreAPI.CoreService().Count().GetCountByFilter(ctx.Kit.Ctx, ctx.Kit.Header, common.BKTableNameProcessTemplate, filters)
1029+
processTemplateCounts, err := ps.CoreAPI.CoreService().Count().GetCountByFilter(ctx.Kit.Ctx, ctx.Kit.Header,
1030+
common.BKTableNameProcessTemplate, filters)
10191031
if err != nil {
1020-
ctx.RespWithError(err, common.CCErrProcGetProcessTemplatesFailed, "count process template by filters: %+v failed.", filters)
1032+
blog.Errorf("count process template by filters: %+v failed, err: %v, rid: %s", filters, err, ctx.Kit.Rid)
1033+
ctx.RespAutoError(err)
10211034
return
10221035
}
10231036
if len(processTemplateCounts) != len(input.ServiceTemplateIDs) {
1024-
ctx.RespWithError(ctx.Kit.CCError.CCError(common.CCErrProcGetProcessTemplatesFailed), common.CCErrProcGetProcessTemplatesFailed,
1025-
"the count of process must be equal with the count of service templates, filters:%#v", filters)
1037+
blog.Errorf("proc temp count != service temp count, filters: %#v, rid: %s", filters, ctx.Kit.Rid)
1038+
ctx.RespAutoError(ctx.Kit.CCError.CCError(common.CCErrProcGetProcessTemplatesFailed))
10261039
return
10271040
}
10281041

10291042
// module reference count
1030-
moduleCounts, err := ps.CoreAPI.CoreService().Count().GetCountByFilter(ctx.Kit.Ctx, ctx.Kit.Header, common.BKTableNameBaseModule, filters)
1043+
moduleCounts, err := ps.CoreAPI.CoreService().Count().GetCountByFilter(ctx.Kit.Ctx, ctx.Kit.Header,
1044+
common.BKTableNameBaseModule, filters)
10311045
if err != nil {
1032-
ctx.RespWithError(err, common.CCErrTopoModuleSelectFailed, "count process template by filters: %+v failed.", filters)
1046+
blog.Errorf("count module by filters: %+v failed, err: %v, rid: %s", filters, err, ctx.Kit.Rid)
1047+
ctx.RespAutoError(err)
10331048
return
10341049
}
10351050
if len(moduleCounts) != len(input.ServiceTemplateIDs) {
1036-
ctx.RespWithError(ctx.Kit.CCError.CCError(common.CCErrTopoModuleSelectFailed), common.CCErrTopoModuleSelectFailed,
1037-
"the count of modules must be equal with the count of service templates, filters:%#v", filters)
1051+
blog.Errorf("module count != service template count, filters: %#v, rid: %s", filters, ctx.Kit.Rid)
1052+
ctx.RespAutoError(ctx.Kit.CCError.CCError(common.CCErrTopoModuleSelectFailed))
10381053
return
10391054
}
10401055

10411056
// service instance reference count
1042-
serviceInstanceCounts, err := ps.CoreAPI.CoreService().Count().GetCountByFilter(ctx.Kit.Ctx, ctx.Kit.Header, common.BKTableNameServiceInstance, filters)
1057+
serviceInstanceCounts, err := ps.CoreAPI.CoreService().Count().GetCountByFilter(ctx.Kit.Ctx, ctx.Kit.Header,
1058+
common.BKTableNameServiceInstance, filters)
10431059
if err != nil {
1044-
ctx.RespWithError(err, common.CCErrProcGetServiceInstancesFailed, "count process template by filters: %+v failed.", filters)
1060+
blog.Errorf("count service instance by filters: %+v failed, err: %v, rid: %s", filters, err, ctx.Kit.Rid)
1061+
ctx.RespAutoError(err)
10451062
return
10461063
}
10471064
if len(serviceInstanceCounts) != len(input.ServiceTemplateIDs) {
1048-
ctx.RespWithError(ctx.Kit.CCError.CCError(common.CCErrProcGetServiceInstancesFailed), common.CCErrProcGetServiceInstancesFailed,
1049-
"the count of service instance must be equal with the count of service templates, filters:%#v", filters)
1065+
blog.Errorf("service instance count != service template count, filters: %#v, rid: %s", filters, ctx.Kit.Rid)
1066+
ctx.RespAutoError(ctx.Kit.CCError.CCError(common.CCErrProcGetServiceInstancesFailed))
10501067
return
10511068
}
10521069

@@ -1059,7 +1076,6 @@ func (ps *ProcServer) FindServiceTemplateCountInfo(ctx *rest.Contexts) {
10591076
ModuleCount: moduleCounts[idx],
10601077
})
10611078
}
1062-
10631079
ctx.RespEntity(result)
10641080
}
10651081

src/ui/src/magicbox/magicbox.scss

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
line-height: 1.4;
6464
.bk-dialog-header-inner {
6565
white-space: normal;
66+
word-break: break-all;
6667
}
6768
}
6869
}

src/ui/src/views/host-apply/children/topology-tree.vue

+33-4
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,36 @@
276276
this.$refs.tree.setExpanded(treeNode?.parent.id, { emitEvent: true })
277277
}
278278
},
279+
getDisabledIds() {
280+
const disabledIds = []
281+
const findIds = function (data, parent) {
282+
const { length } = data
283+
const disabledLength = disabledIds.length
284+
let nowLength = 0
285+
for (const item of data) {
286+
if (item.child.length) {
287+
const match = findIds(item.child, item)
288+
if (match) {
289+
nowLength = nowLength + 1
290+
}
291+
} else {
292+
const { host_apply_rule_count: count } = item
293+
if (count > 0) continue
294+
nowLength = nowLength + 1
295+
disabledIds.push(`${item.bk_obj_id}_${item.bk_inst_id}`)
296+
}
297+
}
298+
// 该次循坏中子元素都无法进行选中操作
299+
if (nowLength && parent && length === nowLength) {
300+
disabledIds.splice(disabledLength, nowLength)
301+
disabledIds.push(`${parent.bk_obj_id}_${parent.bk_inst_id}`)
302+
return true
303+
}
304+
return false
305+
}
306+
findIds(this.treeData)
307+
return disabledIds
308+
},
279309
getTreeStat() {
280310
const stat = {
281311
firstModule: null,
@@ -319,18 +349,17 @@
319349
},
320350
setNodeDisabled() {
321351
const { withTemplateHostApplyIds, noRuleIds } = this.treeStat
322-
352+
const nodeIds = withTemplateHostApplyIds.map(id => `module_${id}`)
323353
// 处于批量操作状态disabled存在模板配置的节点
324354
if (withTemplateHostApplyIds?.length) {
325-
const nodeIds = withTemplateHostApplyIds.map(id => `module_${id}`)
326355
this.$refs.tree.setDisabled(nodeIds, { emitEvent: true, disabled: Boolean(this.action) })
327356
}
328357

329358
// 批量删除操作状态disabled不存在模块配置的节点
330359
if (noRuleIds?.length) {
331360
// 仅需处理未配置模板的节点
332-
const nodeIds = noRuleIds.filter(id => !withTemplateHostApplyIds.includes(id)).map(id => `module_${id}`)
333-
this.$refs.tree.setDisabled(nodeIds, { emitEvent: true, disabled: this.isDel })
361+
const allDisabledIds = this.getDisabledIds().filter(id => !nodeIds.includes(id))
362+
this.$refs.tree.setDisabled(allDisabledIds, { emitEvent: true, disabled: this.isDel })
334363
}
335364
},
336365
updateNodeStatus(id, { isClose, isClear }) {

src/ui/src/views/index/children/full-text-search/search-bar.vue

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142
}
143143

144144
const handleSearch = () => {
145+
if (!keyword.value) {
146+
searchInput.value.focus()
147+
return
148+
}
145149
store.commit('fullTextSearch/setSearchHistory', keyword.value)
146150
forceHide.value = true
147151
const query = pickQuery(route.value.query, ['tab'])

0 commit comments

Comments
 (0)