diff options
author | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2022-02-07 19:34:25 +0100 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2022-02-25 14:52:25 +0100 |
commit | a73b42b9c3877f1a34939d85941482f7f5c44db9 (patch) | |
tree | 289bf84f27eb23a888caaa5152043df2c55a4f08 /src/k8splugin/api/instancehandler.go | |
parent | 88ecb1f9dfeded36e7fd74c776daefcaf67f8ae2 (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/instancehandler.go')
-rw-r--r-- | src/k8splugin/api/instancehandler.go | 56 |
1 files changed, 55 insertions, 1 deletions
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) |