diff options
Diffstat (limited to 'src/k8splugin/api/instancehchandler.go')
-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 + } } |