summaryrefslogtreecommitdiffstats
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.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/dcm/api/logicalCloudHandler.go b/src/dcm/api/logicalCloudHandler.go
index d9a3e5f5..fb0f0c63 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"
+ pkgerrors "github.com/pkg/errors"
)
// logicalCloudHandler is used to store backend implementations objects
@@ -91,6 +92,10 @@ func (h logicalCloudHandler) getHandler(w http.ResponseWriter, r *http.Request)
} 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)
return
}
@@ -129,6 +134,10 @@ func (h logicalCloudHandler) updateHandler(w http.ResponseWriter, r *http.Reques
ret, err := h.client.Update(project, name, v)
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
@@ -150,6 +159,10 @@ func (h logicalCloudHandler) deleteHandler(w http.ResponseWriter, r *http.Reques
err := h.client.Delete(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
}
@@ -165,14 +178,29 @@ func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request
// Get logical cloud
lc, 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
}
+ _, 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)
if err != nil {
+ if err.Error() == "No Cluster References associated" {
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -192,3 +220,50 @@ func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request
return
}
+
+func (h logicalCloudHandler) terminateHandler(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 {
+ if err.Error() == "Logical Cloud does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ _, ctxVal, err := h.client.GetLogicalCloudContext(name)
+ if ctxVal == "" {
+ err = pkgerrors.New("Logical Cloud hasn't been applied yet")
+ http.Error(w, err.Error(), http.StatusConflict)
+ 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.DestroyEtcdContext(lc, clusters, quotas)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ return
+}