Skip to content
Merged
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
13 changes: 7 additions & 6 deletions cmd/config-server/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,12 @@ func (s *Service) ListAppsRest(ctx context.Context, req *pbcs.ListAppsRestReq) (
}

r := &pbds.ListAppsRestReq{
// BizId: strings.Join(spaceIdList, ","),
Start: req.Start,
Limit: req.Limit,
Search: req.Search,
BizId: req.BizId,
Start: req.Start,
Limit: req.Limit,
Search: req.Search,
All: req.All,
ProjectId: kt.ResolvedProjectID(req.GetProjectId()),
}
rp, err := s.client.DS.ListAppsRest(kt.RpcCtx(), r)
if err != nil {
Expand Down Expand Up @@ -275,8 +277,7 @@ func (s *Service) ListAppsRest(ctx context.Context, req *pbcs.ListAppsRestReq) (
}

// ListAppsBySpaceRest list apps with rest filter
func (s *Service) ListAppsBySpaceRest(ctx context.Context,
req *pbcs.ListAppsBySpaceRestReq) (*pbcs.ListAppsResp, error) {
func (s *Service) ListAppsBySpaceRest(ctx context.Context, req *pbcs.ListAppsBySpaceRestReq) (*pbcs.ListAppsResp, error) {
kt := kit.FromGrpcContext(ctx)

res := []*meta.ResourceAttribute{
Expand Down
2 changes: 2 additions & 0 deletions cmd/config-server/service/app_template_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ func (s *Service) GetReleasedAppBoundTmplRevision(ctx context.Context,
AppId: req.AppId,
ReleaseId: req.ReleaseId,
TemplateRevisionId: req.TemplateRevisionId,
ProjectId: grpcKit.ResolvedProjectID(req.ProjectId),
EnvId: grpcKit.ResolvedEnvID(req.EnvId),
}

rp, err := s.client.DS.GetReleasedAppBoundTmplRevision(grpcKit.RpcCtx(), r)
Expand Down
17 changes: 14 additions & 3 deletions cmd/config-server/service/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
pbcs "github.com/TencentBlueKing/bk-bscp/pkg/protocol/config-server"
pbapp "github.com/TencentBlueKing/bk-bscp/pkg/protocol/core/app"
pbgroup "github.com/TencentBlueKing/bk-bscp/pkg/protocol/core/group"
pbtset "github.com/TencentBlueKing/bk-bscp/pkg/protocol/core/template-set"
pbds "github.com/TencentBlueKing/bk-bscp/pkg/protocol/data-service"
"github.com/TencentBlueKing/bk-bscp/pkg/runtime/selector"
)
Expand Down Expand Up @@ -287,14 +288,13 @@ func (s *Service) ListAllGroups(ctx context.Context, req *pbcs.ListAllGroupsReq)
respData := make([]*pbcs.ListAllGroupsResp_ListAllGroupsData, 0, len(lgResp.Details))
for _, group := range lgResp.Details {
apps := make([]*pbcs.ListAllGroupsResp_ListAllGroupsData_BindApp, 0, len(group.Spec.BindApps))
var envID uint32

for _, appID := range group.Spec.BindApps {
if app, ok := appMap[appID]; ok && app != nil {
apps = append(apps, &pbcs.ListAllGroupsResp_ListAllGroupsData_BindApp{
Id: app.Id,
Name: app.Spec.Name,
})
envID = app.EnvId
}
}
data := &pbcs.ListAllGroupsResp_ListAllGroupsData{
Expand All @@ -303,7 +303,7 @@ func (s *Service) ListAllGroups(ctx context.Context, req *pbcs.ListAllGroupsReq)
Public: group.Spec.Public,
BindApps: apps,
Selector: group.Spec.Selector,
EnvId: envID,
EnvApps: buildGroupEnvApps(group.Spec.BindApps, appMap),
}
for _, d := range countResp.Data {
if d.GroupId == group.Id {
Expand Down Expand Up @@ -541,3 +541,14 @@ func (s *Service) isValidGrayPercentValue(value interface{}) bool {
// 验证范围:1-99
return percent >= 1.0 && percent <= 99.0
}

// buildGroupEnvApps 将分组绑定的服务按环境ID分组,委托给 pbtset.GroupAppsByEnv
func buildGroupEnvApps(bindApps []uint32, appMap map[uint32]*pbapp.App) []*pbtset.EnvApps {
appEnvMap := make(map[uint32]uint32, len(bindApps))
for _, appID := range bindApps {
if app, ok := appMap[appID]; ok && app != nil {
appEnvMap[appID] = app.EnvId
}
}
return pbtset.GroupAppsByEnv(bindApps, appEnvMap)
}
2 changes: 2 additions & 0 deletions cmd/config-server/service/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ func (s *Service) DeleteRelease(ctx context.Context, req *pbcs.DeleteReleaseReq)
BizId: req.BizId,
AppId: req.AppId,
ReleaseId: req.ReleaseId,
ProjectId: kt.ResolvedProjectID(req.ProjectId),
EnvId: kt.ResolvedEnvID(req.EnvId),
}
_, err = s.client.DS.DeleteRelease(kt.RpcCtx(), r)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/config-server/service/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func (s *Service) DeleteTmplsFromTmplSets(ctx context.Context, req *pbcs.DeleteT
TemplateIds: req.TemplateIds,
ExclusionOperation: req.ExclusionOperation,
NoSetSpecified: req.NoSetSpecified,
ProjectId: grpcKit.ResolvedProjectID(req.ProjectId),
}

if _, err := s.client.DS.DeleteTmplsFromTmplSets(egCtx, r); err != nil {
Expand Down
10 changes: 7 additions & 3 deletions cmd/config-server/service/template_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (s *Service) ListTemplateSets(ctx context.Context, req *pbcs.ListTemplateSe
Start: req.Start,
Limit: req.Limit,
All: req.All,
ProjectId: grpcKit.ResolvedProjectID(req.ProjectId),
}

rp, err := s.client.DS.ListTemplateSets(grpcKit.RpcCtx(), r)
Expand Down Expand Up @@ -184,8 +185,9 @@ func (s *Service) ListAppTemplateSets(ctx context.Context, req *pbcs.ListAppTemp
}

r := &pbds.ListAppTemplateSetsReq{
BizId: grpcKit.BizID,
AppId: req.AppId,
BizId: grpcKit.BizID,
AppId: req.AppId,
ProjectId: grpcKit.ResolvedProjectID(req.ProjectId),
}

rp, err := s.client.DS.ListAppTemplateSets(grpcKit.RpcCtx(), r)
Expand Down Expand Up @@ -224,7 +226,9 @@ func (s *Service) ListTemplateSetsByIDs(ctx context.Context, req *pbcs.ListTempl
}

r := &pbds.ListTemplateSetsByIDsReq{
Ids: req.Ids,
Ids: req.Ids,
BizId: req.BizId,
ProjectId: grpcKit.ResolvedProjectID(req.ProjectId),
}

rp, err := s.client.DS.ListTemplateSetsByIDs(grpcKit.RpcCtx(), r)
Expand Down
2 changes: 2 additions & 0 deletions cmd/data-service/service/template_binding_relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func (s *Service) ListTmplBoundUnnamedApps(ctx context.Context, req *pbds.ListTm
AppId: r.AppID,
AppName: appMap[r.AppID].Spec.Name,
EnvDisplay: appMap[r.AppID].Spec.EnvDisplay,
EnvId: appMap[r.AppID].EnvID,
})

}
Expand Down Expand Up @@ -885,6 +886,7 @@ func (s *Service) ListTmplSetBoundUnnamedApps(ctx context.Context, req *pbds.Lis
AppId: id,
AppName: appMap[id].Spec.Name,
EnvDisplay: appMap[id].Spec.EnvDisplay,
EnvId: appMap[id].EnvID,
})
}

Expand Down
72 changes: 69 additions & 3 deletions cmd/data-service/service/template_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,31 @@ func (s *Service) ListTemplateSets(ctx context.Context, req *pbds.ListTemplateSe
return nil, err
}

appIDs := make([]uint32, 0)
appIDMap := make(map[uint32]struct{})

for _, ts := range details {
for _, appID := range ts.Spec.BoundApps {
if _, ok := appIDMap[appID]; !ok {
appIDMap[appID] = struct{}{}
appIDs = append(appIDs, appID)
}
}
}

apps, err := s.dao.App().ListAppsByIDs(kt, req.BizId, req.ProjectId, appIDs)
if err != nil {
return nil, err
}

appEnvMap := make(map[uint32]uint32)
for _, app := range apps {
appEnvMap[app.ID] = app.EnvID
}

resp := &pbds.ListTemplateSetsResp{
Count: uint32(count),
Details: pbtset.PbTemplateSets(details),
Details: pbtset.PbTemplateSets(details, appEnvMap),
}
return resp, nil
}
Expand Down Expand Up @@ -321,8 +343,30 @@ func (s *Service) ListAppTemplateSets(ctx context.Context, req *pbds.ListAppTemp
return nil, err
}

appIDs := make([]uint32, 0)
appIDMap := make(map[uint32]struct{})

for _, ts := range details {
for _, appID := range ts.Spec.BoundApps {
if _, ok := appIDMap[appID]; !ok {
appIDMap[appID] = struct{}{}
appIDs = append(appIDs, appID)
}
}
}

apps, err := s.dao.App().ListAppsByIDs(kt, req.BizId, req.ProjectId, appIDs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Forward project_id when listing app template sets

When the project/env HTTP route for ListAppTemplateSets goes through config-server, cmd/config-server/service/template_set.go still builds the data-service request with only BizId and AppId, so this new lookup receives req.ProjectId == 0. Because ListAppsByIDs filters by ProjID, it returns no apps and appEnvMap stays empty, causing the newly added TemplateSet.env_id to be 0 for all template sets returned through that config API path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已处理

if err != nil {
return nil, err
}

appEnvMap := make(map[uint32]uint32)
for _, app := range apps {
appEnvMap[app.ID] = app.EnvID
}

resp := &pbds.ListAppTemplateSetsResp{
Details: pbtset.PbTemplateSets(details),
Details: pbtset.PbTemplateSets(details, appEnvMap),
}
return resp, nil
}
Expand All @@ -342,8 +386,30 @@ func (s *Service) ListTemplateSetsByIDs(ctx context.Context, req *pbds.ListTempl
return nil, err
}

appIDs := make([]uint32, 0)
appIDMap := make(map[uint32]struct{})

for _, ts := range details {
for _, appID := range ts.Spec.BoundApps {
if _, ok := appIDMap[appID]; !ok {
appIDMap[appID] = struct{}{}
appIDs = append(appIDs, appID)
}
}
}

apps, err := s.dao.App().ListAppsByIDs(kt, req.BizId, req.ProjectId, appIDs)
if err != nil {
return nil, err
}

appEnvMap := make(map[uint32]uint32)
for _, app := range apps {
appEnvMap[app.ID] = app.EnvID
}

resp := &pbds.ListTemplateSetsByIDsResp{
Details: pbtset.PbTemplateSets(details),
Details: pbtset.PbTemplateSets(details, appEnvMap),
}
return resp, nil
}
Expand Down
Loading
Loading