diff options
author | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-07-28 03:05:05 +0000 |
---|---|---|
committer | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-07-28 03:10:15 +0000 |
commit | d641c3864d4ba71e127d332c4ac2082f98bba1e5 (patch) | |
tree | 5127f2c8f6a377d0e36457530255612bf9bfba38 /src/dcm/api/logicalCloudHandler.go | |
parent | 39b7d2f8a79f23141301e7b9abf7bf3a0f2e8f21 (diff) |
DCM - fix code formatting via vscode
Visual Studio Code automatic code formatting was
performed on the 4 modified DCM files.
Issue-ID: MULTICLOUD-1143
Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Change-Id: I24d2b44181b5c0737df7cb4541f9eede0950211a
Diffstat (limited to 'src/dcm/api/logicalCloudHandler.go')
-rw-r--r-- | src/dcm/api/logicalCloudHandler.go | 293 |
1 files changed, 146 insertions, 147 deletions
diff --git a/src/dcm/api/logicalCloudHandler.go b/src/dcm/api/logicalCloudHandler.go index d8fcf268..d9a3e5f5 100644 --- a/src/dcm/api/logicalCloudHandler.go +++ b/src/dcm/api/logicalCloudHandler.go @@ -14,182 +14,181 @@ * See the License for the specific language governing permissions * and * limitations under the License. -*/ + */ package api import ( - "encoding/json" - "net/http" - "io" - "github.com/onap/multicloud-k8s/src/dcm/pkg/module" - "github.com/gorilla/mux" -) + "encoding/json" + "io" + "net/http" + "github.com/gorilla/mux" + "github.com/onap/multicloud-k8s/src/dcm/pkg/module" +) // logicalCloudHandler is used to store backend implementations objects type logicalCloudHandler struct { - client module.LogicalCloudManager - clusterClient module.ClusterManager - quotaClient module.QuotaManager + client module.LogicalCloudManager + clusterClient module.ClusterManager + quotaClient module.QuotaManager } // CreateHandler handles creation of the logical cloud entry in the database func (h logicalCloudHandler) createHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - project := vars["project-name"] - var v module.LogicalCloud - - err := json.NewDecoder(r.Body).Decode(&v) - switch { - case err == io.EOF: - http.Error(w, "Empty body", http.StatusBadRequest) - return - case err != nil: - http.Error(w, err.Error(), http.StatusUnprocessableEntity) - return - } - - // Logical Cloud Name is required. - if v.MetaData.LogicalCloudName == "" { - http.Error(w, "Missing name in POST request", http.StatusBadRequest) - return - } - - ret, err := h.client.Create(project, v) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - err = json.NewEncoder(w).Encode(ret) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + vars := mux.Vars(r) + project := vars["project-name"] + var v module.LogicalCloud + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // Logical Cloud Name is required. + if v.MetaData.LogicalCloudName == "" { + http.Error(w, "Missing name in POST request", http.StatusBadRequest) + return + } + + ret, err := h.client.Create(project, v) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } // getHandler handle GET operations on a particular name // Returns a Logical Cloud func (h logicalCloudHandler) getHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - project := vars["project-name"] - name := vars["logical-cloud-name"] - var ret interface{} - var err error - - if len(name) == 0 { - ret, err = h.client.GetAll(project) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } else { - ret, err = h.client.Get(project, name) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - err = json.NewEncoder(w).Encode(ret) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] + var ret interface{} + var err error + + if len(name) == 0 { + ret, err = h.client.GetAll(project) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } else { + ret, err = h.client.Get(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } // UpdateHandler handles Update operations on a particular logical cloud func (h logicalCloudHandler) updateHandler(w http.ResponseWriter, r *http.Request) { - var v module.LogicalCloud - vars := mux.Vars(r) - project := vars["project-name"] - name := vars["logical-cloud-name"] - - err := json.NewDecoder(r.Body).Decode(&v) - switch { - case err == io.EOF: - http.Error(w, "Empty body", http.StatusBadRequest) - return - case err != nil: - http.Error(w, err.Error(), http.StatusUnprocessableEntity) - return - } - - if v.MetaData.LogicalCloudName == "" { - http.Error(w, "Missing name in PUT request", http.StatusBadRequest) - return - } - - ret, err := h.client.Update(project, name, v) - if err != nil { - http.Error(w, err.Error(), - http.StatusInternalServerError) - return - } - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - err = json.NewEncoder(w).Encode(ret) - if err != nil { - http.Error(w, err.Error(), - http.StatusInternalServerError) - return - } + var v module.LogicalCloud + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + if v.MetaData.LogicalCloudName == "" { + http.Error(w, "Missing name in PUT request", http.StatusBadRequest) + return + } + + ret, err := h.client.Update(project, name, v) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } } func (h logicalCloudHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - project := vars["project-name"] - name := vars["logical-cloud-name"] + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] - err := h.client.Delete(project, name) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + err := h.client.Delete(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } - w.WriteHeader(http.StatusNoContent) + w.WriteHeader(http.StatusNoContent) } func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - project := vars["project-name"] - name := vars["logical-cloud-name"] - - // Get logical cloud - lc, err := h.client.Get(project, name) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // Get Clusters - clusters, err := h.clusterClient.GetAllClusters(project, name) - - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - - //Get Quotas - quotas, err := h.quotaClient.GetAllQuotas(project, name) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - err = module.CreateEtcdContext(lc, clusters, quotas) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - return + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] + + // Get logical cloud + lc, err := h.client.Get(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // Get Clusters + clusters, err := h.clusterClient.GetAllClusters(project, name) + + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + //Get Quotas + quotas, err := h.quotaClient.GetAllQuotas(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = module.CreateEtcdContext(lc, clusters, quotas) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + return } |