Skip to content

Commit c5e8ffd

Browse files
authored
chore: installed app version read service (#6162)
* chore: refactoring installed app read service * fix: query from clause issue * fix: improved query * fix: info logger * removed todos * wip * chore: wire refactoring * pointer struct * renamed IsZero to IsEmpty * reverted test commit changes
1 parent 2d63abe commit c5e8ffd

File tree

12 files changed

+98
-27
lines changed

12 files changed

+98
-27
lines changed

cmd/external-app/wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/sql/repository/app/AppRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type App struct {
4141
sql.AuditLog
4242
}
4343

44-
func (app *App) IsZero() bool {
44+
func (app *App) IsEmpty() bool {
4545
if app == nil {
4646
return true
4747
}

pkg/appStore/discover/repository/AppStoreApplicationVersionRepository.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ type AppStoreApplicationVersion struct {
7979
AppStore *AppStore
8080
}
8181

82+
func (a *AppStoreApplicationVersion) IsEmpty() bool {
83+
if a == nil {
84+
return true
85+
}
86+
return a.Id == 0
87+
}
88+
8289
func (impl AppStoreApplicationVersionRepositoryImpl) GetChartInfoById(id int) (*AppStoreApplicationVersion, error) {
8390
var appStoreWithVersion AppStoreApplicationVersion
8491
err := impl.dbConnection.Model(&appStoreWithVersion).Column("readme", "values_schema_json", "notes", "id").

pkg/appStore/installedApp/read/InstalledAppReadEAService.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ type InstalledAppReadServiceEA interface {
2727
// Only the minimum details are fetched.
2828
// Refer bean.InstalledAppMin for more details.
2929
GetInstalledAppByInstalledAppVersionId(installedAppVersionId int) (*bean.InstalledAppMin, error)
30+
// GetInstalledAppVersionIncludingDeleted will return the installed app version by installed app version id.
31+
// Both active and deleted installed app versions are fetched.
32+
// Additional details like app store details are also fetched.
33+
// Refer bean.InstalledAppVersionWithAppStoreDetails for more details.
34+
GetInstalledAppVersionIncludingDeleted(installedAppVersionId int) (*bean.InstalledAppVersionWithAppStoreDetails, error)
3035
}
3136

3237
type InstalledAppReadServiceEAImpl struct {
@@ -83,3 +88,12 @@ func (impl *InstalledAppReadServiceEAImpl) GetInstalledAppByInstalledAppVersionI
8388
}
8489
return adapter.GetInstalledAppInternal(installedAppModel).GetInstalledAppMin(), nil
8590
}
91+
92+
func (impl *InstalledAppReadServiceEAImpl) GetInstalledAppVersionIncludingDeleted(installedAppVersionId int) (*bean.InstalledAppVersionWithAppStoreDetails, error) {
93+
installedAppVersionModel, err := impl.installedAppRepository.GetInstalledAppVersionIncludingDeleted(installedAppVersionId)
94+
if err != nil {
95+
impl.logger.Errorw("error while fetching installed app version by installed app version id", "installedAppVersionId", installedAppVersionId, "error", err)
96+
return nil, err
97+
}
98+
return adapter.GetInstalledAppVersionWithAppStoreDetails(installedAppVersionModel), nil
99+
}

pkg/appStore/installedApp/read/adapter/adapter.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ func GetInstalledAppInternal(installedAppModel *repository.InstalledApps) *bean.
1515
installedAppInternal := &bean.InstalledAppWithEnvAndClusterDetails{}
1616
installedAppInternal.InstalledAppMin = GetInstalledAppMin(installedAppModel)
1717
// Extra App details
18-
if !installedAppModel.App.IsZero() {
18+
if !installedAppModel.App.IsEmpty() {
1919
installedAppInternal.AppName = installedAppModel.App.AppName
2020
installedAppInternal.AppOfferingMode = installedAppModel.App.AppOfferingMode
2121
installedAppInternal.TeamId = installedAppModel.App.TeamId
2222
}
2323
// Extra Environment details
24-
if !installedAppModel.Environment.IsZero() {
24+
if !installedAppModel.Environment.IsEmpty() {
2525
installedAppInternal.EnvironmentName = installedAppModel.Environment.Name
2626
installedAppInternal.EnvironmentIdentifier = installedAppModel.Environment.EnvironmentIdentifier
2727
installedAppInternal.Namespace = installedAppModel.Environment.Namespace
2828
installedAppInternal.ClusterId = installedAppModel.Environment.ClusterId
2929
}
3030
// Cluster details
31-
if !installedAppModel.Environment.Cluster.IsZero() {
31+
if !installedAppModel.Environment.Cluster.IsEmpty() {
3232
installedAppInternal.ClusterName = installedAppModel.Environment.Cluster.ClusterName
3333
}
3434
return installedAppInternal
@@ -73,3 +73,38 @@ func GetInstalledAppDeleteRequest(installedAppModel *repository.InstallAppDelete
7373
Namespace: installedAppModel.Namespace,
7474
}
7575
}
76+
77+
// GetInstalledAppVersionMin will return the installed app version minimum details.
78+
// - input: installedAppVersionModel *repository.InstalledAppVersions
79+
// - returns: *bean.InstalledAppVersionMin
80+
func GetInstalledAppVersionMin(installedAppVersionModel *repository.InstalledAppVersions) *bean.InstalledAppVersionMin {
81+
if installedAppVersionModel == nil {
82+
return nil
83+
}
84+
return &bean.InstalledAppVersionMin{
85+
Id: installedAppVersionModel.Id,
86+
InstalledAppId: installedAppVersionModel.InstalledAppId,
87+
AppStoreApplicationVersionId: installedAppVersionModel.AppStoreApplicationVersionId,
88+
ValuesYaml: installedAppVersionModel.ValuesYaml,
89+
Active: installedAppVersionModel.Active,
90+
ReferenceValueId: installedAppVersionModel.ReferenceValueId,
91+
ReferenceValueKind: installedAppVersionModel.ReferenceValueKind,
92+
}
93+
}
94+
95+
// GetInstalledAppVersionWithAppStoreDetails will return the installed app version with app store details.
96+
// - input: installedAppVersionModel *repository.InstalledAppVersions
97+
// - returns: *bean.InstalledAppVersionWithAppStoreDetails
98+
func GetInstalledAppVersionWithAppStoreDetails(installedAppVersionModel *repository.InstalledAppVersions) *bean.InstalledAppVersionWithAppStoreDetails {
99+
if installedAppVersionModel == nil {
100+
return nil
101+
}
102+
versionDetails := &bean.InstalledAppVersionWithAppStoreDetails{
103+
InstalledAppVersionMin: GetInstalledAppVersionMin(installedAppVersionModel),
104+
}
105+
// Extra App Store Application Version details
106+
if !installedAppVersionModel.AppStoreApplicationVersion.IsEmpty() {
107+
versionDetails.AppStoreVersion = installedAppVersionModel.AppStoreApplicationVersion.Version
108+
}
109+
return versionDetails
110+
}

pkg/appStore/installedApp/read/bean/bean.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,20 @@ func (i *InstalledAppWithEnvAndClusterDetails) GetInstalledAppWithEnvDetails() *
6969
}
7070
return i.InstalledAppWithEnvDetails
7171
}
72+
73+
type InstalledAppVersionMin struct {
74+
// Installed App Version details
75+
Id int
76+
InstalledAppId int
77+
AppStoreApplicationVersionId int
78+
ValuesYaml string
79+
Active bool
80+
ReferenceValueId int
81+
ReferenceValueKind string
82+
}
83+
84+
type InstalledAppVersionWithAppStoreDetails struct {
85+
*InstalledAppVersionMin
86+
// Extra App Store Version details
87+
AppStoreVersion string
88+
}

pkg/appStore/installedApp/repository/InstalledAppRepository.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ type InstalledAppRepository interface {
120120
GetInstalledApp(id int) (*InstalledApps, error)
121121
GetInstalledAppsByAppId(appId int) (InstalledApps, error)
122122
GetInstalledAppVersion(id int) (*InstalledAppVersions, error)
123-
GetInstalledAppVersionAny(id int) (*InstalledAppVersions, error)
123+
// GetInstalledAppVersionIncludingDeleted -
124+
// For the given installed app version id, it will return the installed app version (both active and inactive)
125+
// - returns InstalledAppVersions by id for both active and inactive versions
126+
GetInstalledAppVersionIncludingDeleted(id int) (*InstalledAppVersions, error)
124127
GetAllInstalledApps(filter *appStoreBean.AppStoreFilter) ([]InstalledAppsWithChartDetails, error)
125128
GetAllInstalledAppsByAppStoreId(appStoreId int) ([]InstalledAppAndEnvDetails, error)
126129
GetAllInstalledAppsByChartRepoId(chartRepoId int) ([]InstalledAppAndEnvDetails, error)
@@ -133,7 +136,6 @@ type InstalledAppRepository interface {
133136
GetConnection() (dbConnection *pg.DB)
134137
GetInstalledAppVersionByInstalledAppIdMeta(installedAppId int) ([]*InstalledAppVersions, error)
135138
GetActiveInstalledAppVersionByInstalledAppId(installedAppId int) (*InstalledAppVersions, error)
136-
GetLatestInstalledAppVersionByGitHash(gitHash string) (*InstalledAppVersions, error)
137139
GetClusterComponentByClusterId(clusterId int) ([]*InstalledApps, error) //unused
138140
GetClusterComponentByClusterIds(clusterIds []int) ([]*InstalledApps, error) //unused
139141
GetInstalledAppVersionByAppIdAndEnvId(appId int, envId int) (*InstalledAppVersions, error)
@@ -356,16 +358,6 @@ func (impl *InstalledAppRepositoryImpl) GetActiveInstalledAppVersionByInstalledA
356358
return model, err
357359
}
358360

359-
func (impl *InstalledAppRepositoryImpl) GetLatestInstalledAppVersionByGitHash(gitHash string) (*InstalledAppVersions, error) {
360-
model := &InstalledAppVersions{}
361-
err := impl.dbConnection.Model(model).
362-
Column("installed_app_versions.*", "InstalledApp").
363-
Column("AppStoreApplicationVersion.AppStore.ChartRepo").
364-
Where("installed_app_versions.git_hash = ?", gitHash).
365-
Where("installed_app_versions.active = true").Order("installed_app_versions.id desc").Limit(1).Select()
366-
return model, err
367-
}
368-
369361
func (impl *InstalledAppRepositoryImpl) GetInstalledAppVersion(id int) (*InstalledAppVersions, error) {
370362
model := &InstalledAppVersions{}
371363
err := impl.dbConnection.Model(model).
@@ -392,8 +384,8 @@ func (impl *InstalledAppRepositoryImpl) GetInstalledAppVersion(id int) (*Install
392384
return model, err
393385
}
394386

395-
// GetInstalledAppVersionAny - returns enable and disabled both version
396-
func (impl *InstalledAppRepositoryImpl) GetInstalledAppVersionAny(id int) (*InstalledAppVersions, error) {
387+
// GetInstalledAppVersionIncludingDeleted - returns enable and disabled both versions
388+
func (impl *InstalledAppRepositoryImpl) GetInstalledAppVersionIncludingDeleted(id int) (*InstalledAppVersions, error) {
397389
model := &InstalledAppVersions{}
398390
err := impl.dbConnection.Model(model).
399391
Column("installed_app_versions.*", "InstalledApp", "InstalledApp.App", "AppStoreApplicationVersion").

pkg/appStore/installedApp/service/EAMode/InstalledAppDBService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func (impl *InstalledAppDBServiceImpl) GetInstalledAppVersion(id int, userId int
362362
return installAppVersion, err
363363
}
364364
func (impl *InstalledAppDBServiceImpl) GetInstalledAppVersionByIdIncludeDeleted(id int, userId int32) (*appStoreBean.InstallAppVersionDTO, error) {
365-
model, err := impl.InstalledAppRepository.GetInstalledAppVersionAny(id)
365+
model, err := impl.InstalledAppRepository.GetInstalledAppVersionIncludingDeleted(id)
366366
if err != nil {
367367
if util.IsErrNoRows(err) {
368368
return nil, &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "values are outdated. please fetch the latest version and try again", InternalMessage: err.Error()}

pkg/appStore/values/service/AppStoreValuesService.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package service
1818

1919
import (
2020
"fmt"
21+
installedAppReader "github.com/devtron-labs/devtron/pkg/appStore/installedApp/read"
2122
util2 "github.com/devtron-labs/devtron/pkg/appStore/util"
2223
"time"
2324

@@ -45,17 +46,22 @@ type AppStoreValuesServiceImpl struct {
4546
logger *zap.SugaredLogger
4647
appStoreApplicationRepository appStoreDiscoverRepository.AppStoreApplicationVersionRepository
4748
installedAppRepository repository.InstalledAppRepository
49+
installedAppReadService installedAppReader.InstalledAppReadServiceEA
4850
appStoreVersionValuesRepository appStoreValuesRepository.AppStoreVersionValuesRepository
4951
userService user.UserService
5052
}
5153

5254
func NewAppStoreValuesServiceImpl(logger *zap.SugaredLogger,
53-
appStoreApplicationRepository appStoreDiscoverRepository.AppStoreApplicationVersionRepository, installedAppRepository repository.InstalledAppRepository,
54-
appStoreVersionValuesRepository appStoreValuesRepository.AppStoreVersionValuesRepository, userService user.UserService) *AppStoreValuesServiceImpl {
55+
appStoreApplicationRepository appStoreDiscoverRepository.AppStoreApplicationVersionRepository,
56+
installedAppRepository repository.InstalledAppRepository,
57+
installedAppReadServiceEA installedAppReader.InstalledAppReadServiceEA,
58+
appStoreVersionValuesRepository appStoreValuesRepository.AppStoreVersionValuesRepository,
59+
userService user.UserService) *AppStoreValuesServiceImpl {
5560
return &AppStoreValuesServiceImpl{
5661
logger: logger,
5762
appStoreApplicationRepository: appStoreApplicationRepository,
5863
installedAppRepository: installedAppRepository,
64+
installedAppReadService: installedAppReadServiceEA,
5965
appStoreVersionValuesRepository: appStoreVersionValuesRepository,
6066
userService: userService,
6167
}
@@ -151,15 +157,15 @@ func (impl AppStoreValuesServiceImpl) FindValuesByIdAndKind(referenceId int, kin
151157
}
152158
return valDto, err
153159
} else if kind == appStoreBean.REFERENCE_TYPE_EXISTING {
154-
installedAppVersion, err := impl.installedAppRepository.GetInstalledAppVersionAny(referenceId)
160+
installedAppVersion, err := impl.installedAppReadService.GetInstalledAppVersionIncludingDeleted(referenceId)
155161
if err != nil {
156162
impl.logger.Errorw("error in fetching installed App", "id", referenceId, "err", err)
157163
}
158164
valDto := &appStoreBean.AppStoreVersionValuesDTO{
159165
Name: appStoreBean.REFERENCE_TYPE_EXISTING,
160166
Id: installedAppVersion.Id,
161167
Values: installedAppVersion.ValuesYaml,
162-
ChartVersion: installedAppVersion.AppStoreApplicationVersion.Version,
168+
ChartVersion: installedAppVersion.AppStoreVersion,
163169
AppStoreVersionId: installedAppVersion.AppStoreApplicationVersionId,
164170
}
165171
return valDto, err

pkg/cluster/environment/repository/EnvironmentRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Environment struct {
4949
sql.AuditLog
5050
}
5151

52-
func (environment *Environment) IsZero() bool {
52+
func (environment *Environment) IsEmpty() bool {
5353
if environment == nil {
5454
return true
5555
}

0 commit comments

Comments
 (0)