(ctx context.Context, subscribeInfo *catalogue_dto.SubscribeService)
| 223 | } |
| 224 | |
| 225 | func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catalogue_dto.SubscribeService) error { |
| 226 | if len(subscribeInfo.Applications) == 0 { |
| 227 | return fmt.Errorf("applications is empty") |
| 228 | } |
| 229 | // 获取服务的基本信息 |
| 230 | s, err := i.serviceService.Get(ctx, subscribeInfo.Service) |
| 231 | if err != nil { |
| 232 | return fmt.Errorf("get service failed: %w", err) |
| 233 | } |
| 234 | if !s.AsServer { |
| 235 | return fmt.Errorf("service does not support subscribe") |
| 236 | } |
| 237 | |
| 238 | userId := utils.UserId(ctx) |
| 239 | return i.transaction.Transaction(ctx, func(ctx context.Context) error { |
| 240 | |
| 241 | apps := make([]string, 0, len(subscribeInfo.Applications)) |
| 242 | |
| 243 | for _, appId := range subscribeInfo.Applications { |
| 244 | if appId == s.Id { |
| 245 | // 不能订阅自己 |
| 246 | continue |
| 247 | } |
| 248 | |
| 249 | appInfo, err := i.serviceService.Get(ctx, appId) |
| 250 | if err != nil { |
| 251 | return err |
| 252 | } |
| 253 | if !appInfo.AsApp { |
| 254 | // 当系统不可作为订阅方时,不可订阅 |
| 255 | continue |
| 256 | } |
| 257 | status := subscribe.ApplyStatusReview |
| 258 | if s.ApprovalType == service.ApprovalTypeAuto { |
| 259 | status = subscribe.ApplyStatusSubscribe |
| 260 | cs, err := i.clusterService.List(ctx) |
| 261 | if err != nil { |
| 262 | return err |
| 263 | } |
| 264 | for _, c := range cs { |
| 265 | err := i.onlineSubscriber(ctx, c.Uuid, &gateway.SubscribeRelease{ |
| 266 | Service: subscribeInfo.Service, |
| 267 | Application: appId, |
| 268 | Expired: "0", |
| 269 | }) |
| 270 | |
| 271 | if err != nil { |
| 272 | log.Errorf("online subscriber for cluster[%s] %v", c.Uuid, err) |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | err = i.subscribeApplyService.Create(ctx, &subscribe.CreateApply{ |
| 278 | Uuid: uuid.New().String(), |
| 279 | Service: subscribeInfo.Service, |
| 280 | Team: s.Team, |
| 281 | Application: appId, |
| 282 | ApplyTeam: appInfo.Team, |
nothing calls this directly
no test coverage detected