(req dto.AgentBatchUpgradeReq)
| 499 | } |
| 500 | |
| 501 | func buildBatchUpgradePlans(req dto.AgentBatchUpgradeReq) ([]batchUpgradePlan, []dto.AgentBatchUpgradeResult, error) { |
| 502 | agents, err := listBatchAgents(req.AgentType) |
| 503 | if err != nil { |
| 504 | return nil, nil, err |
| 505 | } |
| 506 | plans := make([]batchUpgradePlan, 0, len(agents)) |
| 507 | results := make([]dto.AgentBatchUpgradeResult, 0) |
| 508 | for _, agent := range agents { |
| 509 | result := dto.AgentBatchUpgradeResult{ |
| 510 | AgentID: agent.ID, |
| 511 | AgentName: agent.Name, |
| 512 | AppInstallID: agent.AppInstallID, |
| 513 | } |
| 514 | ctx, message := loadBatchAgentInstall(agent, req.AgentType) |
| 515 | if message != "" { |
| 516 | result.Message = message |
| 517 | results = append(results, result) |
| 518 | continue |
| 519 | } |
| 520 | install := ctx.install |
| 521 | result.AppInstallID = install.ID |
| 522 | if install.Status == constant.StatusInstalling || install.Status == constant.StatusUpgrading { |
| 523 | result.Message = fmt.Sprintf("agent status is %s", install.Status) |
| 524 | results = append(results, result) |
| 525 | continue |
| 526 | } |
| 527 | if install.Version == req.TargetVersion { |
| 528 | result.Success = true |
| 529 | result.Skipped = true |
| 530 | result.Message = "already target version" |
| 531 | results = append(results, result) |
| 532 | continue |
| 533 | } |
| 534 | detail, err := appDetailRepo.GetFirst(appDetailRepo.WithAppId(install.AppId), appDetailRepo.WithVersion(req.TargetVersion)) |
| 535 | if err != nil { |
| 536 | result.Message = err.Error() |
| 537 | results = append(results, result) |
| 538 | continue |
| 539 | } |
| 540 | if detail.ID == 0 { |
| 541 | result.Message = fmt.Sprintf("target version %s not found", req.TargetVersion) |
| 542 | results = append(results, result) |
| 543 | continue |
| 544 | } |
| 545 | plans = append(plans, batchUpgradePlan{ |
| 546 | ctx: ctx, |
| 547 | req: request.AppInstallUpgrade{ |
| 548 | InstallID: install.ID, |
| 549 | DetailID: detail.ID, |
| 550 | Backup: req.Backup, |
| 551 | PullImage: req.PullImage, |
| 552 | TaskID: buildBatchUpgradeTaskID(req.TaskID, install.ID), |
| 553 | }, |
| 554 | }) |
| 555 | } |
| 556 | return plans, results, nil |
| 557 | } |
| 558 |
no test coverage detected