summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/instancehandler.go
diff options
context:
space:
mode:
authorsanjaymekhale <sm00557598@techmahindra.com>2019-10-25 06:45:06 +0000
committersanjaymekhale <sm00557598@techmahindra.com>2019-10-25 06:45:06 +0000
commitacddbe2e281ebf80d31e7a03646ccfa0a9d6b25b (patch)
treeee28b01ae0e854f9c753e9b1633e1893edc0f903 /src/k8splugin/api/instancehandler.go
parentb0f94ada2751713ea8d62c235d0bc1cc2877034a (diff)
Implementing suggested changes
Renamed package from logs to logutils Issue-ID: MULTICLOUD-577 Change-Id: I05e2acbfbb5dd79bd26df73e0ad64c2068b9f6e5 Signed-off-by: sanjaymekhale <sm00557598@techmahindra.com>
Diffstat (limited to 'src/k8splugin/api/instancehandler.go')
-rw-r--r--src/k8splugin/api/instancehandler.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/k8splugin/api/instancehandler.go b/src/k8splugin/api/instancehandler.go
index ab98e4be..1dcbcda9 100644
--- a/src/k8splugin/api/instancehandler.go
+++ b/src/k8splugin/api/instancehandler.go
@@ -23,6 +23,7 @@ import (
"github.com/gorilla/mux"
pkgerrors "github.com/pkg/errors"
+ log "github.com/onap/multicloud-k8s/src/k8splugin/internal/logutils"
)
// Used to store the backend implementation objects
@@ -36,14 +37,18 @@ func (i instanceHandler) validateBody(body interface{}) error {
switch b := body.(type) {
case app.InstanceRequest:
if b.CloudRegion == "" {
+ log.WithFields("CreateVnfRequest bad request", "CloudRegion", "Invalid/Missing CloudRegion in POST request")
werr := pkgerrors.Wrap(errors.New("Invalid/Missing CloudRegion in POST request"), "CreateVnfRequest bad request")
return werr
}
if b.RBName == "" || b.RBVersion == "" {
+ log.WithFields("CreateVnfRequest bad request", "RBName", "Invalid/Missing resource bundle parameters in POST request")
+ log.WithFields("CreateVnfRequest bad request", "RBVersion", "Invalid/Missing resource bundle parameters in POST request")
werr := pkgerrors.Wrap(errors.New("Invalid/Missing resource bundle parameters in POST request"), "CreateVnfRequest bad request")
return werr
}
if b.ProfileName == "" {
+ log.WithFields("CreateVnfRequest bad request", "ProfileName", "Invalid/Missing profile name in POST request")
werr := pkgerrors.Wrap(errors.New("Invalid/Missing profile name in POST request"), "CreateVnfRequest bad request")
return werr
}
@@ -57,9 +62,11 @@ func (i instanceHandler) createHandler(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&resource)
switch {
case err == io.EOF:
+ log.WithFields("http.StatusBadRequest", "Error", "Body empty")
http.Error(w, "Body empty", http.StatusBadRequest)
return
case err != nil:
+ log.WithFields("http.StatusUnprocessableEntity", "Error", "http.StatusUnprocessableEntity")
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
return
}
@@ -67,12 +74,14 @@ func (i instanceHandler) createHandler(w http.ResponseWriter, r *http.Request) {
// Check body for expected parameters
err = i.validateBody(resource)
if err != nil {
+ log.WithFields("StatusUnprocessableEntity", "Error", "http.StatusUnprocessableEntity")
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
return
}
resp, err := i.client.Create(resource)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -81,6 +90,7 @@ func (i instanceHandler) createHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
err = json.NewEncoder(w).Encode(resp)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -93,6 +103,7 @@ func (i instanceHandler) getHandler(w http.ResponseWriter, r *http.Request) {
resp, err := i.client.Get(id)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -101,6 +112,7 @@ func (i instanceHandler) getHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(resp)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -113,6 +125,7 @@ func (i instanceHandler) statusHandler(w http.ResponseWriter, r *http.Request) {
resp, err := i.client.Status(id)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -121,6 +134,7 @@ func (i instanceHandler) statusHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(resp)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -137,6 +151,7 @@ func (i instanceHandler) listHandler(w http.ResponseWriter, r *http.Request) {
resp, err := i.client.List(rbName, rbVersion, ProfileName)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -145,6 +160,7 @@ func (i instanceHandler) listHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(resp)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -157,6 +173,7 @@ func (i instanceHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
err := i.client.Delete(id)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -164,3 +181,4 @@ func (i instanceHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
}
+