(ctx context.Context, id string, address string)
| 270 | } |
| 271 | |
| 272 | func (s *imlClusterService) UpdateAddress(ctx context.Context, id string, address string) ([]*Node, error) { |
| 273 | |
| 274 | info, err := admin.Admin(address).Info(ctx) |
| 275 | if err != nil { |
| 276 | return nil, err |
| 277 | } |
| 278 | //if info.Cluster != id { |
| 279 | // return nil, errors.New("cluster id not match") |
| 280 | //} |
| 281 | operator := utils.UserId(ctx) |
| 282 | now := time.Now() |
| 283 | cv, err := s.store.FirstQuery(ctx, "`uuid` = ?", []interface{}{id}, "id desc") |
| 284 | if err != nil { |
| 285 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 286 | return nil, err |
| 287 | } |
| 288 | cv = &cluster.Cluster{ |
| 289 | UUID: id, |
| 290 | Name: "默认集群", |
| 291 | Resume: "默认集群", |
| 292 | |
| 293 | Creator: operator, |
| 294 | CreateAt: now, |
| 295 | } |
| 296 | } |
| 297 | cv.Cluster = info.Cluster |
| 298 | |
| 299 | // check node |
| 300 | nodeIds := utils.SliceToSlice(info.Nodes, func(i *admin.Node) string { |
| 301 | return i.Id |
| 302 | }) |
| 303 | nodeNames := utils.SliceToSlice(info.Nodes, func(i *admin.Node) string { |
| 304 | return i.Name |
| 305 | }) |
| 306 | |
| 307 | nodeExist, err := s.nodeStore.FirstQuery(ctx, "`cluster` = ? and (`uuid` in (?) or `name` in (?))", []interface{}{id, nodeIds, nodeNames}, "id desc") |
| 308 | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| 309 | return nil, err |
| 310 | } |
| 311 | if nodeExist != nil && id != nodeExist.Cluster { |
| 312 | return nil, errors.New("node already exists") |
| 313 | } |
| 314 | s.genNodeEntity(id, info.Nodes) |
| 315 | nodeEn, addrEn := s.genNodeEntity(id, info.Nodes) |
| 316 | err = s.store.Transaction(ctx, func(ctx context.Context) error { |
| 317 | _, err := s.nodeStore.DeleteWhere(ctx, map[string]interface{}{ |
| 318 | "cluster": id, |
| 319 | }) |
| 320 | if err != nil { |
| 321 | return err |
| 322 | } |
| 323 | _, err = s.nodeAddressStore.DeleteWhere(ctx, map[string]interface{}{ |
| 324 | "cluster": id, |
| 325 | }) |
| 326 | if err != nil { |
| 327 | return err |
| 328 | } |
| 329 | cv.Updater = operator |
nothing calls this directly
no test coverage detected