summaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/appcontext
diff options
context:
space:
mode:
authorRajamohan Raj <rajamohan.raj@intel.com>2020-05-26 20:08:58 +0000
committerRajamohan Raj <rajamohan.raj@intel.com>2020-06-01 18:45:54 +0000
commitc257a136355a794f5bf778f670c041e8958c3608 (patch)
treee642dae19b2dd8fade13de9342a9dee76d884589 /src/orchestrator/pkg/appcontext
parent7959bd4c6fd403cf4ba58bf572b1259267b3c76d (diff)
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 <rajamohan.raj@intel.com> Change-Id: I21ece189daf6e6b3a7cfdba5df22d57b3d33ca78
Diffstat (limited to 'src/orchestrator/pkg/appcontext')
-rw-r--r--src/orchestrator/pkg/appcontext/appcontext.go90
-rw-r--r--src/orchestrator/pkg/appcontext/appcontext_test.go7
2 files changed, 92 insertions, 5 deletions
diff --git a/src/orchestrator/pkg/appcontext/appcontext.go b/src/orchestrator/pkg/appcontext/appcontext.go
index 5625446d..98baa0f6 100644
--- a/src/orchestrator/pkg/appcontext/appcontext.go
+++ b/src/orchestrator/pkg/appcontext/appcontext.go
@@ -18,14 +18,15 @@ package appcontext
import (
"fmt"
- "strings"
-
+ log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/rtcontext"
pkgerrors "github.com/pkg/errors"
-
- log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+ "strings"
)
+// metaPrefix used for denoting clusterMeta level
+const metaGrpPREFIX = "!@#metaGrp"
+
type AppContext struct {
initDone bool
rtcObj rtcontext.RunTimeContext
@@ -140,7 +141,7 @@ func (ac *AppContext) GetAppHandle(appname string) (interface{}, error) {
return nil, pkgerrors.Errorf("No handle was found for the given app")
}
-//Add cluster to the context under app
+// AddCluster helps to add cluster to the context under app. It takes in the app handle and clusterName as value.
func (ac *AppContext) AddCluster(handle interface{}, clustername string) (interface{}, error) {
h, err := ac.rtc.RtcAddLevel(handle, "cluster", clustername)
if err != nil {
@@ -150,6 +151,85 @@ func (ac *AppContext) AddCluster(handle interface{}, clustername string) (interf
return h, nil
}
+// AddClusterMetaGrp adds the meta info of groupNumber to which a cluster belongs.
+// It takes in cluster handle and groupNumber as arguments
+func (ac *AppContext) AddClusterMetaGrp(ch interface{}, gn string) error {
+ mh, err := ac.rtc.RtcAddOneLevel(ch, metaGrpPREFIX, gn)
+ if err != nil {
+ return err
+ }
+ log.Info(":: Added cluster meta handle ::", log.Fields{"ClusterMetaHandler": mh})
+ return nil
+}
+
+// DeleteClusterMetaGrpHandle deletes the group number to which the cluster belongs, it takes in the cluster handle.
+func (ac *AppContext) DeleteClusterMetaGrpHandle(ch interface{}) error {
+ err := ac.rtc.RtcDeletePrefix(ch)
+ if err != nil {
+ return err
+ }
+ log.Info(":: Deleted cluster meta handle ::", log.Fields{"ClusterMetaHandler": ch})
+ return nil
+}
+
+
+/*
+GetClusterMetaHandle takes in appName and ClusterName as string arguments and return the ClusterMetaHandle as string
+*/
+func (ac *AppContext) GetClusterMetaHandle(app string, cluster string) (string, error) {
+ if app == "" {
+ return "", pkgerrors.Errorf("Not a valid run time context app name")
+ }
+ if cluster == "" {
+ return "", pkgerrors.Errorf("Not a valid run time context cluster name")
+ }
+
+ ch, err := ac.GetClusterHandle(app, cluster)
+ if err != nil {
+ return "", err
+ }
+ cmh := fmt.Sprintf("%v", ch) + metaGrpPREFIX + "/"
+ return cmh, nil
+
+}
+
+/*
+GetClusterGroupMap shall take in appName and return a map showing the grouping among the clusters.
+sample output of "GroupMap" :{"1":["cluster_provider1+clusterName3","cluster_provider1+clusterName5"],"2":["cluster_provider2+clusterName4","cluster_provider2+clusterName6"]}
+*/
+func (ac *AppContext) GetClusterGroupMap(an string) (map[string][]string, error) {
+ cl, err := ac.GetClusterNames(an)
+ if err != nil {
+ log.Info(":: Unable to fetch clusterList for app ::", log.Fields{"AppName ": an})
+ return nil, err
+ }
+ rh, err := ac.rtc.RtcGet()
+ if err != nil {
+ return nil, err
+ }
+
+ var gmap = make(map[string][]string)
+ for _, cn := range cl {
+ s := fmt.Sprintf("%v", rh) + "app/" + an + "/cluster/" + cn + "/" + metaGrpPREFIX + "/"
+ var v string
+ err = ac.rtc.RtcGetValue(s, &v)
+ if err != nil {
+ log.Info(":: No group number for cluster ::", log.Fields{"cluster": cn, "Reason": err})
+ continue
+ }
+ gn := fmt.Sprintf("%v", v)
+ log.Info(":: GroupNumber retrieved ::", log.Fields{"GroupNumber": gn})
+
+ cl, found := gmap[gn]
+ if found == false {
+ cl = make([]string, 0)
+ }
+ cl = append(cl, cn)
+ gmap[gn] = cl
+ }
+ return gmap, nil
+}
+
//Delete cluster from the context and everything underneth
func (ac *AppContext) DeleteCluster(handle interface{}) error {
err := ac.rtc.RtcDeletePrefix(handle)
diff --git a/src/orchestrator/pkg/appcontext/appcontext_test.go b/src/orchestrator/pkg/appcontext/appcontext_test.go
index 07a13d0b..05c73703 100644
--- a/src/orchestrator/pkg/appcontext/appcontext_test.go
+++ b/src/orchestrator/pkg/appcontext/appcontext_test.go
@@ -84,6 +84,13 @@ func (c *MockRunTimeContext) RtcAddLevel(handle interface{}, level string, value
}
+func (c *MockRunTimeContext) RtcAddOneLevel(handle interface{}, level string, value interface{}) (interface{}, error) {
+ str := fmt.Sprintf("%v", handle) + level + "/"
+ c.Items[str] = value
+ return nil, c.Err
+
+}
+
func (c *MockRunTimeContext) RtcAddResource(handle interface{}, resname string, value interface{}) (interface{}, error) {
str := fmt.Sprintf("%v", handle) + "resource" + "/" + resname + "/"
c.Items[str] = value