aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2022-02-07 19:34:25 +0100
committerLukasz Rajewski <lukasz.rajewski@orange.com>2022-02-25 14:52:25 +0100
commita73b42b9c3877f1a34939d85941482f7f5c44db9 (patch)
tree289bf84f27eb23a888caaa5152043df2c55a4f08 /src/k8splugin/api
parent88ecb1f9dfeded36e7fd74c776daefcaf67f8ae2 (diff)
Upgrade handler implementation
Implementation of the upgrade handler for the instance. As a result, exsting instance is modified, resources upated and lefovers removed from the cluster. Issue-ID: MULTICLOUD-1444 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> Change-Id: I4122ee12d9332eaeb5ee016446b3da2bbe94bd2d
Diffstat (limited to 'src/k8splugin/api')
-rw-r--r--src/k8splugin/api/api.go1
-rw-r--r--src/k8splugin/api/brokerhandler.go2
-rw-r--r--src/k8splugin/api/instancehandler.go56
-rw-r--r--src/k8splugin/api/instancehandler_test.go2
4 files changed, 58 insertions, 3 deletions
diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go
index 4e84de70..64c83e03 100644
--- a/src/k8splugin/api/api.go
+++ b/src/k8splugin/api/api.go
@@ -53,6 +53,7 @@ func NewRouter(defClient rb.DefinitionManager,
//Want to get full Data -> add query param: /install/{instID}?full=true
instRouter.HandleFunc("/instance/{instID}", instHandler.getHandler).Methods("GET")
instRouter.HandleFunc("/instance/{instID}/status", instHandler.statusHandler).Methods("GET")
+ instRouter.HandleFunc("/instance/{instID}/upgrade", instHandler.upgradeHandler).Methods("POST")
instRouter.HandleFunc("/instance/{instID}/query", instHandler.queryHandler).Methods("GET")
instRouter.HandleFunc("/instance/{instID}/query", instHandler.queryHandler).
Queries("ApiVersion", "{ApiVersion}",
diff --git a/src/k8splugin/api/brokerhandler.go b/src/k8splugin/api/brokerhandler.go
index b4803101..ecfde8c4 100644
--- a/src/k8splugin/api/brokerhandler.go
+++ b/src/k8splugin/api/brokerhandler.go
@@ -175,7 +175,7 @@ func (b brokerInstanceHandler) createHandler(w http.ResponseWriter, r *http.Requ
log.Info("Instance API Payload", log.Fields{
"payload": instReq,
})
- resp, err := b.client.Create(instReq)
+ resp, err := b.client.Create(instReq, "")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
diff --git a/src/k8splugin/api/instancehandler.go b/src/k8splugin/api/instancehandler.go
index e07bfcb0..6d1fd7b3 100644
--- a/src/k8splugin/api/instancehandler.go
+++ b/src/k8splugin/api/instancehandler.go
@@ -95,7 +95,7 @@ func (i instanceHandler) createHandler(w http.ResponseWriter, r *http.Request) {
return
}
- resp, err := i.client.Create(resource)
+ resp, err := i.client.Create(resource, "")
if err != nil {
log.Error("Error Creating Resource", log.Fields{
"error": err,
@@ -118,6 +118,60 @@ func (i instanceHandler) createHandler(w http.ResponseWriter, r *http.Request) {
}
}
+func (i instanceHandler) upgradeHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ id := vars["instID"]
+ var resource app.UpgradeRequest
+
+ err := json.NewDecoder(r.Body).Decode(&resource)
+ switch {
+ case err == io.EOF:
+ log.Error("Body Empty", log.Fields{
+ "error": io.EOF,
+ })
+ http.Error(w, "Body empty", http.StatusBadRequest)
+ return
+ case err != nil:
+ log.Error("Error unmarshaling Body", log.Fields{
+ "error": err,
+ })
+ http.Error(w, err.Error(), http.StatusUnprocessableEntity)
+ return
+ }
+
+ // Check body for expected parameters
+ err = i.validateBody(resource)
+ if err != nil {
+ log.Error("Invalid Parameters in Body", log.Fields{
+ "error": err,
+ })
+ http.Error(w, err.Error(), http.StatusUnprocessableEntity)
+ return
+ }
+
+ resp, err := i.client.Upgrade(id, resource)
+ if err != nil {
+ log.Error("Error Upgrading Resource", log.Fields{
+ "error": err,
+ "resource": resource,
+ })
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusCreated)
+ err = json.NewEncoder(w).Encode(resp)
+ if err != nil {
+ log.Error("Error Marshaling Response", log.Fields{
+ "error": err,
+ "response": resp,
+ })
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}
+
// getHandler retrieves information about an instance via the ID
func (i instanceHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
diff --git a/src/k8splugin/api/instancehandler_test.go b/src/k8splugin/api/instancehandler_test.go
index faec1329..444b6695 100644
--- a/src/k8splugin/api/instancehandler_test.go
+++ b/src/k8splugin/api/instancehandler_test.go
@@ -48,7 +48,7 @@ type mockInstanceClient struct {
err error
}
-func (m *mockInstanceClient) Create(inp app.InstanceRequest) (app.InstanceResponse, error) {
+func (m *mockInstanceClient) Create(inp app.InstanceRequest, newId string) (app.InstanceResponse, error) {
if m.err != nil {
return app.InstanceResponse{}, m.err
}