aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/appcontext
diff options
context:
space:
mode:
authorRajamohan Raj <rajamohan.raj@intel.com>2020-05-11 22:09:18 +0000
committerRajamohan Raj <rajamohan.raj@intel.com>2020-05-15 23:01:17 +0000
commitdbc92bae58ffbeb38f5c3e5c58a1da2fb3b349f4 (patch)
tree57fce86658311cf0109659446271fdc74db449e3 /src/orchestrator/pkg/appcontext
parentc77850a75eee9f3df2e194521e59728572bc47c2 (diff)
Adding meta data for app in appContext
In this patch, modified the appContext and rtc lib by adding functions for setting and getting the meta data associated with the apps. Issue-ID: MULTICLOUD-1064 Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com> Change-Id: I08f91ddda3044f172caf7b2673c069fed16c32c4
Diffstat (limited to 'src/orchestrator/pkg/appcontext')
-rw-r--r--src/orchestrator/pkg/appcontext/appcontext.go55
-rw-r--r--src/orchestrator/pkg/appcontext/appcontext_test.go30
2 files changed, 77 insertions, 8 deletions
diff --git a/src/orchestrator/pkg/appcontext/appcontext.go b/src/orchestrator/pkg/appcontext/appcontext.go
index 8f7841ac..00e0241a 100644
--- a/src/orchestrator/pkg/appcontext/appcontext.go
+++ b/src/orchestrator/pkg/appcontext/appcontext.go
@@ -22,7 +22,7 @@ import (
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/rtcontext"
pkgerrors "github.com/pkg/errors"
- //"log"
+
log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
)
@@ -32,6 +32,16 @@ type AppContext struct {
rtc rtcontext.Rtcontext
}
+// CompositeAppMeta consists of projectName, CompositeAppName,
+// CompositeAppVersion, ReleaseName. This shall be used for
+// instantiation of a compositeApp
+type CompositeAppMeta struct {
+ Project string `json:"Project"`
+ CompositeApp string `json:"CompositeApp"`
+ Version string `json:"Version"`
+ Release string `json:"Release"`
+}
+
// Init app context
func (ac *AppContext) InitAppContext() (interface{}, error) {
ac.rtcObj = rtcontext.RunTimeContext{}
@@ -46,15 +56,25 @@ func (ac *AppContext) LoadAppContext(cid interface{}) (interface{}, error) {
return ac.rtc.RtcLoad(cid)
}
-// Create a new context and returns the handle
+// CreateCompositeApp method returns composite app handle as interface.
func (ac *AppContext) CreateCompositeApp() (interface{}, error) {
h, err := ac.rtc.RtcCreate()
if err != nil {
return nil, err
}
+ log.Info(":: CreateCompositeApp ::", log.Fields{"CompositeAppHandle": h})
return h, nil
}
+// AddCompositeAppMeta adds the meta data associated with a composite app
+func (ac *AppContext) AddCompositeAppMeta(meta interface{}) error {
+ err := ac.rtc.RtcAddMeta(meta)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
// Deletes the entire context
func (ac *AppContext) DeleteCompositeApp() error {
h, err := ac.rtc.RtcGet()
@@ -69,7 +89,7 @@ func (ac *AppContext) DeleteCompositeApp() error {
}
//Returns the handles for a given composite app context
-func (ac *AppContext) GetCompositeApp() (interface{}, error) {
+func (ac *AppContext) GetCompositeAppHandle() (interface{}, error) {
h, err := ac.rtc.RtcGet()
if err != nil {
return nil, err
@@ -83,7 +103,7 @@ func (ac *AppContext) AddApp(handle interface{}, appname string) (interface{}, e
if err != nil {
return nil, err
}
- log.Info(":: Added app handle ::", log.Fields{"AppHandle":h})
+ log.Info(":: Added app handle ::", log.Fields{"AppHandle": h})
return h, nil
}
@@ -126,7 +146,7 @@ func (ac *AppContext) AddCluster(handle interface{}, clustername string) (interf
if err != nil {
return nil, err
}
- log.Info(":: Added cluster handle ::", log.Fields{"ClusterHandler":h})
+ log.Info(":: Added cluster handle ::", log.Fields{"ClusterHandler": h})
return h, nil
}
@@ -202,7 +222,7 @@ func (ac *AppContext) AddResource(handle interface{}, resname string, value []by
if err != nil {
return nil, err
}
- log.Info(":: Added resource handle ::", log.Fields{"ResourceHandler":h})
+ log.Info(":: Added resource handle ::", log.Fields{"ResourceHandler": h})
return h, nil
}
@@ -260,7 +280,7 @@ func (ac *AppContext) AddInstruction(handle interface{}, level string, insttype
if err != nil {
return nil, err
}
- log.Info(":: Added instruction handle ::", log.Fields{"InstructionHandler":h})
+ log.Info(":: Added instruction handle ::", log.Fields{"InstructionHandler": h})
return h, nil
}
@@ -332,3 +352,24 @@ func (ac *AppContext) GetValue(handle interface{}) (interface{}, error) {
}
return v, nil
}
+
+// GetCompositeAppMeta returns the meta data associated with the compositeApp
+// Its return type is CompositeAppMeta
+func (ac *AppContext) GetCompositeAppMeta() (CompositeAppMeta, error) {
+ mi, err := ac.rtcObj.RtcGetMeta()
+
+ if err != nil {
+ return CompositeAppMeta{}, pkgerrors.Errorf("Failed to get compositeApp meta")
+ }
+ datamap, ok := mi.(map[string]interface{})
+ if ok == false {
+ return CompositeAppMeta{}, pkgerrors.Errorf("Failed to cast meta interface to compositeApp meta")
+ }
+
+ p := fmt.Sprintf("%v", datamap["Project"])
+ ca := fmt.Sprintf("%v", datamap["CompositeApp"])
+ v := fmt.Sprintf("%v", datamap["Version"])
+ rn := fmt.Sprintf("%v", datamap["Release"])
+
+ return CompositeAppMeta{Project: p, CompositeApp: ca, Version: v, Release: rn}, nil
+}
diff --git a/src/orchestrator/pkg/appcontext/appcontext_test.go b/src/orchestrator/pkg/appcontext/appcontext_test.go
index e539ed7a..07a13d0b 100644
--- a/src/orchestrator/pkg/appcontext/appcontext_test.go
+++ b/src/orchestrator/pkg/appcontext/appcontext_test.go
@@ -29,6 +29,13 @@ type MockRunTimeContext struct {
Err error
}
+type MockCompositeAppMeta struct {
+ Project string
+ CompositeApp string
+ Version string
+ Release string
+}
+
func (c *MockRunTimeContext) RtcCreate() (interface{}, error) {
var key string = "/context/9345674458787728/"
@@ -40,6 +47,16 @@ func (c *MockRunTimeContext) RtcCreate() (interface{}, error) {
}
+func (c *MockRunTimeContext) RtcAddMeta(meta interface{}) error {
+ var cid string = "/context/9345674458787728/"
+ key := cid + "meta" + "/"
+ if c.Items == nil {
+ c.Items = make(map[string]interface{})
+ }
+ c.Items[key] = meta
+ return nil
+}
+
func (c *MockRunTimeContext) RtcInit() (interface{}, error) {
var id string = "9345674458787728"
return id, c.Err
@@ -55,6 +72,11 @@ func (c *MockRunTimeContext) RtcGet() (interface{}, error) {
return key, c.Err
}
+func (c *MockRunTimeContext) RtcGetMeta() (interface{}, error) {
+ meta := CompositeAppMeta{Project: "pn", CompositeApp: "ca", Version: "v", Release: "rName"}
+ return meta, nil
+}
+
func (c *MockRunTimeContext) RtcAddLevel(handle interface{}, level string, value string) (interface{}, error) {
str := fmt.Sprintf("%v", handle) + level + "/" + value + "/"
c.Items[str] = value
@@ -122,15 +144,18 @@ func TestCreateCompositeApp(t *testing.T) {
label string
mockRtcontext *MockRunTimeContext
expectedError string
+ meta interface{}
}{
{
label: "Success case",
mockRtcontext: &MockRunTimeContext{},
+ meta: interface{}(MockCompositeAppMeta{Project: "Testproject", CompositeApp: "TestCompApp", Version: "CompAppVersion", Release: "TestRelease"}),
},
{
label: "Create returns error case",
mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error creating run time context:")},
expectedError: "Error creating run time context:",
+ meta: interface{}(MockCompositeAppMeta{Project: "Testproject", CompositeApp: "TestCompApp", Version: "CompAppVersion", Release: "TestRelease"}),
},
}
@@ -169,7 +194,7 @@ func TestGetCompositeApp(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
ac.rtc = testCase.mockRtcontext
- _, err := ac.GetCompositeApp()
+ _, err := ac.GetCompositeAppHandle()
if err != nil {
if !strings.Contains(string(err.Error()), testCase.expectedError) {
t.Fatalf("Method returned an error (%s)", err)
@@ -219,17 +244,20 @@ func TestAddApp(t *testing.T) {
mockRtcontext *MockRunTimeContext
key interface{}
expectedError string
+ meta interface{}
}{
{
label: "Success case",
mockRtcontext: &MockRunTimeContext{},
key: "/context/9345674458787728/",
+ meta: interface{}(MockCompositeAppMeta{Project: "Testproject", CompositeApp: "TestCompApp", Version: "CompAppVersion", Release: "TestRelease"}),
},
{
label: "Error case for adding app",
mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error adding app to run time context:")},
key: "/context/9345674458787728/",
expectedError: "Error adding app to run time context:",
+ meta: interface{}(MockCompositeAppMeta{Project: "Testproject", CompositeApp: "TestCompApp", Version: "CompAppVersion", Release: "TestRelease"}),
},
}