diff options
author | 2021-09-28 21:42:24 +0200 | |
---|---|---|
committer | 2021-09-28 21:43:02 +0200 | |
commit | dc62323aa7f6782d69c7ac6509eb270e86ef31bd (patch) | |
tree | 2f764f7816c44d9a62a0fe72b473ce5627ed89a9 /src/k8splugin/internal/rb | |
parent | 5aa8c4de9fd620ef42ac5bf73b62f76d80e713a0 (diff) |
Fix for config resources delete with instance delete
Issue-ID: MULTICLOUD-1332
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Change-Id: I08a3d623d6f12777d88a168af0cb804c63104887
Diffstat (limited to 'src/k8splugin/internal/rb')
-rw-r--r-- | src/k8splugin/internal/rb/config_template.go | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/k8splugin/internal/rb/config_template.go b/src/k8splugin/internal/rb/config_template.go index cf45a6f2..b84b6461 100644 --- a/src/k8splugin/internal/rb/config_template.go +++ b/src/k8splugin/internal/rb/config_template.go @@ -20,14 +20,16 @@ import ( "bytes" "encoding/json" "io/ioutil" - "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" "os" "path/filepath" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" + "encoding/base64" - pkgerrors "github.com/pkg/errors" "log" + + pkgerrors "github.com/pkg/errors" ) // ConfigTemplate contains the parameters needed for ConfigTemplates @@ -41,6 +43,7 @@ type ConfigTemplate struct { type ConfigTemplateManager interface { Create(rbName, rbVersion string, p ConfigTemplate) error Get(rbName, rbVersion, templateName string) (ConfigTemplate, error) + List(rbName, rbVersion string) ([]ConfigTemplate, error) Delete(rbName, rbVersion, templateName string) error Upload(rbName, rbVersion, templateName string, inp []byte) error } @@ -76,8 +79,8 @@ type ConfigTemplateClient struct { func NewConfigTemplateClient() *ConfigTemplateClient { return &ConfigTemplateClient{ storeName: "rbdef", - tagMeta: "metadata", - tagContent: "content", + tagMeta: "confdefmetadata", + tagContent: "confdefcontent", } } @@ -141,6 +144,44 @@ func (v *ConfigTemplateClient) Get(rbName, rbVersion, templateName string) (Conf return ConfigTemplate{}, pkgerrors.New("Error getting ConfigTemplate") } +// List returns the Resource Bundle ConfigTemplate for corresponding ID +func (v *ConfigTemplateClient) List(rbName, rbVersion string) ([]ConfigTemplate, error) { + + //Get all config templates + dbres, err := db.DBconn.ReadAll(v.storeName, v.tagMeta) + if err != nil || len(dbres) == 0 { + return []ConfigTemplate{}, pkgerrors.Wrap(err, "No Config Templates Found") + } + + var results []ConfigTemplate + for key, value := range dbres { + //value is a byte array + if value != nil { + tmp := ConfigTemplate{} + err = db.DBconn.Unmarshal(value, &tmp) + if err != nil { + log.Printf("[ConfigTemplate] Error: %s Unmarshaling value for: %s", err.Error(), key) + continue + } + keyTmp := ConfigTemplateKey{ + RBName: rbName, + RBVersion: rbVersion, + TemplateName: tmp.TemplateName, + } + _, err := db.DBconn.Read(v.storeName, keyTmp, v.tagMeta) + if err == nil && keyTmp.RBName == rbName && keyTmp.RBVersion == rbVersion { + results = append(results, tmp) + } + } + } + + if len(results) == 0 { + return results, pkgerrors.New("No Config Templates Found for Definition and Version") + } + + return results, nil +} + // Delete the Resource Bundle ConfigTemplate from database func (v *ConfigTemplateClient) Delete(rbName, rbVersion, templateName string) error { key := ConfigTemplateKey{ |