MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / buildBatchUpgradePlans

Function buildBatchUpgradePlans

agent/app/service/agents.go:501–557  ·  view source on GitHub ↗
(req dto.AgentBatchUpgradeReq)

Source from the content-addressed store, hash-verified

499}
500
501func 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

Callers 1

BatchUpgradeMethod · 0.85

Calls 7

listBatchAgentsFunction · 0.85
loadBatchAgentInstallFunction · 0.85
buildBatchUpgradeTaskIDFunction · 0.85
GetFirstMethod · 0.65
WithAppIdMethod · 0.65
WithVersionMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected