From 037cfda2181e4995e4e2a47db6f1121b532b686b Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Fri, 15 Mar 2019 15:03:01 -0700 Subject: 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 --- src/k8splugin/api/handler.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/k8splugin/api/handler.go') 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 -- cgit 1.2.3-korg