"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
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
}
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
}
// 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
}
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
}
resp, err := i.client.Get(id)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
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
}
resp, err := i.client.Status(id)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
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
}
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
}
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
}
err := i.client.Delete(id)
if err != nil {
+ log.WithFields("StatusInternalServerError", "Error", "http.StatusInternalServerError")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
}
+