aboutsummaryrefslogtreecommitdiffstats
path: root/src/dcm/api/logicalCloudHandler.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/dcm/api/logicalCloudHandler.go')
-rw-r--r--src/dcm/api/logicalCloudHandler.go293
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
}