aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-15 15:03:01 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-25 14:41:34 -0700
commit037cfda2181e4995e4e2a47db6f1121b532b686b (patch)
treef9cb838fc5cc037c01a9f55f561c3b5621236667 /src/k8splugin/api
parent8cdd50b6a06aef5cb0541e74a07b10bd4b01b589 (diff)
Add support for composite keys
Composite keys help us store objects which are unique for a given set of pre-existing objects. Eg: Many profiles can exist for a definition and its key will have a definition name as a part of the composite key. P2: Use a predefined interface for keys instead of generic interfaceP{} P3: Add check for empty strings in stringer interface P5: Add appropriate keys in other packages. Issue-ID: MULTICLOUD-531 Change-Id: I314b1fbd718489ae8a45f0f38915c08ca32f9f43 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/api')
-rw-r--r--src/k8splugin/api/handler.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/k8splugin/api/handler.go b/src/k8splugin/api/handler.go
index 4d6abe27..b1cc6709 100644
--- a/src/k8splugin/api/handler.go
+++ b/src/k8splugin/api/handler.go
@@ -35,6 +35,14 @@ import (
var storeName = "rbinst"
var tagData = "data"
+type instanceKey struct {
+ Key string
+}
+
+func (dk instanceKey) String() string {
+ return dk.Key
+}
+
// GetVNFClient retrieves the client used to communicate with a Kubernetes Cluster
var GetVNFClient = func(kubeConfigPath string) (kubernetes.Clientset, error) {
client, err := helper.GetKubeClient(kubeConfigPath)
@@ -130,7 +138,7 @@ func CreateHandler(w http.ResponseWriter, r *http.Request) {
// key: cloud1-default-uuid
// value: "{"deployment":<>,"service":<>}"
- err = db.DBconn.Create(storeName, internalVNFID, tagData, resourceNameMap)
+ err = db.DBconn.Create(storeName, instanceKey{Key: internalVNFID}, tagData, resourceNameMap)
if err != nil {
werr := pkgerrors.Wrap(err, "Create VNF deployment DB error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
@@ -202,7 +210,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
// key: cloud1-default-uuid
// value: "{"deployment":<>,"service":<>}"
- res, err := db.DBconn.Read(storeName, internalVNFID, tagData)
+ res, err := db.DBconn.Read(storeName, instanceKey{Key: internalVNFID}, tagData)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -237,7 +245,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
return
}
- err = db.DBconn.Delete(storeName, internalVNFID, tagData)
+ err = db.DBconn.Delete(storeName, instanceKey{Key: internalVNFID}, tagData)
if err != nil {
werr := pkgerrors.Wrap(err, "Delete VNF db record error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
@@ -330,7 +338,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
// key: cloud1-default-uuid
// value: "{"deployment":<>,"service":<>}"
- res, err := db.DBconn.Read(storeName, internalVNFID, tagData)
+ res, err := db.DBconn.Read(storeName, instanceKey{Key: internalVNFID}, tagData)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return