aboutsummaryrefslogtreecommitdiffstats
path: root/src/dcm/api/logicalCloudHandler.go
diff options
context:
space:
mode:
authorIgor D.C <igor.duarte.cardoso@intel.com>2020-09-30 21:30:06 +0000
committerIgor D.C <igor.duarte.cardoso@intel.com>2020-10-01 17:20:15 +0000
commit80107dc294c86a452c6108ffca6f281b4dbb9192 (patch)
treec246b3a46307dc851a8a2866655609d42e210c23 /src/dcm/api/logicalCloudHandler.go
parent5e114cd8a05986b7762fb9db22a43d61bb9fe00e (diff)
Subtle refactoring in a few functions
In DCM. Essentially refactored two different areas: - rename apply/terminate functions in module to clarify what they do - split gets from getAlls in API code of the 5 DCM resource types And cleaned up here and there. Issue-ID: MULTICLOUD-1143 Change-Id: I9b72c77ba34a1febd5df4a339e87968ddc4a7891 Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Diffstat (limited to 'src/dcm/api/logicalCloudHandler.go')
-rw-r--r--src/dcm/api/logicalCloudHandler.go63
1 files changed, 41 insertions, 22 deletions
diff --git a/src/dcm/api/logicalCloudHandler.go b/src/dcm/api/logicalCloudHandler.go
index b5161efa..5bc2cd27 100644
--- a/src/dcm/api/logicalCloudHandler.go
+++ b/src/dcm/api/logicalCloudHandler.go
@@ -36,8 +36,7 @@ type logicalCloudHandler struct {
quotaClient module.QuotaManager
}
-// CreateHandler handles creation of the logical cloud entry in the database
-
+// CreateHandler handles the creation of a logical cloud
func (h logicalCloudHandler) createHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
@@ -84,7 +83,30 @@ func (h logicalCloudHandler) createHandler(w http.ResponseWriter, r *http.Reques
}
}
-// getHandler handle GET operations on a particular name
+// getAllHandler handles GET operations over logical clouds
+// Returns a list of Logical Clouds
+func (h logicalCloudHandler) getAllHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ project := vars["project-name"]
+ var ret interface{}
+ var err error
+
+ ret, err = h.client.GetAll(project)
+ 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
+ }
+}
+
+// getHandler handles GET operations on a particular name
// Returns a Logical Cloud
func (h logicalCloudHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
@@ -93,22 +115,14 @@ func (h logicalCloudHandler) getHandler(w http.ResponseWriter, r *http.Request)
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 {
- if err.Error() == "Logical Cloud does not exist" {
- http.Error(w, err.Error(), http.StatusNotFound)
- return
- }
- http.Error(w, err.Error(), http.StatusInternalServerError)
+ ret, err = h.client.Get(project, name)
+ if err != nil {
+ if err.Error() == "Logical Cloud does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
return
}
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
}
w.Header().Set("Content-Type", "application/json")
@@ -120,7 +134,7 @@ func (h logicalCloudHandler) getHandler(w http.ResponseWriter, r *http.Request)
}
}
-// UpdateHandler handles Update operations on a particular logical cloud
+// 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)
@@ -162,6 +176,7 @@ func (h logicalCloudHandler) updateHandler(w http.ResponseWriter, r *http.Reques
}
}
+// deleteHandler handles Delete operations on a particular logical cloud
func (h logicalCloudHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
project := vars["project-name"]
@@ -180,6 +195,7 @@ func (h logicalCloudHandler) deleteHandler(w http.ResponseWriter, r *http.Reques
w.WriteHeader(http.StatusNoContent)
}
+// applyHandler handles applying a particular logical cloud
func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
project := vars["project-name"]
@@ -215,14 +231,15 @@ func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request
return
}
- //Get Quotas
+ // Get Quotas
quotas, err := h.quotaClient.GetAllQuotas(project, name)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- err = module.CreateEtcdContext(project, lc, clusters, quotas)
+ // Apply the Logical Cloud
+ err = module.Apply(project, lc, clusters, quotas)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -231,6 +248,7 @@ func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request
return
}
+// applyHandler handles terminating a particular logical cloud
func (h logicalCloudHandler) terminateHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
project := vars["project-name"]
@@ -262,14 +280,15 @@ func (h logicalCloudHandler) terminateHandler(w http.ResponseWriter, r *http.Req
return
}
- //Get Quotas
+ // Get Quotas
quotas, err := h.quotaClient.GetAllQuotas(project, name)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- err = module.DestroyEtcdContext(project, lc, clusters, quotas)
+ // Terminate the Logical Cloud
+ err = module.Terminate(project, lc, clusters, quotas)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return