summaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/rtcontext/rtcontext.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/orchestrator/pkg/rtcontext/rtcontext.go')
-rw-r--r--src/orchestrator/pkg/rtcontext/rtcontext.go45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/orchestrator/pkg/rtcontext/rtcontext.go b/src/orchestrator/pkg/rtcontext/rtcontext.go
index 1835251a..5610ea58 100644
--- a/src/orchestrator/pkg/rtcontext/rtcontext.go
+++ b/src/orchestrator/pkg/rtcontext/rtcontext.go
@@ -29,13 +29,15 @@ const maxrand = 0x7fffffffffffffff
const prefix string = "/context/"
type RunTimeContext struct {
- cid interface{}
+ cid interface{}
+ meta interface{}
}
type Rtcontext interface {
RtcInit() (interface{}, error)
RtcLoad(interface{}) (interface{}, error)
RtcCreate() (interface{}, error)
+ RtcAddMeta(meta interface{}) error
RtcGet() (interface{}, error)
RtcAddLevel(handle interface{}, level string, value string) (interface{}, error)
RtcAddResource(handle interface{}, resname string, value interface{}) (interface{}, error)
@@ -45,6 +47,7 @@ type Rtcontext interface {
RtcGetHandles(handle interface{}) ([]interface{}, error)
RtcGetValue(handle interface{}, value interface{}) error
RtcUpdateValue(handle interface{}, value interface{}) error
+ RtcGetMeta() (interface{}, error)
}
//Intialize context by assiging a new id
@@ -76,7 +79,6 @@ func (rtc *RunTimeContext) RtcLoad(id interface{}) (interface{}, error) {
return handle, nil
}
-//Create context using the id and prefix
func (rtc *RunTimeContext) RtcCreate() (interface{}, error) {
cid := fmt.Sprintf("%v", rtc.cid)
if cid == "" {
@@ -94,6 +96,26 @@ func (rtc *RunTimeContext) RtcCreate() (interface{}, error) {
return rtc.cid, nil
}
+//RtcAddMeta is used for saving meta data of appContext into ETCD.
+func (rtc *RunTimeContext) RtcAddMeta(meta interface{}) error {
+ cid := fmt.Sprintf("%v", rtc.cid)
+ if cid == "" {
+ return pkgerrors.Errorf("Error, context not intialized")
+ }
+ if !strings.HasPrefix(cid, prefix) {
+ return pkgerrors.Errorf("Not a valid run time context prefix")
+ }
+
+ rtc.meta = meta
+ k := cid + "meta" + "/"
+ err := contextdb.Db.Put(k, rtc.meta)
+ if err != nil {
+ return pkgerrors.Errorf("Error saving metadata in run time context: %s", err.Error())
+ }
+
+ return nil
+}
+
//Get the root handle
func (rtc *RunTimeContext) RtcGet() (interface{}, error) {
str := fmt.Sprintf("%v", rtc.cid)
@@ -113,6 +135,23 @@ func (rtc *RunTimeContext) RtcGet() (interface{}, error) {
return rtc.cid, nil
}
+// RtcGetMeta method fetches the meta data of the rtc object and returns it.
+func (rtc *RunTimeContext) RtcGetMeta() (interface{}, error) {
+ str := fmt.Sprintf("%v", rtc.cid)
+ if !strings.HasPrefix(str, prefix) {
+ return nil, pkgerrors.Errorf("Not a valid run time context")
+ }
+
+ var value interface{}
+ k := str + "meta" + "/"
+ err := contextdb.Db.Get(k, &value)
+ if err != nil {
+ return nil, pkgerrors.Errorf("Error getting run time context metadata: %s", err.Error())
+ }
+ return value, nil
+
+}
+
//Add a new level at a given handle and return the new handle
func (rtc *RunTimeContext) RtcAddLevel(handle interface{}, level string, value string) (interface{}, error) {
str := fmt.Sprintf("%v", handle)
@@ -177,7 +216,6 @@ func (rtc *RunTimeContext) RtcAddInstruction(handle interface{}, level string, i
if value == nil {
return nil, pkgerrors.Errorf("Not a valid run time context instruction value")
}
-
k := str + level + "/" + "instruction" + "/" + insttype + "/"
err := contextdb.Db.Put(k, fmt.Sprintf("%v", value))
if err != nil {
@@ -194,7 +232,6 @@ func (rtc *RunTimeContext) RtcDeletePair(handle interface{}) error {
if !strings.HasPrefix(str, sid) {
return pkgerrors.Errorf("Not a valid run time context handle")
}
-
err := contextdb.Db.Delete(str)
if err != nil {
return pkgerrors.Errorf("Error deleting run time context pair: %s", err.Error())