summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dcm/api/api.go14
-rw-r--r--src/dcm/api/clusterHandler.go52
-rw-r--r--src/dcm/api/keyValueHandler.go45
-rw-r--r--src/dcm/api/logicalCloudHandler.go63
-rw-r--r--src/dcm/api/quotaHandler.go50
-rw-r--r--src/dcm/api/userPermissionsHandler.go47
-rw-r--r--src/dcm/pkg/module/apply.go14
7 files changed, 186 insertions, 99 deletions
diff --git a/src/dcm/api/api.go b/src/dcm/api/api.go
index cd8589dd..10856ba2 100644
--- a/src/dcm/api/api.go
+++ b/src/dcm/api/api.go
@@ -21,7 +21,6 @@ import (
// NewRouter creates a router that registers the various urls that are
// supported
-
func NewRouter(
logicalCloudClient module.LogicalCloudManager,
clusterClient module.ClusterManager,
@@ -55,7 +54,7 @@ func NewRouter(
logicalCloudHandler.createHandler).Methods("POST")
lcRouter.HandleFunc(
"/logical-clouds",
- logicalCloudHandler.getHandler).Methods("GET")
+ logicalCloudHandler.getAllHandler).Methods("GET")
lcRouter.HandleFunc(
"/logical-clouds/{logical-cloud-name}",
logicalCloudHandler.getHandler).Methods("GET")
@@ -80,7 +79,7 @@ func NewRouter(
clusterHandler.createHandler).Methods("POST")
clusterRouter.HandleFunc(
"/logical-clouds/{logical-cloud-name}/cluster-references",
- clusterHandler.getHandler).Methods("GET")
+ clusterHandler.getAllHandler).Methods("GET")
clusterRouter.HandleFunc(
"/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}",
clusterHandler.getHandler).Methods("GET")
@@ -105,6 +104,9 @@ func NewRouter(
"/logical-clouds/{logical-cloud-name}/user-permissions",
userPermissionHandler.createHandler).Methods("POST")
upRouter.HandleFunc(
+ "/logical-clouds/{logical-cloud-name}/user-permissions",
+ userPermissionHandler.getAllHandler).Methods("GET")
+ upRouter.HandleFunc(
"/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}",
userPermissionHandler.getHandler).Methods("GET")
upRouter.HandleFunc(
@@ -121,6 +123,9 @@ func NewRouter(
"/logical-clouds/{logical-cloud-name}/cluster-quotas",
quotaHandler.createHandler).Methods("POST")
quotaRouter.HandleFunc(
+ "/logical-clouds/{logical-cloud-name}/cluster-quotas",
+ quotaHandler.getAllHandler).Methods("GET")
+ quotaRouter.HandleFunc(
"/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}",
quotaHandler.getHandler).Methods("GET")
quotaRouter.HandleFunc(
@@ -140,6 +145,9 @@ func NewRouter(
"/logical-clouds/{logical-cloud-name}/kv-pairs",
keyValueHandler.createHandler).Methods("POST")
kvRouter.HandleFunc(
+ "/logical-clouds/{logical-cloud-name}/kv-pairs",
+ keyValueHandler.getAllHandler).Methods("GET")
+ kvRouter.HandleFunc(
"/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}",
keyValueHandler.getHandler).Methods("GET")
kvRouter.HandleFunc(
diff --git a/src/dcm/api/clusterHandler.go b/src/dcm/api/clusterHandler.go
index db110399..427a4262 100644
--- a/src/dcm/api/clusterHandler.go
+++ b/src/dcm/api/clusterHandler.go
@@ -23,9 +23,8 @@ import (
"io"
"net/http"
- "github.com/onap/multicloud-k8s/src/dcm/pkg/module"
-
"github.com/gorilla/mux"
+ "github.com/onap/multicloud-k8s/src/dcm/pkg/module"
)
// clusterHandler is used to store backend implementations objects
@@ -33,8 +32,7 @@ type clusterHandler struct {
client module.ClusterManager
}
-// CreateHandler handles creation of the cluster reference entry in the database
-
+// createHandler handles creation of the cluster reference entry in the database
func (h clusterHandler) createHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
project := vars["project-name"]
@@ -72,7 +70,31 @@ func (h clusterHandler) createHandler(w http.ResponseWriter, r *http.Request) {
}
}
-// getHandler handle GET operations on a particular name
+// getAllHandler handles GET operations over cluster references
+// Returns a list of Cluster References
+func (h clusterHandler) getAllHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ project := vars["project-name"]
+ logicalCloud := vars["logical-cloud-name"]
+ var ret interface{}
+ var err error
+
+ ret, err = h.client.GetAllClusters(project, logicalCloud)
+ 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 Cluster Reference
func (h clusterHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
@@ -82,22 +104,14 @@ func (h clusterHandler) getHandler(w http.ResponseWriter, r *http.Request) {
var ret interface{}
var err error
- if len(name) == 0 {
- ret, err = h.client.GetAllClusters(project, logicalCloud)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
- } else {
- ret, err = h.client.GetCluster(project, logicalCloud, name)
- if err != nil {
- if err.Error() == "Cluster Reference does not exist" {
- http.Error(w, err.Error(), http.StatusNotFound)
- return
- }
- http.Error(w, err.Error(), http.StatusInternalServerError)
+ ret, err = h.client.GetCluster(project, logicalCloud, name)
+ if err != nil {
+ if err.Error() == "Cluster Reference 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")
diff --git a/src/dcm/api/keyValueHandler.go b/src/dcm/api/keyValueHandler.go
index a4a4f14a..69333efb 100644
--- a/src/dcm/api/keyValueHandler.go
+++ b/src/dcm/api/keyValueHandler.go
@@ -33,7 +33,6 @@ type keyValueHandler struct {
}
// CreateHandler handles creation of the key value entry in the database
-
func (h keyValueHandler) createHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
project := vars["project-name"]
@@ -71,6 +70,30 @@ func (h keyValueHandler) createHandler(w http.ResponseWriter, r *http.Request) {
}
}
+// getHandler handles GET operations over key-value pairs
+// Returns a list of Key Values
+func (h keyValueHandler) getAllHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ project := vars["project-name"]
+ logicalCloud := vars["logical-cloud-name"]
+ var ret interface{}
+ var err error
+
+ ret, err = h.client.GetAllKVPairs(project, logicalCloud)
+ 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 handle GET operations on a particular name
// Returns a Key Value
func (h keyValueHandler) getHandler(w http.ResponseWriter, r *http.Request) {
@@ -81,22 +104,14 @@ func (h keyValueHandler) getHandler(w http.ResponseWriter, r *http.Request) {
var ret interface{}
var err error
- if len(name) == 0 {
- ret, err = h.client.GetAllKVPairs(project, logicalCloud)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
- } else {
- ret, err = h.client.GetKVPair(project, logicalCloud, name)
- if err != nil {
- if err.Error() == "KV Pair does not exist" {
- http.Error(w, err.Error(), http.StatusNotFound)
- return
- }
- http.Error(w, err.Error(), http.StatusInternalServerError)
+ ret, err = h.client.GetKVPair(project, logicalCloud, name)
+ if err != nil {
+ if err.Error() == "KV Pair 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")
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
diff --git a/src/dcm/api/quotaHandler.go b/src/dcm/api/quotaHandler.go
index fd9b40f8..1f0e45a5 100644
--- a/src/dcm/api/quotaHandler.go
+++ b/src/dcm/api/quotaHandler.go
@@ -23,9 +23,8 @@ import (
"io"
"net/http"
- "github.com/onap/multicloud-k8s/src/dcm/pkg/module"
-
"github.com/gorilla/mux"
+ "github.com/onap/multicloud-k8s/src/dcm/pkg/module"
)
// quotaHandler is used to store backend implementations objects
@@ -34,7 +33,6 @@ type quotaHandler struct {
}
// CreateHandler handles creation of the quota entry in the database
-
func (h quotaHandler) createHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
project := vars["project-name"]
@@ -72,8 +70,32 @@ func (h quotaHandler) createHandler(w http.ResponseWriter, r *http.Request) {
}
}
+// getHandler handles GET operations over quotas
+// Returns a list of Quotas
+func (h quotaHandler) getAllHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ project := vars["project-name"]
+ logicalCloud := vars["logical-cloud-name"]
+ var ret interface{}
+ var err error
+
+ ret, err = h.client.GetAllQuotas(project, logicalCloud)
+ 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 handle GET operations on a particular name
-// Returns a quota
+// Returns a Quota
func (h quotaHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
project := vars["project-name"]
@@ -82,22 +104,14 @@ func (h quotaHandler) getHandler(w http.ResponseWriter, r *http.Request) {
var ret interface{}
var err error
- if len(name) == 0 {
- ret, err = h.client.GetAllQuotas(project, logicalCloud)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
- } else {
- ret, err = h.client.GetQuota(project, logicalCloud, name)
- if err != nil {
- if err.Error() == "Cluster Quota does not exist" {
- http.Error(w, err.Error(), http.StatusNotFound)
- return
- }
- http.Error(w, err.Error(), http.StatusInternalServerError)
+ ret, err = h.client.GetQuota(project, logicalCloud, name)
+ if err != nil {
+ if err.Error() == "Cluster Quota 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")
diff --git a/src/dcm/api/userPermissionsHandler.go b/src/dcm/api/userPermissionsHandler.go
index 3ac955fa..6d88f573 100644
--- a/src/dcm/api/userPermissionsHandler.go
+++ b/src/dcm/api/userPermissionsHandler.go
@@ -33,7 +33,6 @@ type userPermissionHandler struct {
}
// CreateHandler handles creation of the user permission entry in the database
-
func (h userPermissionHandler) createHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
@@ -72,7 +71,31 @@ func (h userPermissionHandler) createHandler(w http.ResponseWriter, r *http.Requ
}
}
-// getHandler handle GET operations on a particular name
+// getAllHandler handles GET operations over user permissions
+// Returns a list of User Permissions
+func (h userPermissionHandler) getAllHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ project := vars["project-name"]
+ logicalCloud := vars["logical-cloud-name"]
+ var ret interface{}
+ var err error
+
+ ret, err = h.client.GetAllUserPerms(project, logicalCloud)
+ 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 User Permission
func (h userPermissionHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
@@ -82,22 +105,14 @@ func (h userPermissionHandler) getHandler(w http.ResponseWriter, r *http.Request
var ret interface{}
var err error
- if len(name) == 0 {
- ret, err = h.client.GetAllUserPerms(project, logicalCloud)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
- } else {
- ret, err = h.client.GetUserPerm(project, logicalCloud, name)
- if err != nil {
- if err.Error() == "User Permission does not exist" {
- http.Error(w, err.Error(), http.StatusNotFound)
- return
- }
- http.Error(w, err.Error(), http.StatusInternalServerError)
+ ret, err = h.client.GetUserPerm(project, logicalCloud, name)
+ if err != nil {
+ if err.Error() == "User Permission 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")
diff --git a/src/dcm/pkg/module/apply.go b/src/dcm/pkg/module/apply.go
index 0b370f4a..b5ef61c2 100644
--- a/src/dcm/pkg/module/apply.go
+++ b/src/dcm/pkg/module/apply.go
@@ -266,7 +266,7 @@ func queryDBAndSetRsyncInfo() (installappclient.RsyncInfo, error) {
}
/*
-callRsyncInstall method shall take in the app context id and invokes the rsync service via grpc
+callRsyncInstall method shall take in the app context id and invoke the rsync service via grpc
*/
func callRsyncInstall(contextid interface{}) error {
rsyncInfo, err := queryDBAndSetRsyncInfo()
@@ -286,7 +286,7 @@ func callRsyncInstall(contextid interface{}) error {
}
/*
-callRsyncUninstall method shall take in the app context id and invokes the rsync service via grpc
+callRsyncUninstall method shall take in the app context id and invoke the rsync service via grpc
*/
func callRsyncUninstall(contextid interface{}) error {
rsyncInfo, err := queryDBAndSetRsyncInfo()
@@ -305,7 +305,9 @@ func callRsyncUninstall(contextid interface{}) error {
return nil
}
-func CreateEtcdContext(project string, logicalcloud LogicalCloud, clusterList []Cluster,
+// Apply prepares all yaml resources to be given to the clusters via rsync,
+// then creates an appcontext with such resources and asks rsync to apply the logical cloud
+func Apply(project string, logicalcloud LogicalCloud, clusterList []Cluster,
quotaList []Quota) error {
APP := "logical-cloud"
@@ -596,9 +598,9 @@ func CreateEtcdContext(project string, logicalcloud LogicalCloud, clusterList []
}
-// TODO: rename these methods
-// DestroyEtcdContext remove from rsync then delete appcontext and all resources
-func DestroyEtcdContext(project string, logicalcloud LogicalCloud, clusterList []Cluster,
+// Terminate asks rsync to terminate the logical cloud, then waits in the background until
+// rsync claims the logical cloud is terminated, and then deletes the appcontext
+func Terminate(project string, logicalcloud LogicalCloud, clusterList []Cluster,
quotaList []Quota) error {
logicalCloudName := logicalcloud.MetaData.LogicalCloudName