summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/handler.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-12-10 13:34:16 -0800
committerKiran Kamineni <kiran.k.kamineni@intel.com>2018-12-14 14:26:26 -0800
commitd203ccf9174e450b6f5a6a9aabea95b73c9973ff (patch)
tree702034eafbd28b47f33023607ee213cf92519a99 /src/k8splugin/api/handler.go
parentaa56022e0fba3c358e46e8671d9a0cd36094ebaa (diff)
Migrating from consul to mongodb for backend
Migrating to mongodb from consul. The main reason being the value size limitation of 512kb in consul. See https://jira.onap.org/browse/MULTICLOUD-426 for details. This requires a little bit of hierarchy management and data management. We are no longer converting structs to json encoded strings. The underlying db supports structs without any modifications. Also, since Mongo has the concept of collections, each submodule can use its own collection for storage as needed. Definition uses a collection called rbdef right now. P10: Enabling unit tests for mongo.go. This requires the usage of aliased functions. P11: Expanded unit tests for all functions in mongo.go P12: Refactored parameter validation. Removed TestHealthCheck as we are not mocking any of the db commands right now Checking return value of read with an expected value P13: Adding back consul support. Fixing functional test Full consul implementation check and modifications is being tracked by MULTICLOUD-427 P15: Fix ReadAll unit test and corresponding code ReadAll now returns error when no objects are found Issue-ID: MULTICLOUD-426 Change-Id: I42d239b324025fc4ef4e561790aceeff794001ef Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/api/handler.go')
-rw-r--r--src/k8splugin/api/handler.go55
1 files changed, 18 insertions, 37 deletions
diff --git a/src/k8splugin/api/handler.go b/src/k8splugin/api/handler.go
index 53fa2317..4c49ba78 100644
--- a/src/k8splugin/api/handler.go
+++ b/src/k8splugin/api/handler.go
@@ -30,6 +30,10 @@ import (
"k8splugin/krd"
)
+//TODO: Separate the http handler code and backend code out
+var storeName = "rbinst"
+var tagData = "data"
+
// GetVNFClient retrieves the client used to communicate with a Kubernetes Cluster
var GetVNFClient = func(kubeConfigPath string) (kubernetes.Clientset, error) {
client, err := krd.GetKubeClient(kubeConfigPath)
@@ -117,17 +121,9 @@ func CreateHandler(w http.ResponseWriter, r *http.Request) {
// TODO: Uncomment when annotations are done
// krd.AddNetworkAnnotationsToPod(kubeData, resource.Networks)
- // "{"deployment":<>,"service":<>}"
- serializedResourceNameMap, err := db.Serialize(resourceNameMap)
- if err != nil {
- werr := pkgerrors.Wrap(err, "Create VNF deployment JSON Marshalling error")
- http.Error(w, werr.Error(), http.StatusInternalServerError)
- return
- }
-
// key: cloud1-default-uuid
// value: "{"deployment":<>,"service":<>}"
- err = db.DBconn.Create(internalVNFID, serializedResourceNameMap)
+ err = db.DBconn.Create(storeName, internalVNFID, tagData, resourceNameMap)
if err != nil {
werr := pkgerrors.Wrap(err, "Create VNF deployment DB error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
@@ -154,27 +150,22 @@ func ListHandler(w http.ResponseWriter, r *http.Request) {
namespace := vars["namespace"]
prefix := cloudRegionID + "-" + namespace
- internalVNFIDs, err := db.DBconn.ReadAll(prefix)
+ res, err := db.DBconn.ReadAll(storeName, tagData)
if err != nil {
http.Error(w, pkgerrors.Wrap(err, "Get VNF list error").Error(),
http.StatusInternalServerError)
return
}
- if len(internalVNFIDs) == 0 {
- w.WriteHeader(http.StatusNotFound)
- return
- }
-
// TODO: There is an edge case where if namespace is passed but is missing some characters
// trailing, it will print the result with those excluding characters. This is because of
// the way I am trimming the Prefix. This fix is needed.
var editedList []string
- for _, id := range internalVNFIDs {
- if len(id) > 0 {
- editedList = append(editedList, strings.TrimPrefix(id, prefix)[1:])
+ for key, value := range res {
+ if len(value) > 0 {
+ editedList = append(editedList, strings.TrimPrefix(key, prefix)[1:])
}
}
@@ -204,25 +195,20 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
// key: cloud1-default-uuid
// value: "{"deployment":<>,"service":<>}"
- serializedResourceNameMap, err := db.DBconn.Read(internalVNFID)
+ res, err := db.DBconn.Read(storeName, internalVNFID, tagData)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- if serializedResourceNameMap == "" {
- w.WriteHeader(http.StatusNotFound)
- return
- }
-
/*
{
"deployment": ["cloud1-default-uuid-sisedeploy1", "cloud1-default-uuid-sisedeploy2", ... ]
"service": ["cloud1-default-uuid-sisesvc1", "cloud1-default-uuid-sisesvc2", ... ]
},
*/
- deserializedResourceNameMap := make(map[string][]string)
- err = db.DeSerialize(serializedResourceNameMap, &deserializedResourceNameMap)
+ data := make(map[string][]string)
+ err = db.DBconn.Unmarshal(res, &data)
if err != nil {
werr := pkgerrors.Wrap(err, "Unmarshal VNF error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
@@ -237,14 +223,14 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- err = csar.DestroyVNF(deserializedResourceNameMap, namespace, &kubeclient)
+ err = csar.DestroyVNF(data, namespace, &kubeclient)
if err != nil {
werr := pkgerrors.Wrap(err, "Delete VNF error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
return
}
- err = db.DBconn.Delete(internalVNFID)
+ err = db.DBconn.Delete(storeName, internalVNFID, tagData)
if err != nil {
werr := pkgerrors.Wrap(err, "Delete VNF db record error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
@@ -337,25 +323,20 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
// key: cloud1-default-uuid
// value: "{"deployment":<>,"service":<>}"
- serializedResourceNameMap, err := db.DBconn.Read(internalVNFID)
+ res, err := db.DBconn.Read(storeName, internalVNFID, tagData)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- if serializedResourceNameMap == "" {
- w.WriteHeader(http.StatusNotFound)
- return
- }
-
/*
{
"deployment": ["cloud1-default-uuid-sisedeploy1", "cloud1-default-uuid-sisedeploy2", ... ]
"service": ["cloud1-default-uuid-sisesvc1", "cloud1-default-uuid-sisesvc2", ... ]
},
*/
- deserializedResourceNameMap := make(map[string][]string)
- err = db.DeSerialize(serializedResourceNameMap, &deserializedResourceNameMap)
+ data := make(map[string][]string)
+ err = db.DBconn.Unmarshal(res, &data)
if err != nil {
werr := pkgerrors.Wrap(err, "Unmarshal VNF error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
@@ -366,7 +347,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
VNFID: externalVNFID,
CloudRegionID: cloudRegionID,
Namespace: namespace,
- VNFComponents: deserializedResourceNameMap,
+ VNFComponents: data,
}
w.Header().Set("Content-Type", "application/json")