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.go90
1 files changed, 60 insertions, 30 deletions
diff --git a/src/dcm/api/logicalCloudHandler.go b/src/dcm/api/logicalCloudHandler.go
index fb0f0c63..b305b202 100644
--- a/src/dcm/api/logicalCloudHandler.go
+++ b/src/dcm/api/logicalCloudHandler.go
@@ -25,6 +25,7 @@ import (
"github.com/gorilla/mux"
"github.com/onap/multicloud-k8s/src/dcm/pkg/module"
+ orch "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
pkgerrors "github.com/pkg/errors"
)
@@ -35,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)
@@ -59,6 +59,15 @@ func (h logicalCloudHandler) createHandler(w http.ResponseWriter, r *http.Reques
return
}
+ // Validate that the specified Project exists
+ // before associating a Logical Cloud with it
+ p := orch.NewProjectClient()
+ _, err = p.GetProject(project)
+ if err != nil {
+ http.Error(w, "The specified project does not exist.", http.StatusNotFound)
+ return
+ }
+
ret, err := h.client.Create(project, v)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -74,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)
@@ -83,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")
@@ -110,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)
@@ -152,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"]
@@ -163,6 +188,10 @@ func (h logicalCloudHandler) deleteHandler(w http.ResponseWriter, r *http.Reques
http.Error(w, err.Error(), http.StatusNotFound)
return
}
+ if err.Error() == "The Logical Cloud can't be deleted yet, it is being terminated." {
+ http.Error(w, err.Error(), http.StatusConflict)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -170,6 +199,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"]
@@ -186,13 +216,6 @@ func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request
return
}
- _, ctxVal, err := h.client.GetLogicalCloudContext(name)
- if ctxVal != "" {
- err = pkgerrors.New("Logical Cloud already applied")
- http.Error(w, err.Error(), http.StatusConflict)
- return
- }
-
// Get Clusters
clusters, err := h.clusterClient.GetAllClusters(project, name)
@@ -205,15 +228,20 @@ 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(lc, clusters, quotas)
+ // Apply the Logical Cloud
+ err = module.Apply(project, lc, clusters, quotas)
if err != nil {
+ if err.Error() == "The Logical Cloud can't be re-applied yet, it is being terminated." {
+ http.Error(w, err.Error(), http.StatusConflict)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -221,6 +249,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"]
@@ -237,7 +266,7 @@ func (h logicalCloudHandler) terminateHandler(w http.ResponseWriter, r *http.Req
return
}
- _, ctxVal, err := h.client.GetLogicalCloudContext(name)
+ _, ctxVal, err := h.client.GetLogicalCloudContext(project, name)
if ctxVal == "" {
err = pkgerrors.New("Logical Cloud hasn't been applied yet")
http.Error(w, err.Error(), http.StatusConflict)
@@ -252,14 +281,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(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