summaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/appcontext
diff options
context:
space:
mode:
Diffstat (limited to 'src/orchestrator/pkg/appcontext')
-rw-r--r--src/orchestrator/pkg/appcontext/appcontext.go59
-rw-r--r--src/orchestrator/pkg/appcontext/appcontext_test.go78
2 files changed, 76 insertions, 61 deletions
diff --git a/src/orchestrator/pkg/appcontext/appcontext.go b/src/orchestrator/pkg/appcontext/appcontext.go
index 357402b3..bad5fa47 100644
--- a/src/orchestrator/pkg/appcontext/appcontext.go
+++ b/src/orchestrator/pkg/appcontext/appcontext.go
@@ -24,17 +24,22 @@ import (
type AppContext struct {
initDone bool
- rtcObj rtcontext.RunTimeContext
- rtc rtcontext.Rtcontext
+ rtcObj rtcontext.RunTimeContext
+ rtc rtcontext.Rtcontext
}
// Init app context
-func (ac *AppContext) InitAppContext() {
- if !ac.initDone {
- ac.rtcObj = rtcontext.RunTimeContext{}
- ac.initDone = true
- }
+func (ac *AppContext) InitAppContext() (interface{}, error) {
+ ac.rtcObj = rtcontext.RunTimeContext{}
+ ac.rtc = &ac.rtcObj
+ return ac.rtc.RtcInit()
+}
+
+// Load app context that was previously created
+func (ac *AppContext) LoadAppContext(cid interface{}) (interface{}, error) {
+ ac.rtcObj = rtcontext.RunTimeContext{}
ac.rtc = &ac.rtcObj
+ return ac.rtc.RtcLoad(cid)
}
// Create a new context and returns the handle
@@ -47,7 +52,7 @@ func (ac *AppContext) CreateCompositeApp() (interface{}, error) {
}
// Deletes the entire context
-func (ac *AppContext) DeleteCompositeApp() (error) {
+func (ac *AppContext) DeleteCompositeApp() error {
h, err := ac.rtc.RtcGet()
if err != nil {
return err
@@ -61,9 +66,9 @@ func (ac *AppContext) DeleteCompositeApp() (error) {
//Returns the handles for a given composite app context
func (ac *AppContext) GetCompositeApp() (interface{}, error) {
- h, err := ac.rtc.RtcGet()
- if err != nil {
- return nil, err
+ h, err := ac.rtc.RtcGet()
+ if err != nil {
+ return nil, err
}
return h, nil
}
@@ -77,8 +82,8 @@ func (ac *AppContext) AddApp(handle interface{}, appname string) (interface{}, e
return h, nil
}
-//Delete app from the context and everything underneth
-func (ac *AppContext) DeleteApp(handle interface{}) (error) {
+//Delete app from the context and everything underneth
+func (ac *AppContext) DeleteApp(handle interface{}) error {
err := ac.rtc.RtcDeletePrefix(handle)
if err != nil {
return err
@@ -120,7 +125,7 @@ func (ac *AppContext) AddCluster(handle interface{}, clustername string) (interf
}
//Delete cluster from the context and everything underneth
-func (ac *AppContext) DeleteCluster(handle interface{}) (error) {
+func (ac *AppContext) DeleteCluster(handle interface{}) error {
err := ac.rtc.RtcDeletePrefix(handle)
if err != nil {
return err
@@ -156,7 +161,7 @@ func (ac *AppContext) GetClusterHandle(appname string, clustername string) (inte
}
//Add resource under app and cluster
-func (ac *AppContext) AddResource(handle interface{},resname string, value interface{}) (interface{}, error) {
+func (ac *AppContext) AddResource(handle interface{}, resname string, value interface{}) (interface{}, error) {
h, err := ac.rtc.RtcAddResource(handle, resname, value)
if err != nil {
return nil, err
@@ -165,7 +170,7 @@ func (ac *AppContext) AddResource(handle interface{},resname string, value inter
}
//Delete resource given the handle
-func (ac *AppContext) DeleteResource(handle interface{}) (error) {
+func (ac *AppContext) DeleteResource(handle interface{}) error {
err := ac.rtc.RtcDeletePair(handle)
if err != nil {
return err
@@ -201,7 +206,7 @@ func (ac *AppContext) GetResourceHandle(appname string, clustername string, resn
}
//Update the resource value usign the given handle
-func (ac *AppContext) UpdateResourceValue(handle interface{}, value interface{}) (error) {
+func (ac *AppContext) UpdateResourceValue(handle interface{}, value interface{}) error {
return ac.rtc.RtcUpdateValue(handle, value)
}
@@ -217,11 +222,11 @@ func (ac *AppContext) AddInstruction(handle interface{}, level string, insttype
if err != nil {
return nil, err
}
- return h,nil
+ return h, nil
}
//Delete instruction under gievn handle
-func (ac *AppContext) DeleteInstruction(handle interface{}) (error) {
+func (ac *AppContext) DeleteInstruction(handle interface{}) error {
err := ac.rtc.RtcDeletePair(handle)
if err != nil {
return err
@@ -244,11 +249,11 @@ func (ac *AppContext) GetAppInstruction(insttype string) (interface{}, error) {
if err != nil {
return nil, err
}
- return v,nil
+ return v, nil
}
//Update the instruction usign the given handle
-func (ac *AppContext) UpdateInstructionValue(handle interface{}, value interface{}) (error) {
+func (ac *AppContext) UpdateInstructionValue(handle interface{}, value interface{}) error {
return ac.rtc.RtcUpdateValue(handle, value)
}
@@ -264,10 +269,10 @@ func (ac *AppContext) GetResourceInstruction(appname string, clustername string,
s := fmt.Sprintf("%v", rh) + "app/" + appname + "/cluster/" + clustername + "/resource/instruction/" + insttype
var v string
err = ac.rtc.RtcGetValue(s, &v)
- if err != nil {
- return nil, err
- }
- return v,nil
+ if err != nil {
+ return nil, err
+ }
+ return v, nil
}
//Return all the handles under the composite app
@@ -276,7 +281,7 @@ func (ac *AppContext) GetAllHandles(handle interface{}) ([]interface{}, error) {
if err != nil {
return nil, err
}
- return hs,nil
+ return hs, nil
}
//Returns the value for a given handle
@@ -286,5 +291,5 @@ func (ac *AppContext) GetValue(handle interface{}) (interface{}, error) {
if err != nil {
return nil, err
}
- return v,nil
+ return v, nil
}
diff --git a/src/orchestrator/pkg/appcontext/appcontext_test.go b/src/orchestrator/pkg/appcontext/appcontext_test.go
index a6f3e94e..3fde3a9e 100644
--- a/src/orchestrator/pkg/appcontext/appcontext_test.go
+++ b/src/orchestrator/pkg/appcontext/appcontext_test.go
@@ -18,15 +18,15 @@ package appcontext
import (
"fmt"
- "testing"
- "strings"
pkgerrors "github.com/pkg/errors"
+ "strings"
+ "testing"
)
// Mock run time context
type MockRunTimeContext struct {
Items map[string]interface{}
- Err error
+ Err error
}
func (c *MockRunTimeContext) RtcCreate() (interface{}, error) {
@@ -40,6 +40,16 @@ func (c *MockRunTimeContext) RtcCreate() (interface{}, error) {
}
+func (c *MockRunTimeContext) RtcInit() (interface{}, error) {
+ var id string = "9345674458787728"
+ return id, c.Err
+}
+
+func (c *MockRunTimeContext) RtcLoad(id interface{}) (interface{}, error) {
+ str := "/context/" + fmt.Sprintf("%v", id) + "/"
+ return interface{}(str), c.Err
+}
+
func (c *MockRunTimeContext) RtcGet() (interface{}, error) {
var key string = "/context/9345674458787728/"
return key, c.Err
@@ -65,13 +75,13 @@ func (c *MockRunTimeContext) RtcAddInstruction(handle interface{}, level string,
return nil, c.Err
}
-func (c *MockRunTimeContext) RtcDeletePair(handle interface{}) (error) {
+func (c *MockRunTimeContext) RtcDeletePair(handle interface{}) error {
str := fmt.Sprintf("%v", handle)
delete(c.Items, str)
return c.Err
}
-func (c *MockRunTimeContext) RtcDeletePrefix(handle interface{}) (error) {
+func (c *MockRunTimeContext) RtcDeletePrefix(handle interface{}) error {
for k, _ := range c.Items {
delete(c.Items, k)
}
@@ -87,7 +97,7 @@ func (c *MockRunTimeContext) RtcGetHandles(handle interface{}) ([]interface{}, e
return keys, c.Err
}
-func (c *MockRunTimeContext) RtcGetValue(handle interface{}, value interface{}) (error) {
+func (c *MockRunTimeContext) RtcGetValue(handle interface{}, value interface{}) error {
key := fmt.Sprintf("%v", handle)
var s *string
s = value.(*string)
@@ -100,7 +110,7 @@ func (c *MockRunTimeContext) RtcGetValue(handle interface{}, value interface{})
return c.Err
}
-func (c *MockRunTimeContext) RtcUpdateValue(handle interface{}, value interface{}) (error) {
+func (c *MockRunTimeContext) RtcUpdateValue(handle interface{}, value interface{}) error {
key := fmt.Sprintf("%v", handle)
c.Items[key] = value
return c.Err
@@ -109,16 +119,16 @@ func (c *MockRunTimeContext) RtcUpdateValue(handle interface{}, value interface{
func TestCreateCompositeApp(t *testing.T) {
var ac = AppContext{}
testCases := []struct {
- label string
+ label string
mockRtcontext *MockRunTimeContext
expectedError string
}{
{
- label: "Success case",
+ label: "Success case",
mockRtcontext: &MockRunTimeContext{},
},
{
- label: "Create returns error case",
+ label: "Create returns error case",
mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error creating run time context:")},
expectedError: "Error creating run time context:",
},
@@ -141,16 +151,16 @@ func TestCreateCompositeApp(t *testing.T) {
func TestGetCompositeApp(t *testing.T) {
var ac = AppContext{}
testCases := []struct {
- label string
+ label string
mockRtcontext *MockRunTimeContext
expectedError string
}{
{
- label: "Success case",
+ label: "Success case",
mockRtcontext: &MockRunTimeContext{},
},
{
- label: "Get returns error case",
+ label: "Get returns error case",
mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error getting run time context:")},
expectedError: "Error getting run time context:",
},
@@ -173,16 +183,16 @@ func TestGetCompositeApp(t *testing.T) {
func TestDeleteCompositeApp(t *testing.T) {
var ac = AppContext{}
testCases := []struct {
- label string
+ label string
mockRtcontext *MockRunTimeContext
expectedError string
}{
{
- label: "Success case",
+ label: "Success case",
mockRtcontext: &MockRunTimeContext{},
},
{
- label: "Delete returns error case",
+ label: "Delete returns error case",
mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error deleting run time context:")},
expectedError: "Error deleting run time context:",
},
@@ -205,20 +215,20 @@ func TestDeleteCompositeApp(t *testing.T) {
func TestAddApp(t *testing.T) {
var ac = AppContext{}
testCases := []struct {
- label string
+ label string
mockRtcontext *MockRunTimeContext
- key interface{}
+ key interface{}
expectedError string
}{
{
- label: "Success case",
+ label: "Success case",
mockRtcontext: &MockRunTimeContext{},
- key: "/context/9345674458787728/",
+ key: "/context/9345674458787728/",
},
{
- label: "Delete returns error case",
+ label: "Delete returns error case",
mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error adding app to run time context:")},
- key: "/context/9345674458787728/",
+ key: "/context/9345674458787728/",
expectedError: "Error adding app to run time context:",
},
}
@@ -241,29 +251,29 @@ func TestAddApp(t *testing.T) {
func TestGetAppHandle(t *testing.T) {
var ac = AppContext{}
testCases := []struct {
- label string
+ label string
mockRtcontext *MockRunTimeContext
- key interface{}
- appname string
+ key interface{}
+ appname string
expectedError string
}{
{
- label: "Success case",
+ label: "Success case",
mockRtcontext: &MockRunTimeContext{},
- key: "/context/9345674458787728/",
- appname: "testapp1",
+ key: "/context/9345674458787728/",
+ appname: "testapp1",
},
{
- label: "Invalid app name case",
+ label: "Invalid app name case",
mockRtcontext: &MockRunTimeContext{},
- key: "/context/9345674458787728/",
- appname: "",
+ key: "/context/9345674458787728/",
+ appname: "",
},
{
- label: "Delete returns error case",
+ label: "Delete returns error case",
mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error getting app handle from run time context:")},
- key: "/context/9345674458787728/",
- appname: "testapp1",
+ key: "/context/9345674458787728/",
+ appname: "testapp1",
expectedError: "Error getting app handle from run time context:",
},
}