From c257a136355a794f5bf778f670c041e8958c3608 Mon Sep 17 00:00:00 2001 From: Rajamohan Raj Date: Tue, 26 May 2020 20:08:58 +0000 Subject: Adding cluster meta data and saving in etcd As part of this patch, we assign groupNumbers for the set of clusters which are under anyOf, or in other words are optional for deployement of app. Also refactored the instantiation flow by separating out the etcd interactions Issue-ID: MULTICLOUD-1064 Signed-off-by: Rajamohan Raj Change-Id: I21ece189daf6e6b3a7cfdba5df22d57b3d33ca78 --- src/orchestrator/pkg/rtcontext/rtcontext.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/orchestrator/pkg/rtcontext') diff --git a/src/orchestrator/pkg/rtcontext/rtcontext.go b/src/orchestrator/pkg/rtcontext/rtcontext.go index 5610ea58..432c5d87 100644 --- a/src/orchestrator/pkg/rtcontext/rtcontext.go +++ b/src/orchestrator/pkg/rtcontext/rtcontext.go @@ -48,6 +48,7 @@ type Rtcontext interface { RtcGetValue(handle interface{}, value interface{}) error RtcUpdateValue(handle interface{}, value interface{}) error RtcGetMeta() (interface{}, error) + RtcAddOneLevel(pl interface{}, level string, value interface{}) (interface{}, error) } //Intialize context by assiging a new id @@ -176,6 +177,30 @@ func (rtc *RunTimeContext) RtcAddLevel(handle interface{}, level string, value s return (interface{})(key), nil } +// RtcAddOneLevel adds one more level to the existing context prefix.RtcAddOneLevel. It takes in PreviousContentLevel as inteface, new level to be appended as string and the value to be saved of any type. It returns the updated interface and nil if no error. +// +func (rtc *RunTimeContext) RtcAddOneLevel(pl interface{}, level string, value interface{}) (interface{}, error) { + str := fmt.Sprintf("%v", pl) + sid := fmt.Sprintf("%v", rtc.cid) + if !strings.HasPrefix(str, sid) { + return nil, pkgerrors.Errorf("Not a valid run time context handle") + } + + if level == "" { + return nil, pkgerrors.Errorf("Not a valid run time context level") + } + if value == "" { + return nil, pkgerrors.Errorf("Not a valid run time context level value") + } + + key := str + level + "/" + err := contextdb.Db.Put(key, value) + if err != nil { + return nil, pkgerrors.Errorf("Error adding run time context level: %s", err.Error()) + } + return (interface{})(key), nil +} + // Add a resource under the given level and return new handle func (rtc *RunTimeContext) RtcAddResource(handle interface{}, resname string, value interface{}) (interface{}, error) { -- cgit 1.2.3-korg