aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/rb/profile.go
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2019-07-23 07:29:59 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-23 07:29:59 +0000
commit40014c64df3250db72b41e05da3dd40746d3d6d3 (patch)
tree53ac8d7d586341fe66ece7cd4c553e610c06c194 /src/k8splugin/internal/rb/profile.go
parent75afe2e559a170f5cae7e870059db0438e02aa4b (diff)
parent412d02f7bd53a9e810be2c17d1c391c9bc6dda13 (diff)
Merge changes from topics "listprofiles", "tagprofile", "tag_defn"
* changes: Add list api for profiles Make profile db tags specific Make definition tags specific
Diffstat (limited to 'src/k8splugin/internal/rb/profile.go')
-rw-r--r--src/k8splugin/internal/rb/profile.go38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/k8splugin/internal/rb/profile.go b/src/k8splugin/internal/rb/profile.go
index 37e9aba8..49768d4b 100644
--- a/src/k8splugin/internal/rb/profile.go
+++ b/src/k8splugin/internal/rb/profile.go
@@ -20,6 +20,7 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
+ "log"
"path/filepath"
"github.com/onap/multicloud-k8s/src/k8splugin/internal/db"
@@ -44,6 +45,7 @@ type Profile struct {
type ProfileManager interface {
Create(def Profile) (Profile, error)
Get(rbName, rbVersion, prName string) (Profile, error)
+ List(rbName, rbVersion string) ([]Profile, error)
Delete(rbName, rbVersion, prName string) error
Upload(rbName, rbVersion, prName string, inp []byte) error
}
@@ -78,8 +80,8 @@ type ProfileClient struct {
func NewProfileClient() *ProfileClient {
return &ProfileClient{
storeName: "rbdef",
- tagMeta: "metadata",
- tagContent: "content",
+ tagMeta: "profilemetadata",
+ tagContent: "profilecontent",
manifestName: "manifest.yaml",
}
}
@@ -148,6 +150,38 @@ func (v *ProfileClient) Get(rbName, rbVersion, prName string) (Profile, error) {
return Profile{}, pkgerrors.New("Error getting Resource Bundle Profile")
}
+// List returns the Resource Bundle Profile for corresponding ID
+func (v *ProfileClient) List(rbName, rbVersion string) ([]Profile, error) {
+
+ //Get all profiles
+ dbres, err := db.DBconn.ReadAll(v.storeName, v.tagMeta)
+ if err != nil || len(dbres) == 0 {
+ return []Profile{}, pkgerrors.Wrap(err, "No Profiles Found")
+ }
+
+ var results []Profile
+ for key, value := range dbres {
+ //value is a byte array
+ if value != nil {
+ pr := Profile{}
+ err = db.DBconn.Unmarshal(value, &pr)
+ if err != nil {
+ log.Printf("[Profile] Error: %s Unmarshaling value for: %s", err.Error(), key)
+ continue
+ }
+ if pr.RBName == rbName && pr.RBVersion == rbVersion {
+ results = append(results, pr)
+ }
+ }
+ }
+
+ if len(results) == 0 {
+ return results, pkgerrors.New("No Profiles Found for Definition and Version")
+ }
+
+ return results, nil
+}
+
// Delete the Resource Bundle Profile from database
func (v *ProfileClient) Delete(rbName, rbVersion, prName string) error {
key := ProfileKey{