diff --git a/agent/app/dto/request/app.go b/agent/app/dto/request/app.go index 913e32e2f939..145168ea99f9 100644 --- a/agent/app/dto/request/app.go +++ b/agent/app/dto/request/app.go @@ -54,13 +54,14 @@ type AppContainerConfig struct { type AppInstalledSearch struct { dto.PageInfo - Type string `json:"type"` - Name string `json:"name"` - Tags []string `json:"tags"` - Update bool `json:"update"` - Unused bool `json:"unused"` - All bool `json:"all"` - Sync bool `json:"sync"` + Type string `json:"type"` + Name string `json:"name"` + Tags []string `json:"tags"` + Update bool `json:"update"` + Unused bool `json:"unused"` + All bool `json:"all"` + Sync bool `json:"sync"` + CheckUpdate bool `json:"checkUpdate"` } type AppInstalledInfo struct { diff --git a/agent/app/service/app_install.go b/agent/app/service/app_install.go index e75b5a02b564..61d9c1c30107 100644 --- a/agent/app/service/app_install.go +++ b/agent/app/service/app_install.go @@ -121,7 +121,7 @@ func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []respo } } - installDTOs, _ := handleInstalled(installs, req.Update, req.Sync) + installDTOs, _ := handleInstalled(installs, req.Update, req.Sync, req.CheckUpdate) if req.Update { total = int64(len(installDTOs)) } @@ -238,7 +238,7 @@ func (a *AppInstallService) SearchForWebsite(req request.AppInstalledSearch) ([] } } - return handleInstalled(installs, false, true) + return handleInstalled(installs, false, true, false) } func (a *AppInstallService) Operate(req request.AppInstalledOperate) error { diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index 1dda2de1d33a..d30664292ede 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -1531,7 +1531,7 @@ func synAppInstall(containers map[string]container.Summary, appInstall *model.Ap _ = appInstallRepo.Save(context.Background(), appInstall) } -func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) ([]response.AppInstallDTO, error) { +func handleInstalled(appInstallList []model.AppInstall, updated, sync, checkUpdate bool) ([]response.AppInstallDTO, error) { var ( res []response.AppInstallDTO containersMap map[string]container.Summary @@ -1554,6 +1554,7 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) if updated && ignoreUpdate(installed) { continue } + if sync && !doNotNeedSync(installed) { synAppInstall(containersMap, &installed, false) } @@ -1583,20 +1584,30 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) Container: installed.ContainerName, ServiceName: strings.ToLower(installed.ServiceName), } - if !updated { + + if !updated && !checkUpdate { installDTO.LinkDB = hasLinkDB(installed.ID) res = append(res, installDTO) continue } + if installed.Version == "latest" { + if checkUpdate { + installDTO.CanUpdate = false + installDTO.LinkDB = hasLinkDB(installed.ID) + res = append(res, installDTO) + } continue } + installDTO.DockerCompose = installed.DockerCompose installDTO.IsEdit = isEditCompose(installed) + details, err := appDetailRepo.GetBy(appDetailRepo.WithAppId(installed.App.ID)) if err != nil { return nil, err } + var versions []string for _, appDetail := range details { ignores, _ := appIgnoreUpgradeRepo.List(runtimeRepo.WithDetailId(appDetail.ID), appIgnoreUpgradeRepo.WithScope("version")) @@ -1608,11 +1619,19 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) } versions = append(versions, appDetail.Version) } + if len(versions) == 0 { + if checkUpdate { + installDTO.CanUpdate = false + installDTO.LinkDB = hasLinkDB(installed.ID) + res = append(res, installDTO) + } continue } + versions = common.GetSortedVersions(versions) lastVersion := versions[0] + if installed.App.Key == constant.AppMysql || installed.App.Key == constant.AppMysqlCluster { for _, version := range versions { majorVersion := getMajorVersion(installed.Version) @@ -1624,15 +1643,23 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) } } } + if common.IsCrossVersion(installed.Version, lastVersion) { installDTO.CanUpdate = installed.App.CrossVersionUpdate } else { installDTO.CanUpdate = common.CompareVersion(lastVersion, installed.Version) } - if installDTO.CanUpdate { + + if updated { + if installDTO.CanUpdate { + res = append(res, installDTO) + } + } else if checkUpdate { + installDTO.LinkDB = hasLinkDB(installed.ID) res = append(res, installDTO) } } + return res, nil }