-
Notifications
You must be signed in to change notification settings - Fork 474
/
apps.go
89 lines (73 loc) · 2.39 KB
/
apps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package handlers
import (
"net/http"
"github.com/gorilla/mux"
"github.com/kiali/kiali/business"
)
// appParams holds the path and query parameters for appList and appDetails
//
// swagger:parameters appList AppDetails
type appParams struct {
baseHealthParams
// The target workload
//
// in: path
Namespace string `json:"namespace"`
AppName string `json:"app"`
// Optional
IncludeHealth bool `json:"health"`
}
func (p *appParams) extract(r *http.Request) {
vars := mux.Vars(r)
query := r.URL.Query()
p.baseExtract(r, vars)
p.Namespace = vars["namespace"]
p.AppName = vars["app"]
p.IncludeHealth = query.Get("health") != ""
}
// AppList is the API handler to fetch all the apps to be displayed, related to a single namespace
func AppList(w http.ResponseWriter, r *http.Request) {
p := appParams{}
p.extract(r)
criteria := business.AppCriteria{Namespace: p.Namespace, IncludeIstioResources: true, IncludeHealth: p.IncludeHealth, RateInterval: p.RateInterval, QueryTime: p.QueryTime}
// Get business layer
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Apps initialization error: "+err.Error())
return
}
if criteria.IncludeHealth {
rateInterval, err := adjustRateInterval(r.Context(), business, p.Namespace, p.RateInterval, p.QueryTime)
if err != nil {
handleErrorResponse(w, err, "Adjust rate interval error: "+err.Error())
return
}
criteria.RateInterval = rateInterval
}
// Fetch and build apps
appList, err := business.App.GetAppList(r.Context(), criteria)
if err != nil {
handleErrorResponse(w, err)
return
}
RespondWithJSON(w, http.StatusOK, appList)
}
// AppDetails is the API handler to fetch all details to be displayed, related to a single app
func AppDetails(w http.ResponseWriter, r *http.Request) {
p := appParams{}
p.extract(r)
criteria := business.AppCriteria{Namespace: p.Namespace, AppName: p.AppName, IncludeIstioResources: true, IncludeHealth: p.IncludeHealth, RateInterval: p.RateInterval, QueryTime: p.QueryTime}
// Get business layer
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Services initialization error: "+err.Error())
return
}
// Fetch and build app
appDetails, err := business.App.GetAppDetails(r.Context(), criteria)
if err != nil {
handleErrorResponse(w, err)
return
}
RespondWithJSON(w, http.StatusOK, appDetails)
}