Skip to content

Commit 862386c

Browse files
FEATURE: Deployed charts listing search filter (#565)
* deployed chart listing added filters * deployed chart listing filter change for deprecated filter * api spec added deployed chart listing
1 parent 9796834 commit 862386c

File tree

5 files changed

+257
-15
lines changed

5 files changed

+257
-15
lines changed

api/restHandler/AppStoreDeploymentRestHandler.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/json"
2323
"errors"
2424
"fmt"
25+
appstore2 "github.com/devtron-labs/devtron/internal/sql/repository/appstore"
2526
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
2627
"github.com/devtron-labs/devtron/internal/util"
2728
"github.com/devtron-labs/devtron/pkg/appstore"
@@ -233,9 +234,10 @@ func (handler InstalledAppRestHandlerImpl) GetAllInstalledApp(w http.ResponseWri
233234
writeJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
234235
return
235236
}
237+
v := r.URL.Query()
236238
token := r.Header.Get("token")
237239
var envs []int
238-
envsQueryParam := r.URL.Query().Get("envs")
240+
envsQueryParam := v.Get("envs")
239241
if envsQueryParam != "" {
240242
envsStr := strings.Split(envsQueryParam, ",")
241243
for _, t := range envsStr {
@@ -248,8 +250,45 @@ func (handler InstalledAppRestHandlerImpl) GetAllInstalledApp(w http.ResponseWri
248250
envs = append(envs, env)
249251
}
250252
}
253+
onlyDeprecated := false
254+
deprecatedStr := v.Get("onlyDeprecated")
255+
if len(deprecatedStr) > 0 {
256+
onlyDeprecated, err = strconv.ParseBool(deprecatedStr)
257+
if err != nil {
258+
onlyDeprecated = false
259+
}
260+
}
261+
262+
var chartRepoIds []int
263+
chartRepoIdsStr := v.Get("chartRepoId")
264+
if len(chartRepoIdsStr) > 0 {
265+
chartRepoIdStrArr := strings.Split(chartRepoIdsStr, ",")
266+
for _, chartRepoIdStr := range chartRepoIdStrArr {
267+
chartRepoId, err := strconv.Atoi(chartRepoIdStr)
268+
if err == nil {
269+
chartRepoIds = append(chartRepoIds, chartRepoId)
270+
}
271+
}
272+
}
273+
appStoreName := v.Get("appStoreName")
274+
appName := v.Get("appName")
275+
offset := 0
276+
offsetStr := v.Get("offset")
277+
if len(offsetStr) > 0 {
278+
offset, _ = strconv.Atoi(offsetStr)
279+
}
280+
size := 0
281+
sizeStr := v.Get("size")
282+
if len(sizeStr) > 0 {
283+
size, _ = strconv.Atoi(sizeStr)
284+
}
285+
filter := &appstore2.AppStoreFilter{OnlyDeprecated: onlyDeprecated, ChartRepoId: chartRepoIds, AppStoreName: appStoreName, EnvIds: envs, AppName: appName}
286+
if size > 0 {
287+
filter.Size = size
288+
filter.Offset = offset
289+
}
251290
handler.Logger.Infow("request payload, GetAllInstalledApp", "envsQueryParam", envsQueryParam)
252-
res, err := handler.installedAppService.GetAll(envs)
291+
res, err := handler.installedAppService.GetAll(filter)
253292
if err != nil {
254293
handler.Logger.Errorw("service err, GetAllInstalledApp", "err", err, "envsQueryParam", envsQueryParam)
255294
writeJsonResp(w, err, nil, http.StatusInternalServerError)

internal/sql/repository/appstore/AppStoreApplicationVersionRepository.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ type AppStoreWithVersion struct {
8787
type AppStoreFilter struct {
8888
ChartRepoId []int `json:"chartRepoId"`
8989
AppStoreName string `json:"appStoreName"`
90+
AppName string `json:"appName"`
9091
IncludeDeprecated bool `json:"includeDeprecated"`
9192
Offset int `json:"offset"`
9293
Size int `json:"size"`
94+
EnvIds []int `json:"envIds"`
95+
OnlyDeprecated bool `json:"onlyDeprecated"`
9396
}
9497

9598
type ChartRepoSearch struct {

internal/sql/repository/appstore/AppStoreDeploymentRepository.go

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type InstalledAppRepository interface {
3535
GetInstalledApp(id int) (*InstalledApps, error)
3636
GetInstalledAppVersion(id int) (*InstalledAppVersions, error)
3737
GetInstalledAppVersionAny(id int) (*InstalledAppVersions, error)
38-
GetAllInstalledApps(envIds []int) ([]InstalledAppsWithChartDetails, error)
38+
GetAllInstalledApps(filter *AppStoreFilter) ([]InstalledAppsWithChartDetails, error)
3939
GetAllIntalledAppsByAppStoreId(appStoreId int) ([]InstalledAppAndEnvDetails, error)
4040
GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId int, envId int) (*InstalledAppVersions, error)
4141
GetInstalledAppVersionByAppStoreId(appStoreId int) ([]*InstalledAppVersions, error)
@@ -217,17 +217,42 @@ func (impl InstalledAppRepositoryImpl) GetInstalledAppVersionAny(id int) (*Insta
217217
return model, err
218218
}
219219

220-
func (impl InstalledAppRepositoryImpl) GetAllInstalledApps(envIds []int) ([]InstalledAppsWithChartDetails, error) {
220+
func (impl InstalledAppRepositoryImpl) GetAllInstalledApps(filter *AppStoreFilter) ([]InstalledAppsWithChartDetails, error) {
221221
var installedAppsWithChartDetails []InstalledAppsWithChartDetails
222-
var queryTemp string
223-
if len(envIds) > 0 {
224-
queryTemp = "select iav.updated_on, iav.id as installed_app_version_id, ch.name as chart_repo_name, env.environment_name, env.id as environment_id, a.app_name, asav.icon, asav.name as app_store_application_name, asav.id as app_store_application_version_id, ia.id " +
225-
", asav.deprecated from installed_app_versions iav inner join installed_apps ia on iav.installed_app_id = ia.id inner join app a on a.id = ia.app_id inner join environment env on ia.environment_id = env.id inner join app_store_application_version asav on iav.app_store_application_version_id = asav.id inner join app_store aps on aps.id = asav.app_store_id inner join chart_repo ch on ch.id = aps.chart_repo_id where ia.active=true and env.id in (" + sqlIntSeq(envIds) + ") and iav.active=true"
226-
} else {
227-
queryTemp = "select iav.updated_on, iav.id as installed_app_version_id, ch.name as chart_repo_name, env.environment_name, env.id as environment_id, a.app_name, asav.icon, asav.name as app_store_application_name, asav.id as app_store_application_version_id, ia.id " +
228-
", asav.deprecated from installed_app_versions iav inner join installed_apps ia on iav.installed_app_id = ia.id inner join app a on a.id = ia.app_id inner join environment env on ia.environment_id = env.id inner join app_store_application_version asav on iav.app_store_application_version_id = asav.id inner join app_store aps on aps.id = asav.app_store_id inner join chart_repo ch on ch.id = aps.chart_repo_id where ia.active=true and iav.active=true"
222+
var query string
223+
query = "select iav.updated_on, iav.id as installed_app_version_id, ch.name as chart_repo_name,"
224+
query = query + " env.environment_name, env.id as environment_id, a.app_name, asav.icon, asav.name as app_store_application_name,"
225+
query = query + " asav.id as app_store_application_version_id, ia.id , asav.deprecated"
226+
query = query + " from installed_app_versions iav"
227+
query = query + " inner join installed_apps ia on iav.installed_app_id = ia.id"
228+
query = query + " inner join app a on a.id = ia.app_id"
229+
query = query + " inner join environment env on ia.environment_id = env.id"
230+
query = query + " inner join app_store_application_version asav on iav.app_store_application_version_id = asav.id"
231+
query = query + " inner join app_store aps on aps.id = asav.app_store_id"
232+
query = query + " inner join chart_repo ch on ch.id = aps.chart_repo_id"
233+
query = query + " where ia.active = true and iav.active = true"
234+
if filter.OnlyDeprecated {
235+
query = query + " AND asav.deprecated = TRUE"
236+
}
237+
if len(filter.AppStoreName) > 0 {
238+
query = query + " AND aps.name LIKE '%" + filter.AppStoreName + "%'"
239+
}
240+
if len(filter.AppName) > 0 {
241+
query = query + " AND a.app_name LIKE '%" + filter.AppName + "%'"
242+
}
243+
if len(filter.ChartRepoId) > 0 {
244+
query = query + " AND ch.id IN (" + sqlIntSeq(filter.ChartRepoId) + ")"
245+
}
246+
if len(filter.EnvIds) > 0 {
247+
query = query + " AND env.id IN (" + sqlIntSeq(filter.EnvIds) + ")"
248+
}
249+
query = query + " ORDER BY aps.name ASC"
250+
if filter.Size > 0 {
251+
query = query + " OFFSET " + strconv.Itoa(filter.Offset) + " LIMIT " + strconv.Itoa(filter.Size) + ""
229252
}
230-
_, err := impl.dbConnection.Query(&installedAppsWithChartDetails, queryTemp)
253+
query = query + ";"
254+
var err error
255+
_, err = impl.dbConnection.Query(&installedAppsWithChartDetails, query)
231256
if err != nil {
232257
return nil, err
233258
}

pkg/appstore/AppStoreDeploymentService.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type InstalledAppService interface {
6969
UpdateInstalledApp(ctx context.Context, installAppVersionRequest *InstallAppVersionDTO) (*InstallAppVersionDTO, error)
7070
GetInstalledApp(id int) (*InstallAppVersionDTO, error)
7171
GetInstalledAppVersion(id int) (*InstallAppVersionDTO, error)
72-
GetAll(environments []int) ([]InstalledAppsResponse, error)
72+
GetAll(filter *appstore.AppStoreFilter) ([]InstalledAppsResponse, error)
7373
GetAllInstalledAppsByAppStoreId(w http.ResponseWriter, r *http.Request, token string, appStoreId int) ([]InstalledAppsResponse, error)
7474
DeleteInstalledApp(ctx context.Context, installAppVersionRequest *InstallAppVersionDTO) (*InstallAppVersionDTO, error)
7575

@@ -460,8 +460,8 @@ func (impl InstalledAppServiceImpl) GetInstalledAppVersion(id int) (*InstallAppV
460460
return installAppVersion, err
461461
}
462462

463-
func (impl InstalledAppServiceImpl) GetAll(environments []int) ([]InstalledAppsResponse, error) {
464-
installedApps, err := impl.installedAppRepository.GetAllInstalledApps(environments)
463+
func (impl InstalledAppServiceImpl) GetAll(filter *appstore.AppStoreFilter) ([]InstalledAppsResponse, error) {
464+
installedApps, err := impl.installedAppRepository.GetAllInstalledApps(filter)
465465
if err != nil && !util.IsErrNoRows(err) {
466466
impl.logger.Error(err)
467467
return nil, err

specs/charts.yaml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Devtron Labs
5+
paths:
6+
/orchestrator/app-store/installed-app:
7+
get:
8+
description: deployed chart listing, with search filters
9+
parameters:
10+
- name: envs
11+
in: query
12+
description: environment ids
13+
required: false
14+
schema:
15+
type: array
16+
items:
17+
type: string
18+
- name: chartRepoId
19+
in: query
20+
description: chart repo ids
21+
required: false
22+
schema:
23+
type: array
24+
items:
25+
type: string
26+
- name: appStoreName
27+
in: query
28+
description: chart name
29+
required: false
30+
schema:
31+
type: string
32+
- name: appName
33+
in: query
34+
description: chart name as app name for devtron
35+
required: false
36+
schema:
37+
type: string
38+
- name: onlyDeprecated
39+
in: query
40+
description: show only deprecated or all
41+
required: false
42+
schema:
43+
type: boolean
44+
- name: offset
45+
in: query
46+
description: offset for result set
47+
required: false
48+
schema:
49+
type: integer
50+
- name: size
51+
in: query
52+
description: total request size.
53+
required: false
54+
schema:
55+
type: integer
56+
responses:
57+
'200':
58+
description: deployed chart listing, with search filters
59+
content:
60+
application/json:
61+
schema:
62+
properties:
63+
code:
64+
type: integer
65+
description: status code
66+
status:
67+
type: string
68+
description: status
69+
result:
70+
type: array
71+
description: deployed chart listing, with search filters
72+
items:
73+
$ref: '#/components/schemas/ChartInfo'
74+
default:
75+
description: unexpected error
76+
content:
77+
application/json:
78+
schema:
79+
$ref: '#/components/schemas/ErrorResponse'
80+
81+
# components mentioned below
82+
components:
83+
schemas:
84+
ChartInfo:
85+
type: object
86+
required:
87+
- installedAppId
88+
- environmentId
89+
- installedAppVersionId
90+
- appStoreApplicationVersionId
91+
- appStoreApplicationName
92+
- status
93+
- appName
94+
- environmentName
95+
- deployedAt
96+
- deployedBy
97+
- readme
98+
- deprecated
99+
properties:
100+
installedAppId:
101+
type: integer
102+
description: installed chart id
103+
environmentId:
104+
type: integer
105+
description: environment id
106+
installedAppVersionId:
107+
type: integer
108+
description: installed chart version id
109+
appStoreApplicationVersionId:
110+
type: integer
111+
description: team/project id
112+
appStoreApplicationName:
113+
type: string
114+
description: chart name externally
115+
chartName:
116+
type: string
117+
description: chart repo name
118+
icon:
119+
type: string
120+
description: image
121+
status:
122+
type: string
123+
description: status of deployed chart
124+
appName:
125+
type: string
126+
description: chart name is app name for devtron
127+
environmentName:
128+
type: string
129+
description: env name
130+
deployedAt:
131+
type: string
132+
description: deployement time
133+
deployedBy:
134+
type: string
135+
description: user
136+
readme:
137+
type: string
138+
description: readme
139+
deprecated:
140+
type: boolean
141+
description: is deprecated or not
142+
143+
ErrorResponse:
144+
required:
145+
- code
146+
- status
147+
properties:
148+
code:
149+
type: integer
150+
format: int32
151+
description: Error code
152+
status:
153+
type: string
154+
description: Error message
155+
errors:
156+
type: array
157+
description: errors
158+
items:
159+
$ref: '#/components/schemas/Error'
160+
161+
Error:
162+
required:
163+
- code
164+
- status
165+
properties:
166+
code:
167+
type: integer
168+
format: int32
169+
description: Error internal code
170+
internalMessage:
171+
type: string
172+
description: Error internal message
173+
userMessage:
174+
type: string
175+
description: Error user message

0 commit comments

Comments
 (0)