-
Notifications
You must be signed in to change notification settings - Fork 474
/
iter8.go
124 lines (114 loc) · 3.32 KB
/
iter8.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package handlers
import (
"io/ioutil"
"net/http"
"strings"
"github.com/gorilla/mux"
)
func Iter8Status(w http.ResponseWriter, r *http.Request) {
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Services initialization error: "+err.Error())
return
}
iter8Info := business.Iter8.GetIter8Info()
RespondWithJSON(w, http.StatusOK, iter8Info)
}
func Iter8Experiments(w http.ResponseWriter, r *http.Request) {
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Services initialization error: "+err.Error())
return
}
params := r.URL.Query()
namespaces := params.Get("namespaces") // csl of namespaces
ns := strings.Split(namespaces, ",")
experiments, err := business.Iter8.GetIter8Experiments(ns)
if err != nil {
handleErrorResponse(w, err)
return
}
RespondWithJSON(w, http.StatusOK, experiments)
}
func Iter8ExperimentGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
business, err := getBusiness(r)
namespace := params["namespace"]
name := params["name"]
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Services initialization error: "+err.Error())
return
}
experiment, err := business.Iter8.GetIter8Experiment(namespace, name)
if err != nil {
handleErrorResponse(w, err)
return
}
RespondWithJSON(w, http.StatusOK, experiment)
}
func Iter8ExperimentCreate(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Services initialization error: "+err.Error())
return
}
namespace := params["namespace"]
body, err := ioutil.ReadAll(r.Body)
if err != nil {
RespondWithError(w, http.StatusBadRequest, err.Error())
return
}
experiment, err := business.Iter8.CreateIter8Experiment(namespace, body)
if err != nil {
handleErrorResponse(w, err)
return
}
RespondWithJSON(w, http.StatusOK, experiment)
}
func Iter8ExperimentUpdate(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
business, err := getBusiness(r)
namespace := params["namespace"]
name := params["name"]
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Services initialization error: "+err.Error())
return
}
// TODO This is not yet implemented
experiment, err := business.Iter8.GetIter8Experiment(namespace, name)
if err != nil {
handleErrorResponse(w, err)
return
}
RespondWithJSON(w, http.StatusOK, experiment)
}
func Iter8ExperimentDelete(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
business, err := getBusiness(r)
namespace := params["namespace"]
name := params["name"]
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Services initialization error: "+err.Error())
return
}
err = business.Iter8.DeleteIter8Experiment(namespace, name)
if err != nil {
handleErrorResponse(w, err)
return
}
RespondWithCode(w, http.StatusOK)
}
func Iter8Metrics(w http.ResponseWriter, r *http.Request) {
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Services initialization error: "+err.Error())
return
}
metricNames, err := business.Iter8.GetIter8Metrics()
if err != nil {
handleErrorResponse(w, err)
return
}
RespondWithJSON(w, http.StatusOK, metricNames)
}