diff options
author | Ritu Sood <ritu.sood@intel.com> | 2021-10-15 13:58:21 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-10-15 13:58:21 +0000 |
commit | 0ea71e9b830e6d1ed60b3dc6312cd748b24ce739 (patch) | |
tree | abbc4b0a50d0dce9b31c1628d6eb9a3e6d099580 /src/k8splugin/internal/rb/config_template.go | |
parent | 206e9ecc81c4eec81a0471b4a24f3ae206bfe744 (diff) | |
parent | b2f51225bc78212682fd087a4ef8a67c51a94188 (diff) |
Merge "Expose Update Handlers"
Diffstat (limited to 'src/k8splugin/internal/rb/config_template.go')
-rw-r--r-- | src/k8splugin/internal/rb/config_template.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/k8splugin/internal/rb/config_template.go b/src/k8splugin/internal/rb/config_template.go index b84b6461..97fe0fb4 100644 --- a/src/k8splugin/internal/rb/config_template.go +++ b/src/k8splugin/internal/rb/config_template.go @@ -41,7 +41,7 @@ type ConfigTemplate struct { // ConfigTemplateManager is an interface exposes the resource bundle ConfigTemplate functionality type ConfigTemplateManager interface { - Create(rbName, rbVersion string, p ConfigTemplate) error + CreateOrUpdate(rbName, rbVersion string, p ConfigTemplate, update bool) error Get(rbName, rbVersion, templateName string) (ConfigTemplate, error) List(rbName, rbVersion string) ([]ConfigTemplate, error) Delete(rbName, rbVersion, templateName string) error @@ -84,8 +84,8 @@ func NewConfigTemplateClient() *ConfigTemplateClient { } } -// Create an entry for the resource bundle ConfigTemplate in the database -func (v *ConfigTemplateClient) Create(rbName, rbVersion string, p ConfigTemplate) error { +// CreateOrUpdate an entry for the resource bundle ConfigTemplate in the database +func (v *ConfigTemplateClient) CreateOrUpdate(rbName, rbVersion string, p ConfigTemplate, update bool) error { log.Printf("[ConfigiTemplate]: create %s", rbName) // Name is required @@ -95,9 +95,12 @@ func (v *ConfigTemplateClient) Create(rbName, rbVersion string, p ConfigTemplate //Check if ConfigTemplate already exists _, err := v.Get(rbName, rbVersion, p.TemplateName) - if err == nil { + if err == nil && !update { return pkgerrors.New(" ConfigTemplate already exists for this Definition") } + if err != nil && update { + return pkgerrors.New(" ConfigTemplate does not exist for this Definition") + } //Check if provided resource bundle information is valid _, err = NewDefinitionClient().Get(rbName, rbVersion) @@ -111,9 +114,16 @@ func (v *ConfigTemplateClient) Create(rbName, rbVersion string, p ConfigTemplate TemplateName: p.TemplateName, } - err = db.DBconn.Create(v.storeName, key, v.tagMeta, p) - if err != nil { - return pkgerrors.Wrap(err, "Creating ConfigTemplate DB Entry") + if update { + err = db.DBconn.Update(v.storeName, key, v.tagMeta, p) + if err != nil { + return pkgerrors.Wrap(err, "Updating ConfigTemplate DB Entry") + } + } else { + err = db.DBconn.Create(v.storeName, key, v.tagMeta, p) + if err != nil { + return pkgerrors.Wrap(err, "Creating ConfigTemplate DB Entry") + } } return nil |