diff options
author | Ritu Sood <ritu.sood@intel.com> | 2021-04-02 13:14:11 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-04-02 13:14:11 +0000 |
commit | e9a12efd25a570e64b728d8fc482939a727e9214 (patch) | |
tree | a0806977f1f153380a9dad9bd84679d9a9eb0ff1 /src/k8splugin/api | |
parent | 705fad712373e73463fff22a3136e6e92b372048 (diff) | |
parent | 120019529489b5cbcf82d77eec228283fb12d43a (diff) |
Merge "Fix Healthcheck API"
Diffstat (limited to 'src/k8splugin/api')
-rw-r--r-- | src/k8splugin/api/instancehchandler.go | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/src/k8splugin/api/instancehchandler.go b/src/k8splugin/api/instancehchandler.go index fc1c3be4..90715178 100644 --- a/src/k8splugin/api/instancehchandler.go +++ b/src/k8splugin/api/instancehchandler.go @@ -46,7 +46,7 @@ func (ih instanceHCHandler) createHandler(w http.ResponseWriter, r *http.Request } w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) + w.WriteHeader(http.StatusCreated) err = json.NewEncoder(w).Encode(resp) if err != nil { log.Error("Error Marshaling Reponse", log.Fields{ @@ -59,10 +59,75 @@ func (ih instanceHCHandler) createHandler(w http.ResponseWriter, r *http.Request } func (ih instanceHCHandler) getHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + instanceId := vars["instID"] + healthcheckId := vars["hcID"] + + resp, err := ih.client.Get(instanceId, healthcheckId) + if err != nil { + log.Error("Error getting Instance's healthcheck", log.Fields{ + "error": err, + "instanceID": instanceId, + "healthcheckID": healthcheckId, + }) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + 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 + } } func (ih instanceHCHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + instanceId := vars["instID"] + healthcheckId := vars["hcID"] + + err := ih.client.Delete(instanceId, healthcheckId) + if err != nil { + log.Error("Error deleting Instance's healthcheck", log.Fields{ + "error": err, + "instanceID": instanceId, + "healthcheckID": healthcheckId, + }) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusAccepted) } func (ih instanceHCHandler) listHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + id := vars["instID"] + + resp, err := ih.client.List(id) + if err != nil { + log.Error("Error getting instance healthcheck overview", log.Fields{ + "error": err, + "instance-id": id, + }) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + 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 + } } |